Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
WidgetHotbar.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5using UnityEngine.UI;
6
8{
9 public class Extra
10 {
11 public int iconSize = 2;
12
13 public int width = 1;
14
15 public int rows;
16
17 public bool showShortcut;
18
19 public bool vertical;
20
21 public bool visible;
22
23 public bool alwaysShow;
24
25 public bool reverse;
26
27 public bool autoSize;
28 }
29
30 public static bool registering;
31
32 public static bool dirtyCurrentItem;
33
34 public static HotItem registeringItem;
35
37
39
41
42 public int idHotbar;
43
44 public GridLayoutGroup layout;
45
47
48 public RawImage imageGrid;
49
50 public Image imageSelect;
51
53
54 public bool useMask;
55
56 [NonSerialized]
57 public List<ButtonHotItem> buttons = new List<ButtonHotItem>();
58
59 private bool showThisWidget;
60
62
63 public Extra extra => base.config.extra as Extra;
64
66
67 public bool Visible
68 {
69 get
70 {
71 return extra.visible;
72 }
73 set
74 {
75 extra.visible = value;
76 }
77 }
78
79 public override bool ShowInBuildMode => extra.alwaysShow;
80
81 public bool IsHotbarSpeed => idHotbar == 7;
82
84
85 public override object CreateExtra()
86 {
87 return new Extra();
88 }
89
90 public override bool CanShowContextMenu()
91 {
93 {
94 ButtonHotItem componentOf = InputModuleEX.GetComponentOf<ButtonHotItem>();
95 if ((bool)componentOf && componentOf.item != null)
96 {
97 return true;
98 }
99 }
100 return base.CanShowContextMenu();
101 }
102
103 public override void OnActivate()
104 {
105 mold = layout.CreateMold<ButtonHotItem>();
106 if (idHotbar == 2)
107 {
108 HotBarMainMenu = this;
109 }
110 if (idHotbar == 3)
111 {
112 HotbarBuild = this;
113 }
114 if (idHotbar == 5)
115 {
116 HotbarExtra = this;
117 }
118 if (extra.rows == 0)
119 {
120 extra.rows = hotbar.itemsPerPage;
121 }
122 hotbar.actor = this;
123 Rebuild();
124 }
125
126 public override void OnChangeActionMode()
127 {
128 base.OnChangeActionMode();
129 if (hotbar.dirty)
130 {
131 hotbar.dirty = false;
132 Rebuild();
133 }
135 }
136
137 public void Rebuild()
138 {
139 buttons.Clear();
140 layout.cellSize = EMono.setting.ui.iconSizes[extra.iconSize];
141 layout.constraintCount = extra.width;
142 layout.constraint = (extra.vertical ? GridLayoutGroup.Constraint.FixedColumnCount : GridLayoutGroup.Constraint.FixedRowCount);
143 layout.startCorner = (extra.reverse ? GridLayoutGroup.Corner.LowerRight : GridLayoutGroup.Corner.UpperLeft);
144 int num = extra.rows;
145 if (extra.autoSize)
146 {
147 num = 0;
148 for (int i = 0; i < hotbar.CurrentPage.items.Count && hotbar.CurrentPage.items[i] != null; i++)
149 {
150 num++;
151 }
152 }
153 int num2 = (num - 1) / extra.width + 1;
154 int num3 = (extra.vertical ? extra.width : num2);
155 int num4 = (extra.vertical ? num2 : extra.width);
156 imageGrid.uvRect = new Rect(1f, 1f, num3, num4);
157 layout.DestroyChildren();
158 for (int j = 0; j < num; j++)
159 {
160 ButtonHotItem buttonHotItem = Util.Instantiate(mold, layout);
161 buttonHotItem.index = j;
162 buttonHotItem.mainText.text = ((j > 10) ? "" : ((j + 1).ToString() ?? ""));
163 buttonHotItem.widget = this;
164 buttons.Add(buttonHotItem);
165 if (useMask)
166 {
167 buttonHotItem.gameObject.AddComponent<RectMask2D>();
168 }
169 }
170 layout.RebuildLayout();
171 this.RebuildLayout();
172 RebuildPage();
173 }
174
175 public void RebuildPage(int page = -1)
176 {
177 hotbar.SetPage((page == -1) ? hotbar.currentPage : page);
178 foreach (ButtonHotItem button in buttons)
179 {
180 HotItem item = hotbar.GetItem(button.index);
181 button.SetItem(item);
182 }
183 SetVisible();
185 }
186
187 public static void RebuildPages()
188 {
189 foreach (Widget item in EMono.ui.widgets.list)
190 {
191 WidgetHotbar widgetHotbar = item as WidgetHotbar;
192 if ((bool)widgetHotbar)
193 {
194 widgetHotbar.RebuildPage();
195 }
196 }
197 }
198
199 public void SwitchPage()
200 {
201 SE.ClickGeneral();
202 RebuildPage((hotbar.currentPage == 0) ? 1 : 0);
203 }
204
205 public HotItem GetItem(int index)
206 {
207 return hotbar.CurrentPage.items.TryGet(index, returnNull: true);
208 }
209
210 public void TryUse(int index)
211 {
212 HotItem item = GetItem(index);
213 if (item == null)
214 {
215 SE.BeepSmall();
216 }
217 else
218 {
219 item.OnClick(item.button, hotbar);
220 }
221 }
222
224 {
225 UIContextMenu uIContextMenu = EMono.ui.CreateContextMenu();
226 SetShortcutMenu(b, uIContextMenu);
227 uIContextMenu.Show();
228 }
229
230 public override void OnSetContextMenu(UIContextMenu m)
231 {
232 ButtonHotItem b = InputModuleEX.GetComponentOf<ButtonHotItem>();
233 if (showThisWidget || !b || b.item == null || base.IsSealed || b.widget.hotbar.IsLocked)
234 {
235 showThisWidget = false;
236 _ = base.config.skin.Skin;
237 UIContextMenu uIContextMenu = m.AddChild("setting");
238 UIContextMenu uIContextMenu2 = m.AddChild("style");
239 if (!base.IsSealed)
240 {
241 uIContextMenu.AddSlider("numSlot", (float n) => n.ToString() ?? "", extra.rows, delegate(float a)
242 {
243 extra.rows = (int)a;
244 hotbar.SetSlotNum((int)a);
245 Rebuild();
247 }, 1f, 20f, isInt: true, hideOther: false);
248 }
249 uIContextMenu2.AddSlider("iconSize", (float n) => n.ToString() ?? "", extra.iconSize, delegate(float a)
250 {
251 extra.iconSize = (int)a;
252 Rebuild();
254 }, 0f, EMono.setting.ui.iconSizes.Count - 1, isInt: true);
255 SetGridContextMenu(uIContextMenu2);
256 uIContextMenu.AddToggle("vertical", extra.vertical, delegate(bool a)
257 {
258 extra.vertical = a;
259 Rebuild();
261 });
262 uIContextMenu.AddToggle("doubleBar", extra.width == 2, delegate(bool a)
263 {
264 extra.width = ((!a) ? 1 : 2);
265 Rebuild();
267 });
268 uIContextMenu.AddToggle("reverseOrder", extra.reverse, delegate(bool a)
269 {
270 extra.reverse = a;
271 Rebuild();
273 });
274 if (!base.IsSealed)
275 {
276 uIContextMenu.AddToggle("alwaysShow2", extra.alwaysShow, delegate(bool a)
277 {
278 extra.alwaysShow = a;
279 });
280 }
282 if (base.IsSealed)
283 {
284 return;
285 }
286 m.AddButton("resetHotbar", delegate
287 {
288 Dialog.YesNo("dialogResetHotbar", delegate
289 {
291 SE.Trash();
292 });
293 });
294 return;
295 }
296 m.AddButton("removeHotItem", delegate
297 {
298 hotbar.SetItem(null, b.index);
299 RebuildPage();
300 });
302 m.AddToggle("alwaysShow", b.item.always, delegate(bool on)
303 {
304 b.item.always = on;
305 });
306 m.AddButton("thisWidget", delegate
307 {
308 showThisWidget = true;
309 EMono.core.actionsNextFrame.Add(delegate
310 {
312 });
313 });
314 }
315
317 {
318 Action<UIContextMenu, HotItem> action = delegate(UIContextMenu _m, HotItem i)
319 {
320 _m.AddButton(i.Name, delegate
321 {
322 SetItem(b, i);
323 });
324 };
325 UIContextMenu arg = m.AddChild("layerShortcuts");
326 action(arg, new HotItemLayer
327 {
328 id = "LayerHelp"
329 });
330 action(arg, new HotItemLayer
331 {
332 id = "stash"
333 });
334 action(arg, new HotItemLayer
335 {
336 id = "LayerAbility"
337 });
338 action(arg, new HotItemLayer
339 {
340 id = "LayerChara"
341 });
342 action(arg, new HotItemLayer
343 {
344 id = "LayerJournal"
345 });
346 action(arg, new HotItemWidget
347 {
348 id = "Roster"
349 });
350 action(arg, new HotItemWidget
351 {
352 id = "Codex"
353 });
354 action(arg, new HotItemWidget
355 {
356 id = "Search"
357 });
358 action(arg, new HotItemWidget
359 {
360 id = "Tracker"
361 });
362 action(arg, new HotItemWidget
363 {
364 id = "Memo"
365 });
366 action(arg, new HotItemWidget
367 {
368 id = "QuestTracker"
369 });
370 arg = m.AddChild("utilShortcuts");
371 action(arg, new HotItemToggle
372 {
373 type = HotItemToggle.Type.ToggleNoRoof
374 });
375 action(arg, new HotItemToggle
376 {
377 type = HotItemToggle.Type.muteBGM
378 });
379 action(arg, new HotItemToggle
380 {
381 type = HotItemToggle.Type.showBalloon
382 });
383 action(arg, new HotItemActionAudoDump());
384 arg.AddButton("hotActionWidgetSet".lang(), delegate
385 {
386 SetItem(b, new HotItemWidgetSet().Register());
387 });
389 {
390 arg = m.AddChild("menuShortcuts");
391 action(arg, new HotItemContext
392 {
393 id = "system"
394 });
395 if ((bool)this == IsHotbarSpeed)
396 {
397 arg = m.AddChild("uniqueShortcuts");
398 action(arg, new HotItemSpeed
399 {
400 id = 0
401 });
402 action(arg, new HotItemSpeed
403 {
404 id = 1
405 });
406 action(arg, new HotItemSpeed
407 {
408 id = 2
409 });
410 action(arg, new HotItemSpeed
411 {
412 id = 3
413 });
414 }
415 }
416 arg = m.AddChild("specialShortcuts");
417 action(arg, new HotItemTogglePage());
418 action(arg, new HotItemToggleVisible());
419 m.AddButton("registerPos".lang(), delegate
420 {
422 {
423 zone = EMono.game.activeZone,
424 x = EMono.pc.pos.x,
425 y = EMono.pc.pos.z
426 });
427 });
428 m.AddButton("hotActionEQSet".lang(), delegate
429 {
430 SetItem(b, new HotItemEQSet().Register());
431 });
432 m.AddButton("hotActionSleep".lang(), delegate
433 {
434 SetItem(b, new HotItemActionSleep());
435 });
436 }
437
439 {
441 b.SetItem(item);
443 SetVisible();
444 }
445
446 public static void RefreshHighlights()
447 {
448 foreach (Widget item in EMono.ui.widgets.list)
449 {
450 WidgetHotbar widgetHotbar = item as WidgetHotbar;
451 if ((bool)widgetHotbar)
452 {
453 widgetHotbar.RefreshHighlight();
454 }
455 }
456 }
457
458 public static void RefreshButtons()
459 {
460 foreach (Widget item in EMono.ui.widgets.list)
461 {
462 WidgetHotbar widgetHotbar = item as WidgetHotbar;
463 if (!widgetHotbar)
464 {
465 continue;
466 }
467 foreach (ButtonHotItem button in widgetHotbar.buttons)
468 {
469 button.RefreshItem();
470 }
471 }
472 }
473
474 public bool RefreshHighlight()
475 {
476 bool result = false;
477 foreach (ButtonHotItem button in buttons)
478 {
479 if (button.item == null)
480 {
481 continue;
482 }
483 if (button.item.UseIconForHighlight)
484 {
485 if (button.item.ShouldHighlight())
486 {
487 result = true;
488 button.icon.sprite = button.item.GetSprite(highlight: true);
489 }
490 else
491 {
492 button.icon.sprite = button.item.GetSprite();
493 }
494 }
495 else if (button.item.ShouldHighlight())
496 {
497 result = true;
498 button.image.sprite = button.item.SpriteHighlight;
500 {
502 }
503 }
504 else
505 {
506 button.image.sprite = EMono.core.refs.spritesHighlight[0];
507 }
508 }
509 return result;
510 }
511
512 public void _OnDirtyInventory()
513 {
514 foreach (ButtonHotItem button in buttons)
515 {
516 if (button.item != null)
517 {
518 button.Refresh();
519 }
520 }
521 }
522
523 public void SetVisible()
524 {
525 UIButton componentOf = InputModuleEX.GetComponentOf<UIButton>();
526 int num = 0;
527 bool flag = false;
528 foreach (ButtonHotItem button in buttons)
529 {
530 bool flag2 = button.item is HotItemToggleVisible;
531 bool flag3 = Visible || flag2 || (button.item != null && button.item.always);
532 button.image.enabled = flag3;
533 button.mainText.enabled = flag3;
534 button.icon.SetActive(flag3);
535 if (!flag2 && button != componentOf)
536 {
537 button.DoNormalTransition();
538 }
539 if (flag3)
540 {
541 num++;
542 }
543 if (flag2)
544 {
545 flag = true;
546 }
547 }
548 if (num == 0 && !Visible)
549 {
550 Visible = true;
551 SetVisible();
552 }
553 CancelInvoke("CheckAutoHide");
554 if (flag)
555 {
557 InvokeRepeating("CheckAutoHide", 0.1f, 0.2f);
558 }
559 Image image = imageBG;
560 bool flag4 = (imageGrid.enabled = extra.visible);
561 image.enabled = flag4;
562 dragPanel.SetActive(extra.visible);
563 }
564
565 public void ToggleVisible()
566 {
567 extra.visible = !extra.visible;
568 SetVisible();
569 if (!Visible)
570 {
571 return;
572 }
573 imageBG.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
574 imageBG.transform.DOScale(1f, 0.12f).SetEase(Ease.Linear);
575 imageGrid.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
576 imageGrid.transform.DOScale(1f, 0.12f).SetEase(Ease.Linear);
577 foreach (ButtonHotItem button in buttons)
578 {
579 if (!(button.item is HotItemToggleVisible) && (button.item == null || !button.item.always))
580 {
581 button.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
582 button.transform.DOScale(1f, 0.12f).SetEase(Ease.Linear);
583 }
584 }
585 imageBG.SetAlpha(0f);
586 imageGrid.SetAlpha(0f);
587 SkinConfig skin = base.config.skin;
588 imageBG.DOFade(skin.bgColor.a, 0.4f).SetEase(Ease.OutQuint);
589 imageGrid.DOFade(skin.gridColor.a, 0.4f).SetEase(Ease.OutQuint);
590 }
591
592 public void CheckAutoHide()
593 {
594 if (!Visible)
595 {
596 return;
597 }
599 if (timeSinceBecomeVisible < 1f)
600 {
601 return;
602 }
603 if (Input.GetMouseButton(0) || EMono.ui.contextMenu.currentMenu != null || registering)
604 {
606 return;
607 }
608 if (InputModuleEX.IsPointerOver(base.transform))
609 {
611 return;
612 }
613 foreach (ButtonHotItem button in buttons)
614 {
615 if (button.item != null && button.item.KeepVisibleWhenHighlighted && button.item.ShouldHighlight())
616 {
617 return;
618 }
619 }
621 }
622
623 public void OnStartDrag(UIButton b)
624 {
625 EMono.ui.hud.SetDragImage(b.icon);
626 }
627
628 public void OnDrag(UIButton b)
629 {
630 string text = "";
631 if ((bool)GetSwapButton(b))
632 {
633 text = "hotitemSwap";
634 }
635 else if (!EMono.ui.isPointerOverUI)
636 {
637 text = "hotitemTrash";
638 }
639 EMono.ui.hud.SetDragText(text);
640 }
641
643 {
644 foreach (Widget item in EMono.ui.widgets.list)
645 {
646 WidgetHotbar widgetHotbar = item as WidgetHotbar;
647 if (widgetHotbar == null)
648 {
649 continue;
650 }
651 foreach (ButtonHotItem button in widgetHotbar.buttons)
652 {
653 if (InputModuleEX.IsPointerOver(button) && b != button)
654 {
655 return button;
656 }
657 }
658 }
659 return null;
660 }
661
662 public void OnEndDrag(UIButton b, bool cancel = false)
663 {
664 EMono.ui.hud.imageDrag.SetActive(enable: false);
665 ButtonHotItem swapButton = GetSwapButton(b);
666 if ((bool)swapButton)
667 {
668 SE.SelectHotitem();
669 ButtonHotItem buttonHotItem = b as ButtonHotItem;
670 HotItem hotItem = (HotItem)swapButton.item;
671 HotItem hotItem2 = (HotItem)buttonHotItem.item;
672 Hotbar hotbar = swapButton.widget.hotbar;
673 Hotbar hotbar2 = buttonHotItem.widget.hotbar;
674 hotbar.actor.SetItem(swapButton, hotItem2);
675 hotbar2.actor.SetItem(buttonHotItem, hotItem);
676 if (hotItem != null)
677 {
678 hotItem.button = buttonHotItem;
679 hotItem.hotbar = hotbar2;
680 }
681 if (hotItem2 != null)
682 {
683 hotItem2.button = swapButton;
684 hotItem2.hotbar = hotbar;
685 }
687 }
688 else if (EMono.ui.isPointerOverUI)
689 {
690 SE.Beep();
691 }
692 else
693 {
694 SE.Trash();
695 SetItem(b as ButtonHotItem, null);
697 }
698 }
699}
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
void SetItem(GridItem i)
Definition: ButtonGrid.cs:398
WidgetHotbar widget
override void RefreshItem()
new int index
Definition: ButtonHotItem.cs:8
Point pos
Definition: Card.cs:55
List< Sprite > spritesHighlight
Definition: CoreRef.cs:355
CoreRef refs
Definition: Core.cs:51
CoreConfig config
Definition: Core.cs:70
Definition: Dialog.cs:7
static Dialog YesNo(string langDetail, Action actionYes, Action actionNo=null, string langYes="yes", string langNo="no")
Definition: Dialog.cs:244
Definition: EMono.cs:4
static GameSetting setting
Definition: EMono.cs:31
static Core core
Definition: EMono.cs:5
static Chara pc
Definition: EMono.cs:13
static Player player
Definition: EMono.cs:11
static Game game
Definition: EMono.cs:7
static UI ui
Definition: EMono.cs:15
List< Vector2 > iconSizes
Definition: GameSetting.cs:28
UISetting ui
Definition: GameSetting.cs:307
Zone activeZone
Definition: Game.cs:245
Hotbar[] bars
Definition: HotbarManager.cs:6
void ResetHotbar(int id)
Definition: HotbarManager.cs:8
List< HotItem > items
Definition: Hotbar.cs:16
Definition: Hotbar.cs:5
HotItem GetItem(int index, int pageIndex=-1)
Definition: Hotbar.cs:168
bool IsUserHotbar
Definition: Hotbar.cs:102
Type
Definition: Hotbar.cs:7
int itemsPerPage
Definition: Hotbar.cs:81
void SetSlotNum(int a)
Definition: Hotbar.cs:117
Page CurrentPage
Definition: Hotbar.cs:115
bool dirty
Definition: Hotbar.cs:89
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
static bool IsPointerOver(Component c)
HotbarManager hotbars
Definition: Player.cs:886
int x
Definition: Point.cs:36
Color bgColor
Definition: SkinConfig.cs:67
Color gridColor
Definition: SkinConfig.cs:79
virtual string Name
Definition: UIButton.cs:19
virtual bool ShouldHighlight()
Definition: UIButton.cs:51
virtual bool KeepVisibleWhenHighlighted
Definition: UIButton.cs:31
virtual Sprite SpriteHighlight
Definition: UIButton.cs:21
virtual bool UseIconForHighlight
Definition: UIButton.cs:29
virtual Sprite GetSprite()
Definition: UIButton.cs:41
virtual void OnShowContextMenu(UIContextMenu m)
Definition: UIButton.cs:60
bool always
Definition: UIButton.cs:15
Image icon
Definition: UIButton.cs:110
static List< UIButton > buttons
Definition: UIButton.cs:182
void DoNormalTransition(bool instant=true)
Definition: UIButton.cs:531
Item item
Definition: UIButton.cs:172
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)
void AddButton(Func< string > funcText, UnityAction action=null)
UIContextMenu AddChild(string idLang, TextAnchor anchor)
static void RefreshAllList()
Definition: UIInventory.cs:198
void SetVisible()
override object CreateExtra()
Definition: WidgetHotbar.cs:85
void RebuildPage(int page=-1)
static WidgetHotbar HotBarMainMenu
Definition: WidgetHotbar.cs:38
RawImage imageGrid
Definition: WidgetHotbar.cs:48
ButtonHotItem GetSwapButton(UIButton b)
void OnClickEmptyItem(ButtonHotItem b)
void Rebuild()
ButtonHotItem mold
Definition: WidgetHotbar.cs:46
void OnDrag(UIButton b)
void SetShortcutMenu(ButtonHotItem b, UIContextMenu m)
void OnEndDrag(UIButton b, bool cancel=false)
bool showThisWidget
Definition: WidgetHotbar.cs:59
void SetItem(ButtonHotItem b, HotItem item)
static void RefreshHighlights()
void SwitchPage()
HotItem GetItem(int index)
GridLayoutGroup layout
Definition: WidgetHotbar.cs:44
bool RefreshHighlight()
override void OnActivate()
override void OnSetContextMenu(UIContextMenu m)
Hotbar hotbar
Definition: WidgetHotbar.cs:65
void CheckAutoHide()
static bool dirtyCurrentItem
Definition: WidgetHotbar.cs:32
Hotbar.Type type
Definition: WidgetHotbar.cs:52
float timeSinceBecomeVisible
Definition: WidgetHotbar.cs:61
static HotItem registeringItem
Definition: WidgetHotbar.cs:34
void ToggleVisible()
static bool registering
Definition: WidgetHotbar.cs:30
static WidgetHotbar HotbarExtra
Definition: WidgetHotbar.cs:40
bool CanRegisterItem
Definition: WidgetHotbar.cs:83
Image imageSelect
Definition: WidgetHotbar.cs:50
void TryUse(int index)
void OnStartDrag(UIButton b)
override bool CanShowContextMenu()
Definition: WidgetHotbar.cs:90
bool IsHotbarSpeed
Definition: WidgetHotbar.cs:81
override bool ShowInBuildMode
Definition: WidgetHotbar.cs:79
static void RebuildPages()
override void OnChangeActionMode()
List< ButtonHotItem > buttons
Definition: WidgetHotbar.cs:57
static WidgetHotbar HotbarBuild
Definition: WidgetHotbar.cs:36
static void RefreshButtons()
void _OnDirtyInventory()
Definition: Widget.cs:7
void ShowContextMenu()
Definition: Widget.cs:601
void SetBaseContextMenu(UIContextMenu m)
Definition: Widget.cs:608
void SetGridContextMenu(UIContextMenu m)
Definition: Widget.cs:709
UIDragPanel dragPanel
Definition: Widget.cs:154
void ClampToScreen()
Definition: Widget.cs:437
Image imageBG
Definition: Widget.cs:150