function addon.RegisterEvents(frame)
frame:RegisterEvent("PLAYER_ENTERING_WORLD");
- frame:RegisterEvent("PLAYER_REGEN_DISABLED");
- frame:RegisterEvent("READY_CHECK");
- frame:RegisterEvent("READY_CHECK_FINISHED");
- frame:RegisterEvent("GROUP_ROSTER_UPDATE");
frame:RegisterEvent("RAID_TARGET_UPDATE");
if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
+ if not frame.nonraid then
+ frame:RegisterEvent("PLAYER_REGEN_DISABLED");
+ frame:RegisterEvent("READY_CHECK");
+ frame:RegisterEvent("READY_CHECK_FINISHED");
+ frame:RegisterEvent("GROUP_ROSTER_UPDATE");
+ end
end
function addon.RegisterUnitEvents(frame)
-- events are taken from FrameXML/CompactUnitFrame.lua
local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
- frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
- frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
- frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
+ if frame.unit ~= "player" then
+ frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
+ end
+ if not frame.nonraid then
+ frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
+ frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
+ end
end
local registerUnitEvents = addon.RegisterUnitEvents;
local function updateName(frame, unit)
local name = UnitName(unit);
- if not name then return end
+ if not name or not frame.name then return end
name = ssub(name, 1, 6);
if frame.unit == unit then
frame.name:SetText(name);
end,
["UNIT_NAME_UPDATE"] = function(frame)
updateName(frame, frame.unit);
- if frame.guid then
- guids[frame.guid] = nil;
- end
- frame.guid = UnitGUID(frame.unit);
- if frame.guid then
- guids[frame.guid] = frame;
+ if not frame.nonraid then
+ if frame.guid then
+ guids[frame.guid] = nil;
+ end
+ frame.guid = UnitGUID(frame.unit);
+ if frame.guid then
+ guids[frame.guid] = frame;
+ end
end
end,
["PLAYER_ROLES_ASSIGNED"] = function(frame)
updateRaidMarker(frame, frame.displayed);
end,
["PLAYER_REGEN_DISABLED"] = function(frame)
- -- clear buff status on entering combat, should also use UnitAura to re-fill
- frame.tankcd = {};
- frame.alert = {};
- frame.stacks = {};
- frame.heal = {};
- frame.buff1 = {};
- addon.SetAuras(frame.unit, frame.guid);
+ if not frame.nonraid then
+ -- clear buff status on entering combat, should also use UnitAura to re-fill
+ frame.tankcd = {};
+ frame.alert = {};
+ frame.stacks = {};
+ frame.heal = {};
+ frame.buff1 = {};
+ addon.SetAuras(frame.unit, frame.guid);
+ end
end,
["UPDATE_ALL_BARS"] = function(frame)
- updateRole(frame, frame.unit);
updateVehicle(frame);
- updateAggro(frame, frame.displayed);
- updateName(frame, frame.unit);
- updateReadyCheck(frame, frame.unit);
updateRaidMarker(frame, frame.displayed);
-
- if frame.guid then
- guids[frame.guid] = nil;
+ if frame.unit ~= "player" then
+ updateName(frame, frame.unit);
end
- frame.guid = UnitGUID(frame.unit);
- if frame.guid then
- guids[frame.guid] = frame;
+ if not frame.nonraid then
+ updateRole(frame, frame.unit);
+ updateAggro(frame, frame.displayed);
+ updateReadyCheck(frame, frame.unit);
+ if frame.guid then
+ guids[frame.guid] = nil;
+ end
+ frame.guid = UnitGUID(frame.unit);
+ if frame.guid then
+ guids[frame.guid] = frame;
+ end
+ frame.tankcd = {};
+ frame.alert = {};
+ frame.stacks = {};
+ frame.heal = {};
+ frame.buff1 = {};
+ addon.SetAuras(frame.unit, frame.guid);
end
- frame.tankcd = {};
- frame.alert = {};
- frame.stacks = {};
- frame.heal = {};
- frame.buff1 = {};
- addon.SetAuras(frame.unit, frame.guid);
end,
};
eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
events.lua
frame.lua
raid.lua
+player.lua
auras.lua
incoming.lua
--- /dev/null
+-- player.lua
+local _, addon = ...;
+local unpack = unpack;
+local format = string.format;
+local CFrame = CreateFrame("Frame", "kehysPlayerInit", UIParent);
+
+local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist";
+local vehicletoggle = [=[
+ if newstate == "vehicle" then
+ self:SetAttribute("displayed", self:GetAttribute("vehicle"));
+ else
+ self:SetAttribute("displayed", self:GetAttribute("unit"));
+ end
+]=]
+
+local updater = nil;
+function addon.PlayerFrame(parent, width, height, update, event)
+ assert(type(parent) == "table", "Player frame creation missing parent!");
+ assert(type(width) == "number", "Player frame creation missing width!");
+ assert(type(height) == "number", "Player frame creation missing height!");
+ assert(type(update) == "function",
+ "Player frame creation missing update function!");
+ assert(type(event) == "function",
+ "Player frame creation missing event function!");
+
+ local f = CreateFrame("Button", "kehysPlayer", parent,
+ "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
+ f:Hide();
+ f:SetPoint("CENTER", parent, "CENTER", 10, 10);
+ f:SetWidth(width);
+ f:SetHeight(height);
+ f.barwidth = width - 2; -- 1px padding
+ f:SetAttribute("unit", "player");
+ f:SetAttribute("displayed", "player");
+ f:SetAttribute("vehicle", "vehicle");
+ f.nonraid = true;
+ f.prev = {};
+ -- empty, just to be able to use general updater
+ f.alert = {};
+ f.heal = {};
+ f.tankcd = {};
+ f.stacks = {};
+ f.buff1 = {};
+ f.incoming = {};
+
+ updater = function()
+ CTimerAfter(0.1, updater);
+ update(f);
+ end
+ f:SetScript("OnEvent", event);
+ f:SetAttribute("*type1", "target");
+ f:SetAttribute("*type2", "togglemenu");
+ f:SetAttribute("toggleForVehicle", true);
+ RegisterStateDriver(f, "vehicleui", "[vehicleui] vehicle; no");
+ f:SetAttribute("_onstate-vehicleui", vehicletoggle);
+
+ -- create visuals
+ f.base = f:CreateTexture(nil, "BACKGROUND");
+ f.base:SetAllPoints();
+ f.base:SetColorTexture(1, 1, 1);
+ f.base:SetVertexColor(unpack(addon.Colors.Base));
+ f.background = f:CreateTexture(nil, "BACKGROUND", nil, 2);
+ f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
+ f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
+ f.background:SetColorTexture(0.7, 0.7, 0.7);
+ f.health = f:CreateTexture(nil, "BORDER");
+ f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
+ f.health:SetPoint("BOTTOMLEFT", f.background, "LEFT", 0, 1);
+ f.health:SetTexture(barTexture);
+ f.health:SetVertexColor(0.3, 0.3, 0.3);
+ f.health:Hide();
+ f.mana = f:CreateTexture(nil, "BORDER");
+ f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -1);
+ f.mana:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
+ f.mana:SetTexture(barTexture);
+ f.mana:SetVertexColor(0.3, 0.4, 0.7);
+ f.mana:Hide();
+ f.manatext = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
+ f.manatext:SetPoint("RIGHT", frame.background, "RIGHT", -2, -height/4);
+ f.manatext:Hide();
+ f.shield = f:CreateTexture(nil, "BORDER");
+ f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
+ f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
+ f.shield:SetTexture(barTexture);
+ f.shield:SetVertexColor(0, 0.7, 1);
+ f.shield:Hide();
+ f.shieldhl = f:CreateTexture(nil, "ARTWORK");
+ f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
+ f.shieldhl:SetPoint("BOTTOMRIGHT", f, "RIGHT");
+ f.shieldhl:SetColorTexture(0.5, 0.8, 1);
+ f.shieldhl:Hide();
+ f.healpred = f:CreateTexture(nil, "ARTWORK");
+ f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
+ f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
+ f.healpred:SetColorTexture(0.5, 0.6, 0.5);
+ f.healpred:Hide();
+ f.healabsorb = f:CreateTexture(nil, "ARTWORK");
+ f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
+ f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
+ f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
+ f.healabsorb:Hide();
+ f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
+ f.text:SetPoint("LEFT", f.health, "LEFT", 10, 0);
+ f.text:SetFont(STANDARD_TEXT_FONT, 13);
+ f.text:Hide();
+ f.targeticon = f:CreateTexture(nil, "OVERLAY");
+ f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
+ f.targeticon:SetWidth(12);
+ f.targeticon:SetHeight(12);
+ f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
+ f.targeticon:Hide();
+
+ registerEvents(f);
+ registerUnitEvents(f);
+ event(f, "UPDATE_ALL_BARS");
+ updater();
+ f.Show();
+end
+
+CFrame:SetScript("OnEvent", function(self)
+ self:UnregisterAllEvents();
+ CFrame:SetFrameStrata("LOW");
+ CFrame:SetPoint("CENTER", nil, "CENTER");
+ CFrame:SetWidth(2);
+ CFrame:SetHeight(2);
+ initPlayer(self, 180, 100, addon.FrameUpdate, addon.UnitEvent);
+end);
+CFrame:RegisterEvent("PLAYER_LOGIN");
local _, addon = ...;
local unpack = unpack;
local min = math.min;
+local format = string.format;
local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
+local UnitPower, UnitPowerMax = UnitPower, UnitPowerMax;
local UnitIsAFK, UnitIsDND = UnitIsAFK, UnitIsDND;
local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs;
local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
+local IsResting = IsResting;
local dispelcolor = addon.Colors.OverlayColorDispel;
local charmcolor = addon.Colors.OverlayColorCharm;
local unit = frame.displayed;
local width = frame.barwidth;
- -- range check (doesn't have an event)
- local inrange, checked = UnitInRange(unit);
- if checked and not inrange then
- frame:SetAlpha(0.55);
- else
- frame:SetAlpha(1);
+ -- range check (doesn't have an event) frames can be marked constantly visible
+ if not frame.constant then
+ local inrange, checked = UnitInRange(unit);
+ if checked and not inrange then
+ frame:SetAlpha(0.55);
+ else
+ frame:SetAlpha(1);
+ end
end
-- states
if UnitIsDeadOrGhost(unit) then
elseif UnitIsDND(unit) then
frame.text:SetText("dnd");
if not frame.text:IsShown() then frame.text:Show() end
+ elseif frame.nonraid and frame.unit == "player" and IsResting() then
+ frame.text:SetText("zzz");
+ if not frame.text:IsShown() then frame.text:Show() end
else
if frame.text:IsShown() then frame.text:Hide() end
end
+ -- TODO incoming res, maybe just with events?
-- health
local current, hmax = UnitHealth(unit), UnitHealthMax(unit);
if frame.prev.health ~= current or frame.prev.hmax ~= hmax then
elseif frame.healpred:IsShown() then
frame.healpred:Hide();
end
- frame.rounds = frame.rounds + 1;
- if (frame.rounds > 7) then
- frame.tankcd = {};
- frame.alert = {};
- frame.stacks = {};
- frame.heal = {};
- frame.buff1 = {};
- addon.SetAuras(frame.unit, frame.guid);
- frame.rounds = 0;
+ -- mana, if present
+ if frame.mana ~= nil then
+ local current, max = UnitPower(unit), UnitPowerMax(unit);
+ if frame.prev.mana ~= current or frame.prev.mmax ~= max then
+ frame.prev.mana = current;
+ frame.prev.mmax = max;
+ if max < current or max <= 1 then
+ frame.mana:SetWidth(width);
+ frame.mana:SetText("100");
+ if not frame.mana:IsShown() then frame.mana:Show() end
+ if not frame.manatext:IsShown() then frame.manatext:Show() end
+ elseif current <= 0 then
+ if frame.mana:IsShown() then frame.mana:Hide() end
+ if frame.manatext:IsShown() then frame.manatext:Hide() end
+ else
+ local percent = current/max;
+ frame.mana:SetWidth(percent*width);
+ frame.manatext:SetText(format("%d", percent*100));
+ if not frame.mana:IsShown() then frame.mana:Show() end
+ if not frame.manatext:IsShown() then frame.manatext:Show() end
+ end
+ end
+ end
+ -- forced aura updates
+ if frame.rounds ~= nil then
+ frame.rounds = frame.rounds + 1;
+ if (frame.rounds > 7) then
+ frame.tankcd = {};
+ frame.alert = {};
+ frame.stacks = {};
+ frame.heal = {};
+ frame.buff1 = {};
+ addon.SetAuras(frame.unit, frame.guid);
+ frame.rounds = 0;
+ end
end
-- tank CD marker
if next(frame.tankcd) then
frame.overlay.color = majorcolor;
if not frame.overlay:IsShown() then frame.overlay:Show() end
end
- else
+ elseif frame.overlay ~= nil then
local _, _, _, _, _, _, _, _, _, spellid = UnitDebuff(unit, 1, "RAID");
if UnitIsCharmed(unit) and frame.unit == frame.displayed then
-- charmed