Modal windows

This commit is contained in:
Martin
2022-12-21 14:08:49 +01:00
parent b4abb4df21
commit f3eb520300
25 changed files with 5287 additions and 263 deletions

View File

@@ -32,6 +32,8 @@ const { ccclass, property } = _decorator;
@ccclass("Game")
export class Game extends Component {
private static instance: Game;
@property(VirtualJoystic) private virtualJoystic: VirtualJoystic;
@property(Player) private player: Player;
@property(ProjectileLauncher) private haloProjectileLauncherComponent: ProjectileLauncher;
@@ -54,8 +56,8 @@ export class Game extends Component {
private enemyProjectileLauncher: EnemyProjectileLauncher;
private gamePauser: Pauser = new Pauser();
private gameResult: GameResult;
private static instance: Game;
private timeAlive = 0;
public static get Instance(): Game {
@@ -73,7 +75,7 @@ export class Game extends Component {
translationData: TranslationData,
testValues?: TestValues
): Promise<GameResult> {
const gameResult = new GameResult();
this.gameResult = new GameResult();
const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades);
this.virtualJoystic.init();
@@ -84,7 +86,7 @@ export class Game extends Component {
this.player.init(multiInput, this.createPlayerData(settings.player, metaUpgrades));
this.enemyManager.init(this.player.node, settings.enemyManager);
this.itemManager.init(this.enemyManager, this.player, gameResult, settings.items);
this.itemManager.init(this.enemyManager, this.player, this.gameResult, settings.items);
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay, this.itemManager);
new WeaponCollisionSystem(this.player.Weapon);
@@ -132,9 +134,9 @@ export class Game extends Component {
this.diagonalProjectileLauncher,
settings.upgrades
);
new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader, translationData);
const modalLauncher = new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader, translationData);
this.gameUI.init(this.player);
this.gameUI.init(this.player, modalLauncher);
this.background.init(this.player.node);
if (testValues) {
@@ -145,11 +147,18 @@ export class Game extends Component {
this.gameAudioAdapter.init(this.enemyManager);
this.gamePauser.resume();
while (this.player.Health.IsAlive) await delay(100);
while (!this.gameResult.hasExitManually && this.player.Health.IsAlive) await delay(100);
if (!this.gameResult.hasExitManually) {
await delay(1000);
}
this.gamePauser.pause();
Game.instance = null;
gameResult.score = this.timeAlive;
return gameResult;
this.gameResult.score = this.timeAlive;
return this.gameResult;
}
public exitGame(): void {
this.gameResult.hasExitManually = true;
}
public update(deltaTime: number): void {
@@ -188,6 +197,7 @@ export class Game extends Component {
}
export class GameResult {
public hasExitManually = false;
public goldCoins = 0;
public score = 0;
}

View File

@@ -1,5 +1,8 @@
import { MenuModalWindowTypes } from "../../Menu/ModalWindows/MenuModalWindowTypes";
import { Empty } from "../../Menu/ModalWindows/Upgrades/UpgradesModalWindow";
import { ModalWindowManager } from "../../Services/ModalWindowSystem/ModalWindowManager";
import { TranslationData } from "../Data/TranslationData";
import { Game } from "../Game";
import { Pauser } from "../Pauser";
import { LevelUpModalWindowParams } from "../UI/LevelUpWindow/LevelUpModalWindow";
import { Player } from "../Unit/Player/Player";
@@ -27,4 +30,15 @@ export class GameModalLauncher {
this.gamePauser.resume();
this.upgrader.upgradeSkill(skillToUpgrade);
}
public async showPauseModal(): Promise<void> {
this.gamePauser.pause();
const shouldExit = await this.modalWindowManager.showModal<ModalWindowManager, boolean>(GameModalWindowTypes.Pause, this.modalWindowManager);
if (shouldExit) {
Game.Instance.exitGame();
} else {
this.gamePauser.resume();
}
}
}

View File

@@ -1,3 +1,4 @@
export enum GameModalWindowTypes {
LevelUp = "LevelUpModalWindow"
LevelUp = "LevelUpModalWindow",
Pause = "PauseModalWindow"
}

View File

@@ -0,0 +1,36 @@
import { _decorator } from "cc";
import { MenuModalWindowTypes } from "../../Menu/ModalWindows/MenuModalWindowTypes";
import { ModalWindow } from "../../Services/ModalWindowSystem/ModalWindow";
import { ModalWindowManager } from "../../Services/ModalWindowSystem/ModalWindowManager";
import { UIButton } from "../../Services/UI/Button/UIButton";
const { ccclass, property } = _decorator;
@ccclass("PauseModalWindow")
export class PauseModalWindow extends ModalWindow<ModalWindowManager, boolean> {
@property(UIButton) private continueBtn: UIButton;
@property(UIButton) private audioSettingsButton: UIButton;
@property(UIButton) private exitBtn: UIButton;
private modalWindowManager: ModalWindowManager;
protected setup(modalWindowManager: ModalWindowManager): void {
this.modalWindowManager = modalWindowManager;
this.continueBtn.InteractedEvent.on(this.continueGame, this);
this.audioSettingsButton.InteractedEvent.on(this.openSettingsWindow, this);
this.exitBtn.InteractedEvent.on(this.exitGame, this);
}
private openSettingsWindow(): void {
this.modalWindowManager.showModal(MenuModalWindowTypes.AudioSettings, {});
}
private continueGame(): void {
this.dismiss(false);
}
private exitGame(): void {
this.dismiss(true);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7951e831-768d-4cc1-910f-d93b9038b3aa",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,4 +1,6 @@
import { Component, Label, ProgressBar, _decorator } from "cc";
import { UIButton } from "../../Services/UI/Button/UIButton";
import { GameModalLauncher } from "../ModalWIndows/GameModalLauncher";
import { Player } from "../Unit/Player/Player";
import { UnitLevel } from "../Unit/UnitLevel";
@@ -8,20 +10,31 @@ const { ccclass, property } = _decorator;
export class GameUI extends Component {
@property(ProgressBar) private xpBar: ProgressBar;
@property(Label) private timeAliveText: Label;
@property(UIButton) private pauseBtn: UIButton;
private playerLevel: UnitLevel;
private modalLauncher: GameModalLauncher;
public init(player: Player): void {
public init(player: Player, modalLauncher: GameModalLauncher): void {
this.playerLevel = player.Level;
this.modalLauncher = modalLauncher;
this.playerLevel.XpAddedEvent.on(this.updateProgressBar, this);
this.playerLevel.LevelUpEvent.on(this.updateProgressBar, this);
this.xpBar.progress = 0;
this.pauseBtn.InteractedEvent.on(this.showPauseWindow, this);
}
private updateProgressBar(): void {
this.xpBar.progress = this.playerLevel.XP / this.playerLevel.RequiredXP;
}
private showPauseWindow(): void {
console.log("Show pause window");
this.modalLauncher.showPauseModal();
}
public updateTimeAlive(timeAlive: number): void {
this.timeAliveText.string = `${Math.floor(timeAlive)}`;
}

View File

@@ -14,7 +14,7 @@ export class LevelUpSkill extends Component {
public init(skillType: UpgradeType, translationData: TranslationData): void {
this.skillType = skillType;
this.skillTitle.string = `${translationData[`${skillType}_TITLE`]}`;
this.node.on(NodeEventType.MOUSE_DOWN, this.chooseSkill, this);
this.node.on(NodeEventType.TOUCH_START, this.chooseSkill, this);
}
public get ChooseSkillEvent(): ISignal<UpgradeType> {