-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewButton.lua
291 lines (277 loc) · 15 KB
/
ViewButton.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
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
289
290
291
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local GuiService = game:GetService("GuiService")
local ViewButton = {}
ViewButton.__index = ViewButton
local GV = require(script.Parent.Parent.PluginGlobalVariables)
local util = require(GV.MiscDir.GUIUtil)
local TitlebarButton = require(GV.ObjectsDir.TitlebarButton)
local InputPrompt = require(GV.PromptsDir.InputPrompt)
local InputField = require(GV.ObjectsDir.InputField)
local ColorInput = require(GV.ObjectsDir.ColorInput)
local Labeled = require(GV.ObjectsDir.Labeled)
local TextPrompt = require(GV.PromptsDir.TextPrompt)
local PluginWidget = require(GV.FramesDir.PluginWidget)
local LayoutManager = require(GV.ManagersDir.LayoutManager)
local ThemeManager = require(GV.ManagersDir.ThemeManager)
setmetatable(ViewButton,TitlebarButton)
local RefreshedMenus = {}
function ViewButton:CreateThemeEditor(func)
local NewThemePrompt = TextPrompt.new({Title = "Edit Theme", Buttons = {"Save", "Cancel"}, NoPause = true})
local ThemeColorInput = Labeled.new({
Object = ColorInput.new({
Color = ThemeManager.DefaultThemeColor,
NoPause = true
}),
Text = "Theme Color",
LabelSize = 0.5
},
NewThemePrompt.TextPromptContainer)
ThemeColorInput.Object:SetValue(ThemeManager.ThemeColor)
ThemeColorInput.Object:Changed(function(p)
ThemeManager.ReloadTheme(p, ThemeManager.CurrentAccent)
end)
ThemeColorInput.MainFrame.Size = UDim2.new(1,0,0,28)
local AccentColorInput = Labeled.new({
Object = ColorInput.new({
Color = ThemeManager.DefaultAccentColor,
NoPause = true
}),
Text = "Accent Color",
LabelSize = 0.5
},
NewThemePrompt.TextPromptContainer)
AccentColorInput.Object:SetValue(ThemeManager.AccentColor)
AccentColorInput.Object:Changed(function(p)
ThemeManager.ReloadTheme(ThemeManager.CurrentTheme, p)
end)
AccentColorInput.MainFrame.Size = UDim2.new(1,0,0,28)
NewThemePrompt.Textbox:Destroy()
NewThemePrompt.TextFrame.Size = UDim2.new(0,0,0,10)
NewThemePrompt.ButtonsFrame.Parent = nil
NewThemePrompt.ButtonsFrame.Parent = NewThemePrompt.TextPromptContainer
NewThemePrompt:Clicked(function(p) if func then func(p) end end)
end
function ViewButton:LoadWidgetOption(Widget, i)
local WidgetTitle = Widget.WidgetObject.Title
local WidgetMenuObject = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), tostring(i) .. ': "' .. WidgetTitle .. '"')
WidgetMenuObject.Name = '"' .. WidgetTitle .. '" Widget Menu'
local ToggleAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Toggle", "", nil, false)
local RenameAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Rename", "", nil, false)
local DeleteAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Delete", "", nil, false)
ToggleAction.Triggered:Connect(function()
Widget.WidgetObject.Enabled = not Widget.WidgetObject.Enabled
end)
RenameAction.Triggered:Connect(function()
Widget:Rename()
end)
DeleteAction.Triggered:Connect(function()
Widget:Delete()
end)
WidgetMenuObject:AddAction(ToggleAction)
WidgetMenuObject:AddAction(RenameAction)
WidgetMenuObject:AddSeparator()
WidgetMenuObject:AddAction(DeleteAction)
ToggleAction.Parent = WidgetMenuObject
RenameAction.Parent = WidgetMenuObject
DeleteAction.Parent = WidgetMenuObject
return WidgetMenuObject
end
function ViewButton:LoadLayoutOption(Layout, i)
if not Layout.Name then Layout.Name = "Unnamed" end
local SavedLayouts = GV.PluginObject:GetSetting(GV.PluginID.."SavedGUILayouts") or {}
local LayoutMenuObject = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), tostring(i) .. ': "' .. Layout.Name .. '"')
LayoutMenuObject.Name = '"' .. Layout.Name .. '" Layout Menu'
local UseLayoutAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Use", "", nil, false)
local SaveAsAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Save As", "", nil, false)
local RenameAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Rename", "", nil, false)
local DeleteAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Delete", "", nil, false)
UseLayoutAction.Triggered:Connect(function()
local OverridePrompt = TextPrompt.new({Title = "Override Layout", Text = "Are you sure you want to override the current GUI layout?", Buttons = {"Yes", "No"}})
OverridePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
LayoutManager.RecallLayout(Layout)
end)
end)
SaveAsAction.Triggered:Connect(function()
local CurrentLayout = LayoutManager.GetLayout()
CurrentLayout.Name = Layout.Name
SavedLayouts[i] = CurrentLayout
GV.PluginObject:SetSetting(GV.PluginID.."SavedGUILayouts", SavedLayouts)
end)
RenameAction.Triggered:Connect(function()
local RenamePrompt = InputPrompt.new({Title = "Rename Layout ", Text = "Type in a new name:", Buttons = {"OK", "Cancel"}, InputField = InputField.new({Placeholder = "New name", Value = Layout.Name, NoDropdown = true, Unpausable = true})})
RenamePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
Layout.Name = RenamePrompt.Input.Text
SavedLayouts[i] = Layout
GV.PluginObject:SetSetting(GV.PluginID.."SavedGUILayouts", SavedLayouts)
end)
end)
DeleteAction.Triggered:Connect(function()
local DeletePrompt = TextPrompt.new({Title = "Delete " .. Layout.Name, Text = 'Are you sure you want to delete "' .. Layout.Name .. '"?', Buttons = {"Yes", "No"}})
DeletePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
table.remove(SavedLayouts, i)
GV.PluginObject:SetSetting(GV.PluginID.."SavedGUILayouts", SavedLayouts)
end)
end)
LayoutMenuObject:AddAction(UseLayoutAction)
LayoutMenuObject:AddAction(SaveAsAction)
LayoutMenuObject:AddAction(RenameAction)
LayoutMenuObject:AddSeparator()
LayoutMenuObject:AddAction(DeleteAction)
UseLayoutAction.Parent = LayoutMenuObject
SaveAsAction.Parent = LayoutMenuObject
RenameAction.Parent = LayoutMenuObject
DeleteAction.Parent = LayoutMenuObject
return LayoutMenuObject
end
function ViewButton:LoadThemeOption(Theme, i)
local SavedThemes = GV.PluginObject:GetSetting("SavedGUIThemes") or ThemeManager.PreinstalledThemes
local ThemeMenuObject = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), tostring(i) .. ': "' .. Theme.Name .. '"')
ThemeMenuObject.Name = '"' .. Theme.Name .. '" Theme Menu'
local UseThemeAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Use", "", nil, false)
local EditAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Edit", "", nil, false)
local RenameAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Rename", "", nil, false)
local DeleteAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Delete", "", nil, false)
UseThemeAction.Triggered:Connect(function()
local OverridePrompt = TextPrompt.new({Title = "Override Theme", Text = "Are you sure you want to override the current GUI theme?", Buttons = {"Yes", "No"}})
OverridePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
ThemeManager.UpdateTheme(util.TableToColor3(Theme.Theme), util.TableToColor3(Theme.Accent))
end)
end)
EditAction.Triggered:Connect(function()
self:CreateThemeEditor(function(p)
if p == 2 or p == 0 then ThemeManager.ReloadTheme(ThemeManager.ThemeColor, ThemeManager.AccentColor) return end
ThemeManager.UpdateTheme()
SavedThemes[i] = {["Name"] = Theme.Name, ["Theme"] = util.Color3ToTable(ThemeManager.ThemeColor), ["Accent"] = util.Color3ToTable(ThemeManager.AccentColor)}
GV.PluginObject:SetSetting("SavedGUIThemes", SavedThemes)
end)
end)
RenameAction.Triggered:Connect(function()
local RenamePrompt = InputPrompt.new({Title = "Rename Theme", Text = "Type in a new name:", Buttons = {"OK", "Cancel"}, InputField = InputField.new({Placeholder = "New name", Value = Theme.Name, NoDropdown = true, Unpausable = true})})
RenamePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
Theme.Name = RenamePrompt.Input.Text
SavedThemes[i] = Theme
GV.PluginObject:SetSetting("SavedGUIThemes", SavedThemes)
end)
end)
DeleteAction.Triggered:Connect(function()
local DeletePrompt = TextPrompt.new({Title = "Delete " .. Theme.Name, Text = 'Are you sure you want to delete "' .. Theme.Name .. '"?', Buttons = {"Yes", "No"}})
DeletePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
table.remove(SavedThemes, i)
GV.PluginObject:SetSetting("SavedGUIThemes", SavedThemes)
end)
end)
ThemeMenuObject:AddAction(UseThemeAction)
ThemeMenuObject:AddAction(EditAction)
ThemeMenuObject:AddAction(RenameAction)
ThemeMenuObject:AddSeparator()
ThemeMenuObject:AddAction(DeleteAction)
UseThemeAction.Parent = ThemeMenuObject
EditAction.Parent = ThemeMenuObject
RenameAction.Parent = ThemeMenuObject
DeleteAction.Parent = ThemeMenuObject
return ThemeMenuObject
end
function ViewButton:CreateMenu()
self.PluginMenu = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), "View Menu")
self.PluginMenu.Name = "View Menu"
-- Saved Layouts Menu
self.LayoutsMenu = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), "Layouts")
self.LayoutsMenu.Name = "Layout Menu"
local SaveCurrentLayout = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Save Layout", "", nil, false)
SaveCurrentLayout.Triggered:Connect(function()
local SavedLayouts = GV.PluginObject:GetSetting(GV.PluginID.."SavedGUILayouts") or {}
local NamePrompt = InputPrompt.new({Title = "Name Layout ", Text = "Type in a name for this layout:", Buttons = {"OK", "Cancel"}, InputField = InputField.new({Placeholder = "New name", NoDropdown = true, Unpausable = true})})
NamePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
local NewLayout = LayoutManager.GetLayout()
NewLayout.Name = NamePrompt.Input.Text
SavedLayouts[#SavedLayouts+1] = NewLayout
GV.PluginObject:SetSetting(GV.PluginID.."SavedGUILayouts", SavedLayouts)
end)
end)
local ResetLayoutAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Reset Layout", "", nil, false)
ResetLayoutAction.Triggered:Connect(function()
local OverridePrompt = TextPrompt.new({Title = "Override Layout", Text = "Are you sure you want to override the current GUI layout?", Buttons = {"Yes", "No"}})
OverridePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
LayoutManager.ResetLayout()
end)
end)
self.LayoutsMenu:AddAction(SaveCurrentLayout)
self.LayoutsMenu:AddAction(ResetLayoutAction)
self.LayoutsMenu:AddSeparator()
SaveCurrentLayout.Parent = self.LayoutsMenu
ResetLayoutAction.Parent = self.LayoutsMenu
self.PluginMenu:AddMenu(self.LayoutsMenu)
-- Widgets Menu
self.WidgetsMenu = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), "Widgets")
self.WidgetsMenu.Name = "Widget Menu"
local CreateNewWindowAction = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "Create New Window", "", nil, false)
CreateNewWindowAction.Triggered:Connect(function()
PluginWidget.new({Enabled = true})
end)
self.WidgetsMenu:AddAction(CreateNewWindowAction)
self.WidgetsMenu:AddSeparator()
CreateNewWindowAction.Parent = self.WidgetsMenu
self.LayoutsMenu:AddMenu(self.WidgetsMenu)
self.LayoutsMenu:AddSeparator()
-- Appearance/Themes
self.ThemesMenu = GV.PluginObject:CreatePluginMenu(game:GetService("HttpService"):GenerateGUID(false), "Themes")
self.ThemesMenu.Name = "Themes Menu"
local NewTheme = GV.PluginObject:CreatePluginAction(game:GetService("HttpService"):GenerateGUID(false), "New Theme", "", nil, false)
NewTheme.Triggered:Connect(function()
self:CreateThemeEditor(function(p)
if p == 2 or p == 0 then ThemeManager.ReloadTheme(ThemeManager.ThemeColor, ThemeManager.AccentColor) return end
ThemeManager.UpdateTheme()
local NamePrompt = InputPrompt.new({Title = "Name Layout ", Text = "Type in a name for this theme:", Buttons = {"OK", "Cancel"}, InputField = InputField.new({Placeholder = "New name", NoDropdown = true, Unpausable = true})})
NamePrompt:Clicked(function(p)
if p == 2 or p == 0 then return end
local SavedThemes = GV.PluginObject:GetSetting("SavedGUIThemes") or ThemeManager.PreinstalledThemes
SavedThemes[#SavedThemes+1] = {Name = NamePrompt.Input.Text, Theme = util.Color3ToTable(ThemeManager.CurrentTheme), Accent = util.Color3ToTable(ThemeManager.CurrentAccent)}
GV.PluginObject:SetSetting("SavedGUIThemes", SavedThemes)
end)
end)
end)
self.ThemesMenu:AddAction(NewTheme)
self.ThemesMenu:AddSeparator()
self.PluginMenu:AddMenu(self.ThemesMenu)
end
function ViewButton:RefreshMenu()
for _, v in pairs(RefreshedMenus) do
v:Destroy()
end
RefreshedMenus = {}
for i,Widget in pairs(GV.PluginWidgets) do
local LoadedOption = self:LoadWidgetOption(Widget, i)
RefreshedMenus[#RefreshedMenus+1] = LoadedOption
self.WidgetsMenu:AddMenu(LoadedOption)
end
local SavedLayouts = GV.PluginObject:GetSetting(GV.PluginID.."SavedGUILayouts") or {}
for i,Layout in pairs(SavedLayouts) do
local LoadedOption = self:LoadLayoutOption(Layout, i)
RefreshedMenus[#RefreshedMenus+1] = LoadedOption
self.LayoutsMenu:AddMenu(LoadedOption)
end
local SavedThemes = GV.PluginObject:GetSetting("SavedGUIThemes") or ThemeManager.PreinstalledThemes
for i,Theme in pairs(SavedThemes) do
local LoadedTheme = self:LoadThemeOption(Theme, i)
RefreshedMenus[#RefreshedMenus+1] = LoadedTheme
self.ThemesMenu:AddMenu(LoadedTheme)
end
end
function ViewButton.new()
local self = TitlebarButton.new({Name = "VIEW"})
setmetatable(self,ViewButton)
self:CreateMenu()
self:Clicked(function()
self:RefreshMenu()
end)
return self
end
return ViewButton