-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
options.lua
593 lines (494 loc) · 19.9 KB
/
options.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
local _, ADDONSELF = ...
local L = ADDONSELF.L
local RegEvent = ADDONSELF.regevent
local Database = ADDONSELF.db
local f = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate" or nil)
local category = Settings.RegisterCanvasLayoutCategory(f, L["Raid Ledger"])
ADDONSELF.settingcategory = category
Settings.RegisterAddOnCategory(category)
do
local t = f:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
t:SetText(L["Raid Ledger"])
t:SetPoint("TOPLEFT", f, 20, -15)
end
do
local t = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
t:SetText(L["Feedback"] .. " [email protected]")
t:SetPoint("TOPLEFT", f, 20, -50)
end
RegEvent("ADDON_LOADED", function()
-- dropbox filter
do
local t = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
t:SetPoint("TOPLEFT", f, 5, -100)
local tt = t:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tt:SetPoint("BOTTOMLEFT", t, "TOPLEFT", 20, 0)
tt:SetText(L["Auto recording quality"])
local onclick = function(self)
UIDropDownMenu_SetSelectedValue(t, self.value)
Database:SetConfig("filterlevel", self.value)
end
UIDropDownMenu_Initialize(t, function()
local info = UIDropDownMenu_CreateInfo()
info.text = ALL
info.value = -1
info.func = onclick
info.classicChecks = true
UIDropDownMenu_AddButton(info)
for i = 0, getn(ITEM_QUALITY_COLORS)-4 do
info.text = _G["ITEM_QUALITY"..i.."_DESC"]
info.value = i
info.func = onclick
info.checked = nil
UIDropDownMenu_AddButton(info)
end
end)
UIDropDownMenu_SetSelectedValue(t, Database:GetConfigOrDefault("filterlevel", LE_ITEM_QUALITY_RARE))
end
-- autoadd filter
do
-- TODO const
local AUTOADDLOOT_TYPE_ALL = 0
-- local AUTOADDLOOT_TYPE_PARTY = 1
local AUTOADDLOOT_TYPE_RAID = 1
local AUTOADDLOOT_TYPE_DISABLE = 2
local t = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
t:SetPoint("TOPLEFT", f, 150, -100)
local tt = t:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tt:SetPoint("BOTTOMLEFT", t, "TOPLEFT", 20, 0)
tt:SetText(L["Auto recording loot"])
local onclick = function(self)
UIDropDownMenu_SetSelectedValue(t, self.value)
Database:SetConfig("autoaddloot", self.value)
end
UIDropDownMenu_Initialize(t, function()
do
local info = UIDropDownMenu_CreateInfo()
info.text = ALL
info.value = 0
info.func = onclick
UIDropDownMenu_AddButton(info)
end
do
local info = UIDropDownMenu_CreateInfo()
info.text = L["In Raid Only"]
info.value = 1
info.func = onclick
UIDropDownMenu_AddButton(info)
end
do
local info = UIDropDownMenu_CreateInfo()
info.text = NONE
info.value = 2
info.func = onclick
UIDropDownMenu_AddButton(info)
end
end)
UIDropDownMenu_SetSelectedValue(t, Database:GetConfigOrDefault("autoaddloot", AUTOADDLOOT_TYPE_RAID))
end
-- popup outstanding input dialog
do
-- TODO const
local POPUPOUTSTANDING_TYPE_ALL = 0
-- local AUTOADDLOOT_TYPE_PARTY = 1
local POPUPOUTSTANDING_TYPE_RAID = 1
local POPUPOUTSTANDING_TYPE_DISABLE = 2
local t = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
t:SetPoint("TOPLEFT", f, 300, -100)
local tt = t:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tt:SetPoint("BOTTOMLEFT", t, "TOPLEFT", 20, 0)
tt:SetText(L["Popup outstanding input dialog"])
local onclick = function(self)
UIDropDownMenu_SetSelectedValue(t, self.value)
Database:SetConfig("popupoutstanding", self.value)
end
UIDropDownMenu_Initialize(t, function()
do
local info = UIDropDownMenu_CreateInfo()
info.text = ALL
info.value = 0
info.func = onclick
UIDropDownMenu_AddButton(info)
end
do
local info = UIDropDownMenu_CreateInfo()
info.text = L["In Raid Only"]
info.value = 1
info.func = onclick
UIDropDownMenu_AddButton(info)
end
do
local info = UIDropDownMenu_CreateInfo()
info.text = NONE
info.value = 2
info.func = onclick
UIDropDownMenu_AddButton(info)
end
end)
UIDropDownMenu_SetSelectedValue(t, Database:GetConfigOrDefault("popupoutstanding", POPUPOUTSTANDING_TYPE_RAID))
end
do
local b = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
b:SetPoint("TOPLEFT", f, 20, -145)
b.text = b:CreateFontString(nil, "OVERLAY", "GameFontNormal")
b.text:SetPoint("LEFT", b, "RIGHT", 0, 1)
b.text:SetText(L["Minimap Icon"])
b:SetChecked(Database:GetConfigOrDefault("minimapicon", true))
b:SetScript("OnClick", function()
Database:SetConfig("minimapicon", b:GetChecked())
local icon = LibStub("LibDBIcon-1.0")
if b:GetChecked() then
icon:Show("RaidLedger")
else
icon:Hide("RaidLedger")
end
end)
end
do
local raidbutton = nil
local createbtn = function()
if raidbutton then
return
end
if _G.RaidFrame then
local b = CreateFrame("Button", nil, _G.RaidFrame, "UIPanelButtonTemplate")
b:SetWidth(100)
b:SetHeight(20)
b:SetPoint("TOPRIGHT", -25, 0)
b:SetText(L["Raid Ledger"])
b:SetScript("OnClick", function()
local GUI = ADDONSELF.gui
if GUI.mainframe:IsShown() then
GUI.mainframe:Hide()
else
GUI.mainframe:Show()
end
end)
raidbutton = b
end
end
local b = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
b:SetPoint("TOPLEFT", f, 150, -145)
b.text = b:CreateFontString(nil, "OVERLAY", "GameFontNormal")
b.text:SetPoint("LEFT", b, "RIGHT", 0, 1)
b.text:SetText(L["Raid Frame Button"])
b:SetChecked(Database:GetConfigOrDefault("raidbutton", true))
local showorhide = function()
createbtn()
if not raidbutton then
return
end
if b:GetChecked() then
raidbutton:Show()
else
raidbutton:Hide()
end
end
showorhide()
b:SetScript("OnClick", function()
Database:SetConfig("raidbutton", b:GetChecked())
showorhide()
end)
end
local editDebitTemplate
do
local t = CreateFrame("Frame", nil, f, BackdropTemplateMixin and "BackdropTemplate" or nil)
t:SetPoint("TOPLEFT", f, 25, -230)
t:SetWidth(550)
t:SetHeight(200)
t:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true,
tileEdge = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
})
t:SetBackdropColor(0, 0, 0);
local s = CreateFrame("ScrollFrame", nil, t, "UIPanelScrollFrameTemplate")
s:SetWidth(510)
s:SetHeight(175)
s:SetPoint("TOPLEFT", 10, -10)
local edit = CreateFrame("EditBox", nil, s)
edit.cursorOffset = 0
edit:SetWidth(500)
edit:SetHeight(150)
edit:SetAutoFocus(false)
edit:EnableMouse(true)
edit:SetMaxLetters(99999999)
edit:SetMultiLine(true)
edit:SetFontObject(GameTooltipText)
edit:SetScript("OnTextChanged", function(self)
ScrollingEdit_OnTextChanged(self, s)
end)
edit:SetScript("OnCursorChanged", ScrollingEdit_OnCursorChanged)
edit:SetScript("OnEscapePressed", edit.ClearFocus)
s:SetScrollChild(edit)
editDebitTemplate = edit
end
do
local t = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
t:SetPoint("TOPLEFT", f, 5, -200)
local tt = t:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tt:SetPoint("BOTTOMLEFT", t, "TOPLEFT", 20, 0)
tt:SetText(L["Debit Template"])
local templates = Database:GetConfigOrDefault("debittemplates", {})
ADDONSELF.GetDebitTemplate = function(idx)
local idx = idx or UIDropDownMenu_GetSelectedValue(t) or "NOTEXISTS"
local s = templates[idx] and templates[idx].value or ""
local output = {}
s = string.gsub(s,"(#.[^\n]*\n)", "")
for _, line in ipairs({strsplit("\n", s)}) do
line = strtrim(line)
if line ~= nil and line ~= "" then
local x = {strsplit(" ", line)}
if #x >= 3 then
(function()
local costtype = x[#x]
table.remove(x, #x)
local cost = tonumber(x[#x])
table.remove(x, #x)
local reason = strtrim(table.concat(x, " "))
if costtype == "G" then
costtype = "GOLD"
elseif costtype == "%" then
costtype = "PROFIT_PERCENT"
elseif costtype == "%%" then
costtype = "REVENUE_PERCENT"
elseif costtype == "*" then
costtype = "MUL_AVG"
else
return
end
if not cost then
return
end
if reason == "" then
return
end
table.insert( output, 1, {
costtype = costtype,
cost = cost,
reason = reason,
} )
end)()
end
end
end
return output
end
local onclick = function(self)
local idx = self.value
UIDropDownMenu_SetSelectedValue(t, idx)
Database:SetConfig("debittemplateidx", idx)
local n = templates[idx] and templates[idx].name or ""
UIDropDownMenu_SetText(t, n)
local v = templates[idx] and templates[idx].value or ""
editDebitTemplate:SetText(v)
end
local create = function(name)
local template = {
name = name
}
table.insert(templates, template)
local info = UIDropDownMenu_CreateInfo()
info.text = template.name
info.value = #templates
info.func = onclick
UIDropDownMenu_AddButton(info)
end
local save = function(force)
local c = UIDropDownMenu_GetSelectedValue(t)
local v = editDebitTemplate:GetText()
if not force and v == "" then
return
end
if (not c) or (not templates[c]) then
create(date())
UIDropDownMenu_SetSelectedValue(t, #templates)
c = #templates
end
templates[c].value = v
end
editDebitTemplate:SetScript("OnTextChanged", function() save(false) end)
UIDropDownMenu_Initialize(t, function()
for i, template in pairs(templates) do
-- print(template.name)
local info = UIDropDownMenu_CreateInfo()
info.text = template.name
info.value = i
info.func = onclick
UIDropDownMenu_AddButton(info)
end
end)
do
local idx = Database:GetConfigOrDefault("debittemplateidx", nil)
UIDropDownMenu_SetSelectedValue(t, idx)
onclick({value = idx})
end
local popctx = {}
StaticPopupDialogs["RAIDLEDGER_DEBIT_TEMPLATE_NAME"].OnShow = function(self)
local c = popctx.current
if c and templates[c] then
self.editBox:SetText(templates[c].name or "")
end
end
StaticPopupDialogs["RAIDLEDGER_DEBIT_TEMPLATE_NAME"].OnAccept = function(self)
local c = popctx.current
-- if c then rename
if c and templates[c] then
local n = self.editBox:GetText()
if n ~= "" then
templates[c].name = n
UIDropDownMenu_SetText(t, n)
end
return
end
create(self.editBox:GetText())
onclick({value = #templates})
end
do
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
b:SetWidth(70)
b:SetHeight(25)
b:SetPoint("TOPLEFT", t, 160, 0)
b:SetText(NEW)
b:SetScript("OnClick", function()
popctx.current = nil
StaticPopup_Show("RAIDLEDGER_DEBIT_TEMPLATE_NAME")
end)
end
do
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
b:SetWidth(70)
b:SetHeight(25)
b:SetPoint("TOPLEFT", t, 235, 0)
b:SetText(SAVE)
b:SetScript("OnClick", function() save(true) end)
end
do
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
b:SetWidth(70)
b:SetHeight(25)
b:SetPoint("TOPLEFT", t, 310, 0)
b:SetText(DELETE)
b:SetScript("OnClick", function()
local c = UIDropDownMenu_GetSelectedValue(t)
if c then
table.remove( templates, c)
end
if #templates == 0 then
UIDropDownMenu_SetSelectedValue(t, nil)
UIDropDownMenu_SetText(t, "")
editDebitTemplate:SetText("")
else
onclick({value = #templates})
end
end)
end
do
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
b:SetWidth(70)
b:SetHeight(25)
b:SetPoint("TOPLEFT", t, 385, 0)
b:SetText(L["Rename"])
b:SetScript("OnClick", function()
local c = UIDropDownMenu_GetSelectedValue(t)
if c and templates[c] then
popctx.current = c
StaticPopup_Show("RAIDLEDGER_DEBIT_TEMPLATE_NAME")
end
end)
end
do
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
b:SetWidth(125)
b:SetHeight(25)
b:SetPoint("TOPLEFT", t, 460, 0)
b:SetText(L["Import from ledger"])
b:SetScript("OnClick", function()
local items = Database:GetCurrentLedger()["items"]
local all = {}
local s = ""
for _, item in pairs(items or {}) do
local c = item["cost"] or 0
local t = item["type"]
local ct = item["costtype"] or "GOLD"
local d = item["detail"]["displayname"] or ""
if t == "DEBIT" then
local x
if ct == "GOLD" then
x = d .. " " .. c .. " G"
elseif ct == "PROFIT_PERCENT" then
x = d .. " " .. c .. " %"
elseif ct == "REVENUE_PERCENT" then
x = d .. " " .. c .. " %%"
elseif ct == "MUL_AVG" then
x = d .. " " .. c .. " *"
end
s = x .. "\r\n" .. s
all[x] = true
end
end
editDebitTemplate:SetText(strtrim(editDebitTemplate:GetText() .. "\r\n" .. s))
save()
end)
end
local editDebitTemplate
do
local t = CreateFrame("Frame", nil, f, BackdropTemplateMixin and "BackdropTemplate" or nil)
local tt = t:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tt:SetPoint("BOTTOMLEFT", t, "TOPLEFT", 10, 0)
tt:SetText(L["Auto recording blacklist"])
t:SetPoint("TOPLEFT", f, 25, -450)
t:SetWidth(550)
t:SetHeight(100)
t:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true,
tileEdge = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
})
t:SetBackdropColor(0, 0, 0);
local s = CreateFrame("ScrollFrame", nil, t, "UIPanelScrollFrameTemplate")
s:SetWidth(510)
s:SetHeight(75)
s:SetPoint("TOPLEFT", 10, -10)
local edit = CreateFrame("EditBox", nil, s)
edit.cursorOffset = 0
edit:SetWidth(500)
edit:SetHeight(150)
edit:SetAutoFocus(false)
edit:EnableMouse(true)
edit:SetMaxLetters(99999999)
edit:SetMultiLine(true)
edit:SetFontObject(GameTooltipText)
edit:SetScript("OnTextChanged", function(self)
ScrollingEdit_OnTextChanged(self, s)
Database:SetConfig("filteritems", edit:GetText())
end)
edit:SetScript("OnCursorChanged", ScrollingEdit_OnCursorChanged)
edit:SetScript("OnEscapePressed", edit.ClearFocus)
s:SetScrollChild(edit)
edit:SetText(Database:GetConfigOrDefault("filteritems", L["# one item per line, can be item name or item id"] .. "\n" .. L["# line starts with # will be ignored"] .. "\n"))
end
end
end)
StaticPopupDialogs["RAIDLEDGER_DEBIT_TEMPLATE_NAME"] = {
text = L["Name of Debit template"],
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = true,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
multiple = 0,
OnAccept = function()
end,
OnShow = function()
end,
}