Elin Decompiled Documentation EA 23.356.1 Nightly
Loading...
Searching...
No Matches
DropdownGrid.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class DropdownGrid : EMono
7{
8 public static bool IsActive;
9
10 public static DropdownGrid Instance;
11
12 public UIList list;
13
15
16 public RectTransform rectDrop;
17
18 public RectTransform rectDropContent;
19
20 public RectTransform pivot;
21
22 public Recipe recipe;
23
24 public Image icon;
25
26 public SoundData soundPop;
27
28 public Action onValueChange;
29
30 public int slots = 4;
31
32 public Vector3 fixPos;
33
35
37
38 [NonSerialized]
39 public Dictionary<string, int> lastMats = new Dictionary<string, int>();
40
41 private void Awake()
42 {
43 rectDrop.SetActive(enable: false);
44 }
45
46 private void Update()
47 {
48 rectDrop.SetActive(IsActive);
49 }
50
51 public void Build(List<GridItem> items)
52 {
53 list.Clear();
54 list.callbacks = new UIList.Callback<GridItem, ButtonGrid>
55 {
56 onInstantiate = delegate(GridItem a, ButtonGrid b)
57 {
58 a.SetButton(b);
59 },
60 onClick = delegate(GridItem a, ButtonGrid b)
61 {
62 a.OnClick(b);
63 },
64 onRedraw = delegate(GridItem a, ButtonGrid b, int i)
65 {
66 a.SetButton(b);
67 }
68 };
69 for (int num = 0; num < slots; num++)
70 {
71 if (num < items.Count)
72 {
73 list.Add(items[num]);
74 }
75 else
76 {
77 list.Add(new GridItem());
78 }
79 }
80 list.Refresh();
81 }
82
84 {
85 List<Thing> obj = EMono._map.Stocked.ListThingStack(ingredient, searchMode).list;
86 obj.Sort(UIList.SortMode.ByCategory);
87 return obj;
88 }
89
90 public void BuildIngredients(Recipe _recipe, Image _icon, Action _onValueChange, StockSearchMode _searchMode)
91 {
92 recipe = _recipe;
93 icon = _icon;
94 list.Clear();
95 onValueChange = _onValueChange;
96 searchMode = _searchMode;
97 if (recipe == null)
98 {
99 return;
100 }
101 list.callbacks = new UIList.Callback<Recipe.Ingredient, ButtonGrid>
102 {
103 onInstantiate = delegate(Recipe.Ingredient ingredient, ButtonGrid b)
104 {
105 List<Thing> things;
106 if (ingredient.id.IsEmpty())
107 {
108 b.SetIngredient(recipe, ingredient);
109 }
110 else
111 {
112 bool flag = false;
113 List<int> list = EMono.player.recipes.lastIngredients.TryGetValue(recipe.id);
114 int num2 = recipe.ingredients.IndexOf(ingredient);
115 if (num2 != -1 && list != null && list.Count > num2)
116 {
117 int uid = list[num2];
118 if (uid != 0)
119 {
120 Thing thing = EMono.pc.things.Find((Thing t) => t.uid == uid) ?? EMono._map.Stocked.Find(uid);
121 if (thing != null && ingredient.IsValidIngredient(thing) && (!(thing.parent is Card card) || card.GetWindowSaveData() == null || !card.GetWindowSaveData().excludeCraft))
122 {
123 ingredient.SetThing(thing);
124 flag = true;
125 }
126 }
127 }
128 if (!flag)
129 {
130 things = ListIngredients(ingredient, searchMode);
131 if (things.Count == 0)
132 {
133 if (EMono.debug.godBuild && ingredient.thing == null)
134 {
135 Thing thing2 = ThingGen.Create(ingredient.IdThing, recipe.DefaultMaterial.alias).SetNum(99);
136 things.Add(thing2);
137 ingredient.SetThing(thing2);
138 }
139 else
140 {
141 ingredient.SetThing();
142 things.Insert(0, null);
143 }
144 }
145 else if (!ingredient.optional)
146 {
147 if (ingredient.thing == null)
148 {
149 int num3 = lastMats.TryGetValue(recipe.id, -1);
150 if (num3 != -1)
151 {
152 foreach (Thing item in things)
153 {
154 if (item.material.id == num3 && item.Num >= ingredient.req)
155 {
156 ingredient.SetThing(item);
157 break;
158 }
159 }
160 if (ingredient.thing == null && EMono.debug.godBuild)
161 {
162 Thing thing3 = ThingGen.Create(ingredient.id, num3).SetNum(999);
163 EMono.pc.AddThing(thing3);
164 ingredient.SetThing(thing3);
165 }
166 }
167 if (ingredient.thing == null)
168 {
169 SourceMaterial.Row defaultMaterial = recipe.DefaultMaterial;
170 foreach (Thing item2 in things)
171 {
172 if (item2.material.id == defaultMaterial.id && item2.Num >= ingredient.req)
173 {
174 ingredient.SetThing(item2);
175 break;
176 }
177 }
178 if (EMono.debug.godBuild && ingredient.thing == null)
179 {
180 Thing thing4 = (ingredient.useCat ? ThingGen.CreateFromCategory(ingredient.id) : ThingGen.Create(ingredient.id, defaultMaterial.alias)).SetNum(99);
181 things.Add(thing4);
182 ingredient.SetThing(thing4);
183 }
184 }
185 if (ingredient.thing == null)
186 {
187 ingredient.SetThing(FindMax());
188 }
189 }
190 else
191 {
192 bool flag2 = true;
193 foreach (Thing item3 in things)
194 {
195 if (ingredient.thing == item3)
196 {
197 flag2 = false;
198 break;
199 }
200 }
201 if (flag2 && ingredient.thing == null)
202 {
203 ingredient.SetThing(FindMax());
204 }
205 }
206 }
207 }
208 b.SetIngredient(recipe, ingredient);
209 b.onClick.RemoveAllListeners();
210 b.onClick.AddListener(delegate
211 {
212 List<Thing> list2 = ListIngredients(ingredient, searchMode);
213 if (list2.Count == 0 || list2[0] == null)
214 {
215 SE.Beep();
216 }
217 else if ((bool)rectDrop)
218 {
219 Activate(ingredient, list2);
220 }
221 });
222 }
223 Thing FindMax()
224 {
225 if (things.Count == 0)
226 {
227 return null;
228 }
229 int num4 = 0;
230 Thing result = null;
231 foreach (Thing item4 in things)
232 {
233 if (item4.Num > num4)
234 {
235 num4 = item4.Num;
236 result = item4;
237 }
238 }
239 return result;
240 }
241 },
242 onRedraw = delegate(Recipe.Ingredient a, ButtonGrid b, int i)
243 {
244 b.SetIngredient(recipe, a);
245 }
246 };
247 for (int num = 0; num < slots; num++)
248 {
249 if (num < recipe.ingredients.Count)
250 {
252 continue;
253 }
255 {
256 id = ""
257 });
258 }
259 list.Refresh();
260 }
261
262 public void Redraw()
263 {
264 list.Redraw();
265 }
266
267 public void Activate(Recipe.Ingredient ingredient, List<Thing> things)
268 {
269 IsActive = true;
270 Instance = this;
271 rectDrop.SetActive(enable: true);
272 rectDrop.SetParent(EMono.ui.transform);
273 rectDrop.sizeDelta = new Vector2(0f, 0f);
274 rectDrop.anchoredPosition = Vector3.zero;
275 listDrop.callbacks = new UIList.Callback<Thing, ButtonGrid>
276 {
277 onClick = delegate(Thing a, ButtonGrid b)
278 {
279 SE.Resource();
280 ingredient.SetThing(a);
283 if (onValueChange != null)
284 {
286 }
287 Deactivate();
288 if ((bool)LayerCraft.Instance)
289 {
291 }
292 },
293 onInstantiate = delegate(Thing a, ButtonGrid b)
294 {
295 b.SetIngredient(recipe, a);
296 b.SetOnClick(delegate
297 {
298 });
299 b.onRightClick = delegate
300 {
301 };
302 }
303 };
304 listDrop.Clear();
305 foreach (Thing thing in things)
306 {
307 listDrop.Add(thing);
308 }
310 rectDropContent.position = list.transform.position + fixPos;
311 if (listDrop.items.Count == 0)
312 {
313 SE.Beep();
314 Deactivate();
315 }
316 else if ((bool)soundPop)
317 {
318 soundPop.Play();
319 }
320 }
321
322 public void OnChangeIngredient()
323 {
324 if (recipe == null)
325 {
326 return;
327 }
329 if ((bool)rectDrop)
330 {
331 if ((bool)icon)
332 {
334 }
335 list.Redraw();
336 }
337 }
338
339 public void Deactivate()
340 {
341 IsActive = false;
342 if (rectDrop != null)
343 {
344 rectDrop.SetActive(enable: false);
345 }
346 }
347
348 public void OnDestroy()
349 {
350 IsActive = false;
351 UnityEngine.Object.DestroyImmediate(rectDrop.gameObject);
352 }
353
354 public void TrySelect(int a)
355 {
356 ButtonGrid componentOf = InputModuleEX.GetComponentOf<ButtonGrid>();
357 if (!componentOf || componentOf.ing == null)
358 {
359 return;
360 }
361 Recipe.Ingredient ing = componentOf.ing;
362 List<Thing> list = ListIngredients(ing, searchMode);
363 int num = list.IndexOf(ing.thing);
364 if (num != -1)
365 {
366 SE.Resource();
367 num += a;
368 if (num < 0)
369 {
370 num = 0;
371 }
372 if (num >= list.Count)
373 {
374 num = list.Count - 1;
375 }
376 ing.SetThing(list[num]);
379 componentOf.ShowTooltip();
380 if ((bool)recipeInfo)
381 {
383 }
384 if ((bool)LayerCraft.Instance)
385 {
387 }
388 }
389 }
390
391 public void Next()
392 {
393 TrySelect(1);
394 }
395
396 public void Prev()
397 {
398 TrySelect(-1);
399 }
400}
StockSearchMode
void SetIngredient(Recipe r, Recipe.Ingredient _ing)
Definition: ButtonGrid.cs:442
Recipe.Ingredient ing
Definition: ButtonGrid.cs:22
Definition: Card.cs:11
SourceMaterial.Row material
Definition: Card.cs:2103
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3280
ICardParent parent
Definition: Card.cs:56
Thing SetNum(int a)
Definition: Card.cs:3676
int uid
Definition: Card.cs:125
ThingContainer things
Definition: Card.cs:39
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3257
int Num
Definition: Card.cs:161
bool godBuild
Definition: CoreDebug.cs:320
void OnDestroy()
UIRecipeInfo recipeInfo
Definition: DropdownGrid.cs:36
void BuildIngredients(Recipe _recipe, Image _icon, Action _onValueChange, StockSearchMode _searchMode)
Definition: DropdownGrid.cs:90
List< Thing > ListIngredients(Recipe.Ingredient ingredient, StockSearchMode searchMode)
Definition: DropdownGrid.cs:83
void Build(List< GridItem > items)
Definition: DropdownGrid.cs:51
Action onValueChange
Definition: DropdownGrid.cs:28
Recipe recipe
Definition: DropdownGrid.cs:22
void OnChangeIngredient()
StockSearchMode searchMode
Definition: DropdownGrid.cs:34
void Update()
Definition: DropdownGrid.cs:46
RectTransform rectDrop
Definition: DropdownGrid.cs:16
void Activate(Recipe.Ingredient ingredient, List< Thing > things)
void TrySelect(int a)
Vector3 fixPos
Definition: DropdownGrid.cs:32
Dictionary< string, int > lastMats
Definition: DropdownGrid.cs:39
SoundData soundPop
Definition: DropdownGrid.cs:26
static bool IsActive
Definition: DropdownGrid.cs:8
void Awake()
Definition: DropdownGrid.cs:41
static DropdownGrid Instance
Definition: DropdownGrid.cs:10
void Deactivate()
UIList listDrop
Definition: DropdownGrid.cs:14
RectTransform rectDropContent
Definition: DropdownGrid.cs:18
RectTransform pivot
Definition: DropdownGrid.cs:20
Definition: EMono.cs:4
static Chara pc
Definition: EMono.cs:13
static Player player
Definition: EMono.cs:11
static UI ui
Definition: EMono.cs:15
static Map _map
Definition: EMono.cs:17
static CoreDebug debug
Definition: EMono.cs:45
virtual void SetButton(ButtonGrid b)
Definition: GridItem.cs:3
virtual void OnClick(ButtonGrid b)
Definition: GridItem.cs:8
void OnChangeIngredient()
Definition: LayerCraft.cs:406
static LayerCraft Instance
Definition: LayerCraft.cs:8
void RefreshProduct()
Definition: LayerCraft.cs:455
PropsStocked Stocked
Definition: Map.cs:126
RecipeManager recipes
Definition: Player.cs:1167
Thing Find(int uid)
Definition: Props.cs:395
ThingStack ListThingStack(Recipe.Ingredient ing, StockSearchMode searchMode)
Definition: Props.cs:204
Dictionary< string, List< int > > lastIngredients
void SetThing(Thing t=null)
Definition: Recipe.cs:98
Definition: Recipe.cs:7
string id
Definition: Recipe.cs:178
SourceMaterial.Row DefaultMaterial
Definition: Recipe.cs:206
virtual RenderRow renderRow
Definition: Recipe.cs:210
void SaveLastIngredients()
Definition: Recipe.cs:1027
List< Ingredient > ingredients
Definition: Recipe.cs:181
virtual void OnChangeIngredient()
Definition: Recipe.cs:562
int idSkin
Definition: Recipe.cs:198
virtual SourceMaterial.Row GetColorMaterial()
Definition: Recipe.cs:506
int GetColorInt(SourceMaterial.Row mat)
Definition: RenderRow.cs:459
void SetImage(Image image, Sprite sprite=null, int matCol=0, bool setNativeSize=true, int dir=0, int idSkin=0, Card card=null)
Definition: RenderRow.cs:381
Thing Find(int uid)
static Thing CreateFromCategory(string idCat, int lv=-1)
Definition: ThingGen.cs:75
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
List< Thing > list
Definition: ThingStack.cs:5
Definition: Thing.cs:8
bool IsValidIngredient(Recipe.Ingredient ing)
Definition: Thing.cs:1860
void ResetTooltips()
static TooltipManager Instance
virtual void ShowTooltip()
Definition: UIButton.cs:379
Definition: UIList.cs:9
List< object > items
Definition: UIList.cs:273
override void Clear()
Definition: UIList.cs:404
SortMode
Definition: UIList.cs:27
override void Add(object item)
Definition: UIList.cs:357
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:479
override void Redraw()
Definition: UIList.cs:796
void RefreshImages()