3ddb182 - Fix insecure boss frames
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 18 Feb 2018 23:54:51 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 18 Feb 2018 23:54:51 +0000
Secure frames are still not working fully causing some invisible frames
catching mouse clicks.

OmaUF/BossFrames.lua
OmaUF/UnitFrames.lua

index 0f9841d..d2a7ef7 100644 (file)
@@ -2,6 +2,7 @@
 local _;
 local unpack, pairs = unpack, pairs;
 local format = string.format;
+local UnitExists, ShowBossFrameWhenUninteractable = UnitExists, ShowBossFrameWhenUninteractable;
 local GameTooltip = GameTooltip;
 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor;
 
@@ -55,6 +56,17 @@ function OmaUnitFrames.UpdateBossTooltips()
     GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
 end
 
+local function bossEvent(self)
+    -- INSTANCE_ENCOUNTER_ENGAGE_UNIT only
+    for unit, frame in pairs(self.frames) do
+        if UnitExists(unit) or ShowBossFrameWhenUninteractable(unit) then
+            frame:Show();
+        else
+            frame:Hide();
+        end
+    end
+end
+
 local function createFrame(framename, securename, parent, unit, anchorX, anchorY)
     local secure = CreateFrame("Button", securename, parent, inheritedFrames);
     local frame = CreateFrame("Frame", framename, parent);
@@ -144,24 +156,32 @@ local function createFrame(framename, securename, parent, unit, anchorX, anchorY
     -- rest give target and menu
     secure:SetAttribute("*type1", "target");
     secure:SetAttribute("*type2", "togglemenu");
-    --secure:SetAttribute("toggleForVehicle", false); -- TODO run LFR to see if there's boss1pet or something
-    RegisterUnitWatch(frame);
-    RegisterUnitWatch(secure);
-    -- TODO try register visibility state driver with [boss1][boss2][boss3] etc.
+    -- TODO dunno how to update frame securely without hiding frame too often
+    -- ShowBossFrameWhenUninteractable not in restricted environment
+    -- this way all frames are clickable, but there's some invisible clickframes
+    RegisterStateDriver(secure, "visibility", "[@boss1,exists][@boss2,exists][@boss3,exists][@boss4,exists][@boss5,exists] show; hide");
+    return frame;
 end
 
 function OmaUnitFrames.InitializeBoss(parent)
     attributes = Settings.Character.Clickheal;
 
-    createFrame("OmaBoss1", "OmaBossSecure1", parent, "boss1", anchorX, anchorY);
+    -- hidden frame to handle hiding insecure boss frames
+    local bossHeader = CreateFrame("Frame");
+    bossHeader.frames = {};
+    bossHeader:SetScript("OnEvent", bossEvent);
+    bossHeader:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
+    bossHeader.frames["boss1"] = createFrame("OmaBoss1", "OmaBossSecure1", parent, "boss1", anchorX, anchorY);
     for i = 2,MAX_BOSS_FRAMES do
-        createFrame("OmaBoss"..i, "OmaBossSecure"..i, _G["OmaBoss"..(i-1)], "boss"..i, 0, -height-26);
+        bossHeader.frames["boss"..i] = createFrame("OmaBoss"..i, "OmaBossSecure"..i, _G["OmaBossSecure"..(i-1)], "boss"..i, 0, -height-26);
     end
+    bossEvent(bossHeader);
+
     -- Arena frames are in the same spot
-    createFrame("OmaArena1", "OmaArenaSecure1", parent, "arena1", anchorX, anchorY);
+    --[[createFrame("OmaArena1", "OmaArenaSecure1", parent, "arena1", anchorX, anchorY);
     -- MAX_ARENA_ENEMIES from AddOns/Blizzard_ArenaUI/Blizzard_ArenaUI.lua not available
     -- as the addon is not loaded yet, update manually if it changes
     for i = 2,5 do
         createFrame("OmaArena"..i, "OmaArenaSecure"..i, _G["OmaArena"..(i-1)], "arena"..i, 0, -height-26);
-    end
+    end--]]
 end
index f477e37..6ee5380 100644 (file)
@@ -6,7 +6,7 @@ local CTimerAfter = C_Timer.After;
 
 local updateAuraTooltips = OmaUFAuras.UpdateAuraTooltips;
 
-local UnitFrames = CreateFrame("Frame", "OmaUnitFrames", UIParent);
+local UnitFrames = CreateFrame("Frame", "OmaUnitFrame", UIParent);
 
 local M = {};
 OmaUnitFrames = M;