Mercurial > wow > skeletonkey
comparison SkeletonKey/KeySlot.lua @ 15:32d64e42ec9b
- resolve pet bar actions for binding slots
- detect type of petaction (can be spell, stance, or 'PETACTION')
- keep track of displayed pet ability slots and update them alongside pet cache refreshes
author | Nenue |
---|---|
date | Fri, 29 Jul 2016 03:27:15 -0400 |
parents | 82170735e67c |
children | cdd387d39137 |
comparison
equal
deleted
inserted
replaced
14:82170735e67c | 15:32d64e42ec9b |
---|---|
5 -- All the internal slot logic is kept here | 5 -- All the internal slot logic is kept here |
6 | 6 |
7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') | 7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') |
8 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION | 8 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION |
9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 | 9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 |
10 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1 } | 10 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} |
11 local BORDER_ASSIGNED = {0.5,0.5,0.5,1 } | 11 local BORDER_ASSIGNED = {1,1,1,1} |
12 local BORDER_DYNAMIC = {1,1,0,1} | 12 local BORDER_DYNAMIC = {1,1,0,1} |
13 local BORDER_PENDING = {1,0.5,0,1 } | 13 local BORDER_PENDING = {1,0.5,0,1 } |
14 | 14 |
15 local BUTTON_HEADERS = { | 15 local BUTTON_HEADERS = { |
16 ['spell'] = SPELLS, | 16 ['spell'] = SPELLS, |
37 do | 37 do |
38 -- Pet actions | 38 -- Pet actions |
39 local isPickup | 39 local isPickup |
40 hooksecurefunc("PickupPetAction", function(slot, ...) | 40 hooksecurefunc("PickupPetAction", function(slot, ...) |
41 isPickup = GetCursorInfo() | 41 isPickup = GetCursorInfo() |
42 | 42 print(slot, ...) |
43 CURSOR_PETACTION = isPickup and slot | 43 |
44 | |
45 if kb.PetCache.action[slot] then | |
46 if isPickup then | |
47 local key = kb.PetCache.action[slot][1] | |
48 local spellName = _G[key] or key | |
49 if spellName and kb.PetCache.spellslot[spellName] then | |
50 print('picked up', spellName, kb.PetCache.spellslot[spellName][1]) | |
51 CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1] | |
52 CURSOR_BOOKTYPE = BOOKTYPE_PET | |
53 end | |
54 | |
55 else | |
56 print('Dropped pet action =', GetPetActionInfo(slot)) | |
57 end | |
44 print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION) | 58 print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION) |
59 end | |
60 | |
61 local name, subtext, texture, isToken = GetPetActionInfo(slot) | |
62 if name then | |
63 kb.PetCache.action[slot] = {name, subtext, texture, isToken} | |
64 end | |
65 | |
45 end) | 66 end) |
46 end | 67 end |
47 | 68 |
48 | 69 |
49 kb.DropToSlot = function(self) | 70 kb.DropToSlot = function(self) |
57 ResetCursor() | 78 ResetCursor() |
58 return | 79 return |
59 end | 80 end |
60 | 81 |
61 | 82 |
62 local macroName, macroText | 83 local name, icon, _ |
63 local command, name, icon, _ | |
64 local pickupID, pickupBook | 84 local pickupID, pickupBook |
65 | 85 |
66 if actionType == 'spell' then | 86 if actionType == 'spell' then |
67 actionID = subData | 87 actionID = subData |
68 name, _, icon = GetSpellInfo(actionID) | 88 name, _, icon = GetSpellInfo(actionID) |
69 | 89 |
70 elseif actionType == 'macro' then | 90 elseif actionType == 'macro' then |
71 name, icon = GetMacroInfo(actionID) | 91 name, icon = GetMacroInfo(actionID) |
72 elseif actionType == 'petaction' then | 92 elseif actionType == 'petaction' then |
73 if not (CURSOR_SPELLSLOT and CURSOR_BOOKTYPE) then | 93 if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then |
74 | 94 |
75 ClearCursor() | 95 local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) |
76 ResetCursor() | 96 local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) |
77 end | 97 if spellType == 'PETACTION' then |
78 | 98 actionID = spellText |
79 local bookType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE) | 99 else |
80 actionID = spellID | 100 name, _, icon = GetSpellInfo(spellID) |
81 pickupID = CURSOR_SPELLSLOT | 101 actionID = spellID |
82 pickupBook = CURSOR_BOOKTYPE | 102 end |
83 name, _, icon = GetSpellInfo(spellID) | 103 |
104 pickupID = CURSOR_SPELLSLOT | |
105 pickupBook = CURSOR_BOOKTYPE | |
106 else | |
107 | |
108 end | |
109 | |
84 elseif actionType == 'mount' then | 110 elseif actionType == 'mount' then |
85 if subType == 0 then | 111 if subType == 0 then |
86 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL) | 112 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL) |
87 actionID = 0 | 113 actionID = 0 |
88 else | 114 else |
97 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = C_PetJournal.GetPetInfoByPetID(detail); | 123 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = C_PetJournal.GetPetInfoByPetID(detail); |
98 name = customName or petName | 124 name = customName or petName |
99 icon = petIcon | 125 icon = petIcon |
100 | 126 |
101 end | 127 end |
102 macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) | 128 local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) |
103 | 129 |
104 | 130 |
105 local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command) | 131 local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command) |
106 if isAssigned then | 132 if isAssigned then |
107 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] | 133 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] |
133 local GetPickupValue = { | 159 local GetPickupValue = { |
134 spell = function(self) return select(7, GetSpellInfo(self.actionID)) end, | 160 spell = function(self) return select(7, GetSpellInfo(self.actionID)) end, |
135 petaction = function(self) return self.pickupSlot, self.pickupBook end, | 161 petaction = function(self) return self.pickupSlot, self.pickupBook end, |
136 } | 162 } |
137 kb.PickupSlot = function(self) | 163 kb.PickupSlot = function(self) |
138 if not self.command then | 164 if not (self.command and self.isAvailable) then |
139 return | 165 return |
140 end | 166 end |
141 print(self.actionType) | 167 print(self.actionType) |
142 if self.actionType == 'spell' then | 168 if self.actionType == 'spell' then |
143 -- It can't be picked up if SpellInfo(name) returns void | 169 -- It can't be picked up if SpellInfo(name) returns void |
173 end | 199 end |
174 | 200 |
175 if self.command then | 201 if self.command then |
176 print('['..slot..'] =', self.command, GetBindingKey(self.command)) | 202 print('['..slot..'] =', self.command, GetBindingKey(self.command)) |
177 | 203 |
178 if self.pending then | 204 if not self.isAvailable then |
179 self.border:SetColorTexture(unpack(BORDER_PENDING)) | 205 self.border:SetColorTexture(1,0,0,1) |
180 elseif self.isDynamic then | 206 self.ignoreTexture:Show() |
181 self.border:SetColorTexture(unpack(BORDER_DYNAMIC)) | 207 else |
182 else | 208 self.ignoreTexture:Hide() |
183 self.border:SetColorTexture(unpack(BORDER_ASSIGNED)) | 209 |
184 end | 210 if self.pending then |
211 self.border:SetColorTexture(unpack(BORDER_PENDING)) | |
212 elseif self.isDynamic then | |
213 self.border:SetColorTexture(unpack(BORDER_DYNAMIC)) | |
214 else | |
215 self.border:SetColorTexture(unpack(BORDER_ASSIGNED)) | |
216 end | |
217 end | |
218 | |
185 | 219 |
186 if self.actionType == 'macro' then | 220 if self.actionType == 'macro' then |
187 self.macro:Show() | 221 self.macro:Show() |
188 else | 222 else |
189 self.macro:Hide() | 223 self.macro:Hide() |
197 | 231 |
198 end | 232 end |
199 end | 233 end |
200 | 234 |
201 if self.isDynamic then | 235 if self.isDynamic then |
202 print('|cFFFFBB00UpdateSlot|r: ', self.isDynamic, self.isAvailable, self.actionID) | 236 print('|cFF00BBFFUpdateSlot|r:', self.isDynamic, self.isAvailable, self.actionID) |
203 end | 237 end |
204 | 238 |
205 if self.isDynamic == 'profession' then | 239 if self.isDynamic == 'profession' then |
206 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex)) | 240 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex)) |
207 if self.isAvailable then | 241 if self.isAvailable then |
224 print(self.actionID, #kb.inactiveTalentBindings[self.actionID]) | 258 print(self.actionID, #kb.inactiveTalentBindings[self.actionID]) |
225 self.bindingText= kb.BindingString(unpack(kb.inactiveTalentBindings[self.actionID])) | 259 self.bindingText= kb.BindingString(unpack(kb.inactiveTalentBindings[self.actionID])) |
226 end | 260 end |
227 | 261 |
228 end | 262 end |
263 elseif self.isDynamic == 'petaction' and self.command:match("special") then | |
264 self.statusText = '|cFF00FF00Pet Special|r' | |
265 self.bindingText = kb.BindingString(GetBindingKey(self.command)) | |
229 else | 266 else |
230 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r' | 267 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r' |
231 self.bindingText = kb.BindingString(GetBindingKey(self.command)) | 268 self.bindingText = kb.BindingString(GetBindingKey(self.command)) |
232 end | 269 end |
233 | 270 |
298 self.profile = nil | 335 self.profile = nil |
299 self.icon:SetTexture(nil) | 336 self.icon:SetTexture(nil) |
300 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED)) | 337 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED)) |
301 self:EnableKeyboard(false) | 338 self:EnableKeyboard(false) |
302 self:SetScript('OnKeyDown', nil) | 339 self:SetScript('OnKeyDown', nil) |
340 self.ignoreTexture:Hide() | |
303 end | 341 end |
304 | 342 |
305 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook) | 343 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook) |
306 local slot = self:GetID() | 344 local slot = self:GetID() |
307 local isDynamic, isAvailable | 345 local isDynamic, isAvailable |
333 isDynamic = 'talent' | 371 isDynamic = 'talent' |
334 print(' Special slot: |cFFBBFF00talent|r', name, isAvailable) | 372 print(' Special slot: |cFFBBFF00talent|r', name, isAvailable) |
335 end | 373 end |
336 | 374 |
337 isAvailable = GetSpellInfo(name) | 375 isAvailable = GetSpellInfo(name) |
376 end | |
377 elseif actionType == 'petaction' then | |
378 isDynamic = 'petaction' | |
379 if kb.PetCache.spellslot and kb.PetCache.spellslot[name] then | |
380 isAvailable = true | |
381 kb.RemoveCacheButton(kb.petFrames, self) | |
382 else | |
383 print('|cFFFF4400OnCacheUpdate, re-do #', slot) | |
384 tinsert(kb.petFrames, self) | |
338 end | 385 end |
339 elseif actionType == 'macro' then | 386 elseif actionType == 'macro' then |
340 if not actionID then | 387 if not actionID then |
341 actionID = GetMacroIndexByName(name) | 388 actionID = GetMacroIndexByName(name) |
342 end | 389 end |
364 end | 411 end |
365 end | 412 end |
366 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText) | 413 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText) |
367 end | 414 end |
368 | 415 |
369 if actionType == 'petaction' then | |
370 self.pickupSlot = pickupSlot | |
371 self.pickupBook = pickupBook | |
372 else | |
373 self.pickupSlot = nil | |
374 self.pickupBook = nil | |
375 end | |
376 | 416 |
377 actionID = actionID or 0 | 417 actionID = actionID or 0 |
378 self:EnableKeyboard(true) | 418 self:EnableKeyboard(true) |
379 print(' |cFF00FF00kb.currentProfile.buttons['..slot..'] |cFF00FFFF=|r |cFF00FFFF"'.. command.. '"|r |cFF00FF00"'.. name, '"|r |cFFFFFF00icon:'.. icon .. '|r |cFFFF8800"'.. actionType, '"|r |cFFFF0088id:'.. actionID ..'|r |cFF00FF00"'.. macroName .. '"|r') | 419 print(' |cFF00FF00kb.currentProfile.buttons['..slot..'] |cFF00FFFF=|r |cFF00FFFF"'.. command.. '"|r |cFF00FF00"'.. name.. '"|r |cFFFFFF00icon:'.. icon .. '|r |cFFFF8800"'.. actionType, '"|r |cFFFF0088id:'.. actionID ..'|r |cFF00FF00"'.. macroName .. '"|r') |
380 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook} | 420 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook} |
381 | 421 |
382 -- Clean up conflicting entries for loaded button | 422 -- Clean up conflicting entries for loaded button |
383 local previous = kb.currentProfile.commands[command] | 423 local previous = kb.currentProfile.commands[command] |
384 if previous ~= slot and kb.buttons[previous] then | 424 if previous ~= slot and kb.buttons[previous] then |
388 end | 428 end |
389 | 429 |
390 self.isAvailable = isAvailable | 430 self.isAvailable = isAvailable |
391 self.isDynamic = isDynamic | 431 self.isDynamic = isDynamic |
392 | 432 |
433 self.pickupSlot = pickupSlot | |
434 self.pickupBook = pickupBook | |
393 self.macroText = macroText | 435 self.macroText = macroText |
394 self.macroName = macroName | 436 self.macroName = macroName |
395 self.actionType = actionType | 437 self.actionType = actionType |
396 self.actionID = actionID | 438 self.actionID = actionID |
397 self.actionName = name | 439 self.actionName = name |