11local _ , TTT = ... ;
22--- @type TalentTreeTweaks_Main
33local Main = TTT .Main ;
4+ --- @type TalentTreeTweaks_Util
5+ local Util = TTT .Util ;
46local L = TTT .L ;
57
6- local Module = Main :NewModule (' DebugNodeInfo' );
8+ --- @class TalentTreeTweaks_DebugNodeInfo : AceModule , AceHook-3.0 , AceEvent-3.0
9+ local Module = Main :NewModule (' DebugNodeInfo' , ' AceHook-3.0' , ' AceEvent-3.0' );
10+
11+ function Module :OnInitialize ()
12+ self .bindingButton = CreateFrame (' Button' , ' TalentTreeTweaks_DebugNodeInfoButton' );
13+ self .bindingButton :SetScript (' OnClick' , function ()
14+ if self .targetButton then
15+ self :ShowDebugInfo (self .targetButton );
16+ end
17+ end );
18+ end
719
820function Module :OnEnable ()
9- EventRegistry :RegisterCallback (' TalentButton.OnClick' , self .OnButtonClick , self );
21+ Util :OnTalentUILoad (function ()
22+ self :SetupHook (Util :GetTalentFrame ());
23+ end );
24+ Util :ContinueOnAddonLoaded (' Blizzard_GenericTraitUI' , function ()
25+ self :SetupHook (GenericTraitFrame );
26+ end );
27+ Util :ContinueOnAddonLoaded (' Blizzard_RemixArtifactUI' , function ()
28+ self :SetupHook (RemixArtifactFrame );
29+ end );
30+ Util :ContinueOnAddonLoaded (TalentViewerLoader and TalentViewerLoader :GetLodAddonName () or ' TalentTreeViewer' , function ()
31+ local talentsTab = TalentViewer and TalentViewer .GetTalentFrame and TalentViewer :GetTalentFrame ();
32+ if not talentsTab then return ; end
33+ self :SetupHook (talentsTab );
34+ end );
35+ self :RegisterEvent (' PLAYER_REGEN_DISABLED' );
36+ self :RegisterEvent (' PLAYER_REGEN_ENABLED' );
37+ EventRegistry :RegisterCallback (" TalentDisplay.TooltipCreated" , self .OnTalentTooltipCreated , self )
1038end
1139
1240function Module :OnDisable ()
13- EventRegistry :UnregisterCallback (' TalentButton.OnClick' , self );
41+ self .targetButton = nil ;
42+ self :DisableBinding ();
43+ self :UnhookAll ();
44+
45+ local talentFrame = Util :GetTalentFrameIfLoaded ();
46+ if talentFrame then
47+ talentFrame :UnregisterCallback (TalentFrameBaseMixin .Event .TalentButtonAcquired , self );
48+ end
49+ if TalentViewer then
50+ TalentViewer :GetTalentFrame ():UnregisterCallback (TalentFrameBaseMixin .Event .TalentButtonAcquired , self );
51+ end
52+ if GenericTraitFrame then
53+ GenericTraitFrame :UnregisterCallback (TalentFrameBaseMixin .Event .TalentButtonAcquired , self );
54+ end
55+ if RemixArtifactFrame then
56+ RemixArtifactFrame :UnregisterCallback (TalentFrameBaseMixin .Event .TalentButtonAcquired , self );
57+ end
58+ EventRegistry :UnregisterCallback (" TalentDisplay.TooltipCreated" , self )
1459end
1560
1661function Module :GetDescription ()
17- return L [' CTRL-clicking a talent will open a table inspector of your choice, with the nodeInfo associated with the node.' ];
62+ return L [' Allows you to press CTRL-D to open a table inspector of your choice, with the nodeInfo associated with the node.' ];
1863end
1964
2065function Module :GetName ()
@@ -27,7 +72,6 @@ function Module:GetOptions(defaultOptionsTable, db)
2772 viragDevTool = true ,
2873 luaBrowser = true ,
2974 slashDump = false ,
30- addButtonToTable = true ,
3175 }
3276 self .db = db ;
3377 for k , v in pairs (defaultDb ) do
@@ -43,21 +87,15 @@ function Module:GetOptions(defaultOptionsTable, db)
4387 return self .db [info [# info ]];
4488 end ;
4589 local order = 5 ;
46- local function increment () order = order + 1 ; return order ; end ;
90+ local function increment ()
91+ order = order + 1 ; return order ;
92+ end ;
4793
4894 defaultOptionsTable .args .extraDescription = {
4995 type = ' description' ,
5096 name = L [' You can toggle any of the following on/off to enable/disable the integration with that debug tool.' ],
5197 order = increment (),
5298 };
53- defaultOptionsTable .args .addButtonToTable = {
54- type = ' toggle' ,
55- name = L [' Add the button to NodeInfo table when dumped' ],
56- desc = L [' Adds a _button property to the nodeInfo table, which is a reference to the talent button.' ],
57- get = get ,
58- set = set ,
59- order = increment (),
60- };
6199 defaultOptionsTable .args .tinspect = {
62100 type = ' toggle' ,
63101 name = ' /tinspect' ,
@@ -96,15 +134,81 @@ function Module:GetOptions(defaultOptionsTable, db)
96134 return defaultOptionsTable ;
97135end
98136
99- function Module :OnButtonClick (buttonFrame , mouseButton )
100- if mouseButton ~= ' LeftButton' or not IsControlKeyDown () then
137+ function Module :SetupHook (talentsTab )
138+ talentsTab :RegisterCallback (TalentFrameBaseMixin .Event .TalentButtonAcquired , self .OnTalentButtonAcquired , self );
139+ for talentButton in talentsTab :EnumerateAllTalentButtons () do
140+ self :OnTalentButtonAcquired (talentButton );
141+ end
142+ self :SecureHook (talentsTab , ' ShowSelections' , ' OnShowSelections' );
143+ end
144+
145+ function Module :EnableBinding ()
146+ if not InCombatLockdown () then
147+ SetOverrideBinding (
148+ self .bindingButton ,
149+ true ,
150+ ' CTRL-D' ,
151+ string.format (' CLICK %s:LeftButton' , self .bindingButton :GetName ())
152+ );
153+ end
154+ end
155+
156+ function Module :DisableBinding ()
157+ if not InCombatLockdown () then
158+ ClearOverrideBindings (self .bindingButton );
159+ end
160+ end
161+
162+ function Module :PLAYER_REGEN_DISABLED ()
163+ if self .targetButton then
164+ self :DisableBinding ();
165+ end
166+ end
167+
168+ function Module :PLAYER_REGEN_ENABLED ()
169+ if self .targetButton then
170+ self :EnableBinding ();
171+ end
172+ end
173+
174+ function Module :OnTalentButtonEnter (talentButton )
175+ self .targetButton = talentButton ;
176+ self :EnableBinding ();
177+ end
178+
179+ function Module :OnTalentButtonLeave ()
180+ self .targetButton = nil ;
181+ self :DisableBinding ();
182+ end
183+
184+ function Module :OnTalentButtonAcquired (talentButton )
185+ if self :IsHooked (talentButton , ' OnEnter' ) then
101186 return ;
102187 end
103- local nodeInfo = buttonFrame .nodeInfo or buttonFrame .GetNodeInfo and buttonFrame :GetNodeInfo () or {};
104- if self .db .addButtonToTable then
105- nodeInfo = Mixin ({}, nodeInfo );
106- nodeInfo ._button = buttonFrame ;
188+ self :SecureHookScript (talentButton , ' OnEnter' , ' OnTalentButtonEnter' );
189+ self :SecureHookScript (talentButton , ' OnLeave' , ' OnTalentButtonLeave' );
190+ end
191+
192+ function Module :OnShowSelections (talentsTab )
193+ for _ , button in pairs (talentsTab .SelectionChoiceFrame .selectionFrameArray ) do
194+ self :OnTalentButtonAcquired (button );
195+ end
196+ end
197+
198+ function Module :OnTalentTooltipCreated (_ , tooltip )
199+ local text = GREEN_FONT_COLOR :WrapTextInColorCode (L [' CTRL-D to debug nodeInfo' ]);
200+ if InCombatLockdown () then
201+ text = string.format (' %s|cFFFF0000 %s|r' , text , L [' blocked in combat' ]);
107202 end
203+ tooltip :AddLine (text );
204+ tooltip :Show ();
205+ end
206+
207+ function Module :ShowDebugInfo (buttonFrame )
208+ local nodeInfo = buttonFrame .nodeInfo or buttonFrame .GetNodeInfo and buttonFrame :GetNodeInfo () or {};
209+ nodeInfo = Mixin ({}, nodeInfo );
210+ nodeInfo ._button = buttonFrame ;
211+ nodeInfo ._entryInfo = buttonFrame .entryInfo or buttonFrame .GetEntryInfo and buttonFrame :GetEntryInfo () or nil ;
108212
109213 if self .db .tinspect then
110214 UIParentLoadAddOn (" Blizzard_DebugTools" );
0 commit comments