34 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-12-16 11:49:52 +01:00
import { Component, instantiate, Label, Node, Prefab, _decorator } from "cc";
2022-12-16 13:52:54 +01:00
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
import { TranslationData } from "../../../Game/Data/TranslationData";
import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
import { formatString } from "../../../Services/Utils/StringUtils";
2022-12-16 12:20:37 +01:00
import { UpgradeLevelPointUI } from "./UpgradeLevelPointUI";
2022-12-16 11:49:52 +01:00
const { ccclass, property } = _decorator;
@ccclass("UpgradeUI")
export class UpgradeUI extends Component {
@property(Prefab) private levelPointPrefab: Prefab;
@property(Node) private levelPointsParent: Node;
@property(Label) private title: Label;
@property(Label) private description: Label;
2022-12-16 12:20:37 +01:00
@property(Label) private cost: Label;
2022-12-16 11:49:52 +01:00
2022-12-16 13:52:54 +01:00
public init(upgradeType: MetaUpgradeType, upgradeSettings: MetaUpgradeSettings, level: number, translationData: TranslationData): void {
for (let i = 0; i < upgradeSettings.bonuses.length; i++) {
2022-12-16 11:49:52 +01:00
const node: Node = instantiate(this.levelPointPrefab);
node.setParent(this.levelPointsParent);
2022-12-16 12:20:37 +01:00
const levelPointUI = node.getComponent(UpgradeLevelPointUI);
levelPointUI.init();
if (i < 3) {
levelPointUI.upgrade();
}
2022-12-16 11:49:52 +01:00
}
2022-12-16 13:52:54 +01:00
this.title.string = `${translationData[`${upgradeType}_TITLE`]}`;
this.description.string = formatString(`${translationData[`${upgradeType}_DESC`]}`, [upgradeSettings.bonuses[level].toString()]);
this.cost.string = upgradeSettings.costs[level].toString();
2022-12-16 11:49:52 +01:00
}
}