Initial abstraction of state code into StateBar prototype
This commit is contained in:
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
local ButtonBar = Bartender4.ButtonBar.prototype
|
local StateBar = Bartender4.StateBar.prototype
|
||||||
local ActionBar = setmetatable({}, {__index = ButtonBar})
|
local ActionBar = setmetatable({}, {__index = StateBar})
|
||||||
Bartender4.ActionBar = ActionBar
|
Bartender4.ActionBar = ActionBar
|
||||||
|
|
||||||
--[[===================================================================================
|
--[[===================================================================================
|
||||||
@@ -17,7 +17,7 @@ end
|
|||||||
|
|
||||||
-- Apply the specified config to the bar and refresh all settings
|
-- Apply the specified config to the bar and refresh all settings
|
||||||
function ActionBar:ApplyConfig(config)
|
function ActionBar:ApplyConfig(config)
|
||||||
ButtonBar.ApplyConfig(self, config)
|
StateBar.ApplyConfig(self, config)
|
||||||
|
|
||||||
if not self.config.position.x then initialPosition(self) end
|
if not self.config.position.x then initialPosition(self) end
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ function ActionBar:UpdateButtons(numbuttons)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:SkinChanged(...)
|
function ActionBar:SkinChanged(...)
|
||||||
ButtonBar.SkinChanged(self, ...)
|
StateBar.SkinChanged(self, ...)
|
||||||
self:ForAll("Update")
|
self:ForAll("Update")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ local abdefaults = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, Bartender4.ButtonBar.defaults),
|
}, Bartender4.StateBar.defaults),
|
||||||
[1] = {
|
[1] = {
|
||||||
states = {
|
states = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
@@ -188,7 +188,7 @@ end
|
|||||||
-- Creates a new bar object based on the id and the specified config
|
-- Creates a new bar object based on the id and the specified config
|
||||||
function BT4ActionBars:Create(id, config)
|
function BT4ActionBars:Create(id, config)
|
||||||
local id = tostring(id)
|
local id = tostring(id)
|
||||||
local bar = setmetatable(Bartender4.ButtonBar:Create(id, config, (L["Bar %s"]):format(id)), ActionBar_MT)
|
local bar = setmetatable(Bartender4.StateBar:Create(id, config, (L["Bar %s"]):format(id)), ActionBar_MT)
|
||||||
bar.module = self
|
bar.module = self
|
||||||
|
|
||||||
self:CreateBarOption(id)
|
self:CreateBarOption(id)
|
||||||
|
|||||||
+1
-1
@@ -42,8 +42,8 @@ Bartender4.lua
|
|||||||
## Prototypes ##
|
## Prototypes ##
|
||||||
Bar.lua
|
Bar.lua
|
||||||
ButtonBar.lua
|
ButtonBar.lua
|
||||||
|
StateBar.lua
|
||||||
ActionBar.lua
|
ActionBar.lua
|
||||||
ActionBarStates.lua
|
|
||||||
|
|
||||||
## Buttons ##
|
## Buttons ##
|
||||||
ActionButton.lua
|
ActionButton.lua
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4")
|
local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4")
|
||||||
local ButtonBar = Bartender4.ButtonBar.prototype
|
local StateBar = Bartender4.StateBar.prototype
|
||||||
local ActionBar = Bartender4.ActionBar
|
local ActionBar = Bartender4.ActionBar
|
||||||
|
|
||||||
--[[===================================================================================
|
--[[===================================================================================
|
||||||
@@ -57,7 +57,7 @@ end
|
|||||||
|
|
||||||
function module:GetOptionsObject()
|
function module:GetOptionsObject()
|
||||||
if not self.baroptions then
|
if not self.baroptions then
|
||||||
local obj = ButtonBar.GetOptionObject(self)
|
local obj = StateBar.GetOptionObject(self)
|
||||||
|
|
||||||
local cat_general = {
|
local cat_general = {
|
||||||
enabled ={
|
enabled ={
|
||||||
|
|||||||
@@ -1,4 +1,28 @@
|
|||||||
local ActionBar = Bartender4.ActionBar
|
--[[ Generic Template for a ButtonBar with state control ]]
|
||||||
|
|
||||||
|
local ButtonBar = Bartender4.ButtonBar.prototype
|
||||||
|
local StateBar = setmetatable({}, {__index = ButtonBar})
|
||||||
|
local StateBar_MT = {__index = StateBar}
|
||||||
|
|
||||||
|
local defaults = Bartender4:Merge({
|
||||||
|
}, Bartender4.ButtonBar.defaults)
|
||||||
|
|
||||||
|
Bartender4.StateBar = {}
|
||||||
|
Bartender4.StateBar.prototype = StateBar
|
||||||
|
Bartender4.StateBar.defaults = defaults
|
||||||
|
|
||||||
|
function Bartender4.StateBar:Create(id, config, name)
|
||||||
|
local bar = setmetatable(Bartender4.ButtonBar:Create(id, config, name), StateBar_MT)
|
||||||
|
|
||||||
|
return bar
|
||||||
|
end
|
||||||
|
|
||||||
|
function StateBar:ApplyConfig(config)
|
||||||
|
ButtonBar.ApplyConfig(self, config)
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------
|
||||||
|
-- Stance Management
|
||||||
|
|
||||||
local table_insert = table.insert
|
local table_insert = table.insert
|
||||||
local table_concat = table.concat
|
local table_concat = table.concat
|
||||||
@@ -55,7 +79,7 @@ Bartender4.StanceMap = DefaultStanceMap
|
|||||||
local searchFunc = function(h, n) return (h.match == n or h.match2 == n or h.id == n) end
|
local searchFunc = function(h, n) return (h.match == n or h.match2 == n or h.id == n) end
|
||||||
|
|
||||||
local stancemap
|
local stancemap
|
||||||
function ActionBar:UpdateStates(returnOnly)
|
function StateBar:UpdateStates(returnOnly)
|
||||||
if not self.buttons then return end
|
if not self.buttons then return end
|
||||||
self.statebutton = {}
|
self.statebutton = {}
|
||||||
if not stancemap and DefaultStanceMap[playerclass] then
|
if not stancemap and DefaultStanceMap[playerclass] then
|
||||||
@@ -87,8 +111,8 @@ function ActionBar:UpdateStates(returnOnly)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- second priority the manual changes using the actionbar options
|
-- second priority the manual changes using the StateBar options
|
||||||
if self:GetStateOption("actionbar") then
|
if self:GetStateOption("StateBar") then
|
||||||
for i=2,6 do
|
for i=2,6 do
|
||||||
table_insert(statedriver, fmt("[bar:%s]%s", i, i))
|
table_insert(statedriver, fmt("[bar:%s]%s", i, i))
|
||||||
end
|
end
|
||||||
@@ -158,7 +182,7 @@ function ActionBar:UpdateStates(returnOnly)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:GetStanceState(stance)
|
function StateBar:GetStanceState(stance)
|
||||||
local stanceconfig = self.config.states.stance[playerclass]
|
local stanceconfig = self.config.states.stance[playerclass]
|
||||||
if type(stance) == "table" then
|
if type(stance) == "table" then
|
||||||
state = stanceconfig[stance.id]
|
state = stanceconfig[stance.id]
|
||||||
@@ -168,18 +192,18 @@ function ActionBar:GetStanceState(stance)
|
|||||||
return state or 0
|
return state or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:GetStanceStateOption(stance)
|
function StateBar:GetStanceStateOption(stance)
|
||||||
local state = self:GetStanceState(stance)
|
local state = self:GetStanceState(stance)
|
||||||
return state
|
return state
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:SetStanceStateOption(stance, state)
|
function StateBar:SetStanceStateOption(stance, state)
|
||||||
local stanceconfig = self.config.states.stance[playerclass]
|
local stanceconfig = self.config.states.stance[playerclass]
|
||||||
stanceconfig[stance] = state
|
stanceconfig[stance] = state
|
||||||
self:UpdateStates()
|
self:UpdateStates()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:AddButtonStates(state, page)
|
function StateBar:AddButtonStates(state, page)
|
||||||
if not page then page = state end
|
if not page then page = state end
|
||||||
for _, button in self:GetAll() do
|
for _, button in self:GetAll() do
|
||||||
local action = (page == 0) and button.id or (button.rid + (page - 1) * 12)
|
local action = (page == 0) and button.id or (button.rid + (page - 1) * 12)
|
||||||
@@ -187,29 +211,29 @@ function ActionBar:AddButtonStates(state, page)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:GetStateOption(key)
|
function StateBar:GetStateOption(key)
|
||||||
return self.config.states[key]
|
return self.config.states[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:SetStateOption(key, value)
|
function StateBar:SetStateOption(key, value)
|
||||||
self.config.states[key] = value
|
self.config.states[key] = value
|
||||||
self:UpdateStates()
|
self:UpdateStates()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:GetDefaultState()
|
function StateBar:GetDefaultState()
|
||||||
return self.config.states.default
|
return self.config.states.default
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:SetDefaultState(_, value)
|
function StateBar:SetDefaultState(_, value)
|
||||||
self.config.states.default = value
|
self.config.states.default = value
|
||||||
self:UpdateStates()
|
self:UpdateStates()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:GetConfigAutoAssist()
|
function StateBar:GetConfigAutoAssist()
|
||||||
return self.config.autoassist
|
return self.config.autoassist
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:SetConfigAutoAssist(_, value)
|
function StateBar:SetConfigAutoAssist(_, value)
|
||||||
if value ~= nil then
|
if value ~= nil then
|
||||||
self.config.autoassist = value
|
self.config.autoassist = value
|
||||||
end
|
end
|
||||||
@@ -217,7 +241,7 @@ function ActionBar:SetConfigAutoAssist(_, value)
|
|||||||
self:ForAll("RefreshAllStateActions")
|
self:ForAll("RefreshAllStateActions")
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:SetCopyCustomConditionals()
|
function StateBar:SetCopyCustomConditionals()
|
||||||
self.config.states.custom = self:UpdateStates(true)
|
self.config.states.custom = self:UpdateStates(true)
|
||||||
self:UpdateStates()
|
self:UpdateStates()
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user