-
Notifications
You must be signed in to change notification settings - Fork 9
/
ConfirmationDialog.lua
241 lines (203 loc) · 7.67 KB
/
ConfirmationDialog.lua
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
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TextService = game:GetService("TextService")
local UserInputService = game:GetService("UserInputService")
local Resources = require(ReplicatedStorage:WaitForChild("Resources"))
local Color = Resources:LoadLibrary("Color")
local Tween = Resources:LoadLibrary("Tween")
local Typer = Resources:LoadLibrary("Typer")
local Enumeration = Resources:LoadLibrary("Enumeration")
local PseudoInstance = Resources:LoadLibrary("PseudoInstance")
local RoStrapPriorityUI = Resources:LoadLibrary("RoStrapPriorityUI")
Resources:LoadLibrary("ReplicatedPseudoInstance")
Resources:LoadLibrary("Shadow")
Resources:LoadLibrary("RippleButton")
Resources:LoadLibrary("EasingFunctions")
local BUTTON_WIDTH_PADDING = 8
local WIDTH = UserInputService.TouchEnabled and 460 or 560
local FRAME_SIZE = Vector2.new(WIDTH - 48, 1 / 0)
local NEW_SIZE = UDim2.new(0, WIDTH, 0, 182)
local Left = Enum.TextXAlignment.Left.Value
local SourceSans = Enum.Font.SourceSans.Value
local Flat = Enumeration.ButtonStyle.Flat.Value
local Acceleration = Enumeration.EasingFunction.Acceleration.Value
local Deceleration = Enumeration.EasingFunction.Deceleration.Value
local LocalPlayer, PlayerGui do
if RunService:IsClient() then
if RunService:IsServer() then
PlayerGui = game:GetService("CoreGui")
else
repeat LocalPlayer = Players.LocalPlayer until LocalPlayer or not wait()
repeat PlayerGui = LocalPlayer:FindFirstChildOfClass("PlayerGui") until PlayerGui or not wait()
end
end
end
local Frame do
Frame = Instance.new("Frame")
Frame.BackgroundTransparency = 1
Frame.BackgroundColor3 = Color3.new()
Frame.Position = UDim2.new(0.5, 0, 0.5, 0)
Frame.AnchorPoint = Vector2.new(0.5, 0.5)
Frame.Size = UDim2.new(1, 0, 1, 0)
Frame.Name = "ConfirmationDialog"
local UIScale = Instance.new("UIScale")
UIScale.Scale = 0
UIScale.Name = "UIScale"
UIScale.Parent = Frame
local Background = Instance.new("ImageLabel")
Background.BackgroundTransparency = 1
Background.ScaleType = Enum.ScaleType.Slice
Background.SliceCenter = Rect.new(4, 4, 256 - 4, 256 - 4)
Background.Image = "rbxassetid://1934624205"
Background.Size = NEW_SIZE
Background.Position = UDim2.new(0.5, 0, 0.5, 0)
Background.AnchorPoint = Vector2.new(0.5, 0.5)
Background.Name = "Background"
Background.ZIndex = 2
Background.Parent = Frame
local Header = Instance.new("TextLabel")
Header.Font = Enum.Font.SourceSansSemibold
Header.TextSize = 26
Header.Size = UDim2.new(1, -24, 0, 64)
Header.Position = UDim2.new(0, 24, 0, 1)
Header.BackgroundTransparency = 1
Header.TextXAlignment = Left
Header.TextTransparency = 0.13
Header.TextColor3 = Color.Black
Header.Name = "Header"
Header.ZIndex = 3
Header.Parent = Background
local DialogText = Instance.new("TextLabel")
DialogText.BackgroundTransparency = 1
DialogText.Name = "PrimaryText"
DialogText.Position = UDim2.new(0, 24, 0, 40)
DialogText.Size = UDim2.new(1, -24, 0, 64)
DialogText.ZIndex = 3
DialogText.TextSize = 20
DialogText.Font = SourceSans
DialogText.TextXAlignment = Left
DialogText.TextTransparency = 0.4
DialogText.TextColor3 = Color.Black
DialogText.TextWrapped = true
DialogText.Parent = Background
local Shadow = PseudoInstance.new("Shadow")
Shadow.Elevation = 8
Shadow.Parent = Background
end
local function OnDismiss(self)
if not self.Dismissed then
self:Dismiss()
self.OnConfirmed:Fire(LocalPlayer, false)
end
end
local function OnConfirm(self)
if not self.Dismissed then
self:Dismiss()
self.OnConfirmed:Fire(LocalPlayer, true)
end
end
local DialogsActive = 0
local function SubDialogsActive()
DialogsActive = DialogsActive - 1
end
local function AdjustButtonSize(Button)
Button.Size = UDim2.new(0, Button.TextBounds.X + BUTTON_WIDTH_PADDING * 2, 0, 36)
end
local function HideUIScale(self)
self.UIScale.Parent = nil
end
local function RescaleUI(self, Text)
local PrimaryText = self.Object.Background.PrimaryText
if Text then
local TextSize = TextService:GetTextSize(Text, 20, SourceSans, FRAME_SIZE).Y
local SizeY = TextSize + 4 < 64 and 64 or TextSize + 4
self.Object.Background.Size = UDim2.new(0, WIDTH, 0, TextSize + 40 + 52 + 24)
PrimaryText.Size = UDim2.new(1, -24, 0, SizeY)
PrimaryText.Position = UDim2.new(0, 24, 0, SizeY == 64 and 40 or 40 + (SizeY - 64))
else
local TextSize = TextService:GetTextSize(PrimaryText.Text, 20, SourceSans, FRAME_SIZE).Y
local SizeY = TextSize + 4 < 64 and 64 or TextSize + 4
self.Object.Background.Size = UDim2.new(0, WIDTH, 0, TextSize + 40 + 52 + 24)
PrimaryText.Size = UDim2.new(1, -24, 0, SizeY)
PrimaryText.Position = UDim2.new(0, 24, 0, SizeY == 64 and 40 or 40 + (SizeY - 64))
end
end
return PseudoInstance:Register("ConfirmationDialog", {
Storage = {};
Internals = {
"ConfirmButton", "DismissButton", "UIScale";
SHOULD_BLUR = true;
};
Events = {"OnConfirmed"};
Methods = {
Enter = function(self)
RescaleUI(self)
self.UIScale.Parent = self.Object
self.Object.Parent = self.SCREEN
AdjustButtonSize(self.DismissButton)
AdjustButtonSize(self.ConfirmButton)
Tween(self.UIScale, "Scale", 1, Deceleration, self.ENTER_TIME, true, HideUIScale, self)
end;
Dismiss = function(self)
-- Destroys Dialog when done
if not self.Dismissed then
self.Dismissed = true
Tween(self.UIScale, "Scale", 0, Acceleration, self.DISMISS_TIME, true, self.Janitor)
self.UIScale.Parent = self.Object
self:Unblur()
end
end;
};
Properties = {
PrimaryColor3 = Typer.AssignSignature(2, Typer.Color3, function(self, PrimaryColor3)
self.ConfirmButton.PrimaryColor3 = PrimaryColor3
self.DismissButton.PrimaryColor3 = PrimaryColor3
self:rawset("PrimaryColor3", PrimaryColor3)
end);
HeaderText = Typer.AssignSignature(2, Typer.String, function(self, Text)
self.Object.Background.Header.Text = Text
self:rawset("HeaderText", Text)
end);
DialogText = Typer.AssignSignature(2, Typer.String, function(self, Text)
RescaleUI(self, Text)
self.Object.Background.PrimaryText.Text = Text
self:rawset("DialogText", Text)
end);
DismissText = Typer.AssignSignature(2, Typer.String, function(self, Text)
self.DismissButton.Text = Text
self:rawset("DismissText", Text)
end);
ConfirmText = Typer.AssignSignature(2, Typer.String, function(self, Text)
self.ConfirmButton.Text = Text
self:rawset("ConfirmText", Text)
end);
};
Init = function(self, ...)
self:rawset("Object", Frame:Clone())
self.UIScale = self.Object.UIScale
local ConfirmButton = PseudoInstance.new("RippleButton")
ConfirmButton.AnchorPoint = Vector2.new(1, 1)
ConfirmButton.Position = UDim2.new(1, -8, 1, -8)
ConfirmButton.BorderRadius = 4
ConfirmButton.ZIndex = 10
ConfirmButton.TextSize = 16
ConfirmButton.TextTransparency = 0.129
ConfirmButton.Style = Flat
ConfirmButton.Parent = self.Object.Background
local DismissButton = ConfirmButton:Clone()
DismissButton.Position = UDim2.new(0, -8, 1, 0)
DismissButton.Parent = ConfirmButton.Object
self.Janitor:Add(DismissButton:GetPropertyChangedSignal("TextBounds"):Connect(AdjustButtonSize, DismissButton), "Disconnect")
self.Janitor:Add(ConfirmButton:GetPropertyChangedSignal("TextBounds"):Connect(AdjustButtonSize, ConfirmButton), "Disconnect")
self.ConfirmButton = ConfirmButton
self.DismissButton = DismissButton
self.Janitor:Add(ConfirmButton.OnPressed:Connect(OnConfirm, self), "Disconnect")
self.Janitor:Add(DismissButton.OnPressed:Connect(OnDismiss, self), "Disconnect")
self.Janitor:Add(self.UIScale, "Destroy")
self.Janitor:Add(self.Object, "Destroy")
self.Janitor:Add(SubDialogsActive, true)
self.PrimaryColor3 = Color3.fromRGB(98, 0, 238)
self:superinit(...)
end;
}, RoStrapPriorityUI)