-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrations.lua
More file actions
246 lines (216 loc) · 7.96 KB
/
Copy pathIntegrations.lua
File metadata and controls
246 lines (216 loc) · 7.96 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
local _, NS = ...
local RM = NS.RM
local L = NS.L
local merchantButtonsHooked = false
local function GetMerchantItemLinkCompat(index)
if C_MerchantFrame and C_MerchantFrame.GetItemLink then
return C_MerchantFrame.GetItemLink(index)
end
if GetMerchantItemLink then
return GetMerchantItemLink(index)
end
end
local function GetTooltipItemID(tooltip, data)
if data and data.id then
return tonumber(data.id)
end
if tooltip and tooltip.GetItem then
local _, link = tooltip:GetItem()
return RM.ParseItemID(link)
end
end
local function AddRestockTooltipLine(tooltip, data)
if not RM.DB or tooltip.__restockMateSkipPost then
return
end
local itemID = GetTooltipItemID(tooltip, data)
local item = itemID and RM:GetItems()[itemID]
if not item then
return
end
local current = RM:GetCountForItem(item)
local missing = math.max(0, (item.target or 0) - current)
tooltip:AddLine(" ")
tooltip:AddLine(
string.format(L.TOOLTIP_TRACKED, current, item.target or 0, missing),
RM.colors.accent[1],
RM.colors.accent[2],
RM.colors.accent[3],
true
)
tooltip:AddLine(
item.countMode == "total" and L.COUNT_TOTAL or L.COUNT_BAGS,
0.7,
0.72,
0.76,
true
)
end
function RM:InitializeTooltipIntegration()
if TooltipDataProcessor
and TooltipDataProcessor.AddTooltipPostCall
and Enum
and Enum.TooltipDataType
and Enum.TooltipDataType.Item
then
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, AddRestockTooltipLine)
return
end
if GameTooltip and GameTooltip.HookScript then
GameTooltip:HookScript("OnTooltipSetItem", function(tooltip)
AddRestockTooltipLine(tooltip)
end)
end
end
function RM:InitializeModifiedClickIntegration()
if not hooksecurefunc or type(_G.HandleModifiedItemClick) ~= "function" then
return
end
hooksecurefunc(_G, "HandleModifiedItemClick", function(link)
if not RM.DB or not IsAltKeyDown or not IsAltKeyDown() then
return
end
local itemID = RM.ParseItemID(link)
if itemID then
RM:AddItem(itemID, link)
if RM.ui.frame then
RM.ui.frame:Show()
end
end
end)
end
function RM:UpdateMerchantQuickAddButtons()
if not MerchantFrame or not MerchantFrame:IsShown() then
for _, button in ipairs(self.ui.merchantAddButtons or {}) do
button:Hide()
end
return
end
self.ui.merchantAddButtons = self.ui.merchantAddButtons or {}
local perPage = MERCHANT_ITEMS_PER_PAGE or 10
local page = MerchantFrame.page or 1
for displayIndex = 1, perPage do
local merchantRow = _G["MerchantItem" .. displayIndex]
local button = self.ui.merchantAddButtons[displayIndex]
if merchantRow and not button then
button = CreateFrame("Button", nil, merchantRow, "BackdropTemplate")
button:SetSize(20, 20)
button:SetPoint("TOPRIGHT", merchantRow, "TOPRIGHT", -3, -3)
button:SetFrameLevel(merchantRow:GetFrameLevel() + 12)
RM.StyleButton(button)
button:SetText("+")
button.trackedMark = button:CreateTexture(nil, "OVERLAY")
button.trackedMark:SetSize(18, 18)
button.trackedMark:SetPoint("CENTER")
button.trackedMark:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
button.trackedMark:Hide()
button:SetScript("OnClick", function(self)
local index = self.merchantIndex
local itemID = index and RM:GetMerchantItemID(index)
if itemID then
RM:AddItem(itemID, GetMerchantItemLinkCompat(index))
RM.ui.frame:Show()
RM:UpdateMerchantQuickAddButtons()
end
end)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(self.tracked and L.TRACKED or L.QUICK_ADD)
GameTooltip:AddLine(L.ALT_CLICK_ADD, 0.75, 0.77, 0.8, true)
GameTooltip:Show()
end)
button:SetScript("OnLeave", GameTooltip_Hide)
self.ui.merchantAddButtons[displayIndex] = button
end
if button then
local merchantIndex = ((page - 1) * perPage) + displayIndex
local itemID = merchantIndex <= self:GetMerchantItemCount() and self:GetMerchantItemID(merchantIndex)
if itemID then
button.merchantIndex = merchantIndex
button.tracked = self:GetItems()[itemID] ~= nil
button:SetText(button.tracked and "" or "+")
button.trackedMark:SetShown(button.tracked)
self:SetButtonEnabled(button, not button.tracked)
button:Show()
else
button:Hide()
end
end
end
end
function RM:TryHookMerchantUpdate()
if merchantButtonsHooked or not hooksecurefunc or type(_G.MerchantFrame_UpdateMerchantInfo) ~= "function" then
return
end
merchantButtonsHooked = true
hooksecurefunc(_G, "MerchantFrame_UpdateMerchantInfo", function()
C_Timer.After(0, function()
RM:UpdateMerchantQuickAddButtons()
end)
end)
end
function RM:InitializeMerchantIntegration()
self:TryHookMerchantUpdate()
local loader = CreateFrame("Frame")
loader:RegisterEvent("ADDON_LOADED")
loader:SetScript("OnEvent", function(_, _, addonName)
if addonName == "Blizzard_MerchantUI" or addonName == "Blizzard_UIPanels_Game" then
RM:TryHookMerchantUpdate()
end
end)
self.integrationLoader = loader
end
function RM:InitializeSettingsIntegration()
if not Settings or not Settings.RegisterCanvasLayoutCategory or not Settings.RegisterAddOnCategory then
return
end
local panel = CreateFrame("Frame")
panel.name = "RestockMate"
panel.title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
panel.title:SetPoint("TOPLEFT", 16, -16)
panel.title:SetText("RestockMate")
panel.description = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
panel.description:SetPoint("TOPLEFT", panel.title, "BOTTOMLEFT", 0, -12)
panel.description:SetPoint("RIGHT", panel, "RIGHT", -16, 0)
panel.description:SetJustifyH("LEFT")
panel.description:SetText(L.SETTINGS_DESCRIPTION)
panel.open = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
panel.open:SetSize(180, 28)
panel.open:SetPoint("TOPLEFT", panel.description, "BOTTOMLEFT", 0, -18)
panel.open:SetText(L.OPEN_RESTOCKMATE)
panel.open:SetScript("OnClick", function()
RM.ui.frame:Show()
RM:ShowOptions(true)
if SettingsPanel then
SettingsPanel:Hide()
end
end)
local category = Settings.RegisterCanvasLayoutCategory(panel, panel.name)
Settings.RegisterAddOnCategory(category)
self.settingsCategory = category
end
function RM:InitializeIntegrations()
self:InitializeTooltipIntegration()
self:InitializeModifiedClickIntegration()
self:InitializeMerchantIntegration()
self:InitializeSettingsIntegration()
end
_G.RestockMate_OnAddonCompartmentClick = function(_, buttonName)
if buttonName == "RightButton" then
RM.ui.frame:Show()
RM:ShowOptions(true)
else
RM:Toggle()
end
end
_G.RestockMate_OnAddonCompartmentEnter = function(_, button)
local owner = button and button.GetObjectType and button or _G.AddonCompartmentFrame or UIParent
GameTooltip:SetOwner(owner, "ANCHOR_LEFT")
GameTooltip:AddLine("RestockMate")
GameTooltip:AddLine(L.MINIMAP_TOOLTIP_OPEN, 0.8, 0.8, 0.8)
GameTooltip:AddLine(L.ALT_CLICK_ADD, 0.8, 0.8, 0.8)
GameTooltip:Show()
end
_G.RestockMate_OnAddonCompartmentLeave = function()
GameTooltip:Hide()
end