Nenue@16
|
1 -- SkeletonKey
|
Nenue@27
|
2 -- ActionTemplates.lua
|
Nenue@16
|
3 -- Created: 7/29/2016 9:14 PM
|
Nenue@16
|
4 -- %file-revision%
|
Nenue@27
|
5 -- Code dealing with the implementation of action hotkeys
|
Nenue@27
|
6
|
Nenue@21
|
7 local tostring, tonumber, pairs, ipairs = tostring, tonumber, pairs, ipairs
|
Nenue@21
|
8 local unpack, SetBinding = unpack, SetBinding
|
Nenue@21
|
9 local tinsert, tContains, select, wipe = tinsert, tContains, select, table.wipe
|
Nenue@21
|
10 local GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo = GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo
|
Nenue@21
|
11 local GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell = GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell
|
Nenue@21
|
12 local PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells = PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells
|
Nenue@21
|
13 local GetProfessions, GetProfessionInfo, GetTalentInfo = GetProfessions, GetProfessionInfo, GetTalentInfo
|
Nenue@21
|
14 local GetNumBindings, GetBinding = GetNumBindings, GetBinding
|
Nenue@21
|
15
|
Nenue@21
|
16 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder, 'Info')
|
Nenue@34
|
17 local cprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('Cfg', ...) end or function() end
|
Nenue@16
|
18
|
Nenue@17
|
19 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:"
|
Nenue@17
|
20 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:"
|
Nenue@21
|
21 local PET_BASIC_SUBTEXT = 'Basic Attack'
|
Nenue@21
|
22 local PET_SPECIAL_SUBTEXT = 'Special Ability'
|
Nenue@16
|
23 local PETACTION_SCRIPT = {
|
Nenue@22
|
24 [PET_ACTION_MOVE_TO] = {'pet_move_to', SLASH_PET_MOVE_TO1},
|
Nenue@22
|
25 [PET_ACTION_ATTACK] = {'pet_attack', SLASH_PET_ATTACK1},
|
Nenue@22
|
26 [PET_ACTION_FOLLOW] = {'pet_follow', SLASH_PET_FOLLOW1},
|
Nenue@22
|
27 [PET_ACTION_WAIT] = {'pet_stay', SLASH_PET_STAY1 },
|
Nenue@22
|
28 [PET_MODE_AGGRESSIVE] = {'pet_aggressive', SLASH_PET_AGGRESSIVE1 },
|
Nenue@22
|
29 [PET_MODE_DEFENSIVE] = { 'pet_defensive', SLASH_PET_DEFENSIVE1},
|
Nenue@22
|
30 [PET_MODE_PASSIVE] = { 'pet_passive', SLASH_PET_PASSIVE1},
|
Nenue@22
|
31 [PET_MODE_ASSIST] = {'pet_assist', SLASH_PET_ASSIST1},
|
Nenue@16
|
32 }
|
Nenue@21
|
33 local SECONDARY_PROFESSIONS = {
|
Nenue@21
|
34 [5] = 3,
|
Nenue@21
|
35 [7] = 4,
|
Nenue@21
|
36 [9] = 5,
|
Nenue@21
|
37 [10] = 6
|
Nenue@21
|
38 }
|
Nenue@54
|
39 local petSpellCache,petSubtextCache
|
Nenue@21
|
40 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
|
Nenue@16
|
41
|
Nenue@27
|
42 --kb.ChangedBindings = {}
|
Nenue@27
|
43 --kb.ActionTypes = {}
|
Nenue@19
|
44
|
Nenue@19
|
45 local atype = kb.ActionTypes
|
Nenue@19
|
46
|
Nenue@17
|
47 --- Caps Lock
|
Nenue@19
|
48 atype['mount'] = function(id, name)
|
Nenue@17
|
49 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then
|
Nenue@24
|
50 return CLICK_KEYBINDER_MACRO, 'mount_random', "/script C_MountJournal.SummonByID(0)"
|
Nenue@17
|
51 else
|
Nenue@24
|
52 return CLICK_KEYBINDER_MACRO, 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")"
|
Nenue@17
|
53 end
|
Nenue@16
|
54 end
|
Nenue@19
|
55
|
Nenue@19
|
56 atype['macro'] = function(id, name)
|
Nenue@17
|
57 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id
|
Nenue@17
|
58 end
|
Nenue@19
|
59
|
Nenue@19
|
60 atype['equipset'] = function(id, name)
|
Nenue@17
|
61 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")"
|
Nenue@17
|
62 end
|
Nenue@19
|
63
|
Nenue@19
|
64 atype['spell'] = function(id, name)
|
Nenue@17
|
65 local attributeName = name
|
Nenue@17
|
66 if kb.ProfessionCache[id] then
|
Nenue@17
|
67 attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum
|
Nenue@17
|
68 end
|
Nenue@17
|
69 return CLICK_KEYBINDER_KEY, attributeName, name
|
Nenue@17
|
70 end
|
Nenue@19
|
71
|
Nenue@19
|
72 atype['petaction'] = function(_, name)
|
Nenue@17
|
73 -- ID doesn't exist for basic commands, even though they can be picked up
|
Nenue@17
|
74 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
|
Nenue@54
|
75
|
Nenue@54
|
76 if not petSpellCache then
|
Nenue@54
|
77 kb.UpdatePetInfo()
|
Nenue@54
|
78 end
|
Nenue@54
|
79 -- Compose a multi-macro for subtext abilities
|
Nenue@54
|
80 if petSpellCache[name] then
|
Nenue@54
|
81 attributeValue = ""
|
Nenue@54
|
82 for spellName, enabled in pairs(petSubtextCache[petSpellCache[name]]) do
|
Nenue@54
|
83 attributeValue = attributeValue .. "/cast " .. spellName .. "\n"
|
Nenue@54
|
84 end
|
Nenue@54
|
85 end
|
Nenue@54
|
86
|
Nenue@17
|
87 if PETACTION_SCRIPT[name] then
|
Nenue@22
|
88 attributeName, attributeValue = unpack(PETACTION_SCRIPT[name])
|
Nenue@19
|
89 elseif kb.PetCache.special[name] then
|
Nenue@21
|
90 attributeName = "petaction_"..kb.PetCache.special[name][3].."_" .. tonumber(kb.PetCache.special[name][6])
|
Nenue@17
|
91 end
|
Nenue@17
|
92 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue
|
Nenue@16
|
93 end
|
Nenue@16
|
94
|
Nenue@19
|
95 atype['battlepet'] = function(id, name)
|
Nenue@17
|
96 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name)
|
Nenue@17
|
97 end
|
Nenue@19
|
98
|
Nenue@19
|
99 atype['item'] = function(id, name)
|
Nenue@17
|
100 return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id
|
Nenue@17
|
101 end
|
Nenue@16
|
102
|
Nenue@16
|
103
|
Nenue@17
|
104 --- Resolves the SecureActionButton attribute names used for the given action
|
Nenue@16
|
105 kb.RegisterAction = function(actionType, id, name)
|
Nenue@16
|
106
|
Nenue@19
|
107 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
|
Nenue@19
|
108 local target, attributeName, attributeValue = atype[actionType](id, name)
|
Nenue@17
|
109
|
Nenue@17
|
110 local command = target .. attributeName
|
Nenue@17
|
111 local baseName, iterative = attributeName, 1
|
Nenue@17
|
112 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
|
Nenue@17
|
113 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
|
Nenue@17
|
114 attributeName = baseName .. '_' .. iterative
|
Nenue@17
|
115 iterative = iterative + 1
|
Nenue@17
|
116 end
|
Nenue@21
|
117 if attributeName ~= baseName then
|
Nenue@21
|
118 print(' * Creating|cFF00FF00', attributeName)
|
Nenue@17
|
119 else
|
Nenue@21
|
120 print(' * Re-using|cFF00FF00', attributeName)
|
Nenue@17
|
121 end
|
Nenue@17
|
122 kb.macros[attributeName] = {attributeValue, command}
|
Nenue@17
|
123
|
Nenue@17
|
124
|
Nenue@17
|
125 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
|
Nenue@17
|
126 return attributeName, attributeValue, command
|
Nenue@17
|
127 end
|
Nenue@17
|
128
|
Nenue@17
|
129
|
Nenue@17
|
130
|
Nenue@17
|
131
|
Nenue@17
|
132 kb.ApplyTalentBinding = function(talentInfo, cache)
|
Nenue@17
|
133 for i = 5, #talentInfo do
|
Nenue@17
|
134 local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
|
Nenue@17
|
135 SetBinding(talentInfo[i], command)
|
Nenue@17
|
136 cprint(' **', talentInfo[i], '->', command)
|
Nenue@17
|
137 tinsert(cache, talentInfo[i])
|
Nenue@17
|
138 end
|
Nenue@17
|
139 end
|
Nenue@17
|
140 kb.CacheTalentBinding = function(talentInfo, cache)
|
Nenue@17
|
141
|
Nenue@17
|
142 local spellID = talentInfo[4]
|
Nenue@19
|
143 cache[spellID] = cache[spellID] or {}
|
Nenue@19
|
144 cache[spellID] = {select(5,unpack(talentInfo)) }
|
Nenue@19
|
145 --cprint(spellID, unpack(kb.TalentBindings[spellID]))
|
Nenue@17
|
146 end
|
Nenue@17
|
147
|
Nenue@27
|
148
|
Nenue@17
|
149 do
|
Nenue@17
|
150 local bindings = kb.bindings
|
Nenue@17
|
151 local key, macro = KeyBinderKey, KeyBinderMacro
|
Nenue@17
|
152 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
|
Nenue@17
|
153
|
Nenue@17
|
154 if actionType == 'spell' then
|
Nenue@17
|
155 key:SetAttribute("*type-"..name, actionType)
|
Nenue@17
|
156 key:SetAttribute("*"..actionType.."-"..name, name)
|
Nenue@17
|
157 elseif actionType == 'item' then
|
Nenue@17
|
158 key:SetAttribute("*type-"..name, actionType)
|
Nenue@17
|
159 key:SetAttribute("*"..actionType.."-"..name, name)
|
Nenue@17
|
160 elseif actionType == 'macro' then
|
Nenue@17
|
161 macro:SetAttribute("*macro-"..macroName, actionID)
|
Nenue@16
|
162 else
|
Nenue@17
|
163 macro:SetAttribute("*macrotext-"..macroName, macroText)
|
Nenue@16
|
164 end
|
Nenue@50
|
165 local indexKey = actionType..'_'..actionID
|
Nenue@50
|
166 cprint('Loading binding', indexKey)
|
Nenue@50
|
167 bindings[indexKey] = bindings[indexKey] or {}
|
Nenue@50
|
168 bindings[command] = bindings[indexKey]
|
Nenue@50
|
169 return bindings[indexKey], actionID
|
Nenue@16
|
170 end
|
Nenue@16
|
171
|
Nenue@17
|
172 kb.ApplyBindings = function (profile)
|
Nenue@17
|
173 cprint('binding profile', profile)
|
Nenue@17
|
174 for slot, data in pairs(profile.buttons) do
|
Nenue@17
|
175 kb.LoadBinding(unpack(data))
|
Nenue@17
|
176 end
|
Nenue@17
|
177
|
Nenue@17
|
178 for key, command in pairs(profile.bindings) do
|
Nenue@17
|
179
|
Nenue@17
|
180 cprint(' *', key, '->', command)
|
Nenue@17
|
181
|
Nenue@17
|
182 --_G.print('HotKey','loading', key, command)
|
Nenue@17
|
183 SetBinding(key, command)
|
Nenue@17
|
184 if bindings[command] and not tContains(bindings[command], key) then
|
Nenue@17
|
185 tinsert(bindings[command], key)
|
Nenue@17
|
186 end
|
Nenue@17
|
187 end
|
Nenue@17
|
188
|
Nenue@17
|
189 for spellName, talentInfo in pairs(profile.talents) do
|
Nenue@17
|
190 local dummy = GetSpellInfo(spellName)
|
Nenue@17
|
191 local func = kb.CacheTalentBinding
|
Nenue@19
|
192 local dest = kb.TalentBindings
|
Nenue@17
|
193 if dummy then
|
Nenue@17
|
194 cprint('|cFFBBFF00Active:|r', dummy)
|
Nenue@17
|
195 local macroName, spellName, actionType, actionID = unpack(talentInfo)
|
Nenue@50
|
196 local indexKey = actionType .. '_' .. actionID
|
Nenue@50
|
197 bindings[indexKey] = {}
|
Nenue@17
|
198 func = kb.ApplyTalentBinding
|
Nenue@50
|
199 dest = kb.bindings[indexKey]
|
Nenue@17
|
200 else
|
Nenue@17
|
201
|
Nenue@17
|
202 cprint('|cFFFF4400Inactive:|r', talentInfo[2])
|
Nenue@17
|
203 end
|
Nenue@17
|
204 func(talentInfo, dest)
|
Nenue@17
|
205 end
|
Nenue@17
|
206
|
Nenue@17
|
207 end
|
Nenue@17
|
208
|
Nenue@17
|
209 kb.ApplyAllBindings =function ()
|
Nenue@21
|
210 wipe(kb.TalentBindings)
|
Nenue@17
|
211
|
Nenue@17
|
212
|
Nenue@17
|
213 -- reflect action key settings
|
Nenue@17
|
214 if GetCVarBool("ActionButtonUseKeyDown") then
|
Nenue@17
|
215 KeyBinderMacro:RegisterForClicks("AnyDown")
|
Nenue@17
|
216 KeyBinderKey:RegisterForClicks("AnyDown")
|
Nenue@17
|
217 else
|
Nenue@17
|
218 KeyBinderMacro:RegisterForClicks("AnyUp")
|
Nenue@17
|
219 KeyBinderKey:RegisterForClicks("AnyUp")
|
Nenue@17
|
220 end
|
Nenue@17
|
221
|
Nenue@17
|
222 for i, profile in ipairs(kb.orderedProfiles) do
|
Nenue@17
|
223 kb.ApplyBindings(profile)
|
Nenue@17
|
224 end
|
Nenue@17
|
225 -- do this after to ensure that profession binds are properly overridden
|
Nenue@17
|
226 kb.UpdateProfessionInfo()
|
Nenue@17
|
227
|
Nenue@17
|
228
|
Nenue@17
|
229 SaveBindings(GetCurrentBindingSet())
|
Nenue@17
|
230 end
|
Nenue@19
|
231 end
|
Nenue@19
|
232
|
Nenue@19
|
233
|
Nenue@19
|
234 kb.specInfo = {}
|
Nenue@19
|
235 kb.UpdateSpecInfo = function()
|
Nenue@19
|
236 kb.specInfo.id = GetSpecialization()
|
Nenue@19
|
237 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
|
Nenue@19
|
238 end
|
Nenue@19
|
239
|
Nenue@19
|
240 kb.UpdateTalentInfo = function()
|
Nenue@19
|
241 if kb.talentsPushed then
|
Nenue@19
|
242 return
|
Nenue@19
|
243 end
|
Nenue@21
|
244 wipe(kb.TalentCache)
|
Nenue@19
|
245 for row =1, MAX_TALENT_TIERS do
|
Nenue@19
|
246 for col = 1, NUM_TALENT_COLUMNS do
|
Nenue@19
|
247 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
|
Nenue@19
|
248 local talentInfo = kb.TalentCache[spellID] or {}
|
Nenue@19
|
249 talentInfo.row = 1
|
Nenue@19
|
250 talentInfo.col = col
|
Nenue@19
|
251 talentInfo.name = talentName
|
Nenue@19
|
252 talentInfo.talentID = talentID
|
Nenue@19
|
253 talentInfo.selected = selected
|
Nenue@19
|
254 talentInfo.available = available
|
Nenue@19
|
255 talentInfo.spellID = spellID
|
Nenue@19
|
256 kb.TalentCache[spellID] = talentInfo
|
Nenue@19
|
257 kb.TalentCache[talentName] = talentInfo
|
Nenue@19
|
258 print('Talent ', row, col, spellID, talentName)
|
Nenue@19
|
259 end
|
Nenue@19
|
260 end
|
Nenue@19
|
261 kb.talentsPushed = true
|
Nenue@19
|
262
|
Nenue@19
|
263 kb.UpdateDynamicButtons('talent')
|
Nenue@19
|
264 end
|
Nenue@19
|
265
|
Nenue@19
|
266 kb.UpdateProfessionInfo = function()
|
Nenue@21
|
267 wipe(kb.ProfessionCache)
|
Nenue@19
|
268 local profs = {GetProfessions() }
|
Nenue@30
|
269 print(GetProfessions())
|
Nenue@19
|
270 local primaryNum = 0
|
Nenue@30
|
271 for i = 1, 6 do
|
Nenue@30
|
272 if profs[i] then
|
Nenue@30
|
273 local index = profs[i]
|
Nenue@30
|
274 local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(index)
|
Nenue@30
|
275 print(i, index, profName, numSpells, spellOffset)
|
Nenue@30
|
276 if not SECONDARY_PROFESSIONS[index] then
|
Nenue@30
|
277 primaryNum = primaryNum + 1
|
Nenue@30
|
278 end
|
Nenue@30
|
279 local profNum = SECONDARY_PROFESSIONS[index] or primaryNum
|
Nenue@30
|
280 print(i, profNum)
|
Nenue@19
|
281
|
Nenue@19
|
282
|
Nenue@30
|
283 kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {}
|
Nenue@19
|
284
|
Nenue@30
|
285 for j = 1, numSpells do
|
Nenue@30
|
286 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
|
Nenue@19
|
287
|
Nenue@30
|
288 local profInfo = {
|
Nenue@30
|
289 spellName = spellName,
|
Nenue@30
|
290 spellID = spellID,
|
Nenue@30
|
291 icon = icon,
|
Nenue@30
|
292 profOffset = i,
|
Nenue@30
|
293 profIndex = index,
|
Nenue@30
|
294 spellOffset = (spellOffset+j),
|
Nenue@30
|
295 spellNum = j
|
Nenue@30
|
296 }
|
Nenue@26
|
297
|
Nenue@30
|
298 kb.SecureAttribute(KeyBinderKey, "*type-profession_"..i .. '_' ..j, "spell")
|
Nenue@30
|
299 kb.SecureAttribute(KeyBinderKey, "*spell-profession_"..i .. '_' ..j, spellName)
|
Nenue@19
|
300
|
Nenue@30
|
301 kb.ProfessionCache[i .. '_' .. j] = profInfo
|
Nenue@30
|
302 kb.ProfessionCache[spellName] = profInfo
|
Nenue@30
|
303 kb.ProfessionCache[spellID] = profInfo
|
Nenue@30
|
304 print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
|
Nenue@30
|
305 end
|
Nenue@19
|
306 end
|
Nenue@19
|
307
|
Nenue@19
|
308 end
|
Nenue@19
|
309
|
Nenue@19
|
310 kb.UpdateDynamicButtons('profession')
|
Nenue@19
|
311 end
|
Nenue@19
|
312
|
Nenue@19
|
313
|
Nenue@19
|
314
|
Nenue@19
|
315 kb.UpdatePetInfo = function()
|
Nenue@19
|
316 local hasPetSpells, petType = HasPetSpells()
|
Nenue@34
|
317
|
Nenue@56
|
318 -- reconcile saved data if it becomes available
|
Nenue@56
|
319 if kb.db then
|
Nenue@56
|
320 kb.db.petSpellsDB = kb.db.petSpellsDB or {}
|
Nenue@56
|
321 kb.db.petSpellsDB.subtext = kb.db.petSpellsDB.subtext or {}
|
Nenue@56
|
322 kb.db.petSpellsDB.spell = kb.db.petSpellsDB.spell or {}
|
Nenue@56
|
323 local spellCache = kb.db.petSpellsDB.spell
|
Nenue@56
|
324 local subtextCache = kb.db.petSpellsDB.subtext
|
Nenue@56
|
325 if petSpellCache then
|
Nenue@56
|
326 for k,v in pairs(petSpellCache) do
|
Nenue@56
|
327 if not spellCache[k] then
|
Nenue@56
|
328 spellCache[k] = v
|
Nenue@56
|
329 end
|
Nenue@56
|
330 end
|
Nenue@56
|
331 end
|
Nenue@57
|
332 petSpellCache = spellCache
|
Nenue@56
|
333 if petSubtextCache then
|
Nenue@56
|
334 for k,v in pairs(petSubtextCache) do
|
Nenue@56
|
335 if not subtextCache[k] then
|
Nenue@56
|
336 subtextCache[k] = v
|
Nenue@56
|
337 end
|
Nenue@56
|
338 end
|
Nenue@56
|
339 end
|
Nenue@57
|
340 petSubtextCache = subtextCache
|
Nenue@56
|
341 else
|
Nenue@56
|
342 petSpellCache = {}
|
Nenue@56
|
343 petSubtextCache = {}
|
Nenue@56
|
344 end
|
Nenue@54
|
345
|
Nenue@19
|
346 if PetHasSpellbook() then
|
Nenue@19
|
347 print('PET SPELLBOOK')
|
Nenue@19
|
348 local i = 1
|
Nenue@21
|
349 local specialNum = {}
|
Nenue@19
|
350 repeat
|
Nenue@19
|
351
|
Nenue@19
|
352 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
|
Nenue@19
|
353 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
|
Nenue@21
|
354 local texture = GetSpellBookItemTexture(i, BOOKTYPE_PET)
|
Nenue@19
|
355 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
|
Nenue@19
|
356 if not isPassive then
|
Nenue@19
|
357 if spellName then
|
Nenue@21
|
358 kb.PetCache.spellslot[spellName] = {i, spellName, subText, spellID, texture}
|
Nenue@19
|
359 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
|
Nenue@19
|
360
|
Nenue@21
|
361 if subText then
|
Nenue@34
|
362 -- make sure that pet specialization subtext maps correctly
|
Nenue@34
|
363 --if match(subText, kb.PetCache.specName) then
|
Nenue@34
|
364 -- subText = 'specialization'
|
Nenue@34
|
365 --end
|
Nenue@21
|
366 kb.PetCache.subtext[subText] = kb.PetCache.subtext[subText] or {}
|
Nenue@21
|
367 specialNum[subText] = (specialNum[subText] or 0) + 1
|
Nenue@21
|
368
|
Nenue@54
|
369 petSpellCache[spellName] = subText
|
Nenue@54
|
370 petSubtextCache[subText] = petSubtextCache[subText] or {}
|
Nenue@54
|
371
|
Nenue@54
|
372 -- add to the list
|
Nenue@54
|
373 if not petSubtextCache[subText][spellName] then
|
Nenue@54
|
374 petSubtextCache[subText][spellName] = true
|
Nenue@54
|
375
|
Nenue@54
|
376 local macrotext = ""
|
Nenue@54
|
377 for spellName, enabled in pairs(petSubtextCache[subText]) do
|
Nenue@54
|
378 macrotext = macrotext .. "/cast " .. spellName .. "\n"
|
Nenue@54
|
379 end
|
Nenue@54
|
380 kb.SecureAttribute(KeyBinderMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext)
|
Nenue@54
|
381 print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText])
|
Nenue@54
|
382 end
|
Nenue@54
|
383
|
Nenue@54
|
384
|
Nenue@54
|
385
|
Nenue@21
|
386 local entry = {i, spellName, subText, spellID, texture, specialNum[subText]}
|
Nenue@21
|
387
|
Nenue@21
|
388 kb.PetCache.special[spellName] = entry
|
Nenue@21
|
389 kb.PetCache.subtext[subText][specialNum[subText]] = entry
|
Nenue@19
|
390 end
|
Nenue@19
|
391
|
Nenue@19
|
392 if spellID then
|
Nenue@19
|
393 kb.PetCache.spell[i] = {spellID, spellName, subText}
|
Nenue@19
|
394 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
|
Nenue@19
|
395 end
|
Nenue@19
|
396 end
|
Nenue@19
|
397
|
Nenue@19
|
398
|
Nenue@19
|
399 end
|
Nenue@19
|
400
|
Nenue@19
|
401 i = i + 1
|
Nenue@19
|
402 until spellType == nil
|
Nenue@19
|
403 else
|
Nenue@19
|
404 print('NO PET SPELLBOOK')
|
Nenue@21
|
405 wipe(kb.PetCache.spell)
|
Nenue@21
|
406 wipe(kb.PetCache.spellslot)
|
Nenue@19
|
407 end
|
Nenue@19
|
408
|
Nenue@19
|
409 if PetHasActionBar() then
|
Nenue@19
|
410 print('PET ACTION BAR')
|
Nenue@19
|
411 for i = 1, 10 do
|
Nenue@19
|
412
|
Nenue@19
|
413
|
Nenue@19
|
414 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
|
Nenue@19
|
415 if name then
|
Nenue@19
|
416 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
|
Nenue@19
|
417
|
Nenue@19
|
418
|
Nenue@19
|
419 end
|
Nenue@19
|
420 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
|
Nenue@19
|
421 end
|
Nenue@19
|
422 else
|
Nenue@19
|
423 print('NO PET ACTION BAR')
|
Nenue@21
|
424 wipe(kb.PetCache.action)
|
Nenue@19
|
425 end
|
Nenue@19
|
426
|
Nenue@19
|
427 kb.UpdateDynamicButtons('petaction')
|
Nenue@19
|
428
|
Nenue@19
|
429 end
|
Nenue@19
|
430
|
Nenue@19
|
431 kb.UpdateSystemBinds = function()
|
Nenue@21
|
432 wipe(kb.SystemBindings)
|
Nenue@19
|
433 local n = GetNumBindings()
|
Nenue@19
|
434 for i=1, n do
|
Nenue@19
|
435 local command, key1, key2 = GetBinding(i)
|
Nenue@34
|
436 if not command:match('ACTION.*%d+') then
|
Nenue@34
|
437 if key1 then
|
Nenue@34
|
438 kb.SystemBindings[key1] = command
|
Nenue@34
|
439 end
|
Nenue@34
|
440 if key2 then
|
Nenue@34
|
441 kb.SystemBindings[key2] = command
|
Nenue@34
|
442 end
|
Nenue@34
|
443 else
|
Nenue@34
|
444 print('ignoring action button binding', command)
|
Nenue@19
|
445 end
|
Nenue@19
|
446 end
|
Nenue@19
|
447 end
|
Nenue@19
|
448
|
Nenue@19
|
449 kb.UpdateDynamicButtons = function(dynamicType)
|
Nenue@19
|
450 for i, button in ipairs(kb.buttons) do
|
Nenue@19
|
451 if button.isDynamic == dynamicType then
|
Nenue@19
|
452 kb.UpdateSlot(button, true)
|
Nenue@19
|
453 end
|
Nenue@19
|
454 end
|
Nenue@26
|
455 end
|
Nenue@26
|
456
|
Nenue@26
|
457 kb.pendingAttributes = {}
|
Nenue@26
|
458 kb.SecureAttribute = function(target, name, value)
|
Nenue@26
|
459 if InCombatLockdown() then
|
Nenue@34
|
460 if #kb.pendingAttributes == 0 then
|
Nenue@49
|
461 kb:print(kb.L('Key bindings will be applied when you exit combat.'))
|
Nenue@34
|
462 end
|
Nenue@34
|
463
|
Nenue@26
|
464 tinsert(kb.pendingAttributes, {target, name, value})
|
Nenue@26
|
465 kb:RegisterEvent('PLAYER_REGEN_ENABLED')
|
Nenue@34
|
466
|
Nenue@26
|
467 else
|
Nenue@26
|
468
|
Nenue@26
|
469 print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
|
Nenue@26
|
470 target:SetAttribute(name, value)
|
Nenue@26
|
471 end
|
Nenue@26
|
472 end
|
Nenue@26
|
473
|
Nenue@26
|
474 kb.PLAYER_REGEN_ENABLED = function()
|
Nenue@26
|
475 if #kb.pendingAttributes >= 1 then
|
Nenue@26
|
476 local args = tremove(kb.pendingAttributes)
|
Nenue@26
|
477 while args do
|
Nenue@26
|
478 local target, name, value = unpack(args)
|
Nenue@26
|
479 print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
|
Nenue@26
|
480 target:SetAttribute(name, value)
|
Nenue@26
|
481 args = tremove(kb.pendingAttributes)
|
Nenue@26
|
482 end
|
Nenue@26
|
483 end
|
Nenue@27
|
484
|
Nenue@27
|
485 if #kb.pendingCalls >= 1 then
|
Nenue@27
|
486
|
Nenue@27
|
487 local func = tremove(kb.pendingCalls)
|
Nenue@27
|
488 while func do
|
Nenue@27
|
489 func()
|
Nenue@27
|
490 end
|
Nenue@27
|
491 end
|
Nenue@27
|
492 end
|
Nenue@27
|
493
|
Nenue@27
|
494 kb.UpdateBindingsCache = function(actionType, actionID, bindings)
|
Nenue@50
|
495 local indexKey = actionType .. '_' .. actionID
|
Nenue@50
|
496 kb.bindings[indexKey] = bindings
|
Nenue@27
|
497
|
Nenue@50
|
498 print('|cFF00FF00'..indexKey..'|r = {', table.concat(bindings,', '), '}')
|
Nenue@27
|
499 tinsert(kb.ChangedBindings, {actionType, actionID})
|
Nenue@16
|
500 end |