local grpHeader = CreateFrame("Frame", "MyGrpHeader", UIParent, "SecureGroupHeaderTemplate")
grpHeader:SetAttribute("showRaid", true)
--grpHeader:SetAttribute("useparent-unit", true)
grpHeader:SetAttribute("strictFiltering", nil)
grpHeader:SetAttribute("startingIndex", 1)
grpHeader:SetAttribute("maxColumns", 8)
grpHeader:SetAttribute("unitsPerColumn", 5)
grpHeader:SetAttribute("sortMethod", nil)
--grpHeader:SetAttribute("sortMethod", "NAME")
--grpHeader:SetAttribute("minWidth", 50)
--grpHeader:SetAttribute("minHeight", 25)
grpHeader:SetAttribute("minWidth", 0)
grpHeader:SetAttribute("minHeight", 0)
grpHeader:SetAttribute("xOffset", 0)
grpHeader:SetAttribute("yOffset", 0)
grpHeader:SetAttribute("point", "TOP")
grpHeader:SetAttribute("columnSpacing", 1)
grpHeader:SetAttribute("columnAnchorPoint", "LEFT")
--grpHeader:SetAttribute("groupBy", "ASSIGNEDROLE")
--grpHeader:SetAttribute("groupingOrder", "TANK,HEALER,DAMAGER,NONE")
grpHeader:SetAttribute("groupBy", "GROUP")
grpHeader:SetAttribute("groupingOrder", "1,2,3,4,5,6,7,8")
--grpHeader:SetAttribute("groupBy", nil)
--grpHeader:SetAttribute("groupingOrder", nil)
grpHeader:SetAttribute("groupFilter", nil)
grpHeader:SetAttribute("template", "SecureHandlerAttributeTemplate")
grpHeader:SetAttribute("initial-unitWatch", true)
grpHeader:SetAttribute("style-width", 68)
grpHeader:SetAttribute("style-height", 41)
grpHeader:SetAttribute("style-scale", 1)
-- Some helper methods
function grpHeader:Execute(body) return SecureHandlerExecute(self, body) end
function grpHeader:WrapScript(frame, script, preBody, postBody) return SecureHandlerWrapScript(frame, script, self, preBody, postBody) end
function grpHeader:SetFrameRef(label, refFrame) return SecureHandlerSetFrameRef(self, label, refFrame) end
-- Init the header
grpHeader:Execute[=[
Manager = self -- Register self to avoid some bugs
UnitFrames = newtable() -- Our own unit buttons, may be your secure frames
ShadowFrames = newtable()-- The auto-generated unit buttons
-- The snippet for auto-generated unit buttons's unit changed event
-- This is only used when you entering the game world during a combat
refreshUnitChange = [[
local unit = self:GetAttribute("unit")
local frame = self:GetAttribute("UnitFrame")
-- Here you can handle the thing like moving, refreshing and etc
-- I just refresh the real unit button's unit
if frame then
frame:SetAttribute("unit", unit) -- Refresh the real unit button's unit
end
]]
]=]
-- Use SecureHandlerAttributeTemplate for unit buttons
grpHeader:SetAttribute("template", "SecureHandlerAttributeTemplate")
-- The init code for each auto-generated unit buttons
grpHeader:SetAttribute("initialConfigFunction", [[
tinsert(ShadowFrames, self)
-- I don't really need to show those auto-generated buttons
self:SetWidth(0)
self:SetHeight(0)
self:SetID(#ShadowFrames)
-- Binding
local frame = UnitFrames[#ShadowFrames]
self:SetAttribute("Manager", Manager)
if frame then
self:SetAttribute("UnitFrame", frame)
end
-- Only for entering game during combat
-- refreshUnitChange won't fire when the unit is set to nil, so it's not a good choice
self:SetAttribute("refreshUnitChange", refreshUnitChange)
-- Call an un-secure method to notify new unit button is generated
Manager:CallMethod("UpdateUnitCount", #ShadowFrames)
]])
-- Throw out of the screen, but keep it shown
grpHeader:SetPoint("TOPRIGHT", WorldFrame, "TOPLEFT")
grpHeader:SetAttribute("refreshUnitFrames", [[
print("HELLO")
]])
-- The real snippet for unit changing
-- We don't use refreshUnitChange because it won't fire when the unit is changed to nil
local _Onattributechanged = [[
if name == "unit" then
if type(value) == "string" then
value = strlower(value)
else
value = nil
end
print(value)
self:GetAttribute("Manager"):RunAttribute("refreshUnitFrames")
end
]]
local function GenerateUnitFrames(self, count)
-- re-init the auto-generated unit button
local child = self:GetAttribute("child"..count)
child:SetAttribute("refreshUnitChange", nil) -- only used for the entering game combat
child:SetAttribute("_onattributechanged", _Onattributechanged)
-- Other code to generate the unit frames, just ignored here
end
function grpHeader:UpdateUnitCount(count)
local timer = 0
grpHeader:SetScript("OnUpdate", function(self, elapsed)
timer = timer + elapsed
if timer < 1 then
return
end
timer = 0
GenerateUnitFrames(self, count)
end)
end
grpHeader:Show()