Elin Decompiled Documentation EA 23.356.1 Nightly
Loading...
Searching...
No Matches
UICurrency.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class UICurrency : EMono
7{
8 [Serializable]
9 public class Options
10 {
11 public bool money;
12
13 public bool plat;
14
15 public bool ecopo;
16
17 public bool knowledge;
18
19 public bool influence;
20
21 public bool medal;
22
23 public bool money2;
24
25 public bool resources;
26
27 public bool branchMoney;
28
29 public bool branchFood;
30
31 public bool branchMaterial;
32
33 public bool branchKnowledge;
34
35 public bool admin;
36
37 public bool casino;
38
39 public bool weight;
40
41 public bool ticketSky;
42
43 public bool mandrake;
44 }
45
46 public class Item
47 {
48 public Func<string> func;
49
50 public UIText text;
51 }
52
53 public List<Item> items = new List<Item>();
54
55 public bool autoBuild;
56
57 public bool disable;
58
60
61 public Sprite[] icons;
62
63 public LayoutGroup layout;
64
65 public Card target;
66
67 private UIButton mold;
68
69 private void Awake()
70 {
71 if (autoBuild)
72 {
73 Build();
74 }
75 InvokeRepeating("Refresh", 0.1f, 0.1f);
76 }
77
78 private void OnEnable()
79 {
80 Refresh();
81 }
82
83 public void Build(Options _options)
84 {
85 options = _options;
86 Build();
87 }
88
89 public void Build()
90 {
91 items.Clear();
92 mold = layout.CreateMold<UIButton>();
93 if (options.plat)
94 {
95 Add(icons[1], "plat", () => EMono.pc.GetCurrency("plat").ToString("#,0") ?? "");
96 }
97 if (options.money)
98 {
99 Add(icons[0], "money", () => EMono.pc.GetCurrency().ToString("#,0") ?? "");
100 }
101 if (options.money2)
102 {
103 Add(icons[5], "money2", () => EMono.pc.GetCurrency("money2").ToString("#,0") ?? "");
104 }
105 if (options.medal)
106 {
107 Add(icons[4], "medal", () => EMono.pc.GetCurrency("medal").ToString("#,0") ?? "");
108 }
109 if (options.ecopo)
110 {
111 Add(EMono.sources.cards.map["ecopo"].GetSprite(), "ecopo", () => EMono.pc.GetCurrency("ecopo").ToString("#,0") ?? "");
112 }
113 if (options.mandrake)
114 {
115 Add(EMono.sources.cards.map["money3"].GetSprite(), "money3", () => EMono.pc.GetCurrency("money3").ToString("#,0") ?? "");
116 }
117 if (options.ticketSky)
118 {
119 Add(EMono.sources.cards.map["ticket_sky"].GetSprite(), "ticket_sky", () => EMono.pc.GetCurrency("ticket_sky").ToString("#,0") ?? "");
120 }
121 if (options.influence)
122 {
123 Add(icons[3], "influence", () => EMono._zone.influence.ToString() ?? "");
124 }
125 if (options.casino)
126 {
127 Add(icons[10], "casino_coin", () => EMono.pc.GetCurrency("casino_coin").ToString("#,0") ?? "");
128 }
129 if (options.weight)
130 {
131 Add(icons[11], "weightInv", () => Lang._weight(target.ChildrenWeight, showUnit: false) + " / " + Lang._weight(target.WeightLimit));
132 }
133 if (EMono.BranchOrHomeBranch != null)
134 {
137 {
138 Add(icons[5], resources.money.Name, () => resources.money.value.ToString("#,0") ?? "");
139 }
141 {
142 Add(icons[6], resources.food.Name, () => resources.food.value.ToString("#,0") ?? "");
143 }
145 {
146 Add(icons[7], resources.knowledge.Name, () => resources.knowledge.value.ToString("#,0") ?? "");
147 }
148 if (options.admin)
149 {
150 Add(icons[9], "ap", () => EMono.Branch.policies.CurrentAP() + "/" + EMono.Branch.MaxAP);
151 }
152 if (options.resources)
153 {
155 {
156 if (r.IsAvailable)
157 {
158 Add(r.Sprite, r.Name, () => r.value.ToString("#,0") ?? "");
159 }
160 }
161 }
162 }
163 layout.RebuildLayout();
164 }
165
166 public void Add(Sprite icon, string lang, Func<string> func)
167 {
168 UIButton uIButton = Util.Instantiate(mold, layout);
169 uIButton.icon.sprite = icon;
170 uIButton.icon.SetNativeSize();
171 uIButton.tooltip.lang = lang.lang().ToTitleCase(wholeText: true);
172 items.Add(new Item
173 {
174 func = func,
175 text = uIButton.mainText
176 });
177 uIButton.mainText.SetText(func());
178 uIButton.mainText.RebuildLayout();
179 uIButton.RebuildLayout();
180 }
181
182 public void Refresh()
183 {
184 foreach (Item item in items)
185 {
186 string text = item.func();
187 if (item.text.text != (text ?? ""))
188 {
189 item.text.SetText(text);
190 item.text.RebuildLayout();
191 item.text.transform.parent.RebuildLayout();
192 }
193 }
194 }
195}
virtual bool IsAvailable
Definition: Card.cs:11
int ChildrenWeight
Definition: Card.cs:2065
virtual int WeightLimit
Definition: Card.cs:2099
int GetCurrency(string id="money")
Definition: Card.cs:4156
Definition: EMono.cs:4
static Chara pc
Definition: EMono.cs:13
static Zone _zone
Definition: EMono.cs:19
static FactionBranch BranchOrHomeBranch
Definition: EMono.cs:23
static FactionBranch Branch
Definition: EMono.cs:21
static SourceManager sources
Definition: EMono.cs:41
PolicyManager policies
HomeResourceManager resources
List< BaseHomeResource > list
Definition: Lang.cs:7
static string _weight(int a, int b, bool showUnit=true, int unitSize=0)
Definition: Lang.cs:171
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
SourceCard cards
int influence
Definition: Spatial.cs:214
Image icon
Definition: UIButton.cs:110
UIText mainText
Definition: UIButton.cs:102
Func< string > func
Definition: UICurrency.cs:48
void Build()
Definition: UICurrency.cs:89
Options options
Definition: UICurrency.cs:59
void Awake()
Definition: UICurrency.cs:69
Sprite[] icons
Definition: UICurrency.cs:61
void Refresh()
Definition: UICurrency.cs:182
Card target
Definition: UICurrency.cs:65
List< Item > items
Definition: UICurrency.cs:53
LayoutGroup layout
Definition: UICurrency.cs:63
void Build(Options _options)
Definition: UICurrency.cs:83
void OnEnable()
Definition: UICurrency.cs:78
bool autoBuild
Definition: UICurrency.cs:55
void Add(Sprite icon, string lang, Func< string > func)
Definition: UICurrency.cs:166
UIButton mold
Definition: UICurrency.cs:67
bool disable
Definition: UICurrency.cs:57
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:163