Skip to content

Commit

Permalink
Fix issues with copying loadout strings when inspecting someone
Browse files Browse the repository at this point in the history
  • Loading branch information
Numynum committed Dec 29, 2023
1 parent dc02d50 commit b9c1893
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
30 changes: 25 additions & 5 deletions modules/exportInspectedBuild.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,40 @@ 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
self.linkButton:Show();
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
Expand All @@ -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));
Expand Down
17 changes: 15 additions & 2 deletions modules/reduceTaint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b9c1893

Please sign in to comment.