Mercurial > wow > reaction
diff classes/Bar.lua @ 147:901c91dc1bf2
Some refactoring of configmode/keybind handlers
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Thu, 07 May 2009 23:55:00 +0000 |
parents | 86564b5cbbff |
children | de1da46dadb3 |
line wrap: on
line diff
--- a/classes/Bar.lua Thu Apr 30 16:51:43 2009 +0000 +++ b/classes/Bar.lua Thu May 07 23:55:00 2009 +0000 @@ -8,9 +8,12 @@ ReAction:UpdateRevision("$Revision$") +local KB = LibStub("LibKeyBound-1.0") + +---- Bar class ---- local Bar = { } -local proto = { __index = Bar } local weak = { __mode = "k" } +local frameList = { } ReAction.Bar = Bar -- export to ReAction @@ -26,15 +29,21 @@ name = name, buttons = setmetatable( { }, weak ), width = config.width or 480, - height = config.height or 40 + height = config.height or 40, }, - proto ) + {__index = self} ) -- The frame type is 'Button' in order to have an OnClick handler. However, the frame itself is -- not mouse-clickable by the user. local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent - local f = CreateFrame("Button", name and format("ReAction-%s",name), parent, - "SecureHandlerStateTemplate, SecureHandlerClickTemplate") + name = name and "ReAction-"..name + local f = name and frameList[name] + if not f then + f = CreateFrame("Button", name, parent, "SecureHandlerStateTemplate, SecureHandlerClickTemplate") + if name then + frameList[name] = f + end + end f:SetFrameStrata("MEDIUM") f:SetWidth(self.width) f:SetHeight(self.height) @@ -62,7 +71,13 @@ end self:ApplyAnchor() + self:SetConfigMode(ReAction:GetConfigMode()) + self:SetKeybindMode(ReAction:GetKeybindMode()) + ReAction.RegisterCallback(self, "OnConfigModeChanged") + KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") + KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") + KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") return self end @@ -72,21 +87,27 @@ f:UnregisterAllEvents() self:ShowControls(false) ReAction.UnregisterAllCallbacks(self) + KB.UnregisterAllCallbacks(self) ReAction.gridProxy:RemoveFrame(f) - f:Hide() f:SetParent(UIParent) f:ClearAllPoints() + f:Hide() end -function Bar:GetConfig() - return self.config +-- +-- Events +-- + +function Bar:OnConfigModeChanged(event, mode) + self:SetConfigMode(mode) end -function Bar:OnConfigModeChanged(event, mode) - self:ShowControls(mode) -- Bar:ShowControls() defined in Overlay.lua - for b in pairs(self.buttons) do - b:ShowGridTemp(mode) - end +function Bar:LIBKEYBOUND_ENABLED(evt) + self:SetKeybindMode(true) +end + +function Bar:LIBKEYBOUND_DISABLED(evt) + self:SetKeybindMode(false) end function Bar:ApplyAnchor() @@ -246,6 +267,20 @@ return pairs(self.buttons) end +function Bar:SetConfigMode(mode) + self:ShowControls(mode) + for b in self:IterateButtons() do + b:ShowGridTemp(mode) + b:UpdateActionIDLabel(mode) + end +end + +function Bar:SetKeybindMode(mode) + for b in self:IterateButtons() do + b:SetKeybindMode(mode) + end +end + function Bar:PlaceButton(button, baseW, baseH) local idx = self.buttons[button] if idx then @@ -264,4 +299,4 @@ function Bar:SkinButton() -- does nothing by default -end \ No newline at end of file +end