-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathUI.lua
More file actions
81 lines (73 loc) · 2.44 KB
/
UI.lua
File metadata and controls
81 lines (73 loc) · 2.44 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
-- \\ Services // --
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
-- \\ Variables // --
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Module = {
Color = {
Add = function(c1: Color3, c2: Color3): Color3
local r = math.min((c1.R + c2.R) * 255, 255)
local g = math.min((c1.G + c2.G) * 255, 255)
local b = math.min((c1.B + c2.B) * 255, 255)
return Color3.fromRGB(r, g, b)
end,
Sub = function(c1: Color3, c2: Color3): Color3
local r = math.max((c1.R - c2.R) * 255, 0)
local g = math.max((c1.G - c2.G) * 255, 0)
local b = math.max((c1.B - c2.B) * 255, 0)
return Color3.fromRGB(r, g, b)
end,
ToFormat = function(c: Color3): string
local r = math.floor(math.min(c.R * 255, 255))
local g = math.floor(math.min(c.G * 255, 255))
local b = math.floor(math.min(c.B * 255, 255))
return ("rgb(%d, %d, %d)"):format(r, g, b)
end
}
}
-- \\ Main // --
Module.Create = function(class: string, properties: any, radius: number): Instance
local instance = Instance.new(class)
for i, v in next, properties do
if i ~= "Parent" then
if typeof(v) == "Instance" then
v.Parent = instance
else
instance[i] = v
end
end
end
if radius then
local uicorner = Instance.new("UICorner", instance)
uicorner.CornerRadius = radius
end
return instance
end
Module.MakeDraggable = function(obj: Instance, dragObj: Instance, smoothness: number)
local startPos = nil
local dragging = false
dragObj.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
dragging = true
startPos = Vector2.new(Mouse.X - obj.AbsolutePosition.X, Mouse.Y - obj.AbsolutePosition.Y)
end
end)
dragObj.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
dragging = false
end
end)
Mouse.Move:Connect(function()
if dragging then
TweenService:Create(
obj,
TweenInfo.new(math.clamp(smoothness, 0, 1), Enum.EasingStyle.Sine),
{
Position = UDim2.new(0, Mouse.X - startPos.X, 0, Mouse.Y - startPos.Y)
}
):Play()
end
end)
end
return Module