Elin Decompiled Documentation EA 23.102 Nightly
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 List<Thing> filteredList = new List<Thing>();
36
38
40
41 public HashSet<string> cats = new HashSet<string>();
42
43 public Dictionary<string, UIButton> catButton = new Dictionary<string, UIButton>();
44
45 public Dictionary<string, int> catCount = new Dictionary<string, int>();
46
47 public string idCat = "";
48
49 private bool firstSearch = true;
50
51 private float timerSearch;
52
53 public string lastSearch = "";
54
55 public HashSet<Recipe> searchRecipes = new HashSet<Recipe>();
56
58
60
61 public void Init()
62 {
63 UIButton t = layoutPage.CreateMold<UIButton>();
64 moldCat = layoutCat.CreateMold<UIButton>();
65 for (int i = 0; i < 9; i++)
66 {
67 UIButton b = Util.Instantiate(t, layoutPage);
68 b.mainText.text = (i + 1).ToString() ?? "";
69 buttonsPage.Add(b);
70 int _i = i;
71 b.SetOnClick(delegate
72 {
74 {
75 page = _i;
77 SE.Tab();
78 Redraw();
79 }
80 });
81 }
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 for (int i = 0; i < buttonsPage.Count; i++)
95 {
96 buttonsPage[i].interactable = i <= pageMax;
97 }
98 groupPage.selected = null;
100 }
101
102 public void RefreshCats()
103 {
104 foreach (string cat in cats)
105 {
106 if (catButton.ContainsKey(cat))
107 {
108 continue;
109 }
110 UIButton uIButton = Util.Instantiate(moldCat, layoutCat);
111 catButton[cat] = uIButton;
112 string _c = cat;
113 uIButton.SetOnClick(delegate
114 {
116 {
117 SE.Tab();
118 if (idCat == _c)
119 {
120 idCat = "";
121 }
122 else
123 {
124 idCat = _c;
125 }
126 Redraw();
127 }
128 });
129 }
130 foreach (KeyValuePair<string, UIButton> item in catButton)
131 {
132 bool flag = cats.Contains(item.Key);
133 UIButton value = item.Value;
134 value.SetActive(flag);
135 if (flag)
136 {
137 value.mainText.text = EMono.sources.categories.map[item.Key].GetName() + " (" + catCount[item.Key] + ")";
138 value.image.color = ((item.Key == idCat) ? colorCatSelected : colorCat);
139 }
140 }
141 }
142
143 public void RefreshBottom()
144 {
145 itemNum.mainText.text = container.things.Count + " / " + container.things.MaxCapacity;
146 itemElec.mainText.SetText(Mathf.Abs(container.trait.Electricity) + " " + "mw".lang(), (container.trait.Electricity == 0 || container.isOn) ? FontColor.Good : FontColor.Bad);
147 }
148
149 private void LateUpdate()
150 {
151 if (timerSearch > 0f)
152 {
153 timerSearch -= Core.delta;
154 if (timerSearch <= 0f)
155 {
156 Search(inputSearch.text);
157 }
158 }
159 if (EInput.wheel != 0 && !UIContextMenu.Current)
160 {
161 SE.Tab();
162 page -= EInput.wheel;
163 if (page < 0)
164 {
165 page = pageMax;
166 }
167 if (page > pageMax)
168 {
169 page = 0;
170 }
171 Redraw();
172 }
173 }
174
175 public void Search(string s)
176 {
177 s = s.ToLower();
178 if (s.IsEmpty())
179 {
180 s = "";
181 }
182 buttonClearSearch.SetActive(inputSearch.text != "");
183 if (s == lastSearch)
184 {
185 return;
186 }
187 if (firstSearch)
188 {
189 firstSearch = false;
190 foreach (Thing thing in container.things)
191 {
192 thing.tempName = thing.GetName(NameStyle.Full, 1).ToLower();
193 }
194 }
195 timerSearch = intervalSearch;
196 lastSearch = s;
197 Redraw();
198 }
199
200 public void ClearSearch()
201 {
202 inputSearch.text = "";
203 timerSearch = 0f;
204 lastSearch = "";
205 Redraw();
206 }
207
208 public void Redraw()
209 {
210 uiInventory.list.Redraw();
211 }
212}
FontColor
Definition: FontColor.cs:2
NameStyle
Definition: NameStyle.cs:2
Definition: Card.cs:11
Trait trait
Definition: Card.cs:49
ThingContainer things
Definition: Card.cs:34
bool isOn
Definition: Card.cs:514
Definition: Core.cs:14
static float delta
Definition: Core.cs:17
Definition: EInput.cs:8
static int wheel
Definition: EInput.cs:289
Definition: EMono.cs:4
static SourceManager sources
Definition: EMono.cs:41
Card Container
Definition: InvOwner.cs:540
SourceCategory categories
Definition: Thing.cs:8
override string GetName(NameStyle style, int _num=-1)
Definition: Thing.cs:494
virtual int Electricity
Definition: Trait.cs:97
UIText mainText
Definition: UIButton.cs:102
static UIContextMenu Current
InvOwner owner
Definition: UIInventory.cs:137
UIList list
Definition: UIInventory.cs:79
override void Redraw()
Definition: UIList.cs:740
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:43
UIInventory uiInventory
Definition: UIMagicChest.cs:25
string idCat
Definition: UIMagicChest.cs:47
Dictionary< string, int > catCount
Definition: UIMagicChest.cs:45
LayoutGroup layoutBottom
Definition: UIMagicChest.cs:11
Color colorCatSelected
Definition: UIMagicChest.cs:39
bool firstSearch
Definition: UIMagicChest.cs:49
void LateUpdate()
void RefreshBottom()
UIButton buttonClearSearch
Definition: UIMagicChest.cs:17
HashSet< string > cats
Definition: UIMagicChest.cs:41
InputField inputSearch
Definition: UIMagicChest.cs:27
UIButton moldCat
Definition: UIMagicChest.cs:19
void Search(string s)
void ClearSearch()
HashSet< Recipe > searchRecipes
Definition: UIMagicChest.cs:55
string lastSearch
Definition: UIMagicChest.cs:53
LayoutGroup layoutPage
Definition: UIMagicChest.cs:7
float timerSearch
Definition: UIMagicChest.cs:51
UIButton itemElec
Definition: UIMagicChest.cs:15
void OnAfterRedraw()
Definition: UIMagicChest.cs:91
Color colorCat
Definition: UIMagicChest.cs:37
List< Thing > filteredList
Definition: UIMagicChest.cs:35
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:159