Mercurial > wow > reaction
diff modules/ReAction_PetAction/ReAction_PetAction.lua @ 93:567a885cdfad
- pet hotkey support
- fixed showgrid when in keybind mode for action buttons
- fixed a typo (bad 'self') in overlay.lua
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 17 Oct 2008 23:13:44 +0000 |
parents | c2504a8b996c |
children | 39265b16d208 |
line wrap: on
line diff
--- a/modules/ReAction_PetAction/ReAction_PetAction.lua Fri Oct 17 22:43:57 2008 +0000 +++ b/modules/ReAction_PetAction/ReAction_PetAction.lua Fri Oct 17 23:13:44 2008 +0000 @@ -14,6 +14,9 @@ ReAction:UpdateRevision("$Revision$") +-- libraries +local KB = LibStub("LibKeyBound-1.0") + -- module declaration local moduleID = "PetAction" local module = ReAction:NewModule( moduleID ) @@ -40,6 +43,10 @@ ReAction.RegisterCallback(self, "OnEraseBar") ReAction.RegisterCallback(self, "OnRenameBar") ReAction.RegisterCallback(self, "OnConfigModeChanged") + + KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") + KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") + KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") end function module:OnEnable() @@ -146,6 +153,22 @@ end end +function module:LIBKEYBOUND_ENABLED(evt) + for _, buttons in pairs(self.buttons) do + for _, b in pairs(buttons) do + b:SetKeybindMode(true) + end + end +end + +function module:LIBKEYBOUND_DISABLED(evt) + for _, buttons in pairs(self.buttons) do + for _, b in pairs(buttons) do + b:SetKeybindMode(false) + end + end +end + ---- Options ---- function module:GetBarOptions(bar) @@ -195,6 +218,88 @@ }) local frameRecycler = {} +local trash = CreateFrame("Frame") +local KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings +do + local buttonLookup = setmetatable({},{__mode="kv"}) + + -- Use KeyBound-1.0 for binding, but use Override bindings instead of + -- regular bindings to support multiple profile use. This is a little + -- weird with the KeyBound dialog box (which has per-char selector as well + -- as an OK/Cancel box) but it's the least amount of effort to implement. + function GetActionName(f) + local b = buttonLookup[f] + if b then + return format("%s:%s", b.bar:GetName(), b.idx) + end + end + + function GetHotkey(f) + local b = buttonLookup[f] + if b then + return KB:ToShortKey(b:GetConfig().hotkey) + end + end + + function SetKey(f, key) + local b = buttonLookup[f] + if b then + local c = b:GetConfig() + if c.hotkey then + SetOverrideBinding(f, false, c.hotkey, nil) + end + if key then + SetOverrideBindingClick(f, false, key, f:GetName(), nil) + end + c.hotkey = key + b:DisplayHotkey(GetHotkey(f)) + end + end + + function FreeKey(f, key) + local b = buttonLookup[f] + if b then + local c = b:GetConfig() + if c.hotkey == key then + local action = f:GetActionName() + SetOverrideBinding(f, false, c.hotkey, nil) + c.hotkey = nil + b:DisplayHotkey(nil) + return action + end + end + return ReAction:FreeOverrideHotkey(key) + end + + function ClearBindings(f) + SetKey(f, nil) + end + + function GetBindings(f) + local b = buttonLookup[f] + if b then + return b:GetConfig().hotkey + end + end + + function KBAttach( button ) + local f = button:GetFrame() + f.GetActionName = GetActionName + f.GetHotkey = GetHotkey + f.SetKey = SetKey + f.FreeKey = FreeKey + f.ClearBindings = ClearBindings + f.GetBindings = GetBindings + buttonLookup[f] = button + f:SetKey(button:GetConfig().hotkey) + ReAction:RegisterKeybindFrame(f) + if ReAction:GetKeybindMode() then + button.border:SetVertexColor(KB:GetColorKeyBoundMode()) + button.border:Show() + end + end +end + local meta = { __index = Button } function Button:New( bar, idx, config ) @@ -221,20 +326,32 @@ f:SetParent(parent) else f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate") + -- ditch the old hotkey text because it's tied in ActionButton_Update() to the + -- standard binding. We use override bindings. + local hotkey = _G[name.."HotKey"] + hotkey:SetParent(trash) + hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray") + hotkey:SetWidth(36) + hotkey:SetHeight(18) + hotkey:SetJustifyH("RIGHT") + hotkey:SetJustifyV("TOP") + hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2) + f.hotkey = hotkey + f:HookScript("OnDragStart", function() self:Update() end) + f:HookScript("OnReceiveDrag", function() self:Update() end) end if config.actionID then f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton end f:SetFrameStrata("MEDIUM") - self.frame = f - self.icon = _G[("%sIcon"):format(name)] - self.acTex = _G[("%sAutoCastable"):format(name)] - self.acModel = _G[("%sShine"):format(name)] + self.frame = f + self.icon = _G[("%sIcon"):format(name)] + self.acTex = _G[("%sAutoCastable"):format(name)] + self.acModel = _G[("%sShine"):format(name)] self.cooldown = _G[("%sCooldown"):format(name)] - self.hotkey = _G[("%sHotKey"):format(name)] + self.hotkey = f.hotkey + self.border = _G[("%sBorder"):format(name)] - f:HookScript("OnDragStart", function() self:Update() end) - f:HookScript("OnReceiveDrag", function() self:Update() end) f:RegisterEvent("PLAYER_CONTROL_LOST"); f:RegisterEvent("PLAYER_CONTROL_GAINED"); @@ -256,9 +373,11 @@ end end) - --self.binder = ReAction:AttachBinder(self) + KBAttach(self) self:Refresh() + self:SetKeybindMode(ReAction:GetKeybindMode()) + return self end @@ -354,7 +473,7 @@ end function Button:UpdateHotkey() - + self:DisplayHotkey(GetHotkey(self.frame)) end function Button:ShowActionIDLabel(show) @@ -374,3 +493,17 @@ self.actionIDLabel:Hide() end end + + +function Button:SetKeybindMode(mode) + if mode then + self.border:SetVertexColor(KB:GetColorKeyBoundMode()) + self.border:Show() + else + self.border:Hide() + end +end + +function Button:DisplayHotkey( key ) + self.hotkey:SetText(key or "") +end