Improvement to Methods
This commit is contained in:
parent
c6d516a6c9
commit
2d7b763eeb
6 changed files with 177 additions and 11 deletions
|
@ -98,4 +98,10 @@ function button:HoverLeft()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function button:Remove()
|
||||||
|
if self.ButtonGui then
|
||||||
|
self.ButtonGui:Destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return module
|
return module
|
|
@ -8,7 +8,14 @@ local module = {}
|
||||||
function module.new(name: string): types.Component
|
function module.new(name: string): types.Component
|
||||||
local self = setmetatable({
|
local self = setmetatable({
|
||||||
Name= name,
|
Name= name,
|
||||||
_ = {},
|
Buttons = {
|
||||||
|
Active = {},
|
||||||
|
Stored = {},
|
||||||
|
},
|
||||||
|
|
||||||
|
_ = {
|
||||||
|
UpdateCallbacks = {},
|
||||||
|
},
|
||||||
}, component)
|
}, component)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@ -26,8 +33,21 @@ function component:AddButton(button: types.Button)
|
||||||
self.Buttons.Stored[button.Name] = button
|
self.Buttons.Stored[button.Name] = button
|
||||||
end
|
end
|
||||||
|
|
||||||
function component:RemoveButtons()
|
function component:CloseAllButtons()
|
||||||
|
for _, button in self.Buttons.Active do
|
||||||
|
button:Close()
|
||||||
|
end
|
||||||
|
|
||||||
self.Buttons.Active = {}
|
self.Buttons.Active = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function component:RemoveButtons()
|
||||||
|
self:CloseAllButtons()
|
||||||
|
|
||||||
|
for _, button in self.Buttons.Stored do
|
||||||
|
button:Remove()
|
||||||
|
end
|
||||||
|
|
||||||
self.Buttons.Stored = {}
|
self.Buttons.Stored = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,7 +82,7 @@ function component:Build(parent: types.Page): ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function component:Update(command: string, parameters: {}): ()
|
function component:Update(command: string, parameters: {}?): ()
|
||||||
if self._.UpdateCallbacks[command] then
|
if self._.UpdateCallbacks[command] then
|
||||||
self._.UpdateCallbacks[command](self, parameters)
|
self._.UpdateCallbacks[command](self, parameters)
|
||||||
else
|
else
|
||||||
|
@ -91,11 +111,21 @@ function component:Close(): ()
|
||||||
end
|
end
|
||||||
|
|
||||||
function component:Clean(): ()
|
function component:Clean(): ()
|
||||||
|
self:CloseAllButtons()
|
||||||
|
|
||||||
if self.Container then
|
if self.Container then
|
||||||
self.Container:Remove()
|
self.Container:Remove()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function component:Remove(): ()
|
||||||
|
self:Clean()
|
||||||
|
|
||||||
self:RemoveButtons()
|
self:RemoveButtons()
|
||||||
|
|
||||||
|
if self.Frame then
|
||||||
|
self.Frame:Destroy()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return module
|
return module
|
|
@ -35,8 +35,43 @@ function page:AddButton(button: types.Button)
|
||||||
self.Buttons.Stored[button.Name] = button
|
self.Buttons.Stored[button.Name] = button
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:RemoveButtons()
|
function page:GetButton(button: string): types.Component
|
||||||
|
return self.Buttons.Stored[button]
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:OpenButton(component: string)
|
||||||
|
local buttonModule= self.Buttons.Stored[component]
|
||||||
|
if buttonModule then
|
||||||
|
buttonModule:Build(self)
|
||||||
|
buttonModule:Open()
|
||||||
|
self.Buttons.Active[component] = buttonModule
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:CloseButton(component: string)
|
||||||
|
local buttonModule= self.Buttons.Active[component]
|
||||||
|
if buttonModule then
|
||||||
|
buttonModule:Close()
|
||||||
|
buttonModule:Clean()
|
||||||
|
self.Buttons.Active[component] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:CloseAllButtons()
|
||||||
|
for _, button: types.Button in self.Buttons.Active do
|
||||||
|
button:Close()
|
||||||
|
end
|
||||||
|
|
||||||
self.Buttons.Active = {}
|
self.Buttons.Active = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:RemoveButtons()
|
||||||
|
self:CloseAllButtons()
|
||||||
|
|
||||||
|
for _, button: types.Button in self.Buttons.Stored do
|
||||||
|
button:Remove()
|
||||||
|
end
|
||||||
|
|
||||||
self.Buttons.Stored = {}
|
self.Buttons.Stored = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,9 +93,43 @@ function page:GetComponent(component: string): types.Component
|
||||||
return self.Components.Stored[component]
|
return self.Components.Stored[component]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function page:OpenComponent(component: string)
|
||||||
|
local componentModule= self.Components.Stored[component]
|
||||||
|
if componentModule then
|
||||||
|
componentModule:Build(self)
|
||||||
|
componentModule:Open()
|
||||||
|
self.Components.Open[component] = componentModule
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:CloseComponent(component: string)
|
||||||
|
local componentModule= self.Components.Open[component]
|
||||||
|
if componentModule then
|
||||||
|
componentModule:Close()
|
||||||
|
componentModule:Clean()
|
||||||
|
self.Components.Open[component] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:CleanComponents()
|
||||||
|
for _, component: types.Component in self.Components.Open do
|
||||||
|
component:Close()
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, component: types.Component in self.Components.Stored do
|
||||||
|
component:Clean()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.Components.Open = {}
|
||||||
|
end
|
||||||
|
|
||||||
function page:RemoveComponents()
|
function page:RemoveComponents()
|
||||||
for _, component: types.Component in self.Components.Open do
|
for _, component: types.Component in self.Components.Open do
|
||||||
component:Clean()
|
component:Close()
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, component: types.Component in self.Components.Stored do
|
||||||
|
component:Remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.Components.Open = {}
|
self.Components.Open = {}
|
||||||
|
@ -116,14 +185,19 @@ function page:Close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:Clean()
|
function page:Clean()
|
||||||
self:RemoveComponents()
|
self:CleanComponents()
|
||||||
self:RemoveButtons()
|
self:CloseAllButtons()
|
||||||
|
|
||||||
self.Container:Remove()
|
if self.Container then
|
||||||
|
self.Container:Remove()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:Remove()
|
function page:Remove()
|
||||||
self:Clean()
|
self:Clean()
|
||||||
|
|
||||||
|
self:RemoveComponents()
|
||||||
|
self:RemoveButtons()
|
||||||
|
|
||||||
if self.Frame then
|
if self.Frame then
|
||||||
self.Frame:Destroy()
|
self.Frame:Destroy()
|
||||||
|
|
|
@ -37,6 +37,8 @@ export type ButtonClass = {
|
||||||
Released: (self: Button) -> (),
|
Released: (self: Button) -> (),
|
||||||
Hovered: (self: Button) -> (),
|
Hovered: (self: Button) -> (),
|
||||||
HoverLeft: (self: Button) -> (),
|
HoverLeft: (self: Button) -> (),
|
||||||
|
|
||||||
|
Remove: (self: Button) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Button = typeof(setmetatable({} :: ButtonClass, {}))
|
export type Button = typeof(setmetatable({} :: ButtonClass, {}))
|
||||||
|
@ -57,6 +59,7 @@ export type ComponentClass = {
|
||||||
|
|
||||||
BuildButtons: (self: Component) -> (),
|
BuildButtons: (self: Component) -> (),
|
||||||
AddButton: (self: Component, button: Button) -> (),
|
AddButton: (self: Component, button: Button) -> (),
|
||||||
|
CloseAllButtons: (self: Component) -> (),
|
||||||
RemoveButtons: (self: Component) -> (),
|
RemoveButtons: (self: Component) -> (),
|
||||||
|
|
||||||
_: {
|
_: {
|
||||||
|
@ -73,11 +76,12 @@ export type ComponentClass = {
|
||||||
OnClose: (self: Component, callback: (self: Component) -> ()) -> (),
|
OnClose: (self: Component, callback: (self: Component) -> ()) -> (),
|
||||||
|
|
||||||
Build: (self: Component, parent: Page) -> (),
|
Build: (self: Component, parent: Page) -> (),
|
||||||
Update: (self: Component, command: string, parameters: {}) -> (),
|
Update: (self: Component, command: string, parameters: {}?) -> (),
|
||||||
Open: (self: Component) -> (),
|
Open: (self: Component) -> (),
|
||||||
Close: (self: Component) -> (),
|
Close: (self: Component) -> (),
|
||||||
|
|
||||||
Clean: (self: Component) -> (),
|
Clean: (self: Component) -> (),
|
||||||
|
Remove: (self: Component) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Component = typeof(setmetatable({} :: ComponentClass, {}))
|
export type Component = typeof(setmetatable({} :: ComponentClass, {}))
|
||||||
|
@ -98,6 +102,10 @@ export type PageClass = {
|
||||||
|
|
||||||
BuildButtons: (self: Page) -> (),
|
BuildButtons: (self: Page) -> (),
|
||||||
AddButton: (self: Page, button: Button) -> (),
|
AddButton: (self: Page, button: Button) -> (),
|
||||||
|
GetButton: (self: Page, button: string) -> (),
|
||||||
|
OpenButton: (self: Page, button: string) -> (),
|
||||||
|
CloseButton: (self: Page, button: string) -> (),
|
||||||
|
CloseAllButtons: (self: Page) -> (),
|
||||||
RemoveButtons: (self: Page) -> (),
|
RemoveButtons: (self: Page) -> (),
|
||||||
|
|
||||||
Components: {
|
Components: {
|
||||||
|
@ -108,6 +116,9 @@ export type PageClass = {
|
||||||
BuildComponents: (self: Page) -> (),
|
BuildComponents: (self: Page) -> (),
|
||||||
AddComponent: (self: Page, component: Component) -> (),
|
AddComponent: (self: Page, component: Component) -> (),
|
||||||
GetComponent: (self: Page, component: string) -> (),
|
GetComponent: (self: Page, component: string) -> (),
|
||||||
|
OpenComponent: (self: Page, component: string) -> (),
|
||||||
|
CloseComponent: (self: Page, component: string) -> (),
|
||||||
|
CleanComponents: (self: Page) -> (),
|
||||||
RemoveComponents: (self: Page) -> (),
|
RemoveComponents: (self: Page) -> (),
|
||||||
|
|
||||||
_: {
|
_: {
|
||||||
|
@ -145,8 +156,11 @@ export type WindowClass = {
|
||||||
|
|
||||||
BuildPages: (self: Window) -> (),
|
BuildPages: (self: Window) -> (),
|
||||||
AddPage: (self: Window, page: Page) -> (),
|
AddPage: (self: Window, page: Page) -> (),
|
||||||
GetPage: (self: Page, page: string) -> (),
|
GetPage: (self: Window, page: string) -> (),
|
||||||
|
OpenPage: (self: Window, page: string) -> (),
|
||||||
|
ClosePage: (self: Window, page: string) -> (),
|
||||||
RemovePages: (self: Window) -> (),
|
RemovePages: (self: Window) -> (),
|
||||||
|
CleanPages: (self: Window) -> (),
|
||||||
|
|
||||||
_: {
|
_: {
|
||||||
OnBuild: (self: Window) -> ()?,
|
OnBuild: (self: Window) -> ()?,
|
||||||
|
@ -209,6 +223,11 @@ export type Manager = {
|
||||||
]=]
|
]=]
|
||||||
CloseWindow: (self: Manager, window: Window) -> (),
|
CloseWindow: (self: Manager, window: Window) -> (),
|
||||||
|
|
||||||
|
--[=[
|
||||||
|
Close and remove all open ```Window``` objects and log their state changes.
|
||||||
|
]=]
|
||||||
|
CloseAllWindows: (self: Manager) -> (),
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
Intended to only be run on the first time that the client boots up. \
|
Intended to only be run on the first time that the client boots up. \
|
||||||
Receives a table of module scripts with which it will use to build the manager windows.
|
Receives a table of module scripts with which it will use to build the manager windows.
|
||||||
|
|
|
@ -33,6 +33,33 @@ function window:GetPage(page: string): types.Page
|
||||||
return self.Pages.Stored[page]
|
return self.Pages.Stored[page]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function window:OpenPage(page: string)
|
||||||
|
local pageModule: types.Page = self.Pages.Stored[page]
|
||||||
|
if pageModule then
|
||||||
|
pageModule:Build(self)
|
||||||
|
pageModule:Open()
|
||||||
|
self.Pages.Open[page] = pageModule
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function window:ClosePage(page: string)
|
||||||
|
local pageModule: types.Page = self.Pages.Open[page]
|
||||||
|
if pageModule then
|
||||||
|
pageModule:Close()
|
||||||
|
pageModule:Clean()
|
||||||
|
self.Pages.Open[page] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function window:CleanPages()
|
||||||
|
for _, page: types.Page in self.Pages.Open do
|
||||||
|
page:Close()
|
||||||
|
page:Clean()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.Pages.Open = {}
|
||||||
|
end
|
||||||
|
|
||||||
function window:RemovePages()
|
function window:RemovePages()
|
||||||
for _, page: types.Page in self.Pages.Open do
|
for _, page: types.Page in self.Pages.Open do
|
||||||
page:Remove()
|
page:Remove()
|
||||||
|
@ -85,11 +112,12 @@ function window:Close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function window:Clean()
|
function window:Clean()
|
||||||
self:RemovePages()
|
self:CleanPages()
|
||||||
end
|
end
|
||||||
|
|
||||||
function window:Remove()
|
function window:Remove()
|
||||||
self:Clean()
|
self:Clean()
|
||||||
|
self:RemovePages()
|
||||||
|
|
||||||
if self.ScreenGui then
|
if self.ScreenGui then
|
||||||
self.ScreenGui:Destroy()
|
self.ScreenGui:Destroy()
|
||||||
|
|
|
@ -29,6 +29,15 @@ function manager:CloseWindow(window: types.Window)
|
||||||
self.Windows.Open[window.Name] = nil
|
self.Windows.Open[window.Name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function manager:CloseAllWindows()
|
||||||
|
for _, window in self.Windows.Open do
|
||||||
|
window:Close()
|
||||||
|
window:Remove()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.Windows.Open = {}
|
||||||
|
end
|
||||||
|
|
||||||
function manager:Build(source: { ModuleScript })
|
function manager:Build(source: { ModuleScript })
|
||||||
self:Clean()
|
self:Clean()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue