Elin Decompiled Documentation EA 23.355 Stable
Loading...
Searching...
No Matches
UIMagicChest.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
5public class UIMagicChest : EMono
6{
7 public LayoutGroup layoutPage;
8
9 public LayoutGroup layoutCat;
10
11 public LayoutGroup layoutBottom;
12
14
16
18
20
22
23 public List<UIButton> buttonsPage;
24
26
27 public InputField inputSearch;
28
29 public float intervalSearch;
30
31 public int page;
32
33 public int pageMax;
34
35 public int pageJump = 7;
36
37 public List<Thing> filteredList = new List<Thing>();
38
40
42
43 public HashSet<string> cats = new HashSet<string>();
44
45 public Dictionary<string, UIButton> catButton = new Dictionary<string, UIButton>();
46
47 public Dictionary<string, int> catCount = new Dictionary<string, int>();
48
49 public string idCat = "";
50
51 private bool firstSearch = true;
52
53 private float timerSearch;
54
55 public string lastSearch = "";
56
57 public HashSet<Recipe> searchRecipes = new HashSet<Recipe>();
58
60
62
63 public void Init()
64 {
65 UIButton t = layoutPage.CreateMold<UIButton>();
66 moldCat = layoutCat.CreateMold<UIButton>();
67 for (int i = 0; i < 9; i++)
68 {
69 UIButton b = Util.Instantiate(t, layoutPage);
70 buttonsPage.Add(b);
71 b.SetOnClick(delegate
72 {
74 {
75 page = b.refInt;
76 SE.Tab();
77 Redraw();
78 }
79 });
80 }
81 groupPage.selectOnClick = false;
83 inputSearch.onValueChanged.AddListener(Search);
84 inputSearch.onSubmit.AddListener(Search);
86 itemNum.RebuildLayout();
87 itemElec.RebuildLayout();
88 layoutBottom.RebuildLayout();
89 }
90
91 public void OnAfterRedraw()
92 {
94 int count = buttonsPage.Count;
95 bool flag = pageMax >= count;
96 int num = ((!flag) ? 1 : Mathf.Clamp(page - count / 2 + 1, 1, pageMax - count + 2));
97 for (int i = 0; i < count; i++)
98 {
99 UIButton uIButton = buttonsPage[i];
100 int num2 = ((i != 0) ? ((flag && i == count - 1) ? pageMax : (num + i - 1)) : 0);
101 bool flag2 = (i == 1 && num2 > 1) || (i == count - 2 && num2 < pageMax - 1);
102 uIButton.refInt = (flag2 ? Mathf.Clamp(page + ((i == 1) ? (-pageJump) : pageJump), 0, pageMax) : num2);
103 uIButton.mainText.text = (flag2 ? "…" : ((num2 + 1).ToString() ?? ""));
104 uIButton.interactable = num2 <= pageMax;
105 }
106 groupPage.selected = null;
107 groupPage.Select((UIButton a) => a.refInt == page);
108 }
109
110 public void RefreshCats()
111 {
112 foreach (string cat in cats)
113 {
114 if (catButton.ContainsKey(cat))
115 {
116 continue;
117 }
118 UIButton uIButton = Util.Instantiate(moldCat, layoutCat);
119 catButton[cat] = uIButton;
120 string _c = cat;
121 uIButton.SetOnClick(delegate
122 {
124 {
125 SE.Tab();
126 if (idCat == _c)
127 {
128 idCat = "";
129 }
130 else
131 {
132 idCat = _c;
133 }
134 Redraw();
135 }
136 });
137 }
138 foreach (KeyValuePair<string, UIButton> item in catButton)
139 {
140 bool flag = cats.Contains(item.Key);
141 UIButton value = item.Value;
142 value.SetActive(flag);
143 if (flag)
144 {
145 value.mainText.text = EMono.sources.categories.map[item.Key].GetName() + " (" + catCount[item.Key] + ")";
146 value.image.color = ((item.Key == idCat) ? colorCatSelected : colorCat);
147 }
148 }
149 }
150
151 public void RefreshBottom()
152 {
153 itemNum.mainText.text = container.things.Count + " / " + container.things.MaxCapacity;
154 itemElec.mainText.SetText(Mathf.Abs(container.trait.Electricity) + " " + "mw".lang(), (container.trait.Electricity == 0 || container.isOn) ? FontColor.Good : FontColor.Bad);
155 }
156
157 private void LateUpdate()
158 {
159 if (timerSearch > 0f)
160 {
161 timerSearch -= Core.delta;
162 if (timerSearch <= 0f)
163 {
164 Search(inputSearch.text);
165 }
166 }
167 if (EInput.wheel != 0 && !UIContextMenu.Current)
168 {
169 SE.Tab();
170 page -= EInput.wheel;
171 if (page < 0)
172 {
173 page = pageMax;
174 }
175 if (page > pageMax)
176 {
177 page = 0;
178 }
179 Redraw();
180 }
181 }
182
183 public void Search(string s)
184 {
185 s = s.ToLower();
186 if (s.IsEmpty())
187 {
188 s = "";
189 }
190 buttonClearSearch.SetActive(inputSearch.text != "");
191 if (s == lastSearch)
192 {
193 return;
194 }
195 if (firstSearch)
196 {
197 firstSearch = false;
198 foreach (Thing thing in container.things)
199 {
200 thing.tempName = thing.GetName(NameStyle.Full, 1).ToLower();
201 }
202 }
203 timerSearch = intervalSearch;
204 lastSearch = s;
205 Redraw();
206 }
207
208 public void ClearSearch()
209 {
210 inputSearch.text = "";
211 timerSearch = 0f;
212 lastSearch = "";
213 Redraw();
214 }
215
216 public void Redraw()
217 {
218 uiInventory.list.Redraw();
219 }
220}
FontColor
Definition: FontColor.cs:2
NameStyle
Definition: NameStyle.cs:2
Definition: Card.cs:11
Trait trait
Definition: Card.cs:54
ThingContainer things
Definition: Card.cs:39
bool isOn
Definition: Card.cs:545
Definition: Core.cs:14
static float delta
Definition: Core.cs:17
Definition: EInput.cs:8
static int wheel
Definition: EInput.cs:300
Definition: EMono.cs:4
static SourceManager sources
Definition: EMono.cs:41
Card Container
Definition: InvOwner.cs:535
SourceCategory categories
Definition: Thing.cs:8
override string GetName(NameStyle style, int _num=-1)
Definition: Thing.cs:536
virtual int Electricity
Definition: Trait.cs:119
UIText mainText
Definition: UIButton.cs:102
int refInt
Definition: UIButton.cs:154
static UIContextMenu Current
InvOwner owner
Definition: UIInventory.cs:139
UIList list
Definition: UIInventory.cs:79
override void Redraw()
Definition: UIList.cs:796
float intervalSearch
Definition: UIMagicChest.cs:29
List< UIButton > buttonsPage
Definition: UIMagicChest.cs:23
void RefreshCats()
LayoutGroup layoutCat
Definition: UIMagicChest.cs:9
UIButton itemNum
Definition: UIMagicChest.cs:13
UISelectableGroup groupPage
Definition: UIMagicChest.cs:21
Dictionary< string, UIButton > catButton
Definition: UIMagicChest.cs:45
UIInventory uiInventory
Definition: UIMagicChest.cs:25
string idCat
Definition: UIMagicChest.cs:49
Dictionary< string, int > catCount
Definition: UIMagicChest.cs:47
LayoutGroup layoutBottom
Definition: UIMagicChest.cs:11
Color colorCatSelected
Definition: UIMagicChest.cs:41
bool firstSearch
Definition: UIMagicChest.cs:51
void LateUpdate()
void RefreshBottom()
UIButton buttonClearSearch
Definition: UIMagicChest.cs:17
HashSet< string > cats
Definition: UIMagicChest.cs:43
InputField inputSearch
Definition: UIMagicChest.cs:27
UIButton moldCat
Definition: UIMagicChest.cs:19
void Search(string s)
void ClearSearch()
HashSet< Recipe > searchRecipes
Definition: UIMagicChest.cs:57
string lastSearch
Definition: UIMagicChest.cs:55
LayoutGroup layoutPage
Definition: UIMagicChest.cs:7
float timerSearch
Definition: UIMagicChest.cs:53
UIButton itemElec
Definition: UIMagicChest.cs:15
void OnAfterRedraw()
Definition: UIMagicChest.cs:91
Color colorCat
Definition: UIMagicChest.cs:39
List< Thing > filteredList
Definition: UIMagicChest.cs:37
void Select(UIButton button, bool check=true)
virtual void Init(int index=0, UnityAction< int > action=null, bool directChildren=false)
void SetText(string s)
Definition: UIText.cs:163