From 4e23013c644ea05fb8e02d55348027f96885e1ad Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Sat, 21 Jun 2008 13:42:26 +0000 Subject: [PATCH] improve visibility driver logic and API --- ActionBarPrototype.lua | 11 ++------ ActionBarStates.lua | 24 +++++++---------- Bar.lua | 60 ++++++++++++++++++++++++++++++------------ 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/ActionBarPrototype.lua b/ActionBarPrototype.lua index 791e374..a66416b 100644 --- a/ActionBarPrototype.lua +++ b/ActionBarPrototype.lua @@ -197,18 +197,11 @@ function ActionBar:SkinChanged(...) self:ForAll("Update") end -function ActionBar:Lock() - if self.disabled or not self.unlocked then return end - ButtonBar.Lock(self) +function ActionBar:SetShow(...) + ButtonBar.SetShow(self, ...) self:UpdateStates() end -function ActionBar:Unlock() - if self.disabled or self.unlocked then return end - ButtonBar.Unlock(self) - self:UpdateStates(true) -end - --[[=================================================================================== ActionBar Config Interface diff --git a/ActionBarStates.lua b/ActionBarStates.lua index f3047d3..bc83b99 100644 --- a/ActionBarStates.lua +++ b/ActionBarStates.lua @@ -268,7 +268,9 @@ function module:CreateStanceMap() self.stancemap = defstancemap end -function ActionBar:UpdateStates(noHideDriver) +function ActionBar:UpdateStates() + if not self.buttons then return end + self:InitVisibilityDriver() self.statebutton = {} if not module.stancemap and module.DefaultStanceMap[playerclass] then module.stancemap = module.DefaultStanceMap[playerclass] @@ -277,7 +279,7 @@ function ActionBar:UpdateStates(noHideDriver) self:AddButtonStates(i) end - local statedriver, hidedriver = {}, {} + local statedriver = {} if self:GetStateOption("possess") then self:AddButtonStates(11) table_insert(statedriver, "[bonusbar:5]11") @@ -292,7 +294,7 @@ function ActionBar:UpdateStates(noHideDriver) local page = self:GetStateOption(v) if page and page ~= 0 then if page == -1 then - table_insert(hidedriver, fmt("[modifier:%s]hide", v)) + self:RegisterVisibilityCondition(fmt("[modifier:%s]hide", v)) else table_insert(statedriver, fmt("[modifier:%s]%s", v, page)) end @@ -316,14 +318,14 @@ function ActionBar:UpdateStates(noHideDriver) local prowl = self:GetStanceState("prowl") if prowl then if prowl == -1 then - table_insert(hidedriver, fmt("[bonusbar:%s,stealth:1]hide", v.index)) + self:RegisterVisibilityCondition(fmt("[bonusbar:%s,stealth:1]hide", v.index)) else table_insert(statedriver, fmt("[bonusbar:%s,stealth:1]%s", v.index, prowl)) end end end if state == -1 then - table_insert(hidedriver, fmt("[bonusbar:%s]hide", v.index)) + self:RegisterVisibilityCondition(fmt("[bonusbar:%s]hide", v.index)) else table_insert(statedriver, fmt("[bonusbar:%s]%s", v.index, state)) end @@ -333,24 +335,16 @@ function ActionBar:UpdateStates(noHideDriver) end table_insert(statedriver, tostring(self:GetDefaultState() or 0)) - table_insert(hidedriver, "show") RegisterStateDriver(self, "page", table_concat(statedriver, ";")) self:SetAttribute("statemap-page", "$input") - if not noHideDriver then - RegisterStateDriver(self, "visibility", table_concat(hidedriver, ";")) - self:SetAttribute("statemap-visibility", "$input") - self:SetAttribute("state-visibility", self:GetAttribute("state-visibility")) - else - UnregisterStateDriver(self, "visibility") - self:Show() - end - self:ApplyStateButton() SecureStateHeader_Refresh(self) self:SetAttribute("state", self:GetAttribute("state-page")) + + self:ApplyVisibilityDriver() end function ActionBar:GetStanceState(stance) diff --git a/Bar.lua b/Bar.lua index 154beb1..d730d27 100644 --- a/Bar.lua +++ b/Bar.lua @@ -7,6 +7,8 @@ local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") local Bar = CreateFrame("Button") local Bar_MT = {__index = Bar} +local table_concat, table_insert = table.concat, table.insert + --[[=================================================================================== Universal Bar Contructor ===================================================================================]]-- @@ -109,6 +111,7 @@ function Bartender4.Bar:Create(id, config, name) bar.config = config bar.elapsed = 0 + bar.hidedriver = {} return bar end @@ -273,18 +276,20 @@ function Bar:ApplyConfig(config) self.config = config end if self.disabled then return end + self:InitVisibilityDriver() self:SetShow() self:Lock() self:LoadPosition() self:SetConfigScale() self:SetConfigAlpha() self:SetFadeOut() + self:ApplyVisibilityDriver() end function Bar:Unlock() if self.disabled or self.unlocked then return end self.unlocked = true - UnregisterStateDriver(self, "visibility") + self:DisableVisibilityDriver() self:Show() self.overlay:Show() if self.config.show == "alwayshide" then @@ -304,7 +309,7 @@ function Bar:Lock() self.unlocked = nil barOnDragStop(self.overlay) - self:ConfigureShowStates() + self:ApplyVisibilityDriver() self.overlay:Hide() @@ -344,7 +349,8 @@ function Bar:SetShow(show) self.config.show = show end if not self.unlocked then - self:ConfigureShowStates() + self:InitVisibilityDriver() + self:ApplyVisibilityDriver() else self:Show() if self.config.show == "alwayshide" then @@ -355,20 +361,6 @@ function Bar:SetShow(show) end end -function Bar:ConfigureShowStates() - UnregisterStateDriver(self, 'visibility') - local conditions - if self.config.show == "alwaysshow" or self.config.show == true then - self:Show() - elseif self.config.show == "alwayshide" or self.config.show == false then - self:Hide() - elseif self.config.show == "combatshow" then - RegisterStateDriver(self, 'visibility', '[combat]show;hide') - elseif self.config.show == "combathide" then - RegisterStateDriver(self, 'visibility', '[combat]hide;show') - end -end - function Bar:GetConfigAlpha() return self.config.alpha end @@ -447,6 +439,40 @@ function Bar:ControlFadeOut() end end + +function Bar:InitVisibilityDriver() + self.hidedriver = {} + UnregisterStateDriver(self, 'visibility') + if self.config.show == "alwaysshow" or self.config.show == true then + -- + elseif self.config.show == "alwayshide" or self.config.show == false then + self:RegisterVisibilityCondition("hide") + elseif self.config.show == "combatshow" then + self:RegisterVisibilityCondition("[nocombat]hide") + elseif self.config.show == "combathide" then + self:RegisterVisibilityCondition("[combat]hide") + end +end + +function Bar:RegisterVisibilityCondition(condition) + table_insert(self.hidedriver, condition) +end + +function Bar:ApplyVisibilityDriver() + if self.unlocked then return end + -- default state is shown + self:RegisterVisibilityCondition("show") + RegisterStateDriver(self, "visibility", table_concat(self.hidedriver, ";")) + self:SetAttribute("statemap-visibility", "$input") + self:SetAttribute("state-visibility", self:GetAttribute("state-visibility")) +end + +function Bar:DisableVisibilityDriver() + UnregisterStateDriver(self, "visibility") + self:SetAttribute("state-visibility", nil) + self:Show() +end + --[[ Lazyness functions ]]