Mercurial > wow > skeletonkey
diff 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 |
line wrap: on
line diff
--- a/SkeletonKey/SkeletonKey.lua Fri Jul 29 21:18:15 2016 -0400 +++ b/SkeletonKey/SkeletonKey.lua Sat Jul 30 00:08:00 2016 -0400 @@ -16,18 +16,13 @@ local _ local kb, print = LibStub("LibKraken").register(KeyBinder) -local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end kb.L = setmetatable({}, { - __call = function(t, k, ...) return format(t[k] or '', ...) end + __call = function(t, k, ...) return format(t[k] or k, ...) end }) local L = kb.L --- Caps Lock literals -local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:" -local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:" local CLASS_ICON_TEXTURE = "Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES" -local FOOTER_OFFSET -local HEADER_OFFSET L.BINDING_ASSIGNED = '|cFF00FF00%s|r assigned to |cFFFFFF00%s|r (%s).' L.BINDING_REMOVED = '|cFFFFFF00%s|r (|cFF00FFFF%s|r) unbound.' L.BINDING_FAILED_PROTECTED = '|cFFFF4400Unable to use |r|cFF00FF00%s|r|cFFFF4400 (currently |cFFFFFF00%s|r|cFFFF4400)|r' @@ -37,14 +32,14 @@ local BINDING_TYPE_CHARACTER = 2 local BINDING_TYPE_GLOBAL = 1 kb.configTitle = { - [BINDING_TYPE_GLOBAL] = 'Global Binds', - [BINDING_TYPE_CHARACTER] = 'Character: %s', - [BINDING_TYPE_SPECIALIZATION] = 'Specialization: %s' + [BINDING_TYPE_GLOBAL] = L('Global Binds'), + [BINDING_TYPE_CHARACTER] = L('Character: %%s'), + [BINDING_TYPE_SPECIALIZATION] = L('Specialization: %%s') } kb.configDescription = { - [BINDING_TYPE_GLOBAL] = 'The bindings are applied globally.', - [BINDING_TYPE_CHARACTER] = 'Applied when you log onto this character.', - [BINDING_TYPE_SPECIALIZATION] = 'Applied when you log onto this character and are that specialization.', + [BINDING_TYPE_GLOBAL] = L('The bindings are applied globally.'), + [BINDING_TYPE_CHARACTER] = L('Applied when you log onto this character.'), + [BINDING_TYPE_SPECIALIZATION] = L('Applied when you select this specialization.'), } @@ -55,21 +50,13 @@ kb.orderedProfiles = {} kb.buttons = {} kb.macros = {} +kb.bindings = {} kb.petFrames = {} -- pet data is slightly delayed, their buttons are indexed here so they can be refreshed kb.talentFrames = {} kb.professionFrames = {} -- these are sent to plugin -local bindings = {} -local macros = {} -local talentBindings = {} - -local protected = { - ['OPENCHATSLASH'] = true, - ['OPENCHAT'] = true, -} - local db local bindHeader, currentHeader = '', '' @@ -111,7 +98,7 @@ end - print('|cFFFFFF00IsCommandBound:|r', command:gsub(CLICK_KEYBINDER_MACRO, ''),'|r [profile:', db.bindMode .. ']', isAssigned, isBound, assignedBy, boundBy) + print('|cFFFFFF00IsCommandBound:|r', command,'|r [profile:', db.bindMode .. ']', isAssigned, isBound, assignedBy, boundBy) return isAssigned, isBound, assignedBy, boundBy end @@ -151,106 +138,6 @@ - -kb.inactiveTalentBindings = {} -kb.ApplyTalentBinding = function(talentInfo, cache) - for i = 5, #talentInfo do - local command = CLICK_KEYBINDER_KEY.. talentInfo[2] - SetBinding(talentInfo[i], command) - cprint(' **', talentInfo[i], '->', command) - tinsert(cache, talentInfo[i]) - end -end -kb.CacheTalentBinding = function(talentInfo, cache) - - local spellID = talentInfo[4] - kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {} - kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) } - --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID])) -end - -kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText ) - - if actionType == 'spell' then - KeyBinderKey:SetAttribute("*type-"..name, actionType) - KeyBinderKey:SetAttribute("*"..actionType.."-"..name, name) - - elseif actionType == 'item' then - KeyBinderKey:SetAttribute("*type-"..name, actionType) - KeyBinderKey:SetAttribute("*"..actionType.."-"..name, name) - elseif actionType == 'macro' then - KeyBinderMacro:SetAttribute("*macro-"..macroName, actionID) - else - KeyBinderMacro:SetAttribute("*macrotext-"..macroName, macroText) - end - - cprint('Loading binding', actionType, actionID) - bindings[actionType] = bindings[actionType] or {} - bindings[actionType][actionID] = bindings[actionType][actionID] or {} - bindings[command] = bindings[actionType][actionID] - return bindings[actionType], actionID -end - -kb.ApplyBindings = function (profile) - cprint('binding profile', profile) - for slot, data in pairs(profile.buttons) do - kb.LoadBinding(unpack(data)) - end - - for key, command in pairs(profile.bindings) do - - cprint(' *', key, '->', command) - - --_G.print('HotKey','loading', key, command) - SetBinding(key, command) - if bindings[command] and not tContains(bindings[command], key) then - tinsert(bindings[command], key) - end - end - - for spellName, talentInfo in pairs(profile.talents) do - local dummy = GetSpellInfo(spellName) - local func = kb.CacheTalentBinding - local dest = kb.inactiveTalentBindings - if dummy then - cprint('|cFFBBFF00Active:|r', dummy) - local macroName, spellName, actionType, actionID = unpack(talentInfo) - bindings[actionType] = bindings[actionType] or {} - bindings[actionType][actionID] = {} - func = kb.ApplyTalentBinding - dest = bindings[actionType][actionID] - else - - cprint('|cFFFF4400Inactive:|r', talentInfo[2]) - end - func(talentInfo, dest) - end - - SaveBindings(GetCurrentBindingSet()) -end - -kb.ApplyAllBindings =function () - table.wipe(kb.inactiveTalentBindings) - - - -- reflect action key settings - if GetCVarBool("ActionButtonUseKeyDown") then - KeyBinderMacro:RegisterForClicks("AnyDown") - KeyBinderKey:RegisterForClicks("AnyDown") - else - KeyBinderMacro:RegisterForClicks("AnyUp") - KeyBinderKey:RegisterForClicks("AnyUp") - end - - for i, profile in ipairs(kb.orderedProfiles) do - kb.ApplyBindings(profile) - end - -- do this after to ensure that profession binds are properly overridden - kb.UpdateProfessionInfo() - - -end - kb.Command = function(args, editor) if args:match("import") then kb.ImportCommmit(args) @@ -321,24 +208,31 @@ print('|cFF00FF00profile:|r', name) print('|cFF00FF00class:|r', UnitClass('player')) - --- Global defaultMode = BINDING_TYPE_GLOBAL - kb.InitProfile(db) - kb.loadedProfiles[BINDING_TYPE_GLOBAL] = db - - --- Character - if name then - db[name] = kb.InitProfile(db[name], - {classHeader = classHeader, className = className, classID = classID}) - kb.loadedProfiles[BINDING_TYPE_CHARACTER] = db[name] + if db[name] then defaultMode = BINDING_TYPE_CHARACTER + if db[name][kb.specInfo.id] then + defaultMode = BINDING_TYPE_SPECIALIZATION + end end - --- Mutable skills data - kb.UpdateSpecInfo() - kb.UpdateTalentInfo() + db[name] = kb.InitProfile(db[name], + { + classHeader = classHeader, + className = className, + classID = classID + }) + db[name][kb.specInfo.id] = kb.InitProfile(db[name][kb.specInfo.id], + { + specID = kb.specInfo.id, + specName = kb.specInfo.name + }) - kb.orderedProfiles = {kb.loadedProfiles[BINDING_TYPE_GLOBAL], kb.loadedProfiles[BINDING_TYPE_CHARACTER], kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION]} + kb.loadedProfiles[BINDING_TYPE_GLOBAL] = db + kb.loadedProfiles[BINDING_TYPE_CHARACTER] = db[name] + kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] = db[name][kb.specInfo.id] + kb.orderedProfiles = {db, db[name], db[name][kb.specInfo.id]} + if (not db.bindMode) or (not kb.configTitle[db.bindMode]) then print('fixing bad bindMode value, was', db.bindMode) db.bindMode = defaultMode @@ -357,6 +251,7 @@ print('|cFF00FF00bindMode:|r', db.bindMode) kb.currentProfile = kb.loadedProfiles[db.bindMode] + kb.currentHeader = kb.configHeaders[db.bindMode] end local scrollCache = {} @@ -364,6 +259,7 @@ scrollCache[db.bindMode] = kb.scrollOffset db.bindMode = self:GetID() kb.currentProfile = kb.loadedProfiles[self:GetID()] + kb.currentHeader = kb.configHeaders[db.bindMode] kb.scrollOffset = scrollCache[db.bindMode] or 0 kb.ui(true) end @@ -382,13 +278,15 @@ --- post ADDON_LOADED kb.variables = function() - SkeletonKeyDB = SkeletonKeyDB or {spec = {}} + SkeletonKeyDB = kb.InitProfile(SkeletonKeyDB, {}) kb.db = SkeletonKeyDB kb.playerName = UnitName('player') kb.playerRealm = SelectedRealmName() kb.profileName = kb.playerRealm .. '_' .. kb.playerName db = kb.db + kb.UpdateSpecInfo() + kb.UpdateTalentInfo() kb.SelectProfileSet(kb.profileName) -- todo: redo import checking @@ -405,12 +303,10 @@ end -- Volatiles Access -kb.GetBindings = function() return bindings end -kb.GetButtons = function() return buttons end +kb.GetBindings = function() return kb.bindings end +kb.GetButtons = function() return kb.buttons end kb.GetCharacterProfile = function () return kb.loadedProfiles[BINDING_TYPE_CHARACTER] end kb.GetGlobalProfile = function () return kb.loadedProfiles[BINDING_TYPE_GLOBAL] end -kb.GetLooseTalents = function() return talentBindings end -kb.GetReverts = function() return reverts end kb.GetSpecProfile = function () return kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] end