Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ButtonAbility.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using UnityEngine.EventSystems;
4using UnityEngine.UI;
5
7{
9
11
13
14 public Image imageType;
15
16 public Image imageFav;
17
18 public Transform attach;
19
20 public Transform transFav;
21
22 public Chara chara;
23
24 public Act act;
25
26 [NonSerialized]
27 public bool dragged;
28
29 public static Act hotkeyAct;
30
31 public static float hotkeyTimer;
32
33 public static bool usedMouseKey;
34
35 public static bool lockUse;
36
37 public void SetAct(Chara _chara, Element e)
38 {
39 source = e.source;
40 chara = _chara;
42 if (act == null)
43 {
44 Debug.Log(source.alias);
45 }
46 Sprite iconType = act.TargetType.IconType;
47 imageType.SetActive(iconType);
48 imageType.sprite = iconType;
51 {
52 textStock.SetActive(e is Spell);
53 textStock.text = e.vPotential.ToShortNumber();
54 onRightClick = delegate
55 {
56 if (EClass.ui.IsActive)
57 {
58 SE.BeepSmall();
59 }
60 else
61 {
62 Use();
63 }
64 };
65 }
66 else
67 {
69 }
70 SetTooltip("note", delegate(UITooltip t)
71 {
72 e.WriteNote(t.note, chara.elements, delegate
73 {
74 e._WriteNote(t.note, chara, act);
75 });
76 });
78 }
79
80 public void OnDrag(PointerEventData data)
81 {
82 if (dragParent != null && data.button == PointerEventData.InputButton.Left)
83 {
84 if (!dragged)
85 {
86 dragged = true;
89 }
90 else
91 {
92 dragParent.OnDrag(this);
93 }
94 }
95 }
96
97 public override void OnPointerUp(PointerEventData eventData)
98 {
99 if (dragged)
100 {
101 dragged = false;
102 dragParent.OnEndDrag(this);
103 }
104 else
105 {
106 base.OnPointerUp(eventData);
107 }
108 }
109
110 public void Use()
111 {
112 if (!EClass.pc.HasNoGoal)
113 {
114 SE.BeepSmall();
115 }
116 else if (CanAutoUse(act))
117 {
118 if (TryUse(act) && EClass.pc.ai.IsNoGoal)
119 {
121 }
122 }
123 else
124 {
125 HoldAbility();
126 }
127 }
128
129 public static bool TryUse(Act act, Card tg = null, Point pos = null, Card catalyst = null, bool first = true, bool mouse = true)
130 {
131 if (lockUse && first)
132 {
133 return false;
134 }
135 bool flag = false;
136 if (tg == null)
137 {
138 tg = EClass.pc;
139 }
140 if (pos == null)
141 {
142 pos = EClass.pc.pos.Copy();
143 }
144 if (first)
145 {
146 lockUse = true;
147 hotkeyAct = act;
148 if (EInput.GetHotkey() != -1)
149 {
150 mouse = false;
151 hotkeyTimer = 0f;
152 }
153 else
154 {
156 }
157 }
159 {
160 if ((mouse && EInput.rightMouse.pressedLong) || (!mouse && hotkeyTimer >= 0.45f))
161 {
163 flag = true;
164 hotkeyTimer = 1f;
165 }
166 if ((mouse && EInput.rightMouse.pressing) || (!mouse && EInput.GetHotkey() != -1 && hotkeyTimer < 1f))
167 {
169 EClass.core.actionsNextFrame.Add(delegate
170 {
171 TryUse(act, tg, pos, catalyst, first: false, mouse);
172 });
173 if (first)
174 {
175 EClass.core.actionsNextFrame.Add(delegate
176 {
177 EInput.rightMouse.down = false;
178 EInput.rightMouse.consumed = false;
179 EInput.rightMouse.pressing = true;
180 if (usedMouseKey)
181 {
182 EInput.rightMouse.usedKey = true;
183 }
184 else
185 {
186 EInput.rightMouse.usedMouse = true;
187 }
188 });
189 }
190 return false;
191 }
192 }
193 lockUse = false;
194 if (flag && SpecialHoldAction(act))
195 {
197 }
198 else if (EClass.pc.UseAbility(act.source.alias, tg, pos, flag))
199 {
201 }
202 if (catalyst != null)
203 {
204 LayerInventory.SetDirty(catalyst.Thing);
205 }
206 return false;
207 }
208
209 public static bool SpecialHoldAction(Act act)
210 {
211 if (!(EClass.pc.elements.GetElement(act.id) is Act { id: var id } act2))
212 {
213 return false;
214 }
215 if (id == 8230 || id == 8232)
216 {
217 bool flag = true;
218 int num = 0;
219 foreach (Thing item in EClass.pc.things.List((Thing t) => true, onlyAccessible: true))
220 {
221 if (!item.IsIdentified)
222 {
223 if ((EClass.pc.mana.value < act2.GetCost(EClass.pc).cost && !flag) || act2.vPotential <= 0)
224 {
225 break;
226 }
227 if (item.rarity < Rarity.Mythical || act2.id != 8230)
228 {
230 num++;
231 flag = false;
232 }
233 }
234 }
235 if (num == 0)
236 {
237 Msg.Say("identify_nothing");
238 }
239 return true;
240 }
241 return false;
242 }
243
244 public void HoldAbility()
245 {
247 SE.SelectHotitem();
248 }
249
250 public bool CanAutoUse(Act _act)
251 {
252 if (_act.TargetType.CanSelectSelf)
253 {
255 {
256 return !_act.LocalAct;
257 }
258 return true;
259 }
260 return false;
261 }
262
263 public bool ShowMouseHintLeft()
264 {
265 return false;
266 }
267
268 public string GetTextMouseHintLeft()
269 {
270 return "";
271 }
272
273 public bool ShowMouseHintRight()
274 {
275 return CanAutoUse(ACT.Create(source));
276 }
277
278 public string GetTextMouseHintRight()
279 {
280 return "actUse".lang();
281 }
282
283 public override bool CanMiddleClick()
284 {
285 return EClass.ui.AllowInventoryInteractions;
286 }
287
288 public override void OnMiddleClick(bool forceClick)
289 {
291 {
292 ToggleFav();
293 }
294 EInput.middleMouse.pressedLongAction = delegate
295 {
296 if (EClass.ui.AllowInventoryInteractions)
297 {
298 HoldAbility();
299 EInput.Consume();
300 }
301 };
302 }
303
304 public void ToggleFav()
305 {
306 if (EClass.player.favAbility.Contains(source.id))
307 {
308 EClass.player.favAbility.Remove(source.id);
309 SE.Tab();
310 }
311 else
312 {
314 SE.Tab();
315 }
318 }
319
320 public void RefreshFavIcon()
321 {
322 bool enable = EClass.player.favAbility.Contains(source.id);
323 imageFav.SetActive(enable);
324 }
325}
Rarity
Definition: Rarity.cs:2
Definition: ACT.cs:6
static Act Create(int id)
Definition: ACT.cs:36
virtual bool IsNoGoal
Definition: AIAct.cs:74
Definition: ACT.cs:62
virtual bool LocalAct
Definition: ACT.cs:169
virtual TargetType TargetType
Definition: ACT.cs:140
virtual bool HaveLongPressAction
Definition: ACT.cs:131
new void SetImage(Image image)
Definition: ACT.cs:452
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
static Act hotkeyAct
static bool usedMouseKey
static float hotkeyTimer
Transform transFav
UIText textStock
static bool lockUse
void SetAct(Chara _chara, Element e)
void OnDrag(PointerEventData data)
bool ShowMouseHintRight()
void RefreshFavIcon()
SourceElement.Row source
Definition: ButtonAbility.cs:8
IDragParent dragParent
Transform attach
override bool CanMiddleClick()
static bool TryUse(Act act, Card tg=null, Point pos=null, Card catalyst=null, bool first=true, bool mouse=true)
bool CanAutoUse(Act _act)
void HoldAbility()
string GetTextMouseHintLeft()
bool ShowMouseHintLeft()
static bool SpecialHoldAction(Act act)
override void OnMiddleClick(bool forceClick)
override void OnPointerUp(PointerEventData eventData)
string GetTextMouseHintRight()
bool usedKey
Definition: ButtonState.cs:55
bool pressing
Definition: ButtonState.cs:35
bool clicked
Definition: ButtonState.cs:37
void Consume()
Definition: ButtonState.cs:184
bool pressedLong
Definition: ButtonState.cs:64
Definition: Card.cs:11
ElementContainerCard elements
Definition: Card.cs:37
Point pos
Definition: Card.cs:55
ThingContainer things
Definition: Card.cs:34
Definition: Chara.cs:10
bool UseAbility(string idAct, Card tc=null, Point pos=null, bool pt=false)
Definition: Chara.cs:5228
AIAct ai
Definition: Chara.cs:187
Stats mana
Definition: Chara.cs:963
bool HasNoGoal
Definition: Chara.cs:821
Definition: Core.cs:14
static float delta
Definition: Core.cs:17
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static Core core
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:20
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static UI ui
Definition: EClass.cs:16
Definition: EInput.cs:8
static ButtonState middleMouse
Definition: EInput.cs:353
static void Consume(int _skipFrame)
Definition: EInput.cs:656
static ButtonState rightMouse
Definition: EInput.cs:351
static int GetHotkey()
Definition: EInput.cs:975
Element GetElement(string alias)
int id
Definition: ELEMENT.cs:240
SourceElement.Row source
Definition: ELEMENT.cs:263
int vPotential
Definition: ELEMENT.cs:246
virtual string Name
Definition: ELEMENT.cs:294
void WriteNote(UINote n, ElementContainer owner=null, Action< UINote > onWriteNote=null)
Definition: ELEMENT.cs:574
bool altAbility
Definition: Game.cs:267
UIDynamicList list
Definition: LayerAbility.cs:25
static LayerAbility Instance
Definition: LayerAbility.cs:21
static void SetDirty(Thing t)
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
void EndTurn(bool consume=true)
Definition: Player.cs:1866
HashSet< int > favAbility
Definition: Player.cs:868
void SetCurrentHotItem(HotItem item)
Definition: Player.cs:2046
Definition: Point.cs:9
Point Copy()
Definition: Point.cs:467
virtual bool IsRegion
Definition: Spatial.cs:501
Definition: SPELL.cs:468
virtual int value
Definition: Stats.cs:56
virtual bool CanSelectSelf
Definition: TargetType.cs:37
virtual Sprite IconType
Definition: TargetType.cs:43
List< Thing > List(Func< Thing, bool > func, bool onlyAccessible=false)
Definition: Thing.cs:8
Image icon
Definition: UIButton.cs:110
UIText mainText
Definition: UIButton.cs:102
void SetTooltip(Action< UITooltip > onShowTooltip=null, bool enable=true)
Definition: UIButton.cs:361
Action onRightClick
Definition: UIButton.cs:146
Item item
Definition: UIButton.cs:172
void OnPointerUpOnDrag(PointerEventData eventData)
Definition: UIButton.cs:488
override void Redraw()
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159
UINote note
Definition: UITooltip.cs:21
void OnEndDrag(UIButton b, bool cancel=false)
void OnStartDrag(UIButton b)
void OnDrag(UIButton b)