Elin Modding Docs Doc
Loading...
Searching...
No Matches
LayerCraft.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5using UnityEngine.UI;
6
7// Token: 0x02000533 RID: 1331
9{
10 // Token: 0x060023FC RID: 9212 RVA: 0x000CA6E3 File Offset: 0x000C88E3
11 public override void RefreshCurrentGrid()
12 {
13 this.RefreshRecipe(true);
14 }
15
16 // Token: 0x060023FD RID: 9213 RVA: 0x000CA6EC File Offset: 0x000C88EC
17 public override void ClearButtons()
18 {
19 this.RefreshRecipe(true);
20 }
21
22 // Token: 0x060023FE RID: 9214 RVA: 0x000CA6F5 File Offset: 0x000C88F5
23 public override string GetTextHeader(Window window)
24 {
25 return null;
26 }
27
28 // Token: 0x060023FF RID: 9215 RVA: 0x000CA6F8 File Offset: 0x000C88F8
29 public override void OnAfterInit()
30 {
31 this.info1.searchMode = StockSearchMode.AroundPC;
32 this.info1.ddList.pivot.SetActive(true);
33 LayerCraft.Instance = this;
34 }
35
36 // Token: 0x06002400 RID: 9216 RVA: 0x000CA722 File Offset: 0x000C8922
37 public override void OnKill()
38 {
39 if (this.workbenchCrafted)
40 {
41 Tutorial.Play("middle_click");
42 }
43 if (this.pickaxeCrafted)
44 {
45 Tutorial.Play("hardness");
46 }
47 }
48
49 // Token: 0x06002401 RID: 9217 RVA: 0x000CA748 File Offset: 0x000C8948
50 public void SetFactory(Thing t)
51 {
52 this.factory = t;
53 this.RefreshCategory("all");
54 bool flag = t != null && t.trait.IsRequireFuel;
55 this.transFuel.SetActive(flag);
56 if (flag)
57 {
58 Action <>9__2;
59 this.buttonRefuel.SetOnClick(delegate
60 {
61 foreach (Window window in this.windows)
62 {
63 window.SetInteractable(false, 0f);
64 }
65 Layer layer = LayerDragGrid.Create(new InvOwnerRefuel(t, null, CurrencyType.None), false);
66 Action onKill;
67 if ((onKill = <>9__2) == null)
68 {
69 onKill = (<>9__2 = delegate()
70 {
71 if (!this.isDestroyed)
72 {
73 this.OnEndCraft();
74 }
75 });
76 }
77 layer.SetOnKill(onKill);
78 });
79 this.buttonAutoRefuel.SetOnClick(delegate
80 {
81 SE.Click();
82 t.autoRefuel = !t.autoRefuel;
83 this.RefreshProduct();
84 });
85 }
86 }
87
88 // Token: 0x06002402 RID: 9218 RVA: 0x000CA7DC File Offset: 0x000C89DC
89 public void OnClickCraft()
90 {
91 Dictionary<Thing, int> dictionary = new Dictionary<Thing, int>();
92 foreach (Recipe.Ingredient ingredient in this.recipe.ingredients)
93 {
94 if (ingredient.thing != null)
95 {
96 if (!dictionary.ContainsKey(ingredient.thing))
97 {
98 dictionary.Add(ingredient.thing, 0);
99 }
100 Dictionary<Thing, int> dictionary2 = dictionary;
101 Thing thing = ingredient.thing;
102 dictionary2[thing] += ingredient.req * this.inputNum.Num;
103 }
104 }
105 foreach (KeyValuePair<Thing, int> keyValuePair in dictionary)
106 {
107 if (keyValuePair.Key.Num < keyValuePair.Value)
108 {
109 SE.Beep();
110 Msg.Say("craftDupError");
111 return;
112 }
113 }
114 if (this.inputNum.Num == 0)
115 {
116 SE.Beep();
117 return;
118 }
119 Thing thing2 = this.factory;
120 TraitCrafter traitCrafter = ((thing2 != null) ? thing2.trait : null) as TraitCrafter;
121 if (traitCrafter == null)
122 {
123 traitCrafter = Trait.SelfFactory;
124 traitCrafter.owner = ELayer.pc;
125 }
126 (traitCrafter as TraitFactory).recipe = this.recipe;
127 string id = this.recipe.id;
128 if (!(id == "workbench"))
129 {
130 if (id == "axe" || id == "hammer" || id == "pickaxe")
131 {
132 this.pickaxeCrafted = true;
133 }
134 }
135 else
136 {
137 this.workbenchCrafted = true;
138 }
139 ELayer.pc.SetAI(new AI_UseCrafter
140 {
141 crafter = traitCrafter,
142 layer = this,
143 recipe = this.recipe,
144 num = this.inputNum.Num
145 });
146 ActionMode.Adv.SetTurbo(-1);
147 base.gameObject.SetActive(false);
148 }
149
150 // Token: 0x06002403 RID: 9219 RVA: 0x000CA9E4 File Offset: 0x000C8BE4
151 public override List<Thing> GetTargets()
152 {
153 List<Thing> list = new List<Thing>();
154 foreach (Recipe.Ingredient ingredient in this.recipe.ingredients)
155 {
156 if (!ingredient.optional || (ingredient.thing != null && !ingredient.thing.isDestroyed))
157 {
158 list.Add(ingredient.thing);
159 }
160 }
161 return list;
162 }
163
164 // Token: 0x06002404 RID: 9220 RVA: 0x000CAA68 File Offset: 0x000C8C68
165 public override int GetReqIngredient(int index)
166 {
167 return this.recipe.ingredients[index].req * this.inputNum.Num;
168 }
169
170 // Token: 0x06002405 RID: 9221 RVA: 0x000CAA8C File Offset: 0x000C8C8C
171 public override void OnEndCraft()
172 {
173 this.OnCompleteCraft();
174 }
175
176 // Token: 0x06002406 RID: 9222 RVA: 0x000CAA94 File Offset: 0x000C8C94
177 public void OnCompleteCraft()
178 {
179 base.CancelInvoke("WaitUntilIdle");
180 EInput.haltInput = true;
181 TweenUtil.Tween(this.waitComplete, null, delegate()
182 {
183 EInput.haltInput = false;
184 base.gameObject.SetActive(true);
185 foreach (Window window in this.windows)
186 {
187 window.SetInteractable(true, 0.5f);
188 }
189 this.list.Redraw();
190 this.RefreshRecipe(true);
191 this.windowList.groupTab.RefreshButtons();
192 this.list.Select<Recipe>((Recipe r) => this.recipe.id == r.id, false);
193 });
194 }
195
196 // Token: 0x06002407 RID: 9223 RVA: 0x000CAAC0 File Offset: 0x000C8CC0
197 public void WaitUntilIdle()
198 {
199 if (!ActionMode.Adv.IsActive || ELayer.pc.HasNoGoal)
200 {
201 base.CancelInvoke();
202 this.Close();
203 }
204 }
205
206 // Token: 0x06002408 RID: 9224 RVA: 0x000CAAE8 File Offset: 0x000C8CE8
207 private void Update()
208 {
209 float axis = Input.GetAxis("Mouse ScrollWheel");
210 if (Input.GetMouseButton(0))
211 {
212 this.wcount = 2;
213 }
214 if (axis != 0f)
215 {
216 this.wcount = 2;
217 return;
218 }
219 if (this.wcount > 0)
220 {
221 this.wcount--;
222 return;
223 }
224 this.RefreshInfo();
225 }
226
227 // Token: 0x06002409 RID: 9225 RVA: 0x000CAB3C File Offset: 0x000C8D3C
228 public void RefreshInfo()
229 {
230 ButtonGrid buttonGrid = InputModuleEX.GetComponentOf<ButtonGrid>();
231 if (buttonGrid && buttonGrid.recipe == null)
232 {
233 buttonGrid = null;
234 }
235 if (buttonGrid == this.lastB)
236 {
237 return;
238 }
239 this.lastB = buttonGrid;
240 }
241
242 // Token: 0x0600240A RID: 9226 RVA: 0x000CAB78 File Offset: 0x000C8D78
243 public void RefreshCategory(string cat)
244 {
245 Dictionary<string, int> cats = new Dictionary<string, int>();
246 RecipeManager.BuildList();
247 BaseList baseList = this.list;
248 UIList.Callback<Recipe, ButtonGrid> callback = new UIList.Callback<Recipe, ButtonGrid>();
249 callback.onClick = delegate(Recipe a, ButtonGrid b)
250 {
251 this.recipe = a;
252 SE.Play("click_recipe");
253 this.RefreshRecipe(true);
254 ELayer.player.recipes.hoveredRecipes.Add(a.id);
255 b.Dettach("recipe_new");
256 this.list.Select(a, false);
257 };
258 callback.onRedraw = delegate(Recipe a, ButtonGrid b, int i)
259 {
260 if (a.ingredients.Count == 0)
261 {
262 a.BuildIngredientList();
263 }
264 b.SetCraftRecipe(a, ButtonGrid.Mode.Recipe, false);
265 if (!ELayer.player.recipes.hoveredRecipes.Contains(a.id))
266 {
267 b.Attach("recipe_new", false);
268 }
269 };
270 callback.onList = delegate(UIList.SortMode m)
271 {
272 this.newRecipes.Clear();
273 foreach (RecipeSource recipeSource in ELayer.player.recipes.ListSources(this.factory, this.newRecipes))
274 {
275 if (cat == "all" || recipeSource.row.Category.IsChildOf(cat))
276 {
277 Recipe o = Recipe.Create(recipeSource, -1, null);
278 this.list.Add(o);
279 }
280 SourceCategory.Row row = recipeSource.row.Category.GetSecondRoot();
281 if (row.id != "lightsource" && row.IsChildOf("armor"))
282 {
283 row = ELayer.sources.categories.map["armor"];
284 }
285 Dictionary<string, int> cats;
286 if (!cats.ContainsKey(row.id))
287 {
288 cats.Add(row.id, 1);
289 }
290 else
291 {
292 cats = cats;
293 string id = row.id;
294 int num = cats[id];
295 cats[id] = num + 1;
296 }
297 }
298 this.list.objects.Sort((object a, object b) => (b as Recipe).GetSortVal() - (a as Recipe).GetSortVal());
299 int count = this.newRecipes.Count;
300 };
301 callback.onSort = ((Recipe a, UIList.SortMode m) => a.GetSortVal());
302 baseList.callbacks = callback;
303 this.list.sortMode = UIList.SortMode.ByLevel;
304 this.list.List();
305 if (cats.Count > 1 && !this.tabBuilt)
306 {
307 this.windowList.AddTab("all", null, delegate
308 {
309 this.RefreshCategory("all");
310 }, null, null);
311 using (Dictionary<string, int>.Enumerator enumerator = cats.GetEnumerator())
312 {
313 while (enumerator.MoveNext())
314 {
315 KeyValuePair<string, int> c = enumerator.Current;
316 this.windowList.AddTab(ELayer.sources.categories.map[c.Key].GetName() + "(" + c.Value.ToString() + ")", null, delegate
317 {
318 this.RefreshCategory(c.Key);
319 }, null, null);
320 }
321 }
322 this.tabBuilt = true;
323 this.windowList.BuildTabs(0);
324 }
325 this.list.Scroll(0);
326 if (this.list.rows.Count > 0)
327 {
328 this.list.Select(this.list.rows[0].objects[0], true);
329 }
330 }
331
332 // Token: 0x0600240B RID: 9227 RVA: 0x000CAD8C File Offset: 0x000C8F8C
333 public void OnChangeIngredient()
334 {
335 this.RefreshRecipe(true);
336 }
337
338 // Token: 0x0600240C RID: 9228 RVA: 0x000CAD98 File Offset: 0x000C8F98
339 public void RefreshRecipe(bool first)
340 {
341 foreach (Recipe.Ingredient ingredient in this.recipe.ingredients)
342 {
343 if (this.info1.recipe != this.recipe || (!ingredient.optional && (ingredient.thing == null || ingredient.thing.isDestroyed)))
344 {
345 ingredient.SetThing(null);
346 }
347 }
348 if (first)
349 {
350 this.toggleCraftTo.SetToggle(false, null);
351 this.toggleRepeat.SetToggle(false, null);
352 this.inputNum.Num = 1;
353 this.info1.recipe = null;
354 }
355 this.info1.factory = this.factory;
356 this.info1.SetRecipe(this.recipe);
357 this.recipe.OnChangeIngredient();
358 this.RefreshProduct();
359 }
360
361 // Token: 0x0600240D RID: 9229 RVA: 0x000CAE88 File Offset: 0x000C9088
362 public void RefreshInputNum()
363 {
364 this.inputNum.SetMinMax(1, this.recipe.GetMaxCount());
365 this.inputNum.onValueChanged = delegate(int n)
366 {
367 this.RefreshProduct();
368 };
369 this.inputNum.Validate();
370 }
371
372 // Token: 0x0600240E RID: 9230 RVA: 0x000CAEC4 File Offset: 0x000C90C4
373 public void RefreshProduct()
374 {
375 this.RefreshInputNum();
376 ELayer.screen.tileSelector.summary.countValid = this.inputNum.Num;
377 ELayer.screen.tileSelector.summary.factory = this.factory;
378 this.info1.RefreshBalance();
379 if (this.factory != null)
380 {
381 this.textFuel.text = "craftFuel".lang(((int)((float)this.factory.c_charges / (float)this.factory.trait.MaxFuel * 100f)).ToString() ?? "", null, null, null, null);
382 this.buttonAutoRefuel.mainText.text = (this.factory.autoRefuel ? "On" : "Off");
383 this.buttonAutoRefuel.icon.SetAlpha(this.factory.autoRefuel ? 1f : 0.4f);
384 }
385 this.RefreshQuality();
386 List<Thing> list = new List<Thing>();
387 foreach (Recipe.Ingredient ingredient in this.recipe.ingredients)
388 {
389 if (ingredient.thing != null)
390 {
391 list.Add(ingredient.thing);
392 }
393 }
394 Thing thing = this.recipe.Craft(BlessedState.Normal, false, list, true);
395 thing.SetNum(this.inputNum.Num);
396 if (thing.sockets != null)
397 {
398 thing.sockets.Clear();
399 }
400 if (thing.IsEquipmentOrRanged)
401 {
402 foreach (Element element in thing.elements.dict.Values.ToList<Element>())
403 {
404 if (!element.IsTrait)
405 {
406 thing.elements.Remove(element.id);
407 }
408 }
409 }
410 this.info1.buttonProduct.SetCard(thing, ButtonGrid.Mode.Default, null);
411 thing.WriteNote(this.info1.note, null, IInspect.NoteMode.Product, this.recipe);
412 this.product = thing;
413 }
414
415 // Token: 0x0600240F RID: 9231 RVA: 0x000CB108 File Offset: 0x000C9308
416 public bool IsQualityMet()
417 {
418 return true;
419 }
420
421 // Token: 0x06002410 RID: 9232 RVA: 0x000CB10B File Offset: 0x000C930B
422 public void RefreshQuality()
423 {
424 }
425
426 // Token: 0x06002411 RID: 9233 RVA: 0x000CB10D File Offset: 0x000C930D
427 public void OnClickExamine()
428 {
429 ELayer.ui.AddLayer<LayerInfo>().Set(this.product, false);
430 }
431
432 // Token: 0x04001376 RID: 4982
433 public static LayerCraft Instance;
434
435 // Token: 0x04001377 RID: 4983
436 public UIDynamicList list;
437
438 // Token: 0x04001378 RID: 4984
439 public UIRecipeInfo info1;
440
441 // Token: 0x04001379 RID: 4985
442 public UIRecipeInfo info2;
443
444 // Token: 0x0400137A RID: 4986
445 public Vector3 posInfo;
446
447 // Token: 0x0400137B RID: 4987
448 public Thing factory;
449
450 // Token: 0x0400137C RID: 4988
451 public Thing product;
452
453 // Token: 0x0400137D RID: 4989
454 public Recipe recipe;
455
456 // Token: 0x0400137E RID: 4990
457 public UIButton toggleRepeat;
458
459 // Token: 0x0400137F RID: 4991
460 public UIButton toggleCraftTo;
461
462 // Token: 0x04001380 RID: 4992
463 public UIInputText inputNum;
464
465 // Token: 0x04001381 RID: 4993
466 public UIInputText moldInputNum;
467
468 // Token: 0x04001382 RID: 4994
469 public List<RecipeSource> newRecipes = new List<RecipeSource>();
470
471 // Token: 0x04001383 RID: 4995
472 public Window windowList;
473
474 // Token: 0x04001384 RID: 4996
475 public bool showInfo;
476
477 // Token: 0x04001385 RID: 4997
478 private bool pickaxeCrafted;
479
480 // Token: 0x04001386 RID: 4998
481 private bool workbenchCrafted;
482
483 // Token: 0x04001387 RID: 4999
484 public UIButton buttonRefuel;
485
486 // Token: 0x04001388 RID: 5000
487 public UIButton buttonAutoRefuel;
488
489 // Token: 0x04001389 RID: 5001
490 public Transform transFuel;
491
492 // Token: 0x0400138A RID: 5002
493 public UIText textFuel;
494
495 // Token: 0x0400138B RID: 5003
496 public UIText textQualityInvalid;
497
498 // Token: 0x0400138C RID: 5004
499 public UIText textQualityValid;
500
501 // Token: 0x0400138D RID: 5005
502 public Image imageQualityReq;
503
504 // Token: 0x0400138E RID: 5006
505 public Image imageQualityCurrent;
506
507 // Token: 0x0400138F RID: 5007
508 public float waitComplete;
509
510 // Token: 0x04001390 RID: 5008
511 public float qualityBarWidth;
512
513 // Token: 0x04001391 RID: 5009
514 private int wcount;
515
516 // Token: 0x04001392 RID: 5010
517 public ButtonGrid lastB;
518
519 // Token: 0x04001393 RID: 5011
520 private bool tabBuilt;
521}
Definition Msg.cs:7
Definition Thing.cs:10
Definition Trait.cs:9