-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfig.lua
More file actions
702 lines (651 loc) · 18.6 KB
/
Config.lua
File metadata and controls
702 lines (651 loc) · 18.6 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
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
-------------------------------------------------------------------------------
-- Config.lua
--
-- AuctionLite configuration stuff.
-------------------------------------------------------------------------------
local L = LibStub("AceLocale-3.0"):GetLocale("AuctionLite", false)
local DBName = "AuctionLiteDB";
-------------------------------------------------------------------------------
-- First, tables of options
-------------------------------------------------------------------------------
-- Currently no slash commands...
local Options = {
type = "group",
get = function(item) return AuctionLite.db.profile[item[#item]] end,
set = function(item, value) AuctionLite.db.profile[item[#item]] = value end,
args = {
storePrices = {
type = "toggle",
desc = L["Store price data for all items seen (disable to save memory)."],
name = L["Store Price Data"],
order = 4,
},
clearData = {
type = "execute",
handler = AuctionLite,
func = "ClearData",
desc = L["Clear all auction house price data."],
name = L["Clear All Data"],
order = 6,
},
openBags = {
type = "toggle",
desc = L["Open all your bags when you visit the auction house."],
name = L["Open All Bags at AH"],
width = "double",
order = 8,
},
startTab = {
type = "select",
desc = L["Choose which tab is selected when opening the auction house."],
name = L["Start Tab"],
style = "dropdown",
values = {
a_default = L["Default"],
b_buy = L["Buy Tab"],
c_sell = L["Sell Tab"],
d_last = L["Last Used Tab"],
},
order = 12,
},
startFavoriteScan = {
type = "toggle",
desc = L["Scan favorites when opening the auction house."],
name = L["Scan favorites"],
width = "double",
order = 14,
disabled = function()
return AuctionLite.db.profile.startTab ~= "b_buy"
end,
}
},
};
local BuyOptions = {
type = "group",
get = function(item) return AuctionLite.db.profile[item[#item]] end,
set = function(item, value) AuctionLite.db.profile[item[#item]] = value end,
args = {
minProfit = {
type = "range",
desc = L["Deals must be below the historical price by this much gold."],
name = L["Minimum Profit (Gold)"],
min = 0,
max = 1000,
step = 10,
order = 5,
},
minDiscount = {
type = "range",
desc = L["Deals must be below the historical price by this percentage."],
name = L["Minimum Profit (Pct)"],
isPercent = true,
min = 0,
max = 1,
step = 0.01,
order = 6,
},
getAll = {
type = "toggle",
desc = L["Use fast method for full scans (may cause disconnects)."],
name = L["Fast Auction Scan"],
width = "double",
order = 7,
},
countMyListings = {
type = "toggle",
desc = L["On the summary view, show how many listings/items are yours."],
name = L["Show How Many Listings are Mine"],
width = "double",
order = 8,
},
considerResale = {
type = "toggle",
desc = L["Consider resale value of excess items when filling an order on the \"Buy\" tab."],
name = L["Consider Resale Value When Buying"],
width = "double",
order = 9,
},
},
};
local SellOptions = {
type = "group",
get = function(item) return AuctionLite.db.profile[item[#item]] end,
set = function(item, value) AuctionLite.db.profile[item[#item]] = value end,
args = {
bidUndercut = {
type = "range",
desc = L["Percent to undercut market value for bid prices (0-100)."],
name = L["Bid Undercut"],
isPercent = true,
min = 0,
max = 1,
step = 0.01,
order = 1,
},
buyoutUndercut = {
type = "range",
desc = L["Percent to undercut market value for buyout prices (0-100)."],
name = L["Buyout Undercut"],
isPercent = true,
min = 0,
max = 1,
step = 0.01,
order = 2,
},
vendorMultiplier = {
type = "range",
desc = L["Amount to multiply by vendor price to get default sell price."],
name = L["Vendor Multiplier"],
min = 0,
max = 100,
step = 0.5,
order = 3,
},
roundPrices = {
type = "range",
desc = L["Round all prices to this granularity, or zero to disable (0-1)."],
name = L["Round Prices"],
min = 0,
max = 1,
step = 0.01,
order = 4,
},
defaultStacks = {
type = "select",
desc = L["Number of stacks suggested when an item is first placed in the \"Sell\" tab."],
name = L["Default Number of Stacks"],
style = "dropdown",
values = {
a_one = L["One Stack"],
b_full = L["Max Stacks"],
c_excess = L["Max Stacks + Excess"],
},
order = 5,
},
defaultSize = {
type = "select",
desc = L["Stack size suggested when an item is first placed in the \"Sell\" tab."],
name = L["Default Stack Size"],
style = "dropdown",
values = {
a_one = L["One Item"],
b_stack = L["Selected Stack Size"],
c_full = L["Full Stack"],
},
order = 6,
},
printPriceData = {
type = "toggle",
desc = L["Print detailed price data when selling an item."],
name = L["Print Detailed Price Data"],
width = "double",
order = 7,
},
},
};
local YesNoMaybe = {
a_yes = L["Always"],
b_maybe = L["If Applicable"],
c_no = L["Never"],
};
local TooltipOptions = {
type = "group",
get = function(item) return AuctionLite.db.profile[item[#item]] end,
set = function(item, value) AuctionLite.db.profile[item[#item]] = value end,
args = {
showVendor = {
type = "select",
desc = L["Show vendor sell price in tooltips."],
name = L["Show Vendor Price"],
style = "dropdown",
values = YesNoMaybe,
order = 1,
},
blankVendor = {
type = "description",
name = "",
desc = "",
order = 2,
},
showDisenchant = {
type = "select",
desc = L["Show expected disenchant value in tooltips."],
name = L["Show Disenchant Value"],
style = "dropdown",
values = YesNoMaybe,
order = 3,
},
blankDisenchant = {
type = "description",
name = "",
desc = "",
order = 4,
},
showAuction = {
type = "select",
desc = L["Show auction house value in tooltips."],
name = L["Show Auction Value"],
style = "dropdown",
values = YesNoMaybe,
order = 5,
},
blankAuction = {
type = "description",
name = "",
desc = "",
order = 6,
},
blank = {
type = "description",
name = " ",
desc = " ",
order = 7,
},
coinTooltips = {
type = "toggle",
desc = L["Uses the standard gold/silver/copper icons in tooltips."],
name = L["Use Coin Icons in Tooltips"],
width = "double",
order = 8,
},
showStackPrice = {
type = "toggle",
desc = L["Show full stack prices in tooltips (shift toggles on the fly)."],
name = L["Show Full Stack Price"],
width = "double",
order = 9,
},
},
};
local FavoritesOptions = {
type = "group",
handler = AuctionLite,
args = {
selectlist = {
name = L["Select a Favorites List"],
desc = L["Choose a favorites list to edit."],
type = "select",
get = "GetCurrentList",
set = "SetCurrentList",
values = "GetLists",
order = 12,
},
newlist = {
name = L["New..."],
desc = L["Create a new favorites list."],
type = "execute",
func = "NewList",
width = "half",
order = 15,
},
deletelist = {
name = L["Delete"],
desc = L["Delete the selected favorites list."],
type = "execute",
func = "DeleteList",
width = "half",
order = 20,
},
additem = {
name = L["Add an Item"],
desc = L["Add a new item to a favorites list by entering the name here."],
type = "input",
order = 30,
get = false,
set = "AddListItem",
width = "double",
},
selectitem = {
name = "",
desc = "",
type = "multiselect",
order = 40,
get = "GetCurrentListItems",
set = "SetCurrentListItems",
values = "GetListItems",
control = "ListBox",
width = "double",
},
removeitems = {
name = L["Remove Items"],
desc = L["Remove the selected items from the current favorites list."],
type = "execute",
func = "RemoveListItems",
order = 50,
}
},
};
local SlashOptions = {
type = "group",
handler = AuctionLite,
args = {
config = {
type = "execute",
desc = L["Open configuration dialog"],
name = L["Configure"],
func = function()
InterfaceOptionsFrame_OpenToCategory(AuctionLite.optionFrames.tooltips);
InterfaceOptionsFrame_OpenToCategory(AuctionLite.optionFrames.main);
end,
},
},
};
local SlashCmds = {
"al",
"auctionlite",
};
local Defaults = {
factionrealm = {
prices = {},
prefs = {},
},
profile = {
method = 1,
duration = 3,
bidUndercut = 0.25,
buyoutUndercut = 0.02,
vendorMultiplier = 3,
roundPrices = 0.05,
minProfit = 10,
minDiscount = 0.25,
getAll = false,
countMyListings = true,
openBags = false,
considerResale = false,
defaultStacks = "a_one",
defaultSize = "b_stack",
printPriceData = false,
showVendor = "a_yes",
showAuction = "b_maybe",
showDisenchant = "b_maybe",
coinTooltips = true,
showStackPrice = true,
storePrices = true,
startTab = "a_default",
lastTab = 1,
fastScanAd = false,
showGreeting = false,
favorites = { [L["Favorites"]] = {} },
startFavoriteScan = false,
},
};
-------------------------------------------------------------------------------
-- Handlers for favorites config screen
-------------------------------------------------------------------------------
-- Store the favorites list being edited and the selected items in that list.
local CurrentList = nil;
local SelectedItems = {};
local IndexKeys = {};
local ResetFocus = false;
-- Return the current favorites list.
function AuctionLite:GetCurrentList()
return CurrentList;
end
-- Set the current favorites list.
function AuctionLite:SetCurrentList(info, list)
if CurrentList ~= list then
CurrentList = list;
SelectedItems = {};
ResetFocus = true;
end
end
-- Get the list of favorites lists.
function AuctionLite:GetLists()
local lists = {};
for name, _ in pairs(self.db.profile.favorites) do
lists[name] = name;
if CurrentList == nil then
CurrentList = name;
SelectedItems = {};
end
end
return lists;
end
-- Prompt for a name for a new favorites list.
StaticPopupDialogs["AL_NEW_FAVORITES_LIST"] = {
text = L["Enter the name of the new favorites list:"],
button1 = L["Accept"],
button2 = L["Cancel"],
OnAccept = function(self)
local name = self.editBox:GetText();
AuctionLite:CreateList(name);
end,
EditBoxOnEnterPressed = function(self)
local name = self:GetText();
AuctionLite:CreateList(name);
self:GetParent():Hide();
end,
OnShow = function(self)
self.editBox:SetFocus();
end,
OnHide = function(self)
if ChatFrame1EditBox:IsShown() then
ChatFrame1EditBox:SetFocus();
end
self.editBox:SetText("");
end,
hasEditBox = 1,
timeout = 0,
exclusive = 1,
hideOnEscape = 1
};
-- Create a favorites list with a given name.
function AuctionLite:CreateList(name)
local favorites = self.db.profile.favorites;
if favorites[name] == nil then
favorites[name] = {};
CurrentList = name;
SelectedItems = {};
ResetFocus = true;
InterfaceOptionsFrame_OpenToCategory(self.optionFrames.favs);
end
end
-- Request a name for a new favorites list.
function AuctionLite:NewList()
StaticPopup_Show("AL_NEW_FAVORITES_LIST");
end
-- Delete a favorites list.
function AuctionLite:DeleteList()
if CurrentList ~= nil then
self.db.profile.favorites[CurrentList] = nil;
-- Find a new current list.
CurrentList = nil;
for name, _ in pairs(self.db.profile.favorites) do
CurrentList = name;
break;
end
-- If none exists, make an empty one.
if CurrentList == nil then
CurrentList = L["Favorites"];
self.db.profile.favorites[CurrentList] = {};
end
SelectedItems = {};
end
end
-- Add an item to a favorites list.
function AuctionLite:AddListItem(info, value)
if CurrentList ~= nil and value ~= "" then
local items = self.db.profile.favorites[CurrentList];
-- Did we get a link or a name?
local link;
local name = self:SplitLink(value);
if name ~= nil then
link = value;
else
name = value;
link = nil;
end
name = strlower(name);
-- Search for the item in the current list.
local found = false;
for item, _ in pairs(items) do
if self:IsLink(item) then
-- It's a link. If it's a match, we're done; no need to make changes.
if strlower(self:SplitLink(item)) == name then
found = true;
break;
end
else
-- It's a name. If it's a match, remove it so we can add a new entry
-- later, either with a link or with the new capitalization.
if strlower(item) == name then
items[item] = nil;
end
end
end
-- If we didn't find the item (or if we removed the old one), add it.
if not found then
if link ~= nil then
items[link] = true;
else
items[value] = true;
end
end
ResetFocus = true;
end
end
-- Indicate whether an item is selected.
function AuctionLite:GetCurrentListItems(info, key)
return SelectedItems[key];
end
-- Select or deselect an item.
function AuctionLite:SetCurrentListItems(info, key, value)
if not value then
value = nil;
end
SelectedItems[key] = value;
end
-- Get the contents of a favorites list.
function AuctionLite:GetListItems()
local result = {};
if CurrentList ~= nil then
local items = self.db.profile.favorites[CurrentList];
if items ~= nil then
local keys = {};
for item, _ in pairs(items) do
local name, color = self:SplitLink(item);
if name == nil or color == nil then
name = item;
color = "ffffffff";
end
local display = "|c" .. color .. name .. "|r";
table.insert(result, display);
keys[display] = item;
end
table.sort(result);
IndexKeys = {};
for index, display in ipairs(result) do
IndexKeys[index] = keys[display];
end
end
-- Massive hack: Move the focus to the "Add an Item" box. This needs
-- to be done whenever we get a list of items because AceConfig
-- rebuilds the entire panel on every event.
if ResetFocus then
ResetFocus = false;
local i = 1;
while true do
local editBox = _G["AceGUI-3.0EditBox" .. i];
if editBox == nil then
break;
elseif editBox.obj:GetUserDataTable().options == FavoritesOptions then
editBox:SetFocus();
break;
end
i = i + 1;
end
end
end
return result;
end
-- Remove a set of items from a favorites list.
function AuctionLite:RemoveListItems()
if CurrentList ~= nil then
local items = self.db.profile.favorites[CurrentList];
if items ~= nil then
for index, _ in pairs(SelectedItems) do
items[IndexKeys[index]] = nil;
end
end
SelectedItems = {};
end
end
-------------------------------------------------------------------------------
-- Initialization code
-------------------------------------------------------------------------------
-- If we see an Ace2 database, convert it to Ace3.
function AuctionLite:ConvertDB()
local db = _G[DBName];
-- It's Ace2 if it uses "realms" instead of "factionrealm".
if db ~= nil and db.realms ~= nil and db.factionrealm == nil then
-- Change "Realm - Faction" keys to "Faction - Realm" keys.
db.factionrealm = {}
for k, v in pairs(db.realms) do
db.factionrealm[k:gsub("(.*) %- (.*)", "%2 - %1")] = v;
end
-- Now unlink the old DB.
db.realms = nil;
end
end
-- Load our settings database.
function AuctionLite:LoadDB()
self.db = LibStub("AceDB-3.0"):New(DBName, Defaults, "Default");
end
-- If any of the options are outdated, convert them.
function AuctionLite:ConvertOptions()
for _, profile in pairs(self.db.profiles) do
-- Convert tooltip options.
if type(profile.showAuction) == "boolean" then
if profile.showAuction then
profile.showAuction = "b_maybe";
else
profile.showAuction = "c_no";
end
end
if type(profile.showVendor) == "boolean" then
if profile.showVendor then
profile.showVendor = "a_yes";
else
profile.showVendor = "c_no";
end
end
-- Convert favorites.
if profile.favorites ~= nil then
local value = true;
for _, v in pairs(profile.favorites) do
value = v;
break;
end
if type(value) == "boolean" then
profile.favorites = { [L["Favorites"]] = profile.favorites };
end
end
end
end
-- Set up all the config screens.
function AuctionLite:InitConfig()
local profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db);
local config = LibStub("AceConfig-3.0");
config:RegisterOptionsTable("AuctionLite", SlashOptions, SlashCmds);
local registry = LibStub("AceConfigRegistry-3.0");
registry:RegisterOptionsTable("AuctionLite Options", Options);
registry:RegisterOptionsTable("AuctionLite Buy", BuyOptions);
registry:RegisterOptionsTable("AuctionLite Sell", SellOptions);
registry:RegisterOptionsTable("AuctionLite Tooltips", TooltipOptions);
registry:RegisterOptionsTable("AuctionLite Favorites", FavoritesOptions);
registry:RegisterOptionsTable("AuctionLite Profiles", profiles);
local dialog = LibStub("AceConfigDialog-3.0");
self.optionFrames = {
main = dialog:AddToBlizOptions("AuctionLite Options", L["AuctionLite"]),
buy = dialog:AddToBlizOptions("AuctionLite Buy", L["Buy Tab"],
L["AuctionLite"]);
sell = dialog:AddToBlizOptions("AuctionLite Sell", L["Sell Tab"],
L["AuctionLite"]);
tooltips = dialog:AddToBlizOptions("AuctionLite Tooltips", L["Tooltips"],
L["AuctionLite"]);
favs = dialog:AddToBlizOptions("AuctionLite Favorites", L["Favorites"],
L["AuctionLite"]);
profiles = dialog:AddToBlizOptions("AuctionLite Profiles", L["Profiles"],
L["AuctionLite"]);
};
end