Slash-The-Hordes/assets/Scripts/Game/UI/LevelUpWindow/LevelUpModalWindow.ts

38 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-11-24 12:17:05 +00:00
import { instantiate, Node, Prefab, Vec3, _decorator } from "cc";
2022-11-23 08:01:01 +00:00
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
2022-11-25 11:00:09 +00:00
import { shuffle } from "../../../Services/Utils/ArrayUtils";
2022-11-23 08:01:01 +00:00
import { delay } from "../../../Services/Utils/AsyncUtils";
2022-11-24 12:17:05 +00:00
import { UpgradeType } from "../../Upgrades/UpgradeType";
2022-11-23 08:01:01 +00:00
import { LevelUpSkill } from "./LevelUpSkill";
const { ccclass, property } = _decorator;
@ccclass("LevelUpModalWindow")
2022-11-25 11:00:09 +00:00
export class LevelUpModalWindow extends ModalWindow<UpgradeType[], UpgradeType> {
2022-11-23 08:01:01 +00:00
@property(Prefab) private skillPrefab: Prefab;
@property(Node) private skillParent: Node;
2022-11-25 11:00:09 +00:00
private maxUpgradesToPick = 3;
protected async setup(availableUpgrades: UpgradeType[]): Promise<void> {
const shuffledAvailableUpgrades = shuffle(availableUpgrades);
if (this.maxUpgradesToPick < shuffledAvailableUpgrades.length) {
shuffledAvailableUpgrades.length = this.maxUpgradesToPick;
}
2022-11-23 08:01:01 +00:00
const xPositions: number[] = [-180, 0, 180];
await delay(300);
2022-11-25 11:00:09 +00:00
for (let i = 0; i < shuffledAvailableUpgrades.length; i++) {
2022-11-23 08:01:01 +00: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-11-25 11:00:09 +00:00
skill.init(shuffledAvailableUpgrades[i]);
2022-11-23 08:01:01 +00:00
skill.ChooseSkillEvent.on(this.chooseSkill, this);
}
}
private chooseSkill(skill: LevelUpSkill): void {
2022-11-24 12:17:05 +00:00
this.dismiss(UpgradeType.WeaponDamage);
2022-11-23 08:01:01 +00:00
}
}