a88a019 - Add TellMeWhen replacement
[wowui.git] / OmaRF / RaidFrame.lua
index 4259c67..3cde21c 100644 (file)
@@ -1,8 +1,7 @@
 -- RaidFrame.lua
 local _;
 -- RaidFrame.lua
 local _;
-local unpack, pairs, rawget = unpack, pairs, rawget;
+local unpack, pairs = unpack, pairs;
 local format = string.format;
 local format = string.format;
-local UnitHealthMax, UnitPowerMax = UnitHealthMax, UnitPowerMax;
 local UnitInRange = UnitInRange;
 local InCombatLockdown = InCombatLockdown;
 local CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
 local UnitInRange = UnitInRange;
 local InCombatLockdown = InCombatLockdown;
 local CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
@@ -11,10 +10,11 @@ local GameTooltip = nil;
 local GameTooltip_SetDefaultAnchor = nil;
 
 local registerEvents = OmaRFEvents.RegisterEvents;
 local GameTooltip_SetDefaultAnchor = nil;
 
 local registerEvents = OmaRFEvents.RegisterEvents;
+local registerUnitEvents = OmaRFEvents.RegisterUnitEvents;
 local unitEvent = OmaRFEvents.UnitEvent;
 local unitEvent = OmaRFEvents.UnitEvent;
+local setupIndicators = OmaRFIndicators.SetupIndicators;
 
 local Settings = OmaRFSettings;
 
 local Settings = OmaRFSettings;
-local indSize = Settings.IndSize;
 local baseColor = Settings.BaseColor;
 local bgColor = Settings.BgColor;
 local healthColor = Settings.HealthColor;
 local baseColor = Settings.BaseColor;
 local bgColor = Settings.BgColor;
 local healthColor = Settings.HealthColor;
@@ -22,85 +22,37 @@ 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
 -- placeholders with visible values when error happens
-local positions = {};
-local width, height = 10, 10;
 local anchorX, anchorY = 10, 10;
 local attributes = {};
 
 local CFrame = CreateFrame("Frame", "OmaRFFrame", UIParent);
 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
 local anchorX, anchorY = 10, 10;
 local attributes = {};
 
 local CFrame = CreateFrame("Frame", "OmaRFFrame", UIParent);
 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
+local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist";
+local class = nil;
 local party = {};
 local raid = {};
 
 local M = {};
 OmaRaidFrame = M;
 
 local party = {};
 local raid = {};
 
 local M = {};
 OmaRaidFrame = M;
 
-local function setupIndicators(frame)
-    frame.inds = CreateFrame("Frame", nil, frame);
-    frame.inds:SetAllPoints();
-    frame.inds:Hide();
-    for _, pos in pairs(positions) do
-        frame.inds[pos] = frame.inds:CreateTexture(nil, "OVERLAY");
-        frame.inds[pos]:SetPoint(pos, frame.inds, pos);
-        frame.inds[pos]:SetWidth(indSize);
-        frame.inds[pos]:SetHeight(indSize);
-        frame.inds[pos]:SetTexture("Interface\\AddOns\\OmaRF\\images\\rhomb");
-        frame.inds[pos]:SetVertexColor(1, 0, 0);
-        frame.inds[pos]:Hide();
-        frame.inds[pos].text = frame.inds:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
-        frame.inds[pos].text:SetPoint("BOTTOMRIGHT", frame.inds[pos], "BOTTOMRIGHT");
-        frame.inds[pos].text:Hide();
-    end
-    frame.major = CreateFrame("Frame", nil, frame);
-    frame.major:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -indSize + 4);
-    frame.major:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT");
-    for i = 1,3 do
-        frame.major[i] = frame.major:CreateTexture(nil, "OVERLAY");
-        if i == 1 then
-            frame.major[i]:SetPoint("TOPLEFT", frame.major, "TOPLEFT");
-        else
-            frame.major[i]:SetPoint("TOPLEFT", frame.major[i-1], "TOPRIGHT");
-        end
-        frame.major[i]:SetWidth(indSize*2);
-        frame.major[i]:SetHeight(indSize*2);
-        frame.major[i]:Hide();
-        frame.major[i].text = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
-        frame.major[i].text:SetPoint("BOTTOMRIGHT", frame.major[i], "BOTTOMRIGHT");
-        frame.major[i].text:Hide();
-        frame.major[i].stack = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
-        frame.major[i].stack:SetPoint("TOPLEFT", frame.major[i], "TOPLEFT");
-        frame.major[i].stack:Hide();
-    end
-end
-
-local function unitUpdate(self, elapsed)
+local function unitUpdate(frame)
     -- there's no in/out of range event, have to check each frame
     -- from FrameXML/CompactUnitFrame.lua
     -- there's no in/out of range event, have to check each frame
     -- from FrameXML/CompactUnitFrame.lua
-    local inRange, checked = UnitInRange(self.displayed);
+    local inRange, checked = UnitInRange(frame.displayed);
     if checked and not inRange then
     if checked and not inRange then
-        self:SetAlpha(0.55);
+        frame:SetAlpha(0.55);
     else
     else
-        self:SetAlpha(1);
+        frame:SetAlpha(1);
     end
 end
 
 local function frameShow(frame)
     end
 end
 
 local function frameShow(frame)
-    frame:RegisterEvent("PARTY_MEMBER_ENABLE");
-    frame:RegisterEvent("PARTY_MEMBER_DISABLE");
-    frame:RegisterEvent("UNIT_ENTERED_VEHICLE");
-    frame:RegisterEvent("UNIT_EXITED_VEHICLE");
-    frame:RegisterEvent("UNIT_PET");
-    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);
     registerEvents(frame);
+    registerUnitEvents(frame);
     frame:SetScript("OnUpdate", unitUpdate);
     frame:SetScript("OnUpdate", unitUpdate);
-    unitEvent(frame, "UPDATE_ALL_BARS", frame.displayed);
+    unitEvent(frame, "UPDATE_ALL_BARS");
 end
 
 local function frameHide(frame)
 end
 
 local function frameHide(frame)
@@ -108,12 +60,12 @@ local function frameHide(frame)
     frame:SetScript("OnUpdate", nil);
 end
 
     frame:SetScript("OnUpdate", nil);
 end
 
-local function showTooltip(frame)
-    GameTooltip_SetDefaultAnchor(GameTooltip, PlayerFrame);
-    GameTooltip:SetUnit(frame:GetAttribute("unit"));
+local function showTooltip(secure)
+    GameTooltip_SetDefaultAnchor(GameTooltip, secure);
+    GameTooltip:SetUnit(secure:GetAttribute("unit"));
 end
 
 end
 
-local function hideTooltip(frame)
+local function hideTooltip(secure)
     GameTooltip:FadeOut();
 end
 
     GameTooltip:FadeOut();
 end
 
@@ -124,11 +76,8 @@ local function setupFrame(frame, secure, unit)
     frame.displayed = unit;
     -- hide frame to get initial frameShow call
     frame:Hide();
     frame.displayed = unit;
     -- hide frame to get initial frameShow call
     frame:Hide();
-    if unit == "player" then
-        frame.vehicle = "vehicle";
-    else
-        frame.vehicle = unit.."pet";
-    end
+    if unit == "player" then frame.vehicle = "vehicle"
+    else frame.vehicle = unit.."pet" end
     -- create visuals
     secure:SetWidth(width+2);
     secure:SetHeight(height+2);
     -- create visuals
     secure:SetWidth(width+2);
     secure:SetHeight(height+2);
@@ -143,22 +92,20 @@ local function setupFrame(frame, secure, unit)
     frame.background:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
     frame.background:SetColorTexture(unpack(bgColor));
     frame.health = frame:CreateTexture(nil, "BORDER");
     frame.background:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
     frame.background:SetColorTexture(unpack(bgColor));
     frame.health = frame:CreateTexture(nil, "BORDER");
-    frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
+    frame.health:SetTexture(barTexture);
     frame.health:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
     frame.health:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
-    frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
+    frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
     frame.health:SetVertexColor(unpack(healthColor));
     frame.health:SetVertexColor(unpack(healthColor));
-    frame.health:SetWidth(width);
-    frame.health.max = UnitHealthMax(unit);
     frame.mana = frame:CreateTexture(nil, "BORDER");
     frame.mana:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 2);
     frame.mana:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
     frame.mana:SetColorTexture(1, 1, 1);
     frame.mana = frame:CreateTexture(nil, "BORDER");
     frame.mana:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 2);
     frame.mana:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
     frame.mana:SetColorTexture(1, 1, 1);
-    frame.mana:SetWidth(width);
-    frame.mana.max = UnitPowerMax(unit);
+    frame.mana:Hide();
     frame.shield = frame:CreateTexture(nil, "BORDER");
     frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
     frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
     frame.shield = frame:CreateTexture(nil, "BORDER");
     frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
     frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
-    frame.shield:SetColorTexture(unpack(shieldColor));
+    frame.shield:SetTexture(barTexture);
+    frame.shield:SetVertexColor(unpack(shieldColor));
     frame.shield:Hide();
     frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
     frame.shieldhl:SetPoint("TOPLEFT", frame.background, "TOPRIGHT", -1, 0);
     frame.shield:Hide();
     frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
     frame.shieldhl:SetPoint("TOPLEFT", frame.background, "TOPRIGHT", -1, 0);
@@ -178,12 +125,11 @@ local function setupFrame(frame, secure, unit)
     frame.role = frame:CreateTexture(nil, "ARTWORK");
     frame.role:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", -2, 2);
     frame.role:SetPoint("TOPLEFT", frame.background, "BOTTOMRIGHT", -14, 14);
     frame.role = frame:CreateTexture(nil, "ARTWORK");
     frame.role:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", -2, 2);
     frame.role:SetPoint("TOPLEFT", frame.background, "BOTTOMRIGHT", -14, 14);
-    frame.role:SetTexCoord(0.75, 1, 0, 1);
     frame.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
     frame.role:Hide();
     frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
     frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
     frame.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
     frame.role:Hide();
     frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
     frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
-    frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
+    frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT");
     frame.overlay:SetColorTexture(1, 1, 1);
     frame.overlay:Hide();
     frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
     frame.overlay:SetColorTexture(1, 1, 1);
     frame.overlay:Hide();
     frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
@@ -198,18 +144,21 @@ local function setupFrame(frame, secure, unit)
     frame.rez:SetTexture("Interface\\RaidFrame\\Raid-Icon-Rez");
     frame.rez:Hide();
     frame.ready = frame:CreateTexture(nil, "OVERLAY");
     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:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 14);
+    frame.ready:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMLEFT", 14, 0);
     frame.ready:Hide();
     frame.ready:Hide();
+    frame.targeticon = frame:CreateTexture(nil, "OVERLAY");
+    frame.targeticon:SetPoint("CENTER", frame.background, "TOP");
+    frame.targeticon:SetWidth(12);
+    frame.targeticon:SetHeight(12);
+    frame.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
+    frame.targeticon:Hide();
     -- set up indicators
     -- set up indicators
-    setupIndicators(frame);
+    setupIndicators(frame, class);
     -- set scripts
     frame:SetScript("OnShow", frameShow);
     frame:SetScript("OnHide", frameHide);
     frame:SetScript("OnEvent", unitEvent);
     -- 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:SetScript("OnEnter", showTooltip);
     secure:SetScript("OnLeave", hideTooltip);
     -- set attributes
@@ -322,18 +271,17 @@ local function initializeFocus(parent)
     secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
 end
 
     secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
 end
 
-local function loadCharSettings()
-    width, height = Settings.Character.Width, Settings.Character.Height;
+local function initialize()
+    -- let other addons hook these to anchor tooltip elsewhere
+    GameTooltip = _G["GameTooltip"];
+    GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
+    _, class = UnitClass("player");
     anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
     attributes = Settings.Character.Clickheal;
     anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
     attributes = Settings.Character.Clickheal;
-    positions = Settings.Character.Positions;
-end
-
-local function initialize()
-    loadCharSettings();
+    CFrame:SetFrameStrata("LOW");
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
-    CFrame:SetWidth((width+2)*5+1);
+    CFrame:SetWidth((width+2)*5);
     initializeParty(CFrame);
     initializeRaid(CFrame);
     initializeFocus(CFrame);
     initializeParty(CFrame);
     initializeRaid(CFrame);
     initializeFocus(CFrame);
@@ -375,10 +323,10 @@ local function hideBlizzardRaid()
     hideBlizzardRaidButton();
 
     -- hide focus frame
     hideBlizzardRaidButton();
 
     -- hide focus frame
-    for _, frame in pairs({FocusFrame, FocusFrameToT}) do
+    for _, frame in pairs({FocusFrame, FocusFrameToT, FocusFrameSpellBar}) do
         frame:UnregisterAllEvents();
         frame:UnregisterAllEvents();
-        frame.healthbar:UnregisterAllEvents();
-        frame.manabar:UnregisterAllEvents();
+        if frame.healthbar then frame.healthbar:UnregisterAllEvents() end
+        if frame.manabar then frame.manabar:UnregisterAllEvents() end
         if frame.spellbar then frame.spellbar:UnregisterAllEvents() end
         if frame.powerBarAlt then frame.powerBarAlt:UnregisterAllEvents() end
         frame:Hide();
         if frame.spellbar then frame.spellbar:UnregisterAllEvents() end
         if frame.powerBarAlt then frame.powerBarAlt:UnregisterAllEvents() end
         frame:Hide();
@@ -390,8 +338,6 @@ CFrame:RegisterEvent("PLAYER_REGEN_ENABLED");
 CFrame:SetScript("OnEvent", function(self, event, addon)
     if event == "PLAYER_LOGIN" then
         OmaRFLoadChar();
 CFrame:SetScript("OnEvent", function(self, event, addon)
     if event == "PLAYER_LOGIN" then
         OmaRFLoadChar();
-        OmaRFEvents.LoadChar();
-        OmaRFIndicators.LoadChar();
         hideBlizzardRaid();
         initialize();
     elseif event == "PLAYER_REGEN_ENABLED" then
         hideBlizzardRaid();
         initialize();
     elseif event == "PLAYER_REGEN_ENABLED" then