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
|
||||
|
||||
function button:Remove()
|
||||
if self.ButtonGui then
|
||||
self.ButtonGui:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
return module
|
|
@ -8,7 +8,14 @@ local module = {}
|
|||
function module.new(name: string): types.Component
|
||||
local self = setmetatable({
|
||||
Name= name,
|
||||
_ = {},
|
||||
Buttons = {
|
||||
Active = {},
|
||||
Stored = {},
|
||||
},
|
||||
|
||||
_ = {
|
||||
UpdateCallbacks = {},
|
||||
},
|
||||
}, component)
|
||||
|
||||
return self
|
||||
|
@ -26,8 +33,21 @@ function component:AddButton(button: types.Button)
|
|||
self.Buttons.Stored[button.Name] = button
|
||||
end
|
||||
|
||||
function component:RemoveButtons()
|
||||
function component:CloseAllButtons()
|
||||
for _, button in self.Buttons.Active do
|
||||
button:Close()
|
||||
end
|
||||
|
||||
self.Buttons.Active = {}
|
||||
end
|
||||
|
||||
function component:RemoveButtons()
|
||||
self:CloseAllButtons()
|
||||
|
||||
for _, button in self.Buttons.Stored do
|
||||
button:Remove()
|
||||
end
|
||||
|
||||
self.Buttons.Stored = {}
|
||||
end
|
||||
|
||||
|
@ -62,7 +82,7 @@ function component:Build(parent: types.Page): ()
|
|||
end
|
||||
end
|
||||
|
||||
function component:Update(command: string, parameters: {}): ()
|
||||
function component:Update(command: string, parameters: {}?): ()
|
||||
if self._.UpdateCallbacks[command] then
|
||||
self._.UpdateCallbacks[command](self, parameters)
|
||||
else
|
||||
|
@ -91,11 +111,21 @@ function component:Close(): ()
|
|||
end
|
||||
|
||||
function component:Clean(): ()
|
||||
self:CloseAllButtons()
|
||||
|
||||
if self.Container then
|
||||
self.Container:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
function component:Remove(): ()
|
||||
self:Clean()
|
||||
|
||||
self:RemoveButtons()
|
||||
|
||||
if self.Frame then
|
||||
self.Frame:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
return module
|
|
@ -35,8 +35,43 @@ function page:AddButton(button: types.Button)
|
|||
self.Buttons.Stored[button.Name] = button
|
||||
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 = {}
|
||||
end
|
||||
|
||||
function page:RemoveButtons()
|
||||
self:CloseAllButtons()
|
||||
|
||||
for _, button: types.Button in self.Buttons.Stored do
|
||||
button:Remove()
|
||||
end
|
||||
|
||||
self.Buttons.Stored = {}
|
||||
end
|
||||
|
||||
|
@ -58,9 +93,43 @@ function page:GetComponent(component: string): types.Component
|
|||
return self.Components.Stored[component]
|
||||
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()
|
||||
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
|
||||
|
||||
self.Components.Open = {}
|
||||
|
@ -116,15 +185,20 @@ function page:Close()
|
|||
end
|
||||
|
||||
function page:Clean()
|
||||
self:RemoveComponents()
|
||||
self:RemoveButtons()
|
||||
self:CleanComponents()
|
||||
self:CloseAllButtons()
|
||||
|
||||
self.Container:Remove()
|
||||
if self.Container then
|
||||
self.Container:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
function page:Remove()
|
||||
self:Clean()
|
||||
|
||||
self:RemoveComponents()
|
||||
self:RemoveButtons()
|
||||
|
||||
if self.Frame then
|
||||
self.Frame:Destroy()
|
||||
end
|
||||
|
|
|
@ -37,6 +37,8 @@ export type ButtonClass = {
|
|||
Released: (self: Button) -> (),
|
||||
Hovered: (self: Button) -> (),
|
||||
HoverLeft: (self: Button) -> (),
|
||||
|
||||
Remove: (self: Button) -> (),
|
||||
}
|
||||
|
||||
export type Button = typeof(setmetatable({} :: ButtonClass, {}))
|
||||
|
@ -57,6 +59,7 @@ export type ComponentClass = {
|
|||
|
||||
BuildButtons: (self: Component) -> (),
|
||||
AddButton: (self: Component, button: Button) -> (),
|
||||
CloseAllButtons: (self: Component) -> (),
|
||||
RemoveButtons: (self: Component) -> (),
|
||||
|
||||
_: {
|
||||
|
@ -73,11 +76,12 @@ export type ComponentClass = {
|
|||
OnClose: (self: Component, callback: (self: Component) -> ()) -> (),
|
||||
|
||||
Build: (self: Component, parent: Page) -> (),
|
||||
Update: (self: Component, command: string, parameters: {}) -> (),
|
||||
Update: (self: Component, command: string, parameters: {}?) -> (),
|
||||
Open: (self: Component) -> (),
|
||||
Close: (self: Component) -> (),
|
||||
|
||||
Clean: (self: Component) -> (),
|
||||
Remove: (self: Component) -> (),
|
||||
}
|
||||
|
||||
export type Component = typeof(setmetatable({} :: ComponentClass, {}))
|
||||
|
@ -98,6 +102,10 @@ export type PageClass = {
|
|||
|
||||
BuildButtons: (self: Page) -> (),
|
||||
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) -> (),
|
||||
|
||||
Components: {
|
||||
|
@ -108,6 +116,9 @@ export type PageClass = {
|
|||
BuildComponents: (self: Page) -> (),
|
||||
AddComponent: (self: Page, component: Component) -> (),
|
||||
GetComponent: (self: Page, component: string) -> (),
|
||||
OpenComponent: (self: Page, component: string) -> (),
|
||||
CloseComponent: (self: Page, component: string) -> (),
|
||||
CleanComponents: (self: Page) -> (),
|
||||
RemoveComponents: (self: Page) -> (),
|
||||
|
||||
_: {
|
||||
|
@ -145,8 +156,11 @@ export type WindowClass = {
|
|||
|
||||
BuildPages: (self: Window) -> (),
|
||||
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) -> (),
|
||||
CleanPages: (self: Window) -> (),
|
||||
|
||||
_: {
|
||||
OnBuild: (self: Window) -> ()?,
|
||||
|
@ -209,6 +223,11 @@ export type Manager = {
|
|||
]=]
|
||||
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. \
|
||||
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]
|
||||
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()
|
||||
for _, page: types.Page in self.Pages.Open do
|
||||
page:Remove()
|
||||
|
@ -85,11 +112,12 @@ function window:Close()
|
|||
end
|
||||
|
||||
function window:Clean()
|
||||
self:RemovePages()
|
||||
self:CleanPages()
|
||||
end
|
||||
|
||||
function window:Remove()
|
||||
self:Clean()
|
||||
self:RemovePages()
|
||||
|
||||
if self.ScreenGui then
|
||||
self.ScreenGui:Destroy()
|
||||
|
|
|
@ -29,6 +29,15 @@ function manager:CloseWindow(window: types.Window)
|
|||
self.Windows.Open[window.Name] = nil
|
||||
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 })
|
||||
self:Clean()
|
||||
|
||||
|
|
Loading…
Reference in a new issue