first working stance bar, still needs events for updating etc

This commit is contained in:
Hendrik Leppkes
2008-02-16 17:17:31 +00:00
parent 1cec9114c9
commit 3f60367faf
4 changed files with 129 additions and 46 deletions
-38
View File
@@ -19,7 +19,6 @@ do
buttons = "Buttons",
enabled = "Enabled",
grid = "Grid",
style = "Style",
}
-- retrieves a valid bar object from the modules actionbars table
@@ -84,15 +83,6 @@ function module:GetOptionsObject()
set = optSetter,
get = optGetter,
},
style = {
order = 59,
name = "Style",
type = "select",
desc = "Button Style",
values = Bartender4.ButtonStyle:GetStyles(),
set = optSetter,
get = optGetter,
},
buttons = {
order = 60,
name = "Buttons",
@@ -191,15 +181,6 @@ end
-- set the number of buttons and refresh layout
ActionBar.SetButtons = ActionBar.UpdateButtons
function ActionBar:GetStyle()
return self.config.style
end
function ActionBar:SetStyle(style)
self.config.style = style
self:ForAll("ApplyStyle", style)
end
function ActionBar:GetEnabled()
return true
end
@@ -224,22 +205,3 @@ function ActionBar:SetGrid(state)
self:ForAll("HideGrid", true)
end
end
--[[===================================================================================
Utility function
===================================================================================]]--
-- get a iterator over all buttons
function ActionBar:GetAll()
return pairs(self.buttons)
end
-- execute a member function on all buttons
function ActionBar:ForAll(method, ...)
for _, button in self:GetAll() do
local func = button[method]
if func then
func(button, ...)
end
end
end
-1
View File
@@ -10,7 +10,6 @@ local abdefaults = {
buttons = 12,
hidemacrotext = false,
showgrid = false,
style = "dream",
states = {
enabled = false,
stance = {
+41 -1
View File
@@ -8,7 +8,8 @@ local ButtonBar_MT = {__index = ButtonBar}
local defaults = Bartender4:Merge({
padding = 2,
rows = 1
rows = 1,
style = "dream",
}, Bartender4.Bar.defaults)
Bartender4.ButtonBar = {}
@@ -34,6 +35,7 @@ do
optionMap = {
rows = "Rows",
padding = "Padding",
style = "Style",
}
-- retrieves a valid bar object from the barregistry table
@@ -78,6 +80,15 @@ function ButtonBar:GetOptionObject()
set = optSetter,
get = optGetter,
},
style = {
order = 59,
name = "Style",
type = "select",
desc = "Button Style",
values = Bartender4.ButtonStyle:GetStyles(),
set = optSetter,
get = optGetter,
},
rows = {
order = 70,
name = "Rows",
@@ -152,3 +163,32 @@ function ButtonBar:UpdateButtonLayout()
end
end
end
function ButtonBar:GetStyle()
return self.config.style
end
function ButtonBar:SetStyle(style)
self.config.style = style
self:ForAll("ApplyStyle", style)
end
--[[===================================================================================
Utility function
===================================================================================]]--
-- get a iterator over all buttons
function ButtonBar:GetAll()
return pairs(self.buttons)
end
-- execute a member function on all buttons
function ButtonBar:ForAll(method, ...)
for _, button in self:GetAll() do
local func = button[method]
if func then
func(button, ...)
end
end
end
+88 -6
View File
@@ -1,24 +1,29 @@
--[[ $Id$ ]]
local StanceBar = Bartender4:NewModule("StanceBar")
local StanceBarMod = Bartender4:NewModule("StanceBar")
local ActionBars = Bartender4:GetModule("ActionBars")
local ButtonBar = Bartender4.ButtonBar.prototype
local StanceBar = setmetatable({}, {__index = ButtonBar})
local StanceButtonPrototype = CreateFrame("CheckButton")
local StanceButton_MT = {__index = StanceButtonPrototype}
local defaults = { profile = Bartender4:Merge({ enabled = true }, Bartender4.ButtonBar.defaults) }
function StanceBar:OnInitialize()
function StanceBarMod:OnInitialize()
self.db = Bartender4.db:RegisterNamespace("StanceBar", defaults)
self:SetupOptions()
end
function StanceBar:OnEnable()
self.bar = Bartender4.ButtonBar:Create("stance", nil, self.db.profile)
self.buttons = {}
function StanceBarMod:OnEnable()
self.bar = setmetatable(Bartender4.ButtonBar:Create("stance", nil, self.db.profile), {__index = StanceBar})
self.bar:ClearSetPoint("CENTER")
self.bar:ApplyConfig()
end
function StanceBar:SetupOptions()
function StanceBarMod:SetupOptions()
self.options = Bartender4.ButtonBar.prototype:GetOptionObject()
ActionBars.options.args["stance"] = {
order = 30,
type = "group",
@@ -28,3 +33,80 @@ function StanceBar:SetupOptions()
}
ActionBars.options.args["stance"].args = self.options.table
end
function StanceButtonPrototype:Update()
if not self:IsShown() then return end
local id = self:GetID()
local texture, name, isActive, isCastable = GetShapeshiftFormInfo(id)
self.icon:SetTexture(texture);
-- manage cooldowns
if texture then
self.cooldown:Show()
else
self.cooldown:Hide()
end
local start, duration, enable = GetShapeshiftFormCooldown(id)
CooldownFrame_SetTimer(self.cooldown, start, duration, enable)
if ( isActive ) then
self:SetChecked(1);
else
self:SetChecked(0);
end
if ( isCastable ) then
self.icon:SetVertexColor(1.0, 1.0, 1.0)
else
self.icon:SetVertexColor(0.4, 0.4, 0.4)
end
end
StanceButtonPrototype.ApplyStyle = Bartender4.ButtonStyle.ApplyStyle
function StanceButtonPrototype:ClearSetPoint(...)
self:ClearAllPoints()
self:SetPoint(...)
end
function StanceBarMod:CreateStanceButton(id)
local button = setmetatable(CreateFrame("CheckButton", "BT4StanceButton" .. id, self.bar, "ShapeshiftButtonTemplate"), StanceButton_MT)
button:SetID(id)
button.icon = _G[button:GetName() .. "Icon"]
button.cooldown = _G[button:GetName() .. "Cooldown"]
button.normalTexture = button:GetNormalTexture()
button.normalTexture:SetTexture("")
button.checkedTexture = button:GetCheckedTexture()
button.checkedTexture:SetTexture("")
return button
end
function StanceBar:ApplyConfig(config)
ButtonBar.ApplyConfig(self, config)
self:UpdateStanceButtons()
self:ForAll("ApplyStyle", self.config.style)
end
function StanceBar:UpdateStanceButtons()
local buttons = self.buttons or {}
local num_stances = GetNumShapeshiftForms()
for i = (#buttons+1), num_stances do
buttons[i] = StanceBarMod:CreateStanceButton(i)
end
for i = 1, num_stances do
buttons[i]:Show()
buttons[i]:Update()
end
for i = num_stances+1, #buttons do
buttons[i]:Hide()
end
self.buttons = buttons
self:UpdateButtonLayout()
end