- split actionbar module and prototype into independent files

- added meta functions to update bars/buttons
- first options
This commit is contained in:
Hendrik Leppkes
2007-12-03 14:58:16 +00:00
parent 0fc2692a53
commit 276d0b6d1f
6 changed files with 308 additions and 136 deletions
+100
View File
@@ -0,0 +1,100 @@
--[[ $Id: Bartender4.lua 56386 2007-12-01 14:21:40Z nevcairiel $ ]]
local Bar = Bartender4.Bar.prototype
local ActionBar = setmetatable({}, {__index = Bar})
Bartender4.ActionBar = ActionBar
local math_floor = math.floor
--[[
Bar Prototype Functions
]]
local initialPosition
do
-- Sets the Bar to its initial Position in the Center of the Screen
function initialPosition(bar)
bar:ClearSetPoint("CENTER", 0, -250 + (bar.id-1) * 38)
bar:SavePosition()
end
end
-- Apply the specified config to the bar and refresh all settings
function ActionBar:ApplyConfig(config)
Bar.ApplyConfig(self, config)
config = self.config
if not config.Position then initialPosition(self) end
self:UpdateButtons(config.Buttons)
end
-- Update the number of buttons in our bar, creating new ones if necessary
function ActionBar:UpdateButtons(numbuttons)
if numbuttons then
self.config.Buttons = numbuttons
else
numbuttons = self.config.Buttons
end
local buttons = self.buttons or {}
-- create more buttons if needed
for i = (#buttons+1), numbuttons do
buttons[i] = Bartender4.Button:Create(i, self)
end
-- show active buttons
for i = 1, numbuttons do
buttons[i]:Show()
buttons[i]:UpdateAction(true)
end
-- hide inactive buttons
for i = (numbuttons + 1), #buttons do
buttons[i]:Hide()
end
self.buttons = buttons
self:UpdateButtonLayout()
end
-- align the buttons and correct the size of the bar overlay frame
function ActionBar:UpdateButtonLayout()
local numbuttons = self.config.Buttons
local buttons = self.buttons
local pad = self.config.Padding
local Rows = self.config.Rows
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
self:SetSize((36 + pad) * ButtonPerRow - pad + 8, (36 + pad) * Rows - pad + 8)
-- anchor button 1 to the topleft corner of the bar
buttons[1]:ClearSetPoint("TOPLEFT", self, "TOPLEFT", 6, -3)
-- and anchor all other buttons relative to our button 1
for i = 2, numbuttons do
-- jump into a new row
if ((i-1) % ButtonPerRow) == 0 then
buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-ButtonPerRow], "BOTTOMLEFT", 0, -pad)
-- align to the previous button
else
buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-1], "TOPRIGHT", pad, 0)
end
end
end
function ActionBar:GetAll()
return pairs(self.buttons)
end
function ActionBar:ForAll(method, ...)
for _, button in self:GetAll() do
local func = button[method]
if func then
func(button, ...)
end
end
end
+92 -81
View File
@@ -2,13 +2,9 @@
local BT4ActionBars = Bartender4:NewModule("ActionBars")
local Bar = Bartender4.Bar.prototype
local ActionBar = setmetatable({}, {__index = Bar})
local ActionBar = Bartender4.ActionBar
local ActionBar_MT = {__index = ActionBar}
local math_floor = math.floor
local stancedefaults = {
DRUID = { bear = 9, cat = 7, prowl = 8 },
WARRIOR = { battle = 7, def = 8, berserker = 9 },
@@ -33,6 +29,8 @@ local defaults = {
function BT4ActionBars:OnInitialize()
self.db = Bartender4.db
Bartender4:RegisterDefaultsKey("ActionBars", defaults)
self:SetupOptions()
end
-- setup the 10 actionbars
@@ -58,15 +56,98 @@ function BT4ActionBars:ApplyConfig()
end
end
local initialPosition
do
-- Sets the Bar to its initial Position in the Center of the Screen
function initialPosition(bar)
bar:ClearSetPoint("CENTER", 0, -250 + (bar.id-1) * 38)
bar:SavePosition()
function BT4ActionBars:UpdateButtons()
for i,v in ipairs(self.actionbars) do
for j,button in ipairs(v.buttons) do
button:UpdateAction(force)
end
end
end
function BT4ActionBars:GetAll()
return pairs(self.actionbars)
end
function BT4ActionBars:ForAll(method, ...)
for _, bar in self:GetAll() do
local func = bar[method]
if func then
func(bar, ...)
end
end
end
function BT4ActionBars:ForAllButtons(...)
self:ForAll("ForAll", ...)
end
local getFunc, setFunc
do
function getFunc(info)
return (info.arg and Bartender4.db.profile[info.arg] or Bartender4.db.profile[info[#info]])
end
function setFunc(info, value)
local key = info.arg or info[#info]
Bartender4.db.profile[key] = value
end
end
function BT4ActionBars:SetupOptions()
self.options = {
type = "group",
--cmdInline = true,
name = "Action Bars",
get = getFunc,
set = setFunc,
args = {
range = {
order = 1,
name = "Out of Range Indicator",
desc = "Configure how the Out of Range Indicator should display on the buttons.",
type = "select",
style = "dropdown",
arg = "OutOfRange",
set = function(info, value)
setFunc(info, value)
BT4ActionBars:ForAllButtons("UpdateUsable")
end,
values = { none = "No Display", button = "Full Button Mode", hotkey = "Hotkey Mode" },
},
colors = {
order = 2,
type = "group",
guiInline = true,
name = "Colors",
get = function(info)
local color = Bartender4.db.profile.Colors[info[#info]]
return color.r, color.g, color.b
end,
set = function(info, r, g, b)
local color = Bartender4.db.profile.Colors[info[#info]]
color.r, color.g, color.b = r, g, b
BT4ActionBars:ForAllButtons("UpdateUsable")
end,
args = {
range = {
order = 1,
type = "color",
name = "Out of Range Indicator",
desc = "Specify the Color of the Out of Range Indicator",
},
mana = {
order = 2,
type = "color",
name = "Out of Mana Indicator",
desc = "Specify the Color of the Out of Mana Indicator",
},
},
},
},
}
Bartender4:RegisterModuleOptions("actionbars", self.options)
end
-- Creates a new bar object based on the id and the specified config
function BT4ActionBars:Create(id, config)
@@ -79,73 +160,3 @@ function BT4ActionBars:Create(id, config)
return bar
end
--[[
Bar Prototype Functions
]]
-- Apply the specified config to the bar and refresh all settings
function ActionBar:ApplyConfig(config)
Bar.ApplyConfig(self, config)
config = self.config
if not config.Position then initialPosition(self) end
self:UpdateButtons(config.Buttons)
end
-- Update the number of buttons in our bar, creating new ones if necessary
function ActionBar:UpdateButtons(numbuttons)
if numbuttons then
self.config.Buttons = numbuttons
else
numbuttons = self.config.Buttons
end
local buttons = self.buttons or {}
-- create more buttons if needed
for i = (#buttons+1), numbuttons do
buttons[i] = Bartender4.Button:Create(i, self)
end
-- show active buttons
for i = 1, numbuttons do
buttons[i]:Show()
end
-- hide inactive buttons
for i = (numbuttons + 1), #buttons do
buttons[i]:Hide()
end
self.buttons = buttons
self:UpdateButtonLayout()
end
-- align the buttons and correct the size of the bar overlay frame
function ActionBar:UpdateButtonLayout()
local numbuttons = self.config.Buttons
local buttons = self.buttons
local pad = self.config.Padding
local Rows = self.config.Rows
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
self:SetSize((36 + pad) * ButtonPerRow - pad + 8, (36 + pad) * Rows - pad + 8)
-- anchor button 1 to the topleft corner of the bar
buttons[1]:ClearSetPoint("TOPLEFT", self, "TOPLEFT", 6, -3)
-- and anchor all other buttons relative to our button 1
for i = 2, numbuttons do
-- jump into a new row
if ((i-1) % ButtonPerRow) == 0 then
buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-ButtonPerRow], "BOTTOMLEFT", 0, -pad)
-- align to the previous button
else
buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-1], "TOPRIGHT", pad, 0)
end
end
end
+17 -7
View File
@@ -2,19 +2,21 @@
local AceAddon = LibStub("AceAddon-3.0")
Bartender4 = AceAddon:NewAddon("Bartender4", "AceConsole-3.0", "AceEvent-3.0")
local defaults = {
profile = {
OutOfRange = "button",
Colors = { range = { r = 0.8, g = 0.1, b = 0.1 }, mana = { r = 0.5, g = 0.5, b = 1.0 } },
}
}
function Bartender4:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("Bartender4DB")
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateModuleConfigs")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateModuleConfigs")
self:SetupOptions()
end
local defaults = {
profile = {
OutOfRange = "button",
Colors = { OutOfRange = { r = 0.8, g = 0.1, b = 0.1 }, OutOfMana = { r = 0.5, g = 0.5, b = 1.0 } },
}
}
function Bartender4:RegisterDefaultsKey(key, subdefaults)
defaults.profile[key] = subdefaults
@@ -28,3 +30,11 @@ function Bartender4:UpdateModuleConfigs()
end
end
end
function Bartender4:Update()
for k,v in AceAddon:IterateModulesOfAddon("Bartender4") do
if type(v.Update) == "function" then
v:Update()
end
end
end
+2
View File
@@ -13,10 +13,12 @@ embeds.xml
## Core ##
Bartender4.lua
Options.lua
## Prototypes ##
Bar.lua
Button.lua
ActionBarPrototype.lua
## Modules ##
ActionBars.lua
+52 -48
View File
@@ -7,9 +7,7 @@
local Button = CreateFrame("CheckButton")
local Button_MT = {__index = Button}
local function onLeave()
GameTooltip:Hide()
end
local onLeave, onUpdate
Bartender4.Button = {}
Bartender4.Button.prototype = Button
@@ -20,7 +18,7 @@ function Bartender4.Button:Create(id, parent)
button.parent = parent
button:SetScript("OnEvent", button.EventHandler)
button:SetScript("OnUpdate", button.OnUpdate)
button:SetScript("OnUpdate", onUpdate)
button:SetScript("OnEnter", button.SetTooltip)
button:SetScript("OnLeave", onLeave)
button:SetScript("OnAttributeChanged", button.UpdateAction)
@@ -36,6 +34,7 @@ function Bartender4.Button:Create(id, parent)
button.flash = _G[("%sFlash"):format(name)]
button.flash:Hide()
button:SetNormalTexture("")
local realNormalTexture = _G[("%sNormalTexture"):format(name)]
realNormalTexture:Hide()
@@ -72,13 +71,56 @@ function Bartender4.Button:Create(id, parent)
return button
end
function onLeave()
GameTooltip:Hide()
end
function onUpdate(self, elapsed)
if not self.iconTex then self:UpdateIcon() end
if ( self.flashing == 1 ) then
self.flashtime = self.flashtime - elapsed;
if ( self.flashtime <= 0 ) then
local overtime = -self.flashtime;
if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then
overtime = 0;
end
self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
local flashTexture = self.flash
if ( flashTexture:IsVisible() ) then
flashTexture:Hide()
else
flashTexture:Show()
end
end
end
if ( self.rangeTimer ) then
self.rangeTimer = self.rangeTimer - elapsed
if ( self.rangeTimer <= 0 ) then
local valid = IsActionInRange(self.action)
local hotkey = self.hotkey
local hkshown = (hotkey:GetText() == RANGE_INDICATOR and Bartender4.db.profile.OutOfRange == "hotkey")
if valid and hkshown then
hotkey:Show()
elseif hkshown then
hotkey:Hide()
end
self.outOfRange = (valid == 0)
self:UpdateUsable()
self.rangeTimer = TOOLTIP_UPDATE_TIME
end
end
end
function Button:CalculateAction()
return SecureButton_GetModifiedAttribute(self, "action", SecureButton_GetEffectiveButton(self)) or 1
end
function Button:UpdateAction()
function Button:UpdateAction(force)
local action = self:CalculateAction()
if action ~= self.action then
if action ~= self.action or force then
self.action = action
self:Update()
end
@@ -91,13 +133,14 @@ function Button:Update()
self:UpdateHotkeys()
if ( HasAction(action) ) then
self:RegisterActionEvents()
self:UpdateState()
self:UpdateUsable()
self:UpdateCooldown()
self:UpdateFlash()
self:ShowButton()
self:SetScript("OnUpdate", self.OnUpdate)
self:SetScript("OnUpdate", onUpdate)
else
self:UnregisterActionEvents()
@@ -123,7 +166,7 @@ function Button:Update()
if self.parent.config.HideMacrotext then
self.macroName:SetText("")
else
self.macroName:SetText(GetActionText(self.action))
self.macroName:SetText(GetActionText(action))
end
end
@@ -173,7 +216,7 @@ end
function Button:UpdateUsable()
local oor = Bartender4.db.profile.OutOfRange
local isUsable, notEnoughMana = IsUsableAction(self.action)
local oorcolor, oomcolor = Bartender4.db.profile.Colors.OutOfRange, Bartender4.db.profile.Colors.OutOfMana
local oorcolor, oomcolor = Bartender4.db.profile.Colors.range, Bartender4.db.profile.Colors.mana
if ( oor ~= "button" or not self.outOfRange) then
if ( oor == "none" or not self.outOfRange) then
self.hotkey:SetVertexColor(1.0, 1.0, 1.0)
@@ -220,45 +263,6 @@ function Button:StopFlash()
self:UpdateState()
end
function Button:OnUpdate(elapsed)
--if not self.frame.tex then self:UpdateIcon() end
if ( self.flashing == 1 ) then
self.flashtime = self.flashtime - elapsed;
if ( self.flashtime <= 0 ) then
local overtime = -self.flashtime;
if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then
overtime = 0;
end
self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
local flashTexture = self.flash
if ( flashTexture:IsVisible() ) then
flashTexture:Hide()
else
flashTexture:Show()
end
end
end
if ( self.rangeTimer ) then
self.rangeTimer = self.rangeTimer - elapsed
if ( self.rangeTimer <= 0 ) then
local valid = IsActionInRange(self.action)
local hotkey = self.hotkey
local hkshown = (hotkey:GetText() == RANGE_INDICATOR and Bartender4.db.profile.OutOfRange == "hotkey")
if valid and hkshown then
hotkey:Show()
elseif hkshown then
hotkey:Hide()
end
self.outOfRange = (valid == 0)
self:UpdateUsable()
self.rangeTimer = TOOLTIP_UPDATE_TIME
end
end
end
function Button:SetTooltip()
if ( GetCVar("UberTooltips") == "1" ) then
GameTooltip_SetDefaultAnchor(GameTooltip, self)
+45
View File
@@ -0,0 +1,45 @@
--[[ $Id$ ]]
local getFunc, setFunc
do
function getFunc(info)
return (info.arg and Bartender4.db.profile[info.arg] or Bartender4.db.profile[info[#info]])
end
function setFunc(info, value)
local key = info.arg or info[#info]
Bartender4.db.profile[key] = value
end
end
function Bartender4:SetupOptions()
self.options = {
type = "group",
name = "Bartender4",
icon = "Interface\\Icons\\INV_Drink_05",
childGroups = "tree",
args = {
gui = {
type = "execute",
name = "gui",
order = 1,
desc = "Open GUI",
func = function() LibStub("AceConfigDialog-3.0"):Open("Bartender4") end,
guiHidden = true,
},
general = {
type = "group",
--cmdInline = true,
name = "General Settings",
get = getFunc,
set = setFunc,
args = {},
},
},
}
LibStub("AceConfig-3.0"):RegisterOptionsTable("Bartender4", self.options, "bar")
end
function Bartender4:RegisterModuleOptions(key, table)
self.options.args[key] = table
end