6e06bfb - Fix character settings loading
[wowui.git] / OmaRF / RaidFrame.lua
index 1f4bc87..4259c67 100644 (file)
@@ -4,6 +4,7 @@ local unpack, pairs, rawget = unpack, pairs, rawget;
 local format = string.format;
 local UnitHealthMax, UnitPowerMax = UnitHealthMax, UnitPowerMax;
 local UnitInRange = UnitInRange;
+local InCombatLockdown = InCombatLockdown;
 local CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
 local STANDARD_TEXT_FONT = STANDARD_TEXT_FONT;
 local GameTooltip = nil;
@@ -321,7 +322,15 @@ local function initializeFocus(parent)
     secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
 end
 
+local function loadCharSettings()
+    width, height = Settings.Character.Width, Settings.Character.Height;
+    anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
+    attributes = Settings.Character.Clickheal;
+    positions = Settings.Character.Positions;
+end
+
 local function initialize()
+    loadCharSettings();
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
     CFrame:SetWidth((width+2)*5+1);
@@ -330,22 +339,64 @@ local function initialize()
     initializeFocus(CFrame);
 end
 
-local function loadCharSettings()
-    width, height = Settings.Character.Width, Settings.Character.Height;
-    anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
-    attributes = Settings.Character.Clickheal;
-    positions = Settings.Character.Positions;
+-- hiding Blizzard frames somewhat based on ShadowedUF
+local function hideBlizzardRaidButton()
+    if InCombatLockdown() then return end
+    local manager = CompactRaidFrameManager;
+    -- remove show and unlock buttons from manager
+    manager.displayFrame.hiddenModeToggle:Hide();
+    manager.displayFrame.lockedModeToggle:Hide();
+end
+
+local hidden = false;
+local function hideBlizzardRaid()
+    if hidden then return end
+    hidden = true;
+    local function hide()
+        if InCombatLockdown() then return end
+        CompactRaidFrameContainer:Hide();
+        local shown = CompactRaidFrameManager_GetSetting("IsShown");
+        if shown and shown ~= "0" then
+            CompactRaidFrameManager_SetSetting("IsShown", "0");
+        end
+    end
+
+    CompactRaidFrameContainer:UnregisterAllEvents();
+    -- there may still be frames created at startup getting events
+    for i=1,MAX_RAID_MEMBERS do
+        local frame = _G["CompactRaidFrame"..i];
+        if not frame then break end
+        frame:UnregisterAllEvents();
+    end
+    hooksecurefunc("CompactRaidFrameManager_UpdateShown", hide);
+    hide();
+    CompactRaidFrameContainer:HookScript("OnShow", hide);
+    hooksecurefunc("CompactRaidFrameManager_UpdateOptionsFlowContainer", hideBlizzardRaidButton);
+    hideBlizzardRaidButton();
+
+    -- hide focus frame
+    for _, frame in pairs({FocusFrame, FocusFrameToT}) do
+        frame:UnregisterAllEvents();
+        frame.healthbar:UnregisterAllEvents();
+        frame.manabar:UnregisterAllEvents();
+        if frame.spellbar then frame.spellbar:UnregisterAllEvents() end
+        if frame.powerBarAlt then frame.powerBarAlt:UnregisterAllEvents() end
+        frame:Hide();
+    end
 end
 
-CFrame:RegisterEvent("ADDON_LOADED");
 CFrame:RegisterEvent("PLAYER_LOGIN");
-CFrame:SetScript("OnEvent", function(self, event)
+CFrame:RegisterEvent("PLAYER_REGEN_ENABLED");
+CFrame:SetScript("OnEvent", function(self, event, addon)
     if event == "PLAYER_LOGIN" then
-        initialize();
-    elseif event == "ADDON_LOADED" then
         OmaRFLoadChar();
-        loadCharSettings();
         OmaRFEvents.LoadChar();
         OmaRFIndicators.LoadChar();
+        hideBlizzardRaid();
+        initialize();
+    elseif event == "PLAYER_REGEN_ENABLED" then
+        -- if CompactRaidFrameManager_UpdateOptionsFlowContainer was called in combat
+        -- couldn't hide the button
+        hideBlizzardRaidButton();
     end
 end);