From 94605e673ee1e6e767fa25029f9385664dd499bf Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 17 Nov 2022 18:28:39 +0100 Subject: [PATCH] adding basic modal system --- assets/Media/Images.meta | 12 + assets/Media/Images/pixel.png | Bin 0 -> 488 bytes assets/Media/Images/pixel.png.meta | 134 +++ assets/Media/Prefabs/Enemy.prefab | 6 +- assets/Media/Prefabs/ModalWindows.meta | 12 + .../ModalWindows/LevelUpModalWindow.prefab | 812 ++++++++++++++++++ .../LevelUpModalWindow.prefab.meta | 13 + assets/Scenes/scene-2d.scene | 391 +++++++++ assets/Scenes/scene-2d.scene.meta | 11 + assets/Scenes/scene.scene | 337 ++++++-- assets/Scripts/Game/GameBootstrapper.ts | 12 +- .../Scripts/Services/ModalWindowSystem.meta | 12 + .../ModalWindowSystem/LevelUpModalWindow.ts | 16 + .../LevelUpModalWindow.ts.meta | 9 + .../Services/ModalWindowSystem/ModalWindow.ts | 21 + .../ModalWindowSystem/ModalWindow.ts.meta | 9 + .../ModalWindowSystem/ModalWindowManager.ts | 21 + .../ModalWindowManager.ts.meta | 9 + 18 files changed, 1768 insertions(+), 69 deletions(-) create mode 100644 assets/Media/Images.meta create mode 100644 assets/Media/Images/pixel.png create mode 100644 assets/Media/Images/pixel.png.meta create mode 100644 assets/Media/Prefabs/ModalWindows.meta create mode 100644 assets/Media/Prefabs/ModalWindows/LevelUpModalWindow.prefab create mode 100644 assets/Media/Prefabs/ModalWindows/LevelUpModalWindow.prefab.meta create mode 100644 assets/Scenes/scene-2d.scene create mode 100644 assets/Scenes/scene-2d.scene.meta create mode 100644 assets/Scripts/Services/ModalWindowSystem.meta create mode 100644 assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts create mode 100644 assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts.meta create mode 100644 assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts create mode 100644 assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts.meta create mode 100644 assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts create mode 100644 assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts.meta diff --git a/assets/Media/Images.meta b/assets/Media/Images.meta new file mode 100644 index 0000000..e4eccf5 --- /dev/null +++ b/assets/Media/Images.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "8d33409a-75ec-4ab7-a741-513182fae646", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Media/Images/pixel.png b/assets/Media/Images/pixel.png new file mode 100644 index 0000000000000000000000000000000000000000..ee8c636c757e2cdb647169a7e37bd9585e85ba0d GIT binary patch literal 488 zcmVP)X}*^@zTqHs@dk$%&0<1`?#abjW=CxtS$#LE~plS=gHy!8m&~d(xp!^Xo z(#8Dc0~mZ4eY2>w??b~noLv^R=nkB3K+A)vT53)z7x(Boyq-XP1e&g)W+C6R!am3M zpsdMPUBT`ibjtaL#UIrzXc$tAp|b!0010qNS#tmY3ljhU3ljkVnw%H_000b0L_t&t enPd3>|33f){sR73@@ozN0000 { + const result: string = await this.modalWindowManager.showModal("LevelUpModalWindow", "test params"); + console.log("Result: " + result); + } } diff --git a/assets/Scripts/Services/ModalWindowSystem.meta b/assets/Scripts/Services/ModalWindowSystem.meta new file mode 100644 index 0000000..4c16455 --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "b7e00742-d8b5-4554-9f21-df67d6090eb5", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts b/assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts new file mode 100644 index 0000000..d136696 --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts @@ -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 { + @property(CCString) private testField: string; + + protected async setup(params: string): Promise { + console.log("TEST FIELD: " + this.testField + " params: " + params); + + await delay(10000); + this.dismiss("FInishedSuccessfuly"); + } +} diff --git a/assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts.meta b/assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts.meta new file mode 100644 index 0000000..81b143a --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem/LevelUpModalWindow.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "f7ac6f2a-2bea-42ec-b5d0-58976001856c", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts b/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts new file mode 100644 index 0000000..acffa2f --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts @@ -0,0 +1,21 @@ +import { Component } from "cc"; +import { delay } from "../Utils/AsyncUtils"; + +export abstract class ModalWindow extends Component { + private result: TResult; + private isDismissed = false; + + public async runAsync(params?: TParam): Promise { + 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; + } +} diff --git a/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts.meta b/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts.meta new file mode 100644 index 0000000..ccde23d --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "69f011ff-f798-4e03-a1b1-6490acc8fb0f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts b/assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts new file mode 100644 index 0000000..f272468 --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts @@ -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(name: string, params: TParams): Promise { + const windowPrefab: Prefab = this.availableWindows.find((w) => w.name === name); + const windowNode: Node = instantiate(windowPrefab); + windowNode.setParent(this.node); + + const modalWindow: ModalWindow = >windowNode.getComponent(name); + + const result: TResult = await modalWindow.runAsync(params); + windowNode.destroy(); + + return result; + } +} diff --git a/assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts.meta b/assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts.meta new file mode 100644 index 0000000..4e0b45d --- /dev/null +++ b/assets/Scripts/Services/ModalWindowSystem/ModalWindowManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "c623f863-d9be-42c9-abbc-3015cb3a6545", + "files": [], + "subMetas": {}, + "userData": {} +}