Skip to content

Commit a3f7e61

Browse files
committed
Added new module to show overall and affix rating on keystone tooltips
1 parent 38c5502 commit a3f7e61

File tree

6 files changed

+114
-50
lines changed

6 files changed

+114
-50
lines changed

MythicPlusTweaks.toc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ modules\dungeonIconText.lua
1717
modules\alwaysShowAffixes.lua
1818
modules\showOwnRatingOnLFGTooltip.lua
1919
modules\fixLeaderOverallScoreOnLFGTooltip.lua
20+
modules\showScoreOnKeystoneTooltip.lua

SharedUtil.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,37 @@ function Util:ExtractTooltipLines(tooltip)
99
local lineLeft = _G[tooltip:GetName() .. 'TextLeft' .. i];
1010
local lineRight = _G[tooltip:GetName() .. 'TextRight' .. i];
1111

12-
local left, right;
13-
if lineLeft then left = lineLeft:GetText(); end
12+
local left, leftWrap, right;
13+
if lineLeft then
14+
left = lineLeft:GetText();
15+
leftWrap = abs(lineLeft:GetWrappedWidth() - lineLeft:GetUnboundedStringWidth()) > 5;
16+
end
1417
if lineRight then right = lineRight:GetText(); end
1518

1619
if not left and not right then break; end
1720
local leftR, leftG, leftB, _ = lineLeft:GetTextColor();
1821
local rightR, rightG, rightB, _ = lineRight:GetTextColor();
19-
table.insert(linesLeft, {text=left, r=leftR, g=leftG, b=leftB});
22+
table.insert(linesLeft, {text=left, r=leftR, g=leftG, b=leftB, wrap=leftWrap});
2023
table.insert(linesRight, {text=right, r=rightR, g=rightG, b=rightB});
2124
end
2225
return linesLeft, linesRight;
2326
end
2427

28+
function Util:ReplaceTooltipLines(tooltip, linesLeft, linesRight)
29+
tooltip:ClearLines()
30+
for i = 1, max(#linesLeft, #linesRight) do
31+
local left = linesLeft[i];
32+
local right = linesRight[i];
33+
if not right or not right.text or string.len(right.text) == 0 then
34+
tooltip:AddLine(left.text, left.r, left.g, left.b, left.wrap);
35+
else
36+
tooltip:AddDoubleLine(left.text, right.text, left.r, left.g, left.b, right.r, right.g, right.b);
37+
end
38+
end
39+
40+
tooltip:Show();
41+
end
42+
2543
function Util:GetOverallInfoByMapId(mapId)
2644
local inTimeInfo, overtimeInfo = C_MythicPlus.GetSeasonBestForMap(mapId);
2745

modules/dungeonIconTooltip.lua

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Module:OnTooltipShow(tooltip)
4646
local mapId = owner.mapID
4747
local affixScores, _ = C_MythicPlus.GetSeasonBestAffixScoreInfoForMap(mapId);
4848

49-
local linesLeft, linesRight = self:ExtractTooltipLines(tooltip)
49+
local linesLeft, linesRight = Util:ExtractTooltipLines(tooltip)
5050
if(affixScores and #affixScores > 0) then
5151
self:ProcessAffixScores(linesLeft, linesRight, affixScores)
5252
end
@@ -56,16 +56,8 @@ function Module:OnTooltipShow(tooltip)
5656
table.insert(linesRight, {text=''})
5757
end
5858

59-
tooltip:ClearLines()
60-
for i = 1, max(#linesLeft, #linesRight) do
61-
local left = linesLeft[i] or ''
62-
local right = linesRight[i] or ''
63-
64-
tooltip:AddDoubleLine(left.text, right.text, left.r, left.g, left.b, right.r, right.g, right.b)
65-
end
66-
6759
self.skipOnTooltipShow = true
68-
tooltip:Show()
60+
Util:ReplaceTooltipLines(tooltip, linesLeft, linesRight);
6961
self.skipOnTooltipShow = nil
7062
end
7163

@@ -99,22 +91,3 @@ function Module:MapIdIsAddedToTooltip(linesLeft, mapId)
9991
end
10092
return false
10193
end
102-
103-
function Module:ExtractTooltipLines(tooltip)
104-
local linesLeft, linesRight = {}, {}
105-
for i = 1, 15 do
106-
local lineLeft = _G[tooltip:GetName() .. 'TextLeft' .. i]
107-
local lineRight = _G[tooltip:GetName() .. 'TextRight' .. i]
108-
109-
local left, right
110-
if lineLeft then left = lineLeft:GetText() end
111-
if lineRight then right = lineRight:GetText() end
112-
113-
if not left and not right then break end
114-
local leftR, leftG, leftB, _ = lineLeft:GetTextColor()
115-
local rightR, rightG, rightB, _ = lineRight:GetTextColor()
116-
table.insert(linesLeft, {text=left, r=leftR, g=leftG, b=leftB})
117-
table.insert(linesRight, {text=right, r=rightR, g=rightG, b=rightB})
118-
end
119-
return linesLeft, linesRight
120-
end

modules/fixLeaderOverallScoreOnLFGTooltip.lua

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,5 @@ function Module:OnTooltipShow(tooltip, resultId)
4747
end
4848
end
4949

50-
tooltip:ClearLines()
51-
for i = 1, max(#linesLeft, #linesRight) do
52-
local left = linesLeft[i] or '';
53-
local right = linesRight[i] or '';
54-
55-
tooltip:AddDoubleLine(left.text, right.text, left.r, left.g, left.b, right.r, right.g, right.b);
56-
end
57-
58-
tooltip:Show();
50+
Util:ReplaceTooltipLines(tooltip, linesLeft, linesRight);
5951
end

modules/showOwnRatingOnLFGTooltip.lua

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,5 @@ function Module:OnTooltipShow(tooltip, resultId)
8383
end
8484
end
8585

86-
tooltip:ClearLines()
87-
for i = 1, max(#linesLeft, #linesRight) do
88-
local left = linesLeft[i] or '';
89-
local right = linesRight[i] or '';
90-
91-
tooltip:AddDoubleLine(left.text, right.text, left.r, left.g, left.b, right.r, right.g, right.b);
92-
end
93-
94-
tooltip:Show();
86+
Util:ReplaceTooltipLines(tooltip, linesLeft, linesRight);
9587
end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
local _, MPT = ...;
2+
--- @type Main
3+
local Main = MPT.Main;
4+
--- @type Util
5+
local Util = MPT.Util;
6+
7+
local Module = Main:NewModule('ShowScoreOnKeystoneTooltip', 'AceHook-3.0');
8+
9+
function Module:OnEnable()
10+
self:SecureHookScript(GameTooltip, 'OnTooltipSetItem', function(tooltip) Module:OnTooltipShow(tooltip); end);
11+
self:SecureHookScript(ItemRefTooltip, 'OnTooltipSetItem', function(tooltip) Module:OnTooltipShow(tooltip); end);
12+
end
13+
14+
function Module:OnDisable()
15+
self:UnhookAll();
16+
end
17+
18+
function Module:GetDescription()
19+
return 'Adds your mythic+ score to the keystone tooltip.';
20+
end
21+
22+
function Module:GetName()
23+
return 'Show Score On Keystone Tooltip';
24+
end
25+
26+
function Module:GetOptions(defaultOptionsTable)
27+
defaultOptionsTable.args.showExample = {
28+
type = 'execute',
29+
name = 'Show Example Tooltip',
30+
desc = 'Open an example keystone tooltip.',
31+
func = function()
32+
local link = string.format('|cffa335ee|Hkeystone:180653:%d:16:10:1:2:3|h[Keystone]|h|r', C_ChallengeMode.GetMapTable()[1]);
33+
SetItemRef(link, link, 'LeftButton');
34+
end,
35+
};
36+
37+
return defaultOptionsTable;
38+
end
39+
40+
function Module:OnTooltipShow(tooltip)
41+
local _, itemLink = tooltip:GetItem();
42+
if not itemLink then return end
43+
44+
if not C_Item.IsItemKeystoneByID(itemLink:match('item:(%d+)')) then return end
45+
46+
local mapId = itemLink:match(string.format(':%s:(%%d+):', Enum.ItemModification.KeystoneMapChallengeModeID));
47+
if not mapId then return end
48+
49+
local overallInfo = Util:GetOverallInfoByMapId(mapId);
50+
local affixInfo = Util:GetAffixInfoByMapId(mapId);
51+
52+
local linesLeft, linesRight = Util:ExtractTooltipLines(tooltip);
53+
54+
for i, line in ipairs(linesLeft) do
55+
if string.find(line.text, CHALLENGE_MODE_ITEM_POWER_LEVEL) then
56+
if (overallInfo and overallInfo.score > 0) then
57+
table.insert(linesLeft, i + 1, {
58+
text = HIGHLIGHT_FONT_COLOR:WrapTextInColorCode('Your Overall: '
59+
.. overallInfo.scoreColor:WrapTextInColorCode(overallInfo.score)
60+
.. ' (' .. overallInfo.levelColor:WrapTextInColorCode(overallInfo.level) .. ')'),
61+
});
62+
table.insert(linesRight, i + 1, { text = '' });
63+
if (affixInfo and affixInfo.score > 0) then
64+
table.insert(linesLeft, i + 2, {
65+
text = HIGHLIGHT_FONT_COLOR:WrapTextInColorCode('Your Affix score: '
66+
.. affixInfo.scoreColor:WrapTextInColorCode(affixInfo.score)
67+
.. ' (' .. affixInfo.levelColor:WrapTextInColorCode(affixInfo.level) .. ')'),
68+
});
69+
table.insert(linesRight, i + 2, { text = '' });
70+
else
71+
table.insert(linesLeft, i + 2, {
72+
text = HIGHLIGHT_FONT_COLOR:WrapTextInColorCode('Your Affix score: '
73+
.. GRAY_FONT_COLOR:WrapTextInColorCode('-never completed-')),
74+
});
75+
table.insert(linesRight, i + 2, { text = '' });
76+
end
77+
else
78+
table.insert(linesLeft, i + 1, {
79+
text = HIGHLIGHT_FONT_COLOR:WrapTextInColorCode('Your Overall: ' .. GRAY_FONT_COLOR:WrapTextInColorCode('-never completed-')),
80+
});
81+
table.insert(linesRight, i + 1, { text = '' });
82+
end
83+
break;
84+
end
85+
end
86+
87+
Util:ReplaceTooltipLines(tooltip, linesLeft, linesRight);
88+
end

0 commit comments

Comments
 (0)