From b9c1893c71737c74b60fd876315dbedf2dd855f9 Mon Sep 17 00:00:00 2001 From: Mark W Date: Fri, 29 Dec 2023 18:35:57 +0100 Subject: [PATCH] Fix issues with copying loadout strings when inspecting someone --- modules/exportInspectedBuild.lua | 30 +++++++++++++++++++++++++----- modules/reduceTaint.lua | 17 +++++++++++++++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/modules/exportInspectedBuild.lua b/modules/exportInspectedBuild.lua index 705ae25..b337957 100644 --- a/modules/exportInspectedBuild.lua +++ b/modules/exportInspectedBuild.lua @@ -85,6 +85,7 @@ function Module:SetupHook() end if self.db.showLinkInChatButton then + self:SecureHook(talentsTab, 'UpdateInspecting', 'OnUpdateInspecting'); if not self.linkButton then self.linkButton = self:MakeLinkButton(talentsTab); end @@ -92,13 +93,32 @@ function Module:SetupHook() end end +function Module:OnUpdateInspecting(talentsTab) + local isInspecting = talentsTab:IsInspecting(); + if not isInspecting then + self.cachedInspectSpecID = nil; + self.cachedInspectClassID = nil; + self.cachedInspectUnitSex = nil; + self.cachedInspectExportString = nil; + + return; + end + self.cachedInspectSpecID = talentsTab:GetSpecID(); + self.cachedInspectClassID = talentsTab:GetClassID(); + self.cachedInspectUnitSex = talentsTab:GetClassTalentFrame():GetUnitSex(); + self.cachedInspectExportString = talentsTab:GetInspectUnit() and C_Traits.GenerateInspectImportString(talentsTab:GetInspectUnit()) or talentsTab:GetInspectString(); +end + function Module:MakeLinkButton(talentsTab) local button = CreateFrame('Button', nil, talentsTab, 'UIPanelButtonNoTooltipTemplate, UIButtonTemplate'); button:SetText(TALENT_FRAME_DROP_DOWN_EXPORT_CHAT_LINK or L['Post in Chat']); button:SetSize(100, 22); button:SetPoint('BOTTOMLEFT', 47, 5); button:SetScript('OnClick', function() - local exportString = Util:GetLoadoutExportString(talentsTab); + local specID = self.cachedInspectSpecID or talentsTab:GetSpecID(); + local classID = self.cachedInspectClassID or talentsTab:GetClassID(); + local unitSex = self.cachedInspectUnitSex or talentsTab:GetClassTalentFrame():GetUnitSex(); + local exportString = self.cachedInspectExportString or Util:GetLoadoutExportString(talentsTab); if not TALENT_BUILD_CHAT_LINK_TEXT then if not ChatEdit_InsertLink(exportString) then @@ -107,10 +127,10 @@ function Module:MakeLinkButton(talentsTab) return; end - local specName = talentsTab:GetSpecName(); - local className = talentsTab:GetClassName(); - local specID = talentsTab:GetSpecID(); - local classColor = RAID_CLASS_COLORS[select(2, GetClassInfo(talentsTab:GetClassID()))]; + local specName = select(2, GetSpecializationInfoByID(specID, unitSex)); + local classInfo = C_CreatureInfo.GetClassInfo(classID); + local className = classInfo and classInfo.className; + local classColor = RAID_CLASS_COLORS[classInfo and classInfo.classFile]; local level = LEVEL_CAP; local linkDisplayText = ("[%s]"):format(TALENT_BUILD_CHAT_LINK_TEXT:format(specName, className)); diff --git a/modules/reduceTaint.lua b/modules/reduceTaint.lua index 80f81e3..2aa7147 100644 --- a/modules/reduceTaint.lua +++ b/modules/reduceTaint.lua @@ -114,15 +114,28 @@ function Module:SetupHook() self:SecureHook('ShowUIPanel', 'OnShowUIPanel') self:SecureHook('HideUIPanel', 'OnHideUIPanel') + self:SecureHook(talentsTab, 'UpdateInspecting', 'OnUpdateInspecting'); self:ReplaceCopyLoadoutButton(talentsTab); self:HandleMultiActionBarTaint(); end +function Module:OnUpdateInspecting(talentsTab) + local isInspecting = talentsTab:IsInspecting(); + if not isInspecting then + self.cachedInspectExportString = nil; + + return; + end + self.cachedInspectExportString = talentsTab:GetInspectUnit() and C_Traits.GenerateInspectImportString(talentsTab:GetInspectUnit()) or talentsTab:GetInspectString(); +end + function Module:ReplaceCopyLoadoutButton(talentsTab) talentsTab.InspectCopyButton:SetOnClickHandler(function() - local loadoutString = talentsTab:GetInspectUnit() and C_Traits.GenerateInspectImportString(talentsTab:GetInspectUnit()) or talentsTab:GetInspectString(); - if loadoutString ~= '' then + local loadoutString = + self.cachedInspectExportString + or (talentsTab:GetInspectUnit() and C_Traits.GenerateInspectImportString(talentsTab:GetInspectUnit()) or talentsTab:GetInspectString()); + if loadoutString and (loadoutString ~= "") then Util:CopyText(loadoutString, L['Inspected Build']); end end);