-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButton.lua
143 lines (125 loc) · 5.54 KB
/
Button.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
local Button = {}
Button.__index = Button
local GV = require(script.Parent.Parent.PluginGlobalVariables)
local util = require(GV.MiscDir.GUIUtil)
local ThemeManager = require(GV.ManagersDir.ThemeManager)
local TextboxMod = require(GV.ObjectsDir.Textbox)
local GUIObject = require(GV.ObjectsDir.GUIObject)
setmetatable(Button,GUIObject)
Button.Images = {
border = "http://www.roblox.com/asset/?id=10460485555",
bg = "http://www.roblox.com/asset/?id=10460051857",
selected = "http://www.roblox.com/asset/?id=10460676787"
}
function Button:SetDisabled(State)
self.Disabled = State
if self.Disabled then
self.CursorIcon = "rbxasset://SystemCursors/Forbidden"
self.Button.ImageTransparency, self.Textbox.TextTransparency = 0.5, 0.5
else
self.CursorIcon = "rbxasset://SystemCursors/PointingHand"
self.Button.ImageTransparency, self.Textbox.TextTransparency = 0, 0
end
end
function Button:ToggleDisable()
self:SetDisabled(not self.Disabled)
end
function Button:Clicked(func)
self.Action = func
end
function Button:Pressed(func)
self.PressedAction = func
end
function Button:Released(func)
self.ReleasedAction = func
end
-- Text/Textbox, ButtonSize, Disabled
function Button.new(Arguments, Parent)
local self = GUIObject.new(Arguments, Parent)
setmetatable(self,Button)
self.TextboxTable = nil
-- creating a frame to hold the button
self.ButtonFrame = Instance.new("Frame", self.Parent)
self.ButtonFrame.BackgroundTransparency = 1
self.ButtonFrame.Name = "ButtonFrame"
self.ButtonFrame.Size = UDim2.new(1,0,1,0)
self.Button = Instance.new("ImageButton", self.ButtonFrame)
-- set up a textbox for the button
local Textbox = self.Arguments.Textbox or self.Arguments.Text
if type(Textbox) == "string" then
self.TextboxTable = TextboxMod.new({Text = Textbox}, self.Button)
else
self.TextboxTable = Textbox
Textbox:Move(self.Button, true)
end
self.Textbox = self.TextboxTable.Textbox
self.Textbox.ZIndex = 1
local Size = util.GetScale(self.Arguments.ButtonSize)
if Size then self.Button.Size = UDim2.new(Size.Scale,Size.Offset,1,0)
else
local function sync()
self.Button.Size = UDim2.new(0,self.Textbox.TextBounds.X+1.5*self.Textbox.TextSize, 1, 0)
end
self.Textbox.Changed:Connect(function(p)
if p == "TextBounds" then sync() end
end)
end
self.Button.Position = UDim2.new(0.5, 0, 0, 0)
self.Button.AnchorPoint = Vector2.new(0.5,0)
self.Button.BackgroundTransparency = 1
self.Button.Image = self.Images.border
ThemeManager.ColorSync(self.Button, "ImageColor3", Enum.StudioStyleGuideColor.DialogButtonBorder)
self.Button.ScaleType = Enum.ScaleType.Slice
self.Button.SliceCenter = Rect.new(7,7,156,36)
self.Button.Name = "Button"
self.ButtonBackground = Instance.new("ImageLabel", self.Button)
self.ButtonBackground.Name = "ButtonBackground"
self.ButtonBackground.BackgroundTransparency = 1
self.ButtonBackground.Size = UDim2.new(1,0,1,0)
self.ButtonBackground.Image = self.Images.bg
ThemeManager.ColorSync(self.ButtonBackground, "ImageColor3", Enum.StudioStyleGuideColor.Button)
self.ButtonBackground.ScaleType = Enum.ScaleType.Slice
self.ButtonBackground.SliceCenter = Rect.new(7,7,156,36)
self.ButtonBackground.ZIndex = 0
self.Toggleable = false
local Pressed = false
self.Button.MouseMoved:Connect(function()
GV.PluginObject:GetMouse().Icon = self.CursorIcon
if self.Disabled or Pressed or self.Toggleable then return end
ThemeManager.ColorSync(self.Button, "ImageColor3", Enum.StudioStyleGuideColor.ButtonBorder, Enum.StudioStyleGuideModifier.Hover)
ThemeManager.ColorSync(self.ButtonBackground, "ImageColor3", Enum.StudioStyleGuideColor.Button, Enum.StudioStyleGuideModifier.Hover)
end)
self.Button.MouseLeave:Connect(function()
task.wait(0)
GV.PluginObject:GetMouse().Icon = "rbxasset://SystemCursors/Arrow"
if self.Disabled or self.Toggleable then return end
if Pressed and self.ReleasedAction then self.ReleasedAction() end
Pressed = false
ThemeManager.ColorSync(self.Button, "ImageColor3", Enum.StudioStyleGuideColor.ButtonBorder)
ThemeManager.ColorSync(self.ButtonBackground, "ImageColor3", Enum.StudioStyleGuideColor.Button)
end)
self.Button.MouseButton1Down:Connect(function()
if self.Disabled or self.Toggleable then return end
if self.PressedAction then self.PressedAction() end
Pressed = true
ThemeManager.ColorSync(self.Button, "ImageColor3", Enum.StudioStyleGuideColor.ButtonBorder, Enum.StudioStyleGuideModifier.Pressed)
ThemeManager.ColorSync(self.ButtonBackground, "ImageColor3", Enum.StudioStyleGuideColor.Button, Enum.StudioStyleGuideModifier.Pressed)
end)
self.Button.MouseButton1Up:Connect(function()
if self.Disabled or self.Toggleable then return end
if self.ReleasedAction then self.ReleasedAction() end
Pressed = false
ThemeManager.ColorSync(self.Button, "ImageColor3", Enum.StudioStyleGuideColor.ButtonBorder)
ThemeManager.ColorSync(self.ButtonBackground, "ImageColor3", Enum.StudioStyleGuideColor.Button)
end)
self.Button.MouseButton1Click:Connect(function()
if not self.Disabled then
if self.Action then self.Action(self.Value) end
end
end)
self:SetDisabled(self.Arguments.Disabled)
self.Object = self.Button
self.MainMovable = self.ButtonFrame
return self
end
return Button