44 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-11-24 13:17:05 +01:00
import { instantiate, Node, Prefab, Vec3, _decorator } from "cc";
2022-11-23 09:01:01 +01:00
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
2022-11-25 12:00:09 +01:00
import { shuffle } from "../../../Services/Utils/ArrayUtils";
2022-11-23 09:01:01 +01:00
import { delay } from "../../../Services/Utils/AsyncUtils";
2022-12-13 16:58:55 +01:00
import { TranslationData } from "../../Data/TranslationData";
2022-11-24 13:17:05 +01:00
import { UpgradeType } from "../../Upgrades/UpgradeType";
2022-11-23 09:01:01 +01:00
import { LevelUpSkill } from "./LevelUpSkill";
const { ccclass, property } = _decorator;
@ccclass("LevelUpModalWindow")
2022-12-13 16:58:55 +01:00
export class LevelUpModalWindow extends ModalWindow<LevelUpModalWindowParams, UpgradeType> {
2022-11-23 09:01:01 +01:00
@property(Prefab) private skillPrefab: Prefab;
@property(Node) private skillParent: Node;
2022-11-25 12:00:09 +01:00
private maxUpgradesToPick = 3;
2022-12-13 16:58:55 +01:00
protected async setup(params: LevelUpModalWindowParams): Promise<void> {
const shuffledAvailableUpgrades = shuffle(params.availableUpgrades);
2022-11-25 12:00:09 +01:00
if (this.maxUpgradesToPick < shuffledAvailableUpgrades.length) {
shuffledAvailableUpgrades.length = this.maxUpgradesToPick;
}
2022-11-23 09:01:01 +01:00
const xPositions: number[] = [-180, 0, 180];
await delay(300);
2022-11-25 12:00:09 +01:00
for (let i = 0; i < shuffledAvailableUpgrades.length; i++) {
2022-11-23 09:01:01 +01:00
await delay(500);
const skill: LevelUpSkill = instantiate(this.skillPrefab).getComponent(LevelUpSkill);
skill.node.setParent(this.skillParent);
skill.node.setPosition(new Vec3(xPositions[i]));
2022-12-13 16:58:55 +01:00
skill.init(shuffledAvailableUpgrades[i], params.translationData);
2022-11-23 09:01:01 +01:00
skill.ChooseSkillEvent.on(this.chooseSkill, this);
}
}
2022-11-28 11:49:16 +01:00
private chooseSkill(upgradeType: UpgradeType): void {
this.dismiss(upgradeType);
2022-11-23 09:01:01 +01:00
}
}
2022-12-13 16:58:55 +01:00
export class LevelUpModalWindowParams {
public availableUpgrades: UpgradeType[];
public translationData: TranslationData;
}