Mercurial > wow > reaction
changeset 211:97949dbe987f
Demodularize HideBlizzard
- added framework for updating profile database
- removed unused profile.defaultBars[]
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Thu, 18 Nov 2010 12:59:00 -0800 |
parents | c24ac8ee1e45 |
children | e275a8663a16 |
files | Options.lua ReAction.lua ReAction.xml UpdateDB.lua modules/HideBlizzard.lua modules/modules.xml |
diffstat | 6 files changed, 110 insertions(+), 122 deletions(-) [+] |
line wrap: on
line diff
--- a/Options.lua Tue Nov 16 21:49:54 2010 -0800 +++ b/Options.lua Thu Nov 18 12:59:00 2010 -0800 @@ -40,10 +40,9 @@ type = "toggle", name = L["Hide Blizzard Action Bars"], desc = L["Hide the default main bar and extra action bars"], - handler = self:GetModule("HideBlizzard"), - get = "IsHidden", - set = "SetHidden", - disabled = "OptionDisabled", + get = "OptionGetHideBlizzardBars", + set = "OptionSetHideBlizzardBars", + disabled = InCombatLockdown, width = "full", order = 3, }, @@ -51,10 +50,9 @@ type = "toggle", name = L["Hide Blizzard Vehicle Bar"], desc = L["Hide the default vechicle action bar"], - handler = self:GetModule("HideBlizzard"), - get = "IsHidden", - set = "SetHidden", - disabled = "OptionDisabled", + get = "OptionGetHideBlizzardVehicleBar", + set = "OptionSetHideBlizzardVehicleBar", + disabled = function() return InCombatLockdown() or ReAction:OptionGetHideBlizzardBars() == false end, width = "full", order = 4, }, @@ -139,6 +137,14 @@ showAlert = true, whileDead = true, } + + -- reroute blizzard action bar config to ReAction config window + InterfaceOptionsActionBarsPanel:HookScript("OnShow", + function() + if ReAction:OptionGetHideBlizzardBars() then + ReAction:ShowOptions() + end + end ) end @@ -181,6 +187,25 @@ end +function ReAction:OptionSetHideBlizzardBars( info, hide ) + self.db.profile.options.hideBlizzardBars = hide + self:ManageBlizzardBars() +end + +function ReAction:OptionGetHideBlizzardBars() + return self.db.profile.options.hideBlizzardBars +end + +function ReAction:OptionSetHideBlizzardVehicleBar( info, hide ) + self.db.profile.options.hideBlizzardVehicleBar = hide + self:ManageBlizzardBars() +end + +function ReAction:OptionGetHideBlizzardVehicleBar() + return self.db.profile.options.hideBlizzardVehicleBar +end + + -- export to LDB local LDB = LibStub:GetLibrary("LibDataBroker-1.1") if LDB then
--- a/ReAction.lua Tue Nov 16 21:49:54 2010 -0800 +++ b/ReAction.lua Thu Nov 18 12:59:00 2010 -0800 @@ -36,16 +36,30 @@ self.db = LibStub("AceDB-3.0"):New("ReAction_DB", { profile = { + dbversion = nil, bars = { }, - defaultBar = { }, + options = { + hideBlizzardBars = false, + hideBlizzardVehicleBar = false, + }, + }, + global = { + skipKeybindWarning = false, } }, true -- use global 'Default' (locale-specific) ) + self:UpdateDB() + self.bars = { } self.defaultBarConfig = { } + -- 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. + VehicleMenuBar:SetFrameLevel(VehicleMenuBar:GetFrameLevel()+3) + self.callbacks = LibStub("CallbackHandler-1.0"):New(self) LKB.RegisterCallback(self,"LIBKEYBOUND_ENABLED") LKB.RegisterCallback(self,"LIBKEYBOUND_DISABLED") @@ -143,7 +157,7 @@ config.y = config.y or 200 config.x = config.x or 0 end - config = config or profile.bars[name] or tcopy(profile.defaultBar) + config = config or profile.bars[name] or { } profile.bars[name] = config local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua @@ -174,6 +188,8 @@ function ReAction:InitializeBars() if not self.barsInitialized then + self:ManageBlizzardBars() + for name, config in pairs(self.db.profile.bars) do if config then self:CreateBar(name, config) @@ -232,6 +248,37 @@ end end +local blizzFrames = { + MainMenuBar, + MultiBarLeft, + MultiBarRight, + MultiBarBottomLeft, + MultiBarBottomRight, +} + +local hideFrame = CreateFrame("Frame") +hideFrame:Hide() +local hiddenParents = { } +local function ManageBlizzFrame(f, hide) + if hide and not hiddenParents[f] then + hiddenParents[f] = f:GetParent() + f:SetParent(hideFrame) + elseif not hide and hiddenParents[f] then + f:SetParent(hiddenParents[f]) + hiddenParents[f] = nil + if f:IsShown() then + f:Show() -- refresh + end + end +end + +function ReAction:ManageBlizzardBars() + for _, f in pairs(blizzFrames) do + ManageBlizzFrame(f, self.db.profile.options.hideBlizzardBars) + end + ManageBlizzFrame(VehicleMenuBar, self.db.profile.options.hideBlizzardVehicleBar) +end + function ReAction:RegisterBarType( name, config, isDefaultChoice ) self.defaultBarConfig[name] = config if isDefaultChoice then
--- a/ReAction.xml Tue Nov 16 21:49:54 2010 -0800 +++ b/ReAction.xml Thu Nov 18 12:59:00 2010 -0800 @@ -8,6 +8,7 @@ <Script file="ReAction.lua"/> <Script file="Options.lua"/> <Script file="Editor.lua"/> + <Script file="UpdateDB.lua"/> <Include file="classes\classes.xml"/> <Include file="modules\modules.xml"/>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UpdateDB.lua Thu Nov 18 12:59:00 2010 -0800 @@ -0,0 +1,27 @@ +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/modules/HideBlizzard.lua Tue Nov 16 21:49:54 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ ---[[ - ReAction 'Hide Blizzard' module - - Hides Blizzard action bars. This hides the extra action bars, stance bar, pet bar, and - main menu bar, which in turn hides the experience bar, bag bar, micro menu bar, and lag meter. - ---]] - --- local imports -local addonName, addonTable = ... -local ReAction = addonTable.ReAction -local L = ReAction.L - --- module declaration -local moduleID = "HideBlizzard" -local module = ReAction:NewModule( moduleID ) - - --- module methods -function module:OnInitialize() - self.db = ReAction.db:RegisterNamespace( moduleID, - { - profile = { - hide = false - } - } - ) - self.db.RegisterCallback(self,"OnProfileChanged") - self.db.RegisterCallback(self,"OnProfileCopied", "OnProfileChanged") - self.db.RegisterCallback(self,"OnProfileReset", "OnProfileChanged") - - self.hiddenFrame = CreateFrame("Frame") - self.hiddenFrame:Hide() - - -- 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. - VehicleMenuBar:SetFrameLevel(VehicleMenuBar:GetFrameLevel()+3) - -end - -function module:OnEnable() - self:UpdateFrames() -end - -function module:OnDisable() - self:UpdateFrames(true) -end - -function module:OnProfileChanged() - self:UpdateFrames() -end - -local frames = { - [ MainMenuBar ] = { }, - [ MultiBarLeft ] = { }, - [ MultiBarRight ] = { }, - [ MultiBarBottomLeft ] = { }, - [ MultiBarBottomRight ] = { }, - [ VehicleMenuBar ] = { field = "hideVehicle" }, -} - -function module:UpdateFrames( show ) - show = show or not self.db.profile.hide - for frame, info in pairs(frames) do - local show = show -- make a local copy for this frame - if info.field then - show = show or not self.db.profile[info.field] - end - - if show then - if info.parent then - frame:SetParent(info.parent) - end - if frame:IsShown() then - frame:Show() -- refresh - end - else - if not info.parent then - info.parent = frame:GetParent() - end - frame:SetParent(self.hiddenFrame) - end - end -end - -function module:IsHidden(info) - if info then - return self.db.profile.hide and self.db.profile[info[#info]] - else - return self.db.profile.hide - end -end - -function module:SetHidden(info,value) - self.db.profile[info[#info]] = value - self:UpdateFrames() -end - -function module:OptionDisabled(info) - local disabled = InCombatLockdown() - if not disabled and info[#info] ~= "hide" then - disabled = not self.db.profile.hide - end - return disabled -end - - --- reroute blizzard action bar config to ReAction config window -InterfaceOptionsActionBarsPanel:HookScript("OnShow", - function() - if module:IsEnabled() and module:IsHidden() then - ReAction:ShowOptions() - end - end )
--- a/modules/modules.xml Tue Nov 16 21:49:54 2010 -0800 +++ b/modules/modules.xml Thu Nov 18 12:59:00 2010 -0800 @@ -4,7 +4,6 @@ <Script file="State.lua"/> <Script file="LBF.lua"/> -<Script file="HideBlizzard.lua"/> <Script file="Action.lua"/> <Script file="PetAction.lua"/> <Script file="Stance.lua"/>