开始商店 脚本和ui

This commit is contained in:
2025-08-20 17:46:06 +08:00
parent b531948d4d
commit 1896b5fab0
22 changed files with 9189 additions and 11412 deletions

View File

@@ -65,9 +65,6 @@ export class GameDataSyncManager {
console.log(`[Initialize]: 装备数据已从${dataSource}覆盖`);
}
// 同步ViewModel数据
smc.syncData();
// 保存到本地存储(确保数据持久化)
// smc.saveGameData();
@@ -457,10 +454,7 @@ export class GameDataSyncManager {
smc.items = cloudData.items;
smc.tals = cloudData.tals;
smc.equips = cloudData.equips;
// 同步vmdata
smc.syncData();
console.log(`[GameDataSyncManager]: 云端数据加载成功,本地数据已同步`);
return true;
} else {

View File

@@ -8,6 +8,7 @@ import { GameData, WxCloudApi } from "../wx_clound_client_api/WxCloudApi";
import { gameDataSyncManager } from "./GameDataSyncManager";
import { GameSet } from "./config/BoxSet";
import { Test } from "./Test";
import { GameEvent } from "./config/GameEvent";
// import { Role } from "../role/Role";
@@ -76,13 +77,7 @@ export class SingletonModuleComp extends ecs.Comp {
}
// ==================== 数据管理方法 ====================
/**
* 同步数据到vmdata
*/
syncData(){
this.vmdata.data = this.data;
}
/**
* 判断是否为微信客户端
*/
@@ -152,56 +147,50 @@ export class SingletonModuleComp extends ecs.Comp {
*/
addExp(exp:number,autoSave:boolean=true){
this.data.exp+=exp
this.vmdata.data.exp+=exp
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("exp",exp)
}
}
addGold(gold:number,autoSave:boolean=true){
this.data.gold+=gold
this.vmdata.data.gold+=gold
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("gold",gold)
}
}
addDiamond(diamond:number,autoSave:boolean=true){
this.data.diamond+=diamond
this.vmdata.data.diamond+=diamond
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("diamond",diamond)
}
}
addMission(mission:number,autoSave:boolean=true){
this.data.mission+=mission
this.vmdata.data.mission+=mission
oops.message.dispatchEvent(GameEvent.MISSION_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("mission",mission)
}
}
spendMission(mission:number,autoSave:boolean=true){
this.data.mission-=mission
this.vmdata.data.mission-=mission
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("mission",mission)
}
}
spendExp(exp:number,autoSave:boolean=true){
this.data.exp-=exp
this.vmdata.data.exp-=exp
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("exp",exp)
}
}
spendGold(gold:number,autoSave:boolean=true){
this.data.gold-=gold
this.vmdata.data.gold-=gold
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("gold",gold)
}
}
spendDiamond(diamond:number,autoSave:boolean=true){
this.data.diamond-=diamond
this.vmdata.data.diamond-=diamond
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("diamond",diamond)
}
@@ -227,7 +216,6 @@ export class SingletonModuleComp extends ecs.Comp {
}
const newValue = currentValue - value;
this.data[property] = newValue;
this.vmdata.data[property] = newValue;
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}, 当前值: ${newValue}`);
return true;
}
@@ -252,7 +240,6 @@ export class SingletonModuleComp extends ecs.Comp {
const current = this.data[key] || 0;
const next = current - need;
this.data[key] = next;
this.vmdata.data[key] = next;
console.log(`[SMC]: 消耗游戏数据 ${key} = ${need}, 当前值: ${next}`);
}

View File

@@ -0,0 +1,24 @@
import { Items } from "./Items";
export enum GType{
ITEM=1, //物品
GOLD=2, //金币
DIAMOND=3, //钻石
EXP=4, //经验
MEAT=5, //能量
}
export enum CType{
GOLD=1, //金币
DIAMOND=2, //钻石
FREE=3, //免费
AD=4, //广告
}
export const Goods={
1001:{i_uuid:Items[9001].uuid,num:10000,cast:0,type:GType.GOLD,c_type:CType.FREE},
1002:{i_uuid:Items[9002].uuid,num:100000,cast:0,type:GType.GOLD,c_type:CType.AD,},
1003:{i_uuid:Items[9003].uuid,num:500000,cast:100,type:GType.GOLD,c_type:CType.DIAMOND},
1004:{i_uuid:Items[9004].uuid,num:100,cast:0,type:GType.DIAMOND,c_type:CType.FREE},
1005:{i_uuid:Items[9005].uuid,num:200,cast:0,type:GType.DIAMOND,c_type:CType.FREE},
1006:{i_uuid:Items[9006].uuid,num:300,cast:0,type:GType.DIAMOND,c_type:CType.AD},
1007:{i_uuid:Items[9007].uuid,num:500,cast:0,type:GType.DIAMOND,c_type:CType.AD},
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "0ca1e413-6bfd-4e8a-95cc-56fb3e54075a",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -33,6 +33,15 @@ export const Items={
1006:{uuid: 1006,path: "1006",type:1,quality:QualitySet.BLUE,name: "铜钥匙",info:"解锁稀有英雄 也可以直接兑换金币", },
1007:{uuid: 1007,path: "1007",type:1,quality:QualitySet.PURPLE,name: "银钥匙",info:"解锁史诗英雄 也可以直接兑换金币", },
1008:{uuid: 1008,path: "1008",type:1,quality:QualitySet.ORANGE,name: "金钥匙",info:"解锁传说英雄 也可以直接兑换金币", },
9001:{uuid: 9001,path: "9001",type:1,quality:QualitySet.GREEN,name: "金币",info:"少许金币", },
9002:{uuid: 9002,path: "9002",type:1,quality:QualitySet.BLUE,name: "小袋金币",info:"一小袋金币", },
9003:{uuid: 9003,path: "9003",type:1,quality:QualitySet.PURPLE,name: "大袋金币",info:"一大袋金币", },
9004:{uuid: 9004,path: "9004",type:1,quality:QualitySet.GREEN,name: "钻石",info:"少许钻石", },
9005:{uuid: 9005,path: "9005",type:1,quality:QualitySet.GREEN,name: "钻石",info:"少许钻石", },
9006:{uuid: 9006,path: "9006",type:1,quality:QualitySet.BLUE,name: "小袋钻石",info:"一小袋钻石", },
9007:{uuid: 9007,path: "9007",type:1,quality:QualitySet.BLUE,name: "大袋钻石",info:"一大袋钻石", },
9008:{uuid: 9008,path: "9008",type:1,quality:QualitySet.PURPLE,name: "小箱钻石",info:"一小箱钻石", },
9009:{uuid: 9009,path: "9009",type:1,quality:QualitySet.PURPLE,name: "大箱钻石",info:"一大箱钻石", },
}
export enum DropKey{

View File

@@ -1,9 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "f6f84e06-578b-446b-b5d7-595b686efbe0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -287,11 +287,9 @@ export class HeroViewComp extends CCComp {
}
if(gold>0){
smc.addGold(gold)
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
}
if(diamond>0){
smc.addDiamond(diamond)
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
}
console.log("[HeroViewComp]:do_drop",this.hero_uuid,drop_item,exp,gold,diamond)
}

View File

@@ -363,11 +363,11 @@ export class CardComp extends CCComp {
this.reset_card()
}
cost_gold_check(){
if(smc.vmdata.data.gold< this.cost_gold){
if(smc.data.gold< this.cost_gold){
oops.gui.toast("[cardcomp]:金币不足", false);
return false
}
smc.vmdata.data.gold-=this.cost_gold
smc.data.gold-=this.cost_gold
return true
}
reset() {

View File

@@ -0,0 +1,73 @@
import { _decorator, Component, Node, Label, Sprite, SpriteFrame, resources } from 'cc';
import { Goods, GType, CType } from '../common/config/Goods';
import { Items } from '../common/config/Items';
import { NumberFormatter } from '../common/config/BoxSet';
const { ccclass, property } = _decorator;
@ccclass('GoodsComp')
export class GoodsComp extends Component {
// 数据(仅用于更新显示)
private goodsData: any = null;
private itemData: any = null;
private currentUuid: number = 0;
/**
* 更新物品数据
* @param uuid 物品UUID
*/
update_data(uuid: number) {
this.currentUuid = uuid;
this.goodsData = Goods[uuid];
if (!this.goodsData) {
console.error(`Goods data not found for uuid: ${uuid}`);
return;
}
this.itemData = Items[this.goodsData.i_uuid];
if (!this.itemData) {
console.error(`Item data not found for i_uuid: ${this.goodsData.i_uuid}`);
return;
}
this.updateIcon();
this.updateTexts();
this.update_btn(this.goodsData.c_type)
}
update_btn(type:CType){
this.node.getChildByName("ad").active=type==CType.AD
this.node.getChildByName("free").active=type==CType.FREE
this.node.getChildByName("cast").active=type==(CType.DIAMOND||CType.GOLD)
this.node.getChildByName("cast").getChildByName("diamond").active=type==CType.DIAMOND
this.node.getChildByName("cast").getChildByName("gold").active=type==CType.GOLD
this.node.getChildByName("cast").getChildByName("num").getComponent(Label).string=NumberFormatter.formatNumber(this.goodsData.cast)
}
/**
* 更新图标
*/
private updateIcon() {
const iconSprite = this.node.getChildByName("icon")?.getComponent(Sprite);
if (!iconSprite) return;
const path = `gui/items/${this.itemData.path}`;
resources.load(path, SpriteFrame, (err, spriteFrame) => {
if (err) {
console.warn(`icon load failed: ${path}`, err);
return;
}
iconSprite.spriteFrame = spriteFrame;
});
}
/** 仅更新文字(名称与数量) */
private updateTexts() {
// 名称
const nameLabel = this.node.getChildByName("name")?.getComponent(Label);
if (nameLabel) nameLabel.string = this.itemData.name;
// 数量(根节点下的 num
const mainNumLabel = this.node.getChildByName("num")?.getComponent(Label);
if (mainNumLabel) mainNumLabel.string = NumberFormatter.formatNumber(this.goodsData.num);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "e24167ce-79d0-4f99-a3d8-f144bbe959a3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -4,6 +4,7 @@ import { UIID } from '../common/config/GameUIConfig';
import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType } from '../common/config/heroSet';
import { smc } from '../common/SingletonModuleComp';
import { GameEvent } from '../common/config/GameEvent';
import { NumberFormatter } from '../common/config/BoxSet';
const { ccclass, property } = _decorator;
@ccclass('HInfoComp')
@@ -42,14 +43,20 @@ export class HInfoComp extends Component {
this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=ap.toString()
this.node.getChildByName("info").getChildByName("def").getChildByName("num").getComponent(Label).string=def.toString()
let {experience,gold}=getUpgradeResources(lv)
let need_node=this.node.getChildByName("upNeed").getChildByName("need")
need_node.getChildByName("exp").getChildByName("need").getComponent(Label).string=experience.toString()
need_node.getChildByName("gold").getChildByName("need").getComponent(Label).string=gold.toString()
this.updata_need(experience,gold)
this.node.getChildByName("upBtn").active=smc.data.exp>=experience&&smc.data.gold>=gold
this.node.getChildByName("type").getChildByName("w").active=hero_data.type==HType.warrior
this.node.getChildByName("type").getChildByName("r").active=hero_data.type==HType.remote
this.node.getChildByName("type").getChildByName("m").active=hero_data.type==HType.mage
this.show_luck(smc.heros[uuid]?.lv??0)
}
updata_need(experience:number,gold:number){
let need_node=this.node.getChildByName("upNeed").getChildByName("need")
need_node.getChildByName("exp").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(experience)
need_node.getChildByName("gold").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(gold)
need_node.getChildByName("exp").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.exp)
need_node.getChildByName("gold").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.gold)
}
show_luck(lv:number){
this.node.getChildByName("upBtn").active=lv > 0
this.node.getChildByName("upNeed").active=lv > 0
@@ -58,7 +65,7 @@ export class HInfoComp extends Component {
uplevel(){
let lv=smc.heros[this.h_uuid].lv
let {experience,gold}=getUpgradeResources(lv)
if(smc.vmdata.data.exp<=experience||smc.vmdata.data.gold<=gold){
if(smc.data.exp<=experience||smc.data.gold<=gold){
oops.gui.toast("经验或金币不足")
return
}

View File

@@ -36,15 +36,13 @@ export class MissionHomeComp extends CCComp {
oops.message.dispatchEvent(GameEvent.UpdateHero, {})
}
uodate_data(){
smc.syncData()
}
isWxClient(){
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
}
btn_func(e:string,data:any){
if(!this.isWxClient()){
smc.syncDataFromLocal() //调试用,正式环境去掉
}
// console.log("[MissionHomeComp]:btn_func",e,data)
let page_heros=this.node.getChildByName("heros_page")
let page_shop=this.node.getChildByName("shop_page")

View File

@@ -113,7 +113,7 @@ export class MissionMonCompComp extends CCComp { // 添加刷怪队列 - 使
// 根据新的关卡配置生成怪物
private generateMonstersFromStageConfig(monsterConfigs: any[]) {
const currentStage = smc.vmdata.data.mission;
const currentStage = smc.data.mission;
// 设置怪物总数
console.log("[MissionMonComp] generateMonstersFromStageConfig",monsterConfigs)

View File

@@ -0,0 +1,26 @@
import { _decorator, Component, Node } from 'cc';
import { GoodsComp } from './GoodsComp';
const { ccclass, property } = _decorator;
@ccclass('ShopPageComp')
export class ShopPageComp extends Component {
daily_goods:any[]=[1001,1002,1004,1006]
weekly_goods:any[]=[]
monthly_goods:any[]=[]
special_goods:any[]=[]
start() {
this.update_daily_goods()
}
update_daily_goods(){
let items=this.node.getChildByName("daily").getChildByName("items").children
for(let i=0;i<items.length;i++){
let goods=items[i]
goods.getComponent(GoodsComp).update_data(this.daily_goods[i])
}
}
update(deltaTime: number) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "6e8e04b0-e0eb-4668-8543-30322e2c359f",
"files": [],
"subMetas": {},
"userData": {}
}