-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
154 lines (126 loc) · 5.01 KB
/
main.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
153
154
ItemSaver = {}
local IS = ItemSaver
IS.addonVersion = "3.4.0.0"
local util, settings
local LISTS = {
BACKPACK = ZO_PlayerInventoryList,
QUICKSLOT = ZO_QuickSlotList,
BANK = ZO_PlayerBankBackpack,
GUILD_BANK = ZO_GuildBankBackpack,
CRAFTBAG = ZO_CraftBagList,
DECONSTRUCTION = ZO_SmithingTopLevelDeconstructionPanelInventoryBackpack,
IMPROVEMENT = ZO_SmithingTopLevelImprovementPanelInventoryBackpack,
ENCHANTING = ZO_EnchantingTopLevelInventoryBackpack,
ALCHEMY = ZO_AlchemyTopLevelInventoryBackpack,
LIST_DIALOG = ZO_ListDialog1List,
}
local function addContextMenuOptionSoon(rowControl)
if rowControl:GetOwningWindow() == ZO_TradingHouse then return end
local function shouldAddContextMenu()
for _, list in pairs(LISTS) do
if not list:IsHidden() then
return true
end
end
end
if not shouldAddContextMenu() then return end
local function addContextMenuOption(rowControl)
local bagId, slotIndex = util.GetInfoFromRowControl(rowControl)
local setNames = ItemSaver_GetSaveSets()
local createSetEntry = {
label = GetString(SI_ITEMSAVER_CREATE_SAVE_SET),
callback = function()
ZO_Dialogs_ShowDialog("ITEMSAVER_SAVE", {bagId, slotIndex})
ClearMenu()
end,
}
local function setupSubmenu(bagId, slotIndex)
local entries = {
[1] = createSetEntry,
}
for _, setName in pairs(setNames) do
local entry = {
label = GetString(SI_ITEMSAVER_SAVE_TO) .. " \"" .. setName .. "\"",
callback = function()
ItemSaver_ToggleItemSave(setName, bagId, slotIndex)
ClearMenu()
end,
}
table.insert(entries, entry)
end
AddCustomSubMenuItem(GetString(SI_ITEMSAVER_ADDON_NAME), entries)
end
local isSaved, setName = ItemSaver_IsItemSaved(bagId, slotIndex)
if not isSaved then
local deferSubmenu, deferSubmenuNum = ItemSaver_IsSubmenuDeferred()
if deferSubmenu then
if #setNames > deferSubmenuNum then
setupSubmenu(bagId, slotIndex)
else
AddCustomMenuItem(createSetEntry.label, createSetEntry.callback, MENU_ADD_OPTION_LABEL)
for _, setName in pairs(setNames) do
AddCustomMenuItem(GetString(SI_ITEMSAVER_SAVE_TO) .. " \"" .. setName .. "\"", function()
ItemSaver_ToggleItemSave(setName, bagId, slotIndex)
end, MENU_ADD_OPTION_LABEL)
end
end
else
setupSubmenu(bagId, slotIndex)
end
else
AddCustomMenuItem(GetString(SI_ITEMSAVER_UNSAVE_ITEM), function()
ItemSaver_ToggleItemSave(setName, bagId, slotIndex)
end, MENU_ADD_OPTION_LABEL)
end
ShowMenu()
end
local parent = rowControl:GetParent()
if parent ~= ZO_Character then
zo_callLater(function() addContextMenuOption(parent) end, 50)
elseif rowControl.stackCount > 0 then
zo_callLater(function() addContextMenuOption(rowControl) end, 50)
end
end
local function initializeHooks()
--add marker initialization to slot setup callbacks
local hookedSetupFunctions = {}
local function newSetupCallback(rowControl, slot)
local listViewName = rowControl:GetParent():GetParent():GetName()
if hookedSetupFunctions[listViewName] then
hookedSetupFunctions[listViewName](rowControl, slot)
end
util.CreateMarkerControl(rowControl)
end
--list hooks
for _, list in pairs(LISTS) do
hookedSetupFunctions[list:GetName()] = list.dataTypes[1].setupCallback
list.dataTypes[1].setupCallback = newSetupCallback
end
--setup context menu entry
ZO_PreHook("ZO_InventorySlot_ShowContextMenu", addContextMenuOptionSoon)
end
local function ItemSaver_Loaded(eventCode, addonName)
if addonName ~= "ItemSaver" then return end
--set local references
util = IS.util
settings = IS.settings
--initialize LibFilters
util.LibFilters:InitializeLibFilters()
--initialize settings
settings.InitializeSettings()
--setup hooks
initializeHooks()
--create equipment markers
util.RefreshEquipmentControls()
--finish create set dialog initialization
IS.dialog.InitializeDialog()
end
EVENT_MANAGER:RegisterForEvent("ItemSaverLoaded", EVENT_ADD_ON_LOADED,
ItemSaver_Loaded)
local function handleEquipmentChange(eventCode, bagId, slotIndex, isNewItem,
itemSoundCategory, inventoryUpdateReason)
if bagId ~= BAG_WORN or isNewItem or inventoryUpdateReason ~= 0 then return end
util.RefreshEquipmentControls()
end
EVENT_MANAGER:RegisterForEvent("ItemSaverEquipChange", EVENT_INVENTORY_SINGLE_SLOT_UPDATE,
handleEquipmentChange)