mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-09 19:57:33 +00:00
Drop named-unit frames and the pfValidUnits global
CreateUnitFrame and CreateCastbar could take a character name instead of a unit token, but every caller passes a token, so that mode and the empty-label guards around it were dead. The OnClick TargetByName branch could never run anyway: label was always a string, and "" is truthy. With that gone, the aggro scan was the only reader of pfValidUnits, so its unit list now lives in unitframes.lua and is built once at load. /focusname resolves the name with UnitTokenFromName (exact first, then prefix) instead of swapping the target and muting UIErrorsFrame.
This commit is contained in:
+51
-36
@@ -235,7 +235,50 @@ function pfUI.api.GetUnitStats(unitstr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local aggrodata = { }
|
local aggrodata = { }
|
||||||
local aggroScan = nil -- static { u, t, tt } triples, built once so the hot scan allocates nothing
|
|
||||||
|
-- every unit whose target or target's target UnitHasAggro checks, as static
|
||||||
|
-- { u, t, tt } triples so the hot scan allocates nothing
|
||||||
|
local aggroScan = { }
|
||||||
|
do
|
||||||
|
local function add(u)
|
||||||
|
local t = u .. "target"
|
||||||
|
table.insert(aggroScan, { u = u, t = t, tt = t .. "target" })
|
||||||
|
end
|
||||||
|
|
||||||
|
add("pet")
|
||||||
|
add("player")
|
||||||
|
add("target")
|
||||||
|
add("mouseover")
|
||||||
|
|
||||||
|
add("focus")
|
||||||
|
add("focustarget")
|
||||||
|
add("focustargettarget")
|
||||||
|
|
||||||
|
add("pettarget")
|
||||||
|
add("playertarget")
|
||||||
|
add("targettarget")
|
||||||
|
add("mouseovertarget")
|
||||||
|
add("targettargettarget")
|
||||||
|
|
||||||
|
for i=1,4 do
|
||||||
|
add("party" .. i)
|
||||||
|
add("party" .. i .. "target")
|
||||||
|
add("partypet" .. i)
|
||||||
|
add("partypet" .. i .. "target")
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1,40 do
|
||||||
|
add("raid" .. i)
|
||||||
|
add("raid" .. i .. "target")
|
||||||
|
|
||||||
|
add("raidpet" .. i)
|
||||||
|
add("raidpet" .. i .. "target")
|
||||||
|
|
||||||
|
add("nameplate" .. i)
|
||||||
|
add("nameplate" .. i .. "target")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function pfUI.api.UnitHasAggro(unit)
|
function pfUI.api.UnitHasAggro(unit)
|
||||||
local now = GetTime()
|
local now = GetTime()
|
||||||
local data = aggrodata[unit]
|
local data = aggrodata[unit]
|
||||||
@@ -250,16 +293,6 @@ function pfUI.api.UnitHasAggro(unit)
|
|||||||
data.state = 0
|
data.state = 0
|
||||||
|
|
||||||
if UnitExists(unit) and UnitIsFriend(unit, "player") then
|
if UnitExists(unit) and UnitIsFriend(unit, "player") then
|
||||||
-- pfValidUnits never changes after load, so precompute the "<u>target" /
|
|
||||||
-- "<u>targettarget" token strings once instead of concatenating per call.
|
|
||||||
if not aggroScan then
|
|
||||||
aggroScan = {}
|
|
||||||
for u in pairs(pfValidUnits) do
|
|
||||||
local t = u .. "target"
|
|
||||||
table.insert(aggroScan, { u = u, t = t, tt = t .. "target" })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, table.getn(aggroScan) do
|
for i = 1, table.getn(aggroScan) do
|
||||||
local s = aggroScan[i]
|
local s = aggroScan[i]
|
||||||
if UnitExists(s.t) and UnitIsUnit(s.t, unit) and UnitCanAttack(s.u, unit) then
|
if UnitExists(s.t) and UnitIsUnit(s.t, unit) and UnitCanAttack(s.u, unit) then
|
||||||
@@ -349,11 +382,10 @@ function pfUI.uf:UpdateVisibility()
|
|||||||
|
|
||||||
-- this runs for every frame five times a second, so only touch the
|
-- this runs for every frame five times a second, so only touch the
|
||||||
-- attribute when the unit actually changed
|
-- attribute when the unit actually changed
|
||||||
local unitstr = (self.label or "") .. (self.id or "")
|
local unitstr = self.label .. self.id
|
||||||
local unit = unitstr ~= "" and unitstr or nil
|
if unitstr ~= self.unitstr then
|
||||||
if unit ~= self.unitstr then
|
self.unitstr = unitstr
|
||||||
self.unitstr = unit
|
self:SetAttribute("unit", unitstr)
|
||||||
self:SetAttribute("unit", unit)
|
|
||||||
end
|
end
|
||||||
-- anything but "show"/"hide" means "show if the unit exists"
|
-- anything but "show"/"hide" means "show if the unit exists"
|
||||||
local visibility = "exists"
|
local visibility = "exists"
|
||||||
@@ -395,9 +427,7 @@ function pfUI.uf:UpdateVisibility()
|
|||||||
self:RegisterUnitEvents(visibility ~= "hide" and self.unitstr or nil)
|
self:RegisterUnitEvents(visibility ~= "hide" and self.unitstr or nil)
|
||||||
|
|
||||||
-- vanilla visibility
|
-- vanilla visibility
|
||||||
if self.unitname then
|
if visibility == "hide" then
|
||||||
self:Show()
|
|
||||||
elseif visibility == "hide" then
|
|
||||||
self:Hide()
|
self:Hide()
|
||||||
elseif visibility == "show" then
|
elseif visibility == "show" then
|
||||||
self:Show()
|
self:Show()
|
||||||
@@ -1246,8 +1276,6 @@ function pfUI.uf.OnUpdate()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not this.label or this.label == "" then return end
|
|
||||||
|
|
||||||
-- update portrait on first visible frame
|
-- update portrait on first visible frame
|
||||||
if this.portrait and this.portrait.model and this.portrait.model.update then
|
if this.portrait and this.portrait.model and this.portrait.model.update then
|
||||||
this.portrait.model.lastUnit = UnitName(this.portrait.model.update)
|
this.portrait.model.lastUnit = UnitName(this.portrait.model.update)
|
||||||
@@ -1334,11 +1362,7 @@ end
|
|||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
function pfUI.uf.OnClick()
|
function pfUI.uf.OnClick()
|
||||||
if not this.label and this.unitname then
|
pfUI.uf:ClickAction(arg1)
|
||||||
TargetByName(this.unitname, true)
|
|
||||||
else
|
|
||||||
pfUI.uf:ClickAction(arg1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function pfUI.uf:ClickAction(button)
|
function pfUI.uf:ClickAction(button)
|
||||||
@@ -1435,13 +1459,6 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick)
|
|||||||
f.config = config or pfUI_config.unitframes.fallback
|
f.config = config or pfUI_config.unitframes.fallback
|
||||||
f.tick = tick
|
f.tick = tick
|
||||||
|
|
||||||
-- disable events for unknown unitstrings
|
|
||||||
if not pfValidUnits[strlower(unit) .. id] then
|
|
||||||
f.unitname = unit
|
|
||||||
f.label, f.id = "", ""
|
|
||||||
f.RegisterEvent = function() return end
|
|
||||||
end
|
|
||||||
|
|
||||||
CreateBackdropShadow(f)
|
CreateBackdropShadow(f)
|
||||||
|
|
||||||
f.hp = CreateFrame("Frame",nil, f)
|
f.hp = CreateFrame("Frame",nil, f)
|
||||||
@@ -1558,9 +1575,7 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick)
|
|||||||
f:Hide()
|
f:Hide()
|
||||||
end
|
end
|
||||||
|
|
||||||
if f.label ~= "" then
|
f:SetAttribute("unit", f.label .. f.id)
|
||||||
f:SetAttribute("unit", f.label .. f.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- register frame for clique
|
-- register frame for clique
|
||||||
_G.ClickCastFrames = ClickCastFrames or {}
|
_G.ClickCastFrames = ClickCastFrames or {}
|
||||||
|
|||||||
Vendored
-35
@@ -13,38 +13,3 @@ pfGridmath = {
|
|||||||
[11] = {{11,1},{1,11}},
|
[11] = {{11,1},{1,11}},
|
||||||
[12] = {{12,1},{6,2},{4,3},{3,4},{2,6},{1,12}}
|
[12] = {{12,1},{6,2},{4,3},{3,4},{2,6},{1,12}}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- list of valid unitstrings
|
|
||||||
pfValidUnits = {}
|
|
||||||
pfValidUnits["pet"] = true
|
|
||||||
pfValidUnits["player"] = true
|
|
||||||
pfValidUnits["target"] = true
|
|
||||||
pfValidUnits["mouseover"] = true
|
|
||||||
|
|
||||||
pfValidUnits["focus"] = true
|
|
||||||
pfValidUnits["focustarget"] = true
|
|
||||||
pfValidUnits["focustargettarget"] = true
|
|
||||||
|
|
||||||
pfValidUnits["pettarget"] = true
|
|
||||||
pfValidUnits["playertarget"] = true
|
|
||||||
pfValidUnits["targettarget"] = true
|
|
||||||
pfValidUnits["mouseovertarget"] = true
|
|
||||||
pfValidUnits["targettargettarget"] = true
|
|
||||||
|
|
||||||
for i=1,4 do
|
|
||||||
pfValidUnits["party" .. i] = true
|
|
||||||
pfValidUnits["party" .. i .. "target"] = true
|
|
||||||
pfValidUnits["partypet" .. i] = true
|
|
||||||
pfValidUnits["partypet" .. i .. "target"] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
for i=1,40 do
|
|
||||||
pfValidUnits["raid" .. i] = true
|
|
||||||
pfValidUnits["raid" .. i .. "target"] = true
|
|
||||||
|
|
||||||
pfValidUnits["raidpet" .. i] = true
|
|
||||||
pfValidUnits["raidpet" .. i .. "target"] = true
|
|
||||||
|
|
||||||
pfValidUnits["nameplate" .. i] = true
|
|
||||||
pfValidUnits["nameplate" .. i .. "target"] = true
|
|
||||||
end
|
|
||||||
|
|||||||
+6
-11
@@ -150,8 +150,8 @@ pfUI:RegisterModule("castbar", function ()
|
|||||||
-- One-shot poll: read C_Spell for the bar's unit, stamp or clear. Called
|
-- One-shot poll: read C_Spell for the bar's unit, stamp or clear. Called
|
||||||
-- from event handlers (cast start, target/focus change), never per-frame.
|
-- from event handlers (cast start, target/focus change), never per-frame.
|
||||||
local function RefreshBar(cb, rank)
|
local function RefreshBar(cb, rank)
|
||||||
local query = cb.unitstr ~= "" and cb.unitstr or cb.unitname
|
local query = cb.unitstr
|
||||||
if not query or (cb.unitstr ~= "" and not UnitExists(cb.unitstr)) then
|
if not UnitExists(query) then
|
||||||
ClearBar(cb)
|
ClearBar(cb)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -178,7 +178,7 @@ pfUI:RegisterModule("castbar", function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function CreateCastbar(name, parent, unitstr, unitname)
|
local function CreateCastbar(name, parent, unitstr)
|
||||||
local cb = CreateFrame("Frame", name, parent or UIParent)
|
local cb = CreateFrame("Frame", name, parent or UIParent)
|
||||||
|
|
||||||
cb:SetHeight(C.global.font_size * 1.5)
|
cb:SetHeight(C.global.font_size * 1.5)
|
||||||
@@ -186,7 +186,6 @@ pfUI:RegisterModule("castbar", function ()
|
|||||||
cb:SetFrameLevel(8)
|
cb:SetFrameLevel(8)
|
||||||
|
|
||||||
cb.unitstr = unitstr
|
cb.unitstr = unitstr
|
||||||
cb.unitname = unitname
|
|
||||||
|
|
||||||
-- icon
|
-- icon
|
||||||
cb.icon = CreateFrame("Frame", nil, cb)
|
cb.icon = CreateFrame("Frame", nil, cb)
|
||||||
@@ -277,7 +276,7 @@ pfUI:RegisterModule("castbar", function ()
|
|||||||
|
|
||||||
-- Non-player bars: if the unit disappears (target died / detarget),
|
-- Non-player bars: if the unit disappears (target died / detarget),
|
||||||
-- drop the bar immediately.
|
-- drop the bar immediately.
|
||||||
if this.unitstr ~= "" and this.unitstr ~= "player" and not UnitExists(this.unitstr) then
|
if this.unitstr ~= "player" and not UnitExists(this.unitstr) then
|
||||||
ClearBar(this)
|
ClearBar(this)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -423,13 +422,12 @@ pfUI:RegisterModule("castbar", function ()
|
|||||||
-- endMs. delay is a positive magnitude; OnUpdate signs it "+" for casts
|
-- endMs. delay is a positive magnitude; OnUpdate signs it "+" for casts
|
||||||
-- and "-" for channels. Skipped during a tradeskill merge.
|
-- and "-" for channels. Skipped during a tradeskill merge.
|
||||||
if this.endTime and not this.tradeskillTotal then
|
if this.endTime and not this.tradeskillTotal then
|
||||||
local query = this.unitstr ~= "" and this.unitstr or this.unitname
|
|
||||||
local startMs, endMs
|
local startMs, endMs
|
||||||
if this.isChannel then
|
if this.isChannel then
|
||||||
local _, _, _, s, e = C_Spell.UnitChannelInfo(query)
|
local _, _, _, s, e = C_Spell.UnitChannelInfo(unit)
|
||||||
startMs, endMs = s, e
|
startMs, endMs = s, e
|
||||||
else
|
else
|
||||||
local _, _, _, s, e = C_Spell.UnitCastingInfo(query)
|
local _, _, _, s, e = C_Spell.UnitCastingInfo(unit)
|
||||||
startMs, endMs = s, e
|
startMs, endMs = s, e
|
||||||
end
|
end
|
||||||
if startMs and endMs then
|
if startMs and endMs then
|
||||||
@@ -544,9 +542,6 @@ pfUI:RegisterModule("castbar", function ()
|
|||||||
pfUI.castbar.focus:SetHeight(C.castbar.focus.height)
|
pfUI.castbar.focus:SetHeight(C.castbar.focus.height)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- bind castbar to the "focus" unit token; the GUID resolves at read time
|
|
||||||
pfUI.castbar.focus.unitstr = "focus"
|
|
||||||
|
|
||||||
UpdateMovable(pfUI.castbar.focus)
|
UpdateMovable(pfUI.castbar.focus)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
+5
-28
@@ -29,38 +29,15 @@ pfUI:RegisterModule("focus", function ()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- /focus and /clearfocus live in ClassicAPI's SlashCommandsRegistry now.
|
-- /focus and /clearfocus live in ClassicAPI's SlashCommandsRegistry now.
|
||||||
-- /focusname is pfUI-specific because the engine has no name→GUID
|
-- `/focus Name` takes the nearest prefix match; /focusname tries the exact
|
||||||
-- lookup for off-screen units — we resolve via a short target-swap.
|
-- name first, so "Bob" still wins over a nearer "Bobby".
|
||||||
|
|
||||||
pfUI.api.RegisterSlashCommand("PFFOCUSNAME", { '/focusname', '/pffocusname' }, function(msg)
|
pfUI.api.RegisterSlashCommand("PFFOCUSNAME", { '/focusname', '/pffocusname' }, function(msg)
|
||||||
if msg == "" then return end
|
if msg == "" then return end
|
||||||
|
|
||||||
local prevGUID = UnitGUID("target")
|
local unit = UnitTokenFromName(msg, true) or UnitTokenFromName(msg)
|
||||||
local prevPlayer = UnitIsUnit("target", "player")
|
if unit then
|
||||||
|
FocusUnit(unit)
|
||||||
-- Suppress async "Unknown unit" errors fired by TargetByName misses.
|
|
||||||
UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE")
|
|
||||||
|
|
||||||
-- Try exact match first, then prefix match via /target.
|
|
||||||
TargetByName(msg, true)
|
|
||||||
if not UnitExists("target") then
|
|
||||||
SlashCmdList.TARGET(msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
if UnitExists("target") then
|
|
||||||
FocusUnit("target")
|
|
||||||
end
|
|
||||||
|
|
||||||
RunNextFrame(function()
|
|
||||||
UIErrorsFrame:RegisterEvent("UI_ERROR_MESSAGE")
|
|
||||||
end)
|
|
||||||
|
|
||||||
if prevGUID and prevGUID ~= "0x0000000000000000" then
|
|
||||||
TargetUnit(prevGUID)
|
|
||||||
elseif prevPlayer then
|
|
||||||
TargetUnit("player")
|
|
||||||
else
|
|
||||||
ClearTarget()
|
|
||||||
end
|
end
|
||||||
end, true)
|
end, true)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user