improve visibility driver logic and API
This commit is contained in:
@@ -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
|
||||
|
||||
+9
-15
@@ -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)
|
||||
|
||||
@@ -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
|
||||
]]
|
||||
|
||||
Reference in New Issue
Block a user