Skip to content

Commit c3e2310

Browse files
committed
Add a button into the default UI; and add a popup, if you import a different spec into the default UI, allowing you to open it in TalentViewer anyway
1 parent 3cddb30 commit c3e2310

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

ImportExport.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,7 @@ function ImportExport:ImportLoadout(importText)
162162
local loadoutContent = self:ReadLoadoutContent(importStream, treeId);
163163
local loadoutEntryInfo = self:ConvertToImportLoadoutEntryInfo(treeId, loadoutContent);
164164

165-
tmpEntryInfo = loadoutEntryInfo
166-
167-
local success = TalentViewer:GetTalentFrame():ImportLoadout(loadoutEntryInfo);
168-
if(not success) then
169-
self:ShowImportError(LOADOUT_ERROR_IMPORT_FAILED);
170-
return false;
171-
end
165+
TalentViewer:GetTalentFrame():ImportLoadout(loadoutEntryInfo);
172166

173167
return true;
174168
end

TalentViewer.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ function TalentViewer:OnInitialize()
517517
end
518518

519519
self:PatchBlizzardImport()
520+
self:AddButtonToBlizzardTalentFrame()
521+
self:HookIntoBlizzardImport()
520522
end
521523

522524
function TalentViewer:PatchBlizzardImport()
@@ -527,6 +529,57 @@ function TalentViewer:PatchBlizzardImport()
527529
end
528530
end
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+
530583
function TalentViewer:ToggleTalentView()
531584
if TalentViewer_DF:IsShown() then
532585
TalentViewer_DF:Hide()

0 commit comments

Comments
 (0)