This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tooltip.lua
152 lines (116 loc) · 3.72 KB
/
Tooltip.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
local _, addon = ...;
local module = addon:RegisterModule("Tooltip");
local function hasItemsToDisplay(entry)
if not entry then
return false;
end
local currentEntry = entry;
while currentEntry do
if currentEntry.goal > 0 then
return true;
end
currentEntry = currentEntry.lowerItem;
end
return false;
end
local function hookScript(table, name, func)
if table and table:HasScript(name) then
table:HookScript(name, func);
end
end
-- function from SharedTooltipTemplates.lua
local function addColoredLine(tooltip, text, color, wrap, leftOffset)
local r, g, b = color:GetRGB();
if wrap == nil then
wrap = true;
end
tooltip:AddLine(text, r, g, b, wrap, leftOffset)
end
local function addObjectiveLine(tooltip, entryType, id)
if not id or id == "" or not tooltip or not tooltip.GetName then
return;
end
if type(id) == "table" and #id == 1 then
id = id[1];
end
local entries = addon.getItemlist();
if not entries then
print("Entries not available");
return;
end
local entry = entries[id];
if not entry then
return;
end
if not hasItemsToDisplay(entry) then
return;
end
tooltip:AddLine(" ");
local group = entries[entry.parent];
if group then
tooltip:AddLine(format("%s: %s", addon.T["GATHERING"], group.name));
else
tooltip:AddLine(addon.T["GATHERING"]);
end
local currentEntry = entry;
while currentEntry do
if currentEntry.goal > 0 then
local progressCount = min(currentEntry.itemCount, currentEntry.goal);
local entryProgressInfo = string.format("%s: %d/%d", currentEntry.displayName, progressCount, currentEntry.goal);
local fulfilled = currentEntry.itemCount >= currentEntry.goal;
local color = fulfilled and GRAY_FONT_COLOR or HIGHLIGHT_FONT_COLOR;
addColoredLine(tooltip, QUEST_DASH .. " " .. entryProgressInfo, color);
end
currentEntry = currentEntry.lowerItem;
end
end
local function getItemIdFromRecipe()
if TradeSkillFrame == nil or not TradeSkillFrame:IsVisible() or not GetMouseFocus().reagentIndex then
return;
end
local selectedRecipe = TradeSkillFrame.RecipeList:GetSelectedRecipeID();
for i = 1, 8 do
if GetMouseFocus().reagentIndex == i then
return C_TradeSkillUI.GetRecipeReagentItemLink(selectedRecipe, i):match("item:(%d*)") or nil;
end
end
end
local function extendItemTooltip(tooltip)
local link = select(2, tooltip:GetItem());
if not link then
return;
end
local itemString = string.match(link, "item:([%-?%d:]+)");
if not itemString then
return;
end
local id = string.match(link, "item:(%d*)");
if (id == "" or id == "0") then
id = getItemIdFromRecipe();
end
if id then
addObjectiveLine(tooltip, addon.EntryTypes.item, id);
end
end
local function extendTooltipFromItemData(tooltip, data)
addObjectiveLine(tooltip, addon.EntryTypes.item, data.id);
end
hooksecurefunc(GameTooltip, "SetRecipeReagentItem", function(tooltip, itemId)
addObjectiveLine(tooltip, addon.EntryTypes.item, itemId);
end);
hookScript(GameTooltip, "OnTooltipSetItem", extendItemTooltip);
hookScript(ItemRefTooltip, "OnTooltipSetItem", extendItemTooltip);
hookScript(ItemRefShoppingTooltip1, "OnTooltipSetItem", extendItemTooltip);
hookScript(ItemRefShoppingTooltip2, "OnTooltipSetItem", extendItemTooltip);
hookScript(ShoppingTooltip1, "OnTooltipSetItem", extendItemTooltip);
hookScript(ShoppingTooltip2, "OnTooltipSetItem", extendItemTooltip);
if TooltipDataProcessor then
TooltipDataProcessor.AddTooltipPostCall(TooltipDataProcessor.AllTypes, function(tooltip, data)
if not data or not data.type then
return;
end
if data.type == Enum.TooltipDataType.Item then
extendTooltipFromItemData(tooltip, data)
end
end);
end