9405379 - Add focus frame
[wowui.git] / OmaRF / RaidFrame.lua
index dc5a7a7..1f4bc87 100644 (file)
@@ -6,6 +6,8 @@ local UnitHealthMax, UnitPowerMax = UnitHealthMax, UnitPowerMax;
 local UnitInRange = UnitInRange;
 local CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
 local STANDARD_TEXT_FONT = STANDARD_TEXT_FONT;
 local UnitInRange = UnitInRange;
 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;
@@ -94,6 +96,7 @@ local function frameShow(frame)
     frame:RegisterEvent("READY_CHECK");
     frame:RegisterEvent("READY_CHECK_CONFIRM");
     frame:RegisterEvent("READY_CHECK_FINISHED");
     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);
@@ -104,6 +107,15 @@ 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"));
+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);
@@ -194,6 +206,11 @@ local function setupFrame(frame, secure, unit)
     frame:SetScript("OnShow", frameShow);
     frame:SetScript("OnHide", frameHide);
     frame:SetScript("OnEvent", unitEvent);
     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
@@ -290,12 +307,27 @@ 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 initialize()
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
     CFrame:SetWidth((width+2)*5+1);
     initializeParty(CFrame);
     initializeRaid(CFrame);
 local function initialize()
     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
 
 local function loadCharSettings()
 end
 
 local function loadCharSettings()