-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuimodule.luau
More file actions
288 lines (202 loc) · 6.12 KB
/
uimodule.luau
File metadata and controls
288 lines (202 loc) · 6.12 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
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer.PlayerGui
local Libs = ReplicatedStorage.Libs
local PickRandom = require(Libs.PickRandom)
local DeepCopyTable = require(Libs.DeepCopyTable)
local UISounds = SoundService.UI
local Open = UISounds.Open
local Close = UISounds.Close
local Switch = UISounds.Switch
local UiModule = {}
UiModule.__index = UiModule
export type Tab = TextButton
export type Window = Frame & {
Close: GuiButton
}
export type TabWindow = Window & {Frame | ScrollingFrame} & {
Tabs: Frame & {Tab}
}
function UiModule.new(): typeof(UiModule)
local new = setmetatable({}, UiModule)
new.config = {
["window"] = {
tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back),
open = UDim2.new(0.5, 0, 0.5, 0),
close = UDim2.new(0.5, 0, -1, 0),
},
["button"] = {
buttonInfo = TweenInfo.new(1, Enum.EasingStyle.Back),
}
}
return new
end
function UiModule:IntializeButton(button: GuiButton)
if button:GetAttribute("Intialize") then
return
end
button:SetAttribute("Intialize", true)
local TargetSize = button.Size
local debounce = false
local CurrentTween
local hovering = false
local function pressed(x, y)
if debounce == true then
CurrentTween:Cancel()
end
debounce = true
TargetSize = TargetSize - UDim2.new(0, 10, 0, 10)
local PressedTween = TweenService:Create(button, self.config.button.buttonInfo,{Size = TargetSize})
PressedTween.Completed:Once(function(playbackState)
if playbackState == Enum.PlaybackState.Cancelled then
button.Size = TargetSize
else
debounce = false
end
end)
PressedTween:Play()
CurrentTween = PressedTween
end
local function unpressed(x, y)
if debounce == true then
CurrentTween:Cancel()
end
debounce = true
TargetSize = TargetSize + UDim2.new(0, 10, 0, 10)
local UnpressedTween = TweenService:Create(button, self.config.button.buttonInfo,{Size = TargetSize})
UnpressedTween.Completed:Once(function(playbackState)
if playbackState == Enum.PlaybackState.Cancelled then
button.Size = TargetSize
else
debounce = false
end
end)
UnpressedTween:Play()
CurrentTween = UnpressedTween
end
local function enter(x, y)
if debounce == true then
CurrentTween:Cancel()
end
debounce = true
if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
pressed(x, y)
end
TargetSize = TargetSize + UDim2.new(0, 5, 0, 5)
local EnterTween = TweenService:Create(button, self.config.button.buttonInfo,{Size = TargetSize})
EnterTween.Completed:Once(function(playbackState)
if playbackState == Enum.PlaybackState.Cancelled then
button.Size = TargetSize
else
debounce = false
end
end)
EnterTween:Play()
CurrentTween = EnterTween
end
local function unenter(x, y)
if debounce == true then
CurrentTween:Cancel()
end
debounce = true
if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
unpressed(x, y)
end
TargetSize = TargetSize - UDim2.new(0, 5, 0, 5)
local UnenterTween = TweenService:Create(button, self.config.button.buttonInfo,{Size = TargetSize})
UnenterTween.Completed:Once(function(playbackState)
if playbackState == Enum.PlaybackState.Cancelled then
button.Size = TargetSize
else
debounce = false
end
end)
UnenterTween:Play()
CurrentTween = UnenterTween
end
button.MouseEnter:Connect(enter)
button.MouseLeave:Connect(unenter)
button.MouseButton1Down:Connect(pressed)
button.MouseButton1Up:Connect(unpressed)
end
function UiModule:IsWindowVisible(window: Window | Frame)
if window.Position == self.config.window.open then
return true
elseif window.Position == self.config.window.close then
return false
else
return true
end
end
function UiModule:CloseWindow(window: Window | Frame)
local close = TweenService:Create(window, self.config.window.tweenInfo, {["Position"] = self.config.window.close})
close:Play()
PickRandom(Close:GetChildren()):Play()
end
function UiModule:CloseAllWindows()
for i, v in ipairs(PlayerGui.Main:GetChildren()) do
if v:GetAttribute("Window") == true then
if self:IsWindowVisible(v) == true then
self:CloseWindow(v)
end
end
end
end
function UiModule:OpenWindow(window: Window | Frame)
if window:GetAttribute("Window") == true then
self:CloseAllWindows()
end
local open = TweenService:Create(window, self.config.window.tweenInfo, {["Position"] = self.config.window.open})
open:Play()
PickRandom(Open:GetChildren()):Play()
end
function UiModule:ToggleWindow(window: Window | Frame)
local visible = self:IsWindowVisible(window)
if visible then
self:CloseWindow(window)
else
self:OpenWindow(window)
end
end
function UiModule:IntializeWindow(window: Window)
window:SetAttribute("Window", true)
self:IntializeButton(window.Close)
window.Close.MouseButton1Click:Connect(function()
self:CloseWindow(window)
end)
end
function UiModule:IntializeWindowButton(window: Window, button: GuiButton)
self:IntializeButton(button)
button.MouseButton1Click:Connect(function()
self:ToggleWindow(window)
end)
end
function UiModule:IntializeTabWindow(window: TabWindow, CurrentTab: Tab)
self:IntializeWindow(window)
local Tabs = window.Tabs
for i, frame in ipairs(window:GetChildren()) do
if frame.Name ~= "Tabs" and frame:IsA("Frame") or frame:IsA("ScrollingFrame") then
frame.Visible = false
end
end
window[CurrentTab.Name .. "List"].Visible = true
for i, tab in ipairs(Tabs:GetChildren()) do
if tab:IsA("TextButton") then
tab.MouseButton1Click:Connect(function()
PickRandom(Switch:GetChildren()):Play()
CurrentTab = tab
for i, frame in ipairs(window:GetChildren()) do
if frame.Name ~= "Tabs" and frame:IsA("Frame") or frame:IsA("ScrollingFrame") then
frame.Visible = false
end
end
window[CurrentTab.Name .. "List"].Visible = true
end)
end
end
end
return UiModule