Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
LayerInventory.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class LayerInventory : ELayer
6{
7 public static List<LayerInventory> listInv = new List<LayerInventory>();
8
9 public static InvOwner highlightInv;
10
11 public List<UIInventory> invs = new List<UIInventory>();
12
14
15 public bool floatInv;
16
17 public bool mainInv;
18
20
21 [NonSerialized]
22 public bool wasInventoryOpen;
23
24 public InvOwner Inv => invs[0].tabs[0].owner;
25
26 public static LayerInventory GetTopLayer(Thing t, bool includePlayer = false, InvOwner exclude = null)
27 {
28 LayerInventory result = null;
29 int num = -1;
30 foreach (LayerInventory item in listInv)
31 {
32 if (item.IsPlayerContainer(includePlayer) && item.Inv != exclude && !item.Inv.Container.IsToolbelt && !item.Inv.Container.things.IsFull(t, recursive: false))
33 {
34 int siblingIndex = item.transform.GetSiblingIndex();
35 if (siblingIndex > num)
36 {
37 num = siblingIndex;
38 result = item;
39 }
40 }
41 }
42 return result;
43 }
44
45 public static LayerInventory GetLayer(Card t)
46 {
47 LayerInventory result = null;
48 foreach (LayerInventory item in listInv)
49 {
50 if (item.Inv.Container == t)
51 {
52 return item;
53 }
54 }
55 return result;
56 }
57
58 public static LayerInventory GetPCLayer()
59 {
60 return GetLayer(ELayer.pc);
61 }
62
63 public static void Close(Thing t)
64 {
65 foreach (LayerInventory item in listInv)
66 {
67 if (item.invs[0].owner.Container == t)
68 {
69 item.Close();
70 break;
71 }
72 }
73 }
74
75 public static bool IsOpen(Thing t)
76 {
77 foreach (LayerInventory item in listInv)
78 {
79 if (item.invs[0].owner.Container == t)
80 {
81 return true;
82 }
83 }
84 return false;
85 }
86
87 public static void SetDirty(Thing t)
88 {
89 if (!ELayer.game.altInv || t == null)
90 {
91 return;
92 }
93 foreach (LayerInventory item in listInv)
94 {
95 if (item.invs[0].owner.Container == t.parent || ((bool)item.mini && item.mini.gameObject.activeInHierarchy))
96 {
97 item.invs[0].dirty = true;
98 }
99 }
100 if (t.invY == 1 || ELayer.pc.held == t)
101 {
102 WidgetCurrentTool.dirty = true;
103 }
104 if (t.isEquipped)
105 {
106 WidgetEquip.dirty = true;
107 }
108 }
109
110 public static void SetDirtyAll(bool immediate = false)
111 {
112 foreach (LayerInventory item in listInv)
113 {
114 item.invs[0].dirty = true;
115 if (immediate)
116 {
117 item.invs[0].CheckDirty();
118 }
119 }
120 if ((bool)WidgetEquip.Instance)
121 {
122 WidgetEquip.dirty = true;
123 if (immediate)
124 {
126 }
127 }
128 WidgetCurrentTool.dirty = true;
129 if (immediate)
130 {
132 }
133 }
134
135 public static void TryShowGuide(UIList list)
136 {
137 List<ButtonGrid> list2 = new List<ButtonGrid>();
138 foreach (UIList.ButtonPair button in list.buttons)
139 {
140 ButtonGrid buttonGrid = button.component as ButtonGrid;
141 if ((bool)buttonGrid)
142 {
143 list2.Add(buttonGrid);
144 }
145 }
146 TryShowGuide(list2);
147 }
148
149 public static void TryShowGuide(List<ButtonGrid> list)
150 {
151 bool flag = InvOwner.HasTrader && InvOwner.Trader.UseGuide;
152 if (flag)
153 {
154 WidgetSearch.selected = null;
155 }
156 bool flag2 = (bool)WidgetSearch.Instance && WidgetSearch.selected != null && !ELayer.ui.IsDragging;
157 if (!flag2 && WidgetEquip.dragEquip == null && LayerAbility.hotElement == null && !flag)
158 {
159 return;
160 }
161 foreach (ButtonGrid item in list)
162 {
163 Thing thing = item.card as Thing;
164 if (LayerAbility.hotElement != null)
165 {
166 if ((bool)item && item.invOwner != null && (thing == null || thing.trait is TraitAbility) && item.invOwner.owner == ELayer.pc && !(item.invOwner is InvOwnerEquip))
167 {
168 item.Attach("guide", rightAttach: false);
169 }
170 }
171 else if (WidgetEquip.dragEquip != null && !flag)
172 {
173 if (item.invOwner is InvOwnerEquip invOwnerEquip && invOwnerEquip.slot.elementId == WidgetEquip.dragEquip.category.slot)
174 {
175 item.Attach("guide", rightAttach: false);
176 }
177 }
178 else if (flag2)
179 {
181 {
182 item.Attach("guide", rightAttach: false);
183 }
184 }
185 else
186 {
187 if (thing == null)
188 {
189 continue;
190 }
191 bool show = InvOwner.Trader.ShouldShowGuide(thing);
192 if (!show && thing.CanSearchContents)
193 {
194 thing.things.Foreach(delegate(Thing _t)
195 {
196 if (!show && InvOwner.Trader.ShouldShowGuide(_t))
197 {
198 show = true;
199 }
200 });
201 }
202 if (show)
203 {
204 item.Attach("guide", rightAttach: false);
205 }
206 }
207 }
208 }
209
210 public bool IsPlayerContainer(bool includePlayer = false)
211 {
212 if (invs[0].tabs[0].mode != UIInventory.Mode.All)
213 {
214 return false;
215 }
216 if (!includePlayer && invs[0].owner.Container == ELayer.pc)
217 {
218 return false;
219 }
220 return invs[0].owner.Container.GetRootCard() == ELayer.pc;
221 }
222
224 {
225 UIInventory.Tab tab = invs[0].tabs[0];
226 if (!IsPlayerContainer())
227 {
228 return null;
229 }
230 return tab.owner.Container;
231 }
232
233 public override bool HeaderIsListOf(int id)
234 {
235 return false;
236 }
237
238 public override void OnInit()
239 {
240 foreach (UIInventory inv in invs)
241 {
242 inv.OnInit();
243 }
244 listInv.Add(this);
245 if (Inv.Container == ELayer.pc)
246 {
247 InvOwner.Main = Inv;
248 }
249 if (!floatInv)
250 {
251 InvOwner.Trader = Inv;
252 wasInventoryOpen = ELayer.ui.IsInventoryOpen;
253 if (!wasInventoryOpen)
254 {
255 ELayer.ui.OpenFloatInv(ignoreSound: true);
256 }
257 }
258 }
259
260 public override void OnAfterInit()
261 {
262 ELayer.core.actionsNextFrame.Add(delegate
263 {
264 ELayer.core.actionsNextFrame.Add(delegate
265 {
266 if ((bool)invs[0] && (bool)invs[0].gameObject)
267 {
268 invs[0].RefreshHighlight();
269 }
270 });
271 });
272 }
273
274 public UIInventory SetInv(int idWindow = 0)
275 {
276 UIInventory uIInventory = invs[idWindow];
277 uIInventory.window = windows[idWindow];
278 uIInventory.layer = this;
279 return uIInventory;
280 }
281
282 public override void OnUpdateInput()
283 {
284 if (EInput.action == EAction.MenuInventory || Input.GetKeyDown(KeyCode.Tab))
285 {
286 Close();
288 return;
289 }
290 if (EInput.action == EAction.Dump)
291 {
293 }
294 base.OnUpdateInput();
295 }
296
297 public override void OnKill()
298 {
299 listInv.Remove(this);
300 EInput.haltInput = false;
301 if (Inv == InvOwner.Trader)
302 {
303 if (Inv.UseGuide)
304 {
305 SetDirtyAll();
306 }
307 InvOwner.Trader = null;
308 if (!wasInventoryOpen && ELayer.ui.IsInventoryOpen)
309 {
310 ELayer.ui.ToggleInventory();
311 }
312 }
313 if (Inv.Container == ELayer.pc)
314 {
315 InvOwner.Main = null;
316 }
318 {
319 SE.Play("pop_inventory_deactivate");
320 }
321 }
322
323 private void OnDestroy()
324 {
325 if (invs.Count > 0)
326 {
327 SetDirty(invs[0].owner.Container.Thing);
328 }
329 listInv.Remove(this);
330 }
331
332 public override void OnRightClick()
333 {
334 if (invs[0].isList)
335 {
336 base.OnRightClick();
337 }
338 if (!invs[0].floatMode && InputModuleEX.GetComponentOf<ButtonGrid>() == null)
339 {
340 Close();
341 }
342 }
343
344 public static LayerInventory _Create(string path = "")
345 {
346 if (ELayer.game.altInv && path.IsEmpty())
347 {
348 path = "LayerInventoryGrid";
349 }
350 return Layer.Create(path.IsEmpty() ? "LayerInventory" : ("LayerInventory/" + path)) as LayerInventory;
351 }
352
353 public static LayerInventory CreatePCBackpack(bool mousePos = false)
354 {
355 LayerInventory layerInventory = _Create("LayerInventoryFloatMain");
356 Window window = layerInventory.windows[0];
357 layerInventory.mainInv = true;
358 window.setting.saveWindow = true;
359 UIInventory uIInventory = layerInventory.SetInv();
360 uIInventory.AddTab(new InvOwner(ELayer.pc));
361 uIInventory.SetHeader("stash");
362 uIInventory.floatMode = true;
363 return layerInventory;
364 }
365
366 public static bool CloseAllyInv(Chara c)
367 {
368 foreach (LayerInventory item in listInv.Copy())
369 {
370 if (item.Inv.owner == c)
371 {
372 ELayer.ui.layerFloat.RemoveLayer(item);
373 return true;
374 }
375 }
376 return false;
377 }
378
379 public static void CloseAllyInv()
380 {
381 foreach (LayerInventory item in listInv.Copy())
382 {
383 if (!item.IsPlayerContainer(includePlayer: true))
384 {
385 ELayer.ui.layerFloat.RemoveLayer(item);
386 }
387 }
388 }
389
390 public static LayerInventory CreateContainerAlly(Chara owner, Card container)
391 {
392 SetDirty(container.Thing);
393 CloseAllyInv();
394 LayerInventory layerInventory = _Create("LayerInventoryFloat");
395 UIInventory uIInventory = layerInventory.SetInv();
396 Window window = layerInventory.windows[0];
397 window.buttonClose.SetActive(enable: true);
398 uIInventory.AddTab(new InvOwnerAlly(owner, container.Thing));
399 uIInventory.tabs[0].textTab = container.Name;
400 uIInventory.floatMode = true;
401 if (ELayer.player.windowAllyInv == null)
402 {
403 Vector2 sizeDelta = window.Rect().sizeDelta;
404 ELayer.player.windowAllyInv = new Window.SaveData
405 {
406 x = 0f,
407 y = 200f,
408 w = sizeDelta.x,
409 h = sizeDelta.y,
410 anchor = RectPosition.Center,
412 advDistribution = false
413 };
414 }
415 window.saveData = ELayer.player.windowAllyInv;
416 window.saveData.open = true;
417 ELayer.ui.layerFloat.AddLayer(layerInventory);
418 window.ClampToScreen();
419 window.UpdateSaveData();
420 return layerInventory;
421 }
422
423 public static bool IsOpen(Card container)
424 {
425 foreach (LayerInventory item in listInv)
426 {
427 if (item.GetPlayerContainer() == container)
428 {
429 return true;
430 }
431 }
432 return false;
433 }
434
435 public static LayerInventory CreateContainerPC(Card container)
436 {
437 SetDirty(container.Thing);
438 foreach (LayerInventory item in listInv)
439 {
440 if (item.GetPlayerContainer() == container)
441 {
442 ELayer.ui.layerFloat.RemoveLayer(item);
443 return null;
444 }
445 }
446 LayerInventory layerInventory = _Create("LayerInventoryFloat");
447 UIInventory uIInventory = layerInventory.SetInv();
448 Window window = layerInventory.windows[0];
449 Vector2 anchoredPosition = default(Vector2);
450 bool flag = container.c_windowSaveData == null;
451 window.buttonClose.SetActive(enable: true);
452 uIInventory.AddTab(new InvOwner(ELayer.pc, container.Thing));
453 uIInventory.tabs[0].textTab = container.Name;
454 uIInventory.floatMode = true;
455 if (container.c_windowSaveData == null)
456 {
457 anchoredPosition = window.Rect().anchoredPosition + new Vector2(-80f, -80f);
458 Vector2 sizeDelta = window.Rect().sizeDelta;
459 container.c_windowSaveData = new Window.SaveData
460 {
461 x = anchoredPosition.x,
462 y = anchoredPosition.y,
463 w = sizeDelta.x,
464 h = sizeDelta.y,
465 anchor = RectPosition.Auto,
467 advDistribution = false
468 };
469 if (container.trait.IsFridge)
470 {
471 container.c_windowSaveData.onlyRottable = true;
472 }
473 }
474 if (container.IsToolbelt)
475 {
476 container.c_windowSaveData.useBG = false;
477 }
478 window.saveData = container.c_windowSaveData;
479 window.saveData.open = true;
480 if (container.IsToolbelt)
481 {
482 return layerInventory;
483 }
484 ELayer.ui.layerFloat.AddLayer(layerInventory);
485 if (flag)
486 {
487 RectTransform rectTransform = window.Rect();
489 {
490 rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
491 rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
492 anchoredPosition = new Vector2(0f, rectTransform.sizeDelta.y / 2f);
493 }
494 else
495 {
496 RectTransform rectTransform2 = null;
497 RectTransform rectTransform3 = null;
498 foreach (LayerInventory item2 in listInv)
499 {
500 if (!(item2 == layerInventory) && item2.IsFloat)
501 {
502 RectTransform rectTransform4 = item2.windows[0].Rect();
503 if (!rectTransform3 || rectTransform4.Rect().localPosition.x < rectTransform3.Rect().localPosition.x)
504 {
505 rectTransform3 = rectTransform4;
506 }
507 if (!rectTransform2 || rectTransform4.Rect().localPosition.y > rectTransform2.Rect().localPosition.y)
508 {
509 rectTransform2 = rectTransform4;
510 }
511 }
512 }
513 if (uIInventory.tabs[0].owner.Container.things.width < 3 && (bool)rectTransform3)
514 {
515 rectTransform.anchorMin = rectTransform3.anchorMin;
516 rectTransform.anchorMax = rectTransform3.anchorMax;
517 anchoredPosition.x = rectTransform3.anchoredPosition.x - rectTransform.sizeDelta.x - rectTransform3.sizeDelta.x * 0.5f + 35f;
518 anchoredPosition.y = rectTransform3.anchoredPosition.y;
519 }
520 else if ((bool)rectTransform2)
521 {
522 rectTransform.anchorMin = rectTransform2.anchorMin;
523 rectTransform.anchorMax = rectTransform2.anchorMax;
524 anchoredPosition.x = rectTransform2.anchoredPosition.x;
525 anchoredPosition.y = rectTransform2.anchoredPosition.y + rectTransform.sizeDelta.y - 25f;
526 }
527 else
528 {
529 rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
530 rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
531 anchoredPosition = Vector2.one;
532 }
533 }
534 rectTransform.anchoredPosition = anchoredPosition;
535 window.ClampToScreen();
536 window.UpdateSaveData();
537 }
538 return layerInventory;
539 }
540
542 {
543 if (owner.GetRootCard() == ELayer.pc)
544 {
545 return CreateContainerPC(owner);
546 }
547 Card card = owner;
548 if (owner.trait is TraitShippingChest)
549 {
551 card.things.SetSize(owner.things.width, owner.things.height);
552 ELayer.player.uidLastShippedZone = ELayer._zone.uid;
553 }
554 if (owner.trait is TraitDeliveryChest)
555 {
557 Tutorial.Play("deliver_box");
558 }
559 return CreateContainer(owner, card);
560 }
561
562 public static LayerInventory CreateContainer(Card owner, Card container)
563 {
564 if (container.isChara)
565 {
566 SE.PopInventory();
567 }
568 LayerInventory layerInventory = _Create();
569 layerInventory.SetInv().AddTab(owner, UIInventory.Mode.Take, container.Thing).dest = ELayer.pc;
570 if (container.c_windowSaveData == null)
571 {
572 container.c_windowSaveData = new Window.SaveData
573 {
574 useBG = true
575 };
576 if (container == ELayer.game.cards.container_shipping)
577 {
578 container.c_windowSaveData.autodump = AutodumpFlag.none;
579 }
580 }
581 layerInventory.windows[0].saveData = container.c_windowSaveData;
582 ELayer.ui.AddLayer(layerInventory);
583 return layerInventory;
584 }
585
587 {
588 LayerInventory layerInventory = _Create();
589 UIInventory uIInventory = layerInventory.SetInv();
590 T owner = Activator.CreateInstance(typeof(T), c, container, currency) as T;
591 uIInventory.AddTab(owner, UIInventory.Mode.Buy).dest = ELayer.pc;
592 if (container.c_windowSaveData == null)
593 {
594 container.c_windowSaveData = new Window.SaveData
595 {
596 useBG = true
597 };
598 }
599 layerInventory.windows[0].saveData = container.c_windowSaveData;
600 ELayer.ui.AddLayer(layerInventory);
601 return layerInventory;
602 }
603
605 {
606 LayerInventory layerInventory = _Create();
607 UIInventory uIInventory = layerInventory.SetInv();
608 Thing thing = c.things.Find("chest_merchant");
609 SE.Play("shop_open");
610 InvOwnerShop invOwnerShop = new InvOwnerShop(c, thing, currency, price);
611 uIInventory.AddTab(invOwnerShop, UIInventory.Mode.Buy).dest = ELayer.pc;
612 if (Window.dictData.TryGetValue("ChestMerchant") == null)
613 {
614 Window.dictData.Add("ChestMerchant", new Window.SaveData
615 {
616 useBG = true
617 });
618 }
619 layerInventory.windows[0].saveData = thing.GetWindowSaveData();
620 uIInventory.tabs[0].owner.BuildUICurrency(layerInventory.uiCurrency, c.trait.CostRerollShop != 0);
621 ShopTransaction.current = new ShopTransaction
622 {
623 trader = invOwnerShop
624 };
626 return layerInventory;
627 }
628}
AutodumpFlag
Definition: AutodumpFlag.cs:2
@ currency
CurrencyType
Definition: CurrencyType.cs:2
EAction
Definition: EAction.cs:2
PriceType
Definition: PriceType.cs:2
RectPosition
Definition: RectPosition.cs:2
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
int elementId
Definition: BodySlot.cs:6
Thing container_shipping
Definition: CardManager.cs:52
Thing container_deliver
Definition: CardManager.cs:55
Definition: Card.cs:11
string Name
Definition: Card.cs:2013
ICardParent parent
Definition: Card.cs:51
Trait trait
Definition: Card.cs:49
Window.SaveData GetWindowSaveData()
Definition: Card.cs:2376
ThingContainer things
Definition: Card.cs:34
virtual bool isChara
Definition: Card.cs:1959
virtual Thing Thing
Definition: Card.cs:1934
Card GetRootCard()
Definition: Card.cs:3173
Window.SaveData c_windowSaveData
Definition: Card.cs:1721
SourceCategory.Row category
Definition: Card.cs:1925
Definition: Chara.cs:10
Card held
Definition: Chara.cs:67
new GameConfig game
Definition: CoreConfig.cs:596
CoreConfig config
Definition: Core.cs:70
Definition: EInput.cs:8
static void WaitReleaseKey()
Definition: EInput.cs:650
static EAction action
Definition: EInput.cs:259
Definition: ELayer.cs:4
static Chara pc
Definition: ELayer.cs:15
static Player player
Definition: ELayer.cs:13
static Core core
Definition: ELayer.cs:7
static Game game
Definition: ELayer.cs:9
bool IsFloat
Definition: ELayer.cs:45
static UI ui
Definition: ELayer.cs:21
static Zone _zone
Definition: ELayer.cs:25
CardManager cards
Definition: Game.cs:155
bool altInv
Definition: Game.cs:263
bool isKilling
Definition: Game.cs:237
BodySlot slot
Definition: InvOwnerEquip.cs:3
static InvOwner Trader
Definition: InvOwner.cs:524
Card owner
Definition: InvOwner.cs:538
Card Container
Definition: InvOwner.cs:540
virtual bool UseGuide
Definition: InvOwner.cs:576
virtual bool ShouldShowGuide(Thing t)
Definition: InvOwner.cs:686
static ButtonAbility hotElement
Definition: LayerAbility.cs:23
static InvOwner highlightInv
List< UIInventory > invs
static LayerInventory _Create(string path="")
static LayerInventory CreateContainer(Card owner)
static bool CloseAllyInv(Chara c)
override void OnUpdateInput()
static LayerInventory CreateContainerAlly(Chara owner, Card container)
static LayerInventory CreatePCBackpack(bool mousePos=false)
override void OnKill()
override void OnInit()
UIInventory SetInv(int idWindow=0)
static bool IsOpen(Card container)
static void SetDirty(Thing t)
static LayerInventory GetLayer(Card t)
static void SetDirtyAll(bool immediate=false)
static List< LayerInventory > listInv
Card GetPlayerContainer()
WindowCharaMini mini
override void OnAfterInit()
static LayerInventory GetPCLayer()
override void OnRightClick()
static bool IsOpen(Thing t)
static void CloseAllyInv()
override bool HeaderIsListOf(int id)
static LayerInventory GetTopLayer(Thing t, bool includePlayer=false, InvOwner exclude=null)
static LayerInventory CreateBuy(Card c, CurrencyType currency=CurrencyType.Money, PriceType price=PriceType.Default)
static LayerInventory CreateContainer(Card owner, Card container)
static void Close(Thing t)
static LayerInventory CreateContainer< T >(Card c, Card container, CurrencyType currency=CurrencyType.None)
UICurrency uiCurrency
static void TryShowGuide(UIList list)
bool IsPlayerContainer(bool includePlayer=false)
static LayerInventory CreateContainerPC(Card container)
static void TryShowGuide(List< ButtonGrid > list)
Definition: Layer.cs:9
List< Window > windows
Definition: Layer.cs:116
virtual void Close()
Definition: Layer.cs:463
static Layer Create(string path)
Definition: Layer.cs:299
Layer SetOnKill(Action action)
Definition: Layer.cs:579
Window.SaveData windowAllyInv
Definition: Player.cs:931
bool openContainerCenter
Definition: Player.cs:799
static ShopTransaction current
int uid
Definition: Spatial.cs:70
static void TryPerform()
Definition: TaskDump.cs:6
Thing Find(int uid)
void Foreach(Action< Thing > action, bool onlyAccessible=true)
Definition: Thing.cs:8
bool CanSearchContents
Definition: Thing.cs:80
virtual int CostRerollShop
Definition: Trait.cs:492
static void Play(string idStep)
Definition: Tutorial.cs:7
InvOwner owner
Definition: UIInventory.cs:68
void SetHeader(string s)
Definition: UIInventory.cs:207
void OnInit()
Definition: UIInventory.cs:229
List< Tab > tabs
Definition: UIInventory.cs:133
Tab AddTab(Card c, Mode mode, Thing container=null)
Definition: UIInventory.cs:212
Definition: UIList.cs:9
List< ButtonPair > buttons
Definition: UIList.cs:244
static WidgetCurrentTool Instance
static Thing dragEquip
Definition: WidgetEquip.cs:15
static WidgetEquip Instance
Definition: WidgetEquip.cs:11
void CheckDirty()
Definition: WidgetEquip.cs:61
static WidgetSearch Instance
Definition: WidgetSearch.cs:25
static Card selected
Definition: WidgetSearch.cs:29
Definition: Window.cs:13
void ClampToScreen()
Definition: Window.cs:1765
static Dictionary< string, SaveData > dictData
Definition: Window.cs:594
Button buttonClose
Definition: Window.cs:624
void UpdateSaveData()
Definition: Window.cs:1093