From b8dfa8569984caedd177d4e320255ddf0a0f0cc8 Mon Sep 17 00:00:00 2001 From: G G Date: Fri, 9 Aug 2024 11:32:27 -0400 Subject: [PATCH] Add functions for toggling spotlight frames --- RaidFrames/Groups/SpotlightFrame.lua | 46 +++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/RaidFrames/Groups/SpotlightFrame.lua b/RaidFrames/Groups/SpotlightFrame.lua index 1a8ffcfd..f2614850 100644 --- a/RaidFrames/Groups/SpotlightFrame.lua +++ b/RaidFrames/Groups/SpotlightFrame.lua @@ -398,6 +398,24 @@ function unit:SetUnit(index, target) F:Print(L["Invalid unit."]) end end +function spotlightFrame:ToggleUnit(target) + local firstAvailable + for i, f in pairs(Cell.unitButtons.spotlight) do + local unit = f:GetAttribute("unit") + if not unit and not firstAvailable then + firstAvailable = i + end + if unit and unit == target then + f:SetAttribute("unit", nil) + f:SetAttribute("refreshOnUpdate", nil) + f:SetAttribute("updateOnTargetChanged", nil) + assignmentButtons[i]:SetText("none") + menu:Save(i, nil) + return + end + end + unit:SetUnit(firstAvailable, target) +end unitname = Cell:CreateButton(menu, L["Unit's Name"], "transparent-accent", {20, 20}, true, false, nil, nil, "SecureHandlerAttributeTemplate,SecureHandlerClickTemplate") P:Point(unitname, "TOPLEFT", unit, "BOTTOMLEFT") @@ -431,6 +449,32 @@ function unitname:SetUnit(index, target) F:Print(L["Invalid unit."]) end end +function spotlightFrame:ToggleUnitName(target) + local unitId = F:GetTargetUnitID(target) + if unitId and (UnitIsPlayer(unitId) or UnitInPartyIsAI(unitId)) then + local name = GetUnitName(unitId, true) + local existing = names[name] + if existing then + local f = Cell.unitButtons.spotlight[existing] + f:SetAttribute("unit", nil) + f:SetAttribute("refreshOnUpdate", nil) + f:SetAttribute("updateOnTargetChanged", nil) + assignmentButtons[existing]:SetText("none") + menu:Save(existing, nil) + return + end + + for i, f in pairs(Cell.unitButtons.spotlight) do + local unit = f:GetAttribute("unit") + if not unit then + unitname:SetUnit(i, target) + return + end + end + else + F:Print(L["Invalid unit."]) + end +end unitpet = Cell:CreateButton(menu, L["Unit's Pet"], "transparent-accent", {20, 20}, true, false, nil, nil, "SecureHandlerAttributeTemplate,SecureHandlerClickTemplate") P:Point(unitpet, "TOPLEFT", unitname, "BOTTOMLEFT") @@ -982,4 +1026,4 @@ local function UpdateAppearance(which) end) end end -Cell:RegisterCallback("UpdateAppearance", "SpotlightFrame_UpdateAppearance", UpdateAppearance) \ No newline at end of file +Cell:RegisterCallback("UpdateAppearance", "SpotlightFrame_UpdateAppearance", UpdateAppearance)