-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaderghdhggfdasdasd
3793 lines (3043 loc) · 163 KB
/
aderghdhggfdasdasd
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--// CUSTOM DRAWING
local drawing = {} do
local services = setmetatable({}, {
__index = function(self, key)
if key == "InputService" then
key = "UserInputService"
end
if not rawget(self, key) then
local service = game:GetService(key)
rawset(self, service, service)
return service
end
return rawget(self, key)
end
})
-- taken from Nevermore Engine https://github.com/Quenty/NevermoreEngine/tree/main/src
local HttpService = game:GetService("HttpService")
local ENABLE_TRACEBACK = false
local Signal = {}
Signal.__index = Signal
Signal.ClassName = "Signal"
--[=[
Returns whether a class is a signal
@param value any
@return boolean
]=]
function Signal.isSignal(value)
return type(value) == "table"
and getmetatable(value) == Signal
end
--[=[
Constructs a new signal.
@return Signal<T>
]=]
function Signal.new()
local self = setmetatable({}, Signal)
self._bindableEvent = Instance.new("BindableEvent")
self._argMap = {}
self._source = ENABLE_TRACEBACK and debug.traceback() or ""
-- Events in Roblox execute in reverse order as they are stored in a linked list and
-- new connections are added at the head. This event will be at the tail of the list to
-- clean up memory.
self._bindableEvent.Event:Connect(function(key)
self._argMap[key] = nil
-- We've been destroyed here and there's nothing left in flight.
-- Let's remove the argmap too.
-- This code may be slower than leaving this table allocated.
if (not self._bindableEvent) and (not next(self._argMap)) then
self._argMap = nil
end
end)
return self
end
--[=[
Fire the event with the given arguments. All handlers will be invoked. Handlers follow
@param ... T -- Variable arguments to pass to handler
]=]
function Signal:Fire(...)
if not self._bindableEvent then
warn(("Signal is already destroyed. %s"):format(self._source))
return
end
local args = table.pack(...)
-- TODO: Replace with a less memory/computationally expensive key generation scheme
local key = HttpService:GenerateGUID(false)
self._argMap[key] = args
-- Queues each handler onto the queue.
self._bindableEvent:Fire(key)
end
--[=[
Connect a new handler to the event. Returns a connection object that can be disconnected.
@param handler (... T) -> () -- Function handler called when `:Fire(...)` is called
@return RBXScriptConnection
]=]
function Signal:Connect(handler)
if not (type(handler) == "function") then
error(("connect(%s)"):format(typeof(handler)), 2)
end
return self._bindableEvent.Event:Connect(function(key)
-- note we could queue multiple events here, but we'll do this just as Roblox events expect
-- to behave.
local args = self._argMap[key]
if args then
handler(table.unpack(args, 1, args.n))
else
error("Missing arg data, probably due to reentrance.")
end
end)
end
--[=[
Wait for fire to be called, and return the arguments it was given.
@yields
@return T
]=]
function Signal:Wait()
local key = self._bindableEvent.Event:Wait()
local args = self._argMap[key]
if args then
return table.unpack(args, 1, args.n)
else
error("Missing arg data, probably due to reentrance.")
return nil
end
end
--[=[
Disconnects all connected events to the signal. Voids the signal as unusable.
Sets the metatable to nil.
]=]
function Signal:Destroy()
if self._bindableEvent then
-- This should disconnect all events, but in-flight events should still be
-- executed.
self._bindableEvent:Destroy()
self._bindableEvent = nil
end
-- Do not remove the argmap. It will be cleaned up by the cleanup connection.
setmetatable(self, nil)
end
local signal = Signal
local function ismouseover(obj)
local posX, posY = obj.Position.X, obj.Position.Y
local sizeX, sizeY = posX + obj.Size.X, posY + obj.Size.Y
local mousepos = services.InputService:GetMouseLocation()
if mousepos.X >= posX and mousepos.Y >= posY and mousepos.X <= sizeX and mousepos.Y <= sizeY then
return true
end
return false
end
local function udim2tovector2(udim2, vec2)
local xscalevector2 = vec2.X * udim2.X.Scale
local yscalevector2 = vec2.Y * udim2.Y.Scale
local newvec2 = Vector2.new(xscalevector2 + udim2.X.Offset, yscalevector2 + udim2.Y.Offset)
return newvec2
end
-- totally not skidded from devforum (trust)
local function istouching(pos1, size1, pos2, size2)
local top = pos2.Y - pos1.Y
local bottom = pos2.Y + size2.Y - (pos1.Y + size1.Y)
local left = pos2.X - pos1.X
local right = pos2.X + size2.X - (pos1.X + size1.X)
local touching = true
if top > 0 then
touching = false
elseif bottom < 0 then
touching = false
elseif left > 0 then
touching = false
elseif right < 0 then
touching = false
end
return touching
end
local objchildren = {}
local objmts = {}
local objvisibles = {}
local mtobjs = {}
local udim2posobjs = {}
local udim2sizeobjs = {}
local objpositions = {}
local listobjs = {}
local listcontents = {}
local listchildren = {}
local listadds = {}
local objpaddings = {}
local scrollobjs = {}
local listindexes = {}
local custompropertysets = {}
local custompropertygets = {}
local objconnections = {}
local objmtchildren = {}
local scrollpositions = {}
local currentcanvasposobjs = {}
local childrenposupdates = {}
local childrenvisupdates = {}
local squares = {}
local objsignals = {}
local objexists = {}
local function mouseoverhighersquare(obj)
for _, square in next, squares do
if square.Visible == true and square.ZIndex > obj.ZIndex then
if ismouseover(square) then
return true
end
end
end
end
services.InputService.InputEnded:Connect(function(input, gpe)
for obj, signals in next, objsignals do
if objexists[obj] then
if signals.inputbegan[input] then
signals.inputbegan[input] = false
if signals.InputEnded then
signals.InputEnded:Fire(input, gpe)
end
end
if obj.Visible then
if ismouseover(obj) then
if input.UserInputType == Enum.UserInputType.MouseButton1 and not mouseoverhighersquare(obj) then
if signals.MouseButton1Up then
signals.MouseButton1Up:Fire()
end
if signals.mouse1down and signals.MouseButton1Click then
signals.mouse1down = false
signals.MouseButton1Click:Fire()
end
end
if input.UserInputType == Enum.UserInputType.MouseButton2 and not mouseoverhighersquare(obj) then
if signals.MouseButton2Clicked then
signals.MouseButton2Clicked:Fire()
end
if signals.MouseButton2Up then
signals.MouseButton2Up:Fire()
end
end
end
end
end
end
end)
services.InputService.InputChanged:Connect(function(input, gpe)
for obj, signals in next, objsignals do
if objexists[obj] and obj.Visible and (signals.MouseEnter or signals.MouseMove or signals.InputChanged or signals.MouseLeave) then
if ismouseover(obj) then
if not signals.mouseentered then
signals.mouseentered = true
if signals.MouseEnter then
signals.MouseEnter:Fire(input.Position)
end
if signals.MouseMoved then
signals.MouseMoved:Fire(input.Position)
end
end
if signals.InputChanged then
signals.InputChanged:Fire(input, gpe)
end
elseif signals.mouseentered then
signals.mouseentered = false
if signals.MouseLeave then
signals.MouseLeave:Fire(input.Position)
end
end
end
end
end)
services.InputService.InputBegan:Connect(function(input, gpe)
for obj, signals in next, objsignals do
if objexists[obj] then
if obj.Visible then
if ismouseover(obj) and not mouseoverhighersquare(obj) then
signals.inputbegan[input] = true
if signals.InputBegan then
signals.InputBegan:Fire(input, gpe)
end
if input.UserInputType == Enum.UserInputType.MouseButton1 and (not mouseoverhighersquare(obj) or obj.Transparency == 0) then
signals.mouse1down = true
if signals.MouseButton1Down then
signals.MouseButton1Down:Fire()
end
end
if input.UserInputType == Enum.UserInputType.MouseButton2 and (not mouseoverhighersquare(obj) or obj.Transparency == 0) then
if signals.MouseButton2Down then
signals.MouseButton2Down:Fire()
end
end
end
end
end
end
end)
function drawing:new(shape)
local obj = Drawing.new(shape)
objexists[obj] = true
local signalnames = {}
local listfunc
local scrollfunc
local refreshscrolling
objconnections[obj] = {}
if shape == "Square" then
table.insert(squares, obj)
signalnames = {
MouseButton1Click = signal.new(),
MouseButton1Up = signal.new(),
MouseButton1Down = signal.new(),
MouseButton2Click = signal.new(),
MouseButton2Up = signal.new(),
MouseButton2Down = signal.new(),
InputBegan = signal.new(),
InputEnded = signal.new(),
InputChanged = signal.new(),
MouseEnter = signal.new(),
MouseLeave = signal.new(),
MouseMoved = signal.new()
}
local attemptedscrollable = false
scrollfunc = function(self)
if listobjs[self] then
scrollpositions[self] = 0
scrollobjs[self] = true
self.ClipsDescendants = true
local function scroll(amount)
local totalclippedobjs, currentclippedobj, docontinue = 0, nil, false
for i, object in next, listchildren[self] do
if amount == 1 then
if object.Position.Y > mtobjs[self].Position.Y then
if not istouching(object.Position, object.Size, mtobjs[self].Position, mtobjs[self].Size) then
if not currentclippedobj then
currentclippedobj = object
end
totalclippedobjs = totalclippedobjs + 1
docontinue = true
end
end
end
if amount == -1 then
if object.Position.Y <= mtobjs[self].Position.Y then
if not istouching(object.Position, object.Size, mtobjs[self].Position, mtobjs[self].Size) then
currentclippedobj = object
totalclippedobjs = totalclippedobjs + 1
docontinue = true
end
end
end
end
if docontinue then
if amount > 0 then
local poschange = -(currentclippedobj.Size.Y + objpaddings[self])
local closestobj
for i, object in next, objchildren[self] do
if istouching(object.Position + Vector2.new(0, poschange), object.Size, mtobjs[self].Position, mtobjs[self].Size) then
closestobj = object
break
end
end
local diff = (Vector2.new(0, mtobjs[self].Position.Y) - Vector2.new(0, (closestobj.Position.Y + poschange + objpaddings[self]))).magnitude
if custompropertygets[mtobjs[self]]("ClipsDescendants") then
for i, object in next, objchildren[self] do
if not istouching(object.Position + Vector2.new(0, poschange - diff + objpaddings[self]), object.Size, mtobjs[self].Position, mtobjs[self].Size) then
object.Visible = false
childrenvisupdates[objmts[object]](objmts[object], false)
else
object.Visible = true
childrenvisupdates[objmts[object]](objmts[object], true)
end
end
end
scrollpositions[self] = scrollpositions[self] + (poschange - diff + objpaddings[self])
for i, object in next, objchildren[self] do
childrenposupdates[objmts[object]](objmts[object], object.Position + Vector2.new(0, poschange - diff + objpaddings[self]))
object.Position = object.Position + Vector2.new(0, poschange - diff + objpaddings[self])
end
else
local poschange = currentclippedobj.Size.Y + objpaddings[self]
if custompropertygets[mtobjs[self]]("ClipsDescendants") then
for i, object in next, objchildren[self] do
if not istouching(object.Position + Vector2.new(0, poschange), object.Size, mtobjs[self].Position, mtobjs[self].Size) then
object.Visible = false
childrenvisupdates[objmts[object]](objmts[object], false)
else
object.Visible = true
childrenvisupdates[objmts[object]](objmts[object], true)
end
end
end
scrollpositions[self] = scrollpositions[self] + poschange
for i, object in next, objchildren[self] do
childrenposupdates[objmts[object]](objmts[object], object.Position + Vector2.new(0, poschange))
object.Position = object.Position + Vector2.new(0, poschange)
end
end
end
return docontinue
end
refreshscrolling = function()
repeat
until
not scroll(-1)
end
self.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseWheel then
if input.Position.Z > 0 then
scroll(-1)
else
scroll(1)
end
end
end)
else
attemptedscrollable = true
end
end
listfunc = function(self, padding)
objpaddings[self] = padding
listcontents[self] = 0
listchildren[self] = {}
listindexes[self] = {}
listadds[self] = {}
listobjs[self] = true
for i, object in next, objchildren[self] do
table.insert(listchildren[self], object)
table.insert(listindexes[self], listcontents[self] + (#listchildren[self] == 1 and 0 or padding))
local newpos = mtobjs[self].Position + Vector2.new(0, listcontents[self] + (#listchildren[self] == 1 and 0 or padding))
object.Position = newpos
childrenposupdates[object](objmts[object], newpos)
custompropertysets[object]("AbsolutePosition", newpos)
listadds[self][object] = object.Size.Y + (#listchildren[self] == 1 and 0 or padding)
listcontents[self] = listcontents[self] + object.Size.Y + (#listchildren[self] == 1 and 0 or padding)
end
if attemptedscrollable then
scrollfunc(self)
end
end
end
local customproperties = {
Parent = nil,
AbsolutePosition = nil,
AbsoluteSize = nil,
ClipsDescendants = false
}
custompropertysets[obj] = function(k, v)
customproperties[k] = v
end
custompropertygets[obj] = function(k)
return customproperties[k]
end
local mt = setmetatable({exists = true}, {
__index = function(self, k)
if k == "Parent" then
return customproperties.Parent
end
if k == "Visible" then
return objvisibles[obj]
end
if k == "Position" then
return udim2posobjs[obj] or objpositions[obj] or obj[k]
end
if k == "Size" then
return udim2sizeobjs[obj] or obj[k]
end
if k == "AddListLayout" and listfunc then
return listfunc
end
if k == "MakeScrollable" and scrollfunc then
return scrollfunc
end
if k == "RefreshScrolling" and refreshscrolling then
return refreshscrolling
end
if k == "AbsoluteContentSize" then
return listcontents[self]
end
if k == "GetChildren" then
return function(self)
return objmtchildren[self]
end
end
if k == "Remove" then
return function(self)
rawset(self, "exists", false)
objexists[obj] = false
if customproperties.Parent and listobjs[customproperties.Parent] then
local objindex = table.find(objchildren[customproperties.Parent], obj)
listcontents[customproperties.Parent] = listcontents[customproperties.Parent] - listadds[customproperties.Parent][obj]
for i, object in next, objchildren[customproperties.Parent] do
if i > objindex then
object.Position = object.Position - Vector2.new(0, listadds[customproperties.Parent][obj])
end
end
if table.find(listchildren[customproperties.Parent], obj) then
table.remove(listchildren[customproperties.Parent], table.find(listchildren[customproperties.Parent], obj))
end
if table.find(objchildren[customproperties.Parent], obj) then
table.remove(objchildren[customproperties.Parent], table.find(objchildren[customproperties.Parent], obj))
table.remove(listindexes[customproperties.Parent], table.find(objchildren[customproperties.Parent], obj))
end
end
if table.find(squares, mtobjs[self]) then
table.remove(squares, table.find(squares, mtobjs[self]))
end
for _, object in next, objchildren[self] do
if objexists[object] then
table.remove(objsignals, table.find(objsignals, object))
objmts[object]:Remove()
end
end
table.remove(objsignals, table.find(objsignals, obj))
obj:Remove()
end
end
if signalnames and signalnames[k] then
objsignals[obj] = objsignals[obj] or {}
if not objsignals[obj][k] then
objsignals[obj][k] = signalnames[k]
end
objsignals[obj].inputbegan = objsignals[obj].inputbegan or {}
objsignals[obj].mouseentered = objsignals[obj].mouseentered or {}
objsignals[obj].mouse1down = objsignals[obj].mouse1down or {}
return signalnames[k]
end
return customproperties[k] or obj[k]
end,
__newindex = function(self, k, v)
local changechildrenvis
changechildrenvis = function(parent, vis)
if objchildren[parent] then
for _, object in next, objchildren[parent] do
if (custompropertygets[mtobjs[parent]]("ClipsDescendants") and not istouching(object.Position, object.Size, mtobjs[parent].Position, mtobjs[parent].Size)) then
object.Visible = false
changechildrenvis(objmts[object], false)
else
object.Visible = vis and objvisibles[object] or false
changechildrenvis(objmts[object], vis and objvisibles[object] or false)
end
end
end
end
childrenvisupdates[self] = changechildrenvis
if k == "Visible" then
objvisibles[obj] = v
if customproperties.Parent and (not mtobjs[customproperties.Parent].Visible or (custompropertygets[mtobjs[customproperties.Parent]]("ClipsDescendants") and not istouching(obj.Position, obj.Size, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size))) then
v = false
changechildrenvis(self, v)
else
changechildrenvis(self, v)
end
end
if k == "ClipsDescendants" then
customproperties.ClipsDescendants = v
for _, object in next, objchildren[self] do
object.Visible = v and (istouching(object.Position, object.Size, obj.Position, obj.Size) and objvisibles[object] or false) or objvisibles[object]
end
return
end
local changechildrenpos
changechildrenpos = function(parent, val)
if objchildren[parent] then
if listobjs[parent] then
for i, object in next, objchildren[parent] do
local newpos = val + Vector2.new(0, listindexes[parent][i])
if scrollobjs[parent] then
newpos = val + Vector2.new(0, listindexes[parent][i] + scrollpositions[parent])
end
newpos = Vector2.new(math.floor(newpos.X), math.floor(newpos.Y))
object.Position = newpos
custompropertysets[object]("AbsolutePosition", newpos)
changechildrenpos(objmts[object], newpos)
end
else
for _, object in next, objchildren[parent] do
local newpos = val + objpositions[object]
newpos = Vector2.new(math.floor(newpos.X), math.floor(newpos.Y))
object.Position = newpos
custompropertysets[object]("AbsolutePosition", newpos)
changechildrenpos(objmts[object], newpos)
end
end
end
end
childrenposupdates[self] = changechildrenpos
if k == "Position" then
if typeof(v) == "UDim2" then
udim2posobjs[obj] = v
if customproperties.Parent then
objpositions[obj] = udim2tovector2(v, mtobjs[customproperties.Parent].Size)
if listobjs[customproperties.Parent] then
return
else
v = mtobjs[customproperties.Parent].Position + udim2tovector2(v, mtobjs[customproperties.Parent].Size)
end
else
local newpos = udim2tovector2(v, workspace.CurrentCamera.ViewportSize)
objpositions[obj] = newpos
v = udim2tovector2(v, workspace.CurrentCamera.ViewportSize)
end
customproperties.AbsolutePosition = v
if customproperties.Parent and custompropertygets[mtobjs[customproperties.Parent]]("ClipsDescendants") then
obj.Visible = istouching(v, obj.Size, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false
changechildrenvis(self, istouching(v, obj.Size, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false)
end
changechildrenpos(self, v)
else
objpositions[obj] = v
if customproperties.Parent then
if listobjs[customproperties.Parent] then
return
else
v = mtobjs[customproperties.Parent].Position + v
end
end
customproperties.AbsolutePosition = v
if customproperties.Parent and custompropertygets[mtobjs[customproperties.Parent]]("ClipsDescendants") then
obj.Visible = istouching(v, obj.Size, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false
changechildrenvis(self, istouching(v, obj.Size, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false)
end
changechildrenpos(self, v)
end
v = v
end
local changechildrenudim2pos
changechildrenudim2pos = function(parent, val)
if objchildren[parent] and not listobjs[parent] then
for _, object in next, objchildren[parent] do
if udim2posobjs[object] then
local newpos = mtobjs[parent].Position + udim2tovector2(udim2posobjs[object], val)
newpos = Vector2.new(math.floor(newpos.X), math.floor(newpos.Y))
if not listobjs[parent] then
object.Position = newpos
end
custompropertysets[object]("AbsolutePosition", newpos)
objpositions[object] = udim2tovector2(udim2posobjs[object], val)
changechildrenpos(objmts[object], newpos)
end
end
end
end
local changechildrenudim2size
changechildrenudim2size = function(parent, val)
if objchildren[parent] then
for _, object in next, objchildren[parent] do
if udim2sizeobjs[object] then
local newsize = udim2tovector2(udim2sizeobjs[object], val)
object.Size = newsize
if custompropertygets[mtobjs[parent]]("ClipsDescendants") then
object.Visible = istouching(object.Position, object.Size, mtobjs[parent].Position, mtobjs[parent].Size) and objvisibles[object] or false
end
custompropertysets[object]("AbsoluteSize", newsize)
changechildrenudim2size(objmts[object], newsize)
changechildrenudim2pos(objmts[object], newsize)
end
end
end
end
if k == "Size" then
if typeof(v) == "UDim2" then
udim2sizeobjs[obj] = v
if customproperties.Parent then
v = udim2tovector2(v, mtobjs[customproperties.Parent].Size)
else
v = udim2tovector2(v, workspace.CurrentCamera.ViewportSize)
end
if customproperties.Parent and listobjs[customproperties.Parent] then
local oldsize = obj.Size.Y
local sizediff = v.Y - oldsize
local objindex = table.find(objchildren[customproperties.Parent], obj)
listcontents[customproperties.Parent] = listcontents[customproperties.Parent] + sizediff
listadds[customproperties.Parent][obj] = listadds[customproperties.Parent][obj] + sizediff
for i, object in next, objchildren[customproperties.Parent] do
if i > objindex then
object.Position = object.Position + Vector2.new(0, sizediff)
listindexes[customproperties.Parent][i] = listindexes[customproperties.Parent][i] + sizediff
end
end
end
customproperties.AbsoluteSize = v
changechildrenudim2size(self, v)
changechildrenudim2pos(self, v)
if customproperties.ClipsDescendants then
for _, object in next, objchildren[self] do
object.Visible = istouching(object.Position, object.Size, obj.Position, v) and objvisibles[object] or false
end
end
if customproperties.Parent and custompropertygets[mtobjs[customproperties.Parent]]("ClipsDescendants") then
obj.Visible = istouching(obj.Position, v, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false
changechildrenvis(self, istouching(obj.Position, v, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false)
end
else
if customproperties.Parent and listobjs[customproperties.Parent] then
local oldsize = obj.Size.Y
local sizediff = v.Y - oldsize
local objindex = table.find(objchildren[customproperties.Parent], obj)
listcontents[customproperties.Parent] = listcontents[customproperties.Parent] + sizediff
listadds[customproperties.Parent][obj] = listadds[customproperties.Parent][obj] + sizediff
for i, object in next, objchildren[customproperties.Parent] do
if i > objindex then
object.Position = object.Position + Vector2.new(0, sizediff)
listcontents[customproperties.Parent] = listcontents[customproperties.Parent] + sizediff
listindexes[customproperties.Parent][i] = listindexes[customproperties.Parent][i] + sizediff
end
end
end
customproperties.AbsoluteSize = v
changechildrenudim2size(self, v)
changechildrenudim2pos(self, v)
if customproperties.ClipsDescendants then
for _, object in next, objchildren[self] do
object.Visible = istouching(object.Position, object.Size, obj.Position, v) and objvisibles[object] or false
end
end
if customproperties.Parent and custompropertygets[mtobjs[customproperties.Parent]]("ClipsDescendants") then
obj.Visible = istouching(obj.Position, v, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false
changechildrenvis(self, istouching(obj.Position, v, mtobjs[customproperties.Parent].Position, mtobjs[customproperties.Parent].Size) and objvisibles[obj] or false)
end
end
if typeof(v) == "Vector2" then
v = Vector2.new(math.floor(v.X), math.floor(v.Y))
end
end
if k == "Parent" then
assert(type(v) == "table", "Invalid type " .. type(v) .. " for parent")
table.insert(objchildren[v], obj)
table.insert(objmtchildren[v], self)
changechildrenvis(v, mtobjs[v].Visible)
if udim2sizeobjs[obj] then
local newsize = udim2tovector2(udim2sizeobjs[obj], mtobjs[v].Size)
obj.Size = newsize
if custompropertygets[mtobjs[v]]("ClipsDescendants") then
obj.Visible = istouching(obj.Position, newsize, mtobjs[v].Position, mtobjs[v].Size) and objvisibles[obj] or false
end
changechildrenudim2pos(self, newsize)
end
if listobjs[v] then
table.insert(listchildren[v], obj)
table.insert(listindexes[v], listcontents[v] + (#listchildren[v] == 1 and 0 or objpaddings[v]))
local newpos = Vector2.new(0, listcontents[v] + (#listchildren[v] == 1 and 0 or objpaddings[v]))
if scrollobjs[v] then
newpos = Vector2.new(0, listcontents[v] + (#listchildren[v] == 1 and 0 or objpaddings[v]) + scrollpositions[v])
end
listadds[v][obj] = obj.Size.Y + (#listchildren[v] == 1 and 0 or objpaddings[v])
listcontents[v] = listcontents[v] + obj.Size.Y + (#listchildren[v] == 1 and 0 or objpaddings[v])
obj.Position = newpos
customproperties.AbsolutePosition = newpos
changechildrenpos(self, newpos)
end
if udim2posobjs[obj] then
local newpos = mtobjs[v].Position + udim2tovector2(udim2posobjs[obj], mtobjs[v].Size)
objpositions[obj] = udim2tovector2(udim2posobjs[obj], mtobjs[v].Size)
obj.Position = newpos
customproperties.AbsolutePosition = newpos
if custompropertygets[mtobjs[v]]("ClipsDescendants") then
obj.Visible = istouching(newpos, obj.Size, mtobjs[v].Position, mtobjs[v].Size) and objvisibles[obj] or false
end
changechildrenpos(self, newpos)
elseif shape ~= "Line" and shape ~= "Quad" and shape ~= "Triangle" then
local newpos = mtobjs[v].Position + obj.Position
obj.Position = newpos
customproperties.AbsolutePosition = newpos
if custompropertygets[mtobjs[v]]("ClipsDescendants") then
obj.Visible = istouching(newpos, obj.Size, mtobjs[v].Position, mtobjs[v].Size) and objvisibles[obj] or false
end
changechildrenpos(self, newpos)
end
if custompropertygets[mtobjs[v]]("ClipsDescendants") then
obj.Visible = istouching(obj.Position, obj.Size, mtobjs[v].Position, mtobjs[v].Size) and objvisibles[obj] or false
end
customproperties.Parent = v
return
end
obj[k] = v
end
})
objmts[obj] = mt
mtobjs[mt] = obj
objchildren[mt] = {}
objmtchildren[mt] = {}
if shape ~= "Line" and shape ~= "Quad" and shape ~= "Triangle" then
mt.Position = Vector2.new(0, 0)
end
mt.Visible = true
return mt
end
end
-- // UI LIBRARY
local services = setmetatable({}, {
__index = function(_, k)
k = (k == "InputService" and "UserInputService") or k
return game:GetService(k)
end
})
local client = services.Players.LocalPlayer
local utility = {}
function utility.dragify(object, dragoutline)
local start, objectposition, dragging, currentpos
object.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
dragging = true
start = input.Position
dragoutline.Visible = true
objectposition = object.Position
end
end)
utility.connect(services.InputService.InputChanged, function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and dragging then
currentpos = UDim2.new(objectposition.X.Scale, objectposition.X.Offset + (input.Position - start).X, objectposition.Y.Scale, objectposition.Y.Offset + (input.Position - start).Y)
dragoutline.Position = currentpos
end
end)
utility.connect(services.InputService.InputEnded, function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and dragging then
dragging = false
dragoutline.Visible = false
object.Position = currentpos
end
end)
end
function utility.textlength(str, font, fontsize)
local text = Drawing.new("Text")
text.Text = str
text.Font = font
text.Size = fontsize
local textbounds = text.TextBounds