Skip to content

Instantly share code, notes, and snippets.

@Industrial
Created May 9, 2016 16:53
Show Gist options
  • Save Industrial/373bc5ac54da5c11f7834cf5b689b586 to your computer and use it in GitHub Desktop.
Save Industrial/373bc5ac54da5c11f7834cf5b689b586 to your computer and use it in GitHub Desktop.
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'
local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT'
local idTweaks = LibStub('AceAddon-3.0'):GetAddon('idTweaks')
local LibActionButton = LibStub('LibActionButton-1.0')
local ActionButtonsModule = idTweaks:NewModule('ActionButtons', 'AceConsole-3.0', 'AceEvent-3.0')
ActionButtonsModule.bars = {}
function ActionButtonsModule:setDefaults()
self:Print('ActionButtonsModule:setDefaults()')
self.defaults = {
profile = {
}
}
end
function ActionButtonsModule:setDatabase()
self:Print('ActionButtonsModule:setDatabase()')
self.db = idTweaks.db:RegisterNamespace('ActionButtons', self.defaults)
end
function ActionButtonsModule:setOptions()
self:Print('ActionButtonsModule:setOptions()')
self.options = {
name = 'ActionButtons',
handler = self,
type = 'group',
args = {
},
}
end
function ActionButtonsModule:registerOptions()
self:Print('ActionButtonsModule:registerOptions()')
LibStub('AceConfig-3.0'):RegisterOptionsTable('ActionButtons', self.options)
LibStub('AceConfigDialog-3.0'):AddToBlizOptions('ActionButtons', 'ActionButtons', 'idTweaks')
end
function ActionButtonsModule:OnInitialize()
self:Print('ActionButtonsModule:OnInitialize()')
self:setDefaults()
self:setDatabase()
self:setOptions()
end
function ActionButtonsModule:OnEnable()
self:Print('ActionButtonsModule:OnEnable()')
self:registerOptions()
self:createBars()
self:positionBars()
end
function ActionButtonsModule:OnDisable()
self:Print('ActionButtonsModule:OnDisable()')
end
function ActionButtonsModule:createActionBarButton(frame, i)
self:Print('ActionButtonsModule:createActionBarButton('..i..')')
local options = {
showGrid = false,
clickOnDown = false,
clickBoundTarget = false,
outOfRangeColoring = 'button',
colors = {
range = { 0.8, 0.1, 0.1 },
mana = { 0.8, 0.1, 0.1 }
},
hideElements = {
macro = false,
hotkey = false,
equipped = false
},
tooltip = 'enabled',
flyoutDirection = 'UP'
}
local button = LibActionButton:CreateButton(i, 'action', frame.header, options)
button:Show()
button:SetState(1, 'action', i)
frame.buttons[i] = button
return button
end
function ActionButtonsModule:createActionBar(barName, from, to)
self:Print('ActionButtonsModule:createActionBar()')
local frame = CreateFrame('Frame', 'idTweaks_ActionBar_'..barName, UIParent)
frame.header = CreateFrame('Frame', 'idTweaks_ActionBar_'..barName..'_header', frame, 'SecureHandlerStateTemplate')
frame.buttons = {}
-- TODO; Give the frame a black see-through backdrop.
local lastButton
for i=from,to do
local button = self:createActionBarButton(frame, i)
if i == 1 then
button:SetPoint(TL, frame, TL, 3, -3)
else
button:SetPoint(ML, lastButton, MR, 3, 0)
end
lastButton = button
end
frame:SetWidth(lastButton:GetWidth() * 12 + 3 * 2)
frame:SetHeight(lastButton:GetHeight() + 3 * 2)
return frame
end
function ActionButtonsModule:createBars()
self:Print('ActionButtonsModule:createBars()')
self.bars.bar1 = self:createActionBar('bar1', 1, 12)
self.bars.bar2 = self:createActionBar('bar2', 13, 25)
self.bars.bar3 = self:createActionBar('bar3', 26, 38)
self.bars.bar4 = self:createActionBar('bar4', 39, 50)
end
function ActionButtonsModule:positionBars()
self:Print('ActionButtonsModule:positionBars()')
self.bars.bar1:SetPoint(MC, UIParent, MC)
self.bars.bar2:SetPoint(BL, self.bars.bar1, TL)
self.bars.bar3:SetPoint(BL, self.bars.bar2, TL)
self.bars.bar4:SetPoint(BL, self.bars.bar3, TL)
end
idTweaks.ActionButtons = ActionButtonsModule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment