Elin Modding Docs Doc
Loading...
Searching...
No Matches
WidgetCurrentTool.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.Events;
5using UnityEngine.UI;
6
7// Token: 0x020005F8 RID: 1528
9{
10 // Token: 0x06002A36 RID: 10806 RVA: 0x000ED900 File Offset: 0x000EBB00
11 public override object CreateExtra()
12 {
13 return new WidgetCurrentTool.Extra();
14 }
15
16 // Token: 0x17000C1D RID: 3101
17 // (get) Token: 0x06002A37 RID: 10807 RVA: 0x000ED907 File Offset: 0x000EBB07
18 public WidgetCurrentTool.Extra extra
19 {
20 get
21 {
22 return base.config.extra as WidgetCurrentTool.Extra;
23 }
24 }
25
26 // Token: 0x17000C1E RID: 3102
27 // (get) Token: 0x06002A38 RID: 10808 RVA: 0x000ED919 File Offset: 0x000EBB19
28 // (set) Token: 0x06002A39 RID: 10809 RVA: 0x000ED925 File Offset: 0x000EBB25
29 public int page
30 {
31 get
32 {
33 return EMono.player.hotbarPage;
34 }
35 set
36 {
37 EMono.player.hotbarPage = value;
38 }
39 }
40
41 // Token: 0x06002A3A RID: 10810 RVA: 0x000ED934 File Offset: 0x000EBB34
42 public override void OnActivate()
43 {
44 WidgetCurrentTool.Instance = this;
45 this._RefreshCurrentHotItem();
46 this.buttonHotItem.onClick.AddListener(new UnityAction(this.OnClickButtonHotItem));
47 this.buttonSwitchPage.SetOnClick(delegate
48 {
49 this.SwitchPage();
50 });
51 this.RebuildSlots();
52 WidgetCurrentTool.dirty = true;
53 this.placer.Refresh();
54 this.ApplySkin();
55 }
56
57 // Token: 0x06002A3B RID: 10811 RVA: 0x000ED9A0 File Offset: 0x000EBBA0
58 public void RebuildSlots()
59 {
60 this.imageHighlight.transform.SetParent(base.transform, false);
61 this.layout.cellSize = EMono.setting.ui.iconSizes[this.extra.iconSize];
62 SkinConfig skin = base.config.skin;
63 this.list.Clear();
64 this.list.callbacks = new UIList.Callback<Thing, ButtonGridDrag>
65 {
66 onRedraw = delegate(Thing a, ButtonGridDrag b, int i)
67 {
68 int num = i + 1;
69 b.subText2.SetText((num % 10).ToString() ?? "");
70 b.subText2.SetActive(this.extra.showShortcut);
71 b.index = i % 10 + 10 * this.page;
72 b.SetCardGrid(a, new InvOwnerHotbar(EMono.pc, null, CurrencyType.None)
73 {
74 index = i % 10 + 10 * this.page
75 });
76 }
77 };
78 for (int j = 0; j < this.maxSlots; j++)
79 {
80 this.list.Add(null);
81 }
82 this.list.onBeforeRedraw = delegate()
83 {
84 WidgetCurrentTool.dirty = false;
85 for (int i = 0; i < this.grid.Count; i++)
86 {
87 this.grid[i] = null;
88 }
89 foreach (Thing thing in EMono.pc.things)
90 {
91 if (thing.invY == 1 && thing.invX >= this.page * 10 && thing.invX < (this.page + 1) * 10)
92 {
93 if (thing.invX < 0 || thing.invX >= this.grid.Count)
94 {
95 Debug.Log(thing.Name + "/" + thing.invX.ToString());
96 }
97 else
98 {
99 this.grid[thing.invX] = thing;
100 }
101 }
102 }
103 for (int k = 0; k < this.list.buttons.Count; k++)
104 {
105 UIList.ButtonPair value = this.list.buttons[k];
106 value.obj = this.grid[k + this.page * 10];
107 this.list.buttons[k] = value;
108 }
109 this.buttonSwitchPage.mainText.text = ((this.page + 1).ToString() ?? "");
110 };
111 this.list.onAfterRedraw = delegate()
112 {
113 LayerInventory.TryShowGuide(this.list);
114 };
115 this.list.Refresh(false);
116 this.list.Redraw();
117 UIRawImage uirawImage = this.list.bgGrid as UIRawImage;
118 uirawImage.skinRoot = base.GetComponent<SkinRoot>();
119 uirawImage.color = skin.gridColor;
120 base.ClampToScreen();
121 this.RefreshHighlight();
122 }
123
124 // Token: 0x06002A3C RID: 10812 RVA: 0x000EDABC File Offset: 0x000EBCBC
125 private void Update()
126 {
127 this.CheckDirty();
128 }
129
130 // Token: 0x06002A3D RID: 10813 RVA: 0x000EDAC4 File Offset: 0x000EBCC4
131 public void CheckDirty()
132 {
133 if (WidgetCurrentTool.dirty)
134 {
135 this.list.Redraw();
136 this._RefreshCurrentHotItem();
137 }
138 WidgetCurrentTool.dirty = false;
139 }
140
141 // Token: 0x06002A3E RID: 10814 RVA: 0x000EDAE4 File Offset: 0x000EBCE4
142 public static void RefreshCurrentHotItem()
143 {
144 if (WidgetCurrentTool.Instance)
145 {
146 WidgetCurrentTool.Instance._RefreshCurrentHotItem();
147 }
148 }
149
150 // Token: 0x06002A3F RID: 10815 RVA: 0x000EDAFC File Offset: 0x000EBCFC
151 public void SwitchPage()
152 {
153 this.page = ((this.page == 0) ? 1 : 0);
154 this._RefreshCurrentHotItem();
155 WidgetCurrentTool.dirty = true;
156 this.CheckDirty();
157 this.placer.Refresh();
158 SE.Play("switch_hotbar");
159 }
160
161 // Token: 0x06002A40 RID: 10816 RVA: 0x000EDB38 File Offset: 0x000EBD38
162 public void _RefreshCurrentHotItem()
163 {
164 HotItem hotItem = EMono.player.currentHotItem;
165 if (hotItem == null)
166 {
167 hotItem = EMono.player.hotItemNoItem;
168 }
169 this.buttonHotItem.item = hotItem;
170 this.buttonHotItem.icon.material = (hotItem.UseUIObjMaterial ? EMono.core.refs.matUIObj : null);
171 hotItem.SetImage(this.buttonHotItem.icon);
172 this.buttonHotItem.interactable = true;
173 this.buttonHotItem.Refresh();
174 this.iconHeld.SetActive(hotItem is HotItemHeld);
175 this.RefreshHighlight();
176 }
177
178 // Token: 0x06002A41 RID: 10817 RVA: 0x000EDBD8 File Offset: 0x000EBDD8
179 public void OnClickButtonHotItem()
180 {
181 SE.SelectHotitem();
182 if (this.selected != -1 && EMono.player.currentHotItem.Thing == this.selectedButton.card)
183 {
184 this.Select(-1, false);
185 return;
186 }
187 int index = this.selected;
188 this.selected = -1;
189 this.Select(index, false);
190 }
191
192 // Token: 0x17000C1F RID: 3103
193 // (get) Token: 0x06002A42 RID: 10818 RVA: 0x000EDC2E File Offset: 0x000EBE2E
194 public ButtonGrid selectedButton
195 {
196 get
197 {
198 return this.list.buttons[this.selected].component as ButtonGrid;
199 }
200 }
201
202 // Token: 0x06002A43 RID: 10819 RVA: 0x000EDC50 File Offset: 0x000EBE50
203 public void ModSelected(int a)
204 {
205 SE.SelectHotitem();
206 int index = (a > 0) ? this.GetNextSelectableIndex() : this.GetPrevSelectableIndex();
207 this.Select(index, false);
208 }
209
210 // Token: 0x06002A44 RID: 10820 RVA: 0x000EDC80 File Offset: 0x000EBE80
211 public int GetNextSelectableIndex()
212 {
213 int num = this.selected + 1;
214 if (num >= this.maxSlots)
215 {
216 num = -1;
217 }
218 return num;
219 }
220
221 // Token: 0x06002A45 RID: 10821 RVA: 0x000EDCA4 File Offset: 0x000EBEA4
222 public int GetPrevSelectableIndex()
223 {
224 int num = this.selected - 1;
225 if (num <= -2)
226 {
227 num = this.maxSlots - 1;
228 }
229 return num;
230 }
231
232 // Token: 0x06002A46 RID: 10822 RVA: 0x000EDCC9 File Offset: 0x000EBEC9
233 public void Reselect()
234 {
235 this.Select(this.selected, false);
236 }
237
238 // Token: 0x06002A47 RID: 10823 RVA: 0x000EDCD8 File Offset: 0x000EBED8
239 public void Select(int index, bool fromHotkey = false)
240 {
241 if (index != -1 && fromHotkey && EMono.core.config.game.useAbilityOnHotkey)
242 {
243 ButtonGrid buttonGrid = this.list.buttons[index].component as ButtonGrid;
244 TraitAbility traitAbility = (buttonGrid.card != null) ? (buttonGrid.card.trait as TraitAbility) : null;
245 if (traitAbility != null && traitAbility.CanUse(EMono.pc))
246 {
247 if (EMono.player.CanAcceptInput() && traitAbility.OnUse(EMono.pc))
248 {
249 EMono.player.EndTurn(true);
250 }
251 return;
252 }
253 }
254 if (fromHotkey)
255 {
256 SE.SelectHotitem();
257 }
258 if (this.selected == index && this.selectedPage == this.page)
259 {
260 index = -1;
261 }
262 this.selected = index;
263 this.selectedPage = this.page;
264 if (this.selected >= this.maxSlots)
265 {
266 this.selected = -1;
267 }
268 if (this.selected == -1 || this.selectedButton.card == null)
269 {
270 EMono.player.ResetCurrentHotItem();
271 }
272 else
273 {
274 EMono.player.SetCurrentHotItem(this.selectedButton.card.trait.GetHotItem());
275 }
276 if (ActionMode.Adv.IsActive)
277 {
278 ActionMode.Adv.UpdatePlans();
279 }
280 this.RefreshHighlight();
281 }
282
283 // Token: 0x06002A48 RID: 10824 RVA: 0x000EDE20 File Offset: 0x000EC020
284 public void RefreshHighlight()
285 {
286 bool flag = this.selected != -1;
287 this.imageHighlight.SetActive(flag);
288 if (flag)
289 {
290 this.imageHighlight.transform.SetParent(this.selectedButton.transform, false);
291 this.imageHighlight.transform.position = this.selectedButton.transform.position;
292 this.imageHighlight.Rect().sizeDelta = this.selectedButton.Rect().sizeDelta;
293 this.imageHighlight.transform.SetAsFirstSibling();
294 this.imageHighlight.SetAlpha((EMono.player.currentHotItem.Thing == this.selectedButton.card) ? 1f : 0.35f);
295 }
296 }
297
298 // Token: 0x06002A49 RID: 10825 RVA: 0x000EDEEC File Offset: 0x000EC0EC
299 public override bool CanShowContextMenu()
300 {
301 ButtonGrid componentOf = InputModuleEX.GetComponentOf<ButtonGrid>();
302 return (!componentOf || !(componentOf != this.buttonHotItem)) && base.CanShowContextMenu();
303 }
304
305 // Token: 0x06002A4A RID: 10826 RVA: 0x000EDF20 File Offset: 0x000EC120
306 public override void OnSetContextMenu(UIContextMenu m)
307 {
308 InputModuleEX.GetComponentOf<ButtonHotItem>();
309 UIContextMenu uicontextMenu = m.AddChild("setting");
310 UIContextMenu uicontextMenu2 = m.AddChild("style");
311 uicontextMenu2.AddSlider("iconSize", (float n) => n.ToString() ?? "", (float)this.extra.iconSize, delegate(float a)
312 {
313 this.extra.iconSize = (int)a;
314 this.RebuildSlots();
315 }, 0f, (float)(EMono.setting.ui.iconSizes.Count - 1), true, true, false);
316 base.SetGridContextMenu(uicontextMenu2);
317 uicontextMenu.AddToggle("showShortcut", this.extra.showShortcut, delegate(bool a)
318 {
319 this.extra.showShortcut = a;
320 this.RebuildSlots();
321 });
322 base.SetBaseContextMenu(m);
323 }
324
325 // Token: 0x040017CE RID: 6094
326 public const int SlotsPerPage = 10;
327
328 // Token: 0x040017CF RID: 6095
329 public const int MaxPage = 2;
330
331 // Token: 0x040017D0 RID: 6096
332 public static WidgetCurrentTool Instance;
333
334 // Token: 0x040017D1 RID: 6097
335 public ButtonHotItem buttonHotItem;
336
337 // Token: 0x040017D2 RID: 6098
338 public UIButton buttonSwitchPage;
339
340 // Token: 0x040017D3 RID: 6099
341 public Image iconHeld;
342
343 // Token: 0x040017D4 RID: 6100
344 public Image imageHighlight;
345
346 // Token: 0x040017D5 RID: 6101
347 public UIList list;
348
349 // Token: 0x040017D6 RID: 6102
350 public static bool dirty;
351
352 // Token: 0x040017D7 RID: 6103
353 public int maxSlots = 9;
354
355 // Token: 0x040017D8 RID: 6104
356 public List<Thing> grid = new List<Thing>(new Thing[20]);
357
358 // Token: 0x040017D9 RID: 6105
359 public UIPlaceHelper placer;
360
361 // Token: 0x040017DA RID: 6106
362 public GridLayoutGroup layout;
363
364 // Token: 0x040017DB RID: 6107
365 public int selected = -1;
366
367 // Token: 0x040017DC RID: 6108
368 public int selectedPage;
369
370 // Token: 0x02000B67 RID: 2919
371 public class Extra
372 {
373 // Token: 0x04002DCC RID: 11724
374 public int iconSize;
375
376 // Token: 0x04002DCD RID: 11725
377 public bool showShortcut;
378
379 // Token: 0x04002DCE RID: 11726
380 public bool top;
381 }
382}
Definition EMono.cs:6
Definition Thing.cs:10