local Raid = { }
local roleColors = {
TANK = {0.2, 0.2, 0.8},
HEALER = {0, 0.7, 0},
DAMAGER = {0.7, 0, 0},
NONE = {0.7, 0.7, 0.7},
}
local function CreateUnitFrame(header, frameName)
local frame = _G[frameName]
frame:RegisterForClicks("AnyUp")
frame.bg = frame.bg or frame:CreateTexture(nil, "BACKGROUND")
frame.bg:SetAllPoints()
frame.role = frame.role or frame:CreateTexture()
frame.role:SetSize(8, 8)
frame.role:SetPoint("TOPLEFT")
frame:SetScript("OnAttributeChanged", function(self, name, value)
if name == "unit" then
if value then
Raid:UpdateDisplay(self)
end
end
end)
--[[frame:SetScript("OnEvent", function(self)
end)]]
frame:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
if self.unit then
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
GameTooltip:SetUnit(self.unit)
if UnitIsPlayer(self.unit) then
local class, classFileName = UnitClass(self.unit)
local color = RAID_CLASS_COLORS[classFileName]
GameTooltipTextLeft1:SetTextColor(color.r, color.g, color.b, 1)
else
local r, g, b, a = UnitSelectionColor(unit)
GameTooltipTextLeft1:SetTextColor(r, g, b, 1)
end
GameTooltip:Show()
end
end)
frame:SetScript("OnLeave", GameTooltip_Hide)
--[[frame:HookScript("OnShow", function(self)
end)
frame:HookScript("OnHide", function(self)
end)]]
return frame
end
function Raid:OnLoad()
self.events = CreateFrame("Frame")
self.events:SetScript("OnEvent", function(self, event, ...)
--print(event, ...)
Raid[event](Raid, ...)
end)
--[[self.update = CreateFrame("Frame")
self.update:SetScript("OnUpdate", function(self, elapsed)
Raid:OnUpdate(self, elapsed)
end)]]
self.headers = { }
local start = 1
for i = 1, 8 do
self.headers[i] = CreateFrame("Frame", "ZPerl2RaidGroup"..i, UIParent, "SecureRaidGroupHeaderTemplate")
if i == 1 then
self.headers[i]:SetPoint("Left", UIParent, "Left", 20, 0)
else
self.headers[i]:SetPoint("TopLeft", self.headers[i - 1], "TopRight", 0, 0)
end
self.headers[i]:SetAttribute("showRaid", true)
if i == 1 then
self.headers[i]:SetAttribute("showParty", true)
self.headers[i]:SetAttribute("showPlayer", true)
end
--self.headers[i]:SetAttribute("useparent-unit", true)
--self.headers[i]:SetAttribute("strictFiltering", nil)
self.headers[i]:SetAttribute("startingIndex", start)
self.headers[i]:SetAttribute("maxColumns", 1)
self.headers[i]:SetAttribute("unitsPerColumn", 5)
self.headers[i]:SetAttribute("sortMethod", nil)
self.headers[i]:SetAttribute("minWidth", 0)
self.headers[i]:SetAttribute("minHeight", 0)
self.headers[i]:SetAttribute("xOffset", 0)
self.headers[i]:SetAttribute("yOffset", 0)
self.headers[i]:SetAttribute("point", "TOP")
self.headers[i]:SetAttribute("columnSpacing", 1)
self.headers[i]:SetAttribute("columnAnchorPoint", "LEFT")
--self.headers[i]:SetAttribute("groupBy", "ASSIGNEDROLE")
--self.headers[i]:SetAttribute("groupingOrder", "TANK,HEALER,DAMAGER,NONE")
self.headers[i]:SetAttribute("groupBy", "GROUP")
self.headers[i]:SetAttribute("groupingOrder", "1,2,3,4,5,6,7,8")
self.headers[i]:SetAttribute("template", "SecureUnitButtonTemplate")
self.headers[i]:SetAttribute("initial-unitWatch", true)
self.headers[i]:SetAttribute("style-width", 50)
self.headers[i]:SetAttribute("style-height", 25)
self.headers[i]:SetAttribute("style-scale", 1)
self.headers[i]:SetID(i)
self.headers[i]:SetAttribute("initialConfigFunction", [[
local header = self:GetParent()
self:SetHeight(header:GetAttribute("style-height"))
self:SetWidth(header:GetAttribute("style-width"))
self:SetScale(header:GetAttribute("style-scale"))
self:SetAttribute("maxColumns", 1)
self:SetAttribute("unitsPerColumn", 5)
self:SetAttribute("toggleForVehicle", true)
self:SetAttribute("*type1", "target")
self:SetAttribute("type2", "togglemenu")
self:SetAttribute("isHeaderDriven", true)
header:CallMethod("initialConfigFunction", self:GetName())
]])
self.headers[i].initialConfigFunction = CreateUnitFrame
self.headers[i]:Show()
start = start + 5
end
self:RegisterEvents()
end
function Raid:RegisterEvents()
local events = {
"PLAYER_ENTERING_WORLD",
--"GROUP_ROSTER_UPDATE",
"ROLE_CHANGED_INFORM",
}
for i = 1, #events do
local event = events[i]
self.events:RegisterEvent(event)
end
end
function Raid:PLAYER_ENTERING_WORLD()
self:UpdateDisplayAll()
end
function Raid:GROUP_ROSTER_UPDATE()
self:UpdateDisplayAll()
end
function Raid:GUILD_PARTY_STATE_UPDATED()
self:UpdateDisplayAll()
end
function Raid:ROLE_CHANGED_INFORM()
self:UpdateDisplayAll()
end
function Raid:UpdateDisplay(frame)
local unit = frame:GetAttribute("unit")
if unit then
local guid = UnitGUID(unit)
--if guid ~= frame.guid then
frame.unit = unit
frame.guid = guid
if unit then
local _, class = UnitClass(unit)
local classColor = RAID_CLASS_COLORS[class]
if classColor then
frame.bg:SetTexture(classColor.r, classColor.g, classColor.b)
end
frame.role:SetTexture(unpack(roleColors[UnitGroupRolesAssigned(unit)]))
end
--end
end
end
function Raid:UpdateDisplayAll()
for i = 1, 8 do
for _, frame in ipairs(self.headers[i]) do
--for j = 1, 5 do
--local frame = self.headers[i]:GetAttribute("child"..j)
if frame then
local unit = frame:GetAttribute("unit")
frame.unit = unit
--local guid = UnitGUID(unit)
--frame.guid = guid
if unit then
local _, class = UnitClass(unit)
local classColor = RAID_CLASS_COLORS[class]
if classColor then
frame.bg:SetTexture(classColor.r, classColor.g, classColor.b)
end
frame.role:SetTexture(unpack(roleColors[UnitGroupRolesAssigned(unit)]))
end
end
end
end
end
Raid:OnLoad()