2 -- 2019 Aleksi Blinnikka
4 -- Main update function for all frames. Gets around issues with events.
8 local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
9 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
10 local UnitIsAFK, UnitIsDND = UnitIsAFK, UnitIsDND;
11 local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs;
12 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
13 local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
15 local dispelcolor = addon.Colors.OverlayColorDispel;
16 local charmcolor = addon.Colors.OverlayColorCharm;
17 local majorcolor = addon.Colors.OverlayColorAlert;
19 local function updateAuras()
24 function addon.FrameUpdate(frame)
25 assert(type(frame) == "table", "FrameUpdate received invalid frame parameter!");
27 local unit = frame.displayed;
28 local width = frame.barwidth;
29 -- range check (doesn't have an event)
30 local inrange, checked = UnitInRange(unit);
31 if checked and not inrange then
37 if UnitIsDeadOrGhost(unit) then
38 frame.text:SetText("Dead");
39 if not frame.text:IsShown() then frame.text:Show() end
40 if frame.health:IsShown() then frame.health:Hide() end
41 if frame.shield:IsShown() then frame.shield:Hide() end
42 if frame.healpred:IsShown() then frame.healpred:Hide() end
43 if frame.healabsorb:IsShown() then frame.healabsorb:Hide() end
44 --if frame.auras:IsShown() then frame.auras:Hide() end
45 elseif not UnitIsConnected(unit) then
46 frame.text:SetText("DC");
47 if not frame.text:IsShown() then frame.text:Show() end
48 if frame.health:IsShown() then frame.health:Hide() end
49 if frame.shield:IsShown() then frame.shield:Hide() end
50 if frame.healpred:IsShown() then frame.healpred:Hide() end
51 if frame.healabsorb:IsShown() then frame.healabsorb:Hide() end
52 --if frame.auras:IsShown() then frame.auras:Hide() end
54 if UnitIsAFK(unit) then
55 frame.text:SetText("afk");
56 if not frame.text:IsShown() then frame.text:Show() end
57 elseif UnitIsDND(unit) then
58 frame.text:SetText("dnd");
59 if not frame.text:IsShown() then frame.text:Show() end
61 if frame.text:IsShown() then frame.text:Hide() end
64 local current, hmax = UnitHealth(unit), UnitHealthMax(unit);
65 if frame.prev.health ~= current or frame.prev.hmax ~= hmax then
66 frame.prev.health = current;
67 frame.prev.hmax = hmax;
68 if hmax < current or hmax <= 1 then
69 frame.health:SetWidth(width);
70 frame.health.width = width;
71 if not frame.health:IsShown() then frame.health:Show() end
72 elseif current <= 0 then
73 if frame.health:IsShown() then frame.health:Hide() end
75 local w = current/hmax*width;
76 frame.health:SetWidth(w);
77 frame.health.width = w;
78 if not frame.health:IsShown() then frame.health:Show() end
82 local hwidth = frame.health.width;
83 current = UnitGetTotalAbsorbs(unit) or 0;
85 local space = width - hwidth;
86 current = (current / hmax) * width;
88 if frame.shield:IsShown() then frame.shield:Hide() end
89 if not frame.shieldhl:IsShown() then frame.shieldhl:Show() end
90 elseif space < current then
91 frame.shield:SetWidth(space);
92 if not frame.shield:IsShown() then frame.shield:Show() end
93 if not frame.shieldhl:IsShown() then frame.shieldhl:Show() end
95 frame.shield:SetWidth(current);
96 if not frame.shield:IsShown() then frame.shield:Show() end
97 if frame.shieldhl:IsShown() then frame.shieldhl:Hide() end
100 if frame.shield:IsShown() then frame.shield:Hide() end
101 if frame.shieldhl:IsShown() then frame.shieldhl:Hide() end
104 current = UnitGetTotalHealAbsorbs(unit) or 0;
106 current = (current / hmax) * width;
107 frame.healabsorb:SetWidth(min(hwidth, current));
108 if not frame.healabsorb:IsShown() then frame.healabsorb:Show() end
109 elseif frame.healabsorb:IsShown() then
110 frame.healabsorb:Hide();
113 current = UnitGetIncomingHeals(unit) or 0;
115 current = (current / hmax) * width;
116 -- at least 1 pixel prediction shown
117 frame.healpred:SetWidth(min(width - hwidth + 1, current));
118 if not frame.healpred:IsShown() then frame.healpred:Show() end
119 elseif frame.healpred:IsShown() then
120 frame.healpred:Hide();
123 if updateAuras(frame, unit) then
125 if frame.overlay.color ~= majorcolor then
126 frame.overlay:SetVertexColor(unpack(majorcolor));
127 frame.overlay.color = majorcolor;
128 if not frame.overlay:IsShown() then frame.overlay:Show() end
130 elseif UnitIsCharmed(unit) and frame.unit == frame.displayed then
132 if frame.overlay.color ~= charmcolor then
133 frame.overlay:SetVertexColor(unpack(charmcolor));
134 frame.overlay.color = charmcolor;
135 if not frame.overlay:IsShown() then frame.overlay:Show() end
137 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
139 if frame.overlay.color ~= dispelcolor then
140 frame.overlay:SetVertexColor(unpack(dispelcolor));
141 frame.overlay.color = dispelcolor;
142 if not frame.overlay:IsShown() then frame.overlay:Show() end
145 if frame.overlay.color ~= nil then
146 frame.overlay.color = nil;
147 if frame.overlay:IsShown() then frame.overlay:Hide() end