-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.lua
More file actions
709 lines (623 loc) · 22.1 KB
/
Copy pathUtils.lua
File metadata and controls
709 lines (623 loc) · 22.1 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
--[[
Utils.lua - Core Utilities Module
Part of the Roblox UI Library
Handles: Theming, Config Save/Load, Watermark, Animations, Keybind system
]]
local Utils = {}
-- Services
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Stats = game:GetService("Stats")
local LocalPlayer = Players.LocalPlayer
--------------------------------------------------------------------------------
-- DEFAULT THEME
--------------------------------------------------------------------------------
Utils.DefaultTheme = {
-- Backgrounds
Background = Color3.fromRGB(15, 15, 20),
BackgroundDark = Color3.fromRGB(10, 10, 14),
Header = Color3.fromRGB(20, 20, 28),
TabBackground = Color3.fromRGB(18, 18, 24),
TabBackgroundDark = Color3.fromRGB(12, 12, 16),
ElementBackground = Color3.fromRGB(24, 24, 32),
ElementHover = Color3.fromRGB(30, 30, 40),
ElementActive = Color3.fromRGB(35, 35, 48),
ScrollBar = Color3.fromRGB(40, 40, 55),
Divider = Color3.fromRGB(40, 40, 55),
-- Accent
Accent = Color3.fromRGB(100, 80, 255),
AccentDark = Color3.fromRGB(80, 60, 220),
AccentLight = Color3.fromRGB(130, 110, 255),
AccentGlow = Color3.fromRGB(100, 80, 255),
-- Text
TextPrimary = Color3.fromRGB(240, 240, 245),
TextSecondary = Color3.fromRGB(160, 160, 175),
TextMuted = Color3.fromRGB(100, 100, 115),
TextAccent = Color3.fromRGB(130, 110, 255),
-- Status
Success = Color3.fromRGB(80, 200, 120),
Warning = Color3.fromRGB(255, 180, 50),
Error = Color3.fromRGB(255, 80, 80),
ToggleOn = Color3.fromRGB(100, 80, 255),
ToggleOff = Color3.fromRGB(50, 50, 65),
-- Misc
Shadow = Color3.fromRGB(0, 0, 0),
Border = Color3.fromRGB(45, 45, 60),
BorderLight = Color3.fromRGB(55, 55, 70),
ResizeGrab = Color3.fromRGB(60, 60, 80),
-- Config
FontFace = Font.new("rbxasset://fonts/families/GothamSSm.json", Enum.FontWeight.Medium, Enum.FontStyle.Normal),
FontFaceBold = Font.new("rbxasset://fonts/families/GothamSSm.json", Enum.FontWeight.Bold, Enum.FontStyle.Normal),
TextSize = 13,
CornerRadius = UDim.new(0, 8),
ElementCorner = UDim.new(0, 6),
Padding = UDim.new(0, 12),
Transparency = 0.02,
}
-- Predefined theme presets
Utils.ThemePresets = {
Default = nil, -- Set after DefaultTheme is defined
Midnight = {
Accent = Color3.fromRGB(60, 120, 255),
AccentDark = Color3.fromRGB(40, 90, 220),
AccentLight = Color3.fromRGB(90, 150, 255),
AccentGlow = Color3.fromRGB(60, 120, 255),
Background = Color3.fromRGB(10, 10, 18),
Header = Color3.fromRGB(15, 15, 24),
ToggleOn = Color3.fromRGB(60, 120, 255),
TextAccent = Color3.fromRGB(90, 150, 255),
},
Crimson = {
Accent = Color3.fromRGB(220, 50, 50),
AccentDark = Color3.fromRGB(180, 35, 35),
AccentLight = Color3.fromRGB(255, 80, 80),
AccentGlow = Color3.fromRGB(220, 50, 50),
ToggleOn = Color3.fromRGB(220, 50, 50),
TextAccent = Color3.fromRGB(255, 80, 80),
},
Neon = {
Accent = Color3.fromRGB(0, 255, 150),
AccentDark = Color3.fromRGB(0, 220, 120),
AccentLight = Color3.fromRGB(50, 255, 180),
AccentGlow = Color3.fromRGB(0, 255, 150),
ToggleOn = Color3.fromRGB(0, 255, 150),
TextAccent = Color3.fromRGB(50, 255, 180),
},
Sunset = {
Accent = Color3.fromRGB(255, 100, 50),
AccentDark = Color3.fromRGB(220, 80, 35),
AccentLight = Color3.fromRGB(255, 140, 80),
AccentGlow = Color3.fromRGB(255, 100, 50),
ToggleOn = Color3.fromRGB(255, 100, 50),
TextAccent = Color3.fromRGB(255, 140, 80),
},
Ocean = {
Accent = Color3.fromRGB(0, 180, 220),
AccentDark = Color3.fromRGB(0, 150, 190),
AccentLight = Color3.fromRGB(50, 210, 250),
AccentGlow = Color3.fromRGB(0, 180, 220),
ToggleOn = Color3.fromRGB(0, 180, 220),
TextAccent = Color3.fromRGB(50, 210, 250),
},
Forest = {
Accent = Color3.fromRGB(50, 180, 80),
AccentDark = Color3.fromRGB(35, 150, 60),
AccentLight = Color3.fromRGB(80, 220, 110),
AccentGlow = Color3.fromRGB(50, 180, 80),
ToggleOn = Color3.fromRGB(50, 180, 80),
TextAccent = Color3.fromRGB(80, 220, 110),
},
Sakura = {
Accent = Color3.fromRGB(255, 140, 180),
AccentDark = Color3.fromRGB(220, 110, 150),
AccentLight = Color3.fromRGB(255, 170, 200),
AccentGlow = Color3.fromRGB(255, 140, 180),
ToggleOn = Color3.fromRGB(255, 140, 180),
TextAccent = Color3.fromRGB(255, 170, 200),
},
}
Utils.ThemePresets.Default = Utils.DefaultTheme
--------------------------------------------------------------------------------
-- THEME ENGINE
--------------------------------------------------------------------------------
function Utils.CreateTheme(overrides)
local theme = {}
for k, v in pairs(Utils.DefaultTheme) do
theme[k] = v
end
if overrides then
for k, v in pairs(overrides) do
theme[k] = v
end
end
return theme
end
function Utils.ApplyPreset(theme, presetName)
local preset = Utils.ThemePresets[presetName]
if not preset then
warn("[UI Lib] Theme preset '" .. tostring(presetName) .. "' not found.")
return theme
end
for k, v in pairs(preset) do
theme[k] = v
end
return theme
end
--------------------------------------------------------------------------------
-- ANIMATION HELPERS
--------------------------------------------------------------------------------
function Utils.Tween(obj, props, duration, style, direction)
duration = duration or 0.2
style = style or Enum.EasingStyle.Quint
direction = direction or Enum.EasingDirection.Out
local tween = TweenService:Create(obj, TweenInfo.new(duration, style, direction), props)
tween:Play()
return tween
end
function Utils.FadeIn(obj, duration)
obj.Visible = true
obj.GroupTransparency = 1
Utils.Tween(obj, {GroupTransparency = 0}, duration or 0.25)
end
function Utils.FadeOut(obj, duration)
local tween = Utils.Tween(obj, {GroupTransparency = 1}, duration or 0.2)
tween.Completed:Connect(function()
obj.Visible = false
end)
end
--------------------------------------------------------------------------------
-- INSTANCE CREATION HELPERS
--------------------------------------------------------------------------------
function Utils.Create(className, properties, children)
local inst = Instance.new(className)
for k, v in pairs(properties or {}) do
if k ~= "Parent" then
pcall(function()
inst[k] = v
end)
end
end
for _, child in ipairs(children or {}) do
child.Parent = inst
end
if properties and properties.Parent then
inst.Parent = properties.Parent
end
return inst
end
function Utils.MakeCorner(radius, parent)
return Utils.Create("UICorner", {
CornerRadius = radius or UDim.new(0, 8),
Parent = parent,
})
end
function Utils.MakeStroke(color, thickness, parent, transparency)
return Utils.Create("UIStroke", {
Color = color or Color3.fromRGB(45, 45, 60),
Thickness = thickness or 1,
Transparency = transparency or 0,
ApplyStrokeMode = Enum.ApplyStrokeMode.Border,
Parent = parent,
})
end
function Utils.MakePadding(t, b, l, r, parent)
return Utils.Create("UIPadding", {
PaddingTop = t or UDim.new(0, 0),
PaddingBottom = b or UDim.new(0, 0),
PaddingLeft = l or UDim.new(0, 0),
PaddingRight = r or UDim.new(0, 0),
Parent = parent,
})
end
function Utils.MakeList(dir, padding, parent, hAlign, vAlign, wrap)
return Utils.Create("UIListLayout", {
FillDirection = dir or Enum.FillDirection.Vertical,
Padding = padding or UDim.new(0, 6),
HorizontalAlignment = hAlign or Enum.HorizontalAlignment.Left,
VerticalAlignment = vAlign or Enum.VerticalAlignment.Top,
SortOrder = Enum.SortOrder.LayoutOrder,
Wraps = wrap or false,
Parent = parent,
})
end
function Utils.MakeGradient(c1, c2, rotation, parent)
return Utils.Create("UIGradient", {
Color = ColorSequence.new(c1, c2),
Rotation = rotation or 0,
Parent = parent,
})
end
function Utils.MakeShadow(parent, size)
return Utils.Create("ImageLabel", {
Name = "Shadow",
AnchorPoint = Vector2.new(0.5, 0.5),
BackgroundTransparency = 1,
Position = UDim2.new(0.5, 0, 0.5, 4),
Size = size or UDim2.new(1, 30, 1, 30),
ZIndex = 0,
Image = "rbxassetid://6014261993",
ImageColor3 = Color3.fromRGB(0, 0, 0),
ImageTransparency = 0.5,
ScaleType = Enum.ScaleType.Slice,
SliceCenter = Rect.new(49, 49, 450, 450),
Parent = parent,
})
end
--------------------------------------------------------------------------------
-- CONFIG SAVE / LOAD SYSTEM
--------------------------------------------------------------------------------
Utils._configFolder = "UILib_Configs"
function Utils.SaveConfig(name, data)
local success, encoded = pcall(function()
return HttpService:JSONEncode(data)
end)
if not success then
warn("[UI Lib] Failed to encode config:", encoded)
return false
end
local ok, err = pcall(function()
if not isfolder(Utils._configFolder) then
makefolder(Utils._configFolder)
end
writefile(Utils._configFolder .. "/" .. name .. ".json", encoded)
end)
if not ok then
warn("[UI Lib] Failed to save config:", err)
return false
end
return true
end
function Utils.LoadConfig(name)
local path = Utils._configFolder .. "/" .. name .. ".json"
local exists = pcall(function()
return readfile(path)
end)
if not exists then return nil end
local ok, result = pcall(function()
local raw = readfile(path)
return HttpService:JSONDecode(raw)
end)
if not ok then
warn("[UI Lib] Failed to load config:", result)
return nil
end
return result
end
function Utils.DeleteConfig(name)
local path = Utils._configFolder .. "/" .. name .. ".json"
pcall(function()
if isfile(path) then
delfile(path)
end
end)
end
function Utils.ListConfigs()
local ok, files = pcall(function()
if not isfolder(Utils._configFolder) then
makefolder(Utils._configFolder)
end
return listfiles(Utils._configFolder)
end)
if not ok then return {} end
local configs = {}
for _, file in ipairs(files) do
local name = file:match("([^/\\]+)%.json$")
if name then
table.insert(configs, name)
end
end
return configs
end
--------------------------------------------------------------------------------
-- WATERMARK
--------------------------------------------------------------------------------
function Utils.CreateWatermark(theme, title, parentGui)
local wm = Utils.Create("Frame", {
Name = "Watermark",
AnchorPoint = Vector2.new(0, 0),
Position = UDim2.new(0, 12, 0, 12),
Size = UDim2.new(0, 220, 0, 32),
BackgroundColor3 = theme.Background,
BorderSizePixel = 0,
ZIndex = 100,
Parent = parentGui,
})
Utils.MakeCorner(UDim.new(0, 8), wm)
Utils.MakeStroke(theme.Border, 1, wm, 0.3)
local wmShadow = Utils.Create("Frame", {
Name = "ShadowHolder",
BackgroundTransparency = 1,
Size = UDim2.new(1, 20, 1, 20),
Position = UDim2.new(0.5, 0, 0.5, 2),
AnchorPoint = Vector2.new(0.5, 0.5),
ZIndex = 99,
Parent = wm,
})
local accentBar = Utils.Create("Frame", {
Name = "AccentBar",
Size = UDim2.new(0, 3, 0.7, 0),
Position = UDim2.new(0, 6, 0.5, 0),
AnchorPoint = Vector2.new(0, 0.5),
BackgroundColor3 = theme.Accent,
BorderSizePixel = 0,
ZIndex = 101,
Parent = wm,
})
Utils.MakeCorner(UDim.new(1, 0), accentBar)
local titleLabel = Utils.Create("TextLabel", {
Name = "Title",
BackgroundTransparency = 1,
Position = UDim2.new(0, 16, 0, 0),
Size = UDim2.new(1, -20, 1, 0),
FontFace = theme.FontFaceBold,
Text = title or "UI Library",
TextColor3 = theme.TextPrimary,
TextSize = 13,
TextXAlignment = Enum.TextXAlignment.Left,
ZIndex = 101,
Parent = wm,
})
local fpsLabel = Utils.Create("TextLabel", {
Name = "FPS",
BackgroundTransparency = 1,
Position = UDim2.new(0, 16, 0, 0),
Size = UDim2.new(1, -20, 1, 0),
FontFace = theme.FontFace,
Text = "60 FPS | 0 ms",
TextColor3 = theme.TextMuted,
TextSize = 11,
TextXAlignment = Enum.TextXAlignment.Right,
ZIndex = 101,
Parent = wm,
})
-- Auto-resize watermark width
local function updateWidth()
local titleWidth = titleLabel.TextBounds.X
local fpsWidth = fpsLabel.TextBounds.X
local totalWidth = math.max(220, titleWidth + fpsWidth + 50)
wm.Size = UDim2.new(0, totalWidth, 0, 32)
end
-- FPS + Ping updater
local fpsCounter = 0
local fpsDisplay = 60
local lastTime = tick()
RunService.Heartbeat:Connect(function()
fpsCounter += 1
local now = tick()
if now - lastTime >= 1 then
fpsDisplay = fpsCounter
fpsCounter = 0
lastTime = now
local ping = 0
pcall(function()
ping = math.floor(Stats.Network.ServerStatsItem["Data Ping"]:GetValue())
end)
fpsLabel.Text = string.format("%d FPS | %d ms", fpsDisplay, ping)
updateWidth()
end
end)
local wmApi = {}
wmApi.Instance = wm
wmApi.Visible = true
function wmApi:SetVisible(visible)
self.Visible = visible
wm.Visible = visible
end
function wmApi:SetText(text)
titleLabel.Text = text
updateWidth()
end
function wmApi:UpdateTheme(t)
wm.BackgroundColor3 = t.Background
accentBar.BackgroundColor3 = t.Accent
titleLabel.TextColor3 = t.TextPrimary
fpsLabel.TextColor3 = t.TextMuted
end
return wmApi
end
--------------------------------------------------------------------------------
-- NOTIFICATION SYSTEM
--------------------------------------------------------------------------------
function Utils.Notify(theme, parentGui, titleText, message, duration, notifType)
duration = duration or 4
notifType = notifType or "Info"
local colorMap = {
Info = theme.Accent,
Success = theme.Success,
Warning = theme.Warning,
Error = theme.Error,
}
local accentColor = colorMap[notifType] or theme.Accent
local container = parentGui:FindFirstChild("NotificationContainer")
if not container then
container = Utils.Create("Frame", {
Name = "NotificationContainer",
AnchorPoint = Vector2.new(1, 0),
BackgroundTransparency = 1,
Position = UDim2.new(1, -12, 0, 12),
Size = UDim2.new(0, 280, 1, -24),
ZIndex = 200,
Parent = parentGui,
})
Utils.MakeList(Enum.FillDirection.Vertical, UDim.new(0, 8), container, nil, nil)
end
local notif = Utils.Create("Frame", {
Name = "Notification",
Size = UDim2.new(1, 0, 0, 0),
BackgroundColor3 = theme.Background,
BorderSizePixel = 0,
AutomaticSize = Enum.AutomaticSize.Y,
ZIndex = 201,
Parent = container,
})
Utils.MakeCorner(UDim.new(0, 8), notif)
Utils.MakeStroke(theme.Border, 1, notif, 0.4)
local accent = Utils.Create("Frame", {
Size = UDim2.new(0, 3, 1, 0),
BackgroundColor3 = accentColor,
BorderSizePixel = 0,
ZIndex = 202,
Parent = notif,
})
Utils.MakeCorner(UDim.new(1, 0), accent)
local contentPad = Utils.Create("Frame", {
Name = "Content",
BackgroundTransparency = 1,
Size = UDim2.new(1, -20, 0, 0),
Position = UDim2.new(0, 16, 0, 0),
AutomaticSize = Enum.AutomaticSize.Y,
ZIndex = 202,
Parent = notif,
})
Utils.MakeList(Enum.FillDirection.Vertical, UDim.new(0, 4), contentPad)
Utils.MakePadding(UDim.new(0, 10), UDim.new(0, 10), nil, UDim.new(0, 8), contentPad)
Utils.Create("TextLabel", {
BackgroundTransparency = 1,
Size = UDim2.new(1, 0, 0, 16),
FontFace = theme.FontFaceBold,
Text = titleText or "Notification",
TextColor3 = accentColor,
TextSize = 13,
TextXAlignment = Enum.TextXAlignment.Left,
ZIndex = 203,
AutomaticSize = Enum.AutomaticSize.Y,
Parent = contentPad,
})
if message and message ~= "" then
Utils.Create("TextLabel", {
BackgroundTransparency = 1,
Size = UDim2.new(1, 0, 0, 0),
FontFace = theme.FontFace,
Text = message,
TextColor3 = theme.TextSecondary,
TextSize = 12,
TextXAlignment = Enum.TextXAlignment.Left,
TextWrapped = true,
AutomaticSize = Enum.AutomaticSize.Y,
ZIndex = 203,
Parent = contentPad,
})
end
-- Progress bar
local progressBar = Utils.Create("Frame", {
Size = UDim2.new(1, 0, 0, 2),
BackgroundColor3 = accentColor,
BorderSizePixel = 0,
ZIndex = 203,
Parent = notif,
})
Utils.MakeCorner(UDim.new(1, 0), progressBar)
-- Animate in
notif.GroupTransparency = 1
Utils.Tween(notif, {GroupTransparency = 0}, 0.3)
Utils.Tween(progressBar, {Size = UDim2.new(0, 0, 0, 2)}, duration, Enum.EasingStyle.Linear)
-- Remove after duration
task.delay(duration, function()
Utils.Tween(notif, {GroupTransparency = 1}, 0.3)
task.wait(0.35)
notif:Destroy()
end)
end
--------------------------------------------------------------------------------
-- KEYBIND SYSTEM
--------------------------------------------------------------------------------
Utils._keybindCallbacks = {}
Utils._keybindList = {}
function Utils.RegisterKeybind(name, defaultKey, callback, mode)
-- mode: "Toggle" | "Always" | "Hold"
mode = mode or "Toggle"
Utils._keybindList[name] = {
Key = defaultKey,
Mode = mode,
Callback = callback,
Active = (mode == "Always"),
Name = name,
}
return Utils._keybindList[name]
end
function Utils.GetKeybindData()
return Utils._keybindList
end
function Utils.GetKeybindString(name)
local kb = Utils._keybindList[name]
if not kb then return "None" end
if kb.Key and kb.Key ~= Enum.KeyCode.Unknown then
return kb.Key.Name
end
return "None"
end
--------------------------------------------------------------------------------
-- INPUT HELPERS
--------------------------------------------------------------------------------
function Utils.GetKeyName(keyCode)
if keyCode == Enum.KeyCode.Unknown then return "None" end
return keyCode.Name
end
function Utils.IsKeyCode(keyCode)
return typeof(keyCode) == "EnumItem" and keyCode.EnumType == Enum.KeyCode
end
-- Master input handler - connects once, dispatches to all registered keybinds
Utils._inputConnection = nil
function Utils.StartInputHandler()
if Utils._inputConnection then return end
Utils._inputConnection = UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
for name, kb in pairs(Utils._keybindList) do
if input.KeyCode == kb.Key then
if kb.Mode == "Toggle" then
kb.Active = not kb.Active
end
if kb.Callback then
task.spawn(kb.Callback, kb.Active)
end
end
end
end)
end
--------------------------------------------------------------------------------
-- HOVER / CLICK EFFECTS
--------------------------------------------------------------------------------
function Utils.AddHoverEffect(frame, theme, normalColor, hoverColor)
local currentNormal = normalColor or frame.BackgroundColor3
local currentHover = hoverColor or theme.ElementHover
frame.MouseEnter:Connect(function()
Utils.Tween(frame, {BackgroundColor3 = currentHover}, 0.15)
end)
frame.MouseLeave:Connect(function()
Utils.Tween(frame, {BackgroundColor3 = currentNormal}, 0.15)
end)
end
function Utils.AddClickEffect(frame, theme)
frame.MouseButton1Down:Connect(function()
Utils.Tween(frame, {BackgroundColor3 = theme.ElementActive}, 0.08)
end)
frame.MouseButton1Up:Connect(function()
Utils.Tween(frame, {BackgroundColor3 = theme.ElementHover}, 0.08)
end)
end
--------------------------------------------------------------------------------
-- UTILITY FUNCTIONS
--------------------------------------------------------------------------------
function Utils.Lerp(a, b, t)
return a + (b - a) * t
end
function Utils.Clamp(val, min, max)
return math.clamp(val, min, max)
end
function Utils.FormatNumber(n)
if n >= 1e9 then return string.format("%.1fB", n / 1e9) end
if n >= 1e6 then return string.format("%.1fM", n / 1e6) end
if n >= 1e3 then return string.format("%.1fK", n / 1e3) end
return tostring(n)
end
function Utils.GetPlayerAvatar(userId)
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size48x48
local content = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
return content
end
return Utils