diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index b4007dd..6035fd3 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -63,9 +63,9 @@ "metaUpgrades": { "health": { "costs": [ - 5, - 10, - 15 + 0, + 0, + 0 ], "bonuses": [ 10, @@ -75,9 +75,9 @@ }, "overallDamage": { "costs": [ - 6, + 0, 10, - 15 + 0 ], "bonuses": [ 1, @@ -87,8 +87,8 @@ }, "projectilePiercing": { "costs": [ - 7, - 10, + 0, + 0, 15 ], "bonuses": [ @@ -99,9 +99,9 @@ }, "movementSpeed": { "costs": [ - 8, - 10, - 15 + 0, + 0, + 0 ], "bonuses": [ 10, diff --git a/assets/Data/eng.json b/assets/Data/eng.json index 32eab75..9e475ef 100644 --- a/assets/Data/eng.json +++ b/assets/Data/eng.json @@ -15,12 +15,12 @@ "META_HEALTH_DESC": "Increases max health by {0}", "META_OVERALL_DAMAGE_TITLE": "OVERALL DAMAGE", "META_OVERALL_DAMAGE_DESC": "Increases overall damage by {0}", - "META_PROJECTILE_PIERCING_TITLE": "", - "META_PROJECTILE_PIERCING_DESC": "", - "META_MOVEMENT_SPEED_TITLE": "", - "META_MOVEMENT_SPEED_DESC": "", - "META_XP_GATHERER_TITLE": "", - "META_XP_GATHERER_DESC": "", - "META_GOLD_GATHERER_TITLE": "", - "META_GOLD_GATHERER_DESC": "" + "META_PROJECTILE_PIERCING_TITLE": "PROJECTILE PIERCING", + "META_PROJECTILE_PIERCING_DESC": "Projectiles pierce {0} times", + "META_MOVEMENT_SPEED_TITLE": "MOVEMENT SPEED", + "META_MOVEMENT_SPEED_DESC": "Increases movement speed", + "META_XP_GATHERER_TITLE": "XP GATHERER", + "META_XP_GATHERER_DESC": "Increases the amount of XP obtained by {0}", + "META_GOLD_GATHERER_TITLE": "GOLD GATHERER", + "META_GOLD_GATHERER_DESC": "Increases the amount of gold obtained by {0}" } \ No newline at end of file diff --git a/assets/Media/Prefabs/ModalWindows/Upgrades/UpgradeButton.prefab b/assets/Media/Prefabs/ModalWindows/Upgrades/UpgradeButton.prefab index 6846ebc..b357d9f 100644 --- a/assets/Media/Prefabs/ModalWindows/Upgrades/UpgradeButton.prefab +++ b/assets/Media/Prefabs/ModalWindows/Upgrades/UpgradeButton.prefab @@ -29,25 +29,31 @@ }, { "__id__": 20 + }, + { + "__id__": 26 } ], "_active": true, "_components": [ - { - "__id__": 26 - }, - { - "__id__": 28 - }, - { - "__id__": 30 - }, { "__id__": 32 + }, + { + "__id__": 34 + }, + { + "__id__": 36 + }, + { + "__id__": 40 + }, + { + "__id__": 38 } ], "_prefab": { - "__id__": 34 + "__id__": 42 }, "_lpos": { "__type__": "cc.Vec3", @@ -138,8 +144,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 84.64, - "height": 30 + "width": 110, + "height": 80 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -180,7 +186,7 @@ "_fontSize": 30, "_fontFamily": "Arial", "_lineHeight": 30, - "_overflow": 0, + "_overflow": 1, "_enableWrapText": true, "_font": { "__uuid__": "c96b42a9-d20d-4c59-8e99-8ed749a715c8", @@ -232,7 +238,7 @@ "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": 0, + "y": -3, "z": 0 }, "_lrot": { @@ -364,7 +370,7 @@ "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": -33, + "y": -38, "z": 0 }, "_lrot": { @@ -475,7 +481,7 @@ }, { "__type__": "cc.Node", - "_name": "LevelPoints", + "_name": "MaxLevel", "_objFlags": 0, "_parent": { "__id__": 1 @@ -496,7 +502,7 @@ "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": -63.985, + "y": -6, "z": 0 }, "_lrot": { @@ -532,6 +538,138 @@ "__prefab": { "__id__": 22 }, + "_contentSize": { + "__type__": "cc.Size", + "width": 96.43, + "height": 20 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "276iFXJJBND6xagl8JLo54" + }, + { + "__type__": "cc.Label", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 20 + }, + "_enabled": true, + "__prefab": { + "__id__": 24 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 167, + "b": 34, + "a": 255 + }, + "_string": "MAX LEVEL", + "_horizontalAlign": 1, + "_verticalAlign": 1, + "_actualFontSize": 20, + "_fontSize": 20, + "_fontFamily": "Arial", + "_lineHeight": 20, + "_overflow": 0, + "_enableWrapText": true, + "_font": { + "__uuid__": "c96b42a9-d20d-4c59-8e99-8ed749a715c8", + "__expectedType__": "cc.BitmapFont" + }, + "_isSystemFontUsed": false, + "_spacingX": 0, + "_isItalic": false, + "_isBold": false, + "_isUnderline": false, + "_underlineHeight": 2, + "_cacheMode": 0, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "a87NNJ77tKzZ5vkZJk996T" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "0cQMux+vVPoLL0HRl6iqwl" + }, + { + "__type__": "cc.Node", + "_name": "LevelPoints", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 27 + }, + { + "__id__": 29 + } + ], + "_prefab": { + "__id__": 31 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": -63.985, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 26 + }, + "_enabled": true, + "__prefab": { + "__id__": 28 + }, "_contentSize": { "__type__": "cc.Size", "width": 0, @@ -553,11 +691,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 26 }, "_enabled": true, "__prefab": { - "__id__": 24 + "__id__": 30 }, "_resizeMode": 1, "_layoutType": 1, @@ -604,7 +742,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 27 + "__id__": 33 }, "_contentSize": { "__type__": "cc.Size", @@ -631,7 +769,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 29 + "__id__": 35 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -675,14 +813,14 @@ }, "_enabled": true, "__prefab": { - "__id__": 31 + "__id__": 37 }, "levelPointPrefab": { "__uuid__": "41ca6952-fa32-4e38-8d43-eec2e982533c", "__expectedType__": "cc.Prefab" }, "levelPointsParent": { - "__id__": 20 + "__id__": 26 }, "title": { "__id__": 5 @@ -693,12 +831,35 @@ "cost": { "__id__": 17 }, + "maxLevel": { + "__id__": 23 + }, + "uiButton": { + "__id__": 38 + }, "_id": "" }, { "__type__": "cc.CompPrefabInfo", "fileId": "c52I+5RPFJDoP/OUf2yPtC" }, + { + "__type__": "55e5f5nQ8dHiL5fPWjgdXbH", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 39 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "b9Zn/AuoNOdLvE9z2Y6ORa" + }, { "__type__": "cc.Button", "_name": "", @@ -708,7 +869,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 33 + "__id__": 41 }, "clickEvents": [], "_interactable": true, diff --git a/assets/Scripts/AppRoot/SaveSystem.ts b/assets/Scripts/AppRoot/SaveSystem.ts index cd9ee55..e26f203 100644 --- a/assets/Scripts/AppRoot/SaveSystem.ts +++ b/assets/Scripts/AppRoot/SaveSystem.ts @@ -2,7 +2,7 @@ import { sys } from "cc"; import { UserData } from "../Game/Data/UserData"; export class SaveSystem { - private userDataIdentifier = "user-da"; + private userDataIdentifier = "user-d"; public save(userData: UserData): void { sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData)); } diff --git a/assets/Scripts/Game/Data/UserData.ts b/assets/Scripts/Game/Data/UserData.ts index 50f2dce..9fbbc2d 100644 --- a/assets/Scripts/Game/Data/UserData.ts +++ b/assets/Scripts/Game/Data/UserData.ts @@ -12,7 +12,7 @@ export class GameData { export class MetaUpgradesData { public healthLevel = 0; - public overallDamageLevel = 2; + public overallDamageLevel = 0; public projectilePiercingLevel = 0; public movementSpeedLevel = 0; public xpGathererLevel = 0; diff --git a/assets/Scripts/Menu/Menu.ts b/assets/Scripts/Menu/Menu.ts index a633c9b..00d48ff 100644 --- a/assets/Scripts/Menu/Menu.ts +++ b/assets/Scripts/Menu/Menu.ts @@ -1,4 +1,4 @@ -import { _decorator, Component } from "cc"; +import { Component, _decorator } from "cc"; import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager"; import { UIButton } from "../Services/UI/Button/UIButton"; import { GameRunner } from "./GameRunner"; diff --git a/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradeUI.ts b/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradeUI.ts index 5010a65..4927eb4 100644 --- a/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradeUI.ts +++ b/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradeUI.ts @@ -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(); + + 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 { + return this.interactedEvent; } } diff --git a/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradesModalWindow.ts b/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradesModalWindow.ts index fc650f2..33bffe0 100644 --- a/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradesModalWindow.ts +++ b/assets/Scripts/Menu/ModalWindows/Upgrades/UpgradesModalWindow.ts @@ -1,8 +1,8 @@ -import { instantiate, Label, Node, Prefab, _decorator } from "cc"; +import { instantiate, Label, Node, Prefab, TiledUserNodeData, _decorator } from "cc"; import { AppRoot } from "../../../AppRoot/AppRoot"; import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings"; -import { GameData } from "../../../Game/Data/UserData"; -import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType"; +import { UserData, GameData, MetaUpgradesData } from "../../../Game/Data/UserData"; +import { MetaUpgradeType, UpgradeType } from "../../../Game/Upgrades/UpgradeType"; import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow"; import { UpgradeUI } from "./UpgradeUI"; @@ -14,28 +14,59 @@ export class UpgradesModalWindow extends ModalWindow { @property(Node) private upgradeButtonParent: Node; @property(Label) private goldCoinsLabel: Label; - private gameData: GameData; + private typeToLevel = new Map(); + private typeToCosts = new Map(); + private typeToLevelKey = new Map(); + private typeToUpgradeUI = new Map(); + + private userData: UserData; public setup(): void { - this.gameData = AppRoot.Instance.SaveSystem.load().game; - + this.userData = AppRoot.Instance.SaveSystem.load(); const settings = AppRoot.Instance.Settings.metaUpgrades; - const data = this.gameData.metaUpgrades; - this.createUpgradeButton(MetaUpgradeType.Health, settings.health, data.healthLevel); - this.createUpgradeButton(MetaUpgradeType.OverallDamage, settings.overallDamage, data.healthLevel); - this.createUpgradeButton(MetaUpgradeType.ProjectilePiercing, settings.projectilePiercing, data.healthLevel); - this.createUpgradeButton(MetaUpgradeType.MovementSpeed, settings.movementSpeed, data.healthLevel); - this.createUpgradeButton(MetaUpgradeType.XPGatherer, settings.xpGatherer, data.healthLevel); - this.createUpgradeButton(MetaUpgradeType.GoldGatherer, settings.goldGatherer, data.healthLevel); + this.createUpgradeButton(MetaUpgradeType.Health, settings.health, "healthLevel"); + this.createUpgradeButton(MetaUpgradeType.OverallDamage, settings.overallDamage, "overallDamageLevel"); + this.createUpgradeButton(MetaUpgradeType.ProjectilePiercing, settings.projectilePiercing, "projectilePiercingLevel"); + this.createUpgradeButton(MetaUpgradeType.MovementSpeed, settings.movementSpeed, "movementSpeedLevel"); + this.createUpgradeButton(MetaUpgradeType.XPGatherer, settings.xpGatherer, "xpGathererLevel"); + this.createUpgradeButton(MetaUpgradeType.GoldGatherer, settings.goldGatherer, "goldGathererLevel"); - this.goldCoinsLabel.string = this.gameData.goldCoins.toString(); + this.goldCoinsLabel.string = this.userData.game.goldCoins.toString(); } - private createUpgradeButton(upgradeType: MetaUpgradeType, upgradeSettings: MetaUpgradeSettings, level: number): void { + private createUpgradeButton( + upgradeType: MetaUpgradeType, + upgradeSettings: MetaUpgradeSettings, + levelKey: T + ): void { const upgradeButton: Node = instantiate(this.upgradeButtonPrefab); - upgradeButton.getComponent(UpgradeUI).init(upgradeType, upgradeSettings, level, AppRoot.Instance.TranslationData); + const upgradeUI: UpgradeUI = upgradeButton.getComponent(UpgradeUI); + + upgradeUI.init(upgradeType, upgradeSettings, this.userData.game.metaUpgrades[levelKey], AppRoot.Instance.TranslationData); + upgradeUI.InteractedEvent.on(this.tryUpgrade, this); upgradeButton.setParent(this.upgradeButtonParent); + + this.typeToLevel.set(upgradeType, this.userData.game.metaUpgrades[levelKey]); + this.typeToCosts.set(upgradeType, upgradeSettings.costs); + this.typeToLevelKey.set(upgradeType, levelKey); + this.typeToUpgradeUI.set(upgradeType, upgradeUI); + } + + private tryUpgrade(upgradeType: MetaUpgradeType): void { + console.log("Trying to upgrade " + upgradeType); + + const costs: number[] = this.typeToCosts.get(upgradeType); + const currentLevel: number = this.typeToLevel.get(upgradeType); + + if (costs.length <= currentLevel) return; // already max level + if (this.userData.game.goldCoins < costs[currentLevel]) return; // not enough gold + + this.userData.game.goldCoins -= costs[currentLevel]; + const level = ++this.userData.game.metaUpgrades[this.typeToLevelKey.get(upgradeType)]; + this.typeToUpgradeUI.get(upgradeType).updateLevel(level); + + AppRoot.Instance.SaveSystem.save(this.userData); } }