-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.lua
More file actions
624 lines (594 loc) · 15.6 KB
/
index.lua
File metadata and controls
624 lines (594 loc) · 15.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
PaintBrush = {
UIT_KEYS_BUFFER = {},
CLASS_NAMES_BUFFER = {},
default_config_merge = function(node, key, value)
node.config[key] = value
end,
default_node_merge = function(node, index, value)
node.nodes[#node.nodes + 1] = value
end,
config_merge = {
class = function(node, key, value)
node.config[key] = (node.config[key] or "") .. " " .. tostring(value or "")
end,
},
skippable_config_keys = {
nodes = true,
n = true,
config = true,
pb_config = true,
},
element_callbacks_list = {
"remove",
"update",
"click",
"hover",
"stop_hover",
"drag",
"stop_drag",
},
utils = {},
CSS = {
box_title = {
padding = 0.1,
r = 0.25,
colour = { 0, 0, 0, 0.1 },
align = "cm",
},
config_title = {
scale = 0.5,
colour = G.C.UI.TEXT_LIGHT,
},
config_subtitle = {
scale = 0.4,
colour = darken(G.C.UI.TEXT_LIGHT, 0.1),
},
config_line = {
scale = 0.32,
colour = darken(G.C.UI.TEXT_LIGHT, 0.2),
},
config_list_point = {
text = "> ",
scale = 0.32,
colour = G.C.ORANGE,
},
},
}
local next_unknown_key = 1
function PaintBrush.get_uit_key(uit)
for k, v in pairs(G.UIT) do
if v == uit then
PaintBrush.UIT_KEYS_BUFFER[uit] = k
return k
end
end
PaintBrush.UIT_KEYS_BUFFER[uit] = "?" .. next_unknown_key
next_unknown_key = next_unknown_key + 1
return PaintBrush.UIT_KEYS_BUFFER[uit]
end
local next_unknown_class = 1
function PaintBrush.get_object_class_name(meta)
for k, v in pairs(_G) do
if meta == v then
PaintBrush.CLASS_NAMES_BUFFER[meta] = k
return k
end
end
if SMODS then
for k, v in pairs(SMODS) do
if meta == v then
PaintBrush.CLASS_NAMES_BUFFER[meta] = "SMODS." .. k
return "SMODS." .. k
end
end
end
PaintBrush.CLASS_NAMES_BUFFER[meta] = "?Class" .. next_unknown_class
next_unknown_class = next_unknown_class + 1
return PaintBrush.CLASS_NAMES_BUFFER[meta]
end
function PaintBrush.get_topology(node, indent)
if node.render then
node = node:render()
end
indent = indent or ""
local formatted_class_name = ""
node.config = node.config or {}
if node.config.class then
for word in string.gmatch(node.config.class, "%S+") do
formatted_class_name = formatted_class_name .. "." .. word
end
end
local formatted_id = ""
if node.config.id then
formatted_id = "#" .. node.config.id
end
local formatted_n = PaintBrush.UIT_KEYS_BUFFER[node.n] or PaintBrush.get_uit_key(node.n) or "?"
local element_line = string.format("%s<%s%s%s", indent, formatted_n, formatted_id, formatted_class_name)
if node.n == G.UIT.T and node.config then
if node.config.ref_table then
element_line = element_line
.. " ref_table["
.. node.config.ref_value
.. "]='"
.. node.config.ref_table[node.config.ref_value]
.. "'"
else
element_line = element_line .. " text='" .. (node.config.text or "") .. "'"
end
elseif node.n == G.UIT.O then
local meta = getmetatable(node.config.object)
element_line = element_line
.. " object={"
.. (PaintBrush.CLASS_NAMES_BUFFER[meta] or PaintBrush.get_object_class_name(meta))
.. "}"
else
if node.config.align then
element_line = element_line .. " align='" .. node.config.align .. "'"
end
end
element_line = element_line .. ">"
local with_children = false
for _, subnode in pairs(node.nodes or {}) do
with_children = true
element_line = element_line .. "\n" .. PaintBrush.get_topology(subnode, indent .. " ")
end
if with_children then
element_line = element_line .. "\n" .. string.format("%s</%s>", indent or "", formatted_n)
end
return element_line
end
function PaintBrush.print_topology(node)
return print(" \n" .. PaintBrush.get_topology(node))
end
function PaintBrush.process_node_render(node)
if getmetatable(node) == PaintBrush.UINode then
node = node:render()
end
return node
end
function PaintBrush.process_element_created(node, element)
if node.pb_config then
if type(node.pb_config.init) == "function" then
node.pb_config.init(node, element)
end
for _, func in ipairs(PaintBrush.element_callbacks_list) do
if type(node.pb_config[func]) == "function" then
local old_func = element[func]
element[func] = function(self, ...)
return node.pb_config[func](node, self, old_func, ...)
end
end
end
end
end
--
PaintBrush.UINode = {
__call = function(self, ...)
return self:extend(...)
end,
process_config = function(self, key, value)
(PaintBrush.config_merge[key] or PaintBrush.default_config_merge)(self, key, value)
end,
process_node = function(self, index, value)
PaintBrush.default_node_merge(self, index, value)
end,
extend = function(self, ...)
local inputs = { ... }
for _, input in ipairs(inputs) do
if type(input) == "table" then
local children_to_insert = {}
if input.config then
for k, v in pairs(input.config) do
self:process_config(k, v)
end
end
if input.nodes then
for k, v in pairs(input.nodes) do
children_to_insert[#children_to_insert + 1] = { k, v }
end
end
if input.pb_config then
self.pb_config = SMODS.merge_defaults(input.pb_config or {}, self.pb_config or {}) or {}
end
for k, v in pairs(input) do
if type(k) == "number" then
children_to_insert[#children_to_insert + 1] = { k, v }
elseif PaintBrush.skippable_config_keys[k] then
else
self:process_config(k, v)
end
end
local child_index = 0
for _, v in ipairs(children_to_insert) do
if not self.no_flat_children and type(v[2]) == "table" and #v[2] > 0 then
for _, node in pairs(v[2]) do
child_index = child_index + 1
self.process_node(self, child_index, node)
end
else
child_index = child_index + 1
self:process_node(child_index, v[2])
end
end
end
end
return self
end,
render = function(self)
if self.pb_config.class_ref_table ~= nil then
for _, child in ipairs(self.nodes) do
if not child.pb_config then
child.pb_config = {}
end
if child.pb_config.class_ref_table == nil then
child.pb_config.class_ref_table = self.pb_config.class_ref_table
end
end
end
if self.pb_config.class then
local classes = self.pb_config.class_ref_table or PaintBrush.CSS or {}
local classname = self.pb_config.class
local old_config = self.config
self.config = {}
for word in string.gmatch(classname, "%S+") do
if classes[word] then
for k, v in pairs(classes[word]) do
self:process_config(k, v)
end
end
end
for k, v in pairs(old_config) do
self:process_config(k, v)
end
end
if type(self.config.object_func) == "function" then
self.config.object = self.config.object_func(self)
end
if self.n == G.UIT.O and not self.config.object then
self.config.object = Moveable()
end
return {
n = self.n,
config = self.config,
pb_config = self.pb_config,
nodes = self.nodes,
T = self.T,
}
end,
get_topology = function(self, indent)
return PaintBrush.get_topology(self, indent)
end,
print_topology = function(self)
return PaintBrush.print_topology(self)
end,
}
PaintBrush.UINode.__index = PaintBrush.UINode
PaintBrush.node = function(k, ...)
local pbnode = setmetatable({
n = G.UIT[k],
config = {},
pb_config = {},
nodes = {},
}, PaintBrush.UINode)
return pbnode(...)
end
PaintBrush.uit_function = function(k)
assert(k and G.UIT[k] and k ~= "padding", "Invalid node type for PaintBrush node: " .. tostring(k))
local result = function(...)
return PaintBrush.node(k, ...)
end
return result
end
PB = setmetatable({}, {
__call = function(t, ...)
local args = { ... }
local uit
for _, arg in pairs(args) do
if type(arg) == "table" then
uit = arg.n and (G.UIT[arg.n] and arg.n or PaintBrush.get_uit_key(arg.n)) or nil
elseif arg then
uit = G.UIT[arg] and arg or PaintBrush.get_uit_key(arg)
end
if uit then
return t[uit](...)
end
end
error("Not found node type for PaintBrush node")
end,
__index = function(t, k)
return rawget(t, k) or PaintBrush.uit_function(k)
end,
})
function PaintBrush.extend(element_fn, extension)
return function(...)
local node = element_fn()
if extension.no_flat_children ~= nil then
node.no_flat_children = extension.no_flat_children
end
for k, v in pairs(extension) do
if type(v) == "function" then
local old_fn = node[k] or function() end
node[k] = function(self, ...)
return v(self, old_fn, ...)
end
end
end
return node(...)
end
end
local default_rc_process = function(self, super_func, index, v)
if v.is and v:is(Moveable) then
v = PB.O({ v })
elseif type(v) == "string" then
v = PB.T({ colour = G.C.UI.TEXT_LIGHT, scale = 0.32, v })
end
if self.pb_config.rc_fix_target == nil then
if v.n == G.UIT.C or v.n == G.UIT.O then
self.pb_config.rc_fix_target = G.UIT.C
elseif v.n == G.UIT.R then
self.pb_config.rc_fix_target = G.UIT.R
end
super_func(self, index, v)
elseif self.pb_config.rc_fix_target == G.UIT.C and v.n == G.UIT.R then
super_func(self, index, PB.C({ v }))
elseif self.pb_config.rc_fix_target == G.UIT.R and (v.n == G.UIT.C or v.n == G.UIT.O) then
super_func(self, index, PB.R({ v }))
else
super_func(self, index, v)
end
end
PB.ROOT = PaintBrush.extend(PaintBrush.uit_function("ROOT"), {
process_node = default_rc_process,
})
PB.C = PaintBrush.extend(PaintBrush.uit_function("C"), {
process_node = default_rc_process,
})
PB.R = PaintBrush.extend(PaintBrush.uit_function("R"), {
process_node = default_rc_process,
})
PB.O = PaintBrush.extend(PaintBrush.uit_function("O"), {
process_node = function(self, super_func, index, v)
if self.config.object then
self.config.object:remove()
end
self.config.object = v
end,
})
PB.T = PaintBrush.extend(PaintBrush.uit_function("T"), {
process_node = function(self, super_func, index, v)
self.config.text = (self.config.text or "") .. (v or "")
end,
})
PB.B = PaintBrush.extend(PaintBrush.uit_function("B"), {
process_node = function(self, super_func, index, v) end,
})
PB.LOC_TEXT = PaintBrush.extend(PB.C, {
process_config = function(self, super_func, k, v)
if k == "loc_box_config" or k == "row_config" then
self.pb_config[k] = SMODS.merge_defaults(v or {}, self.pb_config[k] or {})
else
super_func(self, k, v)
end
end,
process_node = function(self, super_func, k, v)
if (type(v) == "table" and v.n) or (v.is and v:is(Moveable)) then
super_func(self, k, v)
else
local line = type(v) == "string" and loc_parse_string(v) or v
local box_config = SMODS.merge_defaults(self.pb_config.loc_box_config or {}, {
vars = {},
default_col = G.C.UI.TEXT_LIGHT,
})
super_func(
self,
k,
PB.R({ config = self.pb_config.row_config, nodes = SMODS.localize_box(line, box_config) })
)
end
end,
})
PB.LOC_MULTIBOX = PaintBrush.extend(PB.C, {
no_flat_children = true,
process_config = function(self, super_func, k, v)
if k == "multi_box_config" or k == "loc_box_config" or k == "row_config" or k == "loc_text_config" then
self.pb_config[k] = SMODS.merge_defaults(v or {}, self.pb_config[k] or {})
else
super_func(self, k, v)
end
end,
process_node = function(self, super_func, k, v)
if (type(v) == "table" and v.n) or (v.is and v:is(Moveable)) then
super_func(self, k, v)
else
if type(v) == "string" then
v = { v }
end
super_func(
self,
k,
PB.R({
config = self.pb_config.multi_box_config,
PB.LOC_TEXT({
config = self.pb_config.loc_text_config,
loc_box_config = self.pb_config.loc_box_config,
row_config = self.pb_config.row_config,
v,
}),
})
)
end
end,
})
PB.CENTER_INFO = PaintBrush.extend(PB.C, {
no_flat_children = true,
process_node = function(self, super_func, k, v)
local center = type(v) == "string" and G.P_CENTERS[v] or v
local fake_card = center:create_fake_card()
local AUT = generate_card_ui(center)
local info = { AUT.main }
if AUT.multi_box then
for _, multi in ipairs(AUT.multi_box) do
info[#info + 1] = multi
end
end
super_func(
self,
k,
PB.R({
config = { align = "cm", padding = 0.07, r = 0.1 },
name_from_rows(AUT.name),
SMODS.get_multi_boxes(info),
})
)
end,
})
PB.CENTER_INFO_QUEUE = PaintBrush.extend(PB.C, {
no_flat_children = true,
process_node = function(self, super_func, k, v)
local center = type(v) == "string" and G.P_CENTERS[v] or v
local fake_card = center:create_fake_card()
fake_card.T = {
x = 0,
y = 0,
w = 0,
h = 0,
}
fake_card.config = {
center_key = center.key,
center = center,
}
fake_card.ability_UIBox_table = generate_card_ui(center)
local popup = G.UIDEF.card_h_popup(fake_card)
-- local info_queue_container = table.remove(popup.nodes, 1)
-- local AUT = generate_card_ui(center)
-- print(AUT)
-- local info_boxes = {}
-- for k, v in ipairs(AUT.info) do
-- info_boxes[#info_boxes + 1] = {
-- n = G.UIT.R,
-- config = { align = "cm" },
-- nodes = {
-- {
-- n = G.UIT.R,
-- config = {
-- align = "cm",
-- colour = lighten(G.C.JOKER_GREY, 0.5),
-- r = 0.1,
-- padding = 0.05,
-- emboss = 0.05,
-- },
-- nodes = {
-- info_tip_from_rows(v, v.name),
-- },
-- },
-- },
-- }
-- end
super_func(self, k, popup.nodes[1].nodes[1])
end,
})
--
local test = PB.C({
align = "cm",
padding = 0.1,
pb_config = {
rc_fix_target = G.UIT.R or G.UIT.C or false,
-- init = function(node, element)
-- -- element here fully alive so you can set some variables
-- element.states.collide.can = true
-- element.states.click.can = true
-- end,
-- remove = function(node, element, super_func) end,
-- update = function(node, element, super_func, dt)
-- print("before update")
-- super_func(element, dt)
-- print("after update")
-- end,
-- click = function(node, element, super_func)
-- print("before click")
-- super_func(element)
-- print("after click")
-- end,
-- hover = function(node, element, super_func) end,
-- stop_hover = function(node, element, super_func) end,
-- drag = function(node, element, super_func) end,
-- stop_drag = function(node, element, super_func) end,
},
-- PB.R({
-- class = "box_title",
-- PB.T({ "Hello new UI!", class = "config_title" }, { " And more!", colour = G.C.CHIPS }),
-- }),
-- PB.R({
-- align = "cm",
-- PB.T({ text = "Welcome you here!", class = "config_subtitle" }),
-- }),
-- this
-- PB.R({ align = "cm" })({ colour = G.C.MULT })({ r = 0.1 })({ PB.C() }),
-- same as
-- PB.R({
-- align = "cm",
-- colour = G.C.MULT,
-- r = 0.1,
-- PB.C(),
-- }),
PB.R({
padding = 0.1,
colour = G.C.BLACK,
PB.C({
PB.CENTER_INFO_QUEUE({
"j_phanta_profile",
}),
}),
-- PB.LOC_MULTIBOX({
-- padding = 0.1,
-- multi_box_config = {
-- padding = 0.1,
-- colour = { 0, 0, 0, 0.1 },
-- outline = 1,
-- outline_colour = G.C.WHITE,
-- align = "cm",
-- },
-- loc_text_config = {
-- colour = adjust_alpha(G.C.CHIPS, 0.5),
-- },
-- row_config = {
-- align = "cm",
-- },
-- loc_box_config = {
-- vars = { "Aboba" },
-- },
-- {
-- "Centered {C:edition}edition{}",
-- "Centered #1#",
-- },
-- }, {
-- multi_box_config = {
-- outline_colour = G.C.MULT,
-- },
-- {
-- "Centered {C:attention}attention{}",
-- "Centered {C:attention}info{}",
-- },
-- }),
-- {
-- PB.C({
-- PB.T({ class = "config_list_point" }),
-- PB.T({ class = "config_line", "Hello!" }),
-- }),
-- PB.R({
-- PB.T({ class = "config_list_point", id = "aboba" }),
-- PB.T({ class = "config_line", "Hello Again!", "I love You!" }),
-- }),
-- },
}),
})
-- test:print_topology()
return PB.ROOT({
colour = G.C.CLEAR,
test,
pb_config = {
init = function(node, element)
print("element created")
end,
},
})