forked from manavortex/FurnitureCatalogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFurCContextMenu.lua
192 lines (155 loc) · 6.33 KB
/
FurCContextMenu.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
FurC_LinkHandlerBackup_OnLinkMouseUp = nil
local FURC_S_SHOPPINGLIST_1 = GetString(SI_FURC_ONE_TO_SHOPPINGLIST)
local FURC_S_SHOPPINGLIST_5 = GetString(SI_FURC_FIVE_TO_SHOPPINGLIST)
local FURC_S_TOGGLE_SL = GetString(SI_FURC_TOGGLE_SHOPPINGLIST)
function AddFurnitureShoppingListMenuEntry(itemId, calledFromFurC)
if calledFromFurC then
if (not FurC.GetEnableShoppingList()) then return end
if (nil == moc()) or (nil == FurnitureShoppingListAdd) then return end
local controlName = moc():GetName() or ""
if nil == moc():GetName():match("_ListItem_") then return end
end
local itemLink = FurC.GetItemLink(itemId)
if nil == FurC.Find(itemLink) then return end
AddCustomMenuItem(FURC_S_SHOPPINGLIST_1,
function()
FurnitureShoppingListAdd(itemLink)
end,
MENU_ADD_OPTION_LABEL)
AddCustomMenuItem(FURC_S_SHOPPINGLIST_5,
function()
FurnitureShoppingListAdd(itemLink)
FurnitureShoppingListAdd(itemLink)
FurnitureShoppingListAdd(itemLink)
FurnitureShoppingListAdd(itemLink)
FurnitureShoppingListAdd(itemLink)
end,
MENU_ADD_OPTION_LABEL)
AddCustomMenuItem(FURC_S_TOGGLE_SL,
function()
FurnitureShoppingListWindow_Toggle()
end,
MENU_ADD_OPTION_LABEL)
end
local cachedItemLink, cachedRecipeArray
local function toChat() FurC.ToChat(cachedItemLink) end
local function fave() FurC.Fave(cachedItemLink) end
local function postItemSource() FurC.ToChat(FurC.GetItemDescription(cachedItemLink, cachedRecipeArray, true, true)) end
local function postRecipe() FurC.ToChat(FurC.GetItemLink(cachedRecipeArray.blueprint)) end
local function postRecipeResult() FurC.ToChat(GetItemLinkRecipeResultItemLink(cachedItemLink)) end
local function postMaterial() FurC.ToChat(FurC.GetMats(cachedItemLink, cachedRecipeArray, true, true))
end
local function doNothing() return end
local S_DIVIDER = "-"
local function addMenuItems(itemLink, recipeArray, hideSepBar)
hideSepBar = hideSepBar or false
recipeArray = recipeArray or FurC.Find(itemLink)
if not recipeArray or recipeArray == {} then return end
cachedItemLink = itemLink
cachedRecipeArray = recipeArray
if not FurC.GetSkipDivider() and (not hideSepBar) then
AddCustomMenuItem(S_DIVIDER, doNothing, MENU_ADD_OPTION_LABEL)
end
AddCustomMenuItem(GetString(SI_FURC_MENU_HEADER), toChat, MENU_ADD_OPTION_LABEL)
local faveText = FurC.IsFavorite(itemLink, recipeArray) and GetString(SI_FURC_REMOVE_FAVE) or GetString(SI_FURC_ADD_FAVE)
AddCustomMenuItem(faveText, fave, MENU_ADD_OPTION_LABEL)
local isRecipe = IsItemLinkFurnitureRecipe(itemLink)
-- if we hold a recipe: allow posting recipe
if not isRecipe and recipeArray.blueprint then
AddCustomMenuItem(GetString(SI_FURC_POST_RECIPE), postRecipe, MENU_ADD_OPTION_LABEL)
-- if it's a recipe: Allow posting item
elseif isRecipe then
AddCustomMenuItem(GetString(SI_FURC_POST_ITEM), postRecipeResult, MENU_ADD_OPTION_LABEL)
end
if recipeArray.origin ~= FURC_CRAFTING then
AddCustomMenuItem(GetString(SI_FURC_POST_ITEMSOURCE), postItemSource, MENU_ADD_OPTION_LABEL)
else
-- post material list
AddCustomMenuItem(GetString(SI_FURC_POST_MATERIAL), postMaterial, MENU_ADD_OPTION_LABEL)
-- will do nothing if preferences not met
AddFurnitureShoppingListMenuEntry(itemLink, true)
end
end
--[[ Original version
function FurC_HandleClickEvent(itemLink, button, control) -- button being mouseButton here
if (type(itemLink) == 'string' and #itemLink > 0) then
local handled = LINK_HANDLER:FireCallbacks(LINK_HANDLER.LINK_MOUSE_UP_EVENT, itemLink, button, ZO_LinkHandler_ParseLink(itemLink))
if (not handled) then
FurC_LinkHandlerBackup_OnLinkMouseUp(itemLink, button, control)
if (button == 2 and itemLink ~= '') then
addMenuItems(itemLink, FurC.Find(itemLink))
end
ShowMenu(control)
end
end
end
--]]
function FurC_HandleClickEvent(itemLink, button, _, _, linkType, ...) -- button being mouseButton here
if button == MOUSE_BUTTON_INDEX_RIGHT and
linkType == ITEM_LINK_TYPE and
type(itemLink) == 'string' and
#itemLink > 0 and
itemLink ~= '' then
zo_callLater(function()
addMenuItems(itemLink, FurC.Find(itemLink))
ShowMenu()
end)
end
end
function FurC_HandleMouseEnter(inventorySlot)
local inventorySlot = moc()
if nil == inventorySlot or nil == inventorySlot.dataEntry then return end
local data = inventorySlot.dataEntry.data
if nil == data then return end
local bagId, slotIndex = data.bagId, data.slotIndex
FurC.CurrentLink = GetItemLink(bagId, slotIndex)
if nil == FurC.CurrentLink then return end
end
-- thanks Randactyl for helping me with the handler :)
function FurC_HandleInventoryContextMenu(control)
local st = ZO_InventorySlot_GetType(control)
local itemLink = nil
if st == SLOT_TYPE_ITEM or
st == SLOT_TYPE_BANK_ITEM or
st == SLOT_TYPE_GUILD_BANK_ITEM or
st == SLOT_TYPE_TRADING_HOUSE_POST_ITEM then
local bagId, slotId = ZO_Inventory_GetBagAndIndex(control)
itemLink = GetItemLink(bagId, slotId, linkStyle)
elseif st == SLOT_TYPE_STORE_BUY then
itemLink = GetStoreItemLink(control.index)
elseif st == SLOT_TYPE_TRADING_HOUSE_ITEM_RESULT then
itemLink = GetTradingHouseSearchResultItemLink(ZO_Inventory_GetSlotIndex(control), linkStyle)
elseif st == SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING then
itemLink = GetTradingHouseListingItemLink(ZO_Inventory_GetSlotIndex(control), linkStyle)
end
local recipeArray = FurC.Find(itemLink)
-- d(recipeArray)
if nil == recipeArray then return end
zo_callLater(function()
addMenuItems(itemLink, recipeArray)
ShowMenu()
end, 50)
end
function FurC.OnControlMouseUp(control, button)
if nil == control then return end
if button ~= 2 then return end
local itemLink = control.itemLink
if nil == itemLink then return end
local recipeArray = FurC.Find(itemLink)
if nil == recipeArray then return end
zo_callLater(function()
ItemTooltip:SetHidden(true)
ClearMenu()
addMenuItems(itemLink, recipeArray, true)
ShowMenu()
end, 50)
end
function FurC.InitRightclickMenu()
-- FurC_LinkHandlerBackup_OnLinkMouseUp = ZO_LinkHandler_OnLinkMouseUp
-- ZO_LinkHandler_OnLinkMouseUp = function(itemLink, button, control) FurC_HandleClickEvent(itemLink, button, control) end
LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_MOUSE_UP_EVENT, FurC_HandleClickEvent)
ZO_PreHook('ZO_InventorySlot_OnMouseEnter', FurC_HandleMouseEnter)
ZO_PreHook('ZO_InventorySlot_ShowContextMenu', function(rowControl)
FurC_HandleInventoryContextMenu(rowControl)
end)
end