comparison SkeletonKey/SkeletonKey.lua @ 17:500f9b2bd9ac

- for RegisterAction, use a function table instead of that if/then rats nest - consequently pet bar actions work now - unlocalize bindings data - activate keyslot input manually instead of on mouse over - activate checkbox to keep input mode active - dynamic buttons update in real time for petaction/talent/profession spells
author Nenue
date Sat, 30 Jul 2016 00:08:00 -0400
parents cdd387d39137
children 67db6b712bf3
comparison
equal deleted inserted replaced
16:cdd387d39137 17:500f9b2bd9ac
14 -- .SelectProfile(name) set profile character 14 -- .SelectProfile(name) set profile character
15 -- .ApplyBindings(bindings) walk table with SetBinding() 15 -- .ApplyBindings(bindings) walk table with SetBinding()
16 16
17 local _ 17 local _
18 local kb, print = LibStub("LibKraken").register(KeyBinder) 18 local kb, print = LibStub("LibKraken").register(KeyBinder)
19 local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end
20 kb.L = setmetatable({}, { 19 kb.L = setmetatable({}, {
21 __call = function(t, k, ...) return format(t[k] or '', ...) end 20 __call = function(t, k, ...) return format(t[k] or k, ...) end
22 }) 21 })
23 local L = kb.L 22 local L = kb.L
24 23
25 --- Caps Lock literals 24 --- Caps Lock literals
26 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:"
27 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:"
28 local CLASS_ICON_TEXTURE = "Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES" 25 local CLASS_ICON_TEXTURE = "Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES"
29 local FOOTER_OFFSET
30 local HEADER_OFFSET
31 L.BINDING_ASSIGNED = '|cFF00FF00%s|r assigned to |cFFFFFF00%s|r (%s).' 26 L.BINDING_ASSIGNED = '|cFF00FF00%s|r assigned to |cFFFFFF00%s|r (%s).'
32 L.BINDING_REMOVED = '|cFFFFFF00%s|r (|cFF00FFFF%s|r) unbound.' 27 L.BINDING_REMOVED = '|cFFFFFF00%s|r (|cFF00FFFF%s|r) unbound.'
33 L.BINDING_FAILED_PROTECTED = '|cFFFF4400Unable to use |r|cFF00FF00%s|r|cFFFF4400 (currently |cFFFFFF00%s|r|cFFFF4400)|r' 28 L.BINDING_FAILED_PROTECTED = '|cFFFF4400Unable to use |r|cFF00FF00%s|r|cFFFF4400 (currently |cFFFFFF00%s|r|cFFFF4400)|r'
34 29
35 30
36 local BINDING_TYPE_SPECIALIZATION = 3 31 local BINDING_TYPE_SPECIALIZATION = 3
37 local BINDING_TYPE_CHARACTER = 2 32 local BINDING_TYPE_CHARACTER = 2
38 local BINDING_TYPE_GLOBAL = 1 33 local BINDING_TYPE_GLOBAL = 1
39 kb.configTitle = { 34 kb.configTitle = {
40 [BINDING_TYPE_GLOBAL] = 'Global Binds', 35 [BINDING_TYPE_GLOBAL] = L('Global Binds'),
41 [BINDING_TYPE_CHARACTER] = 'Character: %s', 36 [BINDING_TYPE_CHARACTER] = L('Character: %%s'),
42 [BINDING_TYPE_SPECIALIZATION] = 'Specialization: %s' 37 [BINDING_TYPE_SPECIALIZATION] = L('Specialization: %%s')
43 } 38 }
44 kb.configDescription = { 39 kb.configDescription = {
45 [BINDING_TYPE_GLOBAL] = 'The bindings are applied globally.', 40 [BINDING_TYPE_GLOBAL] = L('The bindings are applied globally.'),
46 [BINDING_TYPE_CHARACTER] = 'Applied when you log onto this character.', 41 [BINDING_TYPE_CHARACTER] = L('Applied when you log onto this character.'),
47 [BINDING_TYPE_SPECIALIZATION] = 'Applied when you log onto this character and are that specialization.', 42 [BINDING_TYPE_SPECIALIZATION] = L('Applied when you select this specialization.'),
48 } 43 }
49 44
50 45
51 46
52 kb.inactiveTalentBindings = {} 47 kb.inactiveTalentBindings = {}
53 kb.configHeaders = {} 48 kb.configHeaders = {}
54 kb.loadedProfiles = {} 49 kb.loadedProfiles = {}
55 kb.orderedProfiles = {} 50 kb.orderedProfiles = {}
56 kb.buttons = {} 51 kb.buttons = {}
57 kb.macros = {} 52 kb.macros = {}
53 kb.bindings = {}
58 kb.petFrames = {} -- pet data is slightly delayed, their buttons are indexed here so they can be refreshed 54 kb.petFrames = {} -- pet data is slightly delayed, their buttons are indexed here so they can be refreshed
59 kb.talentFrames = {} 55 kb.talentFrames = {}
60 kb.professionFrames = {} 56 kb.professionFrames = {}
61 57
62 -- these are sent to plugin 58 -- these are sent to plugin
63
64 local bindings = {}
65 local macros = {}
66 local talentBindings = {}
67
68 local protected = {
69 ['OPENCHATSLASH'] = true,
70 ['OPENCHAT'] = true,
71 }
72 59
73 60
74 local db 61 local db
75 local bindHeader, currentHeader = '', '' 62 local bindHeader, currentHeader = '', ''
76 local specID, specGlobalID, specName, specDesc, specTexture, characterHeader = 0, 0, 'SPEC_NAME', 'SPEC_DESCRIPTION', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME' 63 local specID, specGlobalID, specName, specDesc, specTexture, characterHeader = 0, 0, 'SPEC_NAME', 'SPEC_DESCRIPTION', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME'
109 end 96 end
110 end 97 end
111 98
112 end 99 end
113 100
114 print('|cFFFFFF00IsCommandBound:|r', command:gsub(CLICK_KEYBINDER_MACRO, ''),'|r [profile:', db.bindMode .. ']', isAssigned, isBound, assignedBy, boundBy) 101 print('|cFFFFFF00IsCommandBound:|r', command,'|r [profile:', db.bindMode .. ']', isAssigned, isBound, assignedBy, boundBy)
115 return isAssigned, isBound, assignedBy, boundBy 102 return isAssigned, isBound, assignedBy, boundBy
116 end 103 end
117 104
118 local talentSpellHardCodes = { 105 local talentSpellHardCodes = {
119 [109248] = 'Binding Shot', 106 [109248] = 'Binding Shot',
148 end 135 end
149 136
150 137
151 138
152 139
153
154
155 kb.inactiveTalentBindings = {}
156 kb.ApplyTalentBinding = function(talentInfo, cache)
157 for i = 5, #talentInfo do
158 local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
159 SetBinding(talentInfo[i], command)
160 cprint(' **', talentInfo[i], '->', command)
161 tinsert(cache, talentInfo[i])
162 end
163 end
164 kb.CacheTalentBinding = function(talentInfo, cache)
165
166 local spellID = talentInfo[4]
167 kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {}
168 kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) }
169 --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID]))
170 end
171
172 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
173
174 if actionType == 'spell' then
175 KeyBinderKey:SetAttribute("*type-"..name, actionType)
176 KeyBinderKey:SetAttribute("*"..actionType.."-"..name, name)
177
178 elseif actionType == 'item' then
179 KeyBinderKey:SetAttribute("*type-"..name, actionType)
180 KeyBinderKey:SetAttribute("*"..actionType.."-"..name, name)
181 elseif actionType == 'macro' then
182 KeyBinderMacro:SetAttribute("*macro-"..macroName, actionID)
183 else
184 KeyBinderMacro:SetAttribute("*macrotext-"..macroName, macroText)
185 end
186
187 cprint('Loading binding', actionType, actionID)
188 bindings[actionType] = bindings[actionType] or {}
189 bindings[actionType][actionID] = bindings[actionType][actionID] or {}
190 bindings[command] = bindings[actionType][actionID]
191 return bindings[actionType], actionID
192 end
193
194 kb.ApplyBindings = function (profile)
195 cprint('binding profile', profile)
196 for slot, data in pairs(profile.buttons) do
197 kb.LoadBinding(unpack(data))
198 end
199
200 for key, command in pairs(profile.bindings) do
201
202 cprint(' *', key, '->', command)
203
204 --_G.print('HotKey','loading', key, command)
205 SetBinding(key, command)
206 if bindings[command] and not tContains(bindings[command], key) then
207 tinsert(bindings[command], key)
208 end
209 end
210
211 for spellName, talentInfo in pairs(profile.talents) do
212 local dummy = GetSpellInfo(spellName)
213 local func = kb.CacheTalentBinding
214 local dest = kb.inactiveTalentBindings
215 if dummy then
216 cprint('|cFFBBFF00Active:|r', dummy)
217 local macroName, spellName, actionType, actionID = unpack(talentInfo)
218 bindings[actionType] = bindings[actionType] or {}
219 bindings[actionType][actionID] = {}
220 func = kb.ApplyTalentBinding
221 dest = bindings[actionType][actionID]
222 else
223
224 cprint('|cFFFF4400Inactive:|r', talentInfo[2])
225 end
226 func(talentInfo, dest)
227 end
228
229 SaveBindings(GetCurrentBindingSet())
230 end
231
232 kb.ApplyAllBindings =function ()
233 table.wipe(kb.inactiveTalentBindings)
234
235
236 -- reflect action key settings
237 if GetCVarBool("ActionButtonUseKeyDown") then
238 KeyBinderMacro:RegisterForClicks("AnyDown")
239 KeyBinderKey:RegisterForClicks("AnyDown")
240 else
241 KeyBinderMacro:RegisterForClicks("AnyUp")
242 KeyBinderKey:RegisterForClicks("AnyUp")
243 end
244
245 for i, profile in ipairs(kb.orderedProfiles) do
246 kb.ApplyBindings(profile)
247 end
248 -- do this after to ensure that profession binds are properly overridden
249 kb.UpdateProfessionInfo()
250
251
252 end
253 140
254 kb.Command = function(args, editor) 141 kb.Command = function(args, editor)
255 if args:match("import") then 142 if args:match("import") then
256 kb.ImportCommmit(args) 143 kb.ImportCommmit(args)
257 return 144 return
319 --- General info 206 --- General info
320 classHeader, className, classID = UnitClass('player') 207 classHeader, className, classID = UnitClass('player')
321 print('|cFF00FF00profile:|r', name) 208 print('|cFF00FF00profile:|r', name)
322 print('|cFF00FF00class:|r', UnitClass('player')) 209 print('|cFF00FF00class:|r', UnitClass('player'))
323 210
324 --- Global
325 defaultMode = BINDING_TYPE_GLOBAL 211 defaultMode = BINDING_TYPE_GLOBAL
326 kb.InitProfile(db) 212 if db[name] then
213 defaultMode = BINDING_TYPE_CHARACTER
214 if db[name][kb.specInfo.id] then
215 defaultMode = BINDING_TYPE_SPECIALIZATION
216 end
217 end
218
219 db[name] = kb.InitProfile(db[name],
220 {
221 classHeader = classHeader,
222 className = className,
223 classID = classID
224 })
225 db[name][kb.specInfo.id] = kb.InitProfile(db[name][kb.specInfo.id],
226 {
227 specID = kb.specInfo.id,
228 specName = kb.specInfo.name
229 })
230
327 kb.loadedProfiles[BINDING_TYPE_GLOBAL] = db 231 kb.loadedProfiles[BINDING_TYPE_GLOBAL] = db
328 232 kb.loadedProfiles[BINDING_TYPE_CHARACTER] = db[name]
329 --- Character 233 kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] = db[name][kb.specInfo.id]
330 if name then 234 kb.orderedProfiles = {db, db[name], db[name][kb.specInfo.id]}
331 db[name] = kb.InitProfile(db[name], 235
332 {classHeader = classHeader, className = className, classID = classID})
333 kb.loadedProfiles[BINDING_TYPE_CHARACTER] = db[name]
334 defaultMode = BINDING_TYPE_CHARACTER
335 end
336
337 --- Mutable skills data
338 kb.UpdateSpecInfo()
339 kb.UpdateTalentInfo()
340
341 kb.orderedProfiles = {kb.loadedProfiles[BINDING_TYPE_GLOBAL], kb.loadedProfiles[BINDING_TYPE_CHARACTER], kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION]}
342 if (not db.bindMode) or (not kb.configTitle[db.bindMode]) then 236 if (not db.bindMode) or (not kb.configTitle[db.bindMode]) then
343 print('fixing bad bindMode value, was', db.bindMode) 237 print('fixing bad bindMode value, was', db.bindMode)
344 db.bindMode = defaultMode 238 db.bindMode = defaultMode
345 end 239 end
346 240
355 setmetatable(kb.loadedProfiles[BINDING_TYPE_CHARACTER], {__tostring =function() return kb.configHeaders[BINDING_TYPE_CHARACTER] end}) 249 setmetatable(kb.loadedProfiles[BINDING_TYPE_CHARACTER], {__tostring =function() return kb.configHeaders[BINDING_TYPE_CHARACTER] end})
356 setmetatable(kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION], {__tostring =function() return kb.configHeaders[BINDING_TYPE_SPECIALIZATION] end}) 250 setmetatable(kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION], {__tostring =function() return kb.configHeaders[BINDING_TYPE_SPECIALIZATION] end})
357 251
358 print('|cFF00FF00bindMode:|r', db.bindMode) 252 print('|cFF00FF00bindMode:|r', db.bindMode)
359 kb.currentProfile = kb.loadedProfiles[db.bindMode] 253 kb.currentProfile = kb.loadedProfiles[db.bindMode]
254 kb.currentHeader = kb.configHeaders[db.bindMode]
360 end 255 end
361 256
362 local scrollCache = {} 257 local scrollCache = {}
363 kb.SelectTab = function(self) 258 kb.SelectTab = function(self)
364 scrollCache[db.bindMode] = kb.scrollOffset 259 scrollCache[db.bindMode] = kb.scrollOffset
365 db.bindMode = self:GetID() 260 db.bindMode = self:GetID()
366 kb.currentProfile = kb.loadedProfiles[self:GetID()] 261 kb.currentProfile = kb.loadedProfiles[self:GetID()]
262 kb.currentHeader = kb.configHeaders[db.bindMode]
367 kb.scrollOffset = scrollCache[db.bindMode] or 0 263 kb.scrollOffset = scrollCache[db.bindMode] or 0
368 kb.ui(true) 264 kb.ui(true)
369 end 265 end
370 266
371 kb.RevertBindings = function() 267 kb.RevertBindings = function()
380 276
381 277
382 278
383 --- post ADDON_LOADED 279 --- post ADDON_LOADED
384 kb.variables = function() 280 kb.variables = function()
385 SkeletonKeyDB = SkeletonKeyDB or {spec = {}} 281 SkeletonKeyDB = kb.InitProfile(SkeletonKeyDB, {})
386 kb.db = SkeletonKeyDB 282 kb.db = SkeletonKeyDB
387 kb.playerName = UnitName('player') 283 kb.playerName = UnitName('player')
388 kb.playerRealm = SelectedRealmName() 284 kb.playerRealm = SelectedRealmName()
389 kb.profileName = kb.playerRealm .. '_' .. kb.playerName 285 kb.profileName = kb.playerRealm .. '_' .. kb.playerName
390 db = kb.db 286 db = kb.db
391 287
288 kb.UpdateSpecInfo()
289 kb.UpdateTalentInfo()
392 kb.SelectProfileSet(kb.profileName) 290 kb.SelectProfileSet(kb.profileName)
393 -- todo: redo import checking 291 -- todo: redo import checking
394 292
395 kb.UpdateSystemBinds() 293 kb.UpdateSystemBinds()
396 kb.ApplyAllBindings() 294 kb.ApplyAllBindings()
403 kb.modules = kb.modules or {} 301 kb.modules = kb.modules or {}
404 tinsert(kb.modules, module) 302 tinsert(kb.modules, module)
405 end 303 end
406 304
407 -- Volatiles Access 305 -- Volatiles Access
408 kb.GetBindings = function() return bindings end 306 kb.GetBindings = function() return kb.bindings end
409 kb.GetButtons = function() return buttons end 307 kb.GetButtons = function() return kb.buttons end
410 kb.GetCharacterProfile = function () return kb.loadedProfiles[BINDING_TYPE_CHARACTER] end 308 kb.GetCharacterProfile = function () return kb.loadedProfiles[BINDING_TYPE_CHARACTER] end
411 kb.GetGlobalProfile = function () return kb.loadedProfiles[BINDING_TYPE_GLOBAL] end 309 kb.GetGlobalProfile = function () return kb.loadedProfiles[BINDING_TYPE_GLOBAL] end
412 kb.GetLooseTalents = function() return talentBindings end
413 kb.GetReverts = function() return reverts end
414 kb.GetSpecProfile = function () return kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] end 310 kb.GetSpecProfile = function () return kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] end
415 311
416 312
417 SLASH_SKB1 = "/skb" 313 SLASH_SKB1 = "/skb"
418 SLASH_SKB2 = "/skeletonkey" 314 SLASH_SKB2 = "/skeletonkey"