-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolQuickShifter-functions.lua
More file actions
342 lines (315 loc) · 10.6 KB
/
Copy pathsolQuickShifter-functions.lua
File metadata and controls
342 lines (315 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
-- ////// functions
-- this file contains only own functions
function SQS_UpdateButtonDisplay()
-- called to update the buttons if skill is castable / available or not
-- local forms = GetNumShapeshiftForms(); --nope, only give me amount not the real IDs
local forms = 5
for i=1, forms do
texture = GetShapeshiftFormInfo(i);
if( texture == nil ) then
if i == 1 then SQS_BTN_1:Hide();
elseif i == 2 then SQS_BTN_2:Hide();
elseif i == 3 then SQS_BTN_3:Hide();
elseif i == 4 then SQS_BTN_4:Hide();
elseif i == 5 then SQS_BTN_5:Hide();
end;
else
if i == 1 then
SQS_BTN_1:Show();
SQS_BTN_1.Texture:SetDesaturated(SQS_CheckNoMana(i))
elseif i == 2 then
SQS_BTN_2:Show();
SQS_BTN_2.Texture:SetDesaturated(SQS_CheckNoMana(i));
elseif i == 3 then
SQS_BTN_3:Show();
SQS_BTN_3.Texture:SetDesaturated(SQS_CheckNoMana(i));
elseif i == 4 then
SQS_BTN_4:Show();
SQS_BTN_4.Texture:SetDesaturated(SQS_CheckNoMana(i));
elseif i == 5 then
SQS_BTN_5:Show();
SQS_BTN_5.Texture:SetDesaturated(SQS_CheckNoMana(i));
end;
end
end
-- check GCD Function for casting or Global Cooldown
-- If so show the warning
if SQS.GCD == true then
if SQS_IsGlobalCooldown() == true then
solQuickShifterFrameGCD:Show()
else
solQuickShifterFrameGCD:Hide()
end
end
-- Mounted Check
if IsMounted() then
SQS_BTN_9:Hide();
SQS_BTN_10:Show();
SQS_debug("M")
else
local MountExists, _ = SQS_GetMountName()
if GetShapeshiftForm() == 0 and MountExists then
-- not Mounted and in Humanoid form
SQS_BTN_9:Hide();
SQS_BTN_10:Show();
SQS_debug("NM:H")
else
-- not Monunted but shapeshifted
SQS_BTN_9:Show();
SQS_BTN_10:Hide();
SQS_debug("NM:S")
end
-- SQS_debug("NOT mounted")
end
end
function SQS_CheckNoMana(FormNum)
-- checking if the spell is actually castable atm
-- we return true if NOT and false if. sounds weird
-- but I use that for the desaturate function, see in calling
-- function SQS_UpdateButtonDisplay
if not type(SQS) or SQS == nil then
return false
end
if SQS.OOM ~= true then
return false
end
-- DEFAULT_CHAT_FRAME:AddMessage(addon.." oom check:"..type(SQS.OOM)..":"..tostring(SQS.OOM))
local SpellName, usable, nomana;
if FormNum == 1 then
-- exception here because we have bear and dire bear
usable, nomana = IsUsableSpell(L["SQS_1_BEAR"]);
if nomana == true then
return true
end
usable, nomana = IsUsableSpell(L["SQS_1_DIREBEAR"]);
if nomana == true then
return true
end
end
-- now the others
if FormNum == 2 then SpellName = L["SQS_2_AQUATIC"]
elseif FormNum == 3 then SpellName = L["SQS_3_CAT"]
elseif FormNum == 4 then SpellName = L["SQS_4_TRAVEL"]
elseif FormNum == 5 then SpellName = L["SQS_5_MOONKIN"]
end
-- check
usable, nomana = IsUsableSpell(SpellName);
if nomana == true then
return true
end
-- no break? we assume is usable
return false
end
function SQS_CreateButton(FormNum)
Button = CreateFrame("Button", "SQS_BTN_"..FormNum, solQuickShifterFrame, "SecureActionButtonTemplate");
Button:SetWidth(32);
Button:SetHeight(32);
Button:SetID(FormNum);
-- Position of the button based on the Form
if FormNum == 1 then
-- bear
Button:SetPoint("RIGHT")
elseif FormNum == 2 then
-- aqua
Button:SetPoint("BOTTOMRIGHT", -16, 1)
elseif FormNum == 3 then
-- cat
Button:SetPoint("LEFT")
elseif FormNum == 4 then
-- Travel
Button:SetPoint("TOP")
elseif FormNum == 5 then
-- moonkin
Button:SetPoint("BOTTOMLEFT", 16, 1)
elseif FormNum == 9 then
-- cancel form
Button:SetPoint("CENTER")
elseif FormNum == 10 then
-- cancel mount
Button:SetPoint("CENTER")
end
Button.Texture = Button:CreateTexture(Button:GetName().."NormalTexture", "ARTWORK");
Button.Texture:SetTexture(SQS_GetDefaultIcon(FormNum));
Button.Texture:SetAllPoints();
Button:RegisterForClicks("LeftButtonUp","RightButtonUp");
Button:SetScript("OnEnter", function(self, ...)
self.Texture:ClearAllPoints();
self.Texture:SetTexture(SQS_GetHoverIcon(FormNum));
self.Texture:SetPoint("TOPLEFT", -5, 5);
self.Texture:SetPoint("BOTTOMRIGHT", 5, -5);
end);
Button:SetScript("OnLeave", function(self, ...)
self.Texture:SetAllPoints();
self.Texture:SetTexture(SQS_GetDefaultIcon(FormNum));
end);
-- using macro workaround, thanks bliz classic != classic, old function CastShapeshiftForm() is forbidden now :(
-- this is specially shitty because all the stance/form names are translated to the client language
-- so you cant just use a /cast cat form. Each language this "cat form" is different. In German it would be:
-- /wirken Katzengestalt; luckily you can use /use and only need to translate the form name :(
Button:SetAttribute("type","macro")
Button:SetAttribute("macrotext",SQS_GetMacro(FormNum))
end
function SQS_UpdateButton(UpdateButton,FormNum)
UpdateButton:SetAttribute("macrotext",SQS_GetMacro(FormNum))
UpdateButton.Texture:SetTexture(SQS_GetDefaultIcon(FormNum));
UpdateButton:SetScript("OnEnter", function(self, ...)
self.Texture:ClearAllPoints();
self.Texture:SetTexture(SQS_GetHoverIcon(FormNum));
self.Texture:SetPoint("TOPLEFT", -5, 5);
self.Texture:SetPoint("BOTTOMRIGHT", 5, -5);
end);
UpdateButton:SetScript("OnLeave", function(self, ...)
self.Texture:SetAllPoints();
self.Texture:SetTexture(SQS_GetDefaultIcon(FormNum));
end);
end
function SQS_GetHoverIcon(FormNum)
-- retun a icon for each form button hover
if FormNum == 1 then
return "interface\\icons\\ability_hunter_pet_bear"
elseif FormNum == 2 then
return "interface\\icons\\spell_shadow_demonbreath"
elseif FormNum == 3 then
return "interface\\icons\\ability_druid_rake"
elseif FormNum == 4 then
return "interface\\icons\\inv_misc_head_tiger_01"
elseif FormNum == 5 then
return "interface\\icons\\inv_misc_monstertail_01"
elseif FormNum == 9 then
return "interface\\icons\\Spell_nature_wispsplode"
elseif FormNum == 10 then
return "interface\\icons\\inv_boots_03"
end
end
function SQS_GetDefaultIcon(FormNum)
-- retun a icon for each form button hover
if FormNum == 1 then
return "interface\\icons\\ability_racial_bearform"
elseif FormNum == 2 then
return "interface\\icons\\ability_druid_aquaticform"
elseif FormNum == 3 then
return "interface\\icons\\ability_druid_catform"
elseif FormNum == 4 then
return "interface\\icons\\ability_druid_travelform"
elseif FormNum == 5 then
return "interface\\icons\\spell_nature_forceofnature"
elseif FormNum == 9 then
return "interface\\icons\\spell_frost_wisp"
elseif FormNum == 10 then
-- check if we found a mount
local MountName, MountTexture = SQS_GetMountName()
if MountTexture then
return MountTexture
else
return "interface\\icons\\ability_hunter_beastcall"
end
end
end
function SQS_GetMacro(FormNum)
-- retun the Macro to cast for each form
local PowerShiftMacro = ""
if SQS.PWRSHIFT ~= true then
PowerShiftMacro = " [noform:"..FormNum.."]"
end
if FormNum == 1 then
return "#showtooltip\n/dismount [mounted]\n/cancelform"..PowerShiftMacro.."\n/use [noform:"..FormNum.."] !"..L["SQS_1_DIREBEAR"].."\n/use [noform:"..FormNum.."]"..L["SQS_1_BEAR"]
elseif FormNum == 2 then
return "/dismount [mounted]\n/cancelform"..PowerShiftMacro.."\n/use [noform:"..FormNum..",swimming] !"..L["SQS_2_AQUATIC"]
elseif FormNum == 3 then
return "/dismount [mounted]\n/cancelform"..PowerShiftMacro.."\n/use [noform:"..FormNum.."] !"..L["SQS_3_CAT"]
elseif FormNum == 4 then
return "/dismount [mounted]\n/cancelform"..PowerShiftMacro.."\n/use [noform:"..FormNum.."] !"..L["SQS_4_TRAVEL"]
elseif FormNum == 5 then
return "/dismount [mounted]\n/cancelform"..PowerShiftMacro.."\n/use [noform:"..FormNum.."] !"..L["SQS_5_MOONKIN"]
elseif FormNum == 10 then
local MountName, _ = SQS_GetMountName()
if MountName then
return "/dismount [mounted]\n/cast [nomounted] "..MountName.."\n/cancelform"
else
return "/dismount [mounted]\n/cancelform"
end
else
return "/cancelform"
end
end
function SQS_IsGlobalCooldown()
-- 61304 is the 'Global Cooldown' spell
local _, duration = GetSpellCooldown(61304)
local spell, _ = CastingInfo("player")
-- Check for duration left
if duration > 0 or spell ~= nil then
return true
end
return false
end
-- function for printing to chatframe if debug is enabled
function SQS_debug(DebugMsg)
if SQS_DEBUG == true then
DEFAULT_CHAT_FRAME:AddMessage(addon.."> "..DebugMsg)
end
end
-- function to get the players mount
-- returns: { <string>mount name, <int> Mount Icon, <int> timestamp when found }
function SQS_GetMountName()
-- if Option to DISABLE Mount Feature is checked quit here
if SQS.disableMount == true then
return false
end
-- Check if Player reached Level 40, if not we do not need to continue further
if UnitLevel("player") < 40 then
return false
end
-- maybe we found it previously?
if SQS_MOUNT ~= nil and #SQS_MOUNT > 0 then
-- we use a timestamp to cache a bit, if the last check time is > 60s we check again
-- if not we return what we last found. This prevents going through all bag items
-- on every event call.
local SecAgo = time()-SQS_MOUNT[3]
-- cache 5 min
if SecAgo <= 300 then
return SQS_MOUNT[1], SQS_MOUNT[2]
end
end
-- not checking if player is in Fight
if UnitAffectingCombat("player") then
if SQS_MOUNT ~= nil and #SQS_MOUNT > 0 then
SQS_debug("IN FIGHT: Returnung prev found")
return SQS_MOUNT[1], SQS_MOUNT[2]
else
SQS_debug("IN FIGHT: Returnung FALSE")
return false
end
end
-- parsing the players bags for a mount
for b=0,4 do
for s=1,GetContainerNumSlots(b) do
a=GetContainerItemLink(b,s)if a then
if string.find(a,L["SQS_MOUNT_HORN"]) or
string.find(a,L["SQS_MOUNT_WHISTLE"]) or
string.find(a,L["SQS_MOUNT_REINS"]) or
string.find(a,L["SQS_MOUNT_KODO_1"]) or
string.find(a,L["SQS_MOUNT_KODO_2"]) or
string.find(a,L["SQS_MOUNT_KODO_3"]) or
string.find(a,L["SQS_MOUNT_KODO_4"])
then
local MountName, _, _, ItemLevel, _, _, _, _, _, ItemTexture = GetItemInfo(GetContainerItemID(b,s));
-- double check that it is a lvl 40+ Item to be sure to have a mount
if ItemLevel >= 40 then
-- SQS_debug("Item Name: "..MountName)
-- SQS_debug("Item Texture: "..ItemTexture)
-- SQS_debug("Item Level: "..ItemLevel)
-- set texture of Button 10
SQS_debug("found Mount: "..a.." Container: "..b.." Slot: "..s)
SQS_MOUNT = {MountName, ItemTexture, time()}
-- updating button for mounting
SQS_UpdateButton(SQS_BTN_10, 10)
return MountName, ItemTexture
end
end
end
end
end
-- seems no mount was found
SQS_debug("searched for a Mount but couldnt find anything, return = false.")
return false
end