d76a52e - Change width/height to global setting
[wowui.git] / OmaRF / RaidFrame.lua
index cb2c3a2..783cdeb 100644 (file)
@@ -4,8 +4,11 @@ local unpack, pairs, rawget = unpack, pairs, rawget;
 local format = string.format;
 local UnitHealthMax, UnitPowerMax = UnitHealthMax, UnitPowerMax;
 local UnitInRange = UnitInRange;
 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 CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
 local STANDARD_TEXT_FONT = STANDARD_TEXT_FONT;
+local GameTooltip = nil;
+local GameTooltip_SetDefaultAnchor = nil;
 
 local registerEvents = OmaRFEvents.RegisterEvents;
 local unitEvent = OmaRFEvents.UnitEvent;
 
 local registerEvents = OmaRFEvents.RegisterEvents;
 local unitEvent = OmaRFEvents.UnitEvent;
@@ -19,9 +22,9 @@ local shieldColor = Settings.ShieldColor;
 local shieldhlColor = Settings.ShieldhlColor;
 local healpredColor = Settings.HealpredColor;
 local healabsorbColor = Settings.HealabsorbColor;
 local shieldhlColor = Settings.ShieldhlColor;
 local healpredColor = Settings.HealpredColor;
 local healabsorbColor = Settings.HealabsorbColor;
+local width, height = Settings.Width, Settings.Height;
 -- placeholders with visible values when error happens
 local positions = {};
 -- placeholders with visible values when error happens
 local positions = {};
-local width, height = 10, 10;
 local anchorX, anchorY = 10, 10;
 local attributes = {};
 
 local anchorX, anchorY = 10, 10;
 local attributes = {};
 
@@ -91,6 +94,10 @@ local function frameShow(frame)
     frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
     frame:RegisterEvent("GROUP_ROSTER_UPDATE");
     frame:RegisterEvent("PLAYER_ENTERING_WORLD");
     frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
     frame:RegisterEvent("GROUP_ROSTER_UPDATE");
     frame:RegisterEvent("PLAYER_ENTERING_WORLD");
+    frame:RegisterEvent("READY_CHECK");
+    frame:RegisterEvent("READY_CHECK_CONFIRM");
+    frame:RegisterEvent("READY_CHECK_FINISHED");
+    if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
     registerEvents(frame);
     frame:SetScript("OnUpdate", unitUpdate);
     unitEvent(frame, "UPDATE_ALL_BARS", frame.displayed);
     registerEvents(frame);
     frame:SetScript("OnUpdate", unitUpdate);
     unitEvent(frame, "UPDATE_ALL_BARS", frame.displayed);
@@ -101,6 +108,15 @@ local function frameHide(frame)
     frame:SetScript("OnUpdate", nil);
 end
 
     frame:SetScript("OnUpdate", nil);
 end
 
+local function showTooltip(frame)
+    GameTooltip_SetDefaultAnchor(GameTooltip, frame);
+    GameTooltip:SetUnit(frame:GetAttribute("unit"));
+end
+
+local function hideTooltip(frame)
+    GameTooltip:FadeOut();
+end
+
 local function setupFrame(frame, secure, unit)
     secure:SetAttribute("unit", unit);
     frame:SetAttribute("unit", unit);
 local function setupFrame(frame, secure, unit)
     secure:SetAttribute("unit", unit);
     frame:SetAttribute("unit", unit);
@@ -181,12 +197,21 @@ local function setupFrame(frame, secure, unit)
     frame.rez:SetPoint("BOTTOMRIGHT", frame.background, "CENTER", 12, -12);
     frame.rez:SetTexture("Interface\\RaidFrame\\Raid-Icon-Rez");
     frame.rez:Hide();
     frame.rez:SetPoint("BOTTOMRIGHT", frame.background, "CENTER", 12, -12);
     frame.rez:SetTexture("Interface\\RaidFrame\\Raid-Icon-Rez");
     frame.rez:Hide();
+    frame.ready = frame:CreateTexture(nil, "OVERLAY");
+    frame.ready:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 12);
+    frame.ready:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMLEFT", 12, 0);
+    frame.ready:Hide();
     -- set up indicators
     setupIndicators(frame);
     -- set scripts
     frame:SetScript("OnShow", frameShow);
     frame:SetScript("OnHide", frameHide);
     frame:SetScript("OnEvent", unitEvent);
     -- set up indicators
     setupIndicators(frame);
     -- set scripts
     frame:SetScript("OnShow", frameShow);
     frame:SetScript("OnHide", frameHide);
     frame:SetScript("OnEvent", unitEvent);
+    -- let other addons hook these to anchor tooltip elsewhere
+    GameTooltip = _G["GameTooltip"];
+    GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
+    secure:SetScript("OnEnter", showTooltip);
+    secure:SetScript("OnLeave", hideTooltip);
     -- set attributes
     secure:RegisterForClicks("AnyDown");
     for attr, val in pairs(attributes) do
     -- set attributes
     secure:RegisterForClicks("AnyDown");
     for attr, val in pairs(attributes) do
@@ -283,30 +308,93 @@ local function initializeRaid(parent)
     end
 end
 
     end
 end
 
+local function initializeFocus(parent)
+    local secure = CreateFrame("Button", "OmaFocusSecure", parent, inheritedFrames);
+    local frame = CreateFrame("Frame", "OmaFocus", parent);
+    local unit = "focus";
+    secure:SetPoint("BOTTOMLEFT", parent, "TOPLEFT");
+    frame:SetPoint("BOTTOMLEFT", parent, "TOPLEFT");
+    setupFrame(frame, secure, unit);
+    RegisterUnitWatch(frame);
+    RegisterUnitWatch(secure);
+    local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
+    RegisterStateDriver(secure, "vehicleui", vehicle);
+    secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
+end
+
+local function loadCharSettings()
+    anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
+    attributes = Settings.Character.Clickheal;
+    positions = Settings.Character.Positions;
+end
+
 local function initialize()
 local function initialize()
+    loadCharSettings();
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
     CFrame:SetWidth((width+2)*5+1);
     initializeParty(CFrame);
     initializeRaid(CFrame);
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
     CFrame:SetWidth((width+2)*5+1);
     initializeParty(CFrame);
     initializeRaid(CFrame);
+    initializeFocus(CFrame);
 end
 
 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
 
 end
 
-CFrame:RegisterEvent("ADDON_LOADED");
 CFrame:RegisterEvent("PLAYER_LOGIN");
 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
     if event == "PLAYER_LOGIN" then
-        initialize();
-    elseif event == "ADDON_LOADED" then
         OmaRFLoadChar();
         OmaRFLoadChar();
-        loadCharSettings();
-        OmaRFEvents.LoadChar();
         OmaRFIndicators.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);
     end
 end);