Mercurial > wow > skeletonkey
diff SkeletonKey/KeyBinds.lua @ 1:cd7d06bcd98d
KeyBinds:
set hotkey text for blizzard action buttons
UnitFrame:
prototype templates for the majority of units
author | Nenue |
---|---|
date | Tue, 21 Jun 2016 04:47:52 -0400 |
parents | 69e828f4238a |
children | 07293831dd7b |
line wrap: on
line diff
--- a/SkeletonKey/KeyBinds.lua Mon Jun 20 06:35:11 2016 -0400 +++ b/SkeletonKey/KeyBinds.lua Tue Jun 21 04:47:52 2016 -0400 @@ -14,9 +14,10 @@ -- .profile(name) set profile character -- .loadbinds(bindings) walk table with SetBinding() +local KT = LibKT.register(KeyBinder) local kb = KeyBinder -local KT = select(2,...) -KT.register(KeyBinder) +local db + local MIN_BIND_SLOTS = 32 local BINDS_PER_ROW = 8 local KEY_BUTTON_SIZE = 40 @@ -25,8 +26,7 @@ local TAB_SPACING = 2 local BUTTON_SPACING = 4 local BUTTON_PADDING = 12 -local HEADER_OFFSET -local FOOTER_OFFSET +local HEADER_OFFSET, FOOTER_OFFSET local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544; local BINDING_TYPE_SPECIALIZATION = 3 local BINDING_TYPE_CHARACTER = 2 @@ -81,19 +81,14 @@ local BORDER_ASSIGNED = {0.5,0.5,0.5,1 } local BORDER_PENDING = {1,0.5,0,1 } - - -local bindMode = 3 -- not to be confused with db.bindMode which is boolean +local bindMode = 3 local bindHeader = '' local specHeader, specTexture, characterHeader = 'SPEC_NAME', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME' +local numButtons = BINDS_PER_ROW * 4 local bindsCommitted = true -local profile -local character -local specialization -local global +local profile, character, specialization, global local priority = {} -local numButtons = BINDS_PER_ROW * 4 local buttons = {} local reverts = {} local KeyButton = {} -- collection of KeyButton template handlers @@ -508,13 +503,13 @@ --- Invokes the KeyBinder frame (from the /kb function or some other source) kb.ui = function() - if not KT.db.bindMode then + if not db.showUI then return end if not kb:IsVisible() then kb:Show() - KT.db.bindMode = true + db.showUI = true end if not kb.loaded then @@ -583,30 +578,50 @@ end local ACTION_BARS = { - 'MultiBarBottomLeftButton', - 'MultiBarBottomRighttButton', - 'MultiBarLeftButton', - 'MultiBarRightButton', - 'ActionButton' + {'ActionButton', 0}, + {'MultiBarLeftButton', 24}, + {'MultiBarRightButton', 36}, + {'MultiBarBottomRighttButton', 48}, + {'MultiBarBottomLeftButton', 60}, } -kb.HotKeyText = function () - for _, prefix in ipairs(ACTION_BARS) do - for i = 1,12 do - local button = _G[prefix .. i] - if button and button.action then - local type, id, subType, subID = GetActionInfo(button.action) - if type == 'spell' then - local name = GetSpellInfo(id) - local bind, bind2 = GetBindingKey('SPELL '..name) - if bind or bind2 then - --print('SPELL '..name, GetBindingKey('SPELL '..name)) - button.HotKey:SetText(BindingString(bind)) - button.HotKey:Show() - end - end - end +kb.HotKeyText = function (slot) + local i, offset = 0, 0 + local actionbar + + -- figure out which bar the slot belongs to + for i, bar in ipairs(ACTION_BARS) do + actionbar, offset = unpack(ACTION_BARS[i]) + if bar[2] > slot then + break end end + local button = _G[actionbar .. (slot - offset)] + + if not button then + return + end + + local type, id, subType, subID = GetActionInfo(slot) + + if not type then + return + end + + local bind, command + if type == 'spell' then + local name = GetSpellInfo(id) + command = 'SPELL '..name + elseif type == 'macro' then + command = 'MACRO ' .. id + else + return + end + bind = GetBindingKey(command) + print(slot, bind, '->', command) + if bind then + button.HotKey:SetText(BindingString(bind)) + button.HotKey:Show() + end end kb.InitProfile = function(profile) @@ -629,23 +644,22 @@ --- Gives us the profile structure to work with while instating data kb.profile = function(name) - KT.db = KT.db or {} - global = kb.InitProfile(KT.db) + global = kb.InitProfile(db) profile = global local subtitle if name then - KT.db[name] = KT.db[name] or {} - KT.db[name] = kb.InitProfile(KT.db[name]) - character = KT.db[name] + db[name] = db[name] or {} + db[name] = kb.InitProfile(db[name]) + character = db[name] local spec = GetSpecialization() if spec then - KT.db[name][spec] = KT.db[name][spec] or {} - profile = kb.InitProfile(KT.db[name][spec]) + db[name][spec] = db[name][spec] or {} + profile = kb.InitProfile(db[name][spec]) bindMode = BINDING_TYPE_SPECIALIZATION subtitle = select(2,GetSpecializationInfo(spec)) - specialization = KT.db[name][spec] + specialization = db[name][spec] else - profile = kb.InitProfile(KT.db[name]) + profile = kb.InitProfile(db[name]) bindMode = BINDING_TYPE_CHARACTER subtitle = name specialization = character @@ -655,15 +669,15 @@ - if not KT.db.bindsPage then - KT.db.bindsPage = bindMode + if not db.bindsPage then + db.bindsPage = bindMode end - bindMode = KT.db.bindsPage + bindMode = db.bindsPage if not BINDING_MODE[bindMode] then bindMode = 3 - KT.db.bindsPage = 3 + db.bindsPage = 3 print('overriding', bindMode) end @@ -682,7 +696,7 @@ kb.SelectTab = function(self) bindMode = self:GetID() profile = priority[self:GetID()] - KT.db.bindsPage = self:GetID() + db.bindsPage = self:GetID() kb.ui() end kb.save = function() @@ -711,6 +725,8 @@ --- Get started kb.variables = function() + SkeletonKeyDB = SkeletonKeyDB or {} + db = SkeletonKeyDB kb.profile(GetUnitName('player', true)) for i = 1, 3 do for attribute, data in pairs(priority[i].macros) do @@ -729,48 +745,46 @@ end kb.close = function() - KT.db.bindMode = false + db.showUI = false kb:Hide() end kb.PLAYER_REGEN_DISABLED = function() - if KT.db.bindMode then - + if db.showUI then kb:Hide() end end kb.PLAYER_REGEN_ENABLED = function() - if KT.db.bindMode then + if db.showUI then kb.ui() end end --- Refresh buttons if macros are updated kb.UPDATE_BINDINGS = function() - if KT.db.bindMode then + for i = 1, 120 do + print(i) + kb.HotKeyText(i) + end + if db.showUI then kb.ui() end - kb.HotKeyText() end -kb.ACTIONBAR_SLOT_CHANGED = function() - kb.HotKeyText() +kb.ACTIONBAR_SLOT_CHANGED = function(self, event, slot) + kb.HotKeyText(slot) end - - kb.UPDATE_MACROS = kb.UPDATE_BINDINGS - - SLASH_KB1 = "/kb" -SlashCmdList.KB = function() - if KT.db.bindMode then - KT.db.bindMode = false +SlashCmdList.KB = function(self, input) + if db.showUI then + db.showUI = false print('|cFFFFFF00KeyBinds|r trace, |cFFFF0000OFF|r.') kb:Hide() else - KT.db.bindMode = true + db.showUI = true print('|cFFFFFF00KeyBinds|r trace, |cFF00FF00ON|r.') kb.ui() end -end \ No newline at end of file +end