Elin Modding Docs Doc
Loading...
Searching...
No Matches
LayerInventory.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5// Token: 0x0200057C RID: 1404
6public class LayerInventory : ELayer
7{
8 // Token: 0x06002676 RID: 9846 RVA: 0x000D8D98 File Offset: 0x000D6F98
9 public static LayerInventory GetTopLayer(Thing t, bool includePlayer = false, InvOwner exclude = null)
10 {
11 LayerInventory result = null;
12 int num = -1;
13 foreach (LayerInventory layerInventory in LayerInventory.listInv)
14 {
15 if (layerInventory.IsPlayerContainer(includePlayer) && layerInventory.Inv != exclude && !layerInventory.Inv.Container.IsToolbelt && !layerInventory.Inv.Container.things.IsFull(t, false, true))
16 {
17 int siblingIndex = layerInventory.transform.GetSiblingIndex();
18 if (siblingIndex > num)
19 {
20 num = siblingIndex;
21 result = layerInventory;
22 }
23 }
24 }
25 return result;
26 }
27
28 // Token: 0x06002677 RID: 9847 RVA: 0x000D8E40 File Offset: 0x000D7040
29 public static LayerInventory GetPCLayer()
30 {
31 LayerInventory result = null;
32 foreach (LayerInventory layerInventory in LayerInventory.listInv)
33 {
34 if (layerInventory.Inv.Container.IsPC)
35 {
36 return layerInventory;
37 }
38 }
39 return result;
40 }
41
42 // Token: 0x06002678 RID: 9848 RVA: 0x000D8EA8 File Offset: 0x000D70A8
43 public static void Close(Thing t)
44 {
45 foreach (LayerInventory layerInventory in LayerInventory.listInv)
46 {
47 if (layerInventory.invs[0].owner.Container == t)
48 {
49 layerInventory.Close();
50 break;
51 }
52 }
53 }
54
55 // Token: 0x06002679 RID: 9849 RVA: 0x000D8F14 File Offset: 0x000D7114
56 public static bool IsOpen(Thing t)
57 {
58 using (List<LayerInventory>.Enumerator enumerator = LayerInventory.listInv.GetEnumerator())
59 {
60 while (enumerator.MoveNext())
61 {
62 if (enumerator.Current.invs[0].owner.Container == t)
63 {
64 return true;
65 }
66 }
67 }
68 return false;
69 }
70
71 // Token: 0x0600267A RID: 9850 RVA: 0x000D8F80 File Offset: 0x000D7180
72 public static void SetDirty(Thing t)
73 {
74 if (!ELayer.game.altInv || t == null)
75 {
76 return;
77 }
78 foreach (LayerInventory layerInventory in LayerInventory.listInv)
79 {
80 if (layerInventory.invs[0].owner.Container == t.parent || (layerInventory.mini && layerInventory.mini.gameObject.activeInHierarchy))
81 {
82 layerInventory.invs[0].dirty = true;
83 }
84 }
85 if (t.invY == 1 || ELayer.pc.held == t)
86 {
87 WidgetCurrentTool.dirty = true;
88 }
89 if (t.isEquipped)
90 {
91 WidgetEquip.dirty = true;
92 }
93 }
94
95 // Token: 0x0600267B RID: 9851 RVA: 0x000D9054 File Offset: 0x000D7254
96 public static void SetDirtyAll(bool immediate = false)
97 {
98 foreach (LayerInventory layerInventory in LayerInventory.listInv)
99 {
100 layerInventory.invs[0].dirty = true;
101 if (immediate)
102 {
103 layerInventory.invs[0].CheckDirty();
104 }
105 }
106 if (WidgetEquip.Instance)
107 {
108 WidgetEquip.dirty = true;
109 if (immediate)
110 {
111 WidgetEquip.Instance.CheckDirty();
112 }
113 }
114 WidgetCurrentTool.dirty = true;
115 if (immediate)
116 {
117 WidgetCurrentTool.Instance.CheckDirty();
118 }
119 }
120
121 // Token: 0x0600267C RID: 9852 RVA: 0x000D90F8 File Offset: 0x000D72F8
122 public static void TryShowGuide(UIList list)
123 {
124 List<ButtonGrid> list2 = new List<ButtonGrid>();
125 foreach (UIList.ButtonPair buttonPair in list.buttons)
126 {
127 ButtonGrid buttonGrid = buttonPair.component as ButtonGrid;
128 if (buttonGrid)
129 {
130 list2.Add(buttonGrid);
131 }
132 }
133 LayerInventory.TryShowGuide(list2);
134 }
135
136 // Token: 0x0600267D RID: 9853 RVA: 0x000D916C File Offset: 0x000D736C
137 public static void TryShowGuide(List<ButtonGrid> list)
138 {
139 bool flag = InvOwner.HasTrader && InvOwner.Trader.UseGuide;
140 bool flag2 = WidgetSearch.Instance && WidgetSearch.selected != null;
141 if (!flag2 && WidgetEquip.dragEquip == null && LayerAbility.hotElement == null && !flag)
142 {
143 return;
144 }
145 foreach (ButtonGrid buttonGrid in list)
146 {
147 Thing thing = buttonGrid.card as Thing;
148 if (LayerAbility.hotElement != null)
149 {
150 if ((thing == null || thing.trait is TraitAbility) && buttonGrid.invOwner.owner == ELayer.pc && !(buttonGrid.invOwner is InvOwnerEquip))
151 {
152 buttonGrid.Attach("guide", false);
153 }
154 }
155 else if (WidgetEquip.dragEquip != null && !flag)
156 {
157 InvOwnerEquip invOwnerEquip = buttonGrid.invOwner as InvOwnerEquip;
158 if (invOwnerEquip != null && invOwnerEquip.slot.elementId == WidgetEquip.dragEquip.category.slot)
159 {
160 buttonGrid.Attach("guide", false);
161 }
162 }
163 else if (flag2)
164 {
165 if (buttonGrid.card == WidgetSearch.selected || buttonGrid.card == WidgetSearch.selected.parent)
166 {
167 buttonGrid.Attach("guide", false);
168 }
169 }
170 else if (thing != null)
171 {
172 bool show = InvOwner.Trader.ShouldShowGuide(thing);
173 if (!show && thing.CanSearchContents)
174 {
175 thing.things.Foreach(delegate(Thing _t)
176 {
177 if (!show && InvOwner.Trader.ShouldShowGuide(_t))
178 {
179 show = true;
180 }
181 }, true);
182 }
183 if (show)
184 {
185 buttonGrid.Attach("guide", false);
186 }
187 }
188 }
189 }
190
191 // Token: 0x17000B8B RID: 2955
192 // (get) Token: 0x0600267E RID: 9854 RVA: 0x000D9354 File Offset: 0x000D7554
193 public InvOwner Inv
194 {
195 get
196 {
197 return this.invs[0].tabs[0].owner;
198 }
199 }
200
201 // Token: 0x0600267F RID: 9855 RVA: 0x000D9374 File Offset: 0x000D7574
202 public bool IsPlayerContainer(bool includePlayer = false)
203 {
204 return this.invs[0].tabs[0].mode == UIInventory.Mode.All && (includePlayer || this.invs[0].owner.Container != ELayer.pc) && this.invs[0].owner.Container.GetRootCard() == ELayer.pc;
205 }
206
207 // Token: 0x06002680 RID: 9856 RVA: 0x000D93E8 File Offset: 0x000D75E8
208 public Card GetPlayerContainer()
209 {
210 UIInventory.Tab tab = this.invs[0].tabs[0];
211 if (!this.IsPlayerContainer(false))
212 {
213 return null;
214 }
215 return tab.owner.Container;
216 }
217
218 // Token: 0x06002681 RID: 9857 RVA: 0x000D9423 File Offset: 0x000D7623
219 public override bool HeaderIsListOf(int id)
220 {
221 return false;
222 }
223
224 // Token: 0x06002682 RID: 9858 RVA: 0x000D9428 File Offset: 0x000D7628
225 public override void OnInit()
226 {
227 foreach (UIInventory uiinventory in this.invs)
228 {
229 uiinventory.OnInit();
230 }
231 LayerInventory.listInv.Add(this);
232 if (this.Inv.Container == ELayer.pc)
233 {
234 InvOwner.Main = this.Inv;
235 }
236 if (!this.floatInv)
237 {
238 InvOwner.Trader = this.Inv;
239 this.wasInventoryOpen = ELayer.ui.IsInventoryOpen;
240 if (!this.wasInventoryOpen)
241 {
242 ELayer.ui.OpenFloatInv(true);
243 }
244 }
245 }
246
247 // Token: 0x06002683 RID: 9859 RVA: 0x000D94D8 File Offset: 0x000D76D8
248 public override void OnAfterInit()
249 {
250 ELayer.core.actionsNextFrame.Add(delegate
251 {
252 ELayer.core.actionsNextFrame.Add(delegate
253 {
254 if (this.invs[0] && this.invs[0].gameObject)
255 {
256 this.invs[0].RefreshHighlight();
257 }
258 });
259 });
260 }
261
262 // Token: 0x06002684 RID: 9860 RVA: 0x000D94F5 File Offset: 0x000D76F5
263 public UIInventory SetInv(int idWindow = 0)
264 {
265 UIInventory uiinventory = this.invs[idWindow];
266 uiinventory.window = this.windows[idWindow];
267 uiinventory.layer = this;
268 return uiinventory;
269 }
270
271 // Token: 0x06002685 RID: 9861 RVA: 0x000D951C File Offset: 0x000D771C
272 public override void OnUpdateInput()
273 {
274 if (EInput.action == EAction.MenuInventory || Input.GetKeyDown(KeyCode.Tab))
275 {
276 this.Close();
277 EInput.WaitReleaseKey();
278 return;
279 }
280 base.OnUpdateInput();
281 }
282
283 // Token: 0x06002686 RID: 9862 RVA: 0x000D9544 File Offset: 0x000D7744
284 public override void OnKill()
285 {
286 LayerInventory.listInv.Remove(this);
287 EInput.haltInput = false;
288 if (this.Inv == InvOwner.Trader)
289 {
290 if (this.Inv.UseGuide)
291 {
292 LayerInventory.SetDirtyAll(false);
293 }
294 InvOwner.Trader = null;
295 if (!this.wasInventoryOpen && ELayer.ui.IsInventoryOpen)
296 {
297 ELayer.ui.ToggleInventory(false);
298 }
299 }
300 if (this.Inv.Container == ELayer.pc)
301 {
302 InvOwner.Main = null;
303 }
304 if (!ELayer.game.isKilling && this.Inv.owner == ELayer.pc)
305 {
306 SE.Play("pop_inventory_deactivate");
307 }
308 }
309
310 // Token: 0x06002687 RID: 9863 RVA: 0x000D95E8 File Offset: 0x000D77E8
311 private void OnDestroy()
312 {
313 LayerInventory.SetDirty(this.invs[0].owner.Container.Thing);
314 LayerInventory.listInv.Remove(this);
315 }
316
317 // Token: 0x06002688 RID: 9864 RVA: 0x000D9618 File Offset: 0x000D7818
318 public override void OnRightClick()
319 {
320 if (this.invs[0].isList)
321 {
322 base.OnRightClick();
323 }
324 if (!this.invs[0].floatMode && InputModuleEX.GetComponentOf<ButtonGrid>() == null)
325 {
326 this.Close();
327 }
328 }
329
330 // Token: 0x06002689 RID: 9865 RVA: 0x000D9664 File Offset: 0x000D7864
331 public static LayerInventory _Create(string path = "")
332 {
333 if (ELayer.game.altInv && path.IsEmpty())
334 {
335 path = "LayerInventoryGrid";
336 }
337 return Layer.Create(path.IsEmpty() ? "LayerInventory" : ("LayerInventory/" + path)) as LayerInventory;
338 }
339
340 // Token: 0x0600268A RID: 9866 RVA: 0x000D96B0 File Offset: 0x000D78B0
341 public static LayerInventory CreatePCBackpack(bool mousePos = false)
342 {
343 LayerInventory layerInventory = LayerInventory._Create("LayerInventoryFloatMain");
344 Window window = layerInventory.windows[0];
345 layerInventory.mainInv = true;
346 window.setting.saveWindow = true;
347 UIInventory uiinventory = layerInventory.SetInv(0);
348 uiinventory.AddTab(new InvOwner(ELayer.pc, null, CurrencyType.None, PriceType.Default), UIInventory.Mode.All);
349 uiinventory.SetHeader("stash");
350 uiinventory.floatMode = true;
351 return layerInventory;
352 }
353
354 // Token: 0x0600268B RID: 9867 RVA: 0x000D9718 File Offset: 0x000D7918
355 public static bool CloseAllyInv(Chara c)
356 {
357 foreach (LayerInventory layerInventory in LayerInventory.listInv.Copy<LayerInventory>())
358 {
359 if (layerInventory.Inv.owner == c)
360 {
361 ELayer.ui.layerFloat.RemoveLayer(layerInventory);
362 return true;
363 }
364 }
365 return false;
366 }
367
368 // Token: 0x0600268C RID: 9868 RVA: 0x000D9788 File Offset: 0x000D7988
369 public static void CloseAllyInv()
370 {
371 foreach (LayerInventory layerInventory in LayerInventory.listInv.Copy<LayerInventory>())
372 {
373 if (!layerInventory.IsPlayerContainer(true))
374 {
375 ELayer.ui.layerFloat.RemoveLayer(layerInventory);
376 }
377 }
378 }
379
380 // Token: 0x0600268D RID: 9869 RVA: 0x000D97EC File Offset: 0x000D79EC
381 public static LayerInventory CreateContainerAlly(Chara owner, Card container)
382 {
383 LayerInventory.SetDirty(container.Thing);
384 LayerInventory.CloseAllyInv();
385 LayerInventory layerInventory = LayerInventory._Create("LayerInventoryFloat");
386 UIInventory uiinventory = layerInventory.SetInv(0);
387 Window window = layerInventory.windows[0];
388 window.buttonClose.SetActive(true);
389 uiinventory.AddTab(new InvOwnerAlly(owner, container.Thing, CurrencyType.Money), UIInventory.Mode.All);
390 uiinventory.tabs[0].textTab = container.Name;
391 uiinventory.floatMode = true;
392 if (ELayer.player.windowAllyInv == null)
393 {
394 Vector2 sizeDelta = window.Rect().sizeDelta;
395 ELayer.player.windowAllyInv = new Window.SaveData
396 {
397 x = 0f,
398 y = 200f,
399 w = sizeDelta.x,
400 h = sizeDelta.y,
401 anchor = RectPosition.Center,
402 useBG = ELayer.core.config.game.showInvBG,
403 advDistribution = false
404 };
405 }
406 window.saveData = ELayer.player.windowAllyInv;
407 window.saveData.open = true;
408 ELayer.ui.layerFloat.AddLayer(layerInventory);
409 window.ClampToScreen();
410 window.UpdateSaveData();
411 return layerInventory;
412 }
413
414 // Token: 0x0600268E RID: 9870 RVA: 0x000D9920 File Offset: 0x000D7B20
415 public static bool IsOpen(Card container)
416 {
417 using (List<LayerInventory>.Enumerator enumerator = LayerInventory.listInv.GetEnumerator())
418 {
419 while (enumerator.MoveNext())
420 {
421 if (enumerator.Current.GetPlayerContainer() == container)
422 {
423 return true;
424 }
425 }
426 }
427 return false;
428 }
429
430 // Token: 0x0600268F RID: 9871 RVA: 0x000D997C File Offset: 0x000D7B7C
431 public static LayerInventory CreateContainerPC(Card container)
432 {
433 LayerInventory.SetDirty(container.Thing);
434 foreach (LayerInventory layerInventory in LayerInventory.listInv)
435 {
436 if (layerInventory.GetPlayerContainer() == container)
437 {
438 ELayer.ui.layerFloat.RemoveLayer(layerInventory);
439 return null;
440 }
441 }
442 LayerInventory layerInventory2 = LayerInventory._Create("LayerInventoryFloat");
443 UIInventory uiinventory = layerInventory2.SetInv(0);
444 Window window = layerInventory2.windows[0];
445 Vector2 vector = default(Vector2);
446 bool flag = container.c_windowSaveData == null;
447 window.buttonClose.SetActive(true);
448 uiinventory.AddTab(new InvOwner(ELayer.pc, container.Thing, CurrencyType.None, PriceType.Default), UIInventory.Mode.All);
449 uiinventory.tabs[0].textTab = container.Name;
450 uiinventory.floatMode = true;
451 if (container.c_windowSaveData == null)
452 {
453 vector = window.Rect().anchoredPosition + new Vector2(-80f, -80f);
454 Vector2 sizeDelta = window.Rect().sizeDelta;
455 container.c_windowSaveData = new Window.SaveData
456 {
457 x = vector.x,
458 y = vector.y,
459 w = sizeDelta.x,
460 h = sizeDelta.y,
461 anchor = RectPosition.Auto,
462 useBG = ELayer.core.config.game.showInvBG,
463 advDistribution = false
464 };
465 if (container.trait.IsFridge)
466 {
467 container.c_windowSaveData.onlyRottable = true;
468 }
469 }
470 if (container.IsToolbelt)
471 {
472 container.c_windowSaveData.useBG = false;
473 }
474 window.saveData = container.c_windowSaveData;
475 window.saveData.open = true;
476 if (container.IsToolbelt)
477 {
478 return layerInventory2;
479 }
480 ELayer.ui.layerFloat.AddLayer(layerInventory2);
481 if (flag)
482 {
483 RectTransform rectTransform = window.Rect();
484 RectTransform rectTransform2 = null;
485 RectTransform rectTransform3 = null;
486 foreach (LayerInventory layerInventory3 in LayerInventory.listInv)
487 {
488 if (!(layerInventory3 == layerInventory2) && layerInventory3.IsFloat)
489 {
490 RectTransform rectTransform4 = layerInventory3.windows[0].Rect();
491 if (!rectTransform3 || rectTransform4.Rect().localPosition.x < rectTransform3.Rect().localPosition.x)
492 {
493 rectTransform3 = rectTransform4;
494 }
495 if (!rectTransform2 || rectTransform4.Rect().localPosition.y > rectTransform2.Rect().localPosition.y)
496 {
497 rectTransform2 = rectTransform4;
498 }
499 }
500 }
501 if (uiinventory.tabs[0].owner.Container.things.width < 3 && rectTransform3)
502 {
503 rectTransform.anchorMin = rectTransform3.anchorMin;
504 rectTransform.anchorMax = rectTransform3.anchorMax;
505 vector.x = rectTransform3.anchoredPosition.x - rectTransform.sizeDelta.x - rectTransform3.sizeDelta.x * 0.5f + 35f;
506 vector.y = rectTransform3.anchoredPosition.y;
507 }
508 else if (rectTransform2)
509 {
510 rectTransform.anchorMin = rectTransform2.anchorMin;
511 rectTransform.anchorMax = rectTransform2.anchorMax;
512 vector.x = rectTransform2.anchoredPosition.x;
513 vector.y = rectTransform2.anchoredPosition.y + rectTransform.sizeDelta.y - 25f;
514 }
515 else
516 {
517 rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
518 rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
519 vector = Vector2.one;
520 }
521 rectTransform.anchoredPosition = vector;
522 window.ClampToScreen();
523 window.UpdateSaveData();
524 }
525 return layerInventory2;
526 }
527
528 // Token: 0x06002690 RID: 9872 RVA: 0x000D9D90 File Offset: 0x000D7F90
529 public static LayerInventory CreateContainer(Card owner)
530 {
531 if (owner.GetRootCard() == ELayer.pc)
532 {
533 return LayerInventory.CreateContainerPC(owner);
534 }
535 Card container = owner;
536 if (owner.trait is TraitShippingChest)
537 {
538 container = ELayer.game.cards.container_shipping;
539 ELayer.player.uidLastShippedZone = ELayer._zone.uid;
540 }
541 if (owner.trait is TraitDeliveryChest)
542 {
543 container = ELayer.game.cards.container_deliver;
544 Tutorial.Play("deliver_box");
545 }
546 return LayerInventory.CreateContainer(owner, container);
547 }
548
549 // Token: 0x06002691 RID: 9873 RVA: 0x000D9E14 File Offset: 0x000D8014
550 public static LayerInventory CreateContainer(Card owner, Card container)
551 {
552 if (container.isChara)
553 {
554 SE.PopInventory();
555 }
556 LayerInventory layerInventory = LayerInventory._Create("");
557 layerInventory.SetInv(0).AddTab(owner, UIInventory.Mode.Take, container.Thing).dest = ELayer.pc;
558 if (container.c_windowSaveData == null)
559 {
560 container.c_windowSaveData = new Window.SaveData
561 {
562 useBG = true
563 };
564 if (container == ELayer.game.cards.container_shipping)
565 {
566 container.c_windowSaveData.autodump = AutodumpFlag.none;
567 }
568 }
569 layerInventory.windows[0].saveData = container.c_windowSaveData;
570 ELayer.ui.AddLayer(layerInventory);
571 return layerInventory;
572 }
573
574 // Token: 0x06002692 RID: 9874 RVA: 0x000D9EB4 File Offset: 0x000D80B4
575 public static LayerInventory CreateContainer<T>(Card c, Card container, CurrencyType currency = CurrencyType.None) where T : InvOwner
576 {
577 LayerInventory layerInventory = LayerInventory._Create("");
578 UIInventory uiinventory = layerInventory.SetInv(0);
579 T t = Activator.CreateInstance(typeof(T), new object[]
580 {
581 c,
582 container,
583 currency
584 }) as T;
585 uiinventory.AddTab(t, UIInventory.Mode.Buy).dest = ELayer.pc;
586 if (container.c_windowSaveData == null)
587 {
588 container.c_windowSaveData = new Window.SaveData
589 {
590 useBG = true
591 };
592 }
593 layerInventory.windows[0].saveData = container.c_windowSaveData;
594 ELayer.ui.AddLayer(layerInventory);
595 return layerInventory;
596 }
597
598 // Token: 0x06002693 RID: 9875 RVA: 0x000D9F5C File Offset: 0x000D815C
599 public static LayerInventory CreateBuy(Card c, CurrencyType currency = CurrencyType.Money, PriceType price = PriceType.Default)
600 {
601 LayerInventory layerInventory = LayerInventory._Create("");
602 UIInventory uiinventory = layerInventory.SetInv(0);
603 Thing thing = c.things.Find("chest_merchant", -1, -1);
604 SE.Play("shop_open");
605 InvOwnerShop invOwnerShop = new InvOwnerShop(c, thing, currency, price);
606 uiinventory.AddTab(invOwnerShop, UIInventory.Mode.Buy).dest = ELayer.pc;
607 if (Window.dictData.TryGetValue("ChestMerchant", null) == null)
608 {
609 Window.dictData.Add("ChestMerchant", new Window.SaveData
610 {
611 useBG = true
612 });
613 }
614 layerInventory.windows[0].saveData = thing.GetWindowSaveData();
615 uiinventory.tabs[0].owner.BuildUICurrency(layerInventory.uiCurrency, c.trait.CostRerollShop != 0);
616 ShopTransaction.current = new ShopTransaction
617 {
618 trader = invOwnerShop
619 };
620 layerInventory.SetOnKill(new Action(ShopTransaction.current.OnEndTransaction));
621 return layerInventory;
622 }
623
624 // Token: 0x0400151A RID: 5402
625 public static List<LayerInventory> listInv = new List<LayerInventory>();
626
627 // Token: 0x0400151B RID: 5403
628 public static InvOwner highlightInv;
629
630 // Token: 0x0400151C RID: 5404
631 public List<UIInventory> invs = new List<UIInventory>();
632
633 // Token: 0x0400151D RID: 5405
634 public UICurrency uiCurrency;
635
636 // Token: 0x0400151E RID: 5406
637 public bool floatInv;
638
639 // Token: 0x0400151F RID: 5407
640 public bool mainInv;
641
642 // Token: 0x04001520 RID: 5408
643 public WindowCharaMini mini;
644
645 // Token: 0x04001521 RID: 5409
646 [NonSerialized]
647 public bool wasInventoryOpen;
648}
Definition Card.cs:13
Definition Chara.cs:12
Definition Thing.cs:10