vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | QuickMountEquip |
||
3 | By Robert Jenkins (Merrem@Perenolde / Flarin@Sen'Jin) |
||
4 | |||
5 | Automates equipping of items when mounting/dismounting |
||
6 | |||
7 | UI based on Totem Stomper by AlexYoshi |
||
8 | |||
9 | ]] |
||
10 | QME_Registered = nil; |
||
11 | QuickMount_Version = "2.20"; |
||
12 | |||
13 | QuickMount_ConfigMap = nil; |
||
14 | QuickMount_Disabled = false; |
||
15 | |||
16 | -- Current Player information... |
||
17 | QMCP = ""; |
||
18 | |||
19 | QuickMount_SavedBagFunc = nil; |
||
20 | QuickMount_SavedInvFunc = nil; |
||
21 | QuickMount_SavedUseFunc = nil; |
||
22 | |||
23 | local combat_flag = false; |
||
24 | local attack_button = 0; |
||
25 | |||
26 | local MOUNT = 1; |
||
27 | local UNMOUNT = 2; |
||
28 | local QM_SET_COUNT = 2; |
||
29 | local QM_SET_SIZE = 5; |
||
30 | local IGNORE_SWITCH = false; |
||
31 | |||
32 | local QM_NIL = -100; |
||
33 | |||
34 | local QuickMount_CurrentID = QM_NIL; |
||
35 | local QuickMount_CurrentBag = QM_NIL; |
||
36 | local QuickMount_CurrentSlot = QM_NIL; |
||
37 | local QuickMount_CurrentName = ""; |
||
38 | local QuickMount_CurrentTexture = ""; |
||
39 | |||
40 | local QuickMount_AutoDetect = false; |
||
41 | |||
42 | function QuickMount_RegisterEvents() |
||
43 | this:RegisterEvent("VARIABLES_LOADED") -- configuration loading |
||
44 | if not Fetch_Frame then |
||
45 | this:RegisterEvent("UNIT_NAME_UPDATE") -- configuration loading |
||
46 | end |
||
47 | this:RegisterEvent("PLAYER_AURAS_CHANGED") -- mount buff check |
||
48 | this:RegisterEvent("ACTIONBAR_UPDATE_USABLE") -- flight path check |
||
49 | this:RegisterEvent("PLAYER_REGEN_DISABLED") -- combat check |
||
50 | this:RegisterEvent("PLAYER_REGEN_ENABLED") -- combat check |
||
51 | this:RegisterEvent("DELETE_ITEM_CONFIRM") -- delete check |
||
52 | end |
||
53 | |||
54 | function QuickMount_UnregisterEvents() |
||
55 | this:UnregisterEvent("PLAYER_AURAS_CHANGED") -- mount buff check |
||
56 | this:UnregisterEvent("ACTIONBAR_UPDATE_USABLE") -- flight path check |
||
57 | this:UnregisterEvent("PLAYER_REGEN_DISABLED") -- combat check |
||
58 | this:UnregisterEvent("PLAYER_REGEN_ENABLED") -- combat check |
||
59 | end |
||
60 | |||
61 | function QuickMount_ShowUsage() |
||
62 | QM_Print("/mountequip on | off | quiet | verbose | flightpoint [on/off] | auto-reconfig [on/off] | config | status | load profileName | save profileName | delete profileName | profiles | detect\n"); |
||
63 | end |
||
64 | |||
65 | function QuickMount_Toggle() |
||
66 | QuickMount_Config("config"); |
||
67 | end |
||
68 | |||
69 | -- Show/hide the Main Frame |
||
70 | function QuickMount_Config(msg) |
||
71 | if QuickMount_CheckPlayer() == false then |
||
72 | QM_Print("Sorry, QuickMountEquip variables aren't loaded yet."); |
||
73 | return; |
||
74 | end |
||
75 | if msg == nil or msg == "" then |
||
76 | msg = "config"; |
||
77 | end |
||
78 | |||
79 | local args = {n=0} |
||
80 | local function helper(word) table.insert(args, word) end |
||
81 | string.gsub(msg, "[_%w]+", helper); |
||
82 | |||
83 | if args[1] == 'off' then |
||
84 | QuickMount_Disabled = true; |
||
85 | QM_Print("QuickMountEquip disabled."); |
||
86 | elseif args[1] == 'on' then |
||
87 | QuickMount_Disabled = false; |
||
88 | QM_Print("QuickMountEquip enabled."); |
||
89 | elseif args[1] == 'quiet' then |
||
90 | QuickMount_ConfigMap[QMCP]["Quiet"] = true; |
||
91 | QM_Print("QuickMountEquip verbosity off."); |
||
92 | elseif args[1] == 'verbose' then |
||
93 | QuickMount_ConfigMap[QMCP]["Quiet"] = false; |
||
94 | QM_Print("QuickMountEquip verbosity on."); |
||
95 | elseif args[1] == 'flightpoint' or args[1] == 'flightpath' then |
||
96 | if ( args[2] == nil or args[2] == '' or ( args[2] ~= 'on' and args[2] ~= 'off' ) ) then |
||
97 | QM_Print("Do you want to turn flightpoint checking on or off?"); |
||
98 | else |
||
99 | if args[2] == 'on' then |
||
100 | QuickMount_ConfigMap[QMCP]["FlightPoint"] = true; |
||
101 | QM_Print("QuickMountEquip Flight Point checking on."); |
||
102 | else |
||
103 | QuickMount_ConfigMap[QMCP]["FlightPoint"] = false; |
||
104 | QM_Print("QuickMountEquip Flight Point checking off."); |
||
105 | end |
||
106 | end |
||
107 | elseif args[1] == 'save' then |
||
108 | if args[2] == nil or args[2] == '' then |
||
109 | QM_Print("No profile name specified."); |
||
110 | else |
||
111 | QuickMount_ConfigMap["Profile" .. args[2]] = QuickMount_ConfigMap[QMCP]; |
||
112 | QM_Print("QuickMountEquip profile '" .. args[2] .. "' saved."); |
||
113 | end |
||
114 | elseif args[1] == 'load' then |
||
115 | if args[2] == nil or args[2] == '' then |
||
116 | QM_Print("No profile name specified."); |
||
117 | else |
||
118 | if QuickMount_ConfigMap["Profile" .. args[2]] then |
||
119 | local last_action = QuickMount_ConfigMap[QMCP]["last_action"]; |
||
120 | QuickMount_ConfigMap[QMCP] = QuickMount_ConfigMap["Profile" .. args[2]]; |
||
121 | QuickMount_ConfigMap[QMCP]["last_action"] = last_action; |
||
122 | QM_Print("QuickMountEquip profile '" .. args[2] .. "' loaded."); |
||
123 | else |
||
124 | QM_Print("QuickMountEquip profile '" .. args[2] .. "' not found!"); |
||
125 | end |
||
126 | end |
||
127 | elseif args[1] == 'delete' then |
||
128 | if args[2] == nil or args[2] == '' then |
||
129 | QM_Print("No profile name specified."); |
||
130 | else |
||
131 | if QuickMount_ConfigMap["Profile" .. args[2]] then |
||
132 | QuickMount_ConfigMap["Profile" .. args[2]] = nil; |
||
133 | QM_Print("QuickMountEquip profile '" .. args[2] .. "' deleted."); |
||
134 | else |
||
135 | QM_Print("QuickMountEquip profile '" .. args[2] .. "' not found!"); |
||
136 | end |
||
137 | end |
||
138 | elseif args[1] == 'profiles' then |
||
139 | QM_Print("Profiles:"); |
||
140 | table.foreach(QuickMount_ConfigMap, function(k,v) if string.find(k, "Profile") then QM_Print(string.gsub(k, "Profile", '')) end end); |
||
141 | elseif args[1] == 'detect' then |
||
142 | if args[2] == nil or args[2] == '' then |
||
143 | QM_Print("** Experimental / Advanced **"); |
||
144 | QM_Print("Do '/mountequip detect now' to attempt to detect the name of your mount. You should be unmounted and have zero buffs when you attempt this."); |
||
145 | QM_Print("Then do '/mountequip detect on' to use the detected mount when mounting"); |
||
146 | QM_Print("Or '/mountequip detect off' to turn off the use of the detected mount"); |
||
147 | QM_Print("Or '/mountequip detect clear' to clear the detected setting completely"); |
||
148 | QM_Print("NOTE: If doing this fixes your mounting problem, please let the author know, so it can be automatically included in the next release."); |
||
149 | elseif args[2] == 'now' then |
||
150 | QM_Print("This will attempt to detect the name of your mount. The next buff that appears will be assumed to be your mount. This works best if you start out with zero buffs. You should mount up NOW."); |
||
151 | QuickMount_AutoDetect = true; |
||
152 | QuickMount_ConfigMap[QMCP]["DetectedIcon"] = nil; |
||
153 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = false; |
||
154 | elseif args[2] == 'on' then |
||
155 | if QuickMount_ConfigMap[QMCP]["DetectedIcon"] ~= nil then |
||
156 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = true; |
||
157 | QM_Print("Auto-Detected mount option turned on"); |
||
158 | else |
||
159 | QM_Print("Can't turn on use of the detected icon, since detection hasn't been done yet."); |
||
160 | end |
||
161 | elseif args[2] == 'off' then |
||
162 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = false; |
||
163 | QM_Print("Auto-Detected mount option turned off"); |
||
164 | elseif args[2] == 'clear' then |
||
165 | QuickMount_ConfigMap[QMCP]["DetectedIcon"] = nil; |
||
166 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = false; |
||
167 | QM_Print("Cleared detect options."); |
||
168 | end |
||
169 | elseif args[1] == 'auto-reconfig' then |
||
170 | local status = ""; |
||
171 | if args[2] == nil or args[2] == '' then |
||
172 | if QuickMount_ConfigMap[QMCP]["auto-reconfig"] == true then |
||
173 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = false; |
||
174 | status = "toggled OFF"; |
||
175 | else |
||
176 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = true; |
||
177 | status = "toggled ON"; |
||
178 | end |
||
179 | elseif args[2] == 'on' then |
||
180 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = true; |
||
181 | status = "ON"; |
||
182 | elseif args[2] == 'off' then |
||
183 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = false; |
||
184 | status = "OFF"; |
||
185 | end |
||
186 | QM_Print("Auto-reconfiguring is now " .. status); |
||
187 | elseif args[1] == 'status' then |
||
188 | QuickMount_ShowUsage(); |
||
189 | local status = "QuickMountEquip is currently"; |
||
190 | if QuickMount_Disabled == true then |
||
191 | status = status .. " disabled"; |
||
192 | else |
||
193 | status = status .. " enabled"; |
||
194 | end |
||
195 | status = status .. ", flight point checking is"; |
||
196 | if QuickMount_ConfigMap[QMCP]["FlightPoint"] == false then |
||
197 | status = status .. " off"; |
||
198 | else |
||
199 | status = status .. " on"; |
||
200 | end |
||
201 | status = status .. ", use of detected mount icon "; |
||
202 | if QuickMount_ConfigMap[QMCP]["DetectedIcon"] ~= nil then |
||
203 | status = status .. "(" .. QuickMount_ConfigMap[QMCP]["DetectedIcon"] .. ") is"; |
||
204 | else |
||
205 | status = status .. "is"; |
||
206 | end |
||
207 | if QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] == false then |
||
208 | status = status .. " off"; |
||
209 | else |
||
210 | status = status .. " on"; |
||
211 | end |
||
212 | status = status .. ", auto-reconfigure is"; |
||
213 | if QuickMount_ConfigMap[QMCP]["auto-reconfig"] == false then |
||
214 | status = status .. " off"; |
||
215 | else |
||
216 | status = status .. " on"; |
||
217 | end |
||
218 | if QuickMount_ConfigMap[QMCP]["Quiet"] == false then |
||
219 | status = status .. ", and is in verbose mode."; |
||
220 | else |
||
221 | status = status .. ", and is in quiet mode."; |
||
222 | end |
||
223 | QM_Print(status); |
||
224 | elseif args[1] == 'config' then |
||
225 | -- Reset attack_button, just in case they rearranged hot keys. |
||
226 | attack_button = 0 |
||
227 | if ( QuickMountFrame ) then |
||
228 | if ( QuickMountFrame:IsVisible() ) then |
||
229 | HideUIPanel(QuickMountFrame); |
||
230 | else |
||
231 | ShowUIPanel(QuickMountFrame); |
||
232 | end |
||
233 | else |
||
234 | QM_Print("QuickMountEquip did not load. Please check your logs/FrameXML.log file and report this error"); |
||
235 | end |
||
236 | else |
||
237 | QuickMount_ShowUsage(); |
||
238 | end |
||
239 | end |
||
240 | |||
241 | function QuickMount_CheckPlayer() |
||
242 | if QMCP == "" then |
||
243 | local playername; |
||
244 | if Fetch_Frame then |
||
245 | if not Fetch_Done then |
||
246 | return false; |
||
247 | else |
||
248 | playername = Fetch_PlayerName |
||
249 | end |
||
250 | else |
||
251 | playername = UnitName("player"); |
||
252 | if playername == nil or playername == UKNOWNBEING or playername == UNKNOWNOBJECT then |
||
253 | return false; |
||
254 | end |
||
255 | end |
||
256 | QMCP = GetCVar("realmName") .. "." .. playername; |
||
257 | -- Convert old config |
||
258 | if QuickMount_ButtonMap ~= nil and QuickMount_ButtonMap[1] ~= nil then |
||
259 | QuickMount_ConfigMap = {}; |
||
260 | QuickMount_ConfigMap[QMCP] = QuickMount_ButtonMap; |
||
261 | QuickMount_ConfigMap[QMCP]["Quiet"] = false; |
||
262 | QuickMount_ConfigMap[QMCP]["FlightPoint"] = false; |
||
263 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = false; |
||
264 | end |
||
265 | if QuickMount_ConfigMap == nil or QuickMount_ConfigMap[QMCP] == nil then |
||
266 | QuickMount_Reset(); |
||
267 | end |
||
268 | if QuickMount_ConfigMap[QMCP]["FlightPoint"] == nil then |
||
269 | QuickMount_ConfigMap[QMCP]["FlightPoint"] = false; |
||
270 | end |
||
271 | if QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] == nil then |
||
272 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = false; |
||
273 | end |
||
274 | if QuickMount_ConfigMap[QMCP]["auto-reconfig"] == nil then |
||
275 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = false; |
||
276 | end |
||
277 | QuickMount_UpdateAllSets(); |
||
278 | end |
||
279 | if QMCP == "" or QMCP == "NONE" then |
||
280 | return false; |
||
281 | else |
||
282 | return true; |
||
283 | end |
||
284 | end |
||
285 | |||
286 | -- Reset QuickMount |
||
287 | function QuickMount_Reset() |
||
288 | if QuickMount_CheckPlayer() == false then |
||
289 | return; |
||
290 | end |
||
291 | if QuickMount_ConfigMap == nil then |
||
292 | QuickMount_ConfigMap = {}; |
||
293 | end |
||
294 | QuickMount_ConfigMap[QMCP]={index=nil;}; |
||
295 | for i=1,QM_SET_COUNT,1 do |
||
296 | QuickMount_ConfigMap[QMCP][i]={index=nil;}; |
||
297 | for j=1,QM_SET_SIZE,1 do |
||
298 | QuickMount_ConfigMap[QMCP][i][j]= {id=QM_NIL;bag=QM_NIL;slot=QM_NIL;texture="";name="";}; |
||
299 | end |
||
300 | QuickMount_ConfigMap[QMCP]["Quiet"] = false; |
||
301 | QuickMount_ConfigMap[QMCP]["FlightPoint"] = false; |
||
302 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = false; |
||
303 | QuickMount_ConfigMap[QMCP]["DetectedIcon"] = nil; |
||
304 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = false; |
||
305 | end |
||
306 | end |
||
307 | |||
308 | function QuickMount_GetBuffName(buffIndex) |
||
309 | local x, y = GetPlayerBuff(buffIndex, "HELPFUL"); |
||
310 | QuickMountTooltip:SetUnitBuff("player", buffIndex); |
||
311 | local Bname = QuickMountTooltipTextLeft1:GetText(); |
||
312 | if ( Bname ~= nil ) then |
||
313 | return Bname; |
||
314 | end |
||
315 | return nil; |
||
316 | end |
||
317 | |||
318 | function QuickMount_GetItemName(bag, slot) |
||
319 | local bagNumber = bag; |
||
320 | local name = ""; |
||
321 | if ( type(bagNumber) ~= "number" ) then |
||
322 | bagNumber = tonumber(bag); |
||
323 | end |
||
324 | if (bagNumber <= QM_NIL) then |
||
325 | QuickMountTooltip:SetInventoryItem("player", slot); |
||
326 | else |
||
327 | QuickMountTooltip:SetBagItem(bag, slot); |
||
328 | end |
||
329 | name = QuickMountTooltipTextLeft1:GetText(); |
||
330 | if name == nil then |
||
331 | name = ""; |
||
332 | end |
||
333 | return name; |
||
334 | end |
||
335 | |||
336 | function QuickMount_PickupContainerItem(bag, slot) |
||
337 | local empty = true; |
||
338 | local autoflag = false; |
||
339 | local name = ''; |
||
340 | -- If we are set to auto-reconfigure, and we're unmounted and they are manually swapping items, configure. |
||
341 | if ( QuickMount_CheckPlayer() == true and IGNORE_SWITCH == false and QuickMount_ConfigMap[QMCP]["auto-reconfig"] == true and QuickMount_ConfigMap[QMCP]["last_action"] ~= true and QuickMount_CurrentBag == QM_NIL and QuickMount_CurrentName ~= '' and CursorHasItem() ) then |
||
342 | autoflag = true; |
||
343 | end |
||
344 | if ( QuickMount_SavedBagFunc ) then |
||
345 | QuickMount_SavedBagFunc(bag, slot); |
||
346 | end |
||
347 | local texture, itemCount, locked = GetContainerItemInfo(bag, slot); |
||
348 | if ( texture ) then |
||
349 | name = QuickMount_GetItemName(bag, slot) |
||
350 | end |
||
351 | if IGNORE_SWITCH == false and CursorHasItem() then |
||
352 | QuickMount_PickupItem(bag, slot, name, texture) |
||
353 | empty = false |
||
354 | end |
||
355 | if ( autoflag and not CursorHasItem() and name ~= nil and name ~= '') then |
||
356 | -- Check the UNMOUNT config for this item, swap if found |
||
357 | for i in QuickMount_ConfigMap[QMCP][UNMOUNT] do |
||
358 | if QuickMount_ConfigMap[QMCP][UNMOUNT][i].id > 0 and QuickMount_ConfigMap[QMCP][UNMOUNT][i].name == QuickMount_CurrentName then |
||
359 | QuickMount_PickupItem(bag, slot, name, texture); |
||
360 | QuickMount_ConfigMap[QMCP][UNMOUNT][i] = {id=QuickMount_CurrentID,bag=QuickMount_CurrentBag,slot=QuickMount_CurrentSlot,name=QuickMount_CurrentName,texture=QuickMount_CurrentTexture}; |
||
361 | QuickMount_UpdateSet("QuickMountButtonSet",UNMOUNT,QM_SET_SIZE); |
||
362 | end |
||
363 | end |
||
364 | end |
||
365 | if empty then |
||
366 | QuickMount_ResetItem(); |
||
367 | end |
||
368 | end |
||
369 | |||
370 | function QuickMount_PickupInventoryItem(slot) |
||
371 | local empty = true; |
||
372 | local autoflag = false; |
||
373 | local name = ''; |
||
374 | -- If we are set to auto-reconfigure, and we're unmounted and they are manually swapping items, configure. |
||
375 | if ( QuickMount_CheckPlayer() == true and IGNORE_SWITCH == false and QuickMount_ConfigMap[QMCP]["auto-reconfig"] == true and QuickMount_ConfigMap[QMCP]["last_action"] ~= true and QuickMount_CurrentBag ~= QM_NIL and CursorHasItem() ) then |
||
376 | autoflag = true; |
||
377 | end |
||
378 | if ( QuickMount_SavedInvFunc ) then |
||
379 | QuickMount_SavedInvFunc(slot); |
||
380 | end |
||
381 | local texture = GetInventoryItemTexture("player", slot); |
||
382 | if ( texture ) then |
||
383 | name = QuickMount_GetItemName(QM_NIL, slot) |
||
384 | end |
||
385 | if IGNORE_SWITCH == false and CursorHasItem() and name ~= '' then |
||
386 | QuickMount_PickupItem(QM_NIL, slot, name, texture) |
||
387 | empty = false |
||
388 | end |
||
389 | if ( autoflag and not CursorHasItem() and name ~= nil and name ~= '') then |
||
390 | -- Check the UNMOUNT config for this item, swap if found |
||
391 | for i in QuickMount_ConfigMap[QMCP][UNMOUNT] do |
||
392 | if QuickMount_ConfigMap[QMCP][UNMOUNT][i].id > 0 and QuickMount_ConfigMap[QMCP][UNMOUNT][i].name == name then |
||
393 | QuickMount_ConfigMap[QMCP][UNMOUNT][i] = {id=QuickMount_CurrentID,bag=QuickMount_CurrentBag,slot=QuickMount_CurrentSlot,name=QuickMount_CurrentName,texture=QuickMount_CurrentTexture}; |
||
394 | QuickMount_UpdateSet("QuickMountButtonSet",UNMOUNT,QM_SET_SIZE); |
||
395 | end |
||
396 | end |
||
397 | end |
||
398 | if empty then |
||
399 | QuickMount_ResetItem(); |
||
400 | end |
||
401 | end |
||
402 | |||
403 | function QuickMount_UseContainerItem(bag, slot) |
||
404 | local empty = true; |
||
405 | local autoflag = false; |
||
406 | local name_before = ''; |
||
407 | local name_after = ''; |
||
408 | |||
409 | if ( bag >= 0 and QuickMount_CheckPlayer() == true and IGNORE_SWITCH == false and QuickMount_ConfigMap[QMCP]["auto-reconfig"] == true and QuickMount_ConfigMap[QMCP]["last_action"] ~= true and QuickMount_CurrentBag == QM_NIL and QuickMount_CurrentName == '' and CursorHasItem() ~= true ) then |
||
410 | autoflag = true; |
||
411 | |||
412 | -- local texture_before, itemCount_before, locked_before = GetContainerItemInfo(bag, slot); |
||
413 | -- if ( texture_before ) then |
||
414 | -- name_before = QuickMount_GetItemName(bag, slot) |
||
415 | -- end |
||
416 | end |
||
417 | |||
418 | if ( QuickMount_SavedUseFunc ) then |
||
419 | QuickMount_SavedUseFunc(bag, slot); |
||
420 | end |
||
421 | |||
422 | if ( autoflag ) then |
||
423 | local texture_after, itemCount_after, locked_after = GetContainerItemInfo(bag, slot); |
||
424 | if ( texture_after ) then |
||
425 | name_after = QuickMount_GetItemName(bag, slot) |
||
426 | end |
||
427 | |||
428 | if ( not CursorHasItem() and name_before ~= name_after and name_before ~= nil and name_before ~= '' and name_after ~= nil and name_after ~= '' ) then |
||
429 | -- Check the UNMOUNT config for this item, swap if found |
||
430 | for i in QuickMount_ConfigMap[QMCP][UNMOUNT] do |
||
431 | if QuickMount_ConfigMap[QMCP][UNMOUNT][i].id > 0 and QuickMount_ConfigMap[QMCP][UNMOUNT][i].name == name_after then |
||
432 | QuickMount_PickupItem(bag, slot, name_before, texture_before); |
||
433 | QuickMount_ConfigMap[QMCP][UNMOUNT][i] = {id=QuickMount_CurrentID,bag=QuickMount_CurrentBag,slot=QuickMount_CurrentSlot,name=QuickMount_CurrentName,texture=QuickMount_CurrentTexture}; |
||
434 | QuickMount_UpdateSet("QuickMountButtonSet",UNMOUNT,QM_SET_SIZE); |
||
435 | end |
||
436 | end |
||
437 | end |
||
438 | end |
||
439 | end |
||
440 | |||
441 | function QuickMount_OnLoad() |
||
442 | -- Set the header |
||
443 | local name = this:GetName(); |
||
444 | local header = getglobal(name.."TitleText"); |
||
445 | |||
446 | if ( header ) then |
||
447 | header:SetText("|cFFee9966Mount Equipment|r"); |
||
448 | end |
||
449 | |||
450 | QuickMount_Reset(); |
||
451 | -- RegisterForSave("QuickMount_ConfigMap"); |
||
452 | QuickMount_RegisterEvents(); |
||
453 | |||
454 | local temp = PickupContainerItem; |
||
455 | if ( QuickMount_HookFunction("PickupContainerItem", "QuickMount_PickupContainerItem") ) then |
||
456 | QuickMount_SavedBagFunc = temp; |
||
457 | end |
||
458 | |||
459 | local temp = PickupInventoryItem; |
||
460 | if ( QuickMount_HookFunction("PickupInventoryItem", "QuickMount_PickupInventoryItem") ) then |
||
461 | QuickMount_SavedInvFunc = temp; |
||
462 | end |
||
463 | |||
464 | local temp = UseContainerItem; |
||
465 | if ( QuickMount_HookFunction("UseContainerItem", "QuickMount_UseContainerItem") ) then |
||
466 | QuickMount_SavedUseFunc = temp; |
||
467 | end |
||
468 | |||
469 | -- Slash Commands |
||
470 | SlashCmdList["MOUNTEQUIP"] = function(msg) QuickMount_Config(msg); end |
||
471 | setglobal("SLASH_MOUNTEQUIP1", "/mountequip"); |
||
472 | |||
473 | QME_Registered = 0; |
||
474 | end |
||
475 | |||
476 | function QuickMount_HookFunction(func, newfunc) |
||
477 | local oldValue = getglobal(func); |
||
478 | if ( oldValue ~= getglobal(newfunc) ) then |
||
479 | setglobal(func, getglobal(newfunc)); |
||
480 | return true; |
||
481 | end |
||
482 | return false; |
||
483 | end |
||
484 | |||
485 | function QuickMount_ShowHelp() |
||
486 | local helptext = getglobal("QuickMountFrameHelpText"); |
||
487 | if helptext then |
||
488 | helptext:SetText("Drag Equipment you want auto-equipped into the squares. (Spurs, etc.) Shift click to clear item. Items that go in the same inventory slot should 'line up'. (Boots in slot 1, Trinkets in slot 2, etc.)"); |
||
489 | end |
||
490 | end |
||
491 | |||
492 | function QuickMount_Enable_Toggle(which) |
||
493 | if which then |
||
494 | QuickMount_Disabled = false; |
||
495 | else |
||
496 | QuickMount_Disabled = true; |
||
497 | end |
||
498 | end |
||
499 | |||
500 | function QuickMount_Quiet_Toggle(which) |
||
501 | QuickMount_ConfigMap[QMCP]["Quiet"] = which; |
||
502 | end |
||
503 | |||
504 | function QuickMount_FlightPoint_Toggle(which) |
||
505 | QuickMount_ConfigMap[QMCP]["FlightPoint"] = which; |
||
506 | end |
||
507 | |||
508 | |||
509 | function QuickMount_UseDetectedIcon_Toggle(which) |
||
510 | QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = which; |
||
511 | end |
||
512 | |||
513 | function QuickMount_AutoReconfig_Toggle(which) |
||
514 | QuickMount_ConfigMap[QMCP]["auto-reconfig"] = which; |
||
515 | end |
||
516 | |||
517 | function QuickMount_OnShow() |
||
518 | local checked; |
||
519 | |||
520 | QuickMount_ShowHelp() |
||
521 | |||
522 | -- Configure checkboxes |
||
523 | if (QuickMount_Disabled == false) then |
||
524 | checked = 1; |
||
525 | else |
||
526 | checked = 0; |
||
527 | end |
||
528 | |||
529 | QuickMountCheck1:SetChecked(checked); |
||
530 | QuickMountCheck1Text:SetText("QuickMountEquip enabled."); |
||
531 | QuickMountCheck1.myToolTip = "Check to enable QuickMountEquip."; |
||
532 | QuickMountCheck1.ExecuteCommand = QuickMount_Enable_Toggle; |
||
533 | |||
534 | if (QuickMount_ConfigMap[QMCP]["Quiet"] == true) then |
||
535 | checked = 1; |
||
536 | else |
||
537 | checked = 0; |
||
538 | end |
||
539 | |||
540 | QuickMountCheck2:SetChecked(checked); |
||
541 | QuickMountCheck2Text:SetText("Don't show equip message spam."); |
||
542 | QuickMountCheck2.myToolTip = "Check to disable equip messages."; |
||
543 | QuickMountCheck2.ExecuteCommand = QuickMount_Quiet_Toggle; |
||
544 | |||
545 | if (QuickMount_ConfigMap[QMCP]["FlightPoint"] == true) then |
||
546 | checked = 1; |
||
547 | else |
||
548 | checked = 0; |
||
549 | end |
||
550 | |||
551 | QuickMountCheck3:SetChecked(checked); |
||
552 | QuickMountCheck3Text:SetText("Griffin / FlightPoint check enabled."); |
||
553 | QuickMountCheck3.myToolTip = "Check to enable Griffin / FlightPoint checking.\n(Might also trigger on druid shapeshifting, or\nwhenever your attack button gets disabled outside\nof combat.)"; |
||
554 | QuickMountCheck3.ExecuteCommand = QuickMount_FlightPoint_Toggle; |
||
555 | |||
556 | if (QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] == true and QuickMount_ConfigMap[QMCP]["DetectedIcon"] ~= nil) then |
||
557 | checked = 1; |
||
558 | else |
||
559 | checked = 0; |
||
560 | end |
||
561 | |||
562 | local ourIcon = QuickMount_ConfigMap[QMCP]["DetectedIcon"]; |
||
563 | if ourIcon == nil then |
||
564 | ourIcon = 'NOT DETECTED YET'; |
||
565 | end |
||
566 | QuickMountCheck4:SetChecked(checked); |
||
567 | QuickMountCheck4Text:SetText("Use auto-detected mount icon"); |
||
568 | QuickMountCheck4.myToolTip = "Check to enable the mount auto-detected by\n/mountequip detect\n\nCurrently: " .. ourIcon .. "\n\n** Usually shouldn't be necessary. **"; |
||
569 | QuickMountCheck4.ExecuteCommand = QuickMount_UseDetectedIcon_Toggle; |
||
570 | |||
571 | if (QuickMount_ConfigMap[QMCP]["auto-reconfig"] == true) then |
||
572 | checked = 1; |
||
573 | else |
||
574 | checked = 0; |
||
575 | end |
||
576 | |||
577 | QuickMountCheck5:SetChecked(checked); |
||
578 | QuickMountCheck5Text:SetText("Auto-reconfigure."); |
||
579 | QuickMountCheck5.myToolTip = "Check to enable Auto-reconfiguring.\nThis will automatically reconfigure the add-on if you\nmanually swap a configured item with another.\nOnly works while unmounted and with the\nunmounted equipment line."; |
||
580 | QuickMountCheck5.ExecuteCommand = QuickMount_AutoReconfig_Toggle; |
||
581 | |||
582 | end |
||
583 | |||
584 | function QuickMount_OnHide() |
||
585 | QuickMount_DropItem(); |
||
586 | if MYADDONS_ACTIVE_OPTIONSFRAME == this then |
||
587 | ShowUIPanel(myAddOnsFrame); |
||
588 | end |
||
589 | end |
||
590 | |||
591 | function QME_RegisterUltimateUI() |
||
592 | UltimateUI_RegisterButton ( |
||
593 | "Mount Equipment", |
||
594 | "Auto-Equip", |
||
595 | "|cFF00CC00QuickMountEquip|r\nAllows you to select \nequipment to be auto-equipped \nas you mount/dismount", |
||
596 | "Interface\\Icons\\Ability_Mount_RidingHorse", |
||
597 | QuickMount_Toggle, |
||
598 | function() |
||
599 | return true; -- The button is enabled |
||
600 | end |
||
601 | ); |
||
602 | QME_Registered = 1; |
||
603 | end |
||
604 | |||
605 | function QuickMount_OnEvent(event) |
||
606 | local mounted = false |
||
607 | local sheeped = false |
||
608 | local clogged = false |
||
609 | |||
610 | if event == "VARIABLES_LOADED" then |
||
611 | QMCP = ""; |
||
612 | clogged = true; |
||
613 | -- Add myAddOns support |
||
614 | if myAddOnsList then |
||
615 | myAddOnsList.QuickMountEquip = {name = "QuickMountEquip", description = "Automatically switches gear when you mount", version = QuickMount_Version, frame = "QuickMountFrame", optionsframe = "QuickMountFrame"}; |
||
616 | end |
||
617 | if( QME_Registered == 0 ) then |
||
618 | if ( UltimateUI_RegisterButton ) then |
||
619 | QME_RegisterUltimateUI(); |
||
620 | end |
||
621 | end |
||
622 | end |
||
623 | |||
624 | if event == "UNIT_NAME_UPDATE" and arg1 == "player" then |
||
625 | QMCP = ""; |
||
626 | clogged = true; |
||
627 | end |
||
628 | |||
629 | if QuickMount_CheckPlayer() == false then |
||
630 | return; |
||
631 | end |
||
632 | |||
633 | if clogged == true or QuickMount_Disabled == true then |
||
634 | return; |
||
635 | end |
||
636 | |||
637 | if event == "DELETE_ITEM_CONFIRM" then |
||
638 | -- If the GUI frame is open, don't let them delete anything. |
||
639 | if ( QuickMountFrame and QuickMountFrame:IsVisible() ) then |
||
640 | QuickMount_DropItem(); |
||
641 | end |
||
642 | return; |
||
643 | end |
||
644 | |||
645 | if event == "PLAYER_REGEN_DISABLED" then |
||
646 | combat_flag = true |
||
647 | end |
||
648 | if event == "PLAYER_REGEN_ENABLED" then |
||
649 | combat_flag = false |
||
650 | end |
||
651 | |||
652 | -- Can't switch inventory while in combat, so ignore if in combat |
||
653 | if combat_flag == false then |
||
654 | local _, Pclass = UnitClass("player"); |
||
655 | local detectedIcon = nil; |
||
656 | for i = 1,16 do |
||
657 | local buff_texture = UnitBuff("player", i) |
||
658 | local debuff_texture = UnitDebuff("player", i) |
||
659 | if QuickMount_AutoDetect == true then |
||
660 | if buff_texture then |
||
661 | local parts = {n=0} |
||
662 | local function helper(word) table.insert(parts, word) end |
||
663 | string.gsub(buff_texture, "[_%w]+", helper); |
||
664 | |||
665 | QuickMount_ConfigMap[QMCP]["DetectedIcon"] = parts[parts.n]; |
||
666 | end |
||
667 | else |
||
668 | if debuff_texture and string.find(debuff_texture, "Polymorph") then |
||
669 | sheeped = true |
||
670 | return; |
||
671 | end |
||
672 | if Pclass == "PALADIN" or Pclass == "WARLOCK" then |
||
673 | -- Paladin/Warlock Mount... Hopefully no other buff uses the same texture... |
||
674 | if buff_texture and string.find(buff_texture, "Spell_Nature_Swiftness") then |
||
675 | mounted = true |
||
676 | break; |
||
677 | end |
||
678 | end |
||
679 | if QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] == true and QuickMount_ConfigMap[QMCP]["DetectedIcon"] ~= nil then |
||
680 | detectedIcon = QuickMount_ConfigMap[QMCP]["DetectedIcon"]; |
||
681 | end |
||
682 | if buff_texture and ( string.find(buff_texture, "Mount") or string.find(buff_texture, "Foot_Kodo") or ( detectedIcon ~= nil and string.find(buff_texture, detectedIcon) ) ) then |
||
683 | -- Make sure it isn't "Aspect of the xxx" or "Tiger's Fury" |
||
684 | local BuffName = QuickMount_GetBuffName(i); |
||
685 | local Skip = false; |
||
686 | if BuffName and ( string.find(BuffName, "Aspect") or string.find(BuffName, "Aspekt") or string.find(BuffName, "Tiger's Fury") ) then |
||
687 | Skip = true |
||
688 | end |
||
689 | if Skip == false then |
||
690 | mounted = true |
||
691 | break; |
||
692 | end |
||
693 | end |
||
694 | end |
||
695 | end |
||
696 | |||
697 | if QuickMount_AutoDetect == true then |
||
698 | if QuickMount_ConfigMap[QMCP]["DetectedIcon"] ~= nil then |
||
699 | QuickMount_AutoDetect = false; |
||
700 | -- QuickMount_ConfigMap[QMCP]["UseDetectedIcon"] = true; |
||
701 | QM_Print("Detected mount icon of: " .. QuickMount_ConfigMap[QMCP]["DetectedIcon"]); |
||
702 | end |
||
703 | return; |
||
704 | end |
||
705 | |||
706 | -- Test for flight path. Search for an attack button and see if it's disabled. This assumes the |
||
707 | -- only time attack is disabled outside of combat is because of flight paths. |
||
708 | -- Whoops... Polymorph takes them out of combat, *and* disables attack. Bleh. |
||
709 | if QuickMount_ConfigMap[QMCP]["FlightPoint"] == true and mounted == false and sheeped == false and attack_button ~= QM_NIL then |
||
710 | if attack_button == 0 then |
||
711 | attack_button = QM_NIL |
||
712 | -- Search for an attack button, and remember it. |
||
713 | for i = 1,72 do |
||
714 | if IsAttackAction(i) then |
||
715 | attack_button = i |
||
716 | break; |
||
717 | end |
||
718 | end |
||
719 | end |
||
720 | if attack_button ~= QM_NIL then |
||
721 | local isusable, mana = IsUsableAction(attack_button) |
||
722 | if isusable == nil or isusable == false then |
||
723 | mounted = true |
||
724 | end |
||
725 | end |
||
726 | end |
||
727 | |||
728 | -- Only attempt to equip if it's different from last time. |
||
729 | if QuickMount_ConfigMap[QMCP]["last_action"] == nil or QuickMount_ConfigMap[QMCP]["last_action"] ~= mounted then |
||
730 | QuickMount_ConfigMap[QMCP]["last_action"] = mounted |
||
731 | local row1, row2; |
||
732 | if mounted then |
||
733 | row1 = MOUNT; |
||
734 | row2 = UNMOUNT; |
||
735 | else |
||
736 | row1 = UNMOUNT; |
||
737 | row2 = MOUNT; |
||
738 | end |
||
739 | IGNORE_SWITCH = true; |
||
740 | items = ""; |
||
741 | for i in QuickMount_ConfigMap[QMCP][row1] do |
||
742 | local x, y; |
||
743 | x = QM_NIL; y = QM_NIL; |
||
744 | if QuickMount_ConfigMap[QMCP][row1][i].id > 0 and QuickMount_ConfigMap[QMCP][row2][i].id > 0 and QuickMount_ConfigMap[QMCP][row1][i].name ~= QuickMount_ConfigMap[QMCP][row2][i].name then |
||
745 | -- Swap Items |
||
746 | x, y = QuickMount_FindInvItem(QuickMount_ConfigMap[QMCP][row2][i].name, true); |
||
747 | if CursorHasItem() then |
||
748 | x, y = QuickMount_FindBagItem(QuickMount_ConfigMap[QMCP][row1][i].name, true); |
||
749 | if CursorHasItem() then |
||
750 | y = QM_NIL; |
||
751 | AutoEquipCursorItem(); |
||
752 | end |
||
753 | else |
||
754 | x, y = QuickMount_FindBagItem(QuickMount_ConfigMap[QMCP][row1][i].name, true, true); |
||
755 | end |
||
756 | elseif QuickMount_ConfigMap[QMCP][row1][i].id > 0 then |
||
757 | x, y = QuickMount_FindBagItem(QuickMount_ConfigMap[QMCP][row1][i].name, true, true); |
||
758 | end |
||
759 | if y >= 0 then |
||
760 | items = items .. ' "' .. QuickMount_ConfigMap[QMCP][row1][i].name .. '"'; |
||
761 | end |
||
762 | end |
||
763 | if items ~= "" and QuickMount_ConfigMap[QMCP]["Quiet"] == false then |
||
764 | QM_Print("Equipped" .. items); |
||
765 | end |
||
766 | IGNORE_SWITCH = false; |
||
767 | end -- last_action |
||
768 | end -- combat_flag |
||
769 | end |
||
770 | |||
771 | function QM_Print(msg) |
||
772 | DEFAULT_CHAT_FRAME:AddMessage(msg); |
||
773 | end |
||
774 | |||
775 | function QuickMount_ButtonLoad() |
||
776 | this:RegisterForDrag("LeftButton", "RightButton"); |
||
777 | this:RegisterForClicks("LeftButtonUp", "RightButtonUp"); |
||
778 | end |
||
779 | |||
780 | function QuickMount_FindBagItem(name, pickup, equip) |
||
781 | if name == nil then |
||
782 | return QM_NIL, QM_NIL; |
||
783 | end |
||
784 | -- Look in bags. |
||
785 | for i = 0, 4, 1 do |
||
786 | local numSlot = GetContainerNumSlots(i); |
||
787 | for y = 1, numSlot, 1 do |
||
788 | if (strupper(QuickMount_GetItemName(i, y)) == strupper(name)) then |
||
789 | if pickup or equip then |
||
790 | PickupContainerItem(i,y); |
||
791 | if equip then |
||
792 | AutoEquipCursorItem(); |
||
793 | end |
||
794 | end |
||
795 | return i,y; |
||
796 | end |
||
797 | end |
||
798 | end |
||
799 | |||
800 | return QM_NIL, QM_NIL; |
||
801 | end |
||
802 | |||
803 | function QuickMount_FindInvItem(name, pickup) |
||
804 | if name == nil then |
||
805 | return QM_NIL, QM_NIL; |
||
806 | end |
||
807 | |||
808 | -- Look in inventory. |
||
809 | for i = 1, 19, 1 do |
||
810 | if (strupper(QuickMount_GetItemName(QM_NIL, i)) == strupper(name)) then |
||
811 | if pickup then |
||
812 | PickupInventoryItem(i); |
||
813 | end |
||
814 | return QM_NIL, i; |
||
815 | end |
||
816 | end |
||
817 | |||
818 | return QM_NIL, QM_NIL; |
||
819 | end |
||
820 | |||
821 | function QuickMount_FindItem(bag, slot, name, pickup, equip) |
||
822 | if name == nil then |
||
823 | return QM_NIL, QM_NIL; |
||
824 | end |
||
825 | -- First look where it's suggested we look. |
||
826 | --[[ NOT WORKING... Cacheing problem? |
||
827 | if (strupper(QuickMount_GetItemName(bag,slot)) == strupper(name)) then |
||
828 | if pickup then |
||
829 | if bag >= 0 then |
||
830 | PickupContainerItem(bag,slot); |
||
831 | else |
||
832 | PickupInventoryItem(slot); |
||
833 | end |
||
834 | end |
||
835 | return bag, slot; |
||
836 | end |
||
837 | ]] |
||
838 | |||
839 | local x, y = QuickMount_FindBagItem(name, pickup, equip); |
||
840 | |||
841 | if equip then |
||
842 | return x, y; |
||
843 | end |
||
844 | |||
845 | if x < 0 then |
||
846 | x, y = QuickMount_FindInvItem(name, pickup); |
||
847 | end |
||
848 | |||
849 | return x, y; |
||
850 | end |
||
851 | |||
852 | -- Erases the old button with the hand |
||
853 | function QuickMount_SetButton(row, col) |
||
854 | if QuickMount_CheckPlayer() == false then |
||
855 | return; |
||
856 | end |
||
857 | -- Set the new button |
||
858 | QuickMount_ConfigMap[QMCP][row][col] = {id=QuickMount_CurrentID,bag=QuickMount_CurrentBag,slot=QuickMount_CurrentSlot,name=QuickMount_CurrentName,texture=QuickMount_CurrentTexture}; |
||
859 | QuickMount_DropItem(); |
||
860 | |||
861 | QuickMount_ButtonUpdate(this); |
||
862 | end |
||
863 | |||
864 | -- Swaps the specified button into hand |
||
865 | function QuickMount_SwapButton(row,col) |
||
866 | if QuickMount_CheckPlayer() == false then |
||
867 | return; |
||
868 | end |
||
869 | -- Store the old value if one exists |
||
870 | local temp = nil; |
||
871 | if ( QuickMount_ConfigMap[QMCP][row][col].id > 0 ) then |
||
872 | temp = QuickMount_ConfigMap[QMCP][row][col]; |
||
873 | end |
||
874 | |||
875 | -- Drop the current button |
||
876 | QuickMount_SetButton(row, col); |
||
877 | |||
878 | -- Load the old one into the cursor |
||
879 | if ( temp ) then |
||
880 | if ( temp.id > 0 ) then |
||
881 | local bag, slot = QuickMount_FindItem(temp.bag, temp.slot, temp.name, true); |
||
882 | QuickMount_PickupItem(bag, slot, temp.name, temp.texture); |
||
883 | end |
||
884 | end |
||
885 | end |
||
886 | |||
887 | |||
888 | -- Button Event Handler |
||
889 | function QuickMount_ButtonEvent(event) |
||
890 | end |
||
891 | |||
892 | -- Move the Equipment around |
||
893 | function QuickMount_ButtonDragStart() |
||
894 | local col, row = QuickMount_GetCurrentLocation(this); |
||
895 | |||
896 | -- Pick up the current item |
||
897 | QuickMount_SwapButton(row,col); |
||
898 | end |
||
899 | |||
900 | -- |
||
901 | -- Swap or pick up if clicked with or without a full hand |
||
902 | -- |
||
903 | function QuickMount_ButtonClick(button) |
||
904 | if QuickMount_CheckPlayer() == false then |
||
905 | return; |
||
906 | end |
||
907 | local col, row = QuickMount_GetCurrentLocation(this); |
||
908 | |||
909 | if IsShiftKeyDown() then |
||
910 | QuickMount_ConfigMap[QMCP][row][col] = {id=QM_NIL;bag=QM_NIL;slot=QM_NIL;texture="";name="";}; |
||
911 | QuickMount_ButtonUpdate(this); |
||
912 | elseif IsAltKeyDown() then |
||
913 | -- PrintTable(QuickMount_ConfigMap[QMCP][row][col]); |
||
914 | else |
||
915 | -- Pick up the current item |
||
916 | QuickMount_SwapButton(row,col); |
||
917 | end |
||
918 | end |
||
919 | |||
920 | function QuickMount_ButtonDragEnd() |
||
921 | if QuickMount_CheckPlayer() == false then |
||
922 | return; |
||
923 | end |
||
924 | if( QuickMount_CurrentID > 0 ) then |
||
925 | local col, row = QuickMount_GetCurrentLocation(this); |
||
926 | QuickMount_SwapButton(row,col); |
||
927 | end |
||
928 | end |
||
929 | |||
930 | -- Displays the tooltip of the item in the box. |
||
931 | function QuickMount_ButtonEnter() |
||
932 | if QuickMount_CheckPlayer() == false then |
||
933 | return; |
||
934 | end |
||
935 | local col, row = QuickMount_GetCurrentLocation(this); |
||
936 | |||
937 | local id = QuickMount_ConfigMap[QMCP][row][col].id; |
||
938 | local tooltip = QuickMount_ConfigMap[QMCP][row][col].name; |
||
939 | |||
940 | if ( id > 0 ) then |
||
941 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); |
||
942 | if ( GameTooltip:SetText(tooltip) ) then |
||
943 | this.updateTooltip = TOOLTIP_UPDATE_TIME; |
||
944 | else |
||
945 | this.updateTooltip = nil; |
||
946 | end |
||
947 | end |
||
948 | end |
||
949 | |||
950 | function QuickMount_ButtonLeave() |
||
951 | GameTooltip:Hide(); |
||
952 | end |
||
953 | |||
954 | function QuickMount_ButtonLoad() |
||
955 | end |
||
956 | |||
957 | -- Self Texture Button |
||
958 | function QuickMount_SetSelfTexture(button, row, col) |
||
959 | if QuickMount_CheckPlayer() == false then |
||
960 | return; |
||
961 | end |
||
962 | local name = button:GetName(); |
||
963 | local icon = getglobal(name.."Icon"); |
||
964 | |||
965 | if ( QuickMount_ConfigMap[QMCP][row] == nil ) then return end |
||
966 | local id = QuickMount_ConfigMap[QMCP][row][col].id; |
||
967 | |||
968 | if ( id > 0 ) then |
||
969 | -- Set the pretty texture |
||
970 | local texture = QuickMount_ConfigMap[QMCP][row][col].texture; |
||
971 | if ( texture ) then |
||
972 | icon:SetTexture(texture); |
||
973 | icon:Show(); |
||
974 | else |
||
975 | icon:Hide(); |
||
976 | end |
||
977 | else |
||
978 | icon:Hide(); |
||
979 | end |
||
980 | end |
||
981 | |||
982 | -- Button Update |
||
983 | function QuickMount_ButtonUpdate(button) |
||
984 | -- Check the button |
||
985 | if ( button == nil ) then return; end |
||
986 | |||
987 | -- Uncheck it |
||
988 | button:SetChecked("false"); |
||
989 | local col, row = QuickMount_GetCurrentLocation(button); |
||
990 | |||
991 | -- Check for errors |
||
992 | if ( col == nil or row == nil ) then return; end |
||
993 | |||
994 | -- Enable the button |
||
995 | button:Enable(); |
||
996 | QuickMount_SetSelfTexture(button, row, col); |
||
997 | end |
||
998 | |||
999 | function QuickMount_UpdateSet(setbasename,set,size) |
||
1000 | if set == nul then return; end |
||
1001 | |||
1002 | for i=1,size,1 do |
||
1003 | QuickMount_ButtonUpdate(getglobal(setbasename..set..i)); |
||
1004 | end |
||
1005 | end |
||
1006 | |||
1007 | function QuickMount_UpdateAllSets() |
||
1008 | for set=1,QM_SET_COUNT,1 do |
||
1009 | QuickMount_UpdateSet("QuickMountButtonSet",set,QM_SET_SIZE); |
||
1010 | end |
||
1011 | end |
||
1012 | |||
1013 | -- Tracks the last item picked up |
||
1014 | function QuickMount_PickupItem(bag, slot, name, texture) |
||
1015 | QuickMount_CurrentID = 1; |
||
1016 | QuickMount_CurrentBag = bag; |
||
1017 | QuickMount_CurrentSlot = slot; |
||
1018 | QuickMount_CurrentName = name; |
||
1019 | QuickMount_CurrentTexture = texture; |
||
1020 | end |
||
1021 | |||
1022 | function QuickMount_ResetItem() |
||
1023 | QuickMount_CurrentID = QM_NIL; |
||
1024 | QuickMount_CurrentBag = QM_NIL; |
||
1025 | QuickMount_CurrentSlot = QM_NIL; |
||
1026 | QuickMount_CurrentName = ""; |
||
1027 | QuickMount_CurrentTexture = ""; |
||
1028 | end |
||
1029 | |||
1030 | function QuickMount_DropItem() |
||
1031 | if CursorHasItem() then |
||
1032 | if QuickMount_CurrentBag >= 0 then |
||
1033 | PickupContainerItem(QuickMount_CurrentBag,QuickMount_CurrentSlot); |
||
1034 | elseif QuickMount_CurrentSlot >= 0 then |
||
1035 | PickupInventoryItem(QuickMount_CurrentSlot); |
||
1036 | end |
||
1037 | end |
||
1038 | QuickMount_ResetItem(); |
||
1039 | end |
||
1040 | |||
1041 | function QuickMountCheckButton_OnClick() |
||
1042 | if (this:GetChecked()) then |
||
1043 | this.ExecuteCommand(true); |
||
1044 | else |
||
1045 | this.ExecuteCommand(false); |
||
1046 | end |
||
1047 | end |
||
1048 | |||
1049 | function QuickMountCheckButton_OnEnter() |
||
1050 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); |
||
1051 | if ( GameTooltip:SetText(this.myToolTip) ) then |
||
1052 | this.updateTooltip = TOOLTIP_UPDATE_TIME; |
||
1053 | else |
||
1054 | this.updateTooltip = nil; |
||
1055 | end |
||
1056 | end |
||
1057 | |||
1058 | function QuickMountCheckButton_OnLeave() |
||
1059 | GameTooltip:Hide(); |
||
1060 | end |
||
1061 | |||
1062 | -- Returns the current button location |
||
1063 | function QuickMount_GetCurrentLocation(object) |
||
1064 | return object:GetID(), object:GetParent():GetID(); |
||
1065 | end |