Elin Decompiled Documentation EA 23.102 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 j = 0; j < slots; j++)
70 {
71 if (j < items.Count)
72 {
73 list.Add(items[j]);
74 }
75 else
76 {
77 list.Add(new GridItem());
78 }
79 }
80 list.Refresh();
81 }
82
84 {
85 return EMono._map.Stocked.ListThingStack(ingredient, searchMode).list;
86 }
87
88 public void BuildIngredients(Recipe _recipe, Image _icon, Action _onValueChange, StockSearchMode _searchMode)
89 {
90 recipe = _recipe;
91 icon = _icon;
92 list.Clear();
93 onValueChange = _onValueChange;
94 searchMode = _searchMode;
95 if (recipe == null)
96 {
97 return;
98 }
99 list.callbacks = new UIList.Callback<Recipe.Ingredient, ButtonGrid>
100 {
101 onInstantiate = delegate(Recipe.Ingredient ingredient, ButtonGrid b)
102 {
103 List<Thing> things;
104 if (ingredient.id.IsEmpty())
105 {
106 b.SetIngredient(recipe, ingredient);
107 }
108 else
109 {
110 bool flag = false;
111 List<int> list = EMono.player.recipes.lastIngredients.TryGetValue(recipe.id);
112 int num = recipe.ingredients.IndexOf(ingredient);
113 if (num != -1 && list != null && list.Count > num)
114 {
115 int uid = list[num];
116 if (uid != 0)
117 {
118 Thing thing = EMono.pc.things.Find((Thing t) => t.uid == uid) ?? EMono._map.Stocked.Find(uid);
119 if (thing != null && ingredient.IsValidIngredient(thing) && (!(thing.parent is Card card) || card.GetWindowSaveData() == null || !card.GetWindowSaveData().excludeCraft))
120 {
121 ingredient.SetThing(thing);
122 flag = true;
123 }
124 }
125 }
126 if (!flag)
127 {
128 things = ListIngredients(ingredient, searchMode);
129 if (things.Count == 0)
130 {
131 if (EMono.debug.godBuild && ingredient.thing == null)
132 {
133 Thing thing2 = ThingGen.Create(ingredient.IdThing, recipe.DefaultMaterial.alias).SetNum(99);
134 things.Add(thing2);
135 ingredient.SetThing(thing2);
136 }
137 else
138 {
139 ingredient.SetThing();
140 things.Insert(0, null);
141 }
142 }
143 else if (!ingredient.optional)
144 {
145 if (ingredient.thing == null)
146 {
147 int num2 = lastMats.TryGetValue(recipe.id, -1);
148 if (num2 != -1)
149 {
150 foreach (Thing item in things)
151 {
152 if (item.material.id == num2 && item.Num >= ingredient.req)
153 {
154 ingredient.SetThing(item);
155 break;
156 }
157 }
158 }
159 if (ingredient.thing == null)
160 {
161 SourceMaterial.Row defaultMaterial = recipe.DefaultMaterial;
162 foreach (Thing item2 in things)
163 {
164 if (item2.material.id == defaultMaterial.id && item2.Num >= ingredient.req)
165 {
166 ingredient.SetThing(item2);
167 break;
168 }
169 }
170 if (EMono.debug.godBuild && ingredient.thing == null)
171 {
172 Thing thing3 = (ingredient.useCat ? ThingGen.CreateFromCategory(ingredient.id) : ThingGen.Create(ingredient.id, defaultMaterial.alias)).SetNum(99);
173 things.Add(thing3);
174 ingredient.SetThing(thing3);
175 }
176 }
177 if (ingredient.thing == null)
178 {
179 ingredient.SetThing(FindMax());
180 }
181 }
182 else
183 {
184 bool flag2 = true;
185 foreach (Thing item3 in things)
186 {
187 if (ingredient.thing == item3)
188 {
189 flag2 = false;
190 break;
191 }
192 }
193 if (flag2 && ingredient.thing == null)
194 {
195 ingredient.SetThing(FindMax());
196 }
197 }
198 }
199 }
200 b.SetIngredient(recipe, ingredient);
201 b.onClick.RemoveAllListeners();
202 b.onClick.AddListener(delegate
203 {
204 List<Thing> list2 = ListIngredients(ingredient, searchMode);
205 if (list2.Count == 0 || list2[0] == null)
206 {
207 SE.Beep();
208 }
209 else if ((bool)rectDrop)
210 {
211 Activate(ingredient, list2);
212 }
213 });
214 }
215 Thing FindMax()
216 {
217 if (things.Count == 0)
218 {
219 return null;
220 }
221 int num3 = 0;
222 Thing result = null;
223 foreach (Thing item4 in things)
224 {
225 if (item4.Num > num3)
226 {
227 num3 = item4.Num;
228 result = item4;
229 }
230 }
231 return result;
232 }
233 },
234 onRedraw = delegate(Recipe.Ingredient a, ButtonGrid b, int i)
235 {
236 b.SetIngredient(recipe, a);
237 }
238 };
239 for (int j = 0; j < slots; j++)
240 {
241 if (j < recipe.ingredients.Count)
242 {
244 continue;
245 }
247 {
248 id = ""
249 });
250 }
251 list.Refresh();
252 }
253
254 public void Redraw()
255 {
256 list.Redraw();
257 }
258
259 public void Activate(Recipe.Ingredient ingredient, List<Thing> things)
260 {
261 IsActive = true;
262 Instance = this;
263 rectDrop.SetActive(enable: true);
264 rectDrop.SetParent(EMono.ui.transform);
265 rectDrop.sizeDelta = new Vector2(0f, 0f);
266 rectDrop.anchoredPosition = Vector3.zero;
267 listDrop.callbacks = new UIList.Callback<Thing, ButtonGrid>
268 {
269 onClick = delegate(Thing a, ButtonGrid b)
270 {
271 SE.Resource();
272 ingredient.SetThing(a);
275 if (onValueChange != null)
276 {
278 }
279 Deactivate();
280 if ((bool)LayerCraft.Instance)
281 {
283 }
284 },
285 onInstantiate = delegate(Thing a, ButtonGrid b)
286 {
287 b.SetIngredient(recipe, a);
288 b.SetOnClick(delegate
289 {
290 });
291 b.onRightClick = delegate
292 {
293 };
294 }
295 };
296 listDrop.Clear();
297 foreach (Thing thing in things)
298 {
299 listDrop.Add(thing);
300 }
302 rectDropContent.position = list.transform.position + fixPos;
303 if (listDrop.items.Count == 0)
304 {
305 SE.Beep();
306 Deactivate();
307 }
308 else if ((bool)soundPop)
309 {
310 soundPop.Play();
311 }
312 }
313
314 public void OnChangeIngredient()
315 {
316 if (recipe == null)
317 {
318 return;
319 }
321 if ((bool)rectDrop)
322 {
323 if ((bool)icon)
324 {
326 }
327 list.Redraw();
328 }
329 }
330
331 public void Deactivate()
332 {
333 IsActive = false;
334 if (rectDrop != null)
335 {
336 rectDrop.SetActive(enable: false);
337 }
338 }
339
340 public void OnDestroy()
341 {
342 IsActive = false;
343 UnityEngine.Object.DestroyImmediate(rectDrop.gameObject);
344 }
345
346 public void TrySelect(int a)
347 {
348 ButtonGrid componentOf = InputModuleEX.GetComponentOf<ButtonGrid>();
349 if (!componentOf || componentOf.ing == null)
350 {
351 return;
352 }
353 Recipe.Ingredient ing = componentOf.ing;
354 List<Thing> list = EMono._map.Stocked.ListThingStack(ing, searchMode).list;
355 int num = list.IndexOf(ing.thing);
356 if (num != -1)
357 {
358 SE.Resource();
359 num += a;
360 if (num < 0)
361 {
362 num = 0;
363 }
364 if (num >= list.Count)
365 {
366 num = list.Count - 1;
367 }
368 ing.SetThing(list[num]);
371 componentOf.ShowTooltip();
372 if ((bool)recipeInfo)
373 {
375 }
376 if ((bool)LayerCraft.Instance)
377 {
379 }
380 }
381 }
382
383 public void Next()
384 {
385 TrySelect(1);
386 }
387
388 public void Prev()
389 {
390 TrySelect(-1);
391 }
392}
StockSearchMode
void SetIngredient(Recipe r, Recipe.Ingredient _ing)
Definition: ButtonGrid.cs:435
Recipe.Ingredient ing
Definition: ButtonGrid.cs:22
Definition: Card.cs:11
SourceMaterial.Row material
Definition: Card.cs:1927
ICardParent parent
Definition: Card.cs:51
Thing SetNum(int a)
Definition: Card.cs:3242
int uid
Definition: Card.cs:118
ThingContainer things
Definition: Card.cs:34
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:2878
int Num
Definition: Card.cs:154
bool godBuild
Definition: CoreDebug.cs:303
void OnDestroy()
UIRecipeInfo recipeInfo
Definition: DropdownGrid.cs:36
void BuildIngredients(Recipe _recipe, Image _icon, Action _onValueChange, StockSearchMode _searchMode)
Definition: DropdownGrid.cs:88
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:121
RecipeManager recipes
Definition: Player.cs:898
Thing Find(int uid)
Definition: Props.cs:357
ThingStack ListThingStack(Recipe.Ingredient ing, StockSearchMode searchMode)
Definition: Props.cs:204
Dictionary< string, List< int > > lastIngredients
void SetThing(Thing t=null)
Definition: Recipe.cs:89
Definition: Recipe.cs:7
string id
Definition: Recipe.cs:161
SourceMaterial.Row DefaultMaterial
Definition: Recipe.cs:189
virtual RenderRow renderRow
Definition: Recipe.cs:193
void SaveLastIngredients()
Definition: Recipe.cs:975
List< Ingredient > ingredients
Definition: Recipe.cs:164
virtual void OnChangeIngredient()
Definition: Recipe.cs:532
int idSkin
Definition: Recipe.cs:181
virtual SourceMaterial.Row GetColorMaterial()
Definition: Recipe.cs:481
int GetColorInt(SourceMaterial.Row mat)
Definition: RenderRow.cs:417
void SetImage(Image image, Sprite sprite=null, int matCol=0, bool setNativeSize=true, int dir=0, int idSkin=0)
Definition: RenderRow.cs:346
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:1670
void ResetTooltips()
static TooltipManager Instance
virtual void ShowTooltip()
Definition: UIButton.cs:379
Definition: UIList.cs:9
List< object > items
Definition: UIList.cs:241
override void Clear()
Definition: UIList.cs:349
override void Add(object item)
Definition: UIList.cs:302
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:424
override void Redraw()
Definition: UIList.cs:740
void RefreshImages()