Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
WidgetCurrentTool.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
6{
7 public class Extra
8 {
9 public int iconSize;
10
11 public bool showShortcut;
12
13 public bool top;
14 }
15
16 public const int SlotsPerPage = 10;
17
18 public const int MaxPage = 2;
19
21
23
25
26 public Image iconHeld;
27
28 public Image imageHighlight;
29
30 public UIList list;
31
32 public static bool dirty;
33
34 public int maxSlots = 9;
35
36 public List<Thing> grid = new List<Thing>(new Thing[20]);
37
39
40 public GridLayoutGroup layout;
41
42 public Transform transHighlightSwitch;
43
44 public int selected = -1;
45
46 public int selectedPage;
47
48 public Extra extra => base.config.extra as Extra;
49
50 public int page
51 {
52 get
53 {
54 return EMono.player.hotbarPage;
55 }
56 set
57 {
58 EMono.player.hotbarPage = value;
59 }
60 }
61
63
64 public override object CreateExtra()
65 {
66 return new Extra();
67 }
68
69 public override void OnActivate()
70 {
72 Instance = this;
74 buttonHotItem.onClick.AddListener(OnClickButtonHotItem);
75 buttonSwitchPage.SetOnClick(delegate
76 {
78 {
79 EMono.player.flags.toggleHotbarHighlightDisabled = true;
80 transHighlightSwitch.SetActive(enable: false);
81 }
82 SwitchPage();
83 });
85 dirty = true;
87 ApplySkin();
88 }
89
90 public void RebuildSlots()
91 {
92 imageHighlight.transform.SetParent(base.transform, worldPositionStays: false);
93 layout.cellSize = EMono.setting.ui.iconSizes[extra.iconSize];
94 SkinConfig skin = base.config.skin;
95 list.Clear();
96 list.callbacks = new UIList.Callback<Thing, ButtonGridDrag>
97 {
98 onRedraw = delegate(Thing a, ButtonGridDrag b, int i)
99 {
100 int num = i + 1;
101 b.subText2.SetText((num % 10).ToString() ?? "");
102 b.subText2.SetActive(extra.showShortcut);
103 b.index = i % 10 + 10 * page;
105 {
106 index = i % 10 + 10 * page
107 });
108 }
109 };
110 for (int j = 0; j < maxSlots; j++)
111 {
112 list.Add(null);
113 }
114 list.onBeforeRedraw = delegate
115 {
116 dirty = false;
117 for (int k = 0; k < grid.Count; k++)
118 {
119 grid[k] = null;
120 }
121 foreach (Thing thing in EMono.pc.things)
122 {
123 if (thing.invY == 1 && thing.invX >= page * 10 && thing.invX < (page + 1) * 10)
124 {
125 if (thing.invX < 0 || thing.invX >= grid.Count)
126 {
127 Debug.Log(thing.Name + "/" + thing.invX);
128 }
129 else
130 {
131 grid[thing.invX] = thing;
132 }
133 }
134 }
135 for (int l = 0; l < list.buttons.Count; l++)
136 {
137 UIList.ButtonPair value = list.buttons[l];
138 value.obj = grid[l + page * 10];
139 list.buttons[l] = value;
140 }
141 buttonSwitchPage.mainText.text = (page + 1).ToString() ?? "";
142 };
143 list.onAfterRedraw = delegate
144 {
146 };
147 list.Refresh();
148 list.Redraw();
149 UIRawImage obj = list.bgGrid as UIRawImage;
150 obj.skinRoot = GetComponent<SkinRoot>();
151 obj.color = skin.gridColor;
154 }
155
156 private void Update()
157 {
158 CheckDirty();
159 }
160
161 public void CheckDirty()
162 {
163 if (dirty)
164 {
165 list.Redraw();
167 }
168 dirty = false;
169 }
170
171 public static void RefreshCurrentHotItem()
172 {
173 if ((bool)Instance)
174 {
176 }
177 }
178
179 public void SwitchPage()
180 {
181 page = ((page == 0) ? 1 : 0);
183 dirty = true;
184 CheckDirty();
185 placer.Refresh();
186 SE.Play("switch_hotbar");
187 }
188
190 {
192 if (hotItem == null)
193 {
194 hotItem = EMono.player.hotItemNoItem;
195 }
196 buttonHotItem.item = hotItem;
197 buttonHotItem.icon.material = (hotItem.UseUIObjMaterial ? EMono.core.refs.matUIObj : null);
198 hotItem.SetImage(buttonHotItem.icon);
199 buttonHotItem.interactable = true;
201 iconHeld.SetActive(hotItem is HotItemHeld);
203 }
204
206 {
207 SE.SelectHotitem();
209 {
210 Select(-1);
211 return;
212 }
213 int index = selected;
214 selected = -1;
215 Select(index);
216 }
217
218 public void ModSelected(int a)
219 {
220 SE.SelectHotitem();
221 int index = ((a > 0) ? GetNextSelectableIndex() : GetPrevSelectableIndex());
222 Select(index);
223 }
224
226 {
227 int num = selected + 1;
228 if (num >= maxSlots)
229 {
230 num = -1;
231 }
232 return num;
233 }
234
236 {
237 int num = selected - 1;
238 if (num <= -2)
239 {
240 num = maxSlots - 1;
241 }
242 return num;
243 }
244
245 public void Reselect()
246 {
248 }
249
250 public void Select(int index, bool fromHotkey = false)
251 {
252 if (index != -1 && fromHotkey && EMono.core.config.game.useAbilityOnHotkey)
253 {
254 ButtonGrid buttonGrid = list.buttons[index].component as ButtonGrid;
255 TraitAbility traitAbility = ((buttonGrid.card != null) ? (buttonGrid.card.trait as TraitAbility) : null);
256 if (traitAbility != null && traitAbility.CanUse(EMono.pc))
257 {
258 if (EMono.player.CanAcceptInput() && traitAbility.OnUse(EMono.pc))
259 {
261 }
262 return;
263 }
264 }
265 if (fromHotkey)
266 {
267 SE.SelectHotitem();
268 }
269 if (selected == index && selectedPage == page)
270 {
271 index = -1;
272 }
273 selected = index;
275 if (selected >= maxSlots)
276 {
277 selected = -1;
278 }
279 if (selected == -1 || selectedButton.card == null)
280 {
282 }
283 else
284 {
286 }
288 {
290 }
292 }
293
294 public void RefreshHighlight()
295 {
296 bool flag = selected != -1;
297 imageHighlight.SetActive(flag);
298 if (flag)
299 {
300 imageHighlight.transform.SetParent(selectedButton.transform, worldPositionStays: false);
301 imageHighlight.transform.position = selectedButton.transform.position;
302 imageHighlight.Rect().sizeDelta = selectedButton.Rect().sizeDelta;
303 imageHighlight.transform.SetAsFirstSibling();
305 }
306 }
307
308 public override bool CanShowContextMenu()
309 {
310 ButtonGrid componentOf = InputModuleEX.GetComponentOf<ButtonGrid>();
311 if ((bool)componentOf && componentOf != buttonHotItem)
312 {
313 return false;
314 }
315 return base.CanShowContextMenu();
316 }
317
318 public override void OnSetContextMenu(UIContextMenu m)
319 {
320 InputModuleEX.GetComponentOf<ButtonHotItem>();
321 UIContextMenu uIContextMenu = m.AddChild("setting");
322 UIContextMenu uIContextMenu2 = m.AddChild("style");
323 uIContextMenu2.AddSlider("iconSize", (float n) => n.ToString() ?? "", extra.iconSize, delegate(float a)
324 {
325 extra.iconSize = (int)a;
326 RebuildSlots();
327 }, 0f, EMono.setting.ui.iconSizes.Count - 1, isInt: true);
328 SetGridContextMenu(uIContextMenu2);
329 uIContextMenu.AddToggle("showShortcut", extra.showShortcut, delegate(bool a)
330 {
331 extra.showShortcut = a;
332 RebuildSlots();
333 });
335 }
336}
void UpdatePlans()
Definition: AM_Adv.cs:410
bool IsActive
Definition: ActionMode.cs:121
static AM_Adv Adv
Definition: ActionMode.cs:15
Card card
Definition: ButtonGrid.cs:24
void SetCardGrid(Card c, InvOwner owner=null)
Definition: ButtonGrid.cs:145
int invY
Definition: Card.cs:1831
string Name
Definition: Card.cs:2013
Trait trait
Definition: Card.cs:49
ThingContainer things
Definition: Card.cs:34
int invX
Definition: Card.cs:1819
new GameConfig game
Definition: CoreConfig.cs:596
CoreConfig config
Definition: Core.cs:70
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
List< Vector2 > iconSizes
Definition: GameSetting.cs:28
UISetting ui
Definition: GameSetting.cs:307
virtual void SetImage(Image icon)
Definition: HotItem.cs:91
virtual Thing Thing
Definition: HotItem.cs:38
static void TryShowGuide(UIList list)
bool toggleHotbarHighlightDisabled
Definition: Player.cs:378
Flags flags
Definition: Player.cs:895
void ResetCurrentHotItem()
Definition: Player.cs:2039
void EndTurn(bool consume=true)
Definition: Player.cs:1866
HotItem currentHotItem
Definition: Player.cs:901
HotItemNoItem hotItemNoItem
Definition: Player.cs:1030
bool CanAcceptInput()
Definition: Player.cs:2212
int hotbarPage
Definition: Player.cs:730
void SetCurrentHotItem(HotItem item)
Definition: Player.cs:2046
Color gridColor
Definition: SkinConfig.cs:79
Definition: Thing.cs:8
override bool CanUse(Chara c)
override bool OnUse(Chara c)
virtual HotItem GetHotItem()
Definition: Trait.cs:914
UIText subText2
Definition: UIButton.cs:106
Image icon
Definition: UIButton.cs:110
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)
UIContextMenu AddChild(string idLang, TextAnchor anchor)
Definition: UIList.cs:9
List< ButtonPair > buttons
Definition: UIList.cs:244
override void Clear()
Definition: UIList.cs:349
override void Add(object item)
Definition: UIList.cs:302
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:424
override void Redraw()
Definition: UIList.cs:740
void SetText(string s)
Definition: UIText.cs:159
static WidgetCurrentTool Instance
List< Thing > grid
Transform transHighlightSwitch
void Select(int index, bool fromHotkey=false)
GridLayoutGroup layout
override bool CanShowContextMenu()
static void RefreshCurrentHotItem()
override object CreateExtra()
UIPlaceHelper placer
ButtonHotItem buttonHotItem
override void OnSetContextMenu(UIContextMenu m)
override void OnActivate()
ButtonGrid selectedButton
Definition: Widget.cs:7
virtual void ApplySkin()
Definition: Widget.cs:556
void SetBaseContextMenu(UIContextMenu m)
Definition: Widget.cs:608
void SetGridContextMenu(UIContextMenu m)
Definition: Widget.cs:709
void ClampToScreen()
Definition: Widget.cs:437