4fb3576 - Add pet and target frames
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Thu, 7 May 2020 16:24:42 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Thu, 7 May 2020 16:24:42 +0000
kehys/events.lua
kehys/hideblizz.lua
kehys/kehys.toc
kehys/player.lua
kehys/target.lua [new file with mode: 0644]
kehys/updater.lua

index f7ad732..ff6c4c9 100644 (file)
@@ -91,7 +91,7 @@ addon.Events.UpdateAggro = updateAggro;
 
 local function updateVehicle(frame)
     local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
 
 local function updateVehicle(frame)
     local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
-        UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
+        UnitTargetsVehicleInRaidUI(frame.unit) and frame.vehicle and UnitExists(frame.vehicle);
     if shouldTargetVehicle then
         if not frame.inVehicle then
             frame.inVehicle = true;
     if shouldTargetVehicle then
         if not frame.inVehicle then
             frame.inVehicle = true;
index e33db33..2bf07ad 100644 (file)
@@ -54,13 +54,11 @@ local function hideBlizzardUnitFrames()
     uf_hidden = true;
 
     local frames = {
     uf_hidden = true;
 
     local frames = {
-        PlayerFrame, PaladinPowerBarFrame, WarlockPowerFrame,
-        PlayerFrameAlternateManaBar,
+        PlayerFrame, PlayerFrameAlternateManaBar, PaladinPowerBarFrame,
+        WarlockPowerFrame, ComboFrame, PriestBarFrame, RuneFrame,
+        MonkHarmonyBarFrame, MageArcaneChargesFrame, CastingBarFrame,
+        PetFrame, PetCastingBarFrame, TargetFrame, TargetFrameToT,
     };
     };
-    --local frames = {PlayerFrame, TargetFrame, TargetFrameToT, PetFrame,
-    --    PlayerFrameAlternateManaBar, ComboFrame, PriestBarFrame, RuneFrame,
-    --    WarlockPowerFrame, MonkHarmonyBarFrame, PaladinPowerBarFrame,
-    --    MageArcaneChargesFrame, CastingBarFrame, PetCastingBarFrame};
     --for i = 1,MAX_BOSS_FRAMES do
     --    table.insert(frames, _G["Boss"..i.."TargetFrame"]);
     --    table.insert(frames, _G["Boss"..i.."TargetFrameHealthBar"]);
     --for i = 1,MAX_BOSS_FRAMES do
     --    table.insert(frames, _G["Boss"..i.."TargetFrame"]);
     --    table.insert(frames, _G["Boss"..i.."TargetFrameHealthBar"]);
@@ -85,8 +83,6 @@ local function hideBlizzardUnitFrames()
     PlayerFrame:SetMovable(true);
     PlayerFrame:SetUserPlaced(true);
     PlayerFrame:SetDontSavePosition(true);
     PlayerFrame:SetMovable(true);
     PlayerFrame:SetUserPlaced(true);
     PlayerFrame:SetDontSavePosition(true);
-    CastingBarFrame:ClearAllPoints();
-    CastingBarFrame:SetPoint("BOTTOM", UIParent, "CENTER", -300, -146);
 end
 
 local hider = CreateFrame("Frame");
 end
 
 local hider = CreateFrame("Frame");
index f5c0e6a..d32e41c 100644 (file)
@@ -14,5 +14,6 @@ events.lua
 frame.lua
 raid.lua
 player.lua
 frame.lua
 raid.lua
 player.lua
+target.lua
 auras.lua
 incoming.lua
 auras.lua
 incoming.lua
index 89e15af..20f4c4a 100644 (file)
@@ -14,7 +14,7 @@ local vehicletoggle = [=[
     end
 ]=]
 
     end
 ]=]
 
-local updater = nil;
+local playerUpdate = nil;
 local function initPlayer(parent, width, height, update, event)
     assert(type(parent) == "table", "Player frame creation missing parent!");
     assert(type(width) == "number", "Player frame creation missing width!");
 local function initPlayer(parent, width, height, update, event)
     assert(type(parent) == "table", "Player frame creation missing parent!");
     assert(type(width) == "number", "Player frame creation missing width!");
@@ -40,8 +40,8 @@ local function initPlayer(parent, width, height, update, event)
     f.nonraid = true;
     f.prev = {};
 
     f.nonraid = true;
     f.prev = {};
 
-    updater = function()
-        CTimerAfter(0.1, updater);
+    playerUpdate = function()
+        CTimerAfter(0.1, playerUpdate);
         update(f);
     end
     f:SetScript("OnEvent", event);
         update(f);
     end
     f:SetScript("OnEvent", event);
@@ -96,7 +96,7 @@ local function initPlayer(parent, width, height, update, event)
     f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
     f.healabsorb:Hide();
     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
     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:SetPoint("RIGHT", f, "RIGHT", -2, 8);
     f.text:SetFont(STANDARD_TEXT_FONT, 13);
     f.text:Hide();
     f.targeticon = f:CreateTexture(nil, "OVERLAY");
     f.text:SetFont(STANDARD_TEXT_FONT, 13);
     f.text:Hide();
     f.targeticon = f:CreateTexture(nil, "OVERLAY");
@@ -114,7 +114,101 @@ local function initPlayer(parent, width, height, update, event)
     addon.RegisterEvents(f);
     addon.RegisterUnitEvents(f);
     event(f, "UPDATE_ALL_BARS");
     addon.RegisterEvents(f);
     addon.RegisterUnitEvents(f);
     event(f, "UPDATE_ALL_BARS");
-    updater();
+    playerUpdate();
+    f:Show();
+    return f;
+end
+
+local petUpdate = nil;
+local function initPet(parent, width, height, update, event)
+    assert(type(parent) == "table", "Pet frame creation missing parent!");
+    assert(type(width) == "number", "Pet frame creation missing width!");
+    assert(type(height) == "number", "Pet frame creation missing height!");
+    assert(type(update) == "function",
+           "Pet frame creation missing update function!");
+    assert(type(event) == "function",
+           "Pet frame creation missing event function!");
+
+    local f = CreateFrame("Button", "kehysPet", parent,
+                          "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
+    f:Hide();
+    f:SetPoint("BOTTOMRIGHT", parent, "BOTTOMLEFT", -5, 0);
+    f:SetWidth(width);
+    f:SetHeight(height);
+    f.barwidth = width - 2; -- 1px padding
+    f:SetAttribute("unit", "pet");
+    f:SetAttribute("displayed", "pet");
+    f:SetAttribute("vehicle", "player");
+    f.unit = "pet";
+    f.displayed = "pet";
+    f.vehicle = "player"
+    f.nonraid = true;
+    f.prev = {};
+
+    petUpdate = function()
+        CTimerAfter(0.1, petUpdate);
+        update(f);
+    end
+    f:SetScript("OnEvent", event);
+    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");
+    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, "BOTTOMLEFT");
+    f.health:SetTexture(barTexture);
+    f.health:SetVertexColor(0.8, 0.8, 0.8);
+    f.health: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, "BOTTOMRIGHT");
+    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", 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: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();
+
+    addon.RegisterEvents(f);
+    addon.RegisterUnitEvents(f);
+    event(f, "UPDATE_ALL_BARS");
+    petUpdate();
     f:Show();
 end
 
     f:Show();
 end
 
@@ -124,6 +218,7 @@ CFrame:SetScript("OnEvent", function(self)
     CFrame:SetPoint("CENTER", nil, "CENTER");
     CFrame:SetWidth(2);
     CFrame:SetHeight(2);
     CFrame:SetPoint("CENTER", nil, "CENTER");
     CFrame:SetWidth(2);
     CFrame:SetHeight(2);
-    initPlayer(self, 160, 48, addon.FrameUpdate, addon.UnitEvent);
+    local player = initPlayer(self, 160, 48, addon.FrameUpdate, addon.UnitEvent);
+    initPet(player, 80, 24, addon.FrameUpdate, addon.UnitEvent);
 end);
 CFrame:RegisterEvent("PLAYER_LOGIN");
 end);
 CFrame:RegisterEvent("PLAYER_LOGIN");
diff --git a/kehys/target.lua b/kehys/target.lua
new file mode 100644 (file)
index 0000000..342743b
--- /dev/null
@@ -0,0 +1,122 @@
+-- target.lua
+local _, addon = ...;
+local unpack = unpack;
+local format = string.format;
+local CFrame = CreateFrame("Frame", "kehysTargetInit", UIParent);
+local CTimerAfter = C_Timer.After;
+
+local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
+
+local targetUpdate = nil;
+local function initTarget(parent, width, height, update, event)
+    assert(type(parent) == "table", "Target frame creation missing parent!");
+    assert(type(width) == "number", "Target frame creation missing width!");
+    assert(type(height) == "number", "Target frame creation missing height!");
+    assert(type(update) == "function",
+           "Target frame creation missing update function!");
+    assert(type(event) == "function",
+           "Target frame creation missing event function!");
+
+    local f = CreateFrame("Button", "kehysTarget", parent,
+                          "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
+    f:Hide();
+    f:SetPoint("CENTER", parent, "CENTER", 300, -178);
+    f:SetWidth(width);
+    f:SetHeight(height);
+    f.barwidth = width - 2; -- 1px padding
+    f:SetAttribute("unit", "target");
+    f:SetAttribute("displayed", "target");
+    f.unit = "target";
+    f.displayed = "target";
+    f.nonraid = true;
+    f.prev = {};
+
+    targetUpdate = function()
+        CTimerAfter(0.1, targetUpdate);
+        update(f);
+    end
+    f:SetScript("OnEvent", event);
+    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");
+    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.8, 0.8, 0.8);
+    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, 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", 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, 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: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();
+    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();
+    return f;
+end
+
+CFrame:SetScript("OnEvent", function(self)
+    self:UnregisterAllEvents();
+    CFrame:SetFrameStrata("LOW");
+    CFrame:SetPoint("CENTER", nil, "CENTER");
+    CFrame:SetWidth(2);
+    CFrame:SetHeight(2);
+    initTarget(self, 160, 48, addon.FrameUpdate, addon.UnitEvent);
+end);
+CFrame:RegisterEvent("PLAYER_LOGIN");
index 96e9f49..9a673ae 100644 (file)
@@ -69,13 +69,18 @@ function addon.FrameUpdate(frame)
         frame.prev.hmax = nil;
     else
         if UnitIsAFK(unit) then
         frame.prev.hmax = nil;
     else
         if UnitIsAFK(unit) then
+            frame.text.status = true;
             frame.text:SetText("afk");
             if not frame.text:IsShown() then frame.text:Show() end
         elseif UnitIsDND(unit) then
             frame.text:SetText("afk");
             if not frame.text:IsShown() then frame.text:Show() end
         elseif UnitIsDND(unit) then
+            frame.text.status = true;
             frame.text:SetText("dnd");
             if not frame.text:IsShown() then frame.text:Show() end
         else
             frame.text:SetText("dnd");
             if not frame.text:IsShown() then frame.text:Show() end
         else
-            if frame.text:IsShown() then frame.text:Hide() end
+            frame.text.status = false;
+            if not (frame.nonraid and frame.unit == "target") and frame.text:IsShown() then
+                frame.text:Hide();
+            end
         end
         if frame.nonraid and frame.unit == "player" then
             if InCombatLockdown() then
         end
         if frame.nonraid and frame.unit == "player" then
             if InCombatLockdown() then
@@ -92,6 +97,17 @@ function addon.FrameUpdate(frame)
         -- health
         local current, hmax = UnitHealth(unit), UnitHealthMax(unit);
         if frame.prev.health ~= current or frame.prev.hmax ~= hmax then
         -- health
         local current, hmax = UnitHealth(unit), UnitHealthMax(unit);
         if frame.prev.health ~= current or frame.prev.hmax ~= hmax then
+            if frame.nonraid and frame.unit == "target" 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);
+                end
+                if not frame.text:IsShown() then frame.text:Show() end
+            end
             frame.prev.health = current;
             frame.prev.hmax = hmax;
             if hmax < current or hmax <= 1 then
             frame.prev.health = current;
             frame.prev.hmax = hmax;
             if hmax < current or hmax <= 1 then
@@ -161,7 +177,7 @@ function addon.FrameUpdate(frame)
                 frame.prev.mmax = max;
                 if max < current or max <= 1 then
                     frame.mana:SetWidth(width);
                 frame.prev.mmax = max;
                 if max < current or max <= 1 then
                     frame.mana:SetWidth(width);
-                    frame.mana:SetText("100");
+                    frame.manatext: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 not frame.mana:IsShown() then frame.mana:Show() end
                     if not frame.manatext:IsShown() then frame.manatext:Show() end
                 elseif current <= 0 then