Repository navigation
Expand file tree
/
Copy pathframework_v3.lua
More file actions
1486 lines (1358 loc) · 42.5 KB
/
Copy pathframework_v3.lua
File metadata and controls
1486 lines (1358 loc) · 42.5 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
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
-- VBL GUI Framework v2 (simple)
-- Plain, reliable GUI: flat rounded windows with a title bar, minimize/close,
-- drag support. Notifications use Roblox's built-in SetCore notifications.
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local pg = Players.LocalPlayer:WaitForChild("PlayerGui")
local GUI = {}
GUI.Version = "1.1.0"
GUI.Log = function() end
local function normalizeAssetURL(s)
if type(s) ~= "string" or s == "" then return s end
local id = s:match("asset/?%?id=(%d+)")
if id then
return "rbxassetid://" .. id
end
return s
end
GUI.Theme = {
bg = Color3.fromRGB(12, 12, 16),
panel = Color3.fromRGB(20, 20, 25),
elevated = Color3.fromRGB(40, 40, 50),
border = Color3.fromRGB(38, 43, 56),
text = Color3.fromRGB(230, 233, 240),
dim = Color3.fromRGB(150, 150, 160),
accent = Color3.fromRGB(96, 148, 255),
success = Color3.fromRGB(60, 160, 90),
warn = Color3.fromRGB(240, 180, 70),
danger = Color3.fromRGB(190, 70, 70),
input = Color3.fromRGB(12, 12, 16),
surface = Color3.fromRGB(30, 30, 38),
hover = Color3.fromRGB(45, 48, 58),
disabled = Color3.fromRGB(25, 26, 32),
shadow = Color3.fromRGB(8, 8, 12),
focus = Color3.fromRGB(130, 170, 255),
surfaceHover = Color3.fromRGB(40, 42, 52),
}
-- ---------- theme helpers ----------
local function isColor3(v)
if type(v) == "userdata" then
local ok = pcall(function()
local r, g, b = v.R, v.G, v.B
if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then
error("not a Color3", 0)
end
end)
return ok
end
if type(v) == "table" then
return type(v.R) == "number" and type(v.G) == "number" and type(v.B) == "number"
end
return false
end
function GUI.Token(name, fallback)
local v = GUI.Theme[name]
if isColor3(v) then return v end
if fallback ~= nil then return fallback end
return GUI.Theme.panel
end
function GUI.hoverColor(base)
local ok, result = pcall(function()
if not isColor3(base) then
return GUI.Theme.hover
end
return base:Lerp(Color3.new(1, 1, 1), 0.18)
end)
if ok and isColor3(result) then
return result
end
return GUI.Theme.hover
end
local function rounded(inst, r)
local c = Instance.new("UICorner")
c.CornerRadius = UDim.new(0, r or 8)
c.Parent = inst
return c
end
-- ---------- window ----------
function GUI.Window(opts)
opts = opts or {}
local size = opts.size or Vector2.new(280, 220)
local titleText = opts.title or "VBL"
local basePos = opts.position or UDim2.new(0.5, -size.X / 2, 0, opts.y or 30)
local gui = Instance.new("ScreenGui")
gui.Name = opts.name or "VBLWindow"
gui.ResetOnSpawn = false
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
gui.DisplayOrder = 10
gui.Parent = opts.parent or pg
local root = Instance.new("Frame")
root.Name = "Root"
root.Size = UDim2.fromOffset(size.X, size.Y)
root.Position = basePos
root.BackgroundColor3 = GUI.Theme.panel
root.BackgroundTransparency = 1 -- t5: fade-in starts transparent
root.BorderSizePixel = 1
root.BorderColor3 = GUI.Theme.shadow -- t5: soft shadow border (token)
root.Active = true
rounded(root, 10)
root.Parent = gui
local titlebar = Instance.new("Frame")
titlebar.Name = "WinTitlebar" -- t5: named for fade/hover testing
titlebar.Size = UDim2.new(1, 0, 0, 30)
titlebar.BackgroundColor3 = GUI.Theme.elevated
titlebar.BackgroundTransparency = 1 -- t5: fades in with root
titlebar.BorderSizePixel = 0
rounded(titlebar, 10)
titlebar.Parent = root
local titleFix = Instance.new("Frame")
titleFix.Size = UDim2.new(1, 0, 0, 12)
titleFix.Position = UDim2.new(0, 0, 1, -12)
titleFix.BackgroundColor3 = GUI.Theme.elevated
titleFix.BorderSizePixel = 0
titleFix.Parent = titlebar
local titleLabel = Instance.new("TextLabel")
titleLabel.Size = UDim2.new(1, -64, 1, 0)
titleLabel.Position = UDim2.new(0, 12, 0, 0)
titleLabel.BackgroundTransparency = 1
titleLabel.Text = titleText
titleLabel.TextColor3 = GUI.Theme.text
titleLabel.Font = Enum.Font.GothamBold
titleLabel.TextSize = 13
titleLabel.TextXAlignment = Enum.TextXAlignment.Left
titleLabel.Parent = titlebar
local function titleBtn(text, xOff, danger)
local b = Instance.new("TextButton")
b.Size = UDim2.new(0, 24, 0, 22)
b.Position = UDim2.new(1, xOff, 0.5, -11)
local base = danger and GUI.Theme.danger or GUI.Theme.bg
b.BackgroundColor3 = base
b.BorderSizePixel = 0
b.Text = text
b.TextColor3 = Color3.new(1, 1, 1)
b.Font = Enum.Font.GothamBold
b.TextSize = 14
b.AutoButtonColor = false
b.Name = danger and "WinClose" or "WinMin" -- t5: named for hover/consistency
rounded(b, 6)
b.Parent = titlebar
-- t5: titlebar button hover (close → danger family, minimize → hover token)
b.MouseEnter:Connect(function()
GUI.Animate(b, { BackgroundColor3 = danger and GUI.hoverColor(GUI.Theme.danger) or GUI.Theme.hover }, 0.1)
end)
b.MouseLeave:Connect(function()
GUI.Animate(b, { BackgroundColor3 = base }, 0.1)
end)
return b
end
local closeBtn = titleBtn("X", -30, true)
local minBtn = titleBtn("-", -58, false)
local content = Instance.new("Frame")
content.Name = "Content"
content.Size = UDim2.new(1, 0, 1, -30)
content.Position = UDim2.new(0, 0, 0, 30)
content.BackgroundTransparency = 1
content.Parent = root
local logo = Instance.new("TextButton")
logo.Name = "Logo"
logo.Size = UDim2.fromOffset(38, 38)
logo.Position = basePos + UDim2.new(0, 8, 0, 8)
logo.BackgroundColor3 = GUI.Theme.accent
logo.BorderSizePixel = 0
logo.Text = ""
logo.AutoButtonColor = false
logo.Active = true
logo.Visible = false
rounded(logo, 19)
logo.Parent = gui
local logoLabel = Instance.new("TextLabel")
logoLabel.Size = UDim2.new(1, 0, 1, 0)
logoLabel.BackgroundTransparency = 1
logoLabel.Text = opts.icon or "🏐"
logoLabel.TextColor3 = Color3.new(1, 1, 1)
logoLabel.Font = Enum.Font.GothamBold
logoLabel.TextSize = 20
logoLabel.Parent = logo
local window = {
Root = root,
Content = content,
Title = titleLabel,
Gui = gui,
Logo = logo,
_closed = false,
}
local minimized = false
local function setMinimized(min)
minimized = min
root.Visible = not min
logo.Visible = min
if min then
logo.Position = root.Position + UDim2.new(0, 8, 0, 8)
end
end
window.Close = function()
if window._closed then return end
window._closed = true
if opts.OnClose then pcall(opts.OnClose) end
-- t5: fade out first, hide only after fade completes (task.delay guard)
GUI.Animate(root, { BackgroundTransparency = 1 }, 0.12)
GUI.Animate(titlebar, { BackgroundTransparency = 1 }, 0.12)
task.delay(0.12, function()
if window._closed then
root.Visible = false
logo.Visible = false
end
end)
end
window.ToggleMinimize = function() setMinimized(not minimized) end
window.Minimize = function() setMinimized(true) end
window.Restore = function() setMinimized(false) end
window.SetTitle = function(t) titleLabel.Text = t end
closeBtn.MouseButton1Click:Connect(window.Close)
minBtn.MouseButton1Click:Connect(window.ToggleMinimize)
logo.MouseButton1Click:Connect(function()
if not window._closed then
setMinimized(false)
end
end)
local dragging = false
local dragStart, startPos
local logoDragging = false
local logoDragStart, logoStartPos
titlebar.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
dragStart = input.Position
startPos = root.Position
end
end)
titlebar.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.Touch then
dragging = false
end
end)
logo.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.Touch then
logoDragging = true
logoDragStart = input.Position
logoStartPos = logo.Position
end
end)
logo.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.Touch then
logoDragging = false
end
end)
UserInputService.InputChanged:Connect(function(input)
if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement
or input.UserInputType == Enum.UserInputType.Touch) then
local delta = input.Position - dragStart
root.Position = startPos + UDim2.new(0, delta.X, 0, delta.Y)
end
if logoDragging and (input.UserInputType == Enum.UserInputType.MouseMovement
or input.UserInputType == Enum.UserInputType.Touch) then
local delta = input.Position - logoDragStart
logo.Position = logoStartPos + UDim2.new(0, delta.X, 0, delta.Y)
end
end)
-- t5: fade in on open (GUI.Animate pcall-safe; instant-assign when no TweenService)
GUI.Animate(root, { BackgroundTransparency = 0 }, 0.15)
GUI.Animate(titlebar, { BackgroundTransparency = 0 }, 0.15)
return window
end
-- ---------- widgets ----------
function GUI.Button(parent, text, pos, size, opts)
opts = opts or {}
local b = Instance.new("TextButton")
b.Size = size
b.Position = pos
local base = opts.color or GUI.Theme.elevated
b.BackgroundColor3 = base
b.BorderSizePixel = 0
b.Text = text
b.TextColor3 = opts.textColor or GUI.Theme.text
b.Font = Enum.Font.GothamMedium
b.TextSize = opts.textSize or 11
b.AutoButtonColor = false
rounded(b, opts.radius or 6)
b.Parent = parent
-- t4 restyle: hover/press feedback via GUI.Animate (public tween, 0.1s)
-- (local `tween` T2 declared later in the file is lexically out of scope here)
local function setBg(c)
GUI.Animate(b, { BackgroundColor3 = c }, 0.1)
end
local function darkColor()
local dark = nil
local ok = pcall(function()
dark = base:Lerp(Color3.new(0, 0, 0), 0.2)
end)
if not ok or not isColor3(dark) then
dark = GUI.Theme.disabled
end
return dark
end
b.MouseEnter:Connect(function() setBg(GUI.hoverColor(base)) end)
b.MouseLeave:Connect(function() setBg(base) end)
b.MouseButton1Down:Connect(function() setBg(darkColor()) end)
b.MouseButton1Up:Connect(function() setBg(GUI.hoverColor(base)) end)
return b
end
function GUI.Input(parent, default, pos, size, opts)
opts = opts or {}
local b = Instance.new("TextBox")
b.Size = size
b.Position = pos
b.BackgroundColor3 = GUI.Theme.input
b.BorderSizePixel = 0
b.Text = default or ""
b.TextColor3 = GUI.Theme.text
b.PlaceholderText = opts.placeholder or ""
b.PlaceholderColor3 = GUI.Theme.dim
b.Font = Enum.Font.Code
b.TextSize = 11
b.TextXAlignment = Enum.TextXAlignment.Center
b.ClearTextOnFocus = false
rounded(b, 6)
b.Parent = parent
-- t4 restyle: focus border state (GUI.Theme.focus on focus, normal border on blur)
local function setBorder(c, px)
GUI.Animate(b, { BorderColor3 = c, BorderSizePixel = px or 1 }, 0.1)
end
b.Focused:Connect(function() setBorder(GUI.Theme.focus, 1) end)
b.FocusLost:Connect(function() setBorder(GUI.Theme.border, 0) end)
return b
end
function GUI.Label(parent, text, pos, size, opts)
opts = opts or {}
local l = Instance.new("TextLabel")
l.Size = size
l.Position = pos
l.BackgroundTransparency = 1
l.Text = text
l.TextColor3 = opts.color or GUI.Theme.dim
l.Font = opts.font or Enum.Font.Code
l.TextSize = opts.textSize or 11
l.TextXAlignment = opts.align or Enum.TextXAlignment.Left
l.TextWrapped = opts.wrap or false
l.Parent = parent
return l
end
-- ---------- t2: tabs, checkbox, toggle ----------
local function tween(inst, props, dur)
local ok = pcall(function()
local ts = game:GetService("TweenService")
local tw = ts:Create(inst, TweenInfo.new(dur or 0.12), props)
tw:Play()
end)
if not ok then
for k, v in pairs(props) do
inst[k] = v
end
end
end
function GUI.Tabs(opts)
opts = opts or {}
local tabs = opts.tabs or {}
local n = #tabs
local function tabName(t, j)
if type(t) == "table" then return t.name or ("Tab " .. j) end
return tostring(t)
end
local function tabContent(t)
return type(t) == "table" and t.content or nil
end
local size = opts.size or UDim2.new(1, 0, 0, 32)
local root = Instance.new("Frame")
root.Name = "Tabs"
root.Size = size
root.Position = opts.position or UDim2.fromOffset(0, 0)
root.BackgroundTransparency = 1
root.Parent = opts.parent or pg
local bar = Instance.new("Frame")
bar.Name = "Bar"
bar.Size = UDim2.new(1, 0, 0, 32)
bar.BackgroundColor3 = GUI.Theme.surface
bar.BorderSizePixel = 0
rounded(bar, 8)
bar.Parent = root
local content = Instance.new("Frame")
content.Name = "Content"
content.Size = UDim2.new(1, 0, 0, 0)
content.Position = UDim2.new(0, 0, 0, 36)
content.BackgroundTransparency = 1
content.Parent = root
if size.Y and (size.Y.Scale > 0 or size.Y.Offset > 36) then
content.Size = UDim2.new(1, 0, 1, -36)
end
local indicator = Instance.new("Frame")
indicator.Name = "Indicator"
indicator.Size = UDim2.new(1 / math.max(n, 1), 0, 0, 3)
indicator.Position = UDim2.new(0, 0, 1, -3)
indicator.BackgroundColor3 = GUI.Theme.accent
indicator.BorderSizePixel = 0
rounded(indicator, 2)
indicator.Parent = bar
local buttons = {}
local hovered = {}
local current = 1
local api = {}
local function paint(j)
local b = buttons[j]
if not b then return end
local active = (j == current)
b.TextColor3 = active and GUI.Theme.text or GUI.Theme.dim
b.BackgroundColor3 = active and GUI.Theme.surfaceHover or (hovered[j] and GUI.Theme.hover or GUI.Theme.surface)
end
local function selectTab(i)
if n == 0 then return end
if i < 1 then i = 1 elseif i > n then i = n end
if i == current then return end
current = i
api.Selected = i
for j = 1, n do
local c = tabContent(tabs[j])
if c then c.Visible = (j == i) end
paint(j)
end
tween(indicator, {
Size = UDim2.new(1 / n, 0, 0, 3),
Position = UDim2.new((i - 1) / n, 0, 1, -3),
}, 0.15)
local name = tabName(tabs[i], i)
GUI.Log(("[TABS] selected %d: %s"):format(i, tostring(name)))
if opts.onSelect then pcall(opts.onSelect, i, name) end
end
if n > 0 then
for j = 1, n do
local b = Instance.new("TextButton")
b.Name = tabName(tabs[j], j)
b.Size = UDim2.new(1 / n, 0, 1, 0)
b.BackgroundColor3 = GUI.Theme.surface
b.BorderSizePixel = 0
b.Text = tabName(tabs[j], j)
b.TextColor3 = GUI.Theme.dim
b.Font = Enum.Font.GothamMedium
b.TextSize = 12
b.AutoButtonColor = false
rounded(b, 6)
b.Parent = bar
b.MouseButton1Click:Connect(function() selectTab(j) end)
b.MouseEnter:Connect(function()
hovered[j] = true
paint(j)
end)
b.MouseLeave:Connect(function()
hovered[j] = false
paint(j)
end)
buttons[j] = b
end
current = 1
for j = 1, n do
local c = tabContent(tabs[j])
if c then
c.Parent = content
c.Visible = (j == 1)
end
paint(j)
end
end
api.Frame = root
api.Bar = bar
api.Content = content
api.Selected = current
api.Select = function(i) selectTab(i) end
return api
end
function GUI.Checkbox(parent, opts)
opts = opts or {}
local checked = not not opts.checked
local root = Instance.new("Frame")
root.Name = "Checkbox"
root.Size = opts.size or UDim2.fromOffset(180, 24)
root.Position = opts.position or UDim2.fromOffset(0, 0)
root.BackgroundTransparency = 1
root.Parent = parent
local box = Instance.new("Frame")
box.Name = "Box"
box.Size = UDim2.fromOffset(18, 18)
box.Position = UDim2.new(0, 0, 0.5, -9)
box.BackgroundColor3 = checked and GUI.Theme.accent or GUI.Theme.disabled
box.BorderSizePixel = 0
rounded(box, 4)
box.Parent = root
local check = Instance.new("TextLabel")
check.Name = "Check"
check.Size = UDim2.new(1, 0, 1, 0)
check.BackgroundTransparency = 1
check.Text = "✓"
check.TextColor3 = GUI.Theme.text
check.Font = Enum.Font.GothamBold
check.TextSize = 12
check.Visible = checked
check.Parent = box
local label = Instance.new("TextLabel")
label.Name = "Label"
label.Size = UDim2.new(1, -24, 1, 0)
label.Position = UDim2.new(0, 24, 0, 0)
label.BackgroundTransparency = 1
label.Text = opts.text or ""
label.TextColor3 = checked and GUI.Theme.text or GUI.Theme.dim
label.Font = Enum.Font.GothamMedium
label.TextSize = 12
label.TextXAlignment = Enum.TextXAlignment.Left
label.Parent = root
local btn = Instance.new("TextButton")
btn.Name = "Hitbox"
btn.Size = UDim2.new(1, 0, 1, 0)
btn.BackgroundTransparency = 1
btn.BorderSizePixel = 0
btn.Text = ""
btn.AutoButtonColor = false
btn.Parent = root
local api = {}
local function setChecked(v, fire)
v = not not v
if v == checked then return end
checked = v
api.Checked = checked
check.Visible = checked
tween(box, { BackgroundColor3 = checked and GUI.Theme.accent or GUI.Theme.disabled }, 0.12)
label.TextColor3 = checked and GUI.Theme.text or GUI.Theme.dim
GUI.Log(("[CHECKBOX] %s -> %s"):format(tostring(opts.text), tostring(checked)))
if fire and opts.onChange then pcall(opts.onChange, checked) end
end
btn.MouseButton1Click:Connect(function() setChecked(not checked, true) end)
btn.MouseEnter:Connect(function()
tween(box, { BackgroundColor3 = checked and GUI.hoverColor(GUI.Theme.accent) or GUI.Theme.surfaceHover }, 0.1)
end)
btn.MouseLeave:Connect(function()
tween(box, { BackgroundColor3 = checked and GUI.Theme.accent or GUI.Theme.disabled }, 0.1)
end)
api.Frame = root
api.Box = box
api.Check = check
api.Label = label
api.Checked = checked
api.Set = function(v) setChecked(v, true) end
api.Toggle = function() setChecked(not checked, true) end
return api
end
function GUI.Toggle(parent, opts)
opts = opts or {}
local checked = not not opts.checked
local root = Instance.new("Frame")
root.Name = "Toggle"
root.Size = opts.size or UDim2.fromOffset(180, 24)
root.Position = opts.position or UDim2.fromOffset(0, 0)
root.BackgroundTransparency = 1
root.Parent = parent
local track = Instance.new("Frame")
track.Name = "Track"
track.Size = UDim2.fromOffset(40, 20)
track.Position = UDim2.new(0, 0, 0.5, -10)
track.BackgroundColor3 = checked and GUI.Theme.accent or GUI.Theme.disabled
track.BorderSizePixel = 0
rounded(track, 10)
track.Parent = root
local thumb = Instance.new("Frame")
thumb.Name = "Thumb"
thumb.Size = UDim2.fromOffset(16, 16)
thumb.Position = UDim2.new(0, checked and 22 or 2, 0.5, -8)
thumb.BackgroundColor3 = checked and GUI.Theme.text or GUI.Theme.dim
thumb.BorderSizePixel = 0
rounded(thumb, 8)
thumb.Parent = track
local label = Instance.new("TextLabel")
label.Name = "Label"
label.Size = UDim2.new(1, -48, 1, 0)
label.Position = UDim2.new(0, 48, 0, 0)
label.BackgroundTransparency = 1
label.Text = opts.text or ""
label.TextColor3 = checked and GUI.Theme.text or GUI.Theme.dim
label.Font = Enum.Font.GothamMedium
label.TextSize = 12
label.TextXAlignment = Enum.TextXAlignment.Left
label.Parent = root
local btn = Instance.new("TextButton")
btn.Name = "Hitbox"
btn.Size = UDim2.new(1, 0, 1, 0)
btn.BackgroundTransparency = 1
btn.BorderSizePixel = 0
btn.Text = ""
btn.AutoButtonColor = false
btn.Parent = root
local api = {}
local function setChecked(v, fire)
v = not not v
if v == checked then return end
checked = v
api.Checked = checked
tween(track, { BackgroundColor3 = checked and GUI.Theme.accent or GUI.Theme.disabled }, 0.12)
tween(thumb, {
Position = UDim2.new(0, checked and 22 or 2, 0.5, -8),
BackgroundColor3 = checked and GUI.Theme.text or GUI.Theme.dim,
}, 0.12)
label.TextColor3 = checked and GUI.Theme.text or GUI.Theme.dim
GUI.Log(("[TOGGLE] %s -> %s"):format(tostring(opts.text), tostring(checked)))
if fire and opts.onChange then pcall(opts.onChange, checked) end
end
btn.MouseButton1Click:Connect(function() setChecked(not checked, true) end)
btn.MouseEnter:Connect(function()
tween(track, { BackgroundColor3 = checked and GUI.hoverColor(GUI.Theme.accent) or GUI.Theme.surfaceHover }, 0.1)
end)
btn.MouseLeave:Connect(function()
tween(track, { BackgroundColor3 = checked and GUI.Theme.accent or GUI.Theme.disabled }, 0.1)
end)
api.Frame = root
api.Track = track
api.Thumb = thumb
api.Label = label
api.Checked = checked
api.Set = function(v) setChecked(v, true) end
api.Toggle = function() setChecked(not checked, true) end
return api
end
-- ---------- t3: slider, dropdown, tooltip ----------
-- GUI.Slider(parent, opts)
-- opts: position (UDim2), size (UDim2, default UDim2.new(1, -24, 0, 26)),
-- min (number, default 0), max (number, default 100), value (number, default min),
-- step (number, optional rounding), text (string, optional label), onChange(value)
-- drag: InputBegan jumps + starts drag, UserInputService.InputChanged moves, InputEnded stops
-- ratio = (x - trackOrigin) / trackWidth, clamped to [0, 1]
-- api: { Frame, Track, Fill, Knob, Label?, Value, Set(v), Get() }
function GUI.Slider(parent, opts)
opts = opts or {}
local pos = opts.position or UDim2.new(0, 12, 0, 12)
local size = opts.size or UDim2.new(1, -24, 0, 26)
local min = tonumber(opts.min) or 0
local max = tonumber(opts.max) or 100
local step = opts.step
local value = tonumber(opts.value)
if not value then value = min end
if value < min then value = min elseif value > max then value = max end
local root = Instance.new("Frame")
root.Name = "Slider"
root.Size = size
root.Position = pos
root.BackgroundTransparency = 1
root.Parent = parent
local label
if opts.text then
label = Instance.new("TextLabel")
label.Name = "Label"
label.Size = UDim2.new(1, 0, 0, 14)
label.Position = UDim2.new(0, 2, 0, 0)
label.BackgroundTransparency = 1
label.Text = opts.text
label.TextColor3 = GUI.Theme.text
label.Font = Enum.Font.GothamMedium
label.TextSize = 12
label.TextXAlignment = Enum.TextXAlignment.Left
label.Parent = root
end
local track = Instance.new("Frame")
track.Name = "Track"
track.Position = UDim2.new(0, 0, 1, -10)
track.Size = UDim2.new(1, 0, 0, 4)
track.BackgroundColor3 = GUI.Theme.disabled
track.BorderSizePixel = 0
rounded(track, 2)
track.Parent = root
local fill = Instance.new("Frame")
fill.Name = "Fill"
fill.Size = UDim2.new(0, 0, 1, 0)
fill.BackgroundColor3 = GUI.Theme.accent
fill.BorderSizePixel = 0
rounded(fill, 2)
fill.Parent = track
local knob = Instance.new("Frame")
knob.Name = "Knob"
knob.Size = UDim2.fromOffset(14, 14)
knob.Position = UDim2.new(0, -7, 0.5, -7)
knob.BackgroundColor3 = GUI.Theme.text
knob.BorderSizePixel = 0
rounded(knob, 7)
knob.Parent = track
local api = {}
local function ratio()
if max <= min then return 0 end
return (value - min) / (max - min)
end
local function trackWidth()
local w = nil
pcall(function() w = root.AbsoluteSize.X end)
if type(w) ~= "number" or w <= 0 then
w = nil
pcall(function() w = size.X.Offset end)
end
return w or 0
end
local function trackOrigin()
local x = nil
pcall(function() x = root.AbsolutePosition.X end)
if type(x) ~= "number" then
x = nil
pcall(function() x = pos.X.Offset end)
end
return x or 0
end
local function render()
local r = ratio()
if r < 0 then r = 0 elseif r > 1 then r = 1 end
local w = trackWidth()
if w <= 0 then w = 0 end
local px = math.floor(w * r + 0.5)
fill.Size = UDim2.new(0, px, 1, 0)
knob.Position = UDim2.new(0, px - 7, 0.5, -7)
end
local function apply(v, fire)
v = tonumber(v)
if not v then return end
if v < min then v = min elseif v > max then v = max end
if step and step > 0 then
v = min + math.floor((v - min) / step + 0.5) * step
if v < min then v = min elseif v > max then v = max end
end
if v == value then
render()
return
end
value = v
api.Value = value
render()
GUI.Log(("[SLIDER] %s -> %s"):format(tostring(opts.text or ""), tostring(value)))
if fire and opts.onChange then pcall(opts.onChange, value) end
end
local dragging = false
local function setFromInput(input)
local x = input.Position and input.Position.X
if type(x) ~= "number" then return end
local w = trackWidth()
if w <= 0 then return end
local ox = trackOrigin()
local r = (x - ox) / w
if r < 0 then r = 0 elseif r > 1 then r = 1 end
apply(min + (max - min) * r, true)
end
root.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
setFromInput(input)
end
end)
root.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1
or input.UserInputType == Enum.UserInputType.Touch then
dragging = false
end
end)
UserInputService.InputChanged:Connect(function(input)
if not dragging then return end
if input.UserInputType == Enum.UserInputType.MouseMovement
or input.UserInputType == Enum.UserInputType.Touch then
setFromInput(input)
end
end)
api.Frame = root
api.Track = track
api.Fill = fill
api.Knob = knob
api.Label = label
api.Value = value
api.Set = function(v) apply(v, true) end
api.Get = function() return value end
render()
return api
end
-- GUI.Dropdown(parent, opts)
-- opts: position, size (default UDim2.new(1, -24, 0, 30)),
-- options (array of string | { name = ..., value = ... }), value (initial index or option value),
-- onChange(index, name)
-- api: { Frame, Header, Panel, Value, Selected, Select(i), Open(), Close(), Toggle() }
-- panel: elevated bg + border, rounded 8, ZIndex 20; click outside closes (best-effort)
function GUI.Dropdown(parent, opts)
opts = opts or {}
local pos = opts.position or UDim2.new(0, 12, 0, 12)
local size = opts.size or UDim2.new(1, -24, 0, 30)
local options = opts.options or {}
local n = #options
local function optionName(o, j)
if type(o) == "table" then return tostring(o.name or o[1] or ("Option " .. j)) end
return tostring(o)
end
local function optionValue(o)
if type(o) == "table" then return o.value ~= nil and o.value or o.name end
return o
end
local selected = 1
if n > 0 then
selected = tonumber(opts.value)
if not selected then
for j = 1, n do
if optionValue(options[j]) == opts.value then
selected = j
break
end
end
end
if not selected or selected < 1 then selected = 1
elseif selected > n then selected = n end
end
local root = Instance.new("Frame")
root.Name = "Dropdown"
root.Size = size
root.Position = pos
root.BackgroundTransparency = 1
root.Parent = parent
local header = Instance.new("TextButton")
header.Name = "Header"
header.Size = UDim2.new(1, 0, 1, 0)
header.BackgroundColor3 = GUI.Theme.surface
header.BorderSizePixel = 0
header.Text = ""
header.TextColor3 = GUI.Theme.text
header.Font = Enum.Font.GothamMedium
header.TextSize = 12
header.TextXAlignment = Enum.TextXAlignment.Left
header.AutoButtonColor = false
rounded(header, 6)
header.Parent = root
local arrow = Instance.new("TextLabel")
arrow.Name = "Arrow"
arrow.Size = UDim2.new(0, 20, 1, 0)
arrow.Position = UDim2.new(1, -20, 0, 0)
arrow.BackgroundTransparency = 1
arrow.Text = "▾"
arrow.TextColor3 = GUI.Theme.dim
arrow.Font = Enum.Font.Gotham
arrow.TextSize = 12
arrow.Parent = header
local panel = Instance.new("Frame")
panel.Name = "Panel"
panel.Size = UDim2.new(1, 0, 0, 0)
panel.Position = UDim2.new(0, 0, 1, 4)
panel.BackgroundColor3 = GUI.Theme.elevated
panel.BorderSizePixel = 1
panel.BorderColor3 = GUI.Theme.border
panel.ZIndex = 20
panel.Visible = false
rounded(panel, 8)
panel.Parent = root
local api = {}
local open = false
local items = {}
local function paint()
header.Text = n > 0 and (" " .. optionName(options[selected], selected)) or ""
for j = 1, n do
local b = items[j]
if b then
local active = (j == selected)
b.TextColor3 = active and GUI.Theme.accent or GUI.Theme.text
b.BackgroundColor3 = active and GUI.Theme.surfaceHover or GUI.Theme.surface
end
end
end
local function close()
open = false
panel.Visible = false
arrow.Text = "▾"
end
local function select(i, fire)
if n == 0 then return end
if i < 1 then i = 1 elseif i > n then i = n end
selected = i
api.Value = optionValue(options[i])
api.Selected = i
paint()
close()
GUI.Log(("[DROPDOWN] %s -> %d"):format(optionName(options[i], i), i))
if fire and opts.onChange then pcall(opts.onChange, i, optionName(options[i], i)) end
end
if n > 0 then
panel.Size = UDim2.new(1, 0, 0, 4 + n * 24 + 4)
for j = 1, n do
local b = Instance.new("TextButton")
b.Name = "Item" .. j
b.Size = UDim2.new(1, -8, 0, 24)
b.Position = UDim2.new(0, 4, 0, 4 + (j - 1) * 24)
b.BackgroundColor3 = GUI.Theme.surface
b.BorderSizePixel = 0
b.Text = " " .. optionName(options[j], j)
b.TextColor3 = GUI.Theme.text
b.Font = Enum.Font.Gotham
b.TextSize = 12
b.TextXAlignment = Enum.TextXAlignment.Left
b.AutoButtonColor = false
rounded(b, 4)
b.Parent = panel
b.MouseButton1Click:Connect(function() select(j, true) end)
b.MouseEnter:Connect(function()
b.BackgroundColor3 = GUI.Theme.surfaceHover
end)
b.MouseLeave:Connect(function()
b.BackgroundColor3 = (j == selected) and GUI.Theme.surfaceHover or GUI.Theme.surface
end)
items[j] = b
end
end