Mercurial > wow > reaction
comparison modules/ReAction_PetAction/ReAction_PetAction.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 | 06cd74bdc7da |
comparison
equal
deleted
inserted
replaced
62:f9cdb920470a | 63:768be7eb22a0 |
---|---|
25 buttons = { } | 25 buttons = { } |
26 } | 26 } |
27 } | 27 } |
28 ) | 28 ) |
29 self.buttons = { } | 29 self.buttons = { } |
30 self.options = setmetatable({},{__mode="k"}) | 30 |
31 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") | |
32 | |
33 ReAction.RegisterCallback(self, "OnCreateBar") | |
34 ReAction.RegisterCallback(self, "OnDestroyBar") | |
35 ReAction.RegisterCallback(self, "OnRefreshBar") | |
36 ReAction.RegisterCallback(self, "OnEraseBar") | |
37 ReAction.RegisterCallback(self, "OnRenameBar") | |
38 ReAction.RegisterCallback(self, "OnConfigModeChanged") | |
31 end | 39 end |
32 | 40 |
33 function module:OnEnable() | 41 function module:OnEnable() |
34 ReAction:RegisterBarType(L["Pet Action Bar"], | 42 ReAction:RegisterBarType(L["Pet Action Bar"], |
35 { | 43 { |
43 | 51 |
44 function module:OnDisable() | 52 function module:OnDisable() |
45 ReAction:UnregisterBarType(L["Pet Action Bar"]) | 53 ReAction:UnregisterBarType(L["Pet Action Bar"]) |
46 end | 54 end |
47 | 55 |
48 function module:ApplyToBar(bar) | 56 function module:OnCreateBar(event, bar, name) |
49 if bar.config.type == moduleID then | 57 if bar.config.type == moduleID then |
50 -- auto show/hide when pet exists | 58 -- auto show/hide when pet exists |
51 bar:GetFrame():SetAttribute("unit","pet") | 59 bar:GetFrame():SetAttribute("unit","pet") |
52 RegisterUnitWatch(bar:GetFrame()) | 60 RegisterUnitWatch(bar:GetFrame()) |
53 self:RefreshBar(bar) | 61 self:OnRefreshBar(event, bar, name) |
54 end | 62 end |
55 end | 63 end |
56 | 64 |
57 function module:RefreshBar(bar) | 65 function module:OnRefreshBar(event, bar, name) |
58 if bar.config.type == moduleID then | 66 if bar.config.type == moduleID then |
59 if self.buttons[bar] == nil then | 67 if self.buttons[bar] == nil then |
60 self.buttons[bar] = { } | 68 self.buttons[bar] = { } |
61 end | 69 end |
62 local btns = self.buttons[bar] | 70 local btns = self.buttons[bar] |
63 local profile = self.db.profile | 71 local profile = self.db.profile |
64 local barName = bar:GetName() | 72 if profile.buttons[name] == nil then |
65 if profile.buttons[barName] == nil then | 73 profile.buttons[name] = {} |
66 profile.buttons[barName] = {} | 74 end |
67 end | 75 local btnCfg = profile.buttons[name] |
68 local btnCfg = profile.buttons[barName] | |
69 | 76 |
70 local r, c = bar:GetButtonGrid() | 77 local r, c = bar:GetButtonGrid() |
71 local n = r*c | 78 local n = r*c |
72 for i = 1, n do | 79 for i = 1, n do |
73 if btnCfg[i] == nil then | 80 if btnCfg[i] == nil then |
91 end | 98 end |
92 end | 99 end |
93 end | 100 end |
94 end | 101 end |
95 | 102 |
96 function module:RemoveFromBar(bar) | 103 function module:OnDestroyBar(event, bar, name) |
97 if self.buttons[bar] then | 104 if self.buttons[bar] then |
98 local btns = self.buttons[bar] | 105 local btns = self.buttons[bar] |
99 for _,b in pairs(btns) do | 106 for _,b in pairs(btns) do |
100 if b then | 107 if b then |
101 b:Destroy() | 108 b:Destroy() |
103 end | 110 end |
104 self.buttons[bar] = nil | 111 self.buttons[bar] = nil |
105 end | 112 end |
106 end | 113 end |
107 | 114 |
108 function module:EraseBarConfig(barName) | 115 function module:OnEraseBar(event, bar, name) |
109 self.db.profile.buttons[barName] = nil | 116 self.db.profile.buttons[name] = nil |
110 end | 117 end |
111 | 118 |
112 function module:RenameBarConfig(oldname, newname) | 119 function module:OnRenameBar(event, bar, oldname, newname) |
113 local b = self.db.profile.buttons | 120 local b = self.db.profile.buttons |
114 b[newname], b[oldname] = b[oldname], nil | 121 b[newname], b[oldname] = b[oldname], nil |
115 end | 122 end |
116 | 123 |
117 | 124 |
118 function module:ApplyConfigMode(mode,bars) | 125 function module:OnConfigModeChanged(event, mode) |
119 for _, bar in pairs(bars) do | 126 for _, bar in ReAction:IterateBars() do |
120 if bar and self.buttons[bar] then | 127 if bar and self.buttons[bar] then |
121 for _, b in pairs(self.buttons[bar]) do | 128 for _, b in pairs(self.buttons[bar]) do |
122 if b then | 129 if b then |
123 if mode then | 130 if mode then |
124 self:showActionIDLabel(b) | 131 self:showActionIDLabel(b) |
158 end | 165 end |
159 end | 166 end |
160 | 167 |
161 ---- Options ---- | 168 ---- Options ---- |
162 function module:GetBarOptions(bar) | 169 function module:GetBarOptions(bar) |
163 if not self.options[bar] then | 170 return { |
164 self.options[bar] = { | 171 type = "group", |
165 type = "group", | 172 name = L["Pet Buttons"], |
166 name = L["Pet Buttons"], | 173 hidden = function() return bar.config.type ~= moduleID end, |
167 hidden = function() return bar.config.type ~= moduleID end, | 174 args = { |
168 args = { | |
169 } | |
170 } | 175 } |
171 end | 176 } |
172 return self.options[bar] | |
173 end | 177 end |
174 | 178 |
175 | 179 |
176 | 180 |
177 -- use-count of action IDs | 181 -- use-count of action IDs |