Mercurial > wow > reaction
comparison 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 |
comparison
equal
deleted
inserted
replaced
67:84721edaa749 | 68:fcb5dad031f9 |
---|---|
19 ------ BAR CLASS ------ | 19 ------ BAR CLASS ------ |
20 local Bar = { _classID = {} } | 20 local Bar = { _classID = {} } |
21 | 21 |
22 local function Constructor( self, name, config ) | 22 local function Constructor( self, name, config ) |
23 self.name, self.config = name, config | 23 self.name, self.config = name, config |
24 self.buttons = setmetatable({},{__mode="k"}) | |
24 | 25 |
25 if type(config) ~= "table" then | 26 if type(config) ~= "table" then |
26 error("ReAction.Bar: config table required") | 27 error("ReAction.Bar: config table required") |
27 end | 28 end |
28 | 29 |
29 local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent | 30 local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent |
30 local f = CreateFrame("Frame",nil,parent,"SecureStateDriverTemplate") | 31 local f = CreateFrame("Frame",nil,parent,"SecureStateHeaderTemplate") |
31 f:SetFrameStrata("MEDIUM") | 32 f:SetFrameStrata("MEDIUM") |
32 config.width = config.width or 480 | 33 config.width = config.width or 480 |
33 config.height = config.height or 40 | 34 config.height = config.height or 40 |
34 f:SetWidth(config.width) | 35 f:SetWidth(config.width) |
35 f:SetWidth(config.height) | 36 f:SetWidth(config.height) |
36 | 37 |
37 ReAction.RegisterCallback(self, "OnConfigModeChanged") | 38 ReAction.RegisterCallback(self, "OnConfigModeChanged") |
38 | 39 |
39 self.frame = f | 40 self.frame = f |
40 self:RefreshLayout() | |
41 self:ApplyAnchor() | 41 self:ApplyAnchor() |
42 f:Show() | 42 f:Show() |
43 self:RefreshLayout() | |
43 end | 44 end |
44 | 45 |
45 function Bar:Destroy() | 46 function Bar:Destroy() |
46 local f = self.frame | 47 local f = self.frame |
47 f:UnregisterAllEvents() | 48 f:UnregisterAllEvents() |
163 local scale = bw/baseW | 164 local scale = bw/baseW |
164 | 165 |
165 f:ClearAllPoints() | 166 f:ClearAllPoints() |
166 f:SetPoint("TOPLEFT",x/scale,-y/scale) | 167 f:SetPoint("TOPLEFT",x/scale,-y/scale) |
167 f:SetScale(scale) | 168 f:SetScale(scale) |
168 end | 169 self.buttons[f] = true |
169 | 170 end |
170 | 171 |
171 | 172 function Bar:GetNumPages() |
172 | 173 return self.config.nPages or 1 |
173 | 174 end |
174 | 175 |
176 function Bar:SetHideStates(s) | |
177 for f in pairs(self.buttons) do | |
178 if f:GetParent() == self.frame then | |
179 f:SetAttribute("hidestates",s) | |
180 end | |
181 end | |
182 SecureStateHeader_Refresh(self.frame) | |
183 end | |
184 | |
185 function Bar:SetStateKeybind(keybind, state, defaultstate) | |
186 -- use a tiny offscreen button to get around making the bar itself a clickable button | |
187 local f = self.statebuttonframe | |
188 local off = ("%s_off"):format(state) | |
189 if keybind then | |
190 if not f then | |
191 f = CreateFrame("Button",self:GetName().."_statebutton",UIParent,"SecureActionButtonTemplate") | |
192 f:SetPoint("BOTTOMRIGHT",UIParent,"TOPLEFT") | |
193 f:SetWidth(1) | |
194 f:SetHeight(1) | |
195 f:SetAttribute("attribute-name", "state") | |
196 f:SetAttribute("attribute-frame",self.frame) | |
197 f:SetAttribute("stateheader",self.frame) | |
198 f:Show() | |
199 self.statebuttonframe = f | |
200 end | |
201 -- map two virtual buttons to toggle between the state and the default | |
202 f:SetAttribute(("statebutton-%s"):format(state),("%s:%s;%s"):format(state,off,state)) | |
203 f:SetAttribute(("type-%s"):format(state),"attribute") | |
204 f:SetAttribute(("type-%s"):format(off),"attribute") | |
205 f:SetAttribute(("attribute-value-%s"):format(state), state) | |
206 f:SetAttribute(("attribute-value-%s"):format(off), defaultstate) | |
207 SetBindingClick(keybind, f:GetName(), state) | |
208 elseif f then | |
209 f:SetAttribute(("type-%s"):format(state),ATTRIBUTE_NOOP) | |
210 f:SetAttribute(("type-%s"):format(off),ATTRIBUTE_NOOP) | |
211 end | |
212 end | |
213 | |
214 function Bar:SetStatePageMap(state, map) -- map is a { ["statename"] = pagenumber } table | |
215 local f = self.frame | |
216 local tmp = { } | |
217 for s, p in pairs(map) do | |
218 table.insert(tmp, ("%s:%d"):format(s,p)) | |
219 end | |
220 local spec = table.concat(tmp,";") | |
221 f:SetAttribute("statebutton",spec) | |
222 end | |
223 | |
224 function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled | |
225 local f = self.frame | |
226 for i = 1, #states do | |
227 local s = states[i] | |
228 states[i] = ("%s:%s"):format(s,s) | |
229 end | |
230 table.insert(states,"_default") | |
231 f:SetAttribute("statebindings",table.concat(states,";")) | |
232 for b in pairs(self.buttons) do | |
233 -- TODO: signal child frames that they should | |
234 -- maintain multiple bindings | |
235 end | |
236 end | |
175 | 237 |
176 -- | 238 -- |
177 -- Bar config overlay | 239 -- Bar config overlay |
178 -- | 240 -- |
179 local CreateControls | 241 local CreateControls |