Mercurial > wow > reaction
changeset 213:8ba8ab8bf6dd
Demodularize LBF
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Thu, 18 Nov 2010 20:07:48 -0800 |
parents | e275a8663a16 |
children | 8bf038a5edea |
files | Options.lua Profile.lua ReAction.lua ReAction.xml UpdateDB.lua classes/Bar.lua classes/Button.lua modules/LBF.lua modules/modules.xml |
diffstat | 9 files changed, 118 insertions(+), 163 deletions(-) [+] |
line wrap: on
line diff
--- a/Options.lua Thu Nov 18 13:12:16 2010 -0800 +++ b/Options.lua Thu Nov 18 20:07:48 2010 -0800 @@ -154,6 +154,7 @@ function ReAction:OnProfileChanged() + self:UpgradeProfile() self:RebuildAll() if not self.db.global.skipKeybindWarning then StaticPopup_Show("REACTION_KB_WARN")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Profile.lua Thu Nov 18 20:07:48 2010 -0800 @@ -0,0 +1,50 @@ +local _, addonTable = ... +local ReAction = addonTable.ReAction + +ReAction.PROFILEVERSION_LATEST = 1 + +ReAction.defaultProfile = { + profile = { + dbversion = nil, + bars = { }, + options = { + hideBlizzardBars = false, + hideBlizzardVehicleBar = false, + }, + }, + global = { + skipKeybindWarning = false, + } +} + +function ReAction:UpgradeProfile() + local db = self.db + + if not db.profile.dbversion then + -- upgrade from legacy db to v1 + + -- (1) remove unused defaultBars table (cleanup) + db.profile.defaultBars = nil + + -- (2) HideBlizzard is no longer a module + local hb = db:RegisterNamespace("HideBlizzard") + if hb then + db.profile.options.hideBlizzardBars = hb.profile.hide + db.profile.options.hideBlizzardVehicleBar = hb.profile.hideVehicle + hb:ResetProfile() + end + + -- (3) LBF is no longer a module + local bf = db:RegisterNamespace("ButtonFacade") + if bf then + for name, bar in pairs(db.profile.bars) do + bar.ButtonFacade = bf.profile[name] or bar.ButtonFacade + end + bf:ResetProfile() + end + + db.profile.dbversion = 1 + end + + db.profile.dbversion = self.PROFILEVERSION_LATEST +end
--- a/ReAction.lua Thu Nov 18 13:12:16 2010 -0800 +++ b/ReAction.lua Thu Nov 18 20:07:48 2010 -0800 @@ -34,27 +34,20 @@ ------ Handlers ------ function ReAction:OnInitialize() self.db = LibStub("AceDB-3.0"):New("ReAction_DB", - { - profile = { - dbversion = nil, - bars = { }, - options = { - hideBlizzardBars = false, - hideBlizzardVehicleBar = false, - }, - }, - global = { - skipKeybindWarning = false, - } - }, + self.defaultProfile, true -- use global 'Default' (locale-specific) ) - self:UpdateDB() + self:UpgradeProfile() self.bars = { } self.defaultBarConfig = { } + self.LBF = LibStub("LibButtonFacade",true) + if self.LBF then + self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self) + end + -- It's fairly normal to use the Blizzard vehicle bar, and to have -- your regular buttons in the same location. If you do this, and don't -- bother to hide your buttons, they'll obscure some parts of the vehicle bar. @@ -93,6 +86,24 @@ return self:SetKeybindMode(false) end +function ReAction:OnSkinChanged( skinID, gloss, backdrop, group, button, colors ) + if group == nil then + -- don't store global + else + -- 'group' is the bar-name + local bar = self:GetBar(group) + if bar then + local c = bar:GetConfig().ButtonFacade + if c then + c.skinID = skinID + c.gloss = gloss + c.backdrop = backdrop + c.colors = colors + end + end + end +end + ------ Methods ------
--- a/ReAction.xml Thu Nov 18 13:12:16 2010 -0800 +++ b/ReAction.xml Thu Nov 18 20:07:48 2010 -0800 @@ -8,7 +8,7 @@ <Script file="ReAction.lua"/> <Script file="Options.lua"/> <Script file="Editor.lua"/> - <Script file="UpdateDB.lua"/> + <Script file="Profile.lua"/> <Include file="classes\classes.xml"/> <Include file="modules\modules.xml"/>
--- a/UpdateDB.lua Thu Nov 18 13:12:16 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -local _, addonTable = ... -local ReAction = addonTable.ReAction - -ReAction.PROFILEVERSION_LATEST = 1 - -function ReAction:UpdateDB() - local db = self.db - - if not db.profile.dbversion then - -- upgrade from legacy db to v1 - - -- (1) defaultBars table removed (pure cleanup, never used) - db.profile.defaultBars = nil - - -- (2) HideBlizzard is no longer a module - local hdb = db:RegisterNamespace("HideBlizzard") - if hdb then - db.profile.options.hideBlizzardBars = hdb.profile.hide - db.profile.options.hideBlizzardVehicleBar = hdb.profile.hideVehicle - hdb:ResetProfile() - end - - db.profile.dbversion = 1 - end - - db.profile.dbversion = self.PROFILEVERSION_LATEST -end
--- a/classes/Bar.lua Thu Nov 18 13:12:16 2010 -0800 +++ b/classes/Bar.lua Thu Nov 18 20:07:48 2010 -0800 @@ -246,6 +246,19 @@ self:SetConfigMode(ReAction:GetConfigMode()) self:SetKeybindMode(ReAction:GetKeybindMode()) + if ReAction.LBF then + local g = ReAction.LBF:Group(L["ReAction"], self.name) + self.config.ButtonFacade = self.config.ButtonFacade or { + skinID = "Blizzard", + backdrop = true, + gloss = 0, + colors = {}, + } + local c = self.config.ButtonFacade + g:Skin(c.skinID, c.gloss, c.backdrop, c.colors) + self.LBFGroup = g + end + ReAction.RegisterCallback(self, "OnConfigModeChanged") return self @@ -257,6 +270,9 @@ self:ShowControls(false) ReAction.UnregisterAllCallbacks(self) LKB.UnregisterAllCallbacks(self) + if self.LBFGroup then + self.LBFGroup:Delete(true) + end LSG:RemoveFrame(f) f:SetParent(UIParent) f:ClearAllPoints() @@ -282,6 +298,18 @@ -- only ReAction:RenameBar() should call this function. Calling from any other -- context will desync the bar list in the ReAction class. function Bar:SetName(name) + if self.LBFGroup then + -- LBF doesn't offer a method of renaming a group, so delete and remake the group. + local c = self.config.ButtonFacade + local g = ReAction.LBF:Group(L["ReAction"], name) + for b in self:IterateButtons() do + self.LBFGroup:RemoveButton(b:GetFrame(), true) + g:AddButton(b:GetFrame()) + end + self.LBFGroup:Delete(true) + self.LBFGroup = g + self.LBFGroup:Skin(c.skinID, c.gloss, c.backdrop, c.colors) + end self.name = name if self.overlay then self.overlay:SetLabel(self.name) @@ -451,6 +479,8 @@ -- Store a properly wrapped reference to the child frame as an attribute -- (accessible via "frameref-btn#") f:SetFrameRef(format("btn%d",idx), button:GetFrame()) + + -- button constructors are responsible for calling SkinButton end function Bar:RemoveButton(button) @@ -459,6 +489,9 @@ self:GetFrame():SetAttribute(format("frameref-btn%d",idx),nil) self.buttons[button] = nil end + if self.LBFGroup then + self.LBFGroup:RemoveButton(button:GetFrame(),true) + end end function Bar:PlaceButton(button, baseW, baseH) @@ -477,8 +510,10 @@ end end -function Bar:SkinButton() - -- does nothing by default +function Bar:SkinButton( button, data ) + if self.LBFGroup then + self.LBFGroup:AddButton(button:GetFrame(), data) + end end function Bar:UpdateShowGrid()
--- a/classes/Button.lua Thu Nov 18 13:12:16 2010 -0800 +++ b/classes/Button.lua Thu Nov 18 20:07:48 2010 -0800 @@ -12,9 +12,6 @@ local GetBindingKey = GetBindingKey local format = string.format --- libraries -local LBF = LibStub("LibButtonFacade",true) -- optional - -- private local trash = CreateFrame("Frame") local frameList = { } @@ -259,16 +256,16 @@ end function Button:SetNormalVertexColor( r, g, b, a ) - if LBF then - LBF:SetNormalVertexColor(self:GetFrame(), r, g, b, a) + if ReAction.LBF then + ReAction.LBF:SetNormalVertexColor(self:GetFrame(), r, g, b, a) else self:GetFrame():GetNormalTexture():SetVertexColor(r,g,b,a) end end function Button:GetNormalVertexColor() - if LBF then - return LBF:GetNormalVertexColor(self:GetFrame()) + if ReAction.LBF then + return ReAction.LBF:GetNormalVertexColor(self:GetFrame()) else return self:GetFrame():GetNormalTexture():GetVertexColor() end
--- a/modules/LBF.lua Thu Nov 18 13:12:16 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ --- local imports -local addonName, addonTable = ... -local ReAction = addonTable.ReAction -local L = ReAction.L -local _G = _G - --- module declaration -local moduleID = "ButtonFacade" -local module = ReAction:NewModule( moduleID ) - --- handlers -function module:OnInitialize() - self.db = ReAction.db:RegisterNamespace( moduleID, - { - profile = { - -- default profile goes here - } - } - ) - - self.groups = { } - - self.LBF = LibStub("LibButtonFacade",true) - - if not self.LBF then -- no more initialization - return - end - - -- override a method of ReAction.Bar - -- note that 'self' in this context refers to the bar - function ReAction.Bar:SkinButton( button, data ) - module:GetGroup(self:GetName()):AddButton(button:GetFrame(), data) - end - - -- register some common events - ReAction.RegisterCallback(self, "OnCreateBar") - ReAction.RegisterCallback(self, "OnDestroyBar") - ReAction.RegisterCallback(self, "OnRefreshBar") - ReAction.RegisterCallback(self, "OnEraseBar") - ReAction.RegisterCallback(self, "OnRenameBar") - - self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self) -end - -function module:OnEnable() - -end - -function module:OnDisable() - -end - -function module:OnCreateBar(event, bar, name) - local c = self.db.profile[name] - if not c then - c = { - skinID = "Blizzard", - backdrop = true, - gloss = 0, - colors = {}, - } - self.db.profile[name] = c - end - - local g = self:GetGroup(name) - g.SkinID = c.skinID or "Blizzard" - g.Backdrop = c.backdrop - g.Gloss = c.gloss - g.Colors = c.colors -end - -function module:OnDestroyBar(event, bar, name) - if self.groups[name] then - self.groups[name]:Delete() - self.groups[name] = nil - end -end - -function module:OnRefreshBar(event, bar, name) - local c = self.db.profile[name] - local g = self.groups[name] - if c and g then - g:Skin(c.skinID, c.gloss, c.backdrop, c.colors) - end -end - -function module:OnEraseBar(event, bar, name) - self:OnDestroyBar(event, bar, name) - self.db.profile[name] = nil -end - -function module:OnRenameBar(event, bar, oldName, newName) - if self.groups[name] then - self.groups[name]:Delete(true) - self.db.profile[oldName], self.db.profile[newName] = nil, self.db.profile[oldName] - self:OnCreateBar(event, bar, newName) - end -end - -function module:OnSkinChanged( skinID, gloss, backdrop, group, button, colors ) - local c = self.db.profile[group] - if c then - c.skinID = skinID - c.gloss = gloss - c.backdrop = backdrop - c.colors = colors - end -end - -function module:GetGroup( name ) - if not self.groups[name] then - self.groups[name] = self.LBF:Group("ReAction", name) - end - return self.groups[name] -end
--- a/modules/modules.xml Thu Nov 18 13:12:16 2010 -0800 +++ b/modules/modules.xml Thu Nov 18 20:07:48 2010 -0800 @@ -3,7 +3,6 @@ xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd"> <Script file="State.lua"/> -<Script file="LBF.lua"/> <Script file="Action.lua"/> <Script file="PetAction.lua"/> <Script file="Stance.lua"/>