-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
executable file
·276 lines (261 loc) · 7.94 KB
/
ui.lua
File metadata and controls
executable file
·276 lines (261 loc) · 7.94 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
-- SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
-- Copyright (c) 2025-2026 Thomas Floeren
local MYNAME, A = ...
local db = A.db
local defaults = A.defaults
local MYPRETTYNAME = C_AddOns.GetAddOnMetadata(MYNAME, 'Title')
local MYVERSION = C_AddOns.GetAddOnMetadata(MYNAME, 'Version')
local CLR = A.CLR
local addonprint, arrayprint = A.addonprint, A.arrayprint
local BLOCKSEP = A.BLOCKSEP
local tonumber = tonumber
local type = type
local format = format
A.MSG_NO_REALM = CLR.BAD('Could not get realm name at login! \nPlease try reloading or report the issue.')
A.MSG_NO_AUCTION_DATA = CLR.BAD('Could not fetch data for auction index %s!\nPlease try reopening the BMAH.')
--[[============================================================================
Slash UI
============================================================================]]--
local CMD1, CMD2, CMD3 = '/goyita', '/gy', nil
local function last_record_to_chat(update)
local records = A.messy_main_func(update)
if split_lines_for_console then
local t = strsplittable('\n', records[1])
arrayprint(t)
else
print(records[1])
end
print(BLOCKSEP)
end
local function print_config()
local array = {}
for k, v in pairs(db.cfg) do
local deftext, defvalue = '', defaults.cfg[k]
if defvalue ~= v then deftext = ' (' .. tostring(defvalue) .. ')' end
tinsert(array, tostring(k) .. ' = ' .. tostring(v) .. deftext)
end
table.sort(array)
arrayprint(array)
end
local function set_config(key, value)
if not value then
addonprint(
format(
'%sMissing value! %sSeparate key and value with a %s.',
CLR.BAD(),
CLR.TXT(),
CLR.KEY('Space')
)
)
end
if value == 'true' then
value = true
elseif value == 'false' then
value = false
else
value = tonumber(value) or value
end
if type(db.cfg[key]) == type(value) then
db.cfg[key] = value
addonprint(format('%s set to %s.', CLR.KEY(key), CLR.KEY(tostring(value))))
else
addonprint(
format(
"Either the key (%s) doesn't exist or the value (%s) is invalid.",
CLR.KEY(key),
CLR.KEY(tostring(value))
)
)
end
end
local helptext = {
A.BLOCKSEP,
format( -- Header
'%s%s Help: %s or %s accepts these arguments:',
CLR.HEAD(),
CLR.ADDON(MYPRETTYNAME),
CLR.CMD(CMD1),
CLR.CMD(CMD2)
),
{ -- Show records
'%s (or just %s) : Open records frame (cached view).',
CLR.CMD('r'),
CLR.CMD('/gy'),
},
{ -- Show notifications
'%s or %s : Open notifications frame (history of recent notifications).',
CLR.CMD('notif'),
CLR.CMD('n'),
},
{ -- Print last
'%s : Print last record to the chat console (cached view).',
CLR.CMD('p'),
},
{ -- Set BM reset time
'%s : Set local BlackMarket reset time (default: %s).',
CLR.CMD('rtime <HH:MM>'),
CLR.KEY('23:30'),
},
{ -- Sounds master toggle
'%s : Toggle notification sounds.',
CLR.CMD('sound'),
},
{ -- Chat messages master toggle
'%s : Toggle chat notifications.',
CLR.CMD('chat'),
},
{ -- Notifications frame master toggle
'%s : Toggle on-screen notification frames.',
CLR.CMD('screen'),
},
{ -- Cfg print
'%s : Show all setting keys and values.',
CLR.CMD('c'),
},
{ -- Cfg set
'%s %s : Set a key to the specified value.',
CLR.CMD('c'),
CLR.KEY('<key> <value>'),
},
{ -- Version
'%s : Print addon version.',
CLR.CMD('version'),
},
{ -- Help
'%s or %s : Print this help text.',
CLR.CMD('help'),
CLR.CMD('h'),
},
{ -- Debug mode
'%s : Toggle debug mode.',
CLR.CMD('dm'),
},
format( -- Header for 'clear' section
'%sThe following %q commands require an UI Reload!',
CLR.ADDON(),
CLR.CMD('clear'),
CLR.WARN('UI Realod')
),
{ -- Clear records
'%s : Clear auction records (the text in the records frame).',
CLR.CMD('clearrecords'),
},
{ -- Clear auctions
'%s : Clear auction data (the data used for computing the records).',
CLR.CMD('clearauctions'),
},
{ -- Clear notifs
'%s : Clear notification history.',
CLR.CMD('clearnotifs'),
},
{ -- Clear data
'%s : Clear records, auction data, notification history.',
CLR.CMD('cleardata'),
},
{ -- Clear all data
'%s : Like %q, but all realms.',
CLR.CMD('clearalldata'),
CLR.CMD('cleardata'),
},
{ -- Clear settings
'%s : Clear all user settings, back to defaults.',
CLR.CMD('clearsettings'),
},
A.BLOCKSEP,
}
local function print_help(linestable, linecolor)
linecolor = linecolor or CLR.TXT()
for _, v in ipairs(linestable) do
if type(v) == 'table' then
v[1] = linecolor .. v[1]
print(format(unpack(v)))
else
print(v)
end
end
end
--[[----------------------------------------------------------------------------
Slash function
----------------------------------------------------------------------------]]--
SLASH_BMAHHELPER1 = CMD1
SLASH_BMAHHELPER2 = CMD2
SlashCmdList.BMAHHELPER = function(msg)
local args = {}
for arg in msg:gmatch('[^ ]+') do
tinsert(args, arg)
end
if args[1] == 'version' or args[1] == 'ver' then
addonprint(format('Version %s', CLR.KEY(MYVERSION)))
elseif args[1] == 'dm' then
db.cfg.debugmode = not db.cfg.debugmode
addonprint(
format('Debug mode %s.', db.cfg.debugmode and CLR.ON('enabled') or CLR.OFF('disabled'))
)
elseif args[1] == nil or args[1] == 'r' or args[1] == 'rec' or args[1] == 'records' then
A.show_records(false)
elseif args[1] == 'n' or args[1] == 'notif' or args[1] == 'notifs' then
A.show_notifs(true, false)
elseif args[1] == 'p' or args[1] == 'print' then
last_record_to_chat(false)
elseif args[1] == 'clearrecords' then -- TODO: add confirmations (and check) for all clears
A.clear_records()
elseif args[1] == 'clearauctions' then
A.clear_auctions()
elseif args[1] == 'clearnotifs' then
A.clear_notifs()
elseif args[1] == 'cleardata' then
A.clear_data()
elseif args[1] == 'clearalldata' then
A.clear_alldata()
elseif args[1] == 'clearsettings' then
A.clear_settings()
elseif args[1] == 'sounds' or args[1] == 'sound' then
db.cfg.notif_sound = not db.cfg.notif_sound
addonprint(format('Notification sounds are %s now.', db.cfg.notif_sound and CLR.ON('enabled') or CLR.OFF('disabled')))
elseif args[1] == 'chat' then
db.cfg.notif_chat = not db.cfg.notif_chat
addonprint(format('Chat notifications are %s now.', db.cfg.notif_chat and CLR.ON('enabled') or CLR.OFF('disabled')))
elseif args[1] == 'screen' or args[1] == 'onscreen' then
db.cfg.notif_frame = not db.cfg.notif_frame
addonprint(format('On-screen notifications are %s now.', db.cfg.notif_frame and CLR.ON('enabled') or CLR.OFF('disabled')))
elseif args[1] == 'resettime' or args[1] == 'rtime' then
local timestr = args[2]
if A.is_valid_bm_reset_time(timestr) then
db.cfg.bm_reset_time = timestr
addonprint(format('Black Market reset time set to %s local time. Will become effective after UI reload.', CLR.KEY(timestr)))
else
addonprint(format('%s%s is not a valid time! %sValid examples: %s, %s, %s', CLR.WARN(), CLR.BAD(timestr), CLR.TXT(), CLR.GOOD('23:30'), CLR.GOOD('2:30'), CLR.GOOD('02:30')))
end
elseif args[1] == 'c' and args[2] == nil then
print(BLOCKSEP)
addonprint('Current config:')
print_config()
print(BLOCKSEP)
elseif args[1] == 'c' and args[2] and args[3] then
print(BLOCKSEP)
set_config(args[2], args[3])
print(BLOCKSEP)
elseif args[1] == 'help' or args[1] == 'h' then
print_help(helptext)
elseif args[1] == 't1' then
A.simulate_event(A.BLACK_MARKET_BID_RESULT, A.BLACK_MARKET_ITEM_UPDATE)
elseif args[1] == 't2' then
A.simulate_event(A.BLACK_MARKET_OUTBID)
elseif args[1] == 't3' then
A.simulate_event(A.BLACK_MARKET_WON)
else
addonprint(
format('%s Enter %s for help.', CLR.BAD('Not a valid input.'), CLR.CMD(CMD2 .. ' h'))
)
end
end
--[[============================================================================
For the bindings.xml
============================================================================]]--
-- BINDING_HEADER_GOYITA = "Goyita "
BINDING_NAME_BFA6 = 'Show Records'
function BFA6() A.show_records() end
BINDING_NAME_C780 = 'Show Notifications'
function C780() A.show_notifs() end
BINDING_NAME_FC97 = 'Refresh BMAH'
function FC97() A.bm_refresh() end