local function createLabel(ownerFrame, fontObject)
assert (ownerFrame ~= nil)
local t = ownerFrame:CreateFontString((ownerFrame:GetName() or '') .. 'Text', 'OVERLAY')
fontObject = fontObject or NumberFont_OutlineThick_Mono_Small
assert (fontObject ~= nil)
t:SetFontObject(fontObject)
t:SetAllPoints()
return t
end
local function createBackground(ownerFrame)
assert (ownerFrame ~= nil)
local background = ownerFrame:CreateTexture(ownerFrame:GetName() .. 'Background', 'BACKGROUND')
background:SetAllPoints()
background:SetTexture(0, 0, 0, 0.8)
return background
end
local function createUnitButton(parentFrame, frameName, unit)
assert (parentFrame ~= nil)
assert (frameName ~= nil)
assert (unit ~= nil)
local u = CreateFrame('BUTTON', frameName, parentFrame, 'SecureUnitButtonTemplate')
u:SetAttribute('type', 'target')
u:SetAttribute('unit', unit)
u:SetSize(12 * 6, 12 * 2)
u.text = createLabel(u)
local b = createBackground(u)
b:SetTexture(1.0, 0.0, 0.4, 1.0)
u.background = b
u:SetScript('OnEvent', function(self)
assert (self ~= nil)
local label = self.text
assert (label ~= nil)
local unitDesignation = self:GetAttribute('unit')
assert (unitDesignation ~= nil)
label:SetText(UnitName(unitDesignation) or unitDesignation)
end)
u:RegisterEvent('PARTY_CONVERTED_TO_RAID')
u:RegisterEvent('PARTY_MEMBERS_CHANGED')
u:RegisterEvent('PLAYER_ALIVE')
u:RegisterEvent('RAID_ROSTER_UPDATE')
u:RegisterEvent('UPDATE_BATTLEFIELD_SCORE')
u:RegisterEvent('ADDON_LOADED')
assert (u ~= nil)
return u
end
local function createSpoiler(spoilerParent, spoilerDesignation)
local spoiler = CreateFrame('BUTTON', spoilerDesignation, spoilerParent, 'SecureHandlerClickTemplate')
spoiler:EnableMouse(true)
spoiler:SetAttribute('_onclick', [=[
local debugFlag = true
local parentFrame = self:GetParent()
local siblingTable = parentFrame:GetChildList(newtable())
local i = 0
while (i < #siblingTable) do
i = i + 1
local sibling = siblingTable[i]
sibling:ClearBindings()
sibling:Hide()
end
self:Show()
local j = 0
local childTable = self:GetChildList(newtable())
--[[local bindingTable = newtable(
'A', 'S', 'D', 'F', 'G'
)]]--
while (j < #childTable) do
j = j + 1
local child = childTable[j]
local unitDesignation = child:GetAttribute('unit')
if unitDesignation ~= nil and UnitExists(unitDesignation) and not debugFlag then
child:Show()
elseif debugFlag then
child:Show()
else
child:Hide()
end
print('child', child:GetName())
local key = GetBindingKey('CLICK ChoirUnitButton' .. tostring(j) .. ':LeftButton')
--local key = bindingTable[math.min(j, #childTable)]
if key then
self:SetBindingClick(true, key, child)
end
end
]=])
return spoiler
end
local function createGroup(rootFrame, groupNumber, unitTable)
assert (rootFrame ~= nil)
assert (groupNumber ~= nil)
groupNumber = math.floor(math.abs(groupNumber))
assert ((groupNumber >= 1 and groupNumber <= 8) or unitTable ~= nil)
local groupSize = 5
local u
if unitTable then
u = unitTable
else
local q = 0
u = {}
while (q < groupSize) do
q = q + 1
u[q] = 'raid' .. tostring((groupNumber - 1) * groupSize + q)
end
end
assert (u ~= nil)
assert ('table' == type(u))
assert (#u == groupSize)
local spoiler = createSpoiler(rootFrame, 'ChoirSpoiler' .. tostring(groupNumber))
spoiler:SetSize(12 * 6, 12 * 2)
spoiler:SetPoint('CENTER', 0, 144)
local i = 0
local marginLeft = spoiler:GetWidth()
local padding = 4
while (i < #u) do
i = i + 1
local unitDesignation = u[i]
assert (unitDesignation ~= nil)
local memberNumber = (groupNumber - 1) * groupSize + i
local b = createUnitButton(spoiler, 'ChoirUnitButton' .. tostring(memberNumber), unitDesignation)
b:SetPoint('BOTTOMLEFT', marginLeft + padding, 0)
marginLeft = marginLeft + b:GetWidth() + padding
spoiler:WrapScript(b, 'OnClick', [=[
print('OnClick', self:GetName())
local parentFrame = self:GetParent()
parentFrame:Hide()
]=])
b:Hide()
_G['BINDING_NAME_CLICK ' .. b:GetName() .. ':LeftButton'] = 'Unit ' .. tostring(i)
end
_G['BINDING_NAME_CLICK ' .. spoiler:GetName() .. ':LeftButton'] = 'Group ' .. tostring(groupNumber)
return spoiler
end
local function init(rootFrame)
assert (rootFrame ~= nil)
rootFrame:UnregisterAllEvents()
rootFrame:SetSize(1024, 768)
rootFrame:SetPoint('CENTER', 0, 0)
createGroup(rootFrame, 1)
createGroup(rootFrame, 2)
createGroup(rootFrame, 3)
createGroup(rootFrame, 4)
createGroup(rootFrame, 5)
createGroup(rootFrame, 6)
createGroup(rootFrame, 7)
createGroup(rootFrame, 8)
--[[ TODO Add Esc key that closes the spoiler without clicking any of the children buttons ]]--
--[[ TODO Generalize the interface to be used with any kind of child frames, especially nested spoilers and spell buttons ]]--
local spoilerParty = createGroup(rootFrame, 9, {'player', 'party1', 'party2', 'party3', 'party4'})
_G['BINDING_NAME_CLICK ' .. spoilerParty:GetName() .. ':LeftButton'] = 'Player party'
BINDING_HEADER_CHOIR = 'Choir'
print('[Choir]: init')
end
local function main()
local rootFrame = CreateFrame('FRAME', 'ChoirFrame', UIParent)
rootFrame:RegisterEvent('ADDON_LOADED')
rootFrame:SetScript('OnEvent', init)
end
main()