Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issues with menu bar display

  • Loading branch information...
commit cdd9f4930a8f619a8a6d2ff67c59581f1e87760d 1 parent a4783d6
@Tuller Tuller authored
Showing with 143 additions and 270 deletions.
  1. +1 −1  Dominos.toc
  2. +142 −269 menuBar.lua
View
2  Dominos.toc
@@ -2,7 +2,7 @@
## Title: Dominos
## Notes: A main actionbar replacement
## Author: Tuller
-## Version: 5.0.25
+## Version: 5.0.27
## SavedVariables: DominosDB, DominosVersion
## OptionalDeps: Ace3, LibKeyBound-1.0, Masque, FlyPaper
embeds.xml
View
411 menuBar.lua
@@ -29,8 +29,8 @@ local MICRO_BUTTON_NAMES = {
function MenuBar:New()
local bar = MenuBar.super.New(self, 'menu')
- bar:Layout(true)
- bar:UpdateClickThrough()
+ bar:LoadButtons()
+ bar:Layout()
return bar
end
@@ -38,228 +38,68 @@ end
function MenuBar:Create(frameId)
local bar = MenuBar.super.Create(self, frameId)
- local header = bar.header
+ bar.buttons = {}
+ bar.activeButtons = {}
-
- --[[ init any bar global variables ]]--
-
- header:Execute([[
- SPACING_OFFSET = -2
- PADW_OFFSET = 0
- PADH_OFFSET = 0
- HEIGHT_OFFSET = 22
- WIDTH_OFFSET = 0
-
- myButtons = table.new()
- disabledButtons = table.new()
- activeButtons = table.new()
- ]])
-
- --[[
- after a layout value is altered, set a dirty bit indicating that we need to adjust the bar's layout
- --]]
+ local header = bar.header
header:SetAttribute('_onstate-petbattleui', [[
self:RunAttribute('updateShown')
- self:RunAttribute('updateLayout')
+ self:CallMethod('Layout')
]])
header:SetAttribute('_onstate-overrideui', [[
self:RunAttribute('updateShown')
- self:RunAttribute('updateLayout')
- ]])
-
- header:SetAttribute('_onstate-forcelayout', [[ self:RunAttribute('updateLayout') ]])
-
- header:SetAttribute('_onstate-columns', [[ needsLayout = true ]])
-
- header:SetAttribute('_onstate-spacing', [[ needsLayout = true ]])
-
- header:SetAttribute('_onstate-padW', [[ needsLayout = true ]])
-
- header:SetAttribute('_onstate-padH', [[ needsLayout = true ]])
-
- header:SetAttribute('_onstate-topToBottom', [[ needsLayout = true ]])
-
- header:SetAttribute('_onstate-leftToRight', [[ needsLayout = true ]])
-
- header:SetAttribute('_onstate-disableButton', [[
- local button = self:GetFrameRef('buttonToDisable')
- local disable = newstate
-
- if disabledButtons[button] ~= disable then
- disabledButtons[button] = disable
- needsLayout = true
- end
- ]])
-
- --add button method
- header:SetAttribute('addButton', [[
- local button = self:GetFrameRef('addButton')
-
- if button then
- table.insert(myButtons, button)
- button:SetParent(self:GetFrameRef('buttonFrame') or self)
- end
- ]])
-
- header:SetAttribute('updateActiveButtons', [[
- table.wipe(activeButtons)
-
- for i, button in ipairs(myButtons) do
- if not disabledButtons[button] then
- table.insert(activeButtons, button)
- end
- end
-
- self:SetAttribute('maxLength', #activeButtons)
- ]])
-
- header:SetAttribute('updateLayout', [[
- local layoutState
- if self:GetAttribute('state-petbattleui') then
- layoutState = 'petbattleui'
- elseif self:GetAttribute('state-overrideui') then
- layoutState = 'overrideui'
- else
- layoutState = 'standard'
- end
-
- needsLayout = true
- self:RunAttribute('layout-' .. layoutState)
+ self:CallMethod('Layout')
]])
- header:SetAttribute('layout-petbattleui', [[
- local numButtons = #myButtons
- local cols = ceil(numButtons / 2)
-
- local b = myButtons[1]
- local w = b:GetWidth() - (WIDTH_OFFSET)
- local h = b:GetHeight() - (HEIGHT_OFFSET + 2)
-
- for i, b in pairs(myButtons) do
- local col = (i-1) % cols
- local row = ceil(i / cols) - 1
-
- local b = myButtons[i]
- b:ClearAllPoints()
- b:SetPoint('TOPLEFT', '$parent', 'TOPLEFT', -16 + w*col + WIDTH_OFFSET, 6 -(h*row) + HEIGHT_OFFSET)
- b:Show()
- end
- ]])
+ hooksecurefunc('UpdateMicroButtons', function() bar:Layout() end)
- header:SetAttribute('layout-overrideui', [[
- for i, button in pairs(myButtons) do
- if not(i == 1 or i == floor(#myButtons / 2) + 1) then
- button:ClearAllPoints()
- button:SetPoint('BOTTOMLEFT', self:GetFrameRef(myButtons[i - 1]:GetName() .. 'Overlay'), 'BOTTOMRIGHT', -3, 0)
- button:Show()
- end
- end
- ]])
+ header.Layout = function() bar:Layout() end
- header:SetAttribute('layout-standard', [[
- if not needsLayout then return end
-
- self:RunAttribute('updateActiveButtons')
-
- local numButtons = #activeButtons
- if numButtons == 0 then
- self:GetParent():SetWidth(36)
- self:GetParent():SetHeight(36)
- return
- end
-
- local cols = min(self:GetAttribute('state-columns') or numButtons, numButtons)
- local rows = ceil(numButtons / cols)
-
- local pW, pH = self:GetAttribute('state-padW') or 0, self:GetAttribute('state-padH') or 0
- local spacing = self:GetAttribute('state-spacing') or 0
-
- local isLeftToRight = self:GetAttribute('state-leftToRight')
- local isTopToBottom = self:GetAttribute('state-topToBottom')
-
- local firstButton = myButtons[1]
- local w = firstButton:GetWidth() + spacing - WIDTH_OFFSET
- local h = firstButton:GetHeight() + spacing - HEIGHT_OFFSET
-
- for i = 1, #myButtons do
- myButtons[i]:Hide()
- end
-
- for i, button in pairs(activeButtons) do
- local col, row
-
- if isLeftToRight then
- col = (i-1) % cols
- else
- col = (cols-1) - (i-1) % cols
- end
-
- if isTopToBottom then
- row = ceil(i / cols) - 1
- else
- row = rows - ceil(i / cols)
- end
-
- button:SetParent(self)
- button:ClearAllPoints()
- button:SetPoint('TOPLEFT', '$parent', 'TOPLEFT', w*col + pW, -(h*row + pH) + HEIGHT_OFFSET)
- button:Show()
- end
+ return bar
+end
- self:GetParent():SetWidth(max(w*cols - spacing + pW*2 + WIDTH_OFFSET, 8))
- self:GetParent():SetHeight(max(h*ceil(numButtons / cols) - spacing + pH*2, 8))
-
- needsLayout = nil
- ]])
-
+function MenuBar:LoadButtons()
for i, buttonName in ipairs(MICRO_BUTTONS) do
- bar:AddButton(bar:MakeSecure(_G[buttonName]))
+ self:AddButton(i)
end
- hooksecurefunc('UpdateMicroButtons', function()
- if not InCombatLockdown() then
- bar.header:Execute([[ self:RunAttribute('updateLayout') ]])
- end
- end)
-
- return bar
+ self:UpdateClickThrough()
end
-
---wrap a frame in a secure one for placement/etc
---necesary to reference frames from secure code
-function MenuBar:MakeSecure(frame)
- local overlay = CreateFrame('Frame', nil, frame, 'SecureFrameTemplate')
- overlay:SetAllPoints(frame)
- frame.overlay = overlay
+function MenuBar:AddButton(i)
+ local buttonName = MICRO_BUTTONS[i]
+ local button = _G[buttonName]
- return frame;
+ button:SetParent(self.header)
+ button:Show()
+
+ self.buttons[i] = button
+end
+
+function MenuBar:RemoveButton(i)
+ local button = self.buttons[i]
+ if button then
+ button:SetParent(nil)
+ button:Hide()
+ self.buttons[i] = nil
+ end
end
function MenuBar:LoadSettings(...)
MenuBar.super.LoadSettings(self, ...)
- local header = self.header
+ self.activeButtons = {}
+ self:UpdateDisabledButtons()
+end
- header:SetAttribute('state-columns', self:NumColumns())
- header:SetAttribute('state-spacing', self:GetSpacing())
- header:SetAttribute('state-leftToRight', self:GetLeftToRight())
- header:SetAttribute('state-topToBottom', self:GetTopToBottom())
-
- local pw, ph = self:GetPadding()
- header:SetAttribute('state-padW', pw)
- header:SetAttribute('state-padH', ph)
-
+function MenuBar:UpdateDisabledButtons()
local disabledButtons = self.sets.disabled
- if disabledButtons then
- for buttonName, disabled in pairs(disabledButtons) do
- local button = _G[buttonName]
- if button then
- self:DisableMenuButton(button, disabled)
- end
- end
+ if not disabledButtons then return end
+
+ for buttonName, isDisabled in pairs(disabledButtons) do
+ self:DisableMenuButton(_G[buttonName], isDisabled)
end
end
@@ -271,106 +111,139 @@ function MenuBar:GetDefaults()
}
end
-function MenuBar:MaxLength()
- return self.header:GetAttribute('maxLength')
+function MenuBar:NumButtons()
+ return #self.activeButtons
end
-function MenuBar:AddButton(button)
- self.header:SetFrameRef('addButton', button)
- self.header:SetFrameRef(button:GetName() .. 'Overlay', button.overlay)
- self.header:Execute([[ self:RunAttribute('addButton') ]])
-end
+function MenuBar:DisableMenuButton(button, disabled)
+ local disabledButtons = self.sets.disabled or {}
-function MenuBar:NumButtons()
- return self:MaxLength()
+ disabledButtons[button:GetName()] = disabled or false
+ self.sets.disabled = disabledButtons
+
+ self:Layout()
end
-function MenuBar:SetColumns(columns)
- self.sets.columns = columns ~= self:NumButtons() and columns or false
+function MenuBar:IsMenuButtonDisabled(button)
+ local disabledButtons = self.sets.disabled
+
+ if disabledButtons then
+ return disabledButtons[button:GetName()]
+ end
- self.header:SetAttribute('state-columns', self.sets.columns) --here, false implies (use whatever the maximum value would be)
- self:Layout()
+ return false
end
-function MenuBar:SetSpacing(spacing)
- self.sets.spacing = spacing or 0
+function MenuBar:Layout()
+ if self.header:GetAttribute('state-petbattleui') then
+ self:LayoutPetBattle()
+ return
+ end
- self.header:SetAttribute('state-spacing', self.sets.spacing)
- self:Layout()
+ if self.header:GetAttribute('state-overrideui') then
+ self:LayoutOverrideUI()
+ return
+ end
+
+ self:LayoutNormal()
end
-function MenuBar:SetLeftToRight(isLeftToRight)
- local isRightToLeft = not isLeftToRight
+function MenuBar:LayoutNormal()
+ self:UpdateActiveButtons()
+
+ for i, button in pairs(self.buttons) do
+ button:Hide()
+ end
+
+ local numButtons = #self.activeButtons
+ if numButtons == 0 then
+ self:SetSize(36, 36)
+ return
+ end
+
+ local cols = min(self:NumColumns(), numButtons)
+ local rows = ceil(numButtons / cols)
- self.sets.isRightToLeft = isRightToLeft
- self.header:SetAttribute('state-leftToRight', isLeftToRight and true or false)
- self:Layout()
-end
+ local pW, pH = self:GetPadding()
+ local spacing = self:GetSpacing()
-function MenuBar:SetTopToBottom(isTopToBottom)
- local isBottomToTop = not isTopToBottom
+ local isLeftToRight = self:GetLeftToRight()
+ local isTopToBottom = self:GetTopToBottom()
- self.sets.isBottomToTop = isBottomToTop
- self.header:SetAttribute('state-topToBottom', isTopToBottom and true or false)
- self:Layout()
-end
+ local firstButton = self.buttons[1]
+ local w = firstButton:GetWidth() + spacing - WIDTH_OFFSET
+ local h = firstButton:GetHeight() + spacing - HEIGHT_OFFSET
-function MenuBar:SetPadding(padW, padH)
- local padW = padW or 0
- local padH = padH or padW
-
- self.sets.padW = padW
- self.sets.padH = padH
+ for i, button in pairs(self.activeButtons) do
+ local col, row
+
+ if isLeftToRight then
+ col = (i-1) % cols
+ else
+ col = (cols-1) - (i-1) % cols
+ end
- self.header:SetAttribute('state-padW', self.sets.padW)
- self.header:SetAttribute('state-padH', self.sets.padH)
- self:Layout()
-end
+ if isTopToBottom then
+ row = ceil(i / cols) - 1
+ else
+ row = rows - ceil(i / cols)
+ end
+
+ button:SetParent(self.header)
+ button:ClearAllPoints()
+ button:SetPoint('TOPLEFT', w*col + pW, -(h*row + pH) + HEIGHT_OFFSET)
+ button:Show()
+ end
-function MenuBar:UpdateClickThrough()
- local clickThrough = self:GetClickThrough()
- if clickThrough then
- self.header:Execute([[
- for i, button in ipairs(myButtons) do
- button:EnableMouse(false)
- end
- ]])
- else
- self.header:Execute([[
- for i, button in ipairs(myButtons) do
- button:EnableMouse(true)
- end
- ]])
+ -- Update bar size, if we're not in combat
+ -- TODO: manage bar size via secure code
+ if not InCombatLockdown() then
+ local newWidth = max(w*cols - spacing + pW*2 + WIDTH_OFFSET, 8)
+ local newHeight = max(h*ceil(numButtons / cols) - spacing + pH*2, 8)
+ self:SetSize(newWidth, newHeight)
end
end
-function MenuBar:DisableMenuButton(button, disabled)
- local disabledButtons = self.sets.disabled or {}
-
- disabledButtons[button:GetName()] = disabled or false
- self.header:SetFrameRef('buttonToDisable', button)
- self.header:SetAttribute('state-disableButton', disabled)
- self:Layout()
+function MenuBar:LayoutPetBattle()
+ local parentFrame = _G['PetBattleFrame'].BottomFrame.MicroButtonFrame
+ local anchorX, anchorY = -10, 27
- self.sets.disabled = disabledButtons
+ UpdateMicroButtonsParent(parentFrame)
+ MoveMicroButtons("BOTTOMLEFT", parentFrame, "BOTTOMLEFT", anchorX, anchorY, true)
+
+ self:FixButtonPositions()
end
-function MenuBar:IsMenuButtonDisabled(button)
- local disabledButtons = self.sets.disabled
+function MenuBar:LayoutOverrideUI()
+ local parentFrame = _G['OverrideActionBar']
+ local anchorX, anchorY = OverrideActionBar_GetMicroButtonAnchor()
- if disabledButtons then
- return disabledButtons[button:GetName()]
- end
+ UpdateMicroButtonsParent(parentFrame)
+ MoveMicroButtons("BOTTOMLEFT", parentFrame, "BOTTOMLEFT", anchorX, anchorY, true)
- return false
+ self:FixButtonPositions()
end
-function MenuBar:Layout(force)
- if force then
- self.header:Execute([[ needsLayout = true ]])
+function MenuBar:FixButtonPositions()
+ local myButtons = self.buttons
+
+ for i, button in pairs(myButtons) do
+ if not(i == 1 or i == floor(#myButtons / 2) + 1) then
+ button:ClearAllPoints()
+ button:SetPoint('BOTTOMLEFT', myButtons[i - 1], 'BOTTOMRIGHT', -3, 0)
+ end
+ button:Show()
end
+end
+
+function MenuBar:UpdateActiveButtons()
+ for i = 1, #self.activeButtons do self.activeButtons[i] = nil end
- self.header:Execute([[ self:RunAttribute('updateLayout') ]])
+ for i, button in ipairs(self.buttons) do
+ if not self:IsMenuButtonDisabled(button) then
+ table.insert(self.activeButtons, button)
+ end
+ end
end
--[[ Menu Code ]]--
Please sign in to comment.
Something went wrong with that request. Please try again.