Mercurial > wow > reaction
diff ReAction.lua @ 48:7b7d178dec52
Implemented bar-type selection, extended CreateBar functionality
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Sat, 12 Apr 2008 00:15:09 +0000 |
parents | e12b736c23c3 |
children | c3c64e2def50 |
line wrap: on
line diff
--- a/ReAction.lua Fri Apr 11 22:21:28 2008 +0000 +++ b/ReAction.lua Sat Apr 12 00:15:09 2008 +0000 @@ -147,6 +147,7 @@ self.bars = {} self.options = {} + self.defaultBarConfig = {} self:RegisterOptions("global", self, { unlock = { @@ -245,9 +246,33 @@ end -function ReAction:CreateBar(name, defaultConfig, prefix) +function ReAction:CreateBar(name, ...) + local config = select(1,...) + if config and type(config) ~= "table" then + bartype = select(1,...) + if type(bartype) ~= "string" then + error("ReAction:CreateBar() - first argument must be a config table or a default config type string") + end + config = self.defaultBarConfig[bartype] + if not config then + error(("ReAction:CreateBar() - unknown bar type '%s'"):format(bartype)) + end + config = DeepCopy(config) + config.btnRows = select(2,...) or config.btnRows or 1 + config.btnColumns = select(3,...) or config.btnColumns or 12 + config.btnWidth = select(4,...) or config.btnWidth or 36 + config.btnHeight = select(4,...) or config.btnHeight or 36 + config.spacing = select(5,...) or config.spacing or 3 + config.width = config.width or config.btnColumns*(config.btnWidth + config.spacing) + 1 + config.height = config.height or config.btnRows*(config.btnHeight + config.spacing) + 1 + config.anchor = config.anchor or "BOTTOM" + config.anchorTo = config.anchorTo or "UIParent" + config.relativePoint = config.relativePoint or "BOTTOM" + config.y = config.y or 200 + config.x = config.x or 0 + end local profile = self.db.profile - defaultConfig = defaultConfig or profile.defaultBar + config = config or DeepCopy(profile.defaultBar) prefix = prefix or L["Bar "] if not name then i = 1 @@ -256,7 +281,7 @@ i = i + 1 until self.bars[name] == nil end - profile.bars[name] = profile.bars[name] or DeepCopy(defaultConfig) + profile.bars[name] = profile.bars[name] or config local bar = self.Bar:new( name, profile.bars[name] ) -- ReAction.Bar defined in Bar.lua self:CallMethodOnAllModules("ApplyToBar", bar) self.bars[name] = bar @@ -299,6 +324,22 @@ end end +function ReAction:RegisterDefaultBarConfig( name, config, isDefaultChoice ) + self.defaultBarConfig[name] = config + if isDefaultChoice then + self.defaultBarConfigChoice = name + end + self:RefreshOptions() +end + +function ReAction:UnregisterDefaultBarConfig( name ) + self.defaultBarConfig[name] = nil + if self.defaultBarConfigChoice == name then + self.defaultBarConfigChoice = nil + end + self:RefreshOptions() +end + -- See modules/ReAction_ConfigUI for valid options contexts. function ReAction:RegisterOptions(context, module, opts) if module == nil or context == nil then @@ -320,14 +361,6 @@ end end -function ReAction:GetOptionContextList() - local c = {} - for k in self.options do - tinsert(c,k) - end - return c -end - function ReAction:RefreshOptions() self.callbacks:Fire("OnOptionsRefreshed") end