Mercurial > wow > reaction
comparison ReAction.lua @ 223:c4b134512c50
Move RegisterBarType from modules to button classes
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Mon, 22 Nov 2010 10:25:18 -0800 |
| parents | e63aefb8a555 |
| children | 19fd228d9241 |
comparison
equal
deleted
inserted
replaced
| 222:d08a74e86c96 | 223:c4b134512c50 |
|---|---|
| 29 ReAction.version = "1.1" | 29 ReAction.version = "1.1" |
| 30 ReAction.L = L | 30 ReAction.L = L |
| 31 ReAction.LKB = LKB | 31 ReAction.LKB = LKB |
| 32 | 32 |
| 33 | 33 |
| 34 ReAction.barTypes = { } | |
| 35 | |
| 34 ------ Handlers ------ | 36 ------ Handlers ------ |
| 35 function ReAction:OnInitialize() | 37 function ReAction:OnInitialize() |
| 36 self.db = LibStub("AceDB-3.0"):New("ReAction_DB", | 38 self.db = LibStub("AceDB-3.0"):New("ReAction_DB", |
| 37 self.defaultProfile, | 39 self.defaultProfile, |
| 38 true -- use global 'Default' (locale-specific) | 40 true -- use global 'Default' (locale-specific) |
| 39 ) | 41 ) |
| 40 | 42 |
| 41 self:UpgradeProfile() | 43 self:UpgradeProfile() |
| 42 | 44 |
| 43 self.bars = { } | 45 self.bars = { } |
| 44 self.barTypes = { } | |
| 45 | 46 |
| 46 self.LBF = LibStub("LibButtonFacade",true) | 47 self.LBF = LibStub("LibButtonFacade",true) |
| 47 if self.LBF then | 48 if self.LBF then |
| 48 self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self) | 49 self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self) |
| 49 end | 50 end |
| 141 elseif self.bars[name] then | 142 elseif self.bars[name] then |
| 142 self:UserError(format(L["ReAction: name '%s' already in use"],name)) | 143 self:UserError(format(L["ReAction: name '%s' already in use"],name)) |
| 143 return nil | 144 return nil |
| 144 end | 145 end |
| 145 | 146 |
| 147 local class | |
| 146 if type(config) == "string" then | 148 if type(config) == "string" then |
| 147 local class = self.barTypes[config] | 149 class = self.barTypes[config] |
| 148 if not class then | 150 if not class then |
| 149 error(("ReAction:CreateBar() - unknown bar type '%s'"):format(config)) | 151 error(("ReAction:CreateBar() - unknown bar type '%s'"):format(config)) |
| 150 end | 152 end |
| 151 config = tcopy(class:GetDefaultBarConfig()) | 153 config = tcopy(class:GetDefaultBarConfig()) |
| 152 config.btnRows = select(1,...) or config.btnRows | 154 config.btnRows = select(1,...) or config.btnRows |
| 159 config.anchor = config.anchor or "UIParent" | 161 config.anchor = config.anchor or "UIParent" |
| 160 config.point = config.point or "BOTTOM" | 162 config.point = config.point or "BOTTOM" |
| 161 config.relpoint = config.relpoint or "BOTTOM" | 163 config.relpoint = config.relpoint or "BOTTOM" |
| 162 config.y = config.y or 200 | 164 config.y = config.y or 200 |
| 163 config.x = config.x or 0 | 165 config.x = config.x or 0 |
| 164 end | 166 else |
| 165 config = config or profile.bars[name] or { } | 167 config = config or profile.bars[name] or { } |
| 168 if not config or not config.type or not self.barTypes[config.type] then | |
| 169 error(("ReAction: Unable to construct/fetch config table for bar '%s'"):format(name)) | |
| 170 end | |
| 171 class = self.barTypes[config.type] | |
| 172 end | |
| 166 | 173 |
| 167 profile.bars[name] = config | 174 profile.bars[name] = config |
| 168 local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua | 175 local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua |
| 169 self.bars[name] = bar | 176 self.bars[name] = bar |
| 170 self.callbacks:Fire("OnCreateBar", bar, name) | 177 self.callbacks:Fire("OnCreateBar", bar, name) |
| 291 self.defaultBarType = name | 298 self.defaultBarType = name |
| 292 end | 299 end |
| 293 self:RefreshEditor() | 300 self:RefreshEditor() |
| 294 end | 301 end |
| 295 | 302 |
| 296 function ReAction:UnregisterBarType( class ) | |
| 297 local name = class:GetBarType() | |
| 298 self.barTypes[name] = nil | |
| 299 if self.defaultBarType == name then | |
| 300 self.defaultBarType = nil | |
| 301 end | |
| 302 self:RefreshEditor() | |
| 303 end | |
| 304 | |
| 305 function ReAction:IterateBarTypes() | 303 function ReAction:IterateBarTypes() |
| 306 return pairs(self.barTypes) | 304 return pairs(self.barTypes) |
| 307 end | 305 end |
| 308 | 306 |
| 309 function ReAction:GetDefaultBarConfig(barType) | 307 function ReAction:GetDefaultBarConfig(barType) |
