Elin Decompiled Documentation EA 23.259 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 if (ingredient.thing == null && EMono.debug.godBuild)
159 {
160 Thing thing3 = ThingGen.Create(ingredient.id, num2).SetNum(999);
161 EMono.pc.AddThing(thing3);
162 ingredient.SetThing(thing3);
163 }
164 }
165 if (ingredient.thing == null)
166 {
167 SourceMaterial.Row defaultMaterial = recipe.DefaultMaterial;
168 foreach (Thing item2 in things)
169 {
170 if (item2.material.id == defaultMaterial.id && item2.Num >= ingredient.req)
171 {
172 ingredient.SetThing(item2);
173 break;
174 }
175 }
176 if (EMono.debug.godBuild && ingredient.thing == null)
177 {
178 Thing thing4 = (ingredient.useCat ? ThingGen.CreateFromCategory(ingredient.id) : ThingGen.Create(ingredient.id, defaultMaterial.alias)).SetNum(99);
179 things.Add(thing4);
180 ingredient.SetThing(thing4);
181 }
182 }
183 if (ingredient.thing == null)
184 {
185 ingredient.SetThing(FindMax());
186 }
187 }
188 else
189 {
190 bool flag2 = true;
191 foreach (Thing item3 in things)
192 {
193 if (ingredient.thing == item3)
194 {
195 flag2 = false;
196 break;
197 }
198 }
199 if (flag2 && ingredient.thing == null)
200 {
201 ingredient.SetThing(FindMax());
202 }
203 }
204 }
205 }
206 b.SetIngredient(recipe, ingredient);
207 b.onClick.RemoveAllListeners();
208 b.onClick.AddListener(delegate
209 {
210 List<Thing> list2 = ListIngredients(ingredient, searchMode);
211 if (list2.Count == 0 || list2[0] == null)
212 {
213 SE.Beep();
214 }
215 else if ((bool)rectDrop)
216 {
217 Activate(ingredient, list2);
218 }
219 });
220 }
221 Thing FindMax()
222 {
223 if (things.Count == 0)
224 {
225 return null;
226 }
227 int num3 = 0;
228 Thing result = null;
229 foreach (Thing item4 in things)
230 {
231 if (item4.Num > num3)
232 {
233 num3 = item4.Num;
234 result = item4;
235 }
236 }
237 return result;
238 }
239 },
240 onRedraw = delegate(Recipe.Ingredient a, ButtonGrid b, int i)
241 {
242 b.SetIngredient(recipe, a);
243 }
244 };
245 for (int j = 0; j < slots; j++)
246 {
247 if (j < recipe.ingredients.Count)
248 {
250 continue;
251 }
253 {
254 id = ""
255 });
256 }
257 list.Refresh();
258 }
259
260 public void Redraw()
261 {
262 list.Redraw();
263 }
264
265 public void Activate(Recipe.Ingredient ingredient, List<Thing> things)
266 {
267 IsActive = true;
268 Instance = this;
269 rectDrop.SetActive(enable: true);
270 rectDrop.SetParent(EMono.ui.transform);
271 rectDrop.sizeDelta = new Vector2(0f, 0f);
272 rectDrop.anchoredPosition = Vector3.zero;
273 listDrop.callbacks = new UIList.Callback<Thing, ButtonGrid>
274 {
275 onClick = delegate(Thing a, ButtonGrid b)
276 {
277 SE.Resource();
278 ingredient.SetThing(a);
281 if (onValueChange != null)
282 {
284 }
285 Deactivate();
286 if ((bool)LayerCraft.Instance)
287 {
289 }
290 },
291 onInstantiate = delegate(Thing a, ButtonGrid b)
292 {
293 b.SetIngredient(recipe, a);
294 b.SetOnClick(delegate
295 {
296 });
297 b.onRightClick = delegate
298 {
299 };
300 }
301 };
302 listDrop.Clear();
303 foreach (Thing thing in things)
304 {
305 listDrop.Add(thing);
306 }
308 rectDropContent.position = list.transform.position + fixPos;
309 if (listDrop.items.Count == 0)
310 {
311 SE.Beep();
312 Deactivate();
313 }
314 else if ((bool)soundPop)
315 {
316 soundPop.Play();
317 }
318 }
319
320 public void OnChangeIngredient()
321 {
322 if (recipe == null)
323 {
324 return;
325 }
327 if ((bool)rectDrop)
328 {
329 if ((bool)icon)
330 {
332 }
333 list.Redraw();
334 }
335 }
336
337 public void Deactivate()
338 {
339 IsActive = false;
340 if (rectDrop != null)
341 {
342 rectDrop.SetActive(enable: false);
343 }
344 }
345
346 public void OnDestroy()
347 {
348 IsActive = false;
349 UnityEngine.Object.DestroyImmediate(rectDrop.gameObject);
350 }
351
352 public void TrySelect(int a)
353 {
354 ButtonGrid componentOf = InputModuleEX.GetComponentOf<ButtonGrid>();
355 if (!componentOf || componentOf.ing == null)
356 {
357 return;
358 }
359 Recipe.Ingredient ing = componentOf.ing;
360 List<Thing> list = EMono._map.Stocked.ListThingStack(ing, searchMode).list;
361 int num = list.IndexOf(ing.thing);
362 if (num != -1)
363 {
364 SE.Resource();
365 num += a;
366 if (num < 0)
367 {
368 num = 0;
369 }
370 if (num >= list.Count)
371 {
372 num = list.Count - 1;
373 }
374 ing.SetThing(list[num]);
377 componentOf.ShowTooltip();
378 if ((bool)recipeInfo)
379 {
381 }
382 if ((bool)LayerCraft.Instance)
383 {
385 }
386 }
387 }
388
389 public void Next()
390 {
391 TrySelect(1);
392 }
393
394 public void Prev()
395 {
396 TrySelect(-1);
397 }
398}
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:2052
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3123
ICardParent parent
Definition: Card.cs:56
Thing SetNum(int a)
Definition: Card.cs:3520
int uid
Definition: Card.cs:123
ThingContainer things
Definition: Card.cs:39
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3100
int Num
Definition: Card.cs:159
bool godBuild
Definition: CoreDebug.cs:304
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:1097
Thing Find(int uid)
Definition: Props.cs:389
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:992
List< Ingredient > ingredients
Definition: Recipe.cs:181
virtual void OnChangeIngredient()
Definition: Recipe.cs:549
int idSkin
Definition: Recipe.cs:198
virtual SourceMaterial.Row GetColorMaterial()
Definition: Recipe.cs:498
int GetColorInt(SourceMaterial.Row mat)
Definition: RenderRow.cs:429
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:351
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:1794
void ResetTooltips()
static TooltipManager Instance
virtual void ShowTooltip()
Definition: UIButton.cs:379
Definition: UIList.cs:9
List< object > items
Definition: UIList.cs:272
override void Clear()
Definition: UIList.cs:400
override void Add(object item)
Definition: UIList.cs:353
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:475
override void Redraw()
Definition: UIList.cs:791
void RefreshImages()