mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-25 09:06:03 +00:00
00292ca3b4
commit70b1e66c2dAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Sun Jul 26 18:30:18 2026 -0500 Use SetSize/SetShown and simplify minimap/map commit7b6bfe9975Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 11:27:14 2026 -0500 Include raidpet frames in /pftest test mode The unit-frame test toggle (showall) only previews frames that exist and are positioned. Raidpet frames are created when raidpet.visible == "1", but LayoutPets' collapse mode only positions pets whose raidpet<N> unit actually exists, so solo/in test mode they stayed hidden. Add a showall branch to LayoutPets that mirror-lays every pet cell and shows it (bypassing collapse and the roster gate), still guarded by the existing showpets check so nothing happens when raidpet is disabled. Call LayoutPets from the /pftest handler so the grid updates immediately on toggle-on and restores to the normal layout on toggle-off. commit4c65c38647Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 10:34:33 2026 -0500 Remove unused RangeCache local in UnitInRange commit6c96bbbe6cAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 10:34:33 2026 -0500 Use Clamp() for the two-sided clamps in ui-widgets Replace the hand-rolled math.min/math.max and if/elseif clamp idioms in the status bar and scroll frame with Clamp(). Equivalent for every value seen (min <= max always holds), just clearer. commit830e0a0be1Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 10:34:33 2026 -0500 Drop vanilla GetItemInfo shim for C_Item.GetItemInfo The compat/vanilla.lua GetItemInfo override reshaped vanilla's tuple into retail order by inserting nil at slot 4 (itemLevel), but truncated at 8 fields, dropping itemEquipLoc/itemTexture. ClassicAPI's global GetItemInfo keeps the vanilla shape (its hook only warms the item cache), so the shim stayed necessary but incomplete. Remove it and point the three callers at ClassicAPI's C_Item.GetItemInfo, which returns the full 18-field retail tuple. Positions 1-8 are identical to the old shim output, so bags/roll are unchanged; character.lua's itemSlot (equipLoc, field 9) was always nil under the truncating shim and now resolves correctly for ShaguScore. commitc0da63657dAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 10:09:34 2026 -0500 Various cleanup Removes version compatibility checks for TBC/Vanilla, consolidating code to target a single WoW version. Refactors repetitive SetWidth/SetHeight calls to SetSize for cleaner code. Removes duplicate function definitions from unitxp module and simplifies conditional show/hide operations using SetShown. commit11a6302c2dAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 09:53:37 2026 -0500 Delegate pfUI.api.strsplit to ClassicAPI's strsplit Replace the Lua pattern-based implementation with a thin wrapper around ClassicAPI's C-level strsplit. Keeps the pfUI.api.strsplit entry point for backwards compatibility with addons that call it, while dropping the redundant reimplementation. Behavioral note: the old version used ([^delim]+) which silently collapsed empty fields; delegating to real strsplit now preserves them ("a,,b" -> "a", "", "b"). All in-repo callers split numeric color tuples, version strings, or build name-keyed lookup tables, none of which are affected by empty-field preservation. commit67c126eac8Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 01:01:02 2026 -0500 Bump ClassicAPI minimum version to 1.8.0 commita6cf157518Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 00:49:50 2026 -0500 read spell rank via C_Spell.GetSpellSubtext The rank string comes from the spell subtext ("Rank N"), which ClassicAPI's C_Spell.GetSpellSubtext returns directly -- so drop nampower's GetSpellRecField(spellId, "rank") here. The existing "Rank " gsub parse is unchanged. commit4b1ba99b4fAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 00:33:20 2026 -0500 Move player info overlay onto ClassicAPI (drop Nampower) The haste/spell-power overlay read both values through Nampower and disabled itself entirely without it. Move both to ClassicAPI so it works on any ClassicAPI client: - Spell power: GetSpellPower("net") (nampower) -> GetSpellBonusDamage(i) (ClassicAPI, same per-school field). Merged the build+scan into one loop; the default school seeds the tiebreak so equal schools still favor it. - Haste: GetUnitField("player", "modCastSpeed") -> UnitSpellHaste("player"), which returns the haste percentage directly (the (1/modCastSpeed-1)*100 conversion is now baked in, off the same UNIT_MOD_CAST_SPEED field, signed). - Dropped the "if not GetUnitField then return" gate -- UpdateInfoText no longer touches Nampower, so the overlay runs everywhere. commit7df4aa6d50Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat Jul 25 00:32:44 2026 -0500 Hook the real global _G.UnitHealth for feign death Inside a RegisterModule body, `function UnitHealth(...)` defines UnitHealth on the pfUI environment, not the real global -- so the feign-death real-HP fix only reached callers that resolve UnitHealth through pfUI's env, and missed _G consumers (Blizzard frames, other addons). Hook _G.UnitHealth explicitly (and capture oldUnitHealth from _G) so the un-gate applies everywhere. commitb0bf2fd869Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri Jul 24 21:10:58 2026 -0500 Refactor nampower module Simplify reactive spell storage by using spell IDs instead of texture/name tables. Update to use modern C_Spell APIs (GetSpellTexture, GetSpellName) instead of manual texture paths. Consolidate SetWidth/SetHeight calls to SetSize and use print() instead of DEFAULT_CHAT_FRAME:AddMessage(). commit0b06961333Author: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri Jul 24 20:54:23 2026 -0500 Use GetNamePlateForUnit for target lookups; drop dead ScanGuid block - Replace the three GetNamePlateForGUID(UnitGUID("target")) round-trips with GetNamePlateForUnit("target"), which resolves the token to a GUID internally -- no UnitGUID string detour, and it returns nil for no-target/no-plate so the UnitExists guards collapse. GetNamePlateForGUID is left for raw-GUID cases. - Remove the dead libunitscan.ScanGuid nameplate block (ScanGuid was deleted from libunitscan long ago, so the guard was never true) -- it carried the last GetUnitField("npcFlags") read. commit3e6210086eAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri Jul 24 20:54:23 2026 -0500 Drop Nampower stats system and polling from unit frames GetUnitStats now reads health/power straight from UnitHealth/UnitPower (the descriptor fields the server broadcasts) -- for a real unit token GetUnitField read nothing different, so the whole Nampower-vs-fallback apparatus was measuring a distinction that no longer exists. Removed: - The stats system: pfUI.uf.stats, pfUIStatsFrame + UpdateStatsDisplay, the lastUnitStats change-cache, the /pfuistats slash command, and every counter increment (event/heartbeat/earlyReturn/throttledSkip/nampower/fallback). - All GetUnitField health reads (GetUnitStats, heal-prediction, health-gradient color) -- collapsed to the UnitHealth/UnitHealthMax they already fell back to. - The heartbeat-polling backstop and its fallbackThrottle/lastEventUpdate deps. Frames now refresh on events only; eventless frames still use their own tick, and range/aggro still run in the eventless-actions block. commit63001b7b0cAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri Jul 24 20:09:42 2026 -0500 Move nameplates onto ClassicAPI stable nameplate tokens ClassicAPI now assigns retail-exact, per-plate-stable "nameplateN" tokens and fires vanilla UNIT_* events for them, so the nameplate module can key off the token instead of Nampower/SuperWoW GUID primitives: - Events: UNIT_AURA_GUID/UNIT_FLAGS_GUID -> UNIT_AURA/UNIT_FLAGS, matched by the "nameplateN" token (guarded on the token prefix, since these also fire for target/party/raid). Registered unconditionally -- no GetUnitField gate. - Health: GetUnitField(guid, "health"/"maxHealth") -> UnitHealth/UnitHealthMax on the plate's cached token. Same UNIT_FIELD_HEALTH the server broadcasts (real HP on Turtle; the ~= 100 scaled-vs-real guard is unchanged). - Combat/target in GetCombatStateColor: GetUnitField("flags") + HasFlag -> UnitAffectingCombat(token); GetUnitField("target") + SuperWoW "<guid>target" -> the "nameplateNtarget" chain. Dropped the now-dead HasFlag, UNIT_FLAG_IN_COMBAT, and guidTargetTokenCache. - GetCastInfo now takes the token directly; every caller already holds it, so the UnitTokenFromGUID(guid) round-trip is gone (unused module-wide now). NAME_PLATE_UNIT_ADDED caches the token as plate.nameplate.unit alongside the GUID; REMOVED clears both. GUID is retained only as the stable cache key (debuffCache/threatMemory/combatColorCache). Only GetUnitField("npcFlags") remains -- it has no token/vanilla equivalent. commitce1c49fcbbAuthor: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri Jul 24 18:20:06 2026 -0500 Make focus/focustarget event-driven via ClassicAPI unit events ClassicAPI now fires UNIT_* (health/mana/aura/...) with arg1 == "focus" and arg1 == "focustarget", observed per-unit like target/party/raid. Both frames already registered those events (focus/focustarget are in pfValidUnits) and their OnEvent already matches arg1 == label, so the 0.2s polling ticks were pure workarounds for the missing events. Drop both ticks; the frames now refresh on-event like target, with range/glow still on the shared 0.5s state pass and PLAYER_FOCUS_CHANGED still driving assign/clear.
557 lines
23 KiB
Lua
557 lines
23 KiB
Lua
pfUI:RegisterModule("castbar", function ()
|
||
|
||
local font = C.castbar.use_unitfonts == "1" and pfUI.font_unit or pfUI.font_default
|
||
local font_size = C.castbar.use_unitfonts == "1" and C.global.font_unit_size or C.global.font_size
|
||
local rawborder, default_border = GetBorderSize("unitframes")
|
||
local cbtexture = pfUI.media[C.appearance.castbar.texture]
|
||
|
||
-- Helper function for castbar timer formatting
|
||
local function FormatCastbarTime(value)
|
||
if C.unitframes.castbardecimals == "1" then
|
||
-- 1 decimal, round half up (matches Blizzard spellbook display)
|
||
return string.format("%.1f", floor(value * 10 + 0.5) / 10)
|
||
else
|
||
-- 2 decimals (default)
|
||
return string.format("%.2f", value)
|
||
end
|
||
end
|
||
|
||
-- Clear cast state on the bar. Shows the bar full for one frame, then
|
||
-- OnUpdate fades it out.
|
||
local function ClearBar(cb)
|
||
cb.startTime, cb.endTime, cb.isChannel = nil, nil, nil
|
||
cb.activeName, cb.spellID = nil, nil
|
||
cb.isTradeskill = nil
|
||
cb.tradeskillTotal, cb.tradeskillCompleted, cb.tradeskillSpellID = nil, nil, nil
|
||
cb.tradeskillSingleMs, cb.currentCraftStart = nil, nil
|
||
cb.lastMax = nil
|
||
cb.delay = 0
|
||
cb.bar:SetMinMaxValues(1, 100)
|
||
cb.bar:SetValue(100)
|
||
if cb.bar.spark then cb.bar.spark:Hide() end
|
||
cb.fadeout = 1
|
||
end
|
||
|
||
-- "Spellname (N)" label for an active tradeskill merge — N is the number
|
||
-- of crafts remaining. Falls back to the bare spell name when ≤1 left.
|
||
local function UpdateTradeskillLabel(cb)
|
||
if not cb.tradeskillTotal or not cb.activeName or not cb.showname then return end
|
||
local remaining = cb.tradeskillTotal - (cb.tradeskillCompleted or 0)
|
||
if remaining > 1 then
|
||
cb.bar.left:SetText(string.format("%s (%d)", cb.activeName, remaining))
|
||
else
|
||
cb.bar.left:SetText(cb.activeName)
|
||
end
|
||
end
|
||
|
||
-- Stretch the bar to span all queued crafts (Quartz-style merge): the bar
|
||
-- fills continuously across the chain instead of resetting per craft.
|
||
-- Also arms the per-craft spark — a thin marker that crosses the bar once
|
||
-- per craft (so it moves N× faster than the main fill on an N-stack).
|
||
local function EnterTradeskillMerge(cb, startMs, endMs, count)
|
||
cb.tradeskillTotal = count
|
||
cb.tradeskillCompleted = 0
|
||
cb.tradeskillSpellID = cb.spellID
|
||
local single = endMs - startMs
|
||
cb.tradeskillSingleMs = single
|
||
cb.currentCraftStart = startMs
|
||
local mergedEnd = startMs + single * count
|
||
cb.endTime = mergedEnd
|
||
local duration = (mergedEnd - startMs) / 1000
|
||
cb.bar:SetMinMaxValues(0, duration)
|
||
cb.lastMax = duration
|
||
if cb.bar.spark then cb.bar.spark:Show() end
|
||
UpdateTradeskillLabel(cb)
|
||
end
|
||
|
||
-- Mark the start of craft 2..N within an active merge (called from the
|
||
-- SPELLCAST_START / SPELL_START_SELF handlers). Resets the per-craft
|
||
-- spark to the left edge of the bar.
|
||
local function StartTradeskillCraft(cb)
|
||
cb.currentCraftStart = GetTime() * 1000
|
||
local remaining = cb.tradeskillTotal - (cb.tradeskillCompleted or 0)
|
||
cb.endTime = cb.currentCraftStart + cb.tradeskillSingleMs * remaining
|
||
local duration = (cb.endTime - cb.startTime) / 1000
|
||
cb.bar:SetMinMaxValues(0, duration)
|
||
cb.lastMax = duration
|
||
UpdateTradeskillLabel(cb)
|
||
end
|
||
|
||
-- Stamp the bar with cast data and render text/icon/lag once. OnUpdate
|
||
-- then animates the fill from this state without touching C_Spell.
|
||
local function StampBar(cb, name, tex, startMs, endMs, spellID, isChannel, delayMs, isTradeskill)
|
||
cb.startTime = startMs
|
||
cb.endTime = endMs
|
||
cb.isChannel = isChannel
|
||
cb.spellID = spellID
|
||
cb.activeName = name
|
||
cb.isTradeskill = isTradeskill
|
||
cb.delay = (delayMs or 0) / 1000
|
||
cb:SetAlpha(1)
|
||
cb.fadeout = nil
|
||
|
||
cb.bar:SetStatusBarColor(strsplit(",", C.appearance.castbar[isChannel and "channelcolor" or "castbarcolor"]))
|
||
|
||
local rank = ""
|
||
if spellID then
|
||
rank = C_Spell.GetSpellSubtext(spellID) or ""
|
||
end
|
||
local spellname = (cb.showname and name) and (name .. " ") or ""
|
||
local rankstr = (cb.showrank and rank ~= "") and string.format("|cffaaffcc[%s]|r", rank) or ""
|
||
cb.bar.left:SetText(spellname .. rankstr)
|
||
|
||
if tex and cb.showicon then
|
||
local size = cb:GetHeight()
|
||
cb.icon:Show()
|
||
cb.icon:SetHeight(size)
|
||
cb.icon:SetWidth(size)
|
||
cb.icon.texture:SetTexture(tex)
|
||
cb.bar:SetPoint("TOPLEFT", cb.icon, "TOPRIGHT", cb.spacing, 0)
|
||
else
|
||
cb.bar:SetPoint("TOPLEFT", cb, 0, 0)
|
||
cb.icon:Hide()
|
||
end
|
||
|
||
local duration = (endMs - startMs) / 1000
|
||
if cb.showlag then
|
||
local _, _, lag = GetNetStats()
|
||
cb.bar.lag:SetWidth(math.min(cb:GetWidth(), cb:GetWidth() / duration * (lag/1000)))
|
||
cb.bar.lag:Show()
|
||
else
|
||
cb.bar.lag:Hide()
|
||
end
|
||
|
||
cb.bar:SetMinMaxValues(0, duration)
|
||
cb.lastMax = duration
|
||
end
|
||
|
||
-- 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.
|
||
local function RefreshBar(cb)
|
||
local query = cb.unitstr ~= "" and cb.unitstr or cb.unitname
|
||
if not query or (cb.unitstr ~= "" and not UnitExists(cb.unitstr)) then
|
||
ClearBar(cb)
|
||
return
|
||
end
|
||
local name, _, tex, startMs, endMs, isTradeskill, _, _, spellID, _, delayMs = C_Spell.UnitCastingInfo(query)
|
||
local isChan
|
||
if not name then
|
||
name, _, tex, startMs, endMs, _, _, spellID = C_Spell.UnitChannelInfo(query)
|
||
isChan = true
|
||
end
|
||
-- Synthetic fallback for abilities the engine treats as instant-cast but
|
||
-- that have a meaningful wait window (e.g. Turtle WoW Steady Shot on the
|
||
-- ranged-swing queue). Per-unit table populated by module-side hooks.
|
||
if not name and pfUI.synthetic_casts and pfUI.synthetic_casts[query] then
|
||
local s = pfUI.synthetic_casts[query]
|
||
if s.endMs > GetTime() * 1000 then
|
||
name, tex, startMs, endMs, spellID = s.name, s.icon, s.startMs, s.endMs, s.spellID
|
||
isChan = nil
|
||
end
|
||
end
|
||
if name and startMs and endMs then
|
||
StampBar(cb, name, tex, startMs, endMs, spellID, isChan, delayMs, isTradeskill)
|
||
else
|
||
ClearBar(cb)
|
||
end
|
||
end
|
||
|
||
local function CreateCastbar(name, parent, unitstr, unitname)
|
||
local cb = CreateFrame("Frame", name, parent or UIParent)
|
||
|
||
cb:SetHeight(C.global.font_size * 1.5)
|
||
cb:SetFrameStrata("MEDIUM")
|
||
cb:SetFrameLevel(8)
|
||
|
||
cb.unitstr = unitstr
|
||
cb.unitname = unitname
|
||
|
||
-- icon
|
||
cb.icon = CreateFrame("Frame", nil, cb)
|
||
cb.icon:SetPoint("TOPLEFT", 0, 0)
|
||
cb.icon:SetHeight(16)
|
||
cb.icon:SetWidth(16)
|
||
|
||
cb.icon.texture = cb.icon:CreateTexture(nil, "OVERLAY")
|
||
cb.icon.texture:SetAllPoints()
|
||
cb.icon.texture:SetTexCoord(.08, .92, .08, .92)
|
||
CreateBackdrop(cb.icon, default_border)
|
||
|
||
-- statusbar
|
||
cb.bar = CreateFrame("StatusBar", nil, cb)
|
||
cb.bar:SetStatusBarTexture(cbtexture)
|
||
cb.bar:ClearAllPoints()
|
||
cb.bar:SetAllPoints(cb)
|
||
cb.bar:SetMinMaxValues(0, 100)
|
||
cb.bar:SetValue(20)
|
||
local r,g,b,a = strsplit(",", C.appearance.castbar.castbarcolor)
|
||
cb.bar:SetStatusBarColor(r,g,b,a)
|
||
CreateBackdrop(cb.bar, default_border)
|
||
CreateBackdropShadow(cb.bar)
|
||
|
||
-- text left
|
||
cb.bar.left = cb.bar:CreateFontString("Status", "DIALOG", "GameFontNormal")
|
||
cb.bar.left:ClearAllPoints()
|
||
cb.bar.left:SetPoint("TOPLEFT", cb.bar, "TOPLEFT", 3 + C.castbar[unitstr].txtleftoffx, C.castbar[unitstr].txtleftoffy)
|
||
cb.bar.left:SetPoint("BOTTOMRIGHT", cb.bar, "BOTTOMRIGHT", -3 + C.castbar[unitstr].txtleftoffx, C.castbar[unitstr].txtleftoffy)
|
||
cb.bar.left:SetNonSpaceWrap(false)
|
||
cb.bar.left:SetFontObject(GameFontWhite)
|
||
cb.bar.left:SetTextColor(1,1,1,1)
|
||
cb.bar.left:SetFont(font, font_size, "OUTLINE")
|
||
cb.bar.left:SetJustifyH(C.castbar[unitstr].namealign or "LEFT")
|
||
|
||
-- text right
|
||
cb.bar.right = cb.bar:CreateFontString("Status", "DIALOG", "GameFontNormal")
|
||
cb.bar.right:ClearAllPoints()
|
||
cb.bar.right:SetPoint("TOPLEFT", cb.bar, "TOPLEFT", 3 + C.castbar[unitstr].txtrightoffx, C.castbar[unitstr].txtrightoffy)
|
||
cb.bar.right:SetPoint("BOTTOMRIGHT", cb.bar, "BOTTOMRIGHT", -3 + C.castbar[unitstr].txtrightoffx, C.castbar[unitstr].txtrightoffy)
|
||
cb.bar.right:SetNonSpaceWrap(false)
|
||
cb.bar.right:SetFontObject(GameFontWhite)
|
||
cb.bar.right:SetTextColor(1,1,1,1)
|
||
cb.bar.right:SetFont(font, font_size, "OUTLINE")
|
||
cb.bar.right:SetJustifyH(C.castbar[unitstr].timealign or "RIGHT")
|
||
|
||
cb.bar.lag = cb.bar:CreateTexture(nil, "OVERLAY")
|
||
cb.bar.lag:SetPoint("TOPRIGHT", cb.bar, "TOPRIGHT", 0, 0)
|
||
cb.bar.lag:SetPoint("BOTTOMRIGHT", cb.bar, "BOTTOMRIGHT", 0, 0)
|
||
cb.bar.lag:SetTexture(1,.2,.2,.2)
|
||
|
||
-- Per-craft progress spark for tradeskill merge — a thin vertical line
|
||
-- that crosses the bar once per craft in the chain (so on a 5-stack it
|
||
-- moves 5x faster than the main fill). Position is updated by OnUpdate
|
||
-- while a merge is active; hidden otherwise.
|
||
cb.bar.spark = cb.bar:CreateTexture(nil, "OVERLAY")
|
||
cb.bar.spark:SetTexture(1, 1, 1, 0.8)
|
||
cb.bar.spark:SetWidth(2)
|
||
cb.bar.spark:SetPoint("TOP", cb.bar, "TOPLEFT", 0, 0)
|
||
cb.bar.spark:SetPoint("BOTTOM", cb.bar, "BOTTOMLEFT", 0, 0)
|
||
cb.bar.spark:Hide()
|
||
|
||
-- OnUpdate animates the bar fill and fades it out on completion. All
|
||
-- state transitions (cast start/stop/interrupt, channel start/stop,
|
||
-- pushback) come from the event handler below — we never poll C_Spell
|
||
-- here.
|
||
cb:SetScript("OnUpdate", function()
|
||
if (this.tick or 0) > GetTime() then return end
|
||
this.tick = GetTime() + 0.020 -- ~50 FPS
|
||
|
||
if this.drag and this.drag:IsShown() then
|
||
this:SetAlpha(1)
|
||
return
|
||
end
|
||
|
||
if this.fadeout and this:GetAlpha() > 0 then
|
||
this:SetAlpha(this:GetAlpha() - 0.05)
|
||
if this:GetAlpha() <= 0 then this.fadeout = nil end
|
||
return
|
||
end
|
||
|
||
if not this.endTime then
|
||
if this:GetAlpha() ~= 0 then this:SetAlpha(0) end
|
||
return
|
||
end
|
||
|
||
-- Non-player bars: if the unit disappears (target died / detarget),
|
||
-- drop the bar immediately.
|
||
if this.unitstr ~= "" and this.unitstr ~= "player" and not UnitExists(this.unitstr) then
|
||
ClearBar(this)
|
||
return
|
||
end
|
||
|
||
local now = GetTime()
|
||
local endSec = this.endTime / 1000
|
||
if now >= endSec then
|
||
ClearBar(this)
|
||
return
|
||
end
|
||
|
||
local startSec = this.startTime / 1000
|
||
local max = endSec - startSec
|
||
local cur = this.isChannel and (endSec - now) or (now - startSec)
|
||
if cur > max then cur = max end
|
||
if cur < 0 then cur = 0 end
|
||
|
||
this.bar:SetValue(cur)
|
||
|
||
-- Per-craft spark for a tradeskill merge: position by (now - current
|
||
-- craft's start) / single-craft duration, clamped to [0, 1]. Snaps back
|
||
-- to the left edge each time StartTradeskillCraft fires for craft N+1.
|
||
if this.tradeskillTotal and this.tradeskillSingleMs and this.currentCraftStart then
|
||
local craftElapsed = now * 1000 - this.currentCraftStart
|
||
local p = craftElapsed / this.tradeskillSingleMs
|
||
if p < 0 then p = 0 elseif p > 1 then p = 1 end
|
||
local x = p * this.bar:GetWidth() - 1
|
||
this.bar.spark:ClearAllPoints()
|
||
this.bar.spark:SetPoint("TOP", this.bar, "TOPLEFT", x, 0)
|
||
this.bar.spark:SetPoint("BOTTOM", this.bar, "BOTTOMLEFT", x, 0)
|
||
end
|
||
|
||
if this.showtimer then
|
||
if (this.delay or 0) > 0 then
|
||
local prefix = "|cffffaaaa" .. (this.isChannel and "-" or "+") .. FormatCastbarTime(this.delay) .. " |r "
|
||
this.bar.right:SetText(prefix .. FormatCastbarTime(cur) .. " / " .. FormatCastbarTime(max))
|
||
else
|
||
this.bar.right:SetText(FormatCastbarTime(cur) .. " / " .. FormatCastbarTime(max))
|
||
end
|
||
end
|
||
end)
|
||
|
||
-- Cast lifecycle events. Player bars react to vanilla SPELLCAST_*; non-
|
||
-- player bars also react to Nampower SPELL_*_OTHER (gated by the
|
||
-- NP_EnableSpell{Start,Go}Events CVars, enabled by libdebuff) plus the
|
||
-- retarget event. Player events also feed non-player bars for the
|
||
-- target=self case.
|
||
cb:RegisterEvent("SPELLCAST_START")
|
||
cb:RegisterEvent("SPELLCAST_STOP")
|
||
cb:RegisterEvent("SPELLCAST_FAILED")
|
||
cb:RegisterEvent("SPELLCAST_INTERRUPTED")
|
||
cb:RegisterEvent("SPELLCAST_CHANNEL_START")
|
||
cb:RegisterEvent("SPELLCAST_CHANNEL_STOP")
|
||
cb:RegisterEvent("SPELLCAST_CHANNEL_UPDATE")
|
||
cb:RegisterEvent("SPELL_DELAYED_SELF")
|
||
-- Chained same-spell recasts never run the client cast path (the 1.12
|
||
-- engine short-circuits at spellID == current-cast), so vanilla
|
||
-- SPELLCAST_START never fires for them. nampower's SPELL_START_SELF
|
||
-- (server-driven) is the only signal that shows them.
|
||
cb:RegisterEvent("SPELL_START_SELF")
|
||
if unitstr == "player" then
|
||
cb:RegisterEvent("SPELL_GO_SELF")
|
||
end
|
||
if unitstr ~= "player" and unitstr ~= "" then
|
||
cb:RegisterEvent("SPELL_START_OTHER")
|
||
cb:RegisterEvent("SPELL_FAILED_OTHER")
|
||
if unitstr == "target" then
|
||
cb:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||
elseif unitstr == "focus" then
|
||
cb:RegisterEvent("PLAYER_FOCUS_CHANGED")
|
||
end
|
||
end
|
||
|
||
cb:SetScript("OnEvent", function()
|
||
local unit = this.unitstr
|
||
|
||
if event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_FOCUS_CHANGED" then
|
||
RefreshBar(this)
|
||
return
|
||
end
|
||
|
||
if event == "SPELL_START_OTHER" then
|
||
-- arg3=casterGuid. Defer one frame so ClassicAPI's UnitChannelInfo
|
||
-- can see the engine's +0x228 broadcast for remote-unit channels
|
||
-- (the cohook+packet handler runs in the same frame; the broadcast
|
||
-- propagates after).
|
||
if arg3 == UnitGUID(unit) then
|
||
local target = this
|
||
RunNextFrame(function() RefreshBar(target) end)
|
||
end
|
||
return
|
||
end
|
||
|
||
if event == "SPELL_FAILED_OTHER" then
|
||
if arg1 == UnitGUID(unit) then ClearBar(this) end
|
||
return
|
||
end
|
||
|
||
-- Vanilla SPELLCAST_* + SPELL_DELAYED_SELF fire only for the local
|
||
-- player. Non-player bars handle them only when their unit currently
|
||
-- resolves to the player (target=self / focus=self).
|
||
if not UnitIsUnit(unit, 'player') then return end
|
||
|
||
if event == "SPELLCAST_START" or event == "SPELLCAST_CHANNEL_START" then
|
||
if this.tradeskillTotal then
|
||
-- Mid-chain craft N+1 of N. Keep the merged bar; resync the spark
|
||
-- to the new craft's start and refresh the "(N)" count label.
|
||
StartTradeskillCraft(this)
|
||
else
|
||
RefreshBar(this)
|
||
if this.isTradeskill and (this.pendingTradeskillCount or 0) > 1
|
||
and C.castbar.player.mergetradeskill == "1" then
|
||
EnterTradeskillMerge(this, this.startTime, this.endTime, this.pendingTradeskillCount)
|
||
end
|
||
this.pendingTradeskillCount = nil
|
||
end
|
||
elseif event == "SPELL_START_SELF" then
|
||
-- Catches chained same-spell recasts (no SPELLCAST_START fires) —
|
||
-- including tradeskill chaining where craft 2..N reuse one spell.
|
||
-- Defer one frame so ClassicAPI's SMSG_SPELL_START co-hook has
|
||
-- stamped g_cast before we poll, regardless of co-hook order.
|
||
if this.tradeskillTotal then
|
||
StartTradeskillCraft(this)
|
||
else
|
||
local target = this
|
||
RunNextFrame(function()
|
||
-- Re-check: SPELL_START_SELF (nampower co-hook) fires before vanilla
|
||
-- SPELLCAST_START on the same packet, so SPELLCAST_START may have
|
||
-- entered merge in this same frame. Don't restamp over it.
|
||
if target.tradeskillTotal then
|
||
StartTradeskillCraft(target)
|
||
return
|
||
end
|
||
RefreshBar(target)
|
||
if target.unitstr == "player" and target.isTradeskill
|
||
and (target.pendingTradeskillCount or 0) > 1
|
||
and C.castbar.player.mergetradeskill == "1" then
|
||
EnterTradeskillMerge(target, target.startTime, target.endTime, target.pendingTradeskillCount)
|
||
end
|
||
target.pendingTradeskillCount = nil
|
||
end)
|
||
end
|
||
elseif event == "SPELLCAST_CHANNEL_STOP" then
|
||
-- A channel's stop can arrive after a following cast already claimed
|
||
-- the bar (channel->cast transition); only clear if a channel is
|
||
-- actually being shown, so it doesn't wipe an active cast bar.
|
||
if this.isChannel then ClearBar(this) end
|
||
elseif event == "SPELLCAST_STOP" then
|
||
-- During a tradeskill chain, SPELL_GO_SELF already counted this craft
|
||
-- and either cleared the bar (chain done) or kept it running. Only a
|
||
-- non-merge cast clears here.
|
||
if not this.tradeskillTotal then ClearBar(this) end
|
||
elseif event == "SPELLCAST_FAILED" or event == "SPELLCAST_INTERRUPTED" then
|
||
ClearBar(this)
|
||
elseif event == "SPELL_GO_SELF" then
|
||
-- arg2 = spellId. In a tradeskill merge, count each successful craft
|
||
-- and clear when the chain is done.
|
||
if this.tradeskillTotal and arg2 == this.tradeskillSpellID then
|
||
this.tradeskillCompleted = (this.tradeskillCompleted or 0) + 1
|
||
if this.tradeskillCompleted >= this.tradeskillTotal then
|
||
ClearBar(this)
|
||
else
|
||
UpdateTradeskillLabel(this)
|
||
end
|
||
end
|
||
elseif event == "SPELL_DELAYED_SELF" then
|
||
-- Cast pushback. nampower's event carries the delay (arg2); apply it
|
||
-- locally rather than re-polling, so the bar doesn't depend on
|
||
-- ClassicAPI's SMSG_SPELL_DELAYED co-hook having bumped g_cast before
|
||
-- this fires (co-hook order vs nampower is not guaranteed).
|
||
if not this.endTime or not arg2 then return end
|
||
local delayMs = tonumber(arg2) or 0
|
||
if delayMs > 0 then
|
||
this.delay = (this.delay or 0) + delayMs / 1000
|
||
this.endTime = this.endTime + delayMs
|
||
local newDuration = (this.endTime - this.startTime) / 1000
|
||
this.bar:SetMinMaxValues(0, newDuration)
|
||
this.lastMax = newDuration
|
||
end
|
||
elseif event == "SPELLCAST_CHANNEL_UPDATE" then
|
||
-- Channel pushback. ClassicAPI doesn't track channel delay in
|
||
-- g_channel, so we adjust endTime + delay locally and resize the
|
||
-- bar so OnUpdate animates against the new total.
|
||
if not this.endTime or not arg1 then return end
|
||
local newEndMs = GetTime() * 1000 + arg1
|
||
local diff = this.endTime - newEndMs
|
||
if diff > 50 then
|
||
this.delay = (this.delay or 0) + diff / 1000
|
||
this.endTime = newEndMs
|
||
local newDuration = (this.endTime - this.startTime) / 1000
|
||
this.bar:SetMinMaxValues(0, newDuration)
|
||
this.lastMax = newDuration
|
||
end
|
||
end
|
||
end)
|
||
|
||
cb:SetAlpha(0)
|
||
return cb
|
||
end
|
||
|
||
pfUI.castbar = CreateFrame("Frame", "pfCastBar", UIParent)
|
||
|
||
-- hide blizzard
|
||
if C.castbar.player.hide_blizz == "1" then
|
||
CastingBarFrame:SetScript("OnShow", function() CastingBarFrame:Hide() end)
|
||
CastingBarFrame:UnregisterAllEvents()
|
||
CastingBarFrame:Hide()
|
||
end
|
||
|
||
-- [[ pfPlayerCastbar ]] --
|
||
if C.castbar.player.hide_pfui == "0" then
|
||
pfUI.castbar.player = CreateCastbar("pfPlayerCastbar", UIParent, "player")
|
||
pfUI.castbar.player.showicon = C.castbar.player.showicon == "1" and true or nil
|
||
pfUI.castbar.player.showname = C.castbar.player.showname == "1" and true or nil
|
||
pfUI.castbar.player.showtimer = C.castbar.player.showtimer == "1" and true or nil
|
||
pfUI.castbar.player.showlag = C.castbar.player.showlag == "1" and true or nil
|
||
pfUI.castbar.player.showrank = C.castbar.player.showrank == "1" and true or nil
|
||
pfUI.castbar.player.spacing = default_border * 2 + tonumber(C.unitframes.player.pspace) * GetPerfectPixel()
|
||
|
||
if pfUI.uf.player then
|
||
local anchor = pfUI.uf.player.portrait:GetHeight() > pfUI.uf.player:GetHeight() and pfUI.uf.player.power or pfUI.uf.player
|
||
local width = C.castbar.player.width ~= "-1" and C.castbar.player.width or anchor:GetWidth()
|
||
pfUI.castbar.player:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -pfUI.castbar.player.spacing)
|
||
pfUI.castbar.player:SetWidth(width)
|
||
else
|
||
local width = C.castbar.player.width ~= "-1" and C.castbar.player.width or 200
|
||
pfUI.castbar.player:SetPoint("CENTER", 0, -200)
|
||
pfUI.castbar.player:SetWidth(width)
|
||
end
|
||
|
||
if C.castbar.player.height ~= "-1" then
|
||
pfUI.castbar.player:SetHeight(C.castbar.player.height)
|
||
end
|
||
|
||
UpdateMovable(pfUI.castbar.player)
|
||
|
||
-- Tradeskill merge: hook DoTradeSkill so the player castbar knows the
|
||
-- requested count before the first SPELLCAST_START fires. Always-on hook
|
||
-- (the config knob is read at event time so toggling takes effect on the
|
||
-- next craft without a /reload). DoTradeSkill is synchronous; the server
|
||
-- roundtrip to SPELLCAST_START gives us plenty of time after this hook.
|
||
hooksecurefunc("DoTradeSkill", function(index, num)
|
||
if pfUI.castbar.player then
|
||
pfUI.castbar.player.pendingTradeskillCount = tonumber(num) or 1
|
||
end
|
||
end)
|
||
end
|
||
|
||
-- [[ pfTargetCastbar ]] --
|
||
if C.castbar.target.hide_pfui == "0" then
|
||
pfUI.castbar.target = CreateCastbar("pfTargetCastbar", UIParent, "target")
|
||
pfUI.castbar.target.showicon = C.castbar.target.showicon == "1" and true or nil
|
||
pfUI.castbar.target.showname = C.castbar.target.showname == "1" and true or nil
|
||
pfUI.castbar.target.showtimer = C.castbar.target.showtimer == "1" and true or nil
|
||
pfUI.castbar.target.showlag = C.castbar.target.showlag == "1" and true or nil
|
||
pfUI.castbar.target.showrank = C.castbar.target.showrank == "1" and true or nil
|
||
pfUI.castbar.target.spacing = default_border * 2 + tonumber(C.unitframes.target.pspace) * GetPerfectPixel()
|
||
|
||
if pfUI.uf.target then
|
||
local anchor = pfUI.uf.target.portrait:GetHeight() > pfUI.uf.target:GetHeight() and pfUI.uf.target.power or pfUI.uf.target
|
||
local width = C.castbar.target.width ~= "-1" and C.castbar.target.width or anchor:GetWidth()
|
||
pfUI.castbar.target:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -pfUI.castbar.target.spacing)
|
||
pfUI.castbar.target:SetWidth(width)
|
||
else
|
||
local width = C.castbar.target.width ~= "-1" and C.castbar.target.width or 200
|
||
pfUI.castbar.target:SetPoint("CENTER", 0, -225)
|
||
pfUI.castbar.target:SetWidth(width)
|
||
end
|
||
|
||
if C.castbar.target.height ~= "-1" then
|
||
pfUI.castbar.target:SetHeight(C.castbar.target.height)
|
||
end
|
||
|
||
UpdateMovable(pfUI.castbar.target)
|
||
end
|
||
|
||
-- [[ pfFocusCastbar ]] --
|
||
if C.castbar.focus.hide_pfui == "0" and pfUI.uf.focus then
|
||
pfUI.castbar.focus = CreateCastbar("pfFocusCastbar", UIParent, "focus")
|
||
pfUI.castbar.focus.showicon = C.castbar.focus.showicon == "1" and true or nil
|
||
pfUI.castbar.focus.showname = C.castbar.focus.showname == "1" and true or nil
|
||
pfUI.castbar.focus.showtimer = C.castbar.focus.showtimer == "1" and true or nil
|
||
pfUI.castbar.focus.showlag = C.castbar.focus.showlag == "1" and true or nil
|
||
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()
|
||
|
||
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)
|
||
pfUI.castbar.focus:SetWidth(width)
|
||
|
||
if C.castbar.focus.height ~= "-1" then
|
||
pfUI.castbar.focus:SetHeight(C.castbar.focus.height)
|
||
end
|
||
|
||
-- bind castbar to the "focus" unit token; the GUID resolves at read time
|
||
pfUI.castbar.focus.unitstr = "focus"
|
||
|
||
UpdateMovable(pfUI.castbar.focus)
|
||
end
|
||
end) |