-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInit.lua
More file actions
302 lines (266 loc) · 10.7 KB
/
Copy pathInit.lua
File metadata and controls
302 lines (266 loc) · 10.7 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
---@class BFC
local BFC = select(2, ...)
BFC.name = "BFCraftsman"
BFC.channelName = "BFChannel"
BFC.channelID = 0
BFC.minVersion = 7
_G.BFCraftsman = BFC
local L = BFC.L
---@type AbstractFramework
local AF = _G.AbstractFramework
AF.RegisterAddon(BFC.name, L["BFCraftsman"])
---------------------------------------------------------------------
-- functions
---------------------------------------------------------------------
function BFC.IsStale(lastUpdate)
return time() - lastUpdate > 310 -- 5 minutes
end
local ChatEdit_ActivateChat = ChatEdit_ActivateChat
local ChatEdit_DeactivateChat = ChatEdit_DeactivateChat
local ChatEdit_ChooseBoxForSend = ChatEdit_ChooseBoxForSend
function BFC.SendWhisper(name)
local editBox = ChatEdit_ChooseBoxForSend()
ChatEdit_DeactivateChat(editBox)
ChatEdit_ActivateChat(editBox)
editBox:SetText("/w " .. name .. " ")
end
---------------------------------------------------------------------
-- events
---------------------------------------------------------------------
AF.AddEventHandler(BFC)
BFC:RegisterEvent("ADDON_LOADED", function(_, _, addon)
if addon == BFC.name then
BFC.version = AF.GetAddOnMetadata("Version")
BFC.versionNum = tonumber(BFC.version:match("%d+"))
if type(BFC_DB) ~= "table" then
BFC_DB = {
scale = 1,
publish = {
mode = "disabled",
tagline = "",
craftingFee = nil,
characters = {
-- {
-- name = (string),
-- class = (string),
-- prof1 = {
-- enabled = (boolean),
-- id = (number),
-- lastScanned = (number),
-- recipes = {},
-- allRecipesLearned = false,
-- },
-- prof2 = {...},
-- },
},
},
list = {
-- [id] = {
-- name = (string),
-- class = (string),
-- tagline = (string),
-- craftingFee = (number),
-- recipes = {
-- [recipeID] = {
-- {name, class},
-- },
-- },
-- professions = {
-- [skillLineID] = {
-- {name, class},
-- },
-- },
-- lastUpdate = (number),
-- }
},
favorite = {},
blacklist = {},
showStale = false,
showBlacklisted = false,
-- whisperTemplate = L["WHISPER_TEMPLATE"],
minimap = {},
}
end
BFCMainFrame:SetScale(BFC_DB.scale)
if type(BFC_DB.whisperTemplate) ~= "string" then
BFC_DB.whisperTemplate = L["WHISPER_TEMPLATE"]
end
---------------------------------------------------------------------
-- revise
if type(BFC_DB.publish.enabled) == "boolean" then
BFC_DB.publish.mode = BFC_DB.publish.enabled and "always" or "disabled"
BFC_DB.publish.enabled = nil
end
if type(BFC_DB.publish.currentServerOnly) ~= "boolean" then
BFC_DB.publish.currentServerOnly = true
end
---------------------------------------------------------------------
---------------------------------------------------------------------
-- validate list
for id, t in pairs(BFC_DB.list) do
if type(id) ~= "string" or #id ~= 32 or type(t.professions) ~= "table" or type(t.recipes) ~= "table" then
BFC_DB.list[id] = nil
else
-- t.inInstance = nil -- reset in instance status
t._lastServicesUpdate = nil
end
end
-- validate publish
for _, t in pairs(BFC_DB.publish.characters) do
if type(t.prof1.enabled) ~= "boolean" then t.prof1.enabled = true end
if type(t.prof2.enabled) ~= "boolean" then t.prof2.enabled = true end
end
---------------------------------------------------------------------
-- minimap button
AF.NewMinimapButton(BFC.name, "Interface\\AddOns\\BFCraftsman\\BFC", BFC_DB.minimap, BFC.ToggleMainFrame, L["BFCraftsman"])
elseif addon == "Blizzard_ProfessionsCustomerOrders" then
-- title container button
local button1 = AF.CreateButton(ProfessionsCustomerOrdersFrame.TitleContainer, nil, "accent_hover", 20, 20)
AF.SetPoint(button1, "RIGHT", ProfessionsCustomerOrdersFrameCloseButton, "LEFT", -1, 0)
AF.SetTooltip(button1, "TOP", 0, 5, L["BFCraftsman"])
button1:SetTexture("Interface\\AddOns\\BFCraftsman\\BFC")
button1:SetOnClick(BFC.ToggleMainFrame)
if not BFC_DB.orderFrameHelpViewed then
AF.ShowHelpTip({
widget = button1,
position = "TOP",
text = L["Click this button to open BFCraftsman"],
glow = true,
callback = function()
BFC_DB.orderFrameHelpViewed = true
end,
})
end
-- order form button
local button2 = AF.CreateButton(ProfessionsCustomerOrdersFrame.Form, L["Find Craftsmen"], "accent", 120, 20)
AF.SetPoint(button2, "BOTTOMRIGHT", ProfessionsCustomerOrdersFrame.Form, "TOPRIGHT", -2, 7)
button2:SetOnClick(BFC.ShowListFrame)
button2:SetOnHide(BFC.HideListFrame)
if not BFC_DB.formFrameHelpViewed then
AF.ShowHelpTip({
widget = button2,
position = "RIGHT",
text = L["Click this button to show craftsmen list"],
glow = true,
callback = function()
BFC_DB.formFrameHelpViewed = true
end,
})
end
-- hooksecurefunc(Professions, "CreateNewOrderInfo", function(...)
-- print(...)
-- end)
-- hooksecurefunc(ProfessionsCustomerOrdersFrame.Form, "Init", function(_, order)
-- -- texplore(order)
-- local recipeID = order.spellID
-- -- texplore(C_TradeSkillUI.GetRecipeInfo(recipeID))
-- texplore(C_TradeSkillUI.GetProfessionInfoByRecipeID(recipeID))
-- end)
-- prepare order info
hooksecurefunc(ProfessionsCustomerOrdersFrame.Form, "InitSchematic", BFC.HandleOrderData)
elseif addon == "Blizzard_Professions" then
-- title container button
local button = AF.CreateButton(ProfessionsFrame.TitleContainer, nil, "accent_hover", 20, 20)
AF.SetTooltip(button, "TOP", 0, 5, L["BFCraftsman"])
button:SetTexture("Interface\\AddOns\\BFCraftsman\\BFC")
button:SetOnClick(BFC.ToggleMainFrame)
if C_AddOns.IsAddOnLoaded("TradeSkillMaster") then
AF.SetPoint(button, "RIGHT", ProfessionsFrame.MaximizeMinimize, "LEFT", -65, 0)
else
AF.SetPoint(button, "RIGHT", ProfessionsFrame.MaximizeMinimize, "LEFT", -1, 0)
end
if not BFC_DB.professionsFrameHelpViewed then
AF.ShowHelpTip({
widget = button,
position = "TOP",
text = L["Click this button to open BFCraftsman"],
glow = true,
callback = function()
BFC_DB.professionsFrameHelpViewed = true
end,
})
end
-- setup schematic simulation
BFC.SetupSchematicSimulation()
end
end)
local BNGetInfo = BNGetInfo
BFC:RegisterEvent("PLAYER_LOGIN", function()
-- prepare
local bTag = select(2, BNGetInfo())
if bTag then
BFC.battleTag = AF.Libs.MD5.sumhexa(bTag)
end
BFC.UpdateLearnedProfessions()
BFC.UpdateLearnedRecipes()
BFC.UpdateSendingData()
BFC.ScheduleNextSync(true)
-- check BigFootCommonweal
if C_AddOns.IsAddOnLoaded("BigFootCommonweal") then
local text = L["BFCraftsman is not compatible with %s.\nDisable it?"]:format(AF.WrapTextInColor(LOCALE_zhCN and "大脚公益助手" or "BigFootCommonweal", "accent"))
AF.ShowGlobalDialog(text, function()
C_AddOns.DisableAddOn("BigFootCommonweal")
ReloadUI()
end)
end
end)
---------------------------------------------------------------------
-- channel
---------------------------------------------------------------------
AF.UnregisterChannel("BFCraftsman") -- leave old channel
AF.RegisterTemporaryChannel(BFC.channelName)
AF.BlockChatConfigFrameInteractionForChannel(BFC.channelName)
AF.RegisterCallback("AF_JOIN_TEMP_CHANNEL", function(_, channelName, channelID)
if channelName == BFC.channelName then
BFC.channelID = channelID
BFC.BroadcastVersion()
BFC.UpdateInstanceStatus()
end
end)
---------------------------------------------------------------------
-- slash
---------------------------------------------------------------------
SLASH_BFCRAFTSMAN1 = "/bfc"
SlashCmdList["BFCRAFTSMAN"] = function(msg)
if msg == "reset" then
BFC_DB = nil
ReloadUI()
elseif msg == "clear list" then
wipe(BFC_DB.list)
BFC.UpdateList()
elseif msg == "clear favorite" then
wipe(BFC_DB.favorite)
BFC.UpdateList()
elseif msg == "clear blacklist" then
wipe(BFC_DB.blacklist)
BFC.UpdateList()
--@debug@
elseif msg == "test" then
local validSkillLine = {164, 165, 171, 197, 202, 333, 773, 755}
for i = 1, 30 do
local class = AF.GetClassFile(random(1, 13))
BFC_DB.list["Player" .. i] = {
name = "Player" .. i,
class = class,
tagline = "This is a tagline " .. i,
craftingFee = random(1000, 10000),
lastUpdate = time() - random(1, 10000),
recipes = {},
professions = {},
}
for j = 1, random(1, 2) do
BFC_DB.list["Player" .. i]["professions"][validSkillLine[random(1, 8)]] = {{"Player" .. i, class}}
end
end
BFC.UpdateList()
--@end-debug@
else
BFC.ToggleMainFrame()
end
end
---------------------------------------------------------------------
-- addon button
---------------------------------------------------------------------
function BFC_OnAddonCompartmentClick()
BFC.ToggleMainFrame()
end