Repository navigation
Expand file tree
/
Copy pathNovaUI.lua
More file actions
565 lines (521 loc) · 17.8 KB
/
Copy pathNovaUI.lua
File metadata and controls
565 lines (521 loc) · 17.8 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
-- Nova UI 1.0.0
-- A compact Luau interface library for Roblox scripts.
-- MIT licensed. Single file, no dependencies.
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local NovaUI = {}
NovaUI.__index = NovaUI
NovaUI.Theme = {
Background = Color3.fromRGB(15, 18, 32),
Surface = Color3.fromRGB(20, 24, 42),
SurfaceAlt = Color3.fromRGB(27, 32, 56),
Accent = Color3.fromRGB(139, 92, 246),
AccentAlt = Color3.fromRGB(56, 189, 248),
Text = Color3.fromRGB(245, 243, 255),
Muted = Color3.fromRGB(165, 180, 252),
Dim = Color3.fromRGB(111, 118, 144),
Danger = Color3.fromRGB(251, 113, 133),
Success = Color3.fromRGB(34, 197, 94),
}
local TWEEN = TweenInfo.new(0.16, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local function corner(parent, radius)
local c = Instance.new("UICorner")
c.CornerRadius = UDim.new(0, radius or 12)
c.Parent = parent
return c
end
local function stroke(parent, color, transparency)
local s = Instance.new("UIStroke")
s.Color = color or NovaUI.Theme.SurfaceAlt
s.Transparency = transparency or 0
s.Thickness = 1
s.Parent = parent
return s
end
local function tween(object, properties)
TweenService:Create(object, TWEEN, properties):Play()
end
local function new(class, properties)
local instance = Instance.new(class)
for key, value in pairs(properties or {}) do
instance[key] = value
end
return instance
end
local function parentGui()
if typeof(gethui) == "function" then
local ok, result = pcall(gethui)
if ok and result then return result end
end
return Players.LocalPlayer:WaitForChild("PlayerGui")
end
function NovaUI.new(options)
options = options or {}
local self = setmetatable({}, NovaUI)
self._connections = {}
self._tabs = {}
self._currentTab = nil
self._notifications = {}
self._destroyed = false
local theme = NovaUI.Theme
local gui = new("ScreenGui", {
Name = options.Name or "NovaUI",
ResetOnSpawn = false,
IgnoreGuiInset = true,
ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
DisplayOrder = options.DisplayOrder or 100,
Parent = parentGui(),
})
local root = new("Frame", {
Name = "Window",
AnchorPoint = Vector2.new(0.5, 0.5),
Position = options.Position or UDim2.fromScale(0.5, 0.5),
Size = options.Size or UDim2.fromOffset(520, 360),
BackgroundColor3 = theme.Background,
BorderSizePixel = 0,
ClipsDescendants = true,
Parent = gui,
})
corner(root, 16)
stroke(root, theme.SurfaceAlt, 0.15)
local titleBar = new("Frame", {
Name = "TitleBar",
Size = UDim2.new(1, 0, 0, 48),
BackgroundColor3 = theme.Surface,
BorderSizePixel = 0,
Parent = root,
})
local title = new("TextLabel", {
BackgroundTransparency = 1,
Position = UDim2.fromOffset(16, 0),
Size = UDim2.new(1, -64, 1, 0),
Font = Enum.Font.GothamBold,
Text = options.Title or "Nova UI",
TextColor3 = theme.Text,
TextSize = 15,
TextXAlignment = Enum.TextXAlignment.Left,
Parent = titleBar,
})
local close = new("TextButton", {
BackgroundTransparency = 1,
Position = UDim2.new(1, -44, 0, 0),
Size = UDim2.fromOffset(44, 48),
Font = Enum.Font.GothamBold,
Text = "×",
TextColor3 = theme.Dim,
TextSize = 20,
Parent = titleBar,
})
close.MouseEnter:Connect(function() close.TextColor3 = theme.Danger end)
close.MouseLeave:Connect(function() close.TextColor3 = theme.Dim end)
close.Activated:Connect(function() self:Destroy() end)
local tabBar = new("Frame", {
Name = "Tabs",
Position = UDim2.fromOffset(12, 56),
Size = UDim2.new(1, -24, 0, 40),
BackgroundColor3 = theme.Surface,
BorderSizePixel = 0,
Parent = root,
})
corner(tabBar, 10)
local tabLayout = new("UIListLayout", {
FillDirection = Enum.FillDirection.Horizontal,
Padding = UDim.new(0, 4),
SortOrder = Enum.SortOrder.LayoutOrder,
Parent = tabBar,
})
local tabPadding = new("UIPadding", {
PaddingLeft = UDim.new(0, 4),
PaddingTop = UDim.new(0, 4),
PaddingBottom = UDim.new(0, 4),
Parent = tabBar,
})
local content = new("Frame", {
Name = "Content",
Position = UDim2.fromOffset(12, 104),
Size = UDim2.new(1, -24, 1, -116),
BackgroundTransparency = 1,
Parent = root,
})
self._gui = gui
self._root = root
self._tabBar = tabBar
self._content = content
self._titleBar = titleBar
-- Dragging
local dragging, dragStart, startPos = false, nil, nil
table.insert(self._connections, titleBar.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
dragging = true
dragStart = input.Position
startPos = root.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragging = false
end
end)
end
end))
table.insert(self._connections, UserInputService.InputChanged:Connect(function(input)
if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
local delta = input.Position - dragStart
root.Position = UDim2.new(
startPos.X.Scale, startPos.X.Offset + delta.X,
startPos.Y.Scale, startPos.Y.Offset + delta.Y
)
end
end))
return self
end
function NovaUI:Tab(name)
local theme = NovaUI.Theme
local index = #self._tabs + 1
local button = new("TextButton", {
Name = "Tab_" .. name,
Size = UDim2.fromOffset(104, 32),
BackgroundColor3 = theme.Background,
BackgroundTransparency = 0.4,
Font = Enum.Font.GothamMedium,
Text = name,
TextColor3 = theme.Muted,
TextSize = 13,
LayoutOrder = index,
Parent = self._tabBar,
})
corner(button, 8)
local page = new("ScrollingFrame", {
Name = "Page_" .. name,
Size = UDim2.fromScale(1, 1),
BackgroundTransparency = 1,
BorderSizePixel = 0,
ScrollBarThickness = 4,
ScrollBarImageColor3 = theme.SurfaceAlt,
CanvasSize = UDim2.new(),
AutomaticCanvasSize = Enum.AutomaticSize.Y,
Visible = false,
Parent = self._content,
})
local list = new("UIListLayout", {
Padding = UDim.new(0, 8),
SortOrder = Enum.SortOrder.LayoutOrder,
Parent = page,
})
local tab = setmetatable({
_window = self,
_page = page,
_button = button,
_index = index,
_nextOrder = 0,
_controls = {},
}, { __index = NovaUI })
table.insert(self._tabs, tab)
button.Activated:Connect(function() self:SelectTab(tab) end)
if index == 1 then self:SelectTab(tab) end
return tab
end
function NovaUI:SelectTab(tab)
local theme = NovaUI.Theme
for _, item in ipairs(self._tabs) do
local active = item == tab
item._page.Visible = active
item._button.TextColor3 = active and theme.Text or theme.Muted
item._button.BackgroundTransparency = active and 0 or 0.4
end
self._currentTab = tab
end
function NovaUI:_add(control)
control.LayoutOrder = self._nextOrder
self._nextOrder = self._nextOrder + 1
control.Parent = self._page
table.insert(self._controls, control)
return control
end
function NovaUI:Section(text)
local theme = NovaUI.Theme
local frame = new("Frame", {
Size = UDim2.new(1, 0, 0, 30),
BackgroundTransparency = 1,
})
local label = new("TextLabel", {
BackgroundTransparency = 1,
Size = UDim2.fromScale(1, 1),
Font = Enum.Font.GothamBold,
Text = text,
TextColor3 = theme.AccentAlt,
TextSize = 11,
TextXAlignment = Enum.TextXAlignment.Left,
Parent = frame,
})
return self:_add(frame)
end
function NovaUI:Label(text)
local theme = NovaUI.Theme
local label = new("TextLabel", {
Size = UDim2.new(1, 0, 0, 24),
BackgroundTransparency = 1,
Font = Enum.Font.Gotham,
Text = text,
TextColor3 = theme.Muted,
TextSize = 12,
TextXAlignment = Enum.TextXAlignment.Left,
TextWrapped = true,
})
return self:_add(label)
end
function NovaUI:Button(options)
options = options or {}
local theme = NovaUI.Theme
local button = new("TextButton", {
Size = UDim2.new(1, 0, 0, 40),
BackgroundColor3 = theme.SurfaceAlt,
BorderSizePixel = 0,
Font = Enum.Font.GothamMedium,
Text = options.Text or "Button",
TextColor3 = theme.Text,
TextSize = 13,
})
corner(button, 10)
button.MouseEnter:Connect(function() tween(button, { BackgroundColor3 = theme.Accent }) end)
button.MouseLeave:Connect(function() tween(button, { BackgroundColor3 = theme.SurfaceAlt }) end)
button.Activated:Connect(function()
if typeof(options.Callback) == "function" then
local ok, err = pcall(options.Callback)
if not ok then warn("[NovaUI] Button callback: " .. tostring(err)) end
end
end)
return self:_add(button)
end
function NovaUI:Toggle(options)
options = options or {}
local theme = NovaUI.Theme
local holder = new("Frame", {
Size = UDim2.new(1, 0, 0, 44),
BackgroundColor3 = theme.Surface,
BorderSizePixel = 0,
})
corner(holder, 10)
local label = new("TextLabel", {
BackgroundTransparency = 1,
Position = UDim2.fromOffset(12, 0),
Size = UDim2.new(1, -76, 1, 0),
Font = Enum.Font.GothamMedium,
Text = options.Text or "Toggle",
TextColor3 = theme.Text,
TextSize = 13,
TextXAlignment = Enum.TextXAlignment.Left,
Parent = holder,
})
local switch = new("TextButton", {
BackgroundColor3 = theme.SurfaceAlt,
Position = UDim2.new(1, -60, 0.5, -14),
Size = UDim2.fromOffset(48, 28),
Text = "",
Parent = holder,
})
corner(switch, 14)
local knob = new("Frame", {
BackgroundColor3 = theme.Text,
Position = UDim2.fromOffset(3, 3),
Size = UDim2.fromOffset(22, 22),
Parent = switch,
})
corner(knob, 11)
local state = options.Default == true
local function render()
tween(switch, { BackgroundColor3 = state and theme.Accent or theme.SurfaceAlt })
tween(knob, { Position = state and UDim2.fromOffset(23, 3) or UDim2.fromOffset(3, 3) })
end
local function set(value, fire)
state = value == true
render()
if fire and typeof(options.Callback) == "function" then
local ok, err = pcall(options.Callback, state)
if not ok then warn("[NovaUI] Toggle callback: " .. tostring(err)) end
end
end
switch.Activated:Connect(function() set(not state, true) end)
render()
holder:SetAttribute("NovaValue", state)
self:_add(holder)
return { Set = set, Get = function() return state end }
end
function NovaUI:Slider(options)
options = options or {}
local theme = NovaUI.Theme
local min = options.Min or 0
local max = options.Max or 100
local value = math.clamp(options.Default or min, min, max)
local holder = new("Frame", {
Size = UDim2.new(1, 0, 0, 60),
BackgroundColor3 = theme.Surface,
BorderSizePixel = 0,
})
corner(holder, 10)
local label = new("TextLabel", {
BackgroundTransparency = 1,
Position = UDim2.fromOffset(12, 6),
Size = UDim2.new(1, -80, 0, 20),
Font = Enum.Font.GothamMedium,
Text = options.Text or "Slider",
TextColor3 = theme.Text,
TextSize = 13,
TextXAlignment = Enum.TextXAlignment.Left,
Parent = holder,
})
local readout = new("TextLabel", {
BackgroundTransparency = 1,
Position = UDim2.new(1, -72, 0, 6),
Size = UDim2.fromOffset(60, 20),
Font = Enum.Font.Code,
Text = tostring(value),
TextColor3 = theme.AccentAlt,
TextSize = 12,
TextXAlignment = Enum.TextXAlignment.Right,
Parent = holder,
})
local track = new("Frame", {
BackgroundColor3 = theme.SurfaceAlt,
Position = UDim2.fromOffset(12, 38),
Size = UDim2.new(1, -24, 0, 6),
Parent = holder,
})
corner(track, 3)
local fill = new("Frame", {
BackgroundColor3 = theme.Accent,
Size = UDim2.fromScale((value - min) / math.max(1, max - min), 1),
Parent = track,
})
corner(fill, 3)
local knob = new("Frame", {
BackgroundColor3 = theme.Text,
AnchorPoint = Vector2.new(0.5, 0.5),
Position = UDim2.new((value - min) / math.max(1, max - min), 0, 0.5, 0),
Size = UDim2.fromOffset(12, 12),
Parent = track,
})
corner(knob, 6)
local dragging = false
local function setFromX(x)
local relative = math.clamp((x - track.AbsolutePosition.X) / math.max(1, track.AbsoluteSize.X), 0, 1)
value = min + (max - min) * relative
if options.Step then
value = math.floor(value / options.Step + 0.5) * options.Step
end
value = math.clamp(value, min, max)
local alpha = (value - min) / math.max(1, max - min)
fill.Size = UDim2.fromScale(alpha, 1)
knob.Position = UDim2.new(alpha, 0, 0.5, 0)
readout.Text = tostring(value)
if typeof(options.Callback) == "function" then
local ok, err = pcall(options.Callback, value)
if not ok then warn("[NovaUI] Slider callback: " .. tostring(err)) end
end
end
track.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
dragging = true
setFromX(input.Position.X)
end
end)
table.insert(self._window._connections, UserInputService.InputChanged:Connect(function(input)
if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
setFromX(input.Position.X)
end
end))
table.insert(self._window._connections, UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then dragging = false end
end))
self:_add(holder)
return { Set = function(v) value = math.clamp(v, min, max); setFromX(track.AbsolutePosition.X + track.AbsoluteSize.X * ((value - min) / math.max(1, max - min))) end,
Get = function() return value end }
end
function NovaUI:Dropdown(options)
options = options or {}
local theme = NovaUI.Theme
local items = options.Items or {}
local index = 1
local holder = new("Frame", {
Size = UDim2.new(1, 0, 0, 44),
BackgroundColor3 = theme.Surface,
BorderSizePixel = 0,
})
corner(holder, 10)
local label = new("TextLabel", {
BackgroundTransparency = 1,
Position = UDim2.fromOffset(12, 0),
Size = UDim2.new(0.5, -12, 1, 0),
Font = Enum.Font.GothamMedium,
Text = options.Text or "Option",
TextColor3 = theme.Text,
TextSize = 13,
TextXAlignment = Enum.TextXAlignment.Left,
Parent = holder,
})
local valueButton = new("TextButton", {
BackgroundColor3 = theme.SurfaceAlt,
Position = UDim2.new(0.5, 0, 0.5, -14),
Size = UDim2.new(0.5, -12, 0, 28),
Font = Enum.Font.Code,
Text = tostring(items[index] or "-"),
TextColor3 = theme.AccentAlt,
TextSize = 12,
Parent = holder,
})
corner(valueButton, 8)
valueButton.Activated:Connect(function()
if #items == 0 then return end
index = index % #items + 1
valueButton.Text = tostring(items[index])
if typeof(options.Callback) == "function" then
local ok, err = pcall(options.Callback, items[index], index)
if not ok then warn("[NovaUI] Dropdown callback: " .. tostring(err)) end
end
end)
self:_add(holder)
return { Get = function() return items[index] end, Set = function(i) index = math.clamp(i, 1, math.max(1, #items)); valueButton.Text = tostring(items[index] or "-") end }
end
function NovaUI:Notify(text, duration)
local theme = NovaUI.Theme
local frame = new("Frame", {
AnchorPoint = Vector2.new(1, 0),
Position = UDim2.new(1, -16, 0, 16 + #self._notifications * 44),
Size = UDim2.fromOffset(280, 36),
BackgroundColor3 = theme.Surface,
BorderSizePixel = 0,
Parent = self._root,
})
corner(frame, 10)
stroke(frame, theme.Accent, 0.4)
local label = new("TextLabel", {
BackgroundTransparency = 1,
Position = UDim2.fromOffset(12, 0),
Size = UDim2.new(1, -24, 1, 0),
Font = Enum.Font.GothamMedium,
Text = text,
TextColor3 = theme.Text,
TextSize = 12,
TextXAlignment = Enum.TextXAlignment.Left,
Parent = frame,
})
self._notifications = self._notifications or {}
table.insert(self._notifications, frame)
task.delay(duration or 3, function()
if frame and frame.Parent then
tween(frame, { BackgroundTransparency = 1 })
tween(label, { TextTransparency = 1 })
task.delay(0.2, function() if frame then frame:Destroy() end end)
end
end)
return frame
end
function NovaUI:Destroy()
if self._destroyed then return end
self._destroyed = true
for _, connection in ipairs(self._connections) do
pcall(function() connection:Disconnect() end)
end
self._connections = {}
if self._gui then self._gui:Destroy() end
end
return NovaUI