Files
pfUI/modules/turtle-wow.lua
brues-code 75c4657ab9 ClassicAPI flavor TOCs, and drop the multi-client scaffolding (#53)
* nameplates: source totem icons from UnitCreatedBySpell

Read the totem's icon from the totem-drop spell (UnitCreatedBySpell +
GetSpellTexture) instead of the self-aura at index 1 plus a
UNIT_SPELLCAST_SUCCEEDED capture for active totems. The drop spell is a
broadcast descriptor field present for every summoned unit in range, so
it resolves immediately for passive and active totems alike and gives the
totem's own icon rather than the attack-spell proxy. Drops the
UNIT_SPELLCAST_SUCCEEDED registration and handler.

Re-read the spell each render and key the cached texture on the spell id
so an in-place totem swap (same unit, new drop spell -- no plate re-add)
refreshes the icon without needing the plate to leave and re-enter view.

* CAPI min bumped to 1.13.1

* Gracefully disable pfUI when ClassicAPI is missing

Add API_Check.lua as the first TOC entry. When the ClassicAPI DLL is
absent or below the minimum version it sets pfUI_disabled and stands up
an inert stub so the rest of the addon no-ops instead of flooding load
errors: modules and skins register their bodies into no-ops, and the
setfenv'd api/lib files run inside an environment where CreateFrame and
any missing global resolve to a null object -- so no real frames or live
handlers are created and missing API calls just return null. pfUI.lua
bails early on pfUI_disabled.

* auras: scan through GetAuraSlots instead of by-index loops

Every aura scan loop (unit frame buffs/debuffs, dispel indicators, buff and
custom indicators, player buff frame, buffwatch bars, tooltip buff row) now
enumerates a unit's auras once with C_UnitAuras.GetAuraSlots and reads each
aura by slot id via the positional C_UnitAuras.UnitAuraBySlot. The by-index
getters re-walk the aura array from slot 0 on every call, so a per-button
loop over them was quadratic in the aura count; one enumeration plus a
by-slot read per aura is linear.

pfUI.api.ScanAuraSlots(unit, filter, buf, max) wraps GetAuraSlots' fill-a-
table form (table as the 5th argument) so no vararg Lua frame is involved:
Lua 5.0 allocates an `arg` table for every vararg call, which showed up as
nameplate OnUpdate/OnEvent memory growth in the first cut of this change.

Single by-index reads in tooltip and click handlers are unchanged (one call
each, and SetUnitAura takes the same index).

Requires the ClassicAPI build that adds GetAuraSlots' fill form; on an older
DLL the 5th argument is ignored and ScanAuraSlots would read the first slot
id as the count.

* Show Faction/Race icons in chat

* Load pfUI through ClassicAPI's flavor TOCs

ClassicAPI redirects the read of pfUI\pfUI.toc to a flavored file whenever
the DLL is installed, so which TOC the client opens already answers whether
ClassicAPI is there. Split the manifest three ways and let that do the work:

  pfUI.toc             fallback, reached only when ClassicAPI is missing;
                       loads API_Check.lua and nothing else
  pfUI_ClassicAPI.toc  full addon, every non-Turtle client
  pfUI_Turtle.toc      full addon plus init\turtle.xml, on Turtle

The fallback TOC declares no SavedVariables. It used to, while API_Check.lua
reset pfUI_profiles to an empty table on the disabled path -- which truncated
the player's profiles on logout.

With the missing-DLL case handled by TOC selection, API_Check.lua drops the
null object stub that kept the other ~140 files quiet, along with
pfUI_disabled and the now unreachable early return in pfUI.lua. It keeps the
version gate, which still matters: the flavor redirect landed in ClassicAPI
v1.11.0, below the v1.13.1 pfUI needs, so an old DLL still gets served a
flavor TOC. pfUI.lua also loses a verbatim duplicate of the whole check.

Turtle-only files move to init\turtle.xml: modules\turtle-wow.lua (its
TURTLE_WOW_VERSION guard is now redundant) and the lft, turtle_shop,
barbershop, transmog and ebc skins. turtle-wow registers last instead of
75th of 84; the only ordering it relies on is pfUI.chat, registered 8th.

pfSellData moves to env\selldata.lua, listed only in pfUI_ClassicAPI.toc,
since turtle-wow.lua replaces the table wholesale on Turtle. env\tables.lua
keeps an empty declaration so sellvalue.lua has something to index when the
turtle-wow module is disabled.

The release workflow pinned PFUI_CLASSIC_API_LATEST in pfUI.lua, which has
not held that constant since it moved to API_Check.lua, so the pin was
silently doing nothing. It also switches to brues-code/packager@vCAPI, which
recognizes the _ClassicAPI and _Turtle suffixes and applies the TOC build
type filters to them.

* Split the vendor price tables into their own manifests

Turtle's pfSellData moves out of modules\turtle-wow.lua into
env\selldata_turtle.lua, matching env\selldata.lua for the stock list, and
each is pulled in by the manifest for its client: init\stock.xml from
pfUI_ClassicAPI.toc, init\turtle.xml from pfUI_Turtle.toc. Either way it
loads after init\env.xml and replaces the empty pfSellData declared there.

Turtle's prices used to be assigned inside the turtle-wow module body, which
put them on pfUI.env and skipped them entirely when that module was
disabled. At file scope they land on _G and apply either way.

* Drop the vanilla compat layer

compat\vanilla.lua named the handful of things that differed between clients
back when pfUI targeted several. Only one client remains, so every constant
had exactly one value. Inline each at its use site and delete the file,
init\compat.xml, and both TOC entries.

  COOLDOWN_FRAME_TYPE                    -> "Model"
  LOOT_BUTTON_FRAME_TYPE                 -> "LootButton"
  MINIMAP_TRACKING_FRAME                 -> _G.MiniMapTrackingFrame
  FRIENDS_NAME_LOCATION                  -> "ButtonTextNameLocation"
  EVENTS_MINIMAP_ZONE_UPDATE             -> the event list, in panel.lua
  MICRO_BUTTONS                          -> a local in panel.lua
  NAMEPLATE_OBJECTORDER                  -> a local in nameplates.lua
  ACTIONBAR_SECURE_TEMPLATE_BAR/_BUTTON  -> nil, so the argument goes away

NAMEPLATE_FRAMETYPE and PLAYER_BUFF_START_ID had no readers left.

RunMacroText moves to pfUI.lua. compat\vanilla.lua was setfenv'd into the
pfUI environment, so the function only ever existed on pfUI.env; at file
scope it lands on _G as a real export instead. Nothing in pfUI calls it, and
ClassicAPI neither defines nor looks for a RunMacroText global -- it does
the same throwaway edit box natively in src/macro/Execute.cpp and only
defers to a global RunMacro.

* bump CAPI min to 11303

* auras: uncap the self-debuff tooltip lookup

With selfdebuff on, the displayed debuff list is PLAYER-filtered while
GameTooltip:SetUnitAura indexes the unfiltered HARMFUL list, so both
handlers map one to the other by matching name + sourceGUID. That mapping
scanned slots 1..16 only.

The unfiltered harmful list is not capped at 16. Once a unit's 16 debuff
slots are full the server parks further debuffs in buff slots, and
C_UnitAuras classifies by the aura's polarity flag rather than its slot
range, so it reports those as harmful too -- verified live at 18 harmful on
a 20-aura target. Past the sixteenth the lookup found nothing and fell
through to the raw filtered index, opening the wrong tooltip or none.

Both now enumerate however many harmful auras the unit actually has, via
ScanAuraSlots, which also drops the per-index rescan the by-index accessor
was doing. Each handler gets its own slot buffer: OnEnter can fire while a
refresh is showing/hiding frames under the cursor, so sharing the refresh
buffer could clobber a scan mid-walk.

The nameplate module still collects at most 16 debuffs per plate. That one
is a display cap matching its 16 configured icon frames, not an aura-count
assumption, so it is left alone.

* bump CAPI min to 11304
2026-09-04 19:57:57 -05:00

375 lines
14 KiB
Lua

-- Turtle WoW only: loaded from init\turtle.xml, which only pfUI_Turtle.toc pulls in.
pfUI:RegisterModule("turtle-wow", function ()
-- Manage Turtle WoW's GroupUI (Turtle_GroupUI addon) vs pfUI frames.
--
-- Turtle uses GroupClusterFrame1-8 for BOTH party AND raid display,
-- and GroupPetsClusterFrame for pets only. GroupFrame_Toggle() controls
-- the entire system via the GROUP_ENABLED global.
--
-- Logic:
-- pfUI UF disabled (disable=="1") -> don't touch Turtle at all
-- In party (no raid):
-- pfUI group visible=="1" -> disable Turtle GroupUI, pfUI handles party
-- pfUI group visible=="0" -> enable Turtle GroupUI for party
-- In raid:
-- pfUI raid visible=="1" -> disable Turtle GroupUI, pfUI handles raid
-- pfUI raid visible=="0" -> enable Turtle GroupUI for raid
if C.unitframes.disable == "1" then
-- pfUI unit frames are completely off, let Turtle handle everything
else
-- Set GROUP_REPLACE_PARTY early so Turtle's own init can use it
GROUP_REPLACE_PARTY = "1"
-- Hide Turtle GroupUI frames and disable mouse when pfUI handles group/raid.
-- When pfUI does NOT handle them, we simply don't interfere - Turtle manages itself.
-- Important: Do NOT unregister events - Turtle needs RAID_ROSTER_UPDATE etc.
-- to react when group converts to raid (and vice versa).
local function DisableTurtleGroupFrames()
for i = 1, 8 do
local f = _G["GroupClusterFrame"..i]
if f then
f:Hide()
f:EnableMouse(false)
for _, child in pairs({f:GetChildren()}) do
child:EnableMouse(false)
end
end
end
if GroupPetsClusterFrame then
GroupPetsClusterFrame:Hide()
GroupPetsClusterFrame:EnableMouse(false)
end
end
-- Check if pfUI is handling group or raid for the current situation
local function pfUIHandlesGroupOrRaid()
local disabled = C["disabled"] or {}
if IsInRaid() then
if not C.unitframes.raid then return false end
-- Hide Turtle frames if: pfUI raid module is active, OR player disabled visibility
if disabled["raid"] == "1" then
return C.unitframes.raid.visible ~= "1"
end
return C.unitframes.raid.visible == "1"
else
if not C.unitframes.group then return false end
if disabled["group"] == "1" then
return C.unitframes.group.visible ~= "1"
end
return C.unitframes.group.visible == "1"
end
end
HookAddonOrVariable("GroupFrame", function()
-- After Turtle's own init, hide frames if pfUI handles them
hooksecurefunc("GroupFrame_Toggle", function()
if pfUIHandlesGroupOrRaid() then
DisableTurtleGroupFrames()
end
end)
-- After every group/raid update, re-hide if pfUI handles them
hooksecurefunc("GroupFrame_Update", function()
if pfUIHandlesGroupOrRaid() then
DisableTurtleGroupFrames()
end
end)
end)
end
local delay = CreateFrame("Frame")
delay:SetScript("OnUpdate", function()
this:Hide()
-- correct positions of new game menu layout
if GameMenuButtonShop and (GameMenuButtonPFUI or GameMenuButtonPFUIAddOns) then
-- calculate new offset for the shop button
local offset = 0
local offset = GameMenuButtonPFUI and offset + 22 or offset
local offset = GameMenuButtonPFUIAddOns and offset + 22 or offset
local offset = offset > 0 and offset + 22 or offset
-- move pfUI and addons to top position
GameMenuButtonShop:ClearAllPoints()
GameMenuButtonShop:SetPoint("TOP", 0, -offset)
-- restore turtle wow's custom menu layout
GameMenuButtonOptions:ClearAllPoints()
GameMenuButtonOptions:SetPoint("TOP", GameMenuButtonShop, "BOTTOM", 0, -16)
-- apply pfUI skin to the new shop button
if pfUI.skin["Game Menu"] and pfUI_config["disabled"]["skin_Game Menu"] ~= "1" then
local font = GameMenuButtonShop:GetFontString()
font:SetTextColor(1,1,1,1)
SkinButton(GameMenuButtonShop)
end
end
-- apply chat styles to hardcore chat
if pfUI.chat and pfUI.chat.left then
-- read and parse chat bracket settings
local left = "|r" .. string.sub(C.chat.text.bracket, 1, 1)
local right = string.sub(C.chat.text.bracket, 2, 2) .. "|r"
local default = " " .. "%s" .. "|r:" .. "\32"
_G.CHAT_HARDCORE_GET = left .. "H" .. right .. default
end
-- remove ignore dropdown menu from chat
if pfUI.chat then
for index, value in ipairs(UnitPopupMenus["FRIEND"]) do
if value == "IGNORE_PLAYER" then
table.remove(UnitPopupMenus["FRIEND"], index)
break
end
end
end
-- disable some new spells from tracking frame
if pfUI.tracking then
pfUI.tracking.invalidSpells["Earthshaker Slam"] = true
-- reload spells and menu
pfUI.tracking:RefreshSpells()
pfUI.tracking:RefreshMenu()
end
-- disable turtle wow's map window implementation
if pfUI.map and not Cartographer and not METAMAP_TITLE then
_G.WorldMapFrame_Maximize()
pfUI.map.loader:GetScript("OnEvent")()
_G.WorldMapFrame_Minimize = function() return end
_G.WorldMapFrame_Maximize = function() return end
_G.WorldMapFrameMaximizeButton.Show = function() return end
_G.WorldMapFrameMaximizeButton:Hide()
_G.WorldMapFrameMinimizeButton.Show = function() return end
_G.WorldMapFrameMinimizeButton:Hide()
WorldMapFrameTitle.Show = function() return end
WorldMapFrameTitle:Hide()
end
if pfUI.panel and pfPanelWidgetClock then
pfPanelWidgetClock.Tooltip = function()
GameTooltip:ClearLines()
GameTooltip_SetDefaultAnchor(GameTooltip, this)
local servertime, zonetime, time
local zh, zm = GetGameTime()
local sh, sm = zh, zm
-- convert custom zonetime to servertime
SetMapToCurrentZone()
if GetCurrentMapContinent() == 1 then
sh = sh + 12
sh = sh >= 24 and sh - 24 or sh
end
-- perform am/pm calculations
if C.global.twentyfour == "0" then
local zn, sn = " AM", " AM"
if zh == 0 then
zh = 12
elseif zh == 12 then
zn = " PM"
elseif zh > 12 then
zh = zh - 12
zn = " PM"
end
if sh == 0 then
sh = 12
elseif sh == 12 then
sn = " PM"
elseif sh > 12 then
sh = sh - 12
sn = " PM"
end
time = date("%I:%M %p")
servertime = string.format("%.2d:%.2d %s", sh, sm, sn)
zonetime = string.format("%.2d:%.2d %s", zh, zm, zn)
else
time = date("%H:%M")
servertime = string.format("%.2d:%.2d", sh, sm)
zonetime = string.format("%.2d:%.2d", zh, zm)
end
-- pick color for zone time based on day/night
local zoneColor
if zh >= 6 and zh < 18 then
zoneColor = "|cffffbb00" -- orange (day)
else
zoneColor = "|cff0074FF" -- blue (night)
end
-- create the tooltip
GameTooltip:AddLine("|cff555555" .. T["Time"])
GameTooltip:AddDoubleLine(T["Localtime"], "|cffffffff" .. time)
GameTooltip:AddDoubleLine(T["Servertime"], "|cffffffff".. servertime)
GameTooltip:AddDoubleLine(T["Zonetime"], zoneColor .. zonetime)
GameTooltip:AddLine(" ")
if TimeManagerFrame then
GameTooltip:AddDoubleLine(T["Left Click"], "|cffffffff" .. T["Show/Hide TimeManager"])
else
GameTooltip:AddDoubleLine(T["Left Click"], "|cffffffff" .. T["Show/Hide Timer"])
GameTooltip:AddDoubleLine(T["Right Click"], "|cffffffff" .. T["Reset Timer"])
end
GameTooltip:Show()
end
end
-- skin title dropdown menu
-- taken from: https://github.com/doorknob6/pfUI-turtle/blob/master/skins/turtle/character.lua
if TWTitles and pfUI.skin["Character"] and pfUI_config["disabled"]["skin_Character"] ~= "1" then
CharacterLevelText:SetPoint("TOP", CharacterNameText, "BOTTOM", 0, -2)
SkinDropDown(TWTitles)
TWTitles:SetPoint("TOP", CharacterGuildText, "BOTTOM", 0, -2)
TWTitlesText:SetPoint("LEFT", TWTitles.backdrop, "LEFT", 6, 2)
CharacterResistanceFrame:SetPoint("TOP", TWTitles, "BOTTOM", 0, 0)
end
end)
-- Synthetic Steady Shot cast bar. The engine treats Steady Shot as
-- instant, but the arrow doesn't actually fire until the next ranged
-- swing (~1.4s baseline). Drive a synthetic entry off Nampower's
-- SPELL_QUEUE_EVENT so hunters see a tickdown matching the swing wait.
-- castbar.lua reads pfUI.synthetic_casts[unit] as a fallback when
-- C_Spell.UnitCastingInfo returns nil.
pfUI_locale["enUS"]["customcast"]["TRUESHOT"] = "Steady Shot"
pfUI_locale["zhCN"]["customcast"]["TRUESHOT"] = "稳固射击"
pfUI.synthetic_casts = pfUI.synthetic_casts or {}
local steadyShotName = L["customcast"]["TRUESHOT"]
local STEADY_SHOT_ICON = "Interface\\Icons\\Ability_hunter_steadyshot"
local STEADY_SHOT_DURATION_MS = 1400 -- not haste-scaled; close enough for the visual cue
local ON_SWING_QUEUED, ON_SWING_QUEUE_POPPED = 0, 1
local steadyShot = CreateFrame("Frame")
steadyShot:RegisterEvent("SPELL_QUEUE_EVENT")
steadyShot:SetScript("OnEvent", function()
if event ~= "SPELL_QUEUE_EVENT" then return end
local eventCode, spellId = arg1, arg2
if eventCode ~= ON_SWING_QUEUED and eventCode ~= ON_SWING_QUEUE_POPPED then return end
if C_Spell.GetSpellName(spellId) ~= steadyShotName then return end
if eventCode == ON_SWING_QUEUED then
local now = GetTime() * 1000
pfUI.synthetic_casts["player"] = {
name = steadyShotName,
icon = STEADY_SHOT_ICON,
startMs = now,
endMs = now + STEADY_SHOT_DURATION_MS,
spellID = spellId,
}
else
pfUI.synthetic_casts["player"] = nil
end
end)
-- add skin to twow's talent inspect frame
if pfUI.skin["Inspect"] and pfUI_config["disabled"]["skin_Inspect"] ~= "1" then
local initialized = false
HookAddonOrVariable("Blizzard_InspectUI", function()
hooksecurefunc("InspectFrame_Show", function()
-- break if theres nothing left to do
if initialized then return end
local _, border = GetBorderSize()
-- adjust the inspect frame's Talents tab
SkinTab(InspectFrameTab3)
InspectFrameTab3:ClearAllPoints()
InspectFrameTab3:SetPoint("LEFT", InspectFrameTab2, "RIGHT", border*2 + 1, 0)
-- reload text position
InspectFrameTab3:Hide()
InspectFrameTab3:Show()
-- the talent tree frame is created lazily; skin it once it exists
if TWTalentFrame then
StripTextures(InspectTalentsFrame)
StripTextures(TWTalentFrame)
StripTextures(TWTalentFrameScrollFrame)
SkinScrollbar(TWTalentFrameScrollFrameScrollBar)
-- skin + position the talent-tree tabs
for i = 1, 3 do
local tab = _G["TWTalentFrameTab"..i]
if tab then
SkinTab(tab)
tab:ClearAllPoints()
local lastTab = _G["TWTalentFrameTab"..(i-1)]
if lastTab then
tab:SetPoint("LEFT", lastTab, "RIGHT", border*2 + 1, 0)
else
tab:SetPoint("TOPLEFT", TWTalentFrameScrollFrame, "TOPLEFT", 2, tab:GetHeight() + 4)
end
end
end
-- skin each talent button
for i = 1, (MAX_NUM_TALENTS or 100) do
local talent = _G["TWTalentFrameTalent"..i]
if talent then
StripTextures(talent)
SkinButton(talent, nil, nil, nil, _G["TWTalentFrameTalent"..i.."IconTexture"])
local rank = _G["TWTalentFrameTalent"..i.."Rank"]
if rank then
rank:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
end
end
end
-- only run once the talent frame has actually been skinned
initialized = true
end
end)
end)
end
-- rearrange twow's profession window additions
HookAddonOrVariable("Blizzard_TradeSkillUI", function()
if TradeSkillSkillCheckButton and pfUI.skin["Profession"] and pfUI_config["disabled"]["skin_Profession"] ~= "1" then
SkinCheckbox(TradeSkillSkillCheckButton)
TradeSkillSkillCheckButton:SetWidth(24)
TradeSkillSkillCheckButton:SetHeight(24)
SkinCheckbox(TradeSkillMatsCheckButton)
TradeSkillMatsCheckButton:SetWidth(24)
TradeSkillMatsCheckButton:SetHeight(24)
TradeSkillSearchBox:DisableDrawLayer("BACKGROUND")
CreateBackdrop(TradeSkillSearchBox, nil, nil, 1)
TradeSkillSkillCheckButton:SetPoint("TOPLEFT", 500, -2)
TradeSkillMatsCheckButton:SetPoint("TOPLEFT", 400, -2)
TradeSkillSearchBox:ClearAllPoints()
TradeSkillSearchBox:SetPoint("TOP", TradeSkillFrame, "BOTTOM", 0, -8)
end
end)
if C.disabled["macroicons"] == "1" then
HookAddonOrVariable("Blizzard_MacroUI", function()
if type(UpdateMacroIconFilenames) ~= "function" then return end
function _G.UpdateMacroIconFilenames()
wipe(MACRO_ICON_FILENAMES)
local provider = CreateAndInitFromMixin(IconDataProviderMixin, IconDataProviderExtraType.Spellbook)
local seen = {}
for i = 1, provider:GetNumIcons() do
-- uppercase, prefix-stripped basename, matching Blizzard's original
local icon = string.gsub(string.upper(provider:GetIconByIndex(i)), "INTERFACE\\ICONS\\", "")
if not seen[icon] then
seen[icon] = true
table.insert(MACRO_ICON_FILENAMES, icon)
end
end
provider:Release()
end
end)
end
end)