Mercurial > wow > reaction
comparison modules/ReAction_PossessBar/ReAction_PossessBar.lua @ 63:768be7eb22a0
Converted several ReAction APIs to event-driven model instead of 'call-method-on-all-modules' model. Cleaned up a number of other architectural issues.
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Thu, 22 May 2008 22:02:08 +0000 |
parents | 44649a10378d |
children |
comparison
equal
deleted
inserted
replaced
62:f9cdb920470a | 63:768be7eb22a0 |
---|---|
24 buttons = { } | 24 buttons = { } |
25 } | 25 } |
26 } | 26 } |
27 ) | 27 ) |
28 self.buttons = { } | 28 self.buttons = { } |
29 self.options = setmetatable({},{__mode="k"}) | |
30 | 29 |
31 ReAction:RegisterOptions(self, { | 30 ReAction:RegisterOptions(self, { |
32 [moduleID] = { | 31 [moduleID] = { |
33 type = "group", | 32 type = "group", |
34 name = L["Possess Bar"], | 33 name = L["Possess Bar"], |
40 set = function(info, val) module:SetHideEmptyButtons(val) end, | 39 set = function(info, val) module:SetHideEmptyButtons(val) end, |
41 } | 40 } |
42 } | 41 } |
43 } | 42 } |
44 }) | 43 }) |
44 | |
45 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") | |
46 | |
47 ReAction.RegisterCallback(self, "OnCreateBar") | |
48 ReAction.RegisterCallback(self, "OnDestroyBar") | |
49 ReAction.RegisterCallback(self, "OnRefreshBar") | |
50 ReAction.RegisterCallback(self, "OnEraseBar") | |
51 ReAction.RegisterCallback(self, "OnRenameBar") | |
52 ReAction.RegisterCallback(self, "OnConfigModeChanged") | |
45 end | 53 end |
46 | 54 |
47 function module:OnEnable() | 55 function module:OnEnable() |
48 ReAction:RegisterBarType(L["Possess Bar"], | 56 ReAction:RegisterBarType(L["Possess Bar"], |
49 { | 57 { |
57 | 65 |
58 function module:OnDisable() | 66 function module:OnDisable() |
59 ReAction:UnregisterBarType(L["Possess Bar"]) | 67 ReAction:UnregisterBarType(L["Possess Bar"]) |
60 end | 68 end |
61 | 69 |
62 function module:ApplyToBar(bar) | 70 function module:OnCreateBar(event, bar, name) |
63 if bar.config.type == moduleID then | 71 if bar.config.type == moduleID then |
64 bar:GetFrame():SetParent(PossessBarFrame) | 72 bar:GetFrame():SetParent(PossessBarFrame) |
65 bar.config.parent = "PossessBarFrame" | 73 bar.config.parent = "PossessBarFrame" |
66 self:CreatePossessControlButtons(bar) | 74 self:CreatePossessControlButtons(bar) |
67 end | 75 end |
68 self:RefreshBar(bar) | 76 self:OnRefreshBar(event, bar, name) |
69 end | 77 end |
70 | 78 |
71 function module:RefreshBar(bar) | 79 function module:OnRefreshBar(event, bar, name) |
72 if bar.config.type == moduleID then | 80 if bar.config.type == moduleID then |
73 if self.buttons[bar] == nil then | 81 if self.buttons[bar] == nil then |
74 self.buttons[bar] = { } | 82 self.buttons[bar] = { } |
75 end | 83 end |
76 local btns = self.buttons[bar] | 84 local btns = self.buttons[bar] |
77 local profile = self.db.profile | 85 local profile = self.db.profile |
78 local barName = bar:GetName() | 86 if profile.buttons[name] == nil then |
79 if profile.buttons[barName] == nil then | 87 profile.buttons[name] = {} |
80 profile.buttons[barName] = {} | 88 end |
81 end | 89 local btnCfg = profile.buttons[name] |
82 local btnCfg = profile.buttons[barName] | |
83 | 90 |
84 local r, c = bar:GetButtonGrid() | 91 local r, c = bar:GetButtonGrid() |
85 local n = r*c | 92 local n = r*c |
86 for i = 1, n do | 93 for i = 1, n do |
87 if btnCfg[i] == nil then | 94 if btnCfg[i] == nil then |
105 end | 112 end |
106 end | 113 end |
107 end | 114 end |
108 end | 115 end |
109 | 116 |
110 function module:RemoveFromBar(bar) | 117 function module:OnDestroyBar(event, bar, name) |
111 if self.buttons[bar] then | 118 if self.buttons[bar] then |
112 local btns = self.buttons[bar] | 119 local btns = self.buttons[bar] |
113 for _,b in pairs(btns) do | 120 for _,b in pairs(btns) do |
114 if b then | 121 if b then |
115 b:Destroy() | 122 b:Destroy() |
117 end | 124 end |
118 self.buttons[bar] = nil | 125 self.buttons[bar] = nil |
119 end | 126 end |
120 end | 127 end |
121 | 128 |
122 function module:EraseBarConfig(barName) | 129 function module:OnEraseBar(event, bar, name) |
123 self.db.profile.buttons[barName] = nil | 130 self.db.profile.buttons[name] = nil |
124 end | 131 end |
125 | 132 |
126 function module:RenameBarConfig(oldname, newname) | 133 function module:OnRenameBar(event, bar, oldname, newname) |
127 local b = self.db.profile.buttons | 134 local b = self.db.profile.buttons |
128 b[newname], b[oldname] = b[oldname], nil | 135 b[newname], b[oldname] = b[oldname], nil |
129 end | 136 end |
130 | 137 |
131 function module:SetHideEmptyButtons(hide) | 138 function module:SetHideEmptyButtons(hide) |
141 end | 148 end |
142 self.db.profile.hideEmptyButtons = hide | 149 self.db.profile.hideEmptyButtons = hide |
143 end | 150 end |
144 end | 151 end |
145 | 152 |
146 function module:ApplyConfigMode(mode,bars) | 153 function module:OnConfigModeChanged(event, mode) |
147 for _, bar in pairs(bars) do | 154 for _, bar in ReAction:IterateBars() do |
148 if bar and self.buttons[bar] then | 155 if bar and self.buttons[bar] then |
149 for _, b in pairs(self.buttons[bar]) do | 156 for _, b in pairs(self.buttons[bar]) do |
150 if b then | 157 if b then |
151 if mode then | 158 if mode then |
152 ActionButton_ShowGrid(b.frame) | 159 ActionButton_ShowGrid(b.frame) |
255 end | 262 end |
256 end | 263 end |
257 | 264 |
258 ---- Options ---- | 265 ---- Options ---- |
259 function module:GetBarOptions(bar) | 266 function module:GetBarOptions(bar) |
260 if not self.options[bar] then | 267 return { |
261 self.options[bar] = { | 268 type = "group", |
262 type = "group", | 269 name = L["Possess Buttons"], |
263 name = L["Possess Buttons"], | 270 hidden = function() return bar.config.type ~= moduleID end, |
264 hidden = function() return bar.config.type ~= moduleID end, | 271 args = { |
265 args = { | |
266 } | |
267 } | 272 } |
268 end | 273 } |
269 return self.options[bar] | |
270 end | 274 end |
271 | 275 |
272 | 276 |
273 -- use-count of action IDs | 277 -- use-count of action IDs |
274 local minActionID = 121 | 278 local minActionID = 121 |