generated from Basssiiie/OpenRCT2-Simple-Typescript-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a365a5f
commit 6846746
Showing
3 changed files
with
213 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
TabWindowParams, | ||
WindowParams, | ||
WindowTemplate, | ||
tabwindow, | ||
window | ||
} from "openrct2-flexui" | ||
|
||
class Window<T extends WindowParams | TabWindowParams> { | ||
protected _windowParams: T | ||
protected _windowTemplate: WindowTemplate | ||
protected _isOpen: boolean | ||
|
||
private isTabWindowParams( | ||
params: WindowParams | TabWindowParams | ||
): params is TabWindowParams { | ||
return (params as TabWindowParams).tabs !== undefined | ||
} | ||
|
||
constructor(windowParams: T) { | ||
this._windowParams = windowParams | ||
if (this.isTabWindowParams(windowParams)) { | ||
this._windowTemplate = tabwindow(windowParams) | ||
} else { | ||
this._windowTemplate = window(windowParams) | ||
} | ||
this._isOpen = false | ||
} | ||
|
||
get windowParams(): T { | ||
return this._windowParams | ||
} | ||
|
||
set windowParams(windowParams: T) { | ||
this._windowParams = windowParams | ||
} | ||
|
||
open() { | ||
if (!this._isOpen) { | ||
this._windowTemplate.open() | ||
this._isOpen = true | ||
} else { | ||
this._windowTemplate.focus() | ||
} | ||
} | ||
|
||
close() { | ||
if (this._isOpen) { | ||
this._windowTemplate.close() | ||
this._isOpen = false | ||
} | ||
} | ||
|
||
redefine() { | ||
this.close() | ||
if (this.isTabWindowParams(this._windowParams)) { | ||
this._windowTemplate = tabwindow(this._windowParams) | ||
} else { | ||
this._windowTemplate = window(this._windowParams) | ||
} | ||
this.open() | ||
} | ||
|
||
setProperties(properties: Partial<WindowParams>) { | ||
this._windowParams = { ...this._windowParams, ...properties } | ||
} | ||
} | ||
|
||
export default Window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters