mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
adding basic modal system
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Camera, CCFloat, CCInteger, Component, KeyCode, _decorator } from "cc";
|
||||
import { Camera, CCFloat, CCInteger, Component, director, KeyCode, _decorator } from "cc";
|
||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||
import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem";
|
||||
import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem";
|
||||
import { EnemyManager } from "./Enemy/EnemyManager";
|
||||
@@ -21,6 +22,8 @@ export class GameBootstrapper extends Component {
|
||||
@property(Camera) private camera: Camera;
|
||||
@property(GameUI) private gameUI: GameUI;
|
||||
@property(Number) private requiredLevelXps: number[] = [];
|
||||
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
|
||||
|
||||
private playerCollisionSystem: PlayerCollisionSystem;
|
||||
|
||||
public start(): void {
|
||||
@@ -37,6 +40,8 @@ export class GameBootstrapper extends Component {
|
||||
this.enemyManager.init(this.player.node);
|
||||
|
||||
this.gameUI.init(this.player);
|
||||
|
||||
this.showModal();
|
||||
}
|
||||
|
||||
public update(deltaTime: number): void {
|
||||
@@ -46,4 +51,9 @@ export class GameBootstrapper extends Component {
|
||||
|
||||
this.camera.node.worldPosition = this.player.node.worldPosition;
|
||||
}
|
||||
|
||||
private async showModal(): Promise<void> {
|
||||
const result: string = await this.modalWindowManager.showModal<string, string>("LevelUpModalWindow", "test params");
|
||||
console.log("Result: " + result);
|
||||
}
|
||||
}
|
||||
|
12
assets/Scripts/Services/ModalWindowSystem.meta
Normal file
12
assets/Scripts/Services/ModalWindowSystem.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "b7e00742-d8b5-4554-9f21-df67d6090eb5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
import { CCString, _decorator } from "cc";
|
||||
import { delay } from "../Utils/AsyncUtils";
|
||||
import { ModalWindow } from "./ModalWindow";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("LevelUpModalWindow")
|
||||
export class LevelUpModalWindow extends ModalWindow<string, string> {
|
||||
@property(CCString) private testField: string;
|
||||
|
||||
protected async setup(params: string): Promise<void> {
|
||||
console.log("TEST FIELD: " + this.testField + " params: " + params);
|
||||
|
||||
await delay(10000);
|
||||
this.dismiss("FInishedSuccessfuly");
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f7ac6f2a-2bea-42ec-b5d0-58976001856c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
21
assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts
Normal file
21
assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Component } from "cc";
|
||||
import { delay } from "../Utils/AsyncUtils";
|
||||
|
||||
export abstract class ModalWindow<TParam, TResult> extends Component {
|
||||
private result: TResult;
|
||||
private isDismissed = false;
|
||||
|
||||
public async runAsync(params?: TParam): Promise<TResult> {
|
||||
this.setup(params);
|
||||
while (!this.isDismissed) await delay(100);
|
||||
|
||||
return this.result;
|
||||
}
|
||||
|
||||
protected abstract setup(params?: TParam): void;
|
||||
|
||||
protected dismiss(result?: TResult): void {
|
||||
this.result = result;
|
||||
this.isDismissed = true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "69f011ff-f798-4e03-a1b1-6490acc8fb0f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
import { Component, instantiate, Node, Prefab, _decorator } from "cc";
|
||||
import { ModalWindow } from "./ModalWindow";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ModalWindowManager")
|
||||
export class ModalWindowManager extends Component {
|
||||
@property(Prefab) private availableWindows: Prefab[] = [];
|
||||
|
||||
public async showModal<TParams, TResult>(name: string, params: TParams): Promise<TResult> {
|
||||
const windowPrefab: Prefab = this.availableWindows.find((w) => w.name === name);
|
||||
const windowNode: Node = instantiate(windowPrefab);
|
||||
windowNode.setParent(this.node);
|
||||
|
||||
const modalWindow: ModalWindow<TParams, TResult> = <ModalWindow<TParams, TResult>>windowNode.getComponent(name);
|
||||
|
||||
const result: TResult = await modalWindow.runAsync(params);
|
||||
windowNode.destroy();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c623f863-d9be-42c9-abbc-3015cb3a6545",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user