-
Notifications
You must be signed in to change notification settings - Fork 9
/
FurCEvents.lua
106 lines (92 loc) · 3.22 KB
/
FurCEvents.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
local em = EVENT_MANAGER
local function onRecipeLearned(eventCode, recipeListIndex, recipeIndex)
local itemlink = GetRecipeResultItemLink(recipeListIndex, recipeIndex, LINK_STYLE_BRACKETS)
local info = zo_strformat(GetString(SI_FURC_STRING_RECIPELEARNED), itemlink, recipeListIndex, recipeIndex)
FurC.Logger:Debug(info)
FurC.TryCreateRecipeEntry(recipeListIndex, recipeIndex)
FurC.UpdateGui()
end
local wm = WINDOW_MANAGER
local function createIcon(control)
local icon
icon = wm:CreateControlFromVirtual(control:GetName() .. "FurCIcon", control, "FurC_SlotIconKnownYes")
if FurC.settings["showIconOnLeft"] == nil or FurC.settings["showIconOnLeft"] == true then
icon:SetAnchor(BOTTOMLEFT, control:GetNamedChild("Button"), BOTTOMLEFT, -15, -10)
else
icon:SetAnchor(TOPLEFT, control:GetNamedChild("TraitInfo"), TOPLEFT, 0, 0)
end
icon:SetHidden(true)
control.icon = icon
return icon
end
local function getItemKnowledge(itemLink)
local recipeArray = FurC.Find(itemLink)
if FurC.GetUseInventoryIconsOnChar() then
return FurC.CanCraft(itemId, recipeArray)
end
return FurC.IsAccountKnown(itemId, recipeArray)
end
local function updateItemInInventory(control)
if "listSlot" ~= control.slotControlType then
return
end
local icon = control.icon or createIcon(control)
local data = control.dataEntry.data
local bagId = data.bagId
local slotId = data.slotIndex
local itemLink = GetItemLink(bagId, slotId, LINK_STYLE_DEFAULT)
if not IsItemLinkFurnitureRecipe(itemLink) then
icon:SetHidden(true)
return
end
local known = getItemKnowledge(itemLink)
local hidden = known and FurC.GetHideKnownInventoryIcons() or (not FurC.GetUseInventoryIcons())
icon:SetHidden(hidden)
local templateName = "FurC_SlotIconKnown" .. ((known and "Yes") or "No")
WINDOW_MANAGER:ApplyTemplateToControl(icon, templateName)
icon.data = {
tooltipText = ((known and GetString(SI_FURC_FILTER_SRC_CRAFTING_KNOWN)) or GetString(
SI_FURC_FILTER_SRC_CRAFTING_UNKNOWN
)),
}
icon:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
icon:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
end
function FurC.SetupInventoryRecipeIcons(calledRecursively)
local function isValidBag(bagId, inventory)
if bagId == BAG_WORN then
return false
end
if bagId == BAG_VIRTUAL then
return false
end
local listView = inventory.listView
if not listView then
return false
end
if not listView.dataTypes then
return false
end
if not listView.dataTypes[1] then
return false
end
return nil ~= listView.dataTypes[1].setupCallback
end
local inventories = PLAYER_INVENTORY.inventories
if not inventories and not calledRecursively then
return zo_callLater(function()
FurC.SetupInventoryRecipeIcons(true)
end, 1000)
end
-- ruthlessly stolen from Dryzler's Inventory, then tweaked
for bagId, inventory in pairs(inventories) do
if isValidBag(bagId, inventory) then
ZO_PreHook(inventory.listView.dataTypes[1], "setupCallback", function(control, slot)
updateItemInInventory(control)
end)
end
end
end
function FurC.RegisterEvents()
em:RegisterForEvent("FurnitureCatalogue", EVENT_RECIPE_LEARNED, onRecipeLearned)
end