Mercurial > wow > reaction
diff Bar.lua @ 68:fcb5dad031f9
State transitions now working. Keybind toggle states, stance switching, etc.
Hide bar is the only working state property, but the config is there for page #, re-anchoring, re-scaling, and keybind override.
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 03 Jun 2008 22:57:34 +0000 |
parents | 768be7eb22a0 |
children | 2c12e2b1752e |
line wrap: on
line diff
--- a/Bar.lua Wed May 28 17:59:44 2008 +0000 +++ b/Bar.lua Tue Jun 03 22:57:34 2008 +0000 @@ -21,13 +21,14 @@ local function Constructor( self, name, config ) self.name, self.config = name, config + self.buttons = setmetatable({},{__mode="k"}) if type(config) ~= "table" then error("ReAction.Bar: config table required") end local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent - local f = CreateFrame("Frame",nil,parent,"SecureStateDriverTemplate") + local f = CreateFrame("Frame",nil,parent,"SecureStateHeaderTemplate") f:SetFrameStrata("MEDIUM") config.width = config.width or 480 config.height = config.height or 40 @@ -37,9 +38,9 @@ ReAction.RegisterCallback(self, "OnConfigModeChanged") self.frame = f - self:RefreshLayout() self:ApplyAnchor() f:Show() + self:RefreshLayout() end function Bar:Destroy() @@ -165,13 +166,74 @@ f:ClearAllPoints() f:SetPoint("TOPLEFT",x/scale,-y/scale) f:SetScale(scale) + self.buttons[f] = true end +function Bar:GetNumPages() + return self.config.nPages or 1 +end +function Bar:SetHideStates(s) + for f in pairs(self.buttons) do + if f:GetParent() == self.frame then + f:SetAttribute("hidestates",s) + end + end + SecureStateHeader_Refresh(self.frame) +end +function Bar:SetStateKeybind(keybind, state, defaultstate) + -- use a tiny offscreen button to get around making the bar itself a clickable button + local f = self.statebuttonframe + local off = ("%s_off"):format(state) + if keybind then + if not f then + f = CreateFrame("Button",self:GetName().."_statebutton",UIParent,"SecureActionButtonTemplate") + f:SetPoint("BOTTOMRIGHT",UIParent,"TOPLEFT") + f:SetWidth(1) + f:SetHeight(1) + f:SetAttribute("attribute-name", "state") + f:SetAttribute("attribute-frame",self.frame) + f:SetAttribute("stateheader",self.frame) + f:Show() + self.statebuttonframe = f + end + -- map two virtual buttons to toggle between the state and the default + f:SetAttribute(("statebutton-%s"):format(state),("%s:%s;%s"):format(state,off,state)) + f:SetAttribute(("type-%s"):format(state),"attribute") + f:SetAttribute(("type-%s"):format(off),"attribute") + f:SetAttribute(("attribute-value-%s"):format(state), state) + f:SetAttribute(("attribute-value-%s"):format(off), defaultstate) + SetBindingClick(keybind, f:GetName(), state) + elseif f then + f:SetAttribute(("type-%s"):format(state),ATTRIBUTE_NOOP) + f:SetAttribute(("type-%s"):format(off),ATTRIBUTE_NOOP) + end +end +function Bar:SetStatePageMap(state, map) -- map is a { ["statename"] = pagenumber } table + local f = self.frame + local tmp = { } + for s, p in pairs(map) do + table.insert(tmp, ("%s:%d"):format(s,p)) + end + local spec = table.concat(tmp,";") + f:SetAttribute("statebutton",spec) +end - +function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled + local f = self.frame + for i = 1, #states do + local s = states[i] + states[i] = ("%s:%s"):format(s,s) + end + table.insert(states,"_default") + f:SetAttribute("statebindings",table.concat(states,";")) + for b in pairs(self.buttons) do + -- TODO: signal child frames that they should + -- maintain multiple bindings + end +end -- -- Bar config overlay