Elin Modding Docs Doc
Loading...
Searching...
No Matches
DropdownGrid.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6// Token: 0x0200050C RID: 1292
7public class DropdownGrid : EMono
8{
9 // Token: 0x06002290 RID: 8848 RVA: 0x000C04C1 File Offset: 0x000BE6C1
10 private void Awake()
11 {
12 this.rectDrop.SetActive(false);
13 }
14
15 // Token: 0x06002291 RID: 8849 RVA: 0x000C04CF File Offset: 0x000BE6CF
16 private void Update()
17 {
18 this.rectDrop.SetActive(DropdownGrid.IsActive);
19 }
20
21 // Token: 0x06002292 RID: 8850 RVA: 0x000C04E4 File Offset: 0x000BE6E4
22 public void Build(List<GridItem> items)
23 {
24 this.list.Clear();
25 BaseList baseList = this.list;
26 UIList.Callback<GridItem, ButtonGrid> callback = new UIList.Callback<GridItem, ButtonGrid>();
27 callback.onInstantiate = delegate(GridItem a, ButtonGrid b)
28 {
29 a.SetButton(b);
30 };
31 callback.onClick = delegate(GridItem a, ButtonGrid b)
32 {
33 a.OnClick(b);
34 };
35 callback.onRedraw = delegate(GridItem a, ButtonGrid b, int i)
36 {
37 a.SetButton(b);
38 };
39 baseList.callbacks = callback;
40 for (int j = 0; j < this.slots; j++)
41 {
42 if (j < items.Count)
43 {
44 this.list.Add(items[j]);
45 }
46 else
47 {
48 this.list.Add(new GridItem());
49 }
50 }
51 this.list.Refresh(false);
52 }
53
54 // Token: 0x06002293 RID: 8851 RVA: 0x000C05C5 File Offset: 0x000BE7C5
55 public List<Thing> ListIngredients(Recipe.Ingredient ingredient, StockSearchMode searchMode)
56 {
57 return EMono._map.Stocked.ListThingStack(ingredient, searchMode).list;
58 }
59
60 // Token: 0x06002294 RID: 8852 RVA: 0x000C05E0 File Offset: 0x000BE7E0
61 public void BuildIngredients(Recipe _recipe, Image _icon, Action _onValueChange, StockSearchMode _searchMode)
62 {
63 this.recipe = _recipe;
64 this.icon = _icon;
65 this.list.Clear();
66 this.onValueChange = _onValueChange;
67 this.searchMode = _searchMode;
68 if (this.recipe == null)
69 {
70 return;
71 }
72 this.list.callbacks = new UIList.Callback<Recipe.Ingredient, ButtonGrid>
73 {
74 onInstantiate = delegate(Recipe.Ingredient ingredient, ButtonGrid b)
75 {
76 if (ingredient.id.IsEmpty())
77 {
78 b.SetIngredient(this.recipe, ingredient);
79 return;
80 }
81 List<Thing> things = this.ListIngredients(ingredient, this.searchMode);
82 if (things.Count == 0)
83 {
84 if (EMono.debug.godBuild && ingredient.thing == null)
85 {
86 Thing thing = ThingGen.Create(ingredient.IdThing, this.recipe.DefaultMaterial.alias).SetNum(99);
87 things.Add(thing);
88 ingredient.SetThing(thing);
89 }
90 else
91 {
92 ingredient.SetThing(null);
93 things.Insert(0, null);
94 }
95 }
96 else if (!ingredient.optional)
97 {
98 if (ingredient.thing == null)
99 {
100 int num = this.lastMats.TryGetValue(this.recipe.id, -1);
101 if (num != -1)
102 {
103 foreach (Thing thing2 in things)
104 {
105 if (thing2.material.id == num && thing2.Num >= ingredient.req)
106 {
107 ingredient.SetThing(thing2);
108 break;
109 }
110 }
111 }
112 if (ingredient.thing == null)
113 {
114 SourceMaterial.Row defaultMaterial = this.recipe.DefaultMaterial;
115 foreach (Thing thing3 in things)
116 {
117 if (thing3.material.id == defaultMaterial.id && thing3.Num >= ingredient.req)
118 {
119 ingredient.SetThing(thing3);
120 break;
121 }
122 }
123 if (EMono.debug.godBuild && ingredient.thing == null)
124 {
125 Thing thing4 = (ingredient.useCat ? ThingGen.CreateFromCategory(ingredient.id, -1) : ThingGen.Create(ingredient.id, defaultMaterial.alias)).SetNum(99);
126 things.Add(thing4);
127 ingredient.SetThing(thing4);
128 }
129 }
130 if (ingredient.thing == null)
131 {
132 ingredient.SetThing(things[0]);
133 }
134 }
135 else
136 {
137 bool flag = true;
138 foreach (Thing thing5 in things)
139 {
140 if (ingredient.thing == thing5)
141 {
142 flag = false;
143 break;
144 }
145 }
146 if (flag)
147 {
148 ingredient.SetThing(things[0]);
149 }
150 }
151 }
152 b.SetIngredient(this.recipe, ingredient);
153 b.onClick.RemoveAllListeners();
154 b.onClick.AddListener(delegate()
155 {
156 things = this.ListIngredients(ingredient, this.searchMode);
157 if (ingredient.optional)
158 {
159 if (things.Count == 0 || things[0] == null)
160 {
161 SE.Beep();
162 return;
163 }
164 }
165 else if (ingredient.thing == null)
166 {
167 SE.Beep();
168 return;
169 }
170 if (this.rectDrop)
171 {
172 this.Activate(ingredient, things);
173 this.rectDropContent.position = this.list.transform.position + this.fixPos;
174 }
175 });
176 },
177 onRedraw = delegate(Recipe.Ingredient a, ButtonGrid b, int i)
178 {
179 b.SetIngredient(this.recipe, a);
180 }
181 };
182 for (int j = 0; j < this.slots; j++)
183 {
184 if (j < this.recipe.ingredients.Count)
185 {
186 this.list.Add(this.recipe.ingredients[j]);
187 }
188 else
189 {
190 this.list.Add(new Recipe.Ingredient
191 {
192 id = ""
193 });
194 }
195 }
196 this.list.Refresh(false);
197 }
198
199 // Token: 0x06002295 RID: 8853 RVA: 0x000C06BB File Offset: 0x000BE8BB
200 public void Redraw()
201 {
202 this.list.Redraw();
203 }
204
205 // Token: 0x06002296 RID: 8854 RVA: 0x000C06C8 File Offset: 0x000BE8C8
206 public void Activate(Recipe.Ingredient ingredient, List<Thing> things)
207 {
208 if (this.soundPop)
209 {
210 this.soundPop.Play();
211 }
212 DropdownGrid.IsActive = true;
213 DropdownGrid.Instance = this;
214 this.rectDrop.SetActive(true);
215 this.rectDrop.SetParent(EMono.ui.transform);
216 this.rectDrop.sizeDelta = new Vector2(0f, 0f);
217 this.rectDrop.anchoredPosition = Vector3.zero;
218 this.listDrop.callbacks = new UIList.Callback<Thing, ButtonGrid>
219 {
220 onClick = delegate(Thing a, ButtonGrid b)
221 {
222 SE.Resource();
223 ingredient.SetThing(a);
224 this.OnChangeIngredient();
225 if (this.onValueChange != null)
226 {
227 this.onValueChange();
228 }
229 this.Deactivate();
230 if (LayerCraft.Instance)
231 {
232 LayerCraft.Instance.OnChangeIngredient();
233 }
234 },
235 onInstantiate = delegate(Thing a, ButtonGrid b)
236 {
237 b.SetIngredient(this.recipe, a);
238 }
239 };
240 this.listDrop.Clear();
241 foreach (Thing o in things)
242 {
243 this.listDrop.Add(o);
244 }
245 this.listDrop.Refresh(false);
246 }
247
248 // Token: 0x06002297 RID: 8855 RVA: 0x000C07F0 File Offset: 0x000BE9F0
249 public void OnChangeIngredient()
250 {
251 if (this.recipe == null)
252 {
253 return;
254 }
255 this.recipe.OnChangeIngredient();
256 if (!this.rectDrop)
257 {
258 return;
259 }
260 if (this.icon)
261 {
262 this.recipe.renderRow.SetImage(this.icon, null, this.recipe.renderRow.GetColorInt(this.recipe.GetColorMaterial()), true, 0, this.recipe.idSkin);
263 }
264 this.list.Redraw();
265 }
266
267 // Token: 0x06002298 RID: 8856 RVA: 0x000C0876 File Offset: 0x000BEA76
268 public void Deactivate()
269 {
270 DropdownGrid.IsActive = false;
271 if (this.rectDrop != null)
272 {
273 this.rectDrop.SetActive(false);
274 }
275 }
276
277 // Token: 0x06002299 RID: 8857 RVA: 0x000C0898 File Offset: 0x000BEA98
278 public void OnDestroy()
279 {
280 DropdownGrid.IsActive = false;
281 UnityEngine.Object.DestroyImmediate(this.rectDrop.gameObject);
282 }
283
284 // Token: 0x0600229A RID: 8858 RVA: 0x000C08B0 File Offset: 0x000BEAB0
285 public void TrySelect(int a)
286 {
287 ButtonGrid componentOf = InputModuleEX.GetComponentOf<ButtonGrid>();
288 if (!componentOf || componentOf.ing == null)
289 {
290 return;
291 }
292 Recipe.Ingredient ing = componentOf.ing;
293 List<Thing> list = EMono._map.Stocked.ListThingStack(ing, this.searchMode).list;
294 int num = list.IndexOf(ing.thing);
295 if (num == -1)
296 {
297 return;
298 }
299 SE.Resource();
300 num += a;
301 if (num < 0)
302 {
303 num = 0;
304 }
305 if (num >= list.Count)
306 {
307 num = list.Count - 1;
308 }
309 ing.SetThing(list[num]);
310 this.OnChangeIngredient();
311 TooltipManager.Instance.ResetTooltips();
312 componentOf.ShowTooltip();
313 if (this.recipeInfo)
314 {
315 this.recipeInfo.RefreshImages();
316 }
317 if (LayerCraft.Instance)
318 {
319 LayerCraft.Instance.RefreshProduct();
320 }
321 }
322
323 // Token: 0x0600229B RID: 8859 RVA: 0x000C097B File Offset: 0x000BEB7B
324 public void Next()
325 {
326 this.TrySelect(1);
327 }
328
329 // Token: 0x0600229C RID: 8860 RVA: 0x000C0984 File Offset: 0x000BEB84
330 public void Prev()
331 {
332 this.TrySelect(-1);
333 }
334
335 // Token: 0x040011E4 RID: 4580
336 public static bool IsActive;
337
338 // Token: 0x040011E5 RID: 4581
339 public static DropdownGrid Instance;
340
341 // Token: 0x040011E6 RID: 4582
342 public UIList list;
343
344 // Token: 0x040011E7 RID: 4583
345 public UIList listDrop;
346
347 // Token: 0x040011E8 RID: 4584
348 public RectTransform rectDrop;
349
350 // Token: 0x040011E9 RID: 4585
351 public RectTransform rectDropContent;
352
353 // Token: 0x040011EA RID: 4586
354 public RectTransform pivot;
355
356 // Token: 0x040011EB RID: 4587
357 public Recipe recipe;
358
359 // Token: 0x040011EC RID: 4588
360 public Image icon;
361
362 // Token: 0x040011ED RID: 4589
363 public SoundData soundPop;
364
365 // Token: 0x040011EE RID: 4590
366 public Action onValueChange;
367
368 // Token: 0x040011EF RID: 4591
369 public int slots = 4;
370
371 // Token: 0x040011F0 RID: 4592
372 public Vector3 fixPos;
373
374 // Token: 0x040011F1 RID: 4593
375 public StockSearchMode searchMode;
376
377 // Token: 0x040011F2 RID: 4594
378 public UIRecipeInfo recipeInfo;
379
380 // Token: 0x040011F3 RID: 4595
381 [NonSerialized]
382 public Dictionary<string, int> lastMats = new Dictionary<string, int>();
383}
Definition EMono.cs:6
Definition Thing.cs:10