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;
12 local width, height = 82, 42;
13 local anchorX, anchorY = 0, -330;
14 local attributes = {};
16 local CFrame = CreateFrame("Frame", "kehysMain", UIParent);
21 local function unitUpdate(frame)
22 -- there's no in/out of range event, have to check each frame
23 -- from FrameXML/CompactUnitFrame.lua
24 local inRange, checked = UnitInRange(frame.displayed);
25 if checked and not inRange then
32 local function frameShow(frame)
33 registerEvents(frame);
34 registerUnitEvents(frame);
35 unitEvent(frame, "UPDATE_ALL_BARS");
38 -- vehicle toggle from Shadowed Unit Frames
39 local vehicletoggle = [=[
40 local unit = self:GetAttribute("unit");
41 if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then
42 self:SetAttribute("toggleForVehicle", false);
44 self:SetAttribute("toggleForVehicle", true);
47 local vehiclestates = "[@%s,unithasvehicleui] vehicle; no";
49 local function initializeParty(parent)
50 assert(type(parent) == "table",
51 "Party initialization missing parent frame!");
52 local visibility = "[@%s,exists,group:raid] hide; [@%s,exists] show; hide";
53 local unit = "player";
54 local frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
55 unitUpdate, unitEvent, frameShow);
56 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
57 RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show");
58 RegisterStateDriver(frame, "vehicleui", "[vehicleui] vehicle; no");
59 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
63 frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
64 unitUpdate, unitEvent, frameShow);
65 frame:SetPoint("TOPLEFT", party[i-1], "TOPRIGHT");
66 RegisterStateDriver(frame, "visibility", format(visibility, unit, unit));
67 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
68 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
73 local function initializeRaid(parent)
74 assert(type(parent) == "table",
75 "Raid initialization missing parent frame!");
77 local frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
78 unitUpdate, unitEvent, frameShow);
79 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
80 RegisterUnitWatch(frame);
81 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
82 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
87 frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
88 unitUpdate, unitEvent, frameShow);
89 frame:SetPoint("TOPLEFT", raid[i-5], "BOTTOMLEFT");
90 RegisterUnitWatch(frame);
91 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
92 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
99 frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
100 unitUpdate, unitEvent, frameShow);
101 frame:SetPoint("TOPLEFT", raid[i-1], "TOPRIGHT");
102 RegisterUnitWatch(frame);
103 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
104 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
110 local function initializeFocus(parent)
111 assert(type(parent) == "table",
112 "Focus initialization missing parent frame!");
113 local unit = "focus";
114 local frame = addon.NewRaidFrame(parent, width, height, unit, attributes,
115 unitUpdate, unitEvent, frameShow);
116 frame:SetPoint("BOTTOMLEFT", parent, "TOPLEFT");
117 RegisterUnitWatch(frame);
118 RegisterStateDriver(frame, "vehicleui", format(vehiclestates, unit));
119 frame:SetAttribute("_onstate-vehicleui", vehicletoggle);
122 local function initialize()
123 _, class = UnitClass("player");
124 attributes = addon.Clickheal[class];
125 CFrame:SetFrameStrata("LOW");
126 CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
127 CFrame:SetHeight((height+2)*8);
128 CFrame:SetWidth((width+2)*5);
129 initializeParty(CFrame);
130 initializeRaid(CFrame);
131 initializeFocus(CFrame);
134 CFrame:SetScript("OnEvent", function(self)
135 self:UnregisterAllEvents();
138 CFrame:RegisterEvent("PLAYER_LOGIN");