-
Notifications
You must be signed in to change notification settings - Fork 9
/
Radio.lua
142 lines (114 loc) · 4.6 KB
/
Radio.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
-- Material Design Radio Button PseudoInstance
-- @author Validark
local ContentProvider = game:GetService("ContentProvider")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
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 SelectionController = Resources:LoadLibrary("SelectionController")
local CHECKED_IMAGE = "rbxassetid://2012883990"
local UNCHECKED_IMAGE = "rbxassetid://2012883770"
local DEFAULT_SIZE = UDim2.new(0, 24, 0, 24)
local RadioButton = Instance.new("ImageButton")
RadioButton.BackgroundTransparency = 1
RadioButton.Size = DEFAULT_SIZE
RadioButton.Image = UNCHECKED_IMAGE
RadioButton.ImageColor3 = Color.Black
RadioButton.ImageTransparency = 0.46
local CLICK_RIPPLE_TRANSPARENCY = 0.77
local HOVER_RIPPLE_TRANSPARENCY = 0.93
local ANIMATION_TIME = 0.1 -- 0.125
local Circle = Instance.new("ImageLabel")
Circle.AnchorPoint = Vector2.new(0.5, 0.5)
Circle.BackgroundTransparency = 1
Circle.ImageTransparency = 1
Circle.Position = UDim2.new(0.5, 0, 0.5, 0)
Circle.Size = UDim2.new(1, 0, 1, 0)
Circle.Image = "rbxassetid://517259585"
Circle.Name = "InnerCircle"
Circle.Parent = RadioButton
local RippleCheckedSize = UDim2.new(10 / 24, 0, 10 / 24, 0)
local RippleUncheckedSize = UDim2.new(20 / 24, 0, 20 / 24, 0)
spawn(function()
ContentProvider:PreloadAsync{CHECKED_IMAGE, UNCHECKED_IMAGE}
end)
local Deceleration = Enumeration.EasingFunction.Deceleration.Value
return PseudoInstance:Register("Radio", {
WrappedProperties = {
Button = {"AnchorPoint", "Name", "Parent", "Size", "Position", "LayoutOrder", "NextSelectionDown", "NextSelectionLeft", "NextSelectionRight", "NextSelectionUp"};
};
Internals = {
"InnerCircle";
RippleCheckedFinished = function(self, TweenStatus)
if TweenStatus == Enum.TweenStatus.Completed then
self.Button.Image = CHECKED_IMAGE
self.InnerCircle.Visible = false
end
end;
SetColorAndTransparency = function(self, Color3, Transparency)
local Opacity = (1 - Transparency)
self.HoverRippler.RippleColor3 = Color3
self.ClickRippler.RippleColor3 = Color3
self.HoverRippler.RippleTransparency = Opacity * HOVER_RIPPLE_TRANSPARENCY + Transparency
self.ClickRippler.RippleTransparency = Opacity * CLICK_RIPPLE_TRANSPARENCY + Transparency
self.Button.ImageTransparency = Transparency
self.Button.ImageColor3 = Color3
end;
};
Properties = {
Checked = Typer.AssignSignature(2, Typer.Boolean, function(self, Checked)
if Checked then
self:SetColorAndTransparency(self.PrimaryColor3, 0)
self.Button.Image = CHECKED_IMAGE
else
local MyTheme = self.Themes[self.Theme.Value]
self:SetColorAndTransparency(MyTheme.ImageColor3, MyTheme.ImageTransparency)
self.Button.Image = UNCHECKED_IMAGE
end
self:rawset("Checked", Checked)
self.OnChecked:Fire(Checked)
end);
ZIndex = Typer.AssignSignature(2, Typer.Number, function(self, ZIndex)
self.Button.ZIndex = ZIndex
self.InnerCircle.ZIndex = ZIndex
self:rawset("ZIndex", ZIndex)
end);
};
Methods = {
SetChecked = Typer.AssignSignature(2, Typer.OptionalBoolean, function(self, Checked)
if self.Disabled then return true end
if Checked == nil then Checked = true end
local Changed = self.Checked == Checked == false
if Changed then
local Button = self.Button
local InnerCircle = self.InnerCircle
InnerCircle.ImageColor3 = self.PrimaryColor3
InnerCircle.Visible = true
if Checked then
self:SetColorAndTransparency(self.PrimaryColor3, 0)
Tween(InnerCircle, "Size", RippleCheckedSize, Deceleration, ANIMATION_TIME, true)
Tween(InnerCircle, "ImageTransparency", 0, Deceleration, ANIMATION_TIME * 0.8, true, self.RippleCheckedFinished, self)
else
local MyTheme = self.Themes[self.Theme.Value]
self:SetColorAndTransparency(MyTheme.ImageColor3, MyTheme.ImageTransparency)
Button.Image = UNCHECKED_IMAGE
Tween(InnerCircle, "Size", RippleUncheckedSize, Deceleration, ANIMATION_TIME, true)
Tween(InnerCircle, "ImageTransparency", 1, Deceleration, ANIMATION_TIME * 2, true)
end
end
self:rawset("Checked", Checked)
self.OnChecked:Fire(Checked)
end);
};
Init = function(self)
self.Button = RadioButton:Clone()
self:rawset("Object", self.Button)
self.InnerCircle = self.Button.InnerCircle
self.Janitor:Add(self.Button, "Destroy")
self.Janitor:Add(self.InnerCircle, "Destroy")
self:superinit()
end;
}, SelectionController)