This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
forked from HgAlexx/Buffet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.lua
363 lines (314 loc) · 13.4 KB
/
Config.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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
local addonName, ns = ...
local Core = ns.Core
local Utility = ns.Utility
local Const = ns.Const
local MAX_ACCOUNT_MACROS, MAX_CHARACTER_MACROS = 120, 18
local EDGEGAP, GAP = 16, 8
local tekbutt = LibStub("tekKonfig-Button")
local BACKDROP_TOOLTIP_12_12_4444 = BACKDROP_TOOLTIP_12_12_4444 or {
bgFile = "Interface\\ChatFrame\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileEdge = true,
tileSize = 12,
edgeSize = 12,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
}
if AddonLoader and AddonLoader.RemoveInterfaceOptions then AddonLoader:RemoveInterfaceOptions("Buffet") end
local modEdit = function(parent, anchor, label, text, tips, onAction)
local modlabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
modlabel:SetText(label)
modlabel:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -5)
local modeditbox = CreateFrame("EditBox", nil, parent, BackdropTemplateMixin and "BackdropTemplate")
modeditbox:SetPoint("TOPLEFT", modlabel, "BOTTOMLEFT", 0, -5)
modeditbox:SetFontObject(GameFontHighlight)
modeditbox:SetTextInsets(8,8,8,8)
modeditbox:SetBackdrop(BACKDROP_TOOLTIP_12_12_4444)
modeditbox:SetBackdropColor(.1,.1,.1,.3)
modeditbox:SetMultiLine(false)
modeditbox:SetAutoFocus(false)
modeditbox:SetText(text)
modeditbox:SetScript("OnEditFocusLost", onAction)
modeditbox:SetScript("OnEscapePressed", modeditbox.ClearFocus)
modeditbox.tiptext = tips
modeditbox:SetSize(200,30)
return modeditbox
end
local frame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
frame.name = "Buffet"
frame:Hide()
frame:SetScript("OnShow", function()
local title, subtitle = LibStub("tekKonfig-Heading").new(frame, "Buffet", "This panel allows you to quickly create the base macros for Buffet to edit.\nYou can also set the macro text to be used.")
local function OnClick(self)
local id = GetMacroIndexByName(self.name)
local acc, cha = GetNumMacros()
if id and id ~= 0 then
PickupMacro(id)
elseif acc >= MAX_ACCOUNT_MACROS then
Utility.Print("Unable to create the macro, you seam to have reach the maximum number of allowed macro per account.")
else
local id = CreateMacro(self.name, "INV_Misc_QuestionMark", "")
Core:Scan()
PickupMacro(id)
end
end
local hpbutt = tekbutt.new(frame, "TOPLEFT", subtitle, "BOTTOMLEFT", -2, -GAP)
hpbutt:SetText("HP Macro")
hpbutt.tiptext = "Generate a global macro for food, bandages, health potions and health stones."
hpbutt.name = Const.MacroNames.defaultHP
hpbutt:SetScript("OnClick", OnClick)
if InCombatLockdown() then hpbutt:Disable() end
local mpbutt = tekbutt.new(frame, "TOPLEFT", hpbutt, "TOPRIGHT", 5, 0)
mpbutt:SetText("MP Macro")
mpbutt.tiptext = "Generate a global macro for water, runes, mana potions and mana stones."
mpbutt.name = Const.MacroNames.defaultMP
mpbutt:SetScript("OnClick", OnClick)
if InCombatLockdown() then mpbutt:Disable() end
local hpfoodbutt = tekbutt.new(frame, "TOPLEFT", mpbutt, "TOPRIGHT", 5, 0)
hpfoodbutt:SetText("Food Only")
hpfoodbutt.tiptext = "Generate a global macro for food only."
hpfoodbutt.name = Const.MacroNames.foodOnlyHP
hpfoodbutt:SetScript("OnClick", OnClick)
if InCombatLockdown() then hpfoodbutt:Disable() end
local mpfoodbutt = tekbutt.new(frame, "TOPLEFT", hpfoodbutt, "TOPRIGHT", 5, 0)
mpfoodbutt:SetText("Drink Only")
mpfoodbutt.tiptext = "Generate a global macro for water only."
mpfoodbutt.name = Const.MacroNames.drinkOnlyMP
mpfoodbutt:SetScript("OnClick", OnClick)
if InCombatLockdown() then mpfoodbutt:Disable() end
local hppotbutt = tekbutt.new(frame, "TOPLEFT", mpfoodbutt, "TOPRIGHT", 5, 0)
hppotbutt:SetText("Consumables")
hppotbutt.tiptext = "Generate a global macro for health consumable only, bandages, health potions and health stones."
hppotbutt.name = Const.MacroNames.consumableHP
hppotbutt:SetScript("OnClick", OnClick)
if InCombatLockdown() then hppotbutt:Disable() end
local mppotbutt = tekbutt.new(frame, "TOPLEFT", hppotbutt, "TOPRIGHT", 5, 0)
mppotbutt:SetText("Consumables")
mppotbutt.tiptext = "Generate a global macro for mana consumable only, runes, mana potions and mana stones."
mppotbutt.name = Const.MacroNames.consumableMP
mppotbutt:SetScript("OnClick", OnClick)
if InCombatLockdown() then mppotbutt:Disable() end
local hpmacrolabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
hpmacrolabel:SetText("HP Macro")
hpmacrolabel:SetPoint("TOPLEFT", hpbutt, "BOTTOMLEFT", 5, -GAP)
local YOFFSET = (hpmacrolabel:GetTop() - frame:GetBottom() - EDGEGAP/3)/2
local hpeditbox = CreateFrame("EditBox", nil, frame, BackdropTemplateMixin and "BackdropTemplate")
hpeditbox:SetPoint("TOP", hpmacrolabel, "BOTTOM", 0, -5)
hpeditbox:SetPoint("LEFT", EDGEGAP/3, 0)
hpeditbox:SetPoint("BOTTOMRIGHT", -EDGEGAP/3, YOFFSET + EDGEGAP/3)
hpeditbox:SetFontObject(GameFontHighlight)
hpeditbox:SetTextInsets(8,8,8,8)
hpeditbox:SetBackdrop(BACKDROP_TOOLTIP_12_12_4444)
hpeditbox:SetBackdropColor(.1,.1,.1,.3)
hpeditbox:SetMultiLine(true)
hpeditbox:SetAutoFocus(false)
hpeditbox:SetText(Core.db.macroHP)
hpeditbox:SetScript("OnEditFocusLost", function()
local newmacro = hpeditbox:GetText()
if not newmacro:find("%%MACRO%%") then
Utility.Print('Macro text must contain the string "%MACRO%".')
else
Core.db.macroHP = newmacro
Core:QueueScan()
end
end)
hpeditbox:SetScript("OnEscapePressed", hpeditbox.ClearFocus)
hpeditbox.tiptext = 'Customize the macro text. Must include the string "%MACRO%", which is replaced with the items to be used. This setting is saved on a per-char basis.'
hpeditbox:SetScript("OnEnter", mpbutt:GetScript("OnEnter"))
hpeditbox:SetScript("OnLeave", mpbutt:GetScript("OnLeave"))
local mpmacrolabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
mpmacrolabel:SetText("MP Macro")
mpmacrolabel:SetPoint("TOP", hpeditbox, "BOTTOM", 0, -GAP)
mpmacrolabel:SetPoint("LEFT", hpmacrolabel, "LEFT")
local mpeditbox = CreateFrame("EditBox", nil, frame, BackdropTemplateMixin and "BackdropTemplate")
mpeditbox:SetPoint("TOP", mpmacrolabel, "BOTTOM", 0, -5)
mpeditbox:SetPoint("LEFT", EDGEGAP/3, 0)
mpeditbox:SetPoint("BOTTOMRIGHT", -EDGEGAP/3, EDGEGAP/3)
mpeditbox:SetFontObject(GameFontHighlight)
mpeditbox:SetTextInsets(8,8,8,8)
mpeditbox:SetBackdrop(BACKDROP_TOOLTIP_12_12_4444)
mpeditbox:SetBackdropColor(.1,.1,.1,.3)
mpeditbox:SetMultiLine(true)
mpeditbox:SetAutoFocus(false)
mpeditbox:SetText(Core.db.macroMP)
mpeditbox:SetScript("OnEditFocusLost", function()
local newmacro = mpeditbox:GetText()
if not newmacro:find("%%MACRO%%") then
Utility.Print('Macro text must contain the string "%MACRO%".')
else
Core.db.macroMP = newmacro
Core:QueueScan()
end
end)
mpeditbox:SetScript("OnEscapePressed", mpeditbox.ClearFocus)
mpeditbox.tiptext = hpeditbox.tiptext
mpeditbox:SetScript("OnEnter", mpbutt:GetScript("OnEnter"))
mpeditbox:SetScript("OnLeave", mpbutt:GetScript("OnLeave"))
frame:SetScript("OnEvent", function(self, event)
if event == "PLAYER_REGEN_DISABLED" then
hpbutt:Disable()
mpbutt:Disable()
hpfoodbutt:Disable()
mpfoodbutt:Disable()
hppotbutt:Disable()
mppotbutt:Disable()
else
hpbutt:Enable()
mpbutt:Enable()
hpfoodbutt:Enable()
mpfoodbutt:Enable()
hppotbutt:Enable()
mppotbutt:Enable()
end
end)
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:SetScript("OnShow", nil)
end)
InterfaceOptions_AddCategory(frame)
local frame_config = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
frame_config.name = "Configuration"
frame_config.parent = "Buffet"
frame_config:Hide()
frame_config:SetScript("OnShow", function()
local title, subtitle = LibStub("tekKonfig-Heading").new(
frame_config,
"Configuration",
"This panel allows you to configure all the macros.\nModifiers use macro syntax: nomod | mod:key | mod:key1/key2 | mod:key1,mod:key2\nEmpty modifiers to disable them."
)
local header = frame_config:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
header:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", 0, -16)
header:SetText("Main Macros: AutoHP & AutoMP")
local combatCheckButton = CreateFrame("CheckButton", "CombatCheckButton", frame_config, "ChatConfigCheckButtonTemplate")
CombatCheckButtonText:SetText("Enable combat mode")
combatCheckButton.tooltip = "Check this to enable in-combat items in macro"
combatCheckButton:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 0, -5)
combatCheckButton:SetChecked(Core.db.combat)
combatCheckButton:SetScript("OnClick",
function()
if combatCheckButton:GetChecked() then
Core.db.combat = true
else
Core.db.combat = false
end
Core:QueueScan()
end
)
local hearthstoneCheckButton = CreateFrame("CheckButton", "HearthstoneCheckButton", frame_config, "ChatConfigCheckButtonTemplate")
HearthstoneCheckButtonText:SetText("Default to hearthstone")
hearthstoneCheckButton.tooltip = "Check this to default to hearthstone"
hearthstoneCheckButton:SetPoint("TOPLEFT", combatCheckButton, "BOTTOMLEFT", 0, -5)
hearthstoneCheckButton:SetChecked(Core.db.hearthstone)
hearthstoneCheckButton:SetScript("OnClick",
function()
if hearthstoneCheckButton:GetChecked() then
Core.db.hearthstone = true
else
Core.db.hearthstone = false
end
Core:QueueScan()
end
)
local modConjured = modEdit(
frame_config,
hearthstoneCheckButton,
"In-Combat: conjured items modifier (mana gems, healthstone)",
Core.db.modConjured,
"Modifier for in-combat conjured items",
function(self)
local mod = self:GetText() or ""
if Core.db.modConjured ~= mod then
Core.db.modConjured = mod
Core:QueueScan()
end
end
)
local modPotion = modEdit(
frame_config,
modConjured,
"In-Combat: potion items modifier",
Core.db.modPotion,
"Modifier for in-combat potion items",
function(self)
local mod = self:GetText() or ""
if Core.db.modPotion ~= mod then
Core.db.modPotion = mod
Core:QueueScan()
end
end
)
local modSpecial = modEdit(
frame_config,
modPotion,
"Special items modifier (bandage, runes)",
Core.db.modSpecial,
"Modifier for special items",
function(self)
local mod = self:GetText() or ""
if Core.db.modSpecial ~= mod then
Core.db.modSpecial = mod
Core:QueueScan()
end
end
)
local header = frame_config:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
header:SetPoint("TOPLEFT", modSpecial, "BOTTOMLEFT", 0, -16)
header:SetText("Consumables Macros: ConsumableHP & ConsumableMP")
local consModConjured = modEdit(
frame_config,
header,
"Conjured items modifier (mana gems, healthstone)",
Core.db.consModConjured,
"Modifier for in-combat conjured items",
function(self)
local mod = self:GetText() or ""
if Core.db.consModConjured ~= mod then
Core.db.consModConjured = mod
Core:QueueScan()
end
end
)
local consModPotion = modEdit(
frame_config,
consModConjured,
"Potion items modifier",
Core.db.consModPotion,
"Modifier for in-combat potion items",
function(self)
local mod = self:GetText() or ""
if Core.db.consModPotion ~= mod then
Core.db.consModPotion = mod
Core:QueueScan()
end
end
)
local consModSpecial = modEdit(
frame_config,
consModPotion,
"Special items modifier (bandage, runes)",
Core.db.modSpecial,
"Modifier for special items",
function(self)
local mod = self:GetText() or ""
if Core.db.consModSpecial ~= mod then
Core.db.consModSpecial = mod
Core:QueueScan()
end
end
)
frame_config:SetScript("OnShow", nil)
end)
InterfaceOptions_AddCategory(frame_config)
LibStub("tekKonfig-AboutPanel").new("Buffet", "Buffet")
----------------------------------------
-- Quicklaunch registration --
----------------------------------------
LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Buffet", {
type = "launcher",
icon = "Interface\\Icons\\INV_Misc_Food_DimSum",
OnClick = function()
InterfaceOptionsFrame_OpenToCategory(frame)
InterfaceOptionsFrame_OpenToCategory(frame_config)
InterfaceOptionsFrame_OpenToCategory(frame)
end,
})