Files

416 lines
23 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Adapt only the existing Forever TalentsFrame instance. Native frames, pools,
-- backgrounds, node art, animation controllers, navigation and N stay intact.
local addonName=(...) or 'GatewayDiagnostics'
local provider=GatewayTurtleTalentProvider.New(GatewayTurtleData)
GatewayTurtleTalents=provider
-- These three Source header textures differ from the art at their original paths.
local sourceHeaderIcons = {
[282] = 8764237, -- Druid Restoration
[383] = 8764238, -- Paladin Protection
[301] = 8764239, -- Warlock Destruction
}
local driver=CreateFrame('Frame')
local native,refresh,busy,talentTooltipOwner
local function inspecting(frame)
frame=frame or native
return frame and frame:IsInspecting() or false
end
local function ownContext(frame)
return provider:ActiveContext(inspecting(frame))
end
local function control(text)
-- The normal addon-message API permits asynchronous delivery. SAY does not:
-- actual70334 blocks its second purchase in CHAT_MSG_SYSTEM with no hardware
-- event. Native code accepts only this prefix, WHISPER and authenticated self.
return C_ChatInfo.SendAddonMessage('GWTURTLE',text,'WHISPER',UnitName('player'))
end
local function request() if not inspecting()then control('state')end end
local function hideNativeBuildControls(frame)
for _,key in ipairs({'TabSystem','ActiveSpec','LoadSystem','GamepadPrimaryTabIcon','GamepadSecondaryTabIcon','InspectCopyButton'})do
local control=frame[key];if control then control:Hide()end
end
end
local function activeContext(frame)
local isInspecting=inspecting(frame)
local context=ownContext(frame)
local unit=isInspecting and frame:GetInspectUnit()or nil
local target=unit and type(UnitGUID)=='function'and UnitGUID(unit)or unit
local inspectString=isInspecting and not unit and type(frame.GetInspectString)=='function'and frame:GetInspectString()or nil
local key=isInspecting and('inspect:'..tostring(unit)..':'..tostring(target)..':'..tostring(inspectString))
or(context and('self:'..tostring(context.guid)..':'..tostring(context.class))or'self:unavailable')
if frame.turtleViewKey~=key then
frame.turtleViewKey=key
if talentTooltipOwner then
if GameTooltip:IsOwned(talentTooltipOwner)then GameTooltip:Hide()end
talentTooltipOwner=nil
end
if isInspecting then StaticPopup_Hide('GATEWAY_TURTLE_TALENT_RESET')end
-- These original frame APIs clear pooled nodes/edges and every native
-- info cache. A changed target must not retain the previous view.
frame:ReleaseAllTalentButtons();frame:ClearInfoCaches()
frame.treeHeaderPool:ReleaseAll();frame.treeHeaders={}
frame.talentTreeInfo=nil;frame.treeCurrencyInfo={};frame.treeCurrencyInfoMap={}
frame:MarkTreeDirty()
end
frame.turtleActiveContext=context
frame.turtleInspectUnavailable=isInspecting
-- The original currency renderer falls back to zero when data is absent.
-- Hide its widget for an unavailable view instead of implying zero points.
frame.ClassCurrencyDisplay:SetShown(context~=nil)
-- No native configuration/tree ID is created. All Turtle reads and writes
-- stay on this frame's provider boundary, never on C_Traits purchase APIs.
frame.configurationInfo=nil;frame.talentTreeID=nil
frame:SetDisabledOverlayShown(frame.turtleActiveContext==nil)
if not frame.GatewayTurtleInspectNotice then
local text=frame.DisabledOverlay:CreateFontString(nil,'OVERLAY','GameFontHighlight')
text:SetPoint('CENTER');text:SetWidth(430)
text:SetText('Inspected Turtle talent data is unavailable.\nNo inspected ranks were received. This view is read-only.')
frame.GatewayTurtleInspectNotice=text
end
frame.GatewayTurtleInspectNotice:SetShown(isInspecting)
hideNativeBuildControls(frame)
return context
end
StaticPopupDialogs.GATEWAY_TURTLE_TALENT_RESET={
text='Reset all learned Turtle talents for %s?',button1=ACCEPT,button2=CANCEL,
OnAccept=function(_,offer)
if ownContext()and offer and provider.resetOffer==offer then
control('reset '..offer.guid);provider.resetOffer=nil
end
end,
timeout=0,whileDead=false,hideOnEscape=true,preferredIndex=3,
}
local function showReset()
if not ownContext()then return end
local offer=provider.resetOffer;if not offer then return end
-- The removed global GetCoinTextureString is nil in70334. The offer's
-- authoritative copper cost is exact; no modern currency API is needed.
local cost=string.format('%dg %ds %dc',math.floor(offer.cost/10000),math.floor(offer.cost/100)%100,offer.cost%100)
StaticPopup_Show('GATEWAY_TURTLE_TALENT_RESET',cost,nil,offer)
end
local function description(r)
return provider.FormatDescription(r,provider.spellRecords)
end
local function addDescription(r)
local text,unresolved=description(r)
GameTooltip:AddLine(text,1,1,1,true)
if #unresolved>0 then GameTooltip:AddLine('Some tooltip values are unavailable.',1,.65,.2,true)end
end
local function tooltip(button)
if not ownContext()then GameTooltip:Hide();talentTooltipOwner=nil;return end
local t=provider.byID[button:GetNodeID()];if not t then return end
local info=provider:TooltipInfo(t.id);local current,actual=info.rank,info.committedRank
talentTooltipOwner=button
GameTooltip:SetOwner(button,'ANCHOR_RIGHT');GameTooltip:AddLine(info.record.name,1,.82,0)
GameTooltip:AddLine(current==0 and ('Unlearned (0/'..info.maxRanks..')')or ('Talent rank '..current..'/'..info.maxRanks),1,1,1)
if info.trainedAbilityRank and info.trainedAbilityRank~=''then GameTooltip:AddLine('Learned ability: '..info.trainedAbilityRank,.8,.8,.8)end
if current~=actual then GameTooltip:AddLine('Pending allocation; server rank '..actual,.2,1,.2) end
if current==0 then GameTooltip:AddLine('First rank (1/'..info.maxRanks..')',.8,.8,.8)end
addDescription(info.record)
if info.nextRecord then
GameTooltip:AddLine('Next rank ('..(current+1)..'/'..info.maxRanks..')',.8,.8,.8)
addDescription(info.nextRecord)
end
if t.row>0 then GameTooltip:AddLine('Requires '..(t.row*5)..' points in '..provider.tabs[t.tab].name,.8,.8,.8,true)end
if t.prerequisite~=0 then GameTooltip:AddLine('Requires '..provider.byID[t.prerequisite].ranks[1].name..' rank '..(t.prerequisiteRank+1),.8,.8,.8,true)end
if provider:CanPurchase(t.id) then GameTooltip:AddLine('Click to allocate a point',.2,1,.2)end
GameTooltip:Show()
end
local function bindButton(b)
-- The native pool and mixins still own sizing, art and animations. Spell
-- tooltips/drag are replaced because identical IDs can have different data.
b.SetTooltipInternal=tooltip
b.OnDragStart=function()end -- Missing Turtle spell data must not create an unrelated action.
b.SetSearchMatchType=function()end -- Search is supplied below from genuine Turtle text.
end
local function auditApply(p,status,reason)
GatewayDiagnosticsSaved=GatewayDiagnosticsSaved or {}
GatewayDiagnosticsSaved.turtleApply={status=status,reason=reason,accepted=p.accepted,total=p.total,
remaining=p.total-p.accepted,guid=p.guid,points=provider.state and provider.state.points,steps=p.steps}
if p.expected then
local e=p.expected
GatewayDiagnosticsSaved.turtleApply.inFlight={id=e.id,rank=e.rank,priorRank=e.priorRank,
observedRank=provider:Rank(e.id,false),expectedPoints=e.points,
observedPoints=provider.state and provider.state.points}
end
end
local function stopApply(reason)
local p=provider.pending;if not p then return end
auditApply(p,'stopped',reason);provider.pending=nil
-- Preserve unaccepted selections for review, but do not retry anything.
provider.resyncSeq=provider.state and provider.state.seq
refresh();request()
print('Turtle Apply stopped: '..p.accepted..'/'..p.total..' points acknowledged; accepted purchases remain. '..reason)
if p.expected and provider:Rank(p.expected.id,false)>=p.expected.rank then
print('The in-flight rank is visible, but its point cost was not confirmed; fresh server state is required.')
end
end
local function sendNext()
if not ownContext()then return end
local p=provider.pending;if not p then return end
if p.expected then
if not provider:PurchaseAcknowledged(p.expected)then return end
p.accepted=p.accepted+1
p.steps[#p.steps+1]={id=p.expected.id,rank=p.expected.rank,points=provider.state.points,seq=provider.state.seq}
p.expected=nil
end
local nextPurchase=table.remove(p.queue,1)
if not nextPurchase then
auditApply(p,'complete');provider.pending=nil;refresh();return
end
local expected=provider:PurchaseExpectation(nextPurchase.id,nextPurchase.rank)
if not expected then stopApply('server-state-or-prerequisites-changed');return end
p.id,p.rank,p.expected=nextPurchase.id,nextPurchase.rank,expected;p.deadline=GetTime()+8
auditApply(p,'waiting')
local ok=pcall(control,'learn '..p.id..' '..p.rank)
if not ok then stopApply('control-delivery-failed')end
end
local function apply()
if not ownContext()then return end
if provider.pending or provider.resyncSeq then return end
local queue,reason=provider:Purchases()
if not queue then print('Turtle Apply rejected before sending: '..reason);return end
if #queue==0 then return end
provider.pending={queue=queue,total=#queue,accepted=0,steps={},guid=provider.state.guid}
sendNext();refresh()
end
local function install(frame)
if native then return native==frame or frame==nil end
frame=frame or (PlayerSpellsFrame and PlayerSpellsFrame.TalentsFrame)
if not frame then return false end
native=frame
native.GetConfigID=function()return nil end
native.GetTalentTreeID=function()return nil end
native.HasValidConfig=function(self)return ownContext(self)~=nil end
native.RefreshConfigID=function(self)activeContext(self);if refresh then refresh()end end
native.SetConfigID=native.RefreshConfigID
native.SetTalentTreeID=native.RefreshConfigID
native.LoadTalentTree=function(self)
activeContext(self)
if not self:HasValidConfig()then self:ReleaseAllTalentButtons();self:MarkTreeClean();return end
if not self:IsShown()then self:MarkTreeDirty();return end
self:UpdateTreeInfo(true);self:LoadTalentTreeInternal()
end
native.CheckSetSelectedConfigID=hideNativeBuildControls
native.RefreshLoadoutOptions=hideNativeBuildControls
native.SetSelectedSavedConfigID=hideNativeBuildControls
native.InitializeTabSystem=hideNativeBuildControls
native.UpdateTabs=hideNativeBuildControls
native.InitializeActiveSpec=hideNativeBuildControls
native.SetTab=hideNativeBuildControls
native.IsActiveTabSelected=function()return true end
native.CheckLoadSystemTutorials=function()end
native.GetHasStarterBuild=function()return false end
native.GetIsStarterBuildActive=function()return false end
local originalUpdateInspecting=native.UpdateInspecting
native.UpdateInspecting=function(self,...)
activeContext(self)
originalUpdateInspecting(self,...);activeContext(self)
end
native.GetTreeNodes=function(self)
if not ownContext(self)then return {}end
local ids={}
for _,tab in ipairs(provider:ClassTabs())do
for _,t in ipairs(provider.talentsByTab[tab.id] or {})do ids[#ids+1]=t.id end
end
return ids
end
native.GetAndCacheNodeInfo=function(self,id)
if not ownContext(self)then return nil end
local t=provider.byID[id];if not t then return nil end
local current=provider:Rank(id,true);local actual=provider:Rank(id,false)
local group=0;for i,tab in ipairs(provider:ClassTabs())do if tab.id==t.tab then group=i-1 end end
local edges={}
for _,child in ipairs(provider.childrenByPrerequisite[id] or {})do
edges[#edges+1]={targetNode=child.id,type=Enum.TraitEdgeType.RequiredForAvailability,
visualStyle=Enum.TraitEdgeVisualStyle.Straight,isActive=current>=child.prerequisiteRank+1}
end
local available=provider.state and provider:Spent(t.tab,true)>=t.row*5
local meets=t.prerequisite==0 or provider:Rank(t.prerequisite,true)>=t.prerequisiteRank+1
return {ID=id,type=Enum.TraitNodeType.Single,flags=0,posX=1020+group*4000+t.column*600,posY=2130+t.row*600,
entryIDs={id},activeEntry={entryID=id,rank=current},activeRank=current,currentRank=current,ranksPurchased=current,
ranksIncreased=0,maxRanks=#t.ranks,isVisible=true,isAvailable=not not available,meetsEdgeRequirements=meets,
canPurchaseRank=provider:CanPurchase(id),canRefundRank=false,isRefundInvalid=false,conditionIDs={},groupIDs={t.tab},
visibleEdges=edges,entryIDsWithCommittedRanks=actual>0 and {id} or {},ranksGranted=0}
end
native.GetAndCacheEntryInfo=function(self,id)
if not ownContext(self)then return nil end
local t=provider.byID[id];if not t then return nil end
return {ID=id,definitionID=id,type=Enum.TraitNodeEntryType.SpendSquare,maxRanks=#t.ranks,entryCost={},isAvailable=true}
end
native.GetAndCacheDefinitionInfo=function(self,id)
if not ownContext(self)then return nil end
local t=provider.byID[id];if not t then return nil end
local r=provider:TooltipInfo(id).record
return {ID=id,spellID=r.id,overrideIcon=r.icon or 'Interface\\Icons\\INV_Misc_QuestionMark',overrideName=r.name,overrideDescription=description(r)}
end
native.GetAndCacheCondInfo=function()return nil end
native.UpdateTreeInfo=function(self,skip)
if not ownContext(self)then self.talentTreeInfo=nil;self:UpdateTreeCurrencyInfo(skip);return end
self.talentTreeInfo={ID=self:GetTalentTreeID(),minZoom=1,maxZoom=1,buttonSize=40,hideSingleRankNumbers=false,gates={},cannotRefund=false}
self:UpdateTreeCurrencyInfo(skip)
end
native.UpdateTreeCurrencyInfo=function(self,skip)
if not ownContext(self)then
self.treeCurrencyInfo={};self.treeCurrencyInfoMap={}
self:RefreshTreeHeaders()
self:TriggerEvent('TreeCurrencyInfoUpdated',self.treeCurrencyInfo)
return
end
self.treeCurrencyInfo={{traitCurrencyID=1,quantity=provider:AvailablePoints(),spent=provider:Spent(nil,true),maxQuantity=provider.state and provider.state.points+provider:Spent(nil,false) or 0}}
self.treeCurrencyInfoMap={[1]=self.treeCurrencyInfo[1]}
self:RefreshClassCurrencyDisplay();self:RefreshTreeHeaders()
if not skip then self:UpdateAllButtons()end
self:TriggerEvent('TreeCurrencyInfoUpdated',self.treeCurrencyInfo)
end
native.RefreshTreeHeaders=function(self)
self.treeHeaderPool:ReleaseAll();self.treeHeaders={}
if not ownContext(self)then return end
for i,tab in ipairs(provider:ClassTabs())do
local h=self.treeHeaderPool:Acquire('ClassTalentTreeHeaderTemplate')
local icon = tab.icon
local sourceIcon = sourceHeaderIcons[tab.id]
if sourceIcon and C_UIFileAsset and C_UIFileAsset.IsKnownFile and C_UIFileAsset.IsKnownFile(sourceIcon) then
icon = sourceIcon
end
h:Setup({displayName=tab.name,icon=icon}, {currencyInfos={{spent=provider:Spent(tab.id,true)}}})
h:SetPoint('CENTER',self.BackgroundBorder,'TOPLEFT',140+(i-1)*400,-100);h:Show();self.treeHeaders[#self.treeHeaders+1]=h
end
end
native.GetNodeCost=function(self)if not ownContext(self)then return {}end;return {{ID=1,amount=1}}end
native.IsLocked=function(self)return not self:HasValidConfig() or (provider.pending~=nil or provider.resyncSeq~=nil) or InCombatLockdown()end
native.HasMassPurchase=function()return false end
native.PurchaseRank=function(self,id)if ownContext(self)then return provider:Stage(id)end;return false end
native.RefundRank=function()end -- Turtle only permits complete trainer resets.
native.GetConfigApplicationState=function(self)if not ownContext(self)then return false,false end;local staged=next(provider.staged)~=nil;return staged,staged and not provider.pending and not provider.resyncSeq and not InCombatLockdown()end
native.HasAnyConfigChanges=function(self)return ownContext(self)~=nil and next(provider.staged)~=nil end
native.HasAnyPendingChanges=function(self)return ownContext(self)~=nil and(next(provider.staged)~=nil or provider.pending~=nil)end
native.HasAnyPurchasedRanks=function(self)return ownContext(self)~=nil and provider:Spent(nil,false)>0 end
native.RollbackConfig=function(self)if ownContext(self)then provider:Undo()end end
native.ApplyConfig=apply
native.CommitConfigInternal=apply
native.ApplyButton:SetOnClickHandler(apply)
native.UndoButton:SetOnClickHandler(function()if ownContext()then provider:Undo()end end)
native.ResetButton:SetupMenu(function(_,root)
if not ownContext()then root:CreateTitle('Inspected Turtle talent data is unavailable.');return end
root:CreateTitle('Turtle talent reset')
root:CreateButton('Undo uncommitted allocation',function()if ownContext()then provider:Undo()end end)
if provider.resetOffer then root:CreateButton('Reset learned talents at this trainer',showReset)
else root:CreateTitle('Learned talents must be reset at a class trainer.')end
end)
-- These inherited methods consult native spell/trait search data. Replace
-- just this frame's search behavior; do not override global engine APIs.
native.UpdateStarterBuildHighlights=function()end
native.UpdateTalentActionBarStatuses=function()end
native.UpdateFullSearchResults=function()end
native.SearchBox:Hide();native.SearchOptionsDropdown:Hide()
native:HookScript('OnShow',function()hideNativeBuildControls(native);request();refresh()end)
native:RegisterCallback(TalentFrameBaseMixin.Event.TalentButtonAcquired,function(_,b)bindButton(b)end,driver)
activeContext(native)
refresh()
return true
end
refresh=function()
if not native or busy then return end
busy=true
activeContext(native)
if not native:HasValidConfig()then
native:ReleaseAllTalentButtons();native:MarkTreeClean();native:UpdateConfigButtonsState()
else
native:UpdateTreeInfo(true)
if native:IsShown()then
local first=native:GetTreeNodes()[1]
if first and native:GetTalentButtonByNodeID(first) then
for b in native:EnumerateAllTalentButtons()do b:UpdateNodeInfo()end
else native:LoadTalentTreeInternal()end
native:UpdateConfigButtonsState()
else native:MarkTreeDirty()end
end
busy=false
end
-- RefreshConfigID is called inside original XML OnLoad -> UpdateInspecting,
-- before PlayerSpells' ADDON_LOADED. Bind after its base OnLoad but defer the
-- full install until this call, after the original class header pools exist.
-- Original CRLF file SHA256: c15efc584f4ac901dfd8f7a330e229b3ac91b4660846c28bb6c85d074460db81.
function GatewayTurtleTalentRefreshNativeConfig(frame)
if not install(frame)then return false end
native:RefreshConfigID();return true
end
local baseLoadHooked=false
local function armEarlyBinding()
if baseLoadHooked then return true end
if type(TalentFrameBaseMixin)~='table' or type(TalentFrameBaseMixin.OnLoad)~='function' or type(hooksecurefunc)~='function'then return false end
hooksecurefunc(TalentFrameBaseMixin,'OnLoad',function(frame)
if not ClassTalentsFrameMixin or frame.RefreshConfigID~=ClassTalentsFrameMixin.RefreshConfigID or frame.gatewayTurtleRefreshArmed then return end
-- Do not render or access the not-yet-created treeHeaderPool here.
frame.gatewayTurtleRefreshArmed=true
frame.RefreshConfigID=function(self)return GatewayTurtleTalentRefreshNativeConfig(self)end
end)
baseLoadHooked=true;return true
end
provider.listeners[#provider.listeners+1]=function()
GatewayDiagnosticsSaved=GatewayDiagnosticsSaved or {}
GatewayDiagnosticsSaved.turtleState=provider.state
GatewayDiagnosticsSaved.turtleStateActive=provider.state~=nil
if provider.state then
-- Counted source snapshots are bounded by4096 spells. Retain only the
-- acknowledged scalar fields and copied known IDs, never staged ranks.
-- This audit record is never read to initialize the live provider.
local state=provider.state;local known={}
for id in pairs(state.known)do known[id]=true end
GatewayDiagnosticsSaved.turtleLastAcknowledgedState={seq=state.seq,guid=state.guid,class=state.class,
level=state.level,points=state.points,count=state.count,known=known}
end
refresh()
end
provider:Clear() -- Saved audit state is deliberately not authenticated live state.
driver:RegisterEvent('ADDON_LOADED');driver:RegisterEvent('CHAT_MSG_SYSTEM');driver:RegisterEvent('PLAYER_ENTERING_WORLD');driver:RegisterEvent('PLAYER_LEAVING_WORLD')
driver:RegisterEvent('ADDON_ACTION_BLOCKED');driver:RegisterEvent('ADDON_ACTION_FORBIDDEN')
driver:RegisterEvent('PLAYER_TARGET_CHANGED');driver:RegisterEvent('INSPECT_READY')
driver:SetScript('OnEvent',function(_,event,message,blockedFunction)
if event=='ADDON_ACTION_BLOCKED'or event=='ADDON_ACTION_FORBIDDEN'then
if message==addonName then
GatewayDiagnosticsSaved=GatewayDiagnosticsSaved or {}
local rows=GatewayDiagnosticsSaved.turtleBlockedActions or {}
GatewayDiagnosticsSaved.turtleBlockedActions=rows
if #rows<16 then rows[#rows+1]={event=event,addon=message,
func=type(blockedFunction)=='string'and blockedFunction:sub(1,128)or nil,
stack=type(debugstack)=='function'and debugstack():sub(1,4096)or nil}end
stopApply('client-protected-action-rejected')
end
elseif event=='CHAT_MSG_SYSTEM' then
local guid,cost=message:match('^GWTURTLE1 RESET (%d+) (%d+)$')
if guid then
-- Keep64-bit creature GUID as a string: Lua numbers lose precision.
provider.resetOffer=guid~='0' and {guid=guid,cost=tonumber(cost)} or nil
if provider.resetOffer then showReset()end
elseif message:match('^GWTURTLE1 ERROR ')then stopApply(message:sub(17))
elseif provider:Receive(message) then sendNext()end
elseif event=='PLAYER_TARGET_CHANGED'or event=='INSPECT_READY'then refresh()
elseif event=='PLAYER_LEAVING_WORLD'then provider:Clear()
elseif event=='PLAYER_ENTERING_WORLD'then provider:Clear();install()
else armEarlyBinding();install()end
end)
driver:SetScript('OnUpdate',function()
local p=provider.pending
if p and p.deadline and GetTime()>p.deadline then
stopApply('rank-and-point-acknowledgement-timeout')
end
end)
if type(ChatFrame_AddMessageEventFilter)=='function'then
ChatFrame_AddMessageEventFilter('CHAT_MSG_SYSTEM',function(_,_,message)return type(message)=='string'and message:match('^GWTURTLE1 ')~=nil end)
end
SLASH_GATEWAYTURTLETALENTS1='/turtletalents'
SlashCmdList.GATEWAYTURTLETALENTS=function()
if not PlayerSpellsFrame and C_AddOns and C_AddOns.LoadAddOn then C_AddOns.LoadAddOn('Blizzard_PlayerSpells')end
install()
-- This command explicitly opens the player's own pane. Clear only the
-- original UI inspection context; never repurpose another player's data.
if native then PlayerSpellsFrame:SetInspectUnit(nil)end
request()
if native then PlayerSpellsFrame:SetTab(PlayerSpellsFrame.talentTabID);ShowUIPanel(PlayerSpellsFrame);refresh()end
end
armEarlyBinding();install()