Classic API Focus (#2)

* focus: migrate to FocusUnit / "focus" token / PLAYER_FOCUS_CHANGED

ClassicAPI now polyfills modern WoW's focus system: FocusUnit / ClearFocus
+ "focus" / "focustarget" unit tokens accepted by every UnitX function +
PLAYER_FOCUS_CHANGED event. Drop pfUI's GUID-juggling pseudo-frame.

- env/tables.lua: add "focus" and "focustarget" to pfValidUnits — the
  focus frames now follow the standard event-driven CreateUnitFrame path
  with f.label = "focus"
- modules/focus.lua: rewrite. Slash commands use FocusUnit / ClearFocus
  directly; no more manual frame.label/unitname/id manipulation. /focus
  <name> still does a target-swap to resolve names → units, then
  FocusUnit("target") captures the GUID before the target is restored.
  PLAYER_FOCUS_CHANGED triggers immediate frame refresh on assign/clear.
- api/unitframes.lua: delete the pseudo-focus block (per-tick "scan all
  units for matching name" loop) and the "focus"/"focustarget" special-
  case in the visibility branch — "focus" is now a real token.
- modules/castbar.lua: bind the focus castbar to unitstr = "focus" once;
  drop the OnUpdate that synced pfUI.castbar.focus from
  pfUI.uf.focus.label/unitname. UnitGUID("focus") resolves at read time.
- Drop C_Minimap.SetFocusByGUID / SetFocusByName / ClearFocus calls —
  C_Minimap subscribes to PLAYER_FOCUS_CHANGED on its own.

Net -183 lines. Focus stops being a pfUI-special pseudo-frame and
becomes "just another unit token" — same treatment as target/player.

* add nameplate to valid units

---------

Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com>
This commit is contained in:
brues-code
2026-05-27 20:35:15 -05:00
committed by GitHub
co-authored by Brues
parent f8b4b5b5a3
commit f0d9dca63f
4 changed files with 89 additions and 266 deletions
+2 -28
View File
@@ -390,9 +390,6 @@ pfUI:RegisterModule("castbar", function ()
pfUI.castbar.focus.showrank = C.castbar.focus.showrank == "1" and true or nil
pfUI.castbar.focus.spacing = default_border * 2 + tonumber(C.unitframes.focus.pspace) * GetPerfectPixel()
-- reset unitstr for vanilla focus frame emulation
pfUI.castbar.focus.unitstr = nil
local anchor = pfUI.uf.focus.portrait:GetHeight() > pfUI.uf.focus:GetHeight() and pfUI.uf.focus.power or pfUI.uf.focus
local width = C.castbar.focus.width ~= "-1" and C.castbar.focus.width or anchor:GetWidth()
pfUI.castbar.focus:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -pfUI.castbar.focus.spacing)
@@ -402,31 +399,8 @@ pfUI:RegisterModule("castbar", function ()
pfUI.castbar.focus:SetHeight(C.castbar.focus.height)
end
-- keep unit values in sync with focus unitframe
HookScript(pfUI.castbar.focus, "OnUpdate", function()
-- clear on empty focus frames
if pfUI.uf.focus.unitname == nil and pfUI.uf.focus.label == nil then
pfUI.castbar.focus.unitstr = nil
pfUI.castbar.focus.unitname = nil
return
end
-- skip on initial values
if pfUI.uf.focus.unitname == "focus" then return end
if pfUI.uf.focus.unitname == "" then return end
-- try to obtain a unitstr
pfUI.castbar.focus.unitstr = string.format("%s%s", (pfUI.uf.focus.label or ""), (pfUI.uf.focus.id or ""))
pfUI.castbar.focus.unitstr = pfUI.castbar.focus.unitstr == "" and nil or pfUI.castbar.focus.unitstr
if pfUI.castbar.focus.unitstr then
-- read non-lowercase unitname when possible
pfUI.castbar.focus.unitname = UnitName(pfUI.castbar.focus.unitstr) or pfUI.castbar.focus.unitname
elseif strlower(pfUI.castbar.focus.unitname) ~= strlower(pfUI.uf.focus.unitname) then
-- sync unitname with focus frame's lowercase value
pfUI.castbar.focus.unitname = pfUI.uf.focus.unitname
end
end)
-- bind castbar to the "focus" unit token; the GUID resolves at read time
pfUI.castbar.focus.unitstr = "focus"
UpdateMovable(pfUI.castbar.focus)
end