商店 基本完成
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,13 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
meat:0,
|
meat:0,
|
||||||
exp:0,
|
exp:0,
|
||||||
}
|
}
|
||||||
|
shop:any={
|
||||||
|
daily_goods:[],
|
||||||
|
weekly_goods:[],
|
||||||
|
monthly_goods:[],
|
||||||
|
special_goods:[],
|
||||||
|
goods_count:[1,3,1,3],
|
||||||
|
}
|
||||||
fight_heros:any={ 0:5001, 1:5005, 2:0, 3:0, 4:0, }
|
fight_heros:any={ 0:5001, 1:5005, 2:0, 3:0, 4:0, }
|
||||||
heros:any = {
|
heros:any = {
|
||||||
5001:{uuid:5001,lv:1},
|
5001:{uuid:5001,lv:1},
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { _decorator, Component, Node, Label, Sprite, SpriteFrame, resources } fr
|
|||||||
import { Goods, GType, CType } from '../common/config/Goods';
|
import { Goods, GType, CType } from '../common/config/Goods';
|
||||||
import { Items } from '../common/config/Items';
|
import { Items } from '../common/config/Items';
|
||||||
import { NumberFormatter } from '../common/config/BoxSet';
|
import { NumberFormatter } from '../common/config/BoxSet';
|
||||||
|
import { smc } from '../common/SingletonModuleComp';
|
||||||
|
import { oops } from 'db://oops-framework/core/Oops';
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass('GoodsComp')
|
@ccclass('GoodsComp')
|
||||||
@@ -10,12 +12,14 @@ export class GoodsComp extends Component {
|
|||||||
private goodsData: any = null;
|
private goodsData: any = null;
|
||||||
private itemData: any = null;
|
private itemData: any = null;
|
||||||
private currentUuid: number = 0;
|
private currentUuid: number = 0;
|
||||||
|
goods_count_key:number=-1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新物品数据
|
* 更新物品数据
|
||||||
* @param uuid 物品UUID
|
* @param uuid 物品UUID
|
||||||
*/
|
*/
|
||||||
update_data(uuid: number) {
|
update_data(uuid: number,key:number) {
|
||||||
|
this.goods_count_key=key
|
||||||
this.currentUuid = uuid;
|
this.currentUuid = uuid;
|
||||||
this.goodsData = Goods[uuid];
|
this.goodsData = Goods[uuid];
|
||||||
|
|
||||||
@@ -32,19 +36,34 @@ export class GoodsComp extends Component {
|
|||||||
|
|
||||||
this.updateIcon();
|
this.updateIcon();
|
||||||
this.updateTexts();
|
this.updateTexts();
|
||||||
this.update_btn(this.goodsData.c_type)
|
this.update_btn()
|
||||||
|
this.update_max_num()
|
||||||
}
|
}
|
||||||
update_btn(type:CType){
|
private update_btn( ){
|
||||||
this.node.getChildByName("ad").active=type==CType.AD
|
if(smc.shop.goods_count[this.goods_count_key]<=0){
|
||||||
this.node.getChildByName("free").active=type==CType.FREE
|
this.node.getChildByName("ad").active=false
|
||||||
this.node.getChildByName("cast").active=type==(CType.DIAMOND||CType.GOLD)
|
this.node.getChildByName("free").active=false
|
||||||
this.node.getChildByName("cast").getChildByName("diamond").active=type==CType.DIAMOND
|
this.node.getChildByName("cast").active=false
|
||||||
this.node.getChildByName("cast").getChildByName("gold").active=type==CType.GOLD
|
this.node.getChildByName("nothing").active=true
|
||||||
|
this.node.getChildByName("btn").getComponent(Sprite).grayscale=true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.node.getChildByName("nothing").active=false
|
||||||
|
this.node.getChildByName("btn").getComponent(Sprite).grayscale=false
|
||||||
|
this.node.getChildByName("ad").active=this.goodsData.c_type==CType.AD
|
||||||
|
this.node.getChildByName("free").active=this.goodsData.c_type==CType.FREE
|
||||||
|
this.node.getChildByName("cast").active=this.goodsData.c_type==(CType.DIAMOND||CType.GOLD)
|
||||||
|
this.node.getChildByName("cast").getChildByName("diamond").active=this.goodsData.c_type==CType.DIAMOND
|
||||||
|
this.node.getChildByName("cast").getChildByName("gold").active=this.goodsData.c_type==CType.GOLD
|
||||||
this.node.getChildByName("cast").getChildByName("num").getComponent(Label).string=NumberFormatter.formatNumber(this.goodsData.cast)
|
this.node.getChildByName("cast").getChildByName("num").getComponent(Label).string=NumberFormatter.formatNumber(this.goodsData.cast)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 更新图标
|
* 更新图标
|
||||||
*/
|
*/
|
||||||
|
private update_max_num(){
|
||||||
|
this.node.getChildByName("max").getComponent(Label).string=NumberFormatter.formatNumber(smc.shop.goods_count[this.goods_count_key])
|
||||||
|
|
||||||
|
}
|
||||||
private updateIcon() {
|
private updateIcon() {
|
||||||
const iconSprite = this.node.getChildByName("icon")?.getComponent(Sprite);
|
const iconSprite = this.node.getChildByName("icon")?.getComponent(Sprite);
|
||||||
if (!iconSprite) return;
|
if (!iconSprite) return;
|
||||||
@@ -67,6 +86,72 @@ export class GoodsComp extends Component {
|
|||||||
const mainNumLabel = this.node.getChildByName("num")?.getComponent(Label);
|
const mainNumLabel = this.node.getChildByName("num")?.getComponent(Label);
|
||||||
if (mainNumLabel) mainNumLabel.string = NumberFormatter.formatNumber(this.goodsData.num);
|
if (mainNumLabel) mainNumLabel.string = NumberFormatter.formatNumber(this.goodsData.num);
|
||||||
}
|
}
|
||||||
|
to_buy(){
|
||||||
|
if(smc.shop.goods_count[this.goods_count_key]<=0){
|
||||||
|
oops.gui.toast("商品已售罄")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(this.goodsData.c_type==CType.AD){
|
||||||
|
this.do_ad()
|
||||||
|
}else if(this.goodsData.c_type==CType.FREE){
|
||||||
|
this.do_free()
|
||||||
|
}else if(this.goodsData.c_type==CType.DIAMOND){
|
||||||
|
this.do_diamond_cast()
|
||||||
|
}else if(this.goodsData.c_type==CType.GOLD){
|
||||||
|
this.do_gold_cast()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do_buy(){
|
||||||
|
console.log("[GoodsComp]do_buy",this.goodsData,this.itemData)
|
||||||
|
switch(this.goodsData.type){
|
||||||
|
case GType.ITEM:
|
||||||
|
smc.addItem(this.itemData.uuid,this.goodsData.num) //添加物品
|
||||||
|
break
|
||||||
|
case GType.GOLD:
|
||||||
|
smc.addGold(this.goodsData.num) //添加金币
|
||||||
|
break
|
||||||
|
case GType.DIAMOND:
|
||||||
|
smc.addDiamond(this.goodsData.num) //添加钻石
|
||||||
|
break
|
||||||
|
case GType.MEAT: //添加肉
|
||||||
|
break
|
||||||
|
case GType.EXP: //添加经验
|
||||||
|
smc.addExp(this.goodsData.num)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
smc.shop.goods_count[this.goods_count_key]--
|
||||||
|
this.update_btn()
|
||||||
|
this.update_max_num()
|
||||||
|
}
|
||||||
|
|
||||||
|
do_ad(){
|
||||||
|
if(this.goodsData.c_type==CType.AD){
|
||||||
|
this.do_ad_back(this.do_buy,this.ad_back_false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ad_back_false(){
|
||||||
|
console.log("ad_back_false")
|
||||||
|
}
|
||||||
|
do_ad_back(success:Function,fail:Function){
|
||||||
|
success.call(this)
|
||||||
|
}
|
||||||
|
do_free(){
|
||||||
|
if(this.goodsData.c_type==CType.FREE){
|
||||||
|
this.do_buy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do_diamond_cast(){
|
||||||
|
if(this.goodsData.c_type==CType.DIAMOND){
|
||||||
|
smc.spendDiamond(this.goodsData.cast)
|
||||||
|
this.do_buy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do_gold_cast(){
|
||||||
|
if(this.goodsData.c_type==CType.GOLD){
|
||||||
|
smc.spendGold(this.goodsData.cast)
|
||||||
|
this.do_buy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class ShopPageComp extends Component {
|
|||||||
let items=this.node.getChildByName("daily").getChildByName("items").children
|
let items=this.node.getChildByName("daily").getChildByName("items").children
|
||||||
for(let i=0;i<items.length;i++){
|
for(let i=0;i<items.length;i++){
|
||||||
let goods=items[i]
|
let goods=items[i]
|
||||||
goods.getComponent(GoodsComp).update_data(this.daily_goods[i])
|
goods.getComponent(GoodsComp).update_data(this.daily_goods[i],i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update(deltaTime: number) {
|
update(deltaTime: number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user