@@ -517,6 +517,8 @@ function TalentViewer:OnInitialize()
517517 end
518518
519519 self :PatchBlizzardImport ()
520+ self :AddButtonToBlizzardTalentFrame ()
521+ self :HookIntoBlizzardImport ()
520522end
521523
522524function TalentViewer :PatchBlizzardImport ()
@@ -527,6 +529,57 @@ function TalentViewer:PatchBlizzardImport()
527529 end
528530end
529531
532+ function TalentViewer :AddButtonToBlizzardTalentFrame ()
533+ local button = CreateFrame (' Button' , nil , ClassTalentFrame , ' UIPanelButtonTemplate' )
534+ button :SetText (' Talent Viewer' )
535+ button :SetSize (100 , 22 )
536+ button :SetPoint (' TOPRIGHT' , ClassTalentFrame , ' TOPRIGHT' , - 22 , 0 )
537+ button :SetScript (' OnClick' , function ()
538+ TalentViewer :ToggleTalentView ()
539+ end )
540+ button :SetFrameStrata (' HIGH' )
541+ end
542+
543+ function TalentViewer :HookIntoBlizzardImport ()
544+ --- @type TalentViewerImportExport
545+ local ImportExport = ns .ImportExport
546+ local lastError
547+ local importString
548+
549+ StaticPopupDialogs [" TalentViewerDefaultImportFailedDialog" ] = {
550+ text = LOADOUT_ERROR_WRONG_SPEC .. " \n\n " .. " Would you like to open the build in Talent Viewer instead?" ,
551+ button1 = OKAY ,
552+ button2 = CLOSE ,
553+ OnAccept = function (dialog )
554+ ClassTalentLoadoutImportDialog :OnCancel ()
555+ ImportExport :ImportLoadout (importString )
556+ if TalentViewer_DF :IsShown () then
557+ TalentViewer_DF :Raise ()
558+ else
559+ TalentViewer :ToggleTalentView ()
560+ end
561+ dialog :Hide ();
562+ end ,
563+ timeout = 0 ,
564+ whileDead = true ,
565+ hideOnEscape = true ,
566+ preferredIndex = 3 ,
567+ };
568+
569+ hooksecurefunc (ClassTalentFrame .TalentsTab , ' ImportLoadout' , function (self , str )
570+ if lastError == LOADOUT_ERROR_WRONG_SPEC then
571+ importString = str
572+ StaticPopup_Hide (' LOADOUT_IMPORT_ERROR_DIALOG' )
573+
574+ StaticPopup_Show (' TalentViewerDefaultImportFailedDialog' )
575+ end
576+ lastError = nil
577+ end )
578+ hooksecurefunc (ClassTalentFrame .TalentsTab , ' ShowImportError' , function (self , error )
579+ lastError = error
580+ end )
581+ end
582+
530583function TalentViewer :ToggleTalentView ()
531584 if TalentViewer_DF :IsShown () then
532585 TalentViewer_DF :Hide ()
0 commit comments