-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFurCTooltip.lua
126 lines (110 loc) · 3.94 KB
/
FurCTooltip.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
local async = LibAsync
local task = async:Create("FurnitureCatalogue_Tooltip")
local src = FurC.Constants.ItemSources
local function tryColorize(text)
if not (text and FurC.GetColouredTooltips()) then
return text
end
return text:gsub("cannot craft", "|cFF0000cannot craft"):gsub("Can be crafted", "|c00FF00Can be crafted")
end
local TYPE_STRING = "string"
local function add(t, arg)
if nil ~= arg and (TYPE_STRING ~= type(t) or #t > 0) then
t[#t + 1] = arg
end
return t
end
local function addTooltipData(control, itemLink)
if FurC.GetDisableTooltips() then
return
end
if nil == itemLink or "" == itemLink then
return
end
local isRecipe = IsItemLinkFurnitureRecipe(itemLink)
itemLink = (isRecipe and GetItemLinkRecipeResultItemLink(itemLink)) or itemLink
if not (isRecipe or IsItemLinkPlaceableFurniture(itemLink)) then
return
end
itemId = GetItemLinkItemId(itemLink)
recipeArray = FurC.Find(itemLink)
-- |H0:item:118206:5:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h
if not recipeArray then
return
end
local unknown = not FurC.CanCraft(itemId, recipeArray)
local stringTable = {}
-- if craftable:
if isRecipe or recipeArray.origin == src.CRAFTING then
if unknown and not FurC.GetHideUnknown() or not FurC.GetHideKnowledge() then
local crafterList = FurC.GetCrafterList(itemLink, recipeArray)
if crafterList then
stringTable = add(stringTable, tryColorize(crafterList))
end
end
if not isRecipe and (not FurC.GetHideCraftingStation()) then
stringTable = add(stringTable, FurC.PrintCraftingStation(itemId, recipeArray))
end
if isRecipe then
stringTable = add(stringTable, FurC.getRecipeSource(itemId, recipeArray))
end
-- check if we should show mats
if not (FurC.GetHideMats() or isRecipe) then
stringTable = add(stringTable, FurC.GetMats(itemLink, recipeArray, true):gsub(", ", "\n"))
end
else
if not FurC.GetHideSource() then
stringTable = add(stringTable, FurC.GetItemDescription(itemId, recipeArray))
end
stringTable = add(stringTable, recipeArray.achievement)
end
if #stringTable == 0 then
return
end
control:AddVerticalPadding(8)
ZO_Tooltip_AddDivider(control)
for i = 1, #stringTable do
control:AddLine(zo_strformat("<<C:1>>", stringTable[i]))
end
end
local function TooltipHook(tooltipControl, method, linkFunc)
local origMethod = tooltipControl[method]
tooltipControl[method] = function(self, ...)
origMethod(self, ...)
addTooltipData(self, linkFunc(...))
end
end
local function ReturnItemLink(itemLink)
if FurC.showBlueprints then
local recipeArray = FurC.Find(itemLink)
if recipeArray and recipeArray.blueprint then
return FurC.Utils.GetItemLink(recipeArray.blueprint)
end
end
return FurC.Utils.GetItemLink(itemLink)
end
do
local identifier = FurC.name .. "Tooltips"
-- hook real late
local function HookToolTips()
EVENT_MANAGER:UnregisterForUpdate(identifier)
TooltipHook(ItemTooltip, "SetBagItem", GetItemLink)
TooltipHook(ItemTooltip, "SetTradeItem", GetTradeItemLink)
TooltipHook(ItemTooltip, "SetBuybackItem", GetBuybackItemLink)
TooltipHook(ItemTooltip, "SetStoreItem", GetStoreItemLink)
TooltipHook(ItemTooltip, "SetAttachedMailItem", GetAttachedItemLink)
TooltipHook(ItemTooltip, "SetLootItem", GetLootItemLink)
TooltipHook(ItemTooltip, "SetTradingHouseItem", GetTradingHouseSearchResultItemLink)
TooltipHook(ItemTooltip, "SetTradingHouseListing", GetTradingHouseListingItemLink)
TooltipHook(ItemTooltip, "SetLink", ReturnItemLink)
TooltipHook(PopupTooltip, "SetLink", ReturnItemLink)
end
-- hook late
local function DeferHookToolTips()
EVENT_MANAGER:UnregisterForEvent(identifier, EVENT_PLAYER_ACTIVATED)
EVENT_MANAGER:RegisterForUpdate(identifier, 100, HookToolTips)
end
function FurC.CreateTooltips()
EVENT_MANAGER:RegisterForEvent(identifier, EVENT_PLAYER_ACTIVATED, DeferHookToolTips)
end
end