Elin Decompiled Documentation EA 23.343.5 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
44 public class Item
45 {
46 public Func<string> func;
47
48 public UIText text;
49 }
50
51 public List<Item> items = new List<Item>();
52
53 public bool autoBuild;
54
55 public bool disable;
56
58
59 public Sprite[] icons;
60
61 public LayoutGroup layout;
62
63 public Card target;
64
65 private UIButton mold;
66
67 private void Awake()
68 {
69 if (autoBuild)
70 {
71 Build();
72 }
73 InvokeRepeating("Refresh", 0.1f, 0.1f);
74 }
75
76 private void OnEnable()
77 {
78 Refresh();
79 }
80
81 public void Build(Options _options)
82 {
83 options = _options;
84 Build();
85 }
86
87 public void Build()
88 {
89 items.Clear();
90 mold = layout.CreateMold<UIButton>();
91 if (options.plat)
92 {
93 Add(icons[1], "plat", () => EMono.pc.GetCurrency("plat").ToString("#,0") ?? "");
94 }
95 if (options.money)
96 {
97 Add(icons[0], "money", () => EMono.pc.GetCurrency().ToString("#,0") ?? "");
98 }
99 if (options.money2)
100 {
101 Add(icons[5], "money2", () => EMono.pc.GetCurrency("money2").ToString("#,0") ?? "");
102 }
103 if (options.medal)
104 {
105 Add(icons[4], "medal", () => EMono.pc.GetCurrency("medal").ToString("#,0") ?? "");
106 }
107 if (options.ecopo)
108 {
109 Add(EMono.sources.cards.map["ecopo"].GetSprite(), "ecopo", () => EMono.pc.GetCurrency("ecopo").ToString("#,0") ?? "");
110 }
111 if (options.ticketSky)
112 {
113 Add(EMono.sources.cards.map["ticket_sky"].GetSprite(), "ticket_sky", () => EMono.pc.GetCurrency("ticket_sky").ToString("#,0") ?? "");
114 }
115 if (options.influence)
116 {
117 Add(icons[3], "influence", () => EMono._zone.influence.ToString() ?? "");
118 }
119 if (options.casino)
120 {
121 Add(icons[10], "casino_coin", () => EMono.pc.GetCurrency("casino_coin").ToString("#,0") ?? "");
122 }
123 if (options.weight)
124 {
125 Add(icons[11], "weightInv", () => Lang._weight(target.ChildrenWeight, showUnit: false) + " / " + Lang._weight(target.WeightLimit));
126 }
127 if (EMono.BranchOrHomeBranch != null)
128 {
131 {
132 Add(icons[5], resources.money.Name, () => resources.money.value.ToString("#,0") ?? "");
133 }
135 {
136 Add(icons[6], resources.food.Name, () => resources.food.value.ToString("#,0") ?? "");
137 }
139 {
140 Add(icons[7], resources.knowledge.Name, () => resources.knowledge.value.ToString("#,0") ?? "");
141 }
142 if (options.admin)
143 {
144 Add(icons[9], "ap", () => EMono.Branch.policies.CurrentAP() + "/" + EMono.Branch.MaxAP);
145 }
146 if (options.resources)
147 {
149 {
150 if (r.IsAvailable)
151 {
152 Add(r.Sprite, r.Name, () => r.value.ToString("#,0") ?? "");
153 }
154 }
155 }
156 }
157 layout.RebuildLayout();
158 }
159
160 public void Add(Sprite icon, string lang, Func<string> func)
161 {
162 UIButton uIButton = Util.Instantiate(mold, layout);
163 uIButton.icon.sprite = icon;
164 uIButton.icon.SetNativeSize();
165 uIButton.tooltip.lang = lang.lang().ToTitleCase(wholeText: true);
166 items.Add(new Item
167 {
168 func = func,
169 text = uIButton.mainText
170 });
171 uIButton.mainText.SetText(func());
172 uIButton.mainText.RebuildLayout();
173 uIButton.RebuildLayout();
174 }
175
176 public void Refresh()
177 {
178 foreach (Item item in items)
179 {
180 string text = item.func();
181 if (item.text.text != (text ?? ""))
182 {
183 item.text.SetText(text);
184 item.text.RebuildLayout();
185 item.text.transform.parent.RebuildLayout();
186 }
187 }
188 }
189}
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:46
void Build()
Definition: UICurrency.cs:87
Options options
Definition: UICurrency.cs:57
void Awake()
Definition: UICurrency.cs:67
Sprite[] icons
Definition: UICurrency.cs:59
void Refresh()
Definition: UICurrency.cs:176
Card target
Definition: UICurrency.cs:63
List< Item > items
Definition: UICurrency.cs:51
LayoutGroup layout
Definition: UICurrency.cs:61
void Build(Options _options)
Definition: UICurrency.cs:81
void OnEnable()
Definition: UICurrency.cs:76
bool autoBuild
Definition: UICurrency.cs:53
void Add(Sprite icon, string lang, Func< string > func)
Definition: UICurrency.cs:160
UIButton mold
Definition: UICurrency.cs:65
bool disable
Definition: UICurrency.cs:55
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:163