11 public override object CreateExtra()
33 return EMono.player.hotbarPage;
37 EMono.player.hotbarPage = value;
42 public override void OnActivate()
44 WidgetCurrentTool.Instance =
this;
45 this._RefreshCurrentHotItem();
46 this.buttonHotItem.onClick.AddListener(
new UnityAction(this.OnClickButtonHotItem));
47 this.buttonSwitchPage.SetOnClick(delegate
52 WidgetCurrentTool.dirty =
true;
53 this.placer.Refresh();
58 public void RebuildSlots()
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;
69 b.subText2.SetText((num % 10).ToString() ??
"");
70 b.subText2.SetActive(this.extra.showShortcut);
71 b.index = i % 10 + 10 * this.page;
74 index = i % 10 + 10 * this.page
78 for (
int j = 0; j < this.maxSlots; j++)
82 this.list.onBeforeRedraw = delegate()
84 WidgetCurrentTool.dirty =
false;
85 for (
int i = 0; i < this.grid.Count; i++)
91 if (thing.invY == 1 && thing.invX >=
this.page * 10 && thing.invX < (
this.page + 1) * 10)
93 if (thing.invX < 0 || thing.invX >=
this.grid.Count)
95 Debug.Log(thing.Name +
"/" + thing.invX.ToString());
99 this.grid[thing.invX] = thing;
103 for (
int k = 0; k < this.list.buttons.Count; k++)
105 UIList.ButtonPair value = this.list.buttons[k];
106 value.obj = this.grid[k + this.page * 10];
107 this.list.buttons[k] = value;
109 this.buttonSwitchPage.mainText.text = ((this.page + 1).ToString() ??
"");
111 this.list.onAfterRedraw = delegate()
115 this.list.Refresh(
false);
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();
125 private void Update()
131 public void CheckDirty()
136 this._RefreshCurrentHotItem();
138 WidgetCurrentTool.dirty =
false;
142 public static void RefreshCurrentHotItem()
151 public void SwitchPage()
153 this.page = ((this.page == 0) ? 1 : 0);
154 this._RefreshCurrentHotItem();
155 WidgetCurrentTool.dirty =
true;
157 this.placer.Refresh();
158 SE.Play(
"switch_hotbar");
162 public void _RefreshCurrentHotItem()
167 hotItem =
EMono.player.hotItemNoItem;
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();
175 this.RefreshHighlight();
179 public void OnClickButtonHotItem()
182 if (this.selected != -1 &&
EMono.player.currentHotItem.Thing ==
this.selectedButton.card)
184 this.Select(-1,
false);
187 int index = this.selected;
189 this.Select(index,
false);
198 return this.list.buttons[this.selected].component as
ButtonGrid;
203 public void ModSelected(
int a)
206 int index = (a > 0) ? this.GetNextSelectableIndex() : this.GetPrevSelectableIndex();
207 this.Select(index,
false);
211 public int GetNextSelectableIndex()
213 int num = this.selected + 1;
214 if (num >= this.maxSlots)
222 public int GetPrevSelectableIndex()
224 int num = this.selected - 1;
227 num = this.maxSlots - 1;
233 public void Reselect()
235 this.Select(this.selected,
false);
239 public void Select(
int index,
bool fromHotkey =
false)
241 if (index != -1 && fromHotkey &&
EMono.core.config.game.useAbilityOnHotkey)
245 if (traitAbility !=
null && traitAbility.CanUse(
EMono.pc))
247 if (
EMono.player.CanAcceptInput() && traitAbility.OnUse(
EMono.pc))
249 EMono.player.EndTurn(
true);
258 if (this.selected == index && this.selectedPage == this.page)
262 this.selected = index;
263 this.selectedPage = this.page;
264 if (this.selected >= this.maxSlots)
268 if (this.selected == -1 || this.selectedButton.card ==
null)
270 EMono.player.ResetCurrentHotItem();
274 EMono.player.SetCurrentHotItem(this.selectedButton.card.trait.GetHotItem());
280 this.RefreshHighlight();
284 public void RefreshHighlight()
286 bool flag = this.selected != -1;
287 this.imageHighlight.SetActive(flag);
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);
299 public override bool CanShowContextMenu()
302 return (!componentOf || !(componentOf != this.buttonHotItem)) && base.CanShowContextMenu();
306 public override void OnSetContextMenu(UIContextMenu m)
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)
313 this.extra.iconSize = (int)a;
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)
319 this.extra.showShortcut = a;
322 base.SetBaseContextMenu(m);
326 public const int SlotsPerPage = 10;
329 public const int MaxPage = 2;
338 public UIButton buttonSwitchPage;
341 public Image iconHeld;
344 public Image imageHighlight;
350 public static bool dirty;
353 public int maxSlots = 9;
356 public List<Thing> grid =
new List<Thing>(
new Thing[20]);
362 public GridLayoutGroup layout;
365 public int selected = -1;
368 public int selectedPage;
377 public bool showShortcut;