Mercurial > wow > reaction
comparison 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 |
comparison
equal
deleted
inserted
replaced
146:86564b5cbbff | 147:901c91dc1bf2 |
---|---|
6 local fmod = math.fmod | 6 local fmod = math.fmod |
7 local format = string.format | 7 local format = string.format |
8 | 8 |
9 ReAction:UpdateRevision("$Revision$") | 9 ReAction:UpdateRevision("$Revision$") |
10 | 10 |
11 local KB = LibStub("LibKeyBound-1.0") | |
12 | |
13 ---- Bar class ---- | |
11 local Bar = { } | 14 local Bar = { } |
12 local proto = { __index = Bar } | |
13 local weak = { __mode = "k" } | 15 local weak = { __mode = "k" } |
16 local frameList = { } | |
14 | 17 |
15 ReAction.Bar = Bar -- export to ReAction | 18 ReAction.Bar = Bar -- export to ReAction |
16 | 19 |
17 function Bar:New( name, config ) | 20 function Bar:New( name, config ) |
18 if type(config) ~= "table" then | 21 if type(config) ~= "table" then |
24 { | 27 { |
25 config = config, | 28 config = config, |
26 name = name, | 29 name = name, |
27 buttons = setmetatable( { }, weak ), | 30 buttons = setmetatable( { }, weak ), |
28 width = config.width or 480, | 31 width = config.width or 480, |
29 height = config.height or 40 | 32 height = config.height or 40, |
30 }, | 33 }, |
31 proto ) | 34 {__index = self} ) |
32 | 35 |
33 -- The frame type is 'Button' in order to have an OnClick handler. However, the frame itself is | 36 -- The frame type is 'Button' in order to have an OnClick handler. However, the frame itself is |
34 -- not mouse-clickable by the user. | 37 -- not mouse-clickable by the user. |
35 local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent | 38 local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent |
36 local f = CreateFrame("Button", name and format("ReAction-%s",name), parent, | 39 name = name and "ReAction-"..name |
37 "SecureHandlerStateTemplate, SecureHandlerClickTemplate") | 40 local f = name and frameList[name] |
41 if not f then | |
42 f = CreateFrame("Button", name, parent, "SecureHandlerStateTemplate, SecureHandlerClickTemplate") | |
43 if name then | |
44 frameList[name] = f | |
45 end | |
46 end | |
38 f:SetFrameStrata("MEDIUM") | 47 f:SetFrameStrata("MEDIUM") |
39 f:SetWidth(self.width) | 48 f:SetWidth(self.width) |
40 f:SetHeight(self.height) | 49 f:SetHeight(self.height) |
41 f:SetAlpha(config.alpha or 1.0) | 50 f:SetAlpha(config.alpha or 1.0) |
42 f:Show() | 51 f:Show() |
60 function self:GetFrame() | 69 function self:GetFrame() |
61 return f | 70 return f |
62 end | 71 end |
63 | 72 |
64 self:ApplyAnchor() | 73 self:ApplyAnchor() |
74 self:SetConfigMode(ReAction:GetConfigMode()) | |
75 self:SetKeybindMode(ReAction:GetKeybindMode()) | |
76 | |
65 ReAction.RegisterCallback(self, "OnConfigModeChanged") | 77 ReAction.RegisterCallback(self, "OnConfigModeChanged") |
78 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") | |
79 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") | |
80 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") | |
66 | 81 |
67 return self | 82 return self |
68 end | 83 end |
69 | 84 |
70 function Bar:Destroy() | 85 function Bar:Destroy() |
71 local f = self:GetFrame() | 86 local f = self:GetFrame() |
72 f:UnregisterAllEvents() | 87 f:UnregisterAllEvents() |
73 self:ShowControls(false) | 88 self:ShowControls(false) |
74 ReAction.UnregisterAllCallbacks(self) | 89 ReAction.UnregisterAllCallbacks(self) |
90 KB.UnregisterAllCallbacks(self) | |
75 ReAction.gridProxy:RemoveFrame(f) | 91 ReAction.gridProxy:RemoveFrame(f) |
76 f:Hide() | |
77 f:SetParent(UIParent) | 92 f:SetParent(UIParent) |
78 f:ClearAllPoints() | 93 f:ClearAllPoints() |
79 end | 94 f:Hide() |
80 | 95 end |
81 function Bar:GetConfig() | 96 |
82 return self.config | 97 -- |
83 end | 98 -- Events |
99 -- | |
84 | 100 |
85 function Bar:OnConfigModeChanged(event, mode) | 101 function Bar:OnConfigModeChanged(event, mode) |
86 self:ShowControls(mode) -- Bar:ShowControls() defined in Overlay.lua | 102 self:SetConfigMode(mode) |
87 for b in pairs(self.buttons) do | 103 end |
88 b:ShowGridTemp(mode) | 104 |
89 end | 105 function Bar:LIBKEYBOUND_ENABLED(evt) |
106 self:SetKeybindMode(true) | |
107 end | |
108 | |
109 function Bar:LIBKEYBOUND_DISABLED(evt) | |
110 self:SetKeybindMode(false) | |
90 end | 111 end |
91 | 112 |
92 function Bar:ApplyAnchor() | 113 function Bar:ApplyAnchor() |
93 local f = self:GetFrame() | 114 local f = self:GetFrame() |
94 local c = self.config | 115 local c = self.config |
244 -- iterator returns button, idx and does NOT iterate in index order | 265 -- iterator returns button, idx and does NOT iterate in index order |
245 function Bar:IterateButtons() | 266 function Bar:IterateButtons() |
246 return pairs(self.buttons) | 267 return pairs(self.buttons) |
247 end | 268 end |
248 | 269 |
270 function Bar:SetConfigMode(mode) | |
271 self:ShowControls(mode) | |
272 for b in self:IterateButtons() do | |
273 b:ShowGridTemp(mode) | |
274 b:UpdateActionIDLabel(mode) | |
275 end | |
276 end | |
277 | |
278 function Bar:SetKeybindMode(mode) | |
279 for b in self:IterateButtons() do | |
280 b:SetKeybindMode(mode) | |
281 end | |
282 end | |
283 | |
249 function Bar:PlaceButton(button, baseW, baseH) | 284 function Bar:PlaceButton(button, baseW, baseH) |
250 local idx = self.buttons[button] | 285 local idx = self.buttons[button] |
251 if idx then | 286 if idx then |
252 local r, c, s = self:GetButtonGrid() | 287 local r, c, s = self:GetButtonGrid() |
253 local bh, bw = self:GetButtonSize() | 288 local bh, bw = self:GetButtonSize() |