|
| 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