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

@@ -1,6 +1,7 @@
import { Component, director, JsonAsset, _decorator } from "cc";
import { GameSettings } from "../Game/Data/GameSettings";
import { TranslationData } from "../Game/Data/TranslationData";
import { UserData } from "../Game/Data/UserData";
import { AudioPlayer } from "../Services/AudioPlayer/AudioPlayer";
import { SaveSystem } from "./SaveSystem";
const { ccclass, property } = _decorator;
@@ -14,6 +15,8 @@ export class AppRoot extends Component {
private static instance: AppRoot;
private saveSystem: SaveSystem;
private liveUserData: UserData;
public static get Instance(): AppRoot {
return this.instance;
}
@@ -22,8 +25,8 @@ export class AppRoot extends Component {
return this.audio;
}
public get SaveSystem(): SaveSystem {
return this.saveSystem;
public get LiveUserData(): UserData {
return this.liveUserData;
}
public get Settings(): GameSettings {
@@ -34,6 +37,10 @@ export class AppRoot extends Component {
return <TranslationData>this.engTranslationAsset.json;
}
public saveUserData(): void {
this.saveSystem.save(this.liveUserData);
}
public start(): void {
if (AppRoot.Instance == null) {
AppRoot.instance = this;
@@ -46,6 +53,8 @@ export class AppRoot extends Component {
private init(): void {
this.saveSystem = new SaveSystem();
this.audio.init(1, 1);
this.liveUserData = this.saveSystem.load();
this.audio.init(this.LiveUserData.soundVolume, this.LiveUserData.musicVolume);
}
}

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> {

View File

@@ -23,7 +23,7 @@ export class GameRunner {
public async playGame(): Promise<void> {
this.isRunning = true;
director.loadScene("Game");
const userData: UserData = AppRoot.Instance.SaveSystem.load();
const userData: UserData = AppRoot.Instance.LiveUserData;
while (Game.Instance == null) await delay(10);
const result: GameResult = await Game.Instance.playGame(userData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData);
userData.game.goldCoins += result.goldCoins;
@@ -31,9 +31,7 @@ export class GameRunner {
if (userData.game.highscore < result.score) {
userData.game.highscore = result.score;
}
AppRoot.Instance.SaveSystem.save(userData);
await delay(1000);
AppRoot.Instance.saveUserData();
director.loadScene("Menu");
this.isRunning = false;

View File

@@ -10,6 +10,7 @@ const { ccclass, property } = _decorator;
export class Menu extends Component {
@property(UIButton) private playBtn: UIButton;
@property(UIButton) private upgradeBtn: UIButton;
@property(UIButton) private audioSettingsBtn: UIButton;
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
private menuModalLauncher: MenuModalLauncher;
@@ -17,6 +18,7 @@ export class Menu extends Component {
public async start(): Promise<void> {
this.playBtn.InteractedEvent.on(this.startGame, this);
this.upgradeBtn.InteractedEvent.on(this.openUpgradesWindow, this);
this.audioSettingsBtn.InteractedEvent.on(this.openAudioSettingsWindow, this);
this.menuModalLauncher = new MenuModalLauncher(this.modalWindowManager);
}
@@ -28,4 +30,8 @@ export class Menu extends Component {
private openUpgradesWindow(): void {
this.menuModalLauncher.openUpgradesWindow();
}
private openAudioSettingsWindow(): void {
this.menuModalLauncher.openAudioSettingsWindow();
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "fcf86181-bba6-488b-b46a-4fbc6c162992",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,40 @@
import { Slider, _decorator } from "cc";
import { AppRoot } from "../../../AppRoot/AppRoot";
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
import { UIButton } from "../../../Services/UI/Button/UIButton";
import { Empty } from "../Upgrades/UpgradesModalWindow";
const { ccclass, property } = _decorator;
@ccclass("AudioSettingsModalWindow")
export class AudioSettingsModalWindow extends ModalWindow<Empty, Empty> {
@property(Slider) private soundVolumeSlider: Slider;
@property(Slider) private musicVolumeSlider: Slider;
@property(UIButton) private okButton: UIButton;
protected setup(): void {
this.soundVolumeSlider.progress = AppRoot.Instance.AudioPlayer.SoundVolume;
this.musicVolumeSlider.progress = AppRoot.Instance.AudioPlayer.MusicVolume;
this.soundVolumeSlider.node.on("slide", this.updateSoundVolume, this);
this.musicVolumeSlider.node.on("slide", this.updateMusicVolume, this);
this.okButton.InteractedEvent.on(this.dismiss, this);
}
private updateSoundVolume(): void {
AppRoot.Instance.AudioPlayer.setSoundVolume(this.soundVolumeSlider.progress);
}
private updateMusicVolume(): void {
AppRoot.Instance.AudioPlayer.setMusicVolume(this.musicVolumeSlider.progress);
}
protected dismiss(result?: Empty): void {
super.dismiss(result);
const userData = AppRoot.Instance.LiveUserData;
userData.musicVolume = this.musicVolumeSlider.progress;
userData.soundVolume = this.soundVolumeSlider.progress;
AppRoot.Instance.saveUserData();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0c052d4f-c82c-4aff-a5ed-a7317f69c9ef",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -7,4 +7,8 @@ export class MenuModalLauncher {
public async openUpgradesWindow(): Promise<void> {
await this.modalWindowManager.showModal(MenuModalWindowTypes.Upgrades, {});
}
public async openAudioSettingsWindow(): Promise<void> {
await this.modalWindowManager.showModal(MenuModalWindowTypes.AudioSettings, {});
}
}

View File

@@ -1,3 +1,4 @@
export enum MenuModalWindowTypes {
Upgrades = "UpgradesModalWindow"
Upgrades = "UpgradesModalWindow",
AudioSettings = "AudioSettingsModalWindow"
}

View File

@@ -22,7 +22,7 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
private userData: UserData;
public setup(): void {
this.userData = AppRoot.Instance.SaveSystem.load();
this.userData = AppRoot.Instance.LiveUserData;
const settings = AppRoot.Instance.Settings.metaUpgrades;
this.createUpgradeButton(MetaUpgradeType.Health, settings.health, "healthLevel");
@@ -67,7 +67,7 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
this.typeToUpgradeUI.get(upgradeType).updateLevel(level);
this.goldCoinsLabel.string = this.userData.game.goldCoins.toString();
AppRoot.Instance.SaveSystem.save(this.userData);
AppRoot.Instance.saveUserData;
}
}

View File

@@ -11,6 +11,14 @@ export class AudioPlayer extends Component {
this.setMusicVolume(musicVolume);
}
public get SoundVolume(): number {
return this.soundSource.volume;
}
public get MusicVolume(): number {
return this.musicSource.volume;
}
public setSoundVolume(volume: number): void {
this.soundSource.volume = volume;
}