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