Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
LayerCollectible.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using UnityEngine.UI;
4
5public class LayerCollectible : ELayer
6{
7 public UIList list;
8
10
12
14
16
17 public Image imageItem;
18
19 public Vector3 contextFix;
20
21 public Func<Hoard.Item, bool> onClick;
22
24
25 public override void OnAfterInit()
26 {
27 if (hoard.items.Count == 0)
28 {
29 hoard.Add("gold", 1);
30 }
31 Refresh();
32 }
33
34 public void Refresh()
35 {
36 ELayer.ui.GetLayer<LayerHoard>();
37 list.callbacks = new UIList.Callback<Hoard.Item, UIButton>
38 {
39 onClick = delegate(Hoard.Item a, UIButton b)
40 {
41 selected = b;
42 if (onClick != null)
43 {
44 if (onClick(a))
45 {
46 Close();
47 }
48 }
49 else
50 {
51 UIContextMenu uIContextMenu = ELayer.ui.contextMenu.Create("ContextHoard");
52 int max = a.num;
53 if (max > 1 && a.IsUnique)
54 {
55 max = 1;
56 }
57 uIContextMenu.AddSlider("display", (float n) => n + " / " + max, a.show, delegate(float v)
58 {
59 a.show = (int)v;
60 SetButton(a, b);
61 RefreshInfo(b, force: true);
62 }, 0f, max, isInt: true, hideOther: false);
63 uIContextMenu.AddToggle("displayRandom", a.random, delegate(bool on)
64 {
65 a.random = on;
66 });
67 uIContextMenu.Show(EInput.uiMousePosition + contextFix);
68 }
69 },
70 onInstantiate = delegate(Hoard.Item a, UIButton b)
71 {
72 SetButton(a, b);
73 }
74 };
75 foreach (SourceCollectible.Row row in ELayer.sources.collectibles.rows)
76 {
77 if (hoard.items.ContainsKey(row.id))
78 {
79 list.Add(hoard.items[row.id]);
80 }
81 }
82 list.Refresh();
83 selected = list.buttons[0].component as UIButton;
85 }
86
87 private void Update()
88 {
89 UIButton componentOf = InputModuleEX.GetComponentOf<UIButton>();
90 if ((bool)componentOf && componentOf.refObj is Hoard.Item)
91 {
92 RefreshInfo(componentOf);
93 }
94 else
95 {
97 }
98 }
99
100 public void SetButton(Hoard.Item a, UIButton b)
101 {
102 string text = a.num.ToString() ?? "";
103 if (a.num != a.show)
104 {
105 text = text + " (" + a.show + ")";
106 }
107 b.mainText.text = text;
108 b.icon.sprite = hoard.GetSprite(a.id);
109 b.icon.SetNativeSize();
110 b.refObj = a;
111 }
112
113 public void RefreshInfo(UIButton button, bool force = false)
114 {
115 if (force || (!(lastShown == button) && (bool)button))
116 {
117 Hoard.Item item = button.refObj as Hoard.Item;
118 string text = "collectibleTitle".lang(item.Source.GetName(), item.num.ToString() ?? "", item.show.ToString() ?? "");
119 if (item.IsUnique)
120 {
121 text += " UNIQUE";
122 }
123 textName.text = text;
124 textDetail.text = item.Source.GetText("detail", returnNull: true).IsEmpty("none".lang());
125 imageItem.sprite = hoard.GetSprite(item.id);
126 imageItem.SetNativeSize();
127 lastShown = button;
128 }
129 }
130}
Definition: EInput.cs:8
static Vector3 uiMousePosition
Definition: EInput.cs:369
Definition: ELayer.cs:4
static Player player
Definition: ELayer.cs:13
static SourceManager sources
Definition: ELayer.cs:37
static UI ui
Definition: ELayer.cs:21
Definition: Hoard.cs:8
Item Add(string id)
Definition: Hoard.cs:161
Sprite GetSprite(string id)
Definition: Hoard.cs:211
Dictionary< string, Item > items
Definition: Hoard.cs:106
void RefreshInfo(UIButton button, bool force=false)
Func< Hoard.Item, bool > onClick
override void OnAfterInit()
void SetButton(Hoard.Item a, UIButton b)
virtual void Close()
Definition: Layer.cs:463
Hoard hoard
Definition: Player.cs:892
SourceCollectible collectibles
Image icon
Definition: UIButton.cs:110
UIContextMenuItem AddToggle(string idLang="", bool isOn=false, UnityAction< bool > action=null)
void Show(UIItem i)
UIContextMenuItem AddSlider(string text, Func< float, string > textFunc, float value, Action< float > action, float min=0f, float max=1f, bool isInt=false, bool hideOther=true, bool useInput=false)
Definition: UIList.cs:9
List< ButtonPair > buttons
Definition: UIList.cs:244
override void Add(object item)
Definition: UIList.cs:302
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:424
Definition: UIText.cs:6