mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2026-02-14 12:22:42 +00:00
Meta upgrades
This commit is contained in:
@@ -2,6 +2,9 @@ import { Component, instantiate, Label, Node, Prefab, _decorator } from "cc";
|
||||
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
|
||||
import { TranslationData } from "../../../Game/Data/TranslationData";
|
||||
import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
|
||||
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../../Services/EventSystem/Signal";
|
||||
import { UIButton } from "../../../Services/UI/Button/UIButton";
|
||||
import { formatString } from "../../../Services/Utils/StringUtils";
|
||||
import { UpgradeLevelPointUI } from "./UpgradeLevelPointUI";
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -13,21 +16,61 @@ export class UpgradeUI extends Component {
|
||||
@property(Label) private title: Label;
|
||||
@property(Label) private description: Label;
|
||||
@property(Label) private cost: Label;
|
||||
@property(Label) private maxLevel: Label;
|
||||
|
||||
@property(UIButton) private uiButton: UIButton;
|
||||
|
||||
private interactedEvent = new Signal<MetaUpgradeType>();
|
||||
|
||||
private upgradeType: MetaUpgradeType;
|
||||
private upgradeSettings: MetaUpgradeSettings;
|
||||
private translationData: TranslationData;
|
||||
|
||||
private levelPointUIs: UpgradeLevelPointUI[] = [];
|
||||
|
||||
public init(upgradeType: MetaUpgradeType, upgradeSettings: MetaUpgradeSettings, level: number, translationData: TranslationData): void {
|
||||
for (let i = 0; i < upgradeSettings.bonuses.length; i++) {
|
||||
this.upgradeType = upgradeType;
|
||||
this.upgradeSettings = upgradeSettings;
|
||||
this.translationData = translationData;
|
||||
|
||||
this.title.string = `${translationData[`${upgradeType}_TITLE`]}`;
|
||||
this.uiButton.InteractedEvent.on(() => this.interactedEvent.trigger(upgradeType), this);
|
||||
|
||||
for (let i = 0; i < this.upgradeSettings.bonuses.length; i++) {
|
||||
const node: Node = instantiate(this.levelPointPrefab);
|
||||
node.setParent(this.levelPointsParent);
|
||||
|
||||
const levelPointUI = node.getComponent(UpgradeLevelPointUI);
|
||||
levelPointUI.init();
|
||||
if (i < 3) {
|
||||
levelPointUI.upgrade();
|
||||
|
||||
this.levelPointUIs.push(levelPointUI);
|
||||
}
|
||||
|
||||
this.updateLevel(level);
|
||||
}
|
||||
|
||||
public updateLevel(level: number): void {
|
||||
for (let i = 0; i < this.levelPointUIs.length; i++) {
|
||||
if (i < level) {
|
||||
this.levelPointUIs[i].upgrade();
|
||||
}
|
||||
}
|
||||
|
||||
this.title.string = `${translationData[`${upgradeType}_TITLE`]}`;
|
||||
this.description.string = formatString(`${translationData[`${upgradeType}_DESC`]}`, [upgradeSettings.bonuses[level].toString()]);
|
||||
this.cost.string = upgradeSettings.costs[level].toString();
|
||||
if (level < this.upgradeSettings.bonuses.length) {
|
||||
this.maxLevel.node.active = false;
|
||||
this.description.string = formatString(`${this.translationData[`${this.upgradeType}_DESC`]}`, [
|
||||
this.upgradeSettings.bonuses[level].toString()
|
||||
]);
|
||||
this.cost.string = this.upgradeSettings.costs[level].toString();
|
||||
} else {
|
||||
// reached max level
|
||||
this.maxLevel.node.active = true;
|
||||
this.cost.node.active = false;
|
||||
this.description.node.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
public get InteractedEvent(): ISignal<MetaUpgradeType> {
|
||||
return this.interactedEvent;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user