开始商店 脚本和ui
This commit is contained in:
@@ -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() {
|
||||
|
||||
73
assets/script/game/map/GoodsComp.ts
Normal file
73
assets/script/game/map/GoodsComp.ts
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/map/GoodsComp.ts.meta
Normal file
9
assets/script/game/map/GoodsComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e24167ce-79d0-4f99-a3d8-f144bbe959a3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
26
assets/script/game/map/ShopPageComp.ts
Normal file
26
assets/script/game/map/ShopPageComp.ts
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/map/ShopPageComp.ts.meta
Normal file
9
assets/script/game/map/ShopPageComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6e8e04b0-e0eb-4668-8543-30322e2c359f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user