UpgradesModalWindow

This commit is contained in:
Martin 2022-12-22 13:44:28 +01:00
parent 4bdc76510b
commit 8b2897f38b
6 changed files with 100 additions and 55 deletions

Binary file not shown.

View File

@ -0,0 +1,14 @@
{
"ver": "1.0.0",
"importer": "audio-clip",
"imported": true,
"uuid": "40d2ac89-6719-4d9e-9d15-0b93ac31510f",
"files": [
".json",
".wav"
],
"subMetas": {},
"userData": {
"downloadMode": 0
}
}

View File

@ -24,18 +24,18 @@
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 48
},
{ {
"__id__": 50 "__id__": 50
}, },
{ {
"__id__": 52 "__id__": 52
},
{
"__id__": 54
} }
], ],
"_prefab": { "_prefab": {
"__id__": 54 "__id__": 56
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -84,14 +84,14 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 43 "__id__": 45
}, },
{ {
"__id__": 45 "__id__": 47
} }
], ],
"_prefab": { "_prefab": {
"__id__": 47 "__id__": 49
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -283,17 +283,17 @@
"__id__": 12 "__id__": 12
}, },
{ {
"__id__": 20 "__id__": 22
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 40 "__id__": 42
} }
], ],
"_prefab": { "_prefab": {
"__id__": 42 "__id__": 44
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -341,10 +341,13 @@
}, },
{ {
"__id__": 17 "__id__": 17
},
{
"__id__": 19
} }
], ],
"_prefab": { "_prefab": {
"__id__": 19 "__id__": 21
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -462,6 +465,26 @@
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "6cKPriiXpMaIUOeMX1Lu+M" "fileId": "6cKPriiXpMaIUOeMX1Lu+M"
}, },
{
"__type__": "146cdU9Cw9I+otUVSgpwCCT",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 12
},
"_enabled": true,
"__prefab": {
"__id__": 20
},
"button": {
"__id__": 17
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "9ffkR9f0JG+Yvnwzrf6VSC"
},
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
"root": { "root": {
@ -481,26 +504,26 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 21 "__id__": 23
}, },
{ {
"__id__": 27 "__id__": 29
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 33
},
{ {
"__id__": 35 "__id__": 35
}, },
{ {
"__id__": 37 "__id__": 37
},
{
"__id__": 39
} }
], ],
"_prefab": { "_prefab": {
"__id__": 39 "__id__": 41
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -535,20 +558,20 @@
"_name": "CoinsLabel", "_name": "CoinsLabel",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 20 "__id__": 22
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 22 "__id__": 24
}, },
{ {
"__id__": 24 "__id__": 26
} }
], ],
"_prefab": { "_prefab": {
"__id__": 26 "__id__": 28
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -583,11 +606,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 21 "__id__": 23
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 23 "__id__": 25
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -610,11 +633,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 21 "__id__": 23
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 25 "__id__": 27
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -667,20 +690,20 @@
"_name": "UpgradesParent", "_name": "UpgradesParent",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 20 "__id__": 22
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 28 "__id__": 30
}, },
{ {
"__id__": 30 "__id__": 32
} }
], ],
"_prefab": { "_prefab": {
"__id__": 32 "__id__": 34
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -715,11 +738,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 27 "__id__": 29
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 29 "__id__": 31
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -742,11 +765,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 27 "__id__": 29
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 31 "__id__": 33
}, },
"_resizeMode": 1, "_resizeMode": 1,
"_layoutType": 3, "_layoutType": 3,
@ -789,11 +812,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 20 "__id__": 22
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 34 "__id__": 36
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -816,11 +839,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 20 "__id__": 22
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 36 "__id__": 38
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -860,11 +883,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 20 "__id__": 22
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 38 "__id__": 40
}, },
"_id": "" "_id": ""
}, },
@ -891,7 +914,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 41 "__id__": 43
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -928,7 +951,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 44 "__id__": 46
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -955,7 +978,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 46 "__id__": 48
}, },
"playOnLoad": false, "playOnLoad": false,
"_clips": [ "_clips": [
@ -997,7 +1020,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 49 "__id__": 51
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -1025,7 +1048,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 51 "__id__": 53
}, },
"_alignFlags": 45, "_alignFlags": 45,
"_target": null, "_target": null,
@ -1060,10 +1083,10 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 53 "__id__": 55
}, },
"animation": { "animation": {
"__id__": 45 "__id__": 47
}, },
"closeButton": { "closeButton": {
"__id__": 17 "__id__": 17
@ -1076,10 +1099,14 @@
"__expectedType__": "cc.Prefab" "__expectedType__": "cc.Prefab"
}, },
"upgradeButtonParent": { "upgradeButtonParent": {
"__id__": 27 "__id__": 29
}, },
"goldCoinsLabel": { "goldCoinsLabel": {
"__id__": 24 "__id__": 26
},
"upgradeAudioClip": {
"__uuid__": "40d2ac89-6719-4d9e-9d15-0b93ac31510f",
"__expectedType__": "cc.AudioClip"
}, },
"_id": "" "_id": ""
}, },

View File

@ -2,7 +2,7 @@ import { sys } from "cc";
import { UserData } from "../Game/Data/UserData"; import { UserData } from "../Game/Data/UserData";
export class SaveSystem { export class SaveSystem {
private userDataIdentifier = "user-d"; private userDataIdentifier = "user-de";
public save(userData: UserData): void { public save(userData: UserData): void {
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData)); sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
} }

View File

@ -1,6 +1,6 @@
export class UserData { export class UserData {
public soundVolume = 0; public soundVolume = 1;
public musicVolume = 0; public musicVolume = 1;
public game = new GameData(); public game = new GameData();
} }

View File

@ -1,8 +1,8 @@
import { instantiate, Label, Node, Prefab, TiledUserNodeData, _decorator } from "cc"; import { AudioClip, instantiate, Label, Node, Prefab, _decorator } from "cc";
import { AppRoot } from "../../../AppRoot/AppRoot"; import { AppRoot } from "../../../AppRoot/AppRoot";
import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings"; import { MetaUpgradeSettings } from "../../../Game/Data/GameSettings";
import { UserData, GameData, MetaUpgradesData } from "../../../Game/Data/UserData"; import { MetaUpgradesData, UserData } from "../../../Game/Data/UserData";
import { MetaUpgradeType, UpgradeType } from "../../../Game/Upgrades/UpgradeType"; import { MetaUpgradeType } from "../../../Game/Upgrades/UpgradeType";
import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow"; import { ModalWindow } from "../../../Services/ModalWindowSystem/ModalWindow";
import { UpgradeUI } from "./UpgradeUI"; import { UpgradeUI } from "./UpgradeUI";
@ -13,6 +13,7 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
@property(Prefab) private upgradeButtonPrefab: Prefab; @property(Prefab) private upgradeButtonPrefab: Prefab;
@property(Node) private upgradeButtonParent: Node; @property(Node) private upgradeButtonParent: Node;
@property(Label) private goldCoinsLabel: Label; @property(Label) private goldCoinsLabel: Label;
@property(AudioClip) private upgradeAudioClip: AudioClip;
private typeToLevel = new Map<MetaUpgradeType, number>(); private typeToLevel = new Map<MetaUpgradeType, number>();
private typeToCosts = new Map<MetaUpgradeType, number[]>(); private typeToCosts = new Map<MetaUpgradeType, number[]>();
@ -62,12 +63,15 @@ export class UpgradesModalWindow extends ModalWindow<Empty, Empty> {
if (costs.length <= currentLevel) return; // already max level if (costs.length <= currentLevel) return; // already max level
if (this.userData.game.goldCoins < costs[currentLevel]) return; // not enough gold if (this.userData.game.goldCoins < costs[currentLevel]) return; // not enough gold
AppRoot.Instance.AudioPlayer.playSound(this.upgradeAudioClip);
this.userData.game.goldCoins -= costs[currentLevel]; this.userData.game.goldCoins -= costs[currentLevel];
const level = ++this.userData.game.metaUpgrades[this.typeToLevelKey.get(upgradeType)]; const level = ++this.userData.game.metaUpgrades[this.typeToLevelKey.get(upgradeType)];
this.typeToUpgradeUI.get(upgradeType).updateLevel(level); this.typeToUpgradeUI.get(upgradeType).updateLevel(level);
this.typeToLevel.set(upgradeType, level);
this.goldCoinsLabel.string = this.userData.game.goldCoins.toString(); this.goldCoinsLabel.string = this.userData.game.goldCoins.toString();
AppRoot.Instance.saveUserData; AppRoot.Instance.saveUserData();
} }
} }