2 -- 2019 Aleksi Blinnikka
4 local format = string.format;
5 local UnitInRange = UnitInRange;
6 local RegisterStateDriver, RegisterUnitWatch = RegisterStateDriver, RegisterUnitWatch;
8 local registerEvents = addon.RegisterEvents;
9 local registerUnitEvents = addon.RegisterUnitEvents;
10 local unitEvent = addon.UnitEvent;
11 local unitUpdate = addon.FrameUpdate;
13 local width, height = 82, 42;
14 local anchorX, anchorY = 0, -330;
15 local attributes = {};
17 local CFrame = CreateFrame("Frame", "kehysMain", UIParent);
22 local function frameShow(frame)
23 registerEvents(frame);
24 registerUnitEvents(frame);
25 unitEvent(frame, "UPDATE_ALL_BARS");
28 -- vehicle toggle from Shadowed Unit Frames
29 local vehicletoggle = [=[
30 local unit = self:GetAttribute("unit");
31 if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then
32 self:SetAttribute("toggleForVehicle", false);
34 self:SetAttribute("toggleForVehicle", true);
37 local vehiclestates = "[@%s,unithasvehicleui] vehicle; no";
39 local function initializeParty(parent)
40 assert(type(parent) == "table",
41 "Party initialization missing parent frame!");
42 local visibility = "[@%s,exists,group:raid] hide; [@%s,exists] show; hide";
43 local unit = "player";
44 local frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
45 unitUpdate, unitEvent, frameShow);
46 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
47 RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show");
48 RegisterStateDriver(frame, "vehicleui", "[vehicleui] vehicle; no");
49 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
53 frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
54 unitUpdate, unitEvent, frameShow);
55 frame:SetPoint("TOPLEFT", party[i-1], "TOPRIGHT");
56 RegisterStateDriver(frame, "visibility", format(visibility, unit, unit));
57 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
58 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
63 local function initializeRaid(parent)
64 assert(type(parent) == "table",
65 "Raid initialization missing parent frame!");
67 local frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
68 unitUpdate, unitEvent, frameShow);
69 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
70 RegisterUnitWatch(frame);
71 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
72 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
77 frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
78 unitUpdate, unitEvent, frameShow);
79 frame:SetPoint("TOPLEFT", raid[i-5], "BOTTOMLEFT");
80 RegisterUnitWatch(frame);
81 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
82 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
89 frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
90 unitUpdate, unitEvent, frameShow);
91 frame:SetPoint("TOPLEFT", raid[i-1], "TOPRIGHT");
92 RegisterUnitWatch(frame);
93 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
94 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
100 local function initializeFocus(parent)
101 assert(type(parent) == "table",
102 "Focus initialization missing parent frame!");
103 local unit = "focus";
104 local frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
105 unitUpdate, unitEvent, frameShow);
106 frame:SetPoint("BOTTOMLEFT", parent, "TOPLEFT");
107 RegisterUnitWatch(frame);
108 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
109 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
112 local function initialize()
113 _, class = UnitClass("player");
114 attributes = addon.Clickheal[class];
115 CFrame:SetFrameStrata("LOW");
116 CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
117 CFrame:SetHeight((height+2)*8);
118 CFrame:SetWidth((width+2)*5);
119 initializeParty(CFrame);
120 initializeRaid(CFrame);
121 initializeFocus(CFrame);
124 CFrame:SetScript("OnEvent", function(self)
125 self:UnregisterAllEvents();
128 CFrame:RegisterEvent("PLAYER_LOGIN");