Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Hotbar.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Newtonsoft.Json;
3
4public class Hotbar : EClass
5{
6 public enum Type
7 {
9 Main,
11 }
12
13 public class Page : EClass
14 {
15 [JsonProperty]
16 public List<HotItem> items = new List<HotItem>();
17
18 [JsonProperty]
19 public int selected = -1;
20
22 {
23 get
24 {
25 if (selected != -1)
26 {
27 return items[selected];
28 }
29 return null;
30 }
31 }
32
33 public void SetItem(Hotbar h, HotItem item, int index)
34 {
35 if (index == -1)
36 {
37 for (int i = 0; i < items.Count; i++)
38 {
39 if (items[i] == null)
40 {
41 index = i;
42 break;
43 }
44 }
45 if (index == -1)
46 {
47 return;
48 }
49 }
50 if (items[index] != null)
51 {
52 items[index].button = null;
53 }
54 items[index] = item;
55 }
56
57 public HotItem GetItem(int index)
58 {
59 if (index >= items.Count)
60 {
61 return null;
62 }
63 return items[index];
64 }
65 }
66
67 public const int IDMainMenu = 2;
68
69 public const int IDBuild = 3;
70
71 public const int IDUser2 = 5;
72
73 public const int IDUser3 = 6;
74
75 public const int IDSpeed = 7;
76
77 [JsonProperty]
78 public int currentPage;
79
80 [JsonProperty]
81 public int itemsPerPage = 6;
82
83 [JsonProperty]
84 public int id;
85
86 [JsonProperty]
87 public List<Page> pages = new List<Page>();
88
89 public bool dirty;
90
92
94
95 public HotItem SelectedItem => pages[currentPage].SelectedItem;
96
97 public HotItem DefaultItem => null;
98
99 public bool IsLocked => id == 3;
100
101 public bool IsUserHotbar
102 {
103 get
104 {
105 if (id != 5)
106 {
107 return id == 6;
108 }
109 return true;
110 }
111 }
112
113 public bool ShowFunctionKey => id == 5;
114
116
117 public void SetSlotNum(int a)
118 {
119 itemsPerPage = a;
120 foreach (Page page in pages)
121 {
122 ValidatePage(page);
123 }
124 }
125
126 public void AddPage()
127 {
128 Page page = new Page();
129 pages.Add(page);
130 ValidatePage(page);
131 }
132
133 public void ValidatePage(Page page, int num = -1)
134 {
135 if (num != -1 && itemsPerPage < num)
136 {
137 itemsPerPage = num;
138 }
139 if (page.items.Count < itemsPerPage)
140 {
141 int num2 = itemsPerPage - page.items.Count;
142 for (int i = 0; i < num2; i++)
143 {
144 page.items.Add(DefaultItem);
145 }
146 }
147 }
148
149 public void SetPage(int pageIndex)
150 {
151 currentPage = pageIndex;
152 }
153
154 public void Remove(HotItem item)
155 {
156 for (int i = 0; i < pages.Count; i++)
157 {
158 for (int j = 0; j < pages[i].items.Count; j++)
159 {
160 if (pages[i].items[j] == item)
161 {
162 SetItem(null, j, i, refreshActor: true);
163 }
164 }
165 }
166 }
167
168 public HotItem GetItem(int index, int pageIndex = -1)
169 {
170 return pages[(pageIndex == -1) ? currentPage : pageIndex].GetItem(index);
171 }
172
173 public HotItem SetItem(HotItem item, int index = -1, int pageIndex = -1, bool refreshActor = false)
174 {
175 if (item == null)
176 {
178 }
179 if (pageIndex == -1)
180 {
181 pageIndex = currentPage;
182 }
183 if (pageIndex >= pages.Count)
184 {
185 AddPage();
186 pageIndex = pages.Count - 1;
187 }
188 Page page = pages[pageIndex];
189 ValidatePage(page, index + 1);
190 page.SetItem(this, item, index);
191 item?.OnAddedToBar();
192 if (refreshActor && (bool)actor)
193 {
195 }
196 return item;
197 }
198
199 public void Select(HotItem item)
200 {
201 SE.SelectHotitem();
203 }
204
206 {
207 item.disabled = !item.disabled;
208 if (item.disabled)
209 {
210 item.OnUnselect();
211 }
212 SE.SelectHotitem();
213 EClass.player.SetCurrentHotItem(item.disabled ? null : item);
214 }
215
216 public void Unselect(int pageIndex = -1)
217 {
218 if (pageIndex == -1)
219 {
220 pageIndex = currentPage;
221 }
222 HotItem selectedItem = pages[pageIndex].SelectedItem;
223 pages[pageIndex].selected = -1;
224 selectedItem?.OnUnselect();
226 }
227
229 {
230 int selected = pages[currentPage].selected;
231 if (selected == -1)
232 {
233 return null;
234 }
235 return pages[currentPage].items[selected];
236 }
237
238 public int GetNextSelectableIndex(int pageIndex = -1)
239 {
240 if (pageIndex == -1)
241 {
242 pageIndex = currentPage;
243 }
244 Page page = pages[pageIndex];
245 int num = page.selected + 1;
246 if (num >= itemsPerPage)
247 {
248 num = -1;
249 }
250 ValidatePage(page);
251 return num;
252 }
253
254 public int GetPrevSelectableIndex(int pageIndex = -1)
255 {
256 if (pageIndex == -1)
257 {
258 pageIndex = currentPage;
259 }
260 Page page = pages[pageIndex];
261 int num = page.selected - 1;
262 if (num < -1)
263 {
264 num = itemsPerPage - 1;
265 }
266 ValidatePage(page);
267 return num;
268 }
269}
Definition: EClass.cs:5
static Player player
Definition: EClass.cs:12
virtual void OnUnselect()
Definition: HotItem.cs:87
int selected
Definition: Hotbar.cs:19
List< HotItem > items
Definition: Hotbar.cs:16
HotItem GetItem(int index)
Definition: Hotbar.cs:57
void SetItem(Hotbar h, HotItem item, int index)
Definition: Hotbar.cs:33
HotItem SelectedItem
Definition: Hotbar.cs:22
Definition: Hotbar.cs:5
const int IDSpeed
Definition: Hotbar.cs:75
int GetPrevSelectableIndex(int pageIndex=-1)
Definition: Hotbar.cs:254
HotItem GetItem(int index, int pageIndex=-1)
Definition: Hotbar.cs:168
void Select(HotItem item)
Definition: Hotbar.cs:199
HotItem DefaultItem
Definition: Hotbar.cs:97
void ToggleDisable(HotItem item)
Definition: Hotbar.cs:205
HotItem GetSelectedItem()
Definition: Hotbar.cs:228
const int IDMainMenu
Definition: Hotbar.cs:67
const int IDUser3
Definition: Hotbar.cs:73
bool IsUserHotbar
Definition: Hotbar.cs:102
Type
Definition: Hotbar.cs:7
void ValidatePage(Page page, int num=-1)
Definition: Hotbar.cs:133
const int IDUser2
Definition: Hotbar.cs:71
int itemsPerPage
Definition: Hotbar.cs:81
void SetSlotNum(int a)
Definition: Hotbar.cs:117
int GetNextSelectableIndex(int pageIndex=-1)
Definition: Hotbar.cs:238
void Remove(HotItem item)
Definition: Hotbar.cs:154
List< Page > pages
Definition: Hotbar.cs:87
Page CurrentPage
Definition: Hotbar.cs:115
void Unselect(int pageIndex=-1)
Definition: Hotbar.cs:216
bool ShowFunctionKey
Definition: Hotbar.cs:113
bool dirty
Definition: Hotbar.cs:89
void AddPage()
Definition: Hotbar.cs:126
HotbarManager manager
Definition: Hotbar.cs:93
int currentPage
Definition: Hotbar.cs:78
bool IsLocked
Definition: Hotbar.cs:99
HotItem SetItem(HotItem item, int index=-1, int pageIndex=-1, bool refreshActor=false)
Definition: Hotbar.cs:173
WidgetHotbar actor
Definition: Hotbar.cs:91
int id
Definition: Hotbar.cs:84
void SetPage(int pageIndex)
Definition: Hotbar.cs:149
const int IDBuild
Definition: Hotbar.cs:69
HotItem SelectedItem
Definition: Hotbar.cs:95
HotbarManager hotbars
Definition: Player.cs:886
void SetCurrentHotItem(HotItem item)
Definition: Player.cs:2046
void RebuildPage(int page=-1)