-- raid.lua -- 2019 Aleksi Blinnikka local _, addon = ...; local format = string.format; local UnitInRange = UnitInRange; local RegisterStateDriver, RegisterUnitWatch = RegisterStateDriver, RegisterUnitWatch; local registerEvents = addon.RegisterEvents; local registerUnitEvents = addon.RegisterUnitEvents; local unitEvent = addon.UnitEvent; local unitUpdate = addon.FrameUpdate; local width, height = 82, 42; local anchorX, anchorY = 0, -330; local attributes = {}; local CFrame = CreateFrame("Frame", "kehysMain", UIParent); local class = nil; local party = {}; local raid = {}; local function frameShow(frame) registerEvents(frame); registerUnitEvents(frame); unitEvent(frame, "UPDATE_ALL_BARS"); end -- vehicle toggle from Shadowed Unit Frames local vehicletoggle = [=[ local unit = self:GetAttribute("unit"); if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then self:SetAttribute("toggleForVehicle", false); else self:SetAttribute("toggleForVehicle", true); end ]=] local vehiclestates = "[@%s,unithasvehicleui] vehicle; no"; local function initializeParty(parent) assert(type(parent) == "table", "Party initialization missing parent frame!"); local visibility = "[@%s,exists,group:raid] hide; [@%s,exists] show; hide"; local unit = "player"; local frame = addon.NewRaidFrame(parent, width, height, unit, attributes, unitUpdate, unitEvent, frameShow); frame:SetPoint("TOPLEFT", parent, "TOPLEFT"); RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show"); RegisterStateDriver(frame, "vehicleui", "[vehicleui] vehicle; no"); frame:SetAttribute("_onstate-vehicleui", vehicletoggle); party[0] = frame; for i = 1,4 do unit = "party"..i; frame = addon.NewRaidFrame(parent, width, height, unit, attributes, unitUpdate, unitEvent, frameShow); frame:SetPoint("TOPLEFT", party[i-1], "TOPRIGHT"); RegisterStateDriver(frame, "visibility", format(visibility, unit, unit)); RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit)); frame:SetAttribute("_onstate-vehicleui", vehicletoggle); party[i] = frame; end end local function initializeRaid(parent) assert(type(parent) == "table", "Raid initialization missing parent frame!"); local unit = "raid1"; local frame = addon.NewRaidFrame(parent, width, height, unit, attributes, unitUpdate, unitEvent, frameShow); frame:SetPoint("TOPLEFT", parent, "TOPLEFT"); RegisterUnitWatch(frame); RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit)); frame:SetAttribute("_onstate-vehicleui", vehicletoggle); raid[1] = frame; for y = 1,7 do local i = y*5+1; unit = "raid"..i; frame = addon.NewRaidFrame(parent, width, height, unit, attributes, unitUpdate, unitEvent, frameShow); frame:SetPoint("TOPLEFT", raid[i-5], "BOTTOMLEFT"); RegisterUnitWatch(frame); RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit)); frame:SetAttribute("_onstate-vehicleui", vehicletoggle); raid[i] = frame; end for y = 0,7 do for x = 1,4 do local i = y*5+x+1; unit = "raid"..i; frame = addon.NewRaidFrame(parent, width, height, unit, attributes, unitUpdate, unitEvent, frameShow); frame:SetPoint("TOPLEFT", raid[i-1], "TOPRIGHT"); RegisterUnitWatch(frame); RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit)); frame:SetAttribute("_onstate-vehicleui", vehicletoggle); raid[i] = frame; end end end local function initializeFocus(parent) assert(type(parent) == "table", "Focus initialization missing parent frame!"); local unit = "focus"; local frame = addon.NewRaidFrame(parent, width, height, unit, attributes, unitUpdate, unitEvent, frameShow); frame:SetPoint("BOTTOMLEFT", parent, "TOPLEFT"); RegisterUnitWatch(frame); RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit)); frame:SetAttribute("_onstate-vehicleui", vehicletoggle); end local function initialize() _, class = UnitClass("player"); attributes = addon.Clickheal[class]; if class == "MAGE" then width = 72; height = 37; anchorX = 0; anchorY = -380; end CFrame:SetFrameStrata("LOW"); CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY); CFrame:SetHeight((height+2)*8); CFrame:SetWidth((width+2)*5); initializeParty(CFrame); initializeRaid(CFrame); initializeFocus(CFrame); end CFrame:SetScript("OnEvent", function(self) self:UnregisterAllEvents(); initialize(); end); CFrame:RegisterEvent("PLAYER_LOGIN");