From: Aleksi Blinnikka Date: Thu, 7 May 2020 21:41:19 +0000 (+0300) Subject: Add boss frames X-Git-Url: https://www.aleksib.fi/git/wowui.git/commitdiff_plain/79feebea0985e4fc1d0fee41cbeca982c5e389f9?ds=sidebyside Add boss frames --- diff --git a/kehys/boss.lua b/kehys/boss.lua new file mode 100644 index 0000000..988b93d --- /dev/null +++ b/kehys/boss.lua @@ -0,0 +1,150 @@ +-- boss.lua +local _, addon = ...; +local unpack = unpack; +local format = string.format; +local CFrame = CreateFrame("Frame", "kehysBossInit", UIParent); +local CTimerAfter = C_Timer.After; + +local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist"; + +local function showTooltip(frame) + GameTooltip_SetDefaultAnchor(GameTooltip, frame); + GameTooltip:SetUnit(frame:GetAttribute("unit")); +end + +local function hideTooltip() + GameTooltip:FadeOut(); +end + +local id = 1; +local updaters = {}; +local function initBoss(parent, y, width, height, update, event) + assert(type(parent) == "table", "Boss frame creation missing parent!"); + assert(type(y) == "number", "Boss frame creation missing Y offset!"); + assert(type(width) == "number", "Boss frame creation missing width!"); + assert(type(height) == "number", "Boss frame creation missing height!"); + assert(type(update) == "function", + "Boss frame creation missing update function!"); + assert(type(event) == "function", + "Boss frame creation missing event function!"); + + local unit = "boss"..id; + local f = CreateFrame("Button", "kehysBoss"..id, parent, + "SecureUnitButtonTemplate,SecureHandlerStateTemplate"); + id = id + 1; + f:Hide(); + f:SetPoint("CENTER", parent, "CENTER", 540, y+200); + f:SetWidth(width); + f:SetHeight(height); + f.barwidth = width - 2; -- 1px padding + f:SetAttribute("unit", unit); + f:SetAttribute("displayed", unit); + f.unit = unit; + f.displayed = unit; + f.boss = true; + f.prev = {}; + + updaters[f] = function() + if f.updating then + CTimerAfter(0.1, updaters[f]); + return update(f); + end + end + f:SetScript("OnEvent", event); + f:SetScript("OnHide", function() + f:UnregisterAllEvents(); + f.updating = false; + f.prev = {}; + end); + f:SetScript("OnShow", function() + addon.RegisterEvents(f); + addon.RegisterUnitEvents(f); + event(f, "UPDATE_ALL_BARS"); + f.updating = true; + updaters[f](); + end); + f:SetScript("OnEnter", showTooltip); + f:SetScript("OnLeave", hideTooltip); + f:RegisterForClicks("AnyDown"); + f:SetAttribute("*type1", "target"); + f:SetAttribute("*type2", "togglemenu"); + f:SetAttribute("toggleForVehicle", false); + + -- create visuals + f.base = f:CreateTexture(nil, "BACKGROUND"); + f.base:SetAllPoints(); + f.base:SetColorTexture(0, 0, 0, 0.5); + f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1); + f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1); + f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1); + f.health = f:CreateTexture(nil, "BORDER"); + f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT"); + f.health:SetPoint("BOTTOMLEFT", f.background, "LEFT", 0, -height/8); + f.health:SetTexture(barTexture); + f.health:SetVertexColor(0.7, 0.7, 0.7); + f.health:Hide(); + f.mana = f:CreateTexture(nil, "BORDER"); + f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -height/8); + f.mana:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT"); + f.mana:SetTexture(barTexture); + f.mana:SetVertexColor(0.1, 0.5, 0.9); + f.mana:Hide(); + f.manatext = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight"); + f.manatext:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT", -2, 1); + f.manatext:SetFont(STANDARD_TEXT_FONT, 10); + 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", 0, -height/8); + 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.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + f.name:SetPoint("LEFT", f, "LEFT", 2, 6); + f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + f.text:SetPoint("RIGHT", f, "RIGHT", -2, 6); + 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(); + -- Use Blizzard Alt Power Bar + local powerbar = _G[format("Boss%iTargetFramePowerBarAlt", string.sub(unit, 5, 5))]; + powerbar:SetParent(f); + powerbar:ClearAllPoints(); + powerbar:SetPoint("RIGHT", f, "LEFT"); + + RegisterUnitWatch(f); + f:Show(); + return f; +end + +CFrame:SetScript("OnEvent", function(self) + self:UnregisterAllEvents(); + CFrame:SetFrameStrata("LOW"); + CFrame:SetPoint("CENTER", nil, "CENTER"); + CFrame:SetWidth(2); + CFrame:SetHeight(2); + for i =1,MAX_BOSS_FRAMES do + initBoss(self, -(i*36), 160, 32, addon.FrameUpdate, addon.UnitEvent); + end +end); +CFrame:RegisterEvent("PLAYER_LOGIN"); diff --git a/kehys/events.lua b/kehys/events.lua index 6a96b3e..6b82322 100644 --- a/kehys/events.lua +++ b/kehys/events.lua @@ -36,6 +36,7 @@ function addon.RegisterEvents(frame) if frame.unit == "player" then frame:RegisterEvent("PLAYER_ALIVE") end if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end if frame.unit == "target" then frame:RegisterEvent("PLAYER_TARGET_CHANGED") end + if frame.boss then frame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT") end if frame.raid then frame:RegisterEvent("PLAYER_REGEN_DISABLED"); frame:RegisterEvent("READY_CHECK"); @@ -50,7 +51,7 @@ function addon.RegisterUnitEvents(frame) 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 == "focus" or frame.unit == "target" then + if frame.unit == "focus" or frame.unit == "target" or frame.boss then frame:RegisterUnitEvent("UNIT_TARGETABLE_CHANGED", frame.unit, displayed); end if frame.raid or frame.unit ~= "player" then @@ -79,8 +80,10 @@ local function updateName(frame, unit) if not frame.raid then if UnitIsEnemy("player", unit) then frame.health:SetVertexColor(1, 0, 0); - else + elseif UnitIsPlayer(unit) then frame.health:SetVertexColor(color.r, color.g, color.b); + else + frame.health:SetVertexColor(0, 1, 0); end else frame.name:SetVertexColor(color.r, color.g, color.b); @@ -234,6 +237,7 @@ eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["PLAYER_TARGET_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["UNIT_TARGETABLE_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"]; +eventFuncs["INSTANCE_ENCOUNTER_ENGAGE_UNIT"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["PLAYER_ALIVE"] = eventFuncs["UPDATE_ALL_BARS"]; function addon.UnitEvent(self, event) diff --git a/kehys/hideblizz.lua b/kehys/hideblizz.lua index 2bf07ad..160822e 100644 --- a/kehys/hideblizz.lua +++ b/kehys/hideblizz.lua @@ -59,12 +59,12 @@ local function hideBlizzardUnitFrames() MonkHarmonyBarFrame, MageArcaneChargesFrame, CastingBarFrame, PetFrame, PetCastingBarFrame, TargetFrame, TargetFrameToT, }; - --for i = 1,MAX_BOSS_FRAMES do - -- table.insert(frames, _G["Boss"..i.."TargetFrame"]); - -- table.insert(frames, _G["Boss"..i.."TargetFrameHealthBar"]); - -- table.insert(frames, _G["Boss"..i.."TargetFrameManaBar"]); - -- -- keep boss frame powerBarAlt - --end + for i = 1,MAX_BOSS_FRAMES do + table.insert(frames, _G["Boss"..i.."TargetFrame"]); + table.insert(frames, _G["Boss"..i.."TargetFrameHealthBar"]); + table.insert(frames, _G["Boss"..i.."TargetFrameManaBar"]); + -- keep boss frame powerBarAlt + end for _, frame in pairs(frames) do frame:UnregisterAllEvents(); if frame.healthbar then frame.healthbar:UnregisterAllEvents() end diff --git a/kehys/kehys.toc b/kehys/kehys.toc index d32e41c..dfbf593 100644 --- a/kehys/kehys.toc +++ b/kehys/kehys.toc @@ -15,5 +15,6 @@ frame.lua raid.lua player.lua target.lua +boss.lua auras.lua incoming.lua diff --git a/kehys/player.lua b/kehys/player.lua index 08ea8fe..ca0bd8b 100644 --- a/kehys/player.lua +++ b/kehys/player.lua @@ -96,7 +96,7 @@ local function initPlayer(parent, width, height, update, event) f.healabsorb:Hide(); f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); f.text:SetPoint("RIGHT", f, "RIGHT", -2, 8); - f.text:SetFont(STANDARD_TEXT_FONT, 13); + f.text:SetFont(STANDARD_TEXT_FONT, 15); f.text:Hide(); f.targeticon = f:CreateTexture(nil, "OVERLAY"); f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1); @@ -144,17 +144,28 @@ local function initPet(parent, width, height, update, event) f.prev = {}; petUpdate = function() - CTimerAfter(0.1, petUpdate); - update(f); + if f.updating then + CTimerAfter(0.1, petUpdate); + return update(f); + end end f:SetScript("OnEvent", event); + f:SetScript("OnHide", function() + f:UnregisterAllEvents(); + f.updating = false; + f.prev = {}; + end); + f:SetScript("OnShow", function() + addon.RegisterEvents(f); + addon.RegisterUnitEvents(f); + event(f, "UPDATE_ALL_BARS"); + f.updating = true; + petUpdate(); + end); f:RegisterForClicks("AnyDown"); f:SetAttribute("*type1", "target"); f:SetAttribute("*type2", "togglemenu"); f:SetAttribute("toggleForVehicle", true); - RegisterUnitWatch(f); - RegisterStateDriver(f, "vehicleui", "[vehicleui] vehicle; no"); - f:SetAttribute("_onstate-vehicleui", vehicletoggle); -- create visuals f.base = f:CreateTexture(nil, "BACKGROUND"); @@ -193,8 +204,8 @@ local function initPet(parent, width, height, update, event) f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); f.name:SetPoint("LEFT", f, "LEFT", 5, 0); f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); - f.text:SetPoint("RIGHT", f, "RIGHT", -5, 0); - f.text:SetFont(STANDARD_TEXT_FONT, 13); + f.text:SetPoint("RIGHT", f, "RIGHT", -3, -1); + f.text:SetFont(STANDARD_TEXT_FONT, 10); f.text:Hide(); f.targeticon = f:CreateTexture(nil, "OVERLAY"); f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1); @@ -203,11 +214,9 @@ local function initPet(parent, width, height, update, event) f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons"); f.targeticon:Hide(); - addon.RegisterEvents(f); - addon.RegisterUnitEvents(f); - event(f, "UPDATE_ALL_BARS"); - petUpdate(); - f:Show(); + RegisterUnitWatch(f); + RegisterStateDriver(f, "vehicleui", "[vehicleui] vehicle; no"); + f:SetAttribute("_onstate-vehicleui", vehicletoggle); end CFrame:SetScript("OnEvent", function(self) diff --git a/kehys/target.lua b/kehys/target.lua index 9b98d94..13434f0 100644 --- a/kehys/target.lua +++ b/kehys/target.lua @@ -7,6 +7,15 @@ local CTimerAfter = C_Timer.After; local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist"; +local function showTooltip(frame) + GameTooltip_SetDefaultAnchor(GameTooltip, frame); + GameTooltip:SetUnit(frame:GetAttribute("unit")); +end + +local function hideTooltip() + GameTooltip:FadeOut(); +end + local targetUpdate = nil; local function initTarget(parent, width, height, update, event) assert(type(parent) == "table", "Target frame creation missing parent!"); @@ -31,17 +40,30 @@ local function initTarget(parent, width, height, update, event) f.prev = {}; targetUpdate = function() - CTimerAfter(0.1, targetUpdate); - update(f); + if f.updating then + CTimerAfter(0.1, targetUpdate); + return update(f); + end end f:SetScript("OnEvent", event); - f:SetScript("OnHide", function (frame) frame.prev = {} end); - f:SetScript("OnShow", function (frame) update(frame) end); + f:SetScript("OnHide", function() + f:UnregisterAllEvents(); + f.updating = false; + f.prev = {}; + end); + f:SetScript("OnShow", function() + addon.RegisterEvents(f); + addon.RegisterUnitEvents(f); + event(f, "UPDATE_ALL_BARS"); + f.updating = true; + targetUpdate(); + end); + f:SetScript("OnEnter", showTooltip); + f:SetScript("OnLeave", hideTooltip); f:RegisterForClicks("AnyDown"); f:SetAttribute("*type1", "target"); f:SetAttribute("*type2", "togglemenu"); f:SetAttribute("toggleForVehicle", false); - RegisterUnitWatch(f); -- create visuals f.base = f:CreateTexture(nil, "BACKGROUND"); @@ -90,7 +112,7 @@ local function initTarget(parent, width, height, update, event) f.name:SetPoint("LEFT", f, "LEFT", 2, 8); f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); f.text:SetPoint("RIGHT", f, "RIGHT", -2, 8); - f.text:SetFont(STANDARD_TEXT_FONT, 13); + f.text:SetFont(STANDARD_TEXT_FONT, 15); f.text:Hide(); f.targeticon = f:CreateTexture(nil, "OVERLAY"); f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1); @@ -98,17 +120,8 @@ local function initTarget(parent, width, height, update, event) f.targeticon:SetHeight(12); f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons"); f.targeticon:Hide(); - f.status = f:CreateTexture(nil, "OVERLAY"); - f.status:SetPoint("TOPLEFT", f.background, "BOTTOMLEFT", -8, 8); - f.status:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMLEFT", 8, -8); - f.status:SetTexture("Interface\\CHARACTERFRAME\\UI-StateIcon"); - f.status:Hide(); - addon.RegisterEvents(f); - addon.RegisterUnitEvents(f); - event(f, "UPDATE_ALL_BARS"); - targetUpdate(); - f:Show(); + RegisterUnitWatch(f); return f; end diff --git a/kehys/updater.lua b/kehys/updater.lua index 3690953..8e1fcc6 100644 --- a/kehys/updater.lua +++ b/kehys/updater.lua @@ -83,7 +83,7 @@ function addon.FrameUpdate(frame) if not frame.text:IsShown() then frame.text:Show() end else frame.text.status = false; - if (frame.raid or frame.unit ~= "target") and frame.text:IsShown() then + if frame.raid and frame.text:IsShown() then frame.text:Hide(); end end @@ -101,17 +101,28 @@ function addon.FrameUpdate(frame) -- health local current, hmax = UnitHealth(unit), UnitHealthMax(unit); if frame.prev.health ~= current or frame.prev.hmax ~= hmax then - if not frame.raid and frame.unit == "target" and not frame.text.status - and frame.prev.htext ~= current then + if not frame.raid and not frame.text.status and frame.prev.htext ~= current then frame.prev.htext = current; - if current > 1000000000 then -- 1.0B - frame.text:SetFormattedText("%.2fB", current / 1000000000); - elseif current > 1000000 then -- 1.0M - frame.text:SetFormattedText("%.2fM", current / 1000000); - elseif current > 1000 then -- 1.0K - frame.text:SetFormattedText("%.1fK", current / 1000); + if frame.boss then + if hmax < current or hmax <= 1 then + frame.text:SetText("100"); + if not frame.text:IsShown() then frame.text:Show() end + elseif current <= 0 then + if frame.text:IsShown() then frame.text:Hide() end + else + frame.text:SetFormattedText("%.1f", current/hmax*100); + if not frame.text:IsShown() then frame.text:Show() end + end + else + if current > 1000000000 then -- 1.0B + frame.text:SetFormattedText("%.2fB", current / 1000000000); + elseif current > 1000000 then -- 1.0M + frame.text:SetFormattedText("%.2fM", current / 1000000); + elseif current > 1000 then -- 1.0K + frame.text:SetFormattedText("%.1fK", current / 1000); + end + if not frame.text:IsShown() then frame.text:Show() end end - if not frame.text:IsShown() then frame.text:Show() end end frame.prev.health = current; frame.prev.hmax = hmax; diff --git a/loitsu/castbar.lua b/loitsu/castbar.lua index a78e2fc..79c81fb 100644 --- a/loitsu/castbar.lua +++ b/loitsu/castbar.lua @@ -212,6 +212,6 @@ end init:SetScript("OnEvent", function (self) self:UnregisterAllEvents(); createCastBar("player", 160, -300, -140); - createCastBar("target", 160, 300, -140); + createCastBar("target", 160, 290, -140); end); init:RegisterEvent("PLAYER_LOGIN");