comparison SkeletonKey/ActionTypes.lua @ 19:67db6b712bf3

- option checkbutton literals are stored by enclosure - detect and save any old keybindings when a slot is assigned (anything that begins with 'CLICK KeyBinder*' is ours) - mouseover mode key input will stay active after leaving a button - button border flashes when a non-modifier key is pressed
author Nenue
date Sat, 30 Jul 2016 19:08:11 -0400
parents 500f9b2bd9ac
children 564015ef0317
comparison
equal deleted inserted replaced
18:91398d284a99 19:67db6b712bf3
19 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'}, 19 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'},
20 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'}, 20 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'},
21 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'}, 21 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'},
22 } 22 }
23 23
24 kb.ActionTypes = {}
25 kb.PetCache = {}
26 kb.TalentCache = {}
27 kb.ProfessionCache = {}
28
29 local atype = kb.ActionTypes
30
24 --- Caps Lock 31 --- Caps Lock
25 local ACTION_HANDLERS = {} 32 atype['mount'] = function(id, name)
26 ACTION_HANDLERS['mount'] = function(id, name)
27 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then 33 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then
28 return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO 34 return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO
29 else 35 else
30 return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO 36 return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO
31 end 37 end
32 end 38 end
33 ACTION_HANDLERS['macro'] = function(id, name) 39
40 atype['macro'] = function(id, name)
34 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id 41 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id
35 end 42 end
36 ACTION_HANDLERS['equipset'] = function(id, name) 43
44 atype['equipset'] = function(id, name)
37 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")" 45 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")"
38 end 46 end
39 ACTION_HANDLERS['spell'] = function(id, name) 47
48 atype['spell'] = function(id, name)
40 local attributeName = name 49 local attributeName = name
41 if kb.ProfessionCache[id] then 50 if kb.ProfessionCache[id] then
42 attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum 51 attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum
43 end 52 end
44 return CLICK_KEYBINDER_KEY, attributeName, name 53 return CLICK_KEYBINDER_KEY, attributeName, name
45 end 54 end
46 ACTION_HANDLERS['petaction'] = function(_, name) 55
56 atype['petaction'] = function(_, name)
47 -- ID doesn't exist for basic commands, even though they can be picked up 57 -- ID doesn't exist for basic commands, even though they can be picked up
48 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name) 58 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
49 if PETACTION_SCRIPT[name] then 59 if PETACTION_SCRIPT[name] then
50 attributeValue, attributeName = unpack(PETACTION_SCRIPT[name]) 60 attributeValue, attributeName = unpack(PETACTION_SCRIPT[name])
51 end 61 elseif kb.PetCache.special[name] then
52 62 attributeName = "petaction_special" .. tonumber(kb.PetCache.special[name][2])
63 end
53 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue 64 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue
54 end 65 end
55 66
56 ACTION_HANDLERS['battlepet'] = function(id, name) 67 atype['battlepet'] = function(id, name)
57 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name) 68 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name)
58 end 69 end
59 ACTION_HANDLERS['item'] = function(id, name) 70
71 atype['item'] = function(id, name)
60 return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id 72 return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id
61 end 73 end
62 74
63 75
64 --- Resolves the SecureActionButton attribute names used for the given action 76 --- Resolves the SecureActionButton attribute names used for the given action
65 kb.RegisterAction = function(actionType, id, name) 77 kb.RegisterAction = function(actionType, id, name)
66 78
67 assert(ACTION_HANDLERS[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') 79 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
68 local target, attributeName, attributeValue = ACTION_HANDLERS[actionType](id, name) 80 local target, attributeName, attributeValue = atype[actionType](id, name)
69 81
70 local command = target .. attributeName 82 local command = target .. attributeName
71 local baseName, iterative = attributeName, 1 83 local baseName, iterative = attributeName, 1
72 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do 84 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
73 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"') 85 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
87 end 99 end
88 100
89 101
90 102
91 103
92 kb.inactiveTalentBindings = {}
93 kb.ApplyTalentBinding = function(talentInfo, cache) 104 kb.ApplyTalentBinding = function(talentInfo, cache)
94 for i = 5, #talentInfo do 105 for i = 5, #talentInfo do
95 local command = CLICK_KEYBINDER_KEY.. talentInfo[2] 106 local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
96 SetBinding(talentInfo[i], command) 107 SetBinding(talentInfo[i], command)
97 cprint(' **', talentInfo[i], '->', command) 108 cprint(' **', talentInfo[i], '->', command)
99 end 110 end
100 end 111 end
101 kb.CacheTalentBinding = function(talentInfo, cache) 112 kb.CacheTalentBinding = function(talentInfo, cache)
102 113
103 local spellID = talentInfo[4] 114 local spellID = talentInfo[4]
104 kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {} 115 cache[spellID] = cache[spellID] or {}
105 kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) } 116 cache[spellID] = {select(5,unpack(talentInfo)) }
106 --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID])) 117 --cprint(spellID, unpack(kb.TalentBindings[spellID]))
107 end 118 end
108 119
109 do 120 do
110 local bindings = kb.bindings 121 local bindings = kb.bindings
111 local key, macro = KeyBinderKey, KeyBinderMacro 122 local key, macro = KeyBinderKey, KeyBinderMacro
148 end 159 end
149 160
150 for spellName, talentInfo in pairs(profile.talents) do 161 for spellName, talentInfo in pairs(profile.talents) do
151 local dummy = GetSpellInfo(spellName) 162 local dummy = GetSpellInfo(spellName)
152 local func = kb.CacheTalentBinding 163 local func = kb.CacheTalentBinding
153 local dest = kb.inactiveTalentBindings 164 local dest = kb.TalentBindings
154 if dummy then 165 if dummy then
155 cprint('|cFFBBFF00Active:|r', dummy) 166 cprint('|cFFBBFF00Active:|r', dummy)
156 local macroName, spellName, actionType, actionID = unpack(talentInfo) 167 local macroName, spellName, actionType, actionID = unpack(talentInfo)
157 bindings[actionType] = bindings[actionType] or {} 168 bindings[actionType] = bindings[actionType] or {}
158 bindings[actionType][actionID] = {} 169 bindings[actionType][actionID] = {}
166 end 177 end
167 178
168 end 179 end
169 180
170 kb.ApplyAllBindings =function () 181 kb.ApplyAllBindings =function ()
171 table.wipe(kb.inactiveTalentBindings) 182 table.wipe(kb.TalentBindings)
172 183
173 184
174 -- reflect action key settings 185 -- reflect action key settings
175 if GetCVarBool("ActionButtonUseKeyDown") then 186 if GetCVarBool("ActionButtonUseKeyDown") then
176 KeyBinderMacro:RegisterForClicks("AnyDown") 187 KeyBinderMacro:RegisterForClicks("AnyDown")
188 199
189 200
190 SaveBindings(GetCurrentBindingSet()) 201 SaveBindings(GetCurrentBindingSet())
191 end 202 end
192 end 203 end
204
205
206 local PET_SPECIAL_SUBTEXT = 'Special Ability'
207 local SECONDARY_PROFESSIONS = {
208 [5] = 3,
209 [7] = 4,
210 [9] = 5,
211 [10] = 6
212 }
213
214 kb.TalentCache = {}
215 kb.ProfessionCache = {}
216 kb.PetCache = {}
217 kb.specInfo = {}
218 kb.UpdateSpecInfo = function()
219 kb.specInfo.id = GetSpecialization()
220 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
221 print('|cFF00FF00current spec:|r', kb.specInfo.id, 'of', GetNumSpecializations())
222 end
223
224 kb.UpdateTalentInfo = function()
225 if kb.talentsPushed then
226 return
227 end
228 table.wipe(kb.TalentCache)
229 for row =1, MAX_TALENT_TIERS do
230 for col = 1, NUM_TALENT_COLUMNS do
231 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
232 local talentInfo = kb.TalentCache[spellID] or {}
233 talentInfo.row = 1
234 talentInfo.col = col
235 talentInfo.name = talentName
236 talentInfo.talentID = talentID
237 talentInfo.selected = selected
238 talentInfo.available = available
239 talentInfo.spellID = spellID
240 kb.TalentCache[spellID] = talentInfo
241 kb.TalentCache[talentName] = talentInfo
242 print('Talent ', row, col, spellID, talentName)
243 end
244 end
245 kb.talentsPushed = true
246
247 kb.UpdateDynamicButtons('talent')
248 end
249
250 kb.UpdateProfessionInfo = function()
251 table.wipe(kb.ProfessionCache)
252 local profs = {GetProfessions() }
253 local primaryNum = 0
254 for i, index in ipairs(profs) do
255 local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index)
256 print(i, index, profName, numSpells, spellOffset)
257 if not SECONDARY_PROFESSIONS[index] then
258 primaryNum = primaryNum + 1
259 end
260 local profNum = SECONDARY_PROFESSIONS[index] or primaryNum
261
262
263 kb.ProfessionCache[profNum] = kb.ProfessionCache[i] or {}
264
265 for j = 1, numSpells do
266 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
267
268 local profInfo = {
269 spellName = spellName,
270 spellID = spellID,
271 icon = icon,
272 profOffset = i,
273 profIndex = index,
274 spellOffset = (spellOffset+j),
275 spellNum = j
276 }
277 KeyBinderKey:SetAttribute("*type-profession_"..i .. '_' ..j, "spell")
278 KeyBinderKey:SetAttribute("*spell-profession_"..i .. '_' ..j, spellName)
279
280 kb.ProfessionCache[i .. '_' .. j] = profInfo
281 kb.ProfessionCache[spellName] = profInfo
282 kb.ProfessionCache[spellID] = profInfo
283 print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
284 end
285
286 end
287
288 kb.UpdateDynamicButtons('profession')
289 end
290
291
292
293 kb.UpdatePetInfo = function()
294 kb.PetCache.spell = kb.PetCache.spell or {}
295 kb.PetCache.spellslot = kb.PetCache.spellslot or {}
296 kb.PetCache.action = kb.PetCache.action or {}
297 kb.PetCache.special = kb.PetCache.action or {}
298 local hasPetSpells, petType = HasPetSpells()
299 if PetHasSpellbook() then
300 print('PET SPELLBOOK')
301 local i = 1
302 local specialNum = 0
303 repeat
304
305 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
306 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
307 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
308 if not isPassive then
309 if spellName then
310 kb.PetCache.spellslot[spellName] = {i, spellName, subText}
311 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
312
313 if subText == PET_SPECIAL_SUBTEXT then
314 specialNum = specialNum + 1
315 kb.PetCache.special[spellName] = {i, specialNum, spellID, subText }
316 print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText)
317 KeyBinderMacro:SetAttribute("*macrotext-pet_special_"..specialNum, "/cast "..spellName)
318 end
319
320 if spellID then
321 kb.PetCache.spell[i] = {spellID, spellName, subText}
322 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
323 end
324 end
325
326
327 end
328
329 i = i + 1
330 until spellType == nil
331 else
332 print('NO PET SPELLBOOK')
333 table.wipe(kb.PetCache.spell)
334 table.wipe(kb.PetCache.spellslot)
335 end
336
337 if PetHasActionBar() then
338 print('PET ACTION BAR')
339 for i = 1, 10 do
340
341
342 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
343 if name then
344 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
345
346
347 end
348 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
349 end
350 else
351 print('NO PET ACTION BAR')
352 table.wipe(kb.PetCache.action)
353 end
354
355 kb.UpdateDynamicButtons('petaction')
356
357 end
358
359 kb.UpdateSystemBinds = function()
360 table.wipe(kb.SystemBindings)
361 local n = GetNumBindings()
362 for i=1, n do
363 local command, key1, key2 = GetBinding(i)
364 if key1 then
365 kb.SystemBindings[key1] = command
366 end
367 if key2 then
368 kb.SystemBindings[key2] = command
369 end
370 end
371 end
372
373 kb.UpdateDynamicButtons = function(dynamicType)
374 for i, button in ipairs(kb.buttons) do
375 if button.isDynamic == dynamicType then
376 kb.UpdateSlot(button, true)
377 end
378 end
379 end