mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
Chest modal
This commit is contained in:
@@ -97,7 +97,6 @@ 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, this.gameResult, settings.items);
|
||||
|
||||
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay, this.itemManager);
|
||||
new WeaponCollisionSystem(this.player.Weapon);
|
||||
@@ -157,6 +156,7 @@ export class Game extends Component {
|
||||
);
|
||||
const modalLauncher = new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader, translationData);
|
||||
|
||||
this.itemManager.init(this.enemyManager, this.player, this.gameResult, modalLauncher, settings.items);
|
||||
this.gameUI.init(this.player, modalLauncher);
|
||||
this.background.init(this.player.node);
|
||||
|
||||
|
@@ -3,6 +3,7 @@ import { ISignal } from "../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../Services/EventSystem/Signal";
|
||||
import { ItemSettings } from "../Data/GameSettings";
|
||||
import { GameResult } from "../Game";
|
||||
import { GameModalLauncher } from "../ModalWIndows/GameModalLauncher";
|
||||
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
|
||||
import { Player } from "../Unit/Player/Player";
|
||||
@@ -24,15 +25,17 @@ export class ItemManager extends Component {
|
||||
|
||||
private player: Player;
|
||||
private gameResult: GameResult;
|
||||
private modalLauncher: GameModalLauncher;
|
||||
private healthPerPotion: number;
|
||||
|
||||
private pickupEvent = new Signal<ItemType>();
|
||||
|
||||
private itemTypeToAction = new Map<ItemType, () => void>();
|
||||
|
||||
public init(enemyManager: EnemyManager, player: Player, gameResult: GameResult, settings: ItemSettings): void {
|
||||
public init(enemyManager: EnemyManager, player: Player, gameResult: GameResult, modalLauncher: GameModalLauncher, settings: ItemSettings): void {
|
||||
this.player = player;
|
||||
this.gameResult = gameResult;
|
||||
this.modalLauncher = modalLauncher;
|
||||
this.healthPerPotion = settings.healthPerPotion;
|
||||
|
||||
enemyManager.EnemyAddedEvent.on(this.addEnemyListeners, this);
|
||||
@@ -50,7 +53,7 @@ export class ItemManager extends Component {
|
||||
this.itemTypeToAction.set(ItemType.Gold, this.addGold.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.HealthPotion, this.useHealthPotion.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.Magnet, this.activateMagnet.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.Chest, this.giveRandomSkill.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.Chest, this.openChest.bind(this));
|
||||
}
|
||||
|
||||
public get PickupEvent(): ISignal<ItemType> {
|
||||
@@ -84,7 +87,9 @@ export class ItemManager extends Component {
|
||||
this.player.Magnet.activate();
|
||||
}
|
||||
|
||||
private giveRandomSkill(): void {}
|
||||
private openChest(): void {
|
||||
this.modalLauncher.showChestModal();
|
||||
}
|
||||
|
||||
private addEnemyListeners(enemy: Enemy): void {
|
||||
enemy.DeathEvent.on(this.trySpawnItems, this);
|
||||
|
21
assets/Scripts/Game/ModalWIndows/ChestModalWindow.ts
Normal file
21
assets/Scripts/Game/ModalWIndows/ChestModalWindow.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { randomRangeInt, _decorator } from "cc";
|
||||
import { ModalWindow } from "../../Services/ModalWindowSystem/ModalWindow";
|
||||
import { UIButton } from "../../Services/UI/Button/UIButton";
|
||||
import { LevelUpModalWindowParams } from "../UI/LevelUpWindow/LevelUpModalWindow";
|
||||
import { LevelUpSkill } from "../UI/LevelUpWindow/LevelUpSkill";
|
||||
import { UpgradeType } from "../Upgrades/UpgradeType";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ChestModalWindow")
|
||||
export class ChestModalWindow extends ModalWindow<LevelUpModalWindowParams, UpgradeType> {
|
||||
@property(LevelUpSkill) private levelUpSkill: LevelUpSkill;
|
||||
@property(UIButton) private okButton: UIButton;
|
||||
|
||||
protected setup(params: LevelUpModalWindowParams): void {
|
||||
const randomIndex = randomRangeInt(0, params.availableUpgrades.length - 1);
|
||||
const skillToUpgrade = params.availableUpgrades[randomIndex];
|
||||
this.levelUpSkill.init(skillToUpgrade, params.translationData);
|
||||
|
||||
this.okButton.InteractedEvent.on(() => this.dismiss(skillToUpgrade), this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "422c8f7d-cc38-4c6a-9c61-420c291a610b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -27,8 +27,18 @@ export class GameModalLauncher {
|
||||
GameModalWindowTypes.LevelUp,
|
||||
{ availableUpgrades: Array.from(this.upgrader.getAvailableUpgrades()), translationData: this.translationData }
|
||||
);
|
||||
this.gamePauser.resume();
|
||||
this.upgrader.upgradeSkill(skillToUpgrade);
|
||||
this.gamePauser.resume();
|
||||
}
|
||||
|
||||
public async showChestModal(): Promise<void> {
|
||||
this.gamePauser.pause();
|
||||
const skillToUpgrade: UpgradeType = await this.modalWindowManager.showModal<LevelUpModalWindowParams, UpgradeType>(
|
||||
GameModalWindowTypes.Chest,
|
||||
{ availableUpgrades: Array.from(this.upgrader.getAvailableUpgrades()), translationData: this.translationData }
|
||||
);
|
||||
this.upgrader.upgradeSkill(skillToUpgrade);
|
||||
this.gamePauser.resume();
|
||||
}
|
||||
|
||||
public async showPauseModal(): Promise<void> {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
export enum GameModalWindowTypes {
|
||||
LevelUp = "LevelUpModalWindow",
|
||||
Chest = "ChestModalWindow",
|
||||
Pause = "PauseModalWindow"
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@ export class ModalWindowManager extends Component {
|
||||
windowNode.setParent(this.node);
|
||||
|
||||
const modalWindow: ModalWindow<TParams, TResult> = <ModalWindow<TParams, TResult>>windowNode.getComponent(name);
|
||||
|
||||
const result: TResult = await modalWindow.runAsync(params);
|
||||
windowNode.destroy();
|
||||
|
||||
|
Reference in New Issue
Block a user