pubgv3/assets/scripts/UI/UIShop/ShopItem.ts
guoqing.zhu bfdc4f0212 update
2022-06-15 16:12:58 +08:00

59 lines
1.5 KiB
TypeScript

var gameConfig = require('gameConfig');
const { ccclass, property } = cc._decorator;
@ccclass
export class ShopItem extends cc.Component {
@property(cc.Label) lb_cost: cc.Label = null;
@property(cc.Label) lb_name: cc.Label = null;
@property(sp.Skeleton) heroSpine: sp.Skeleton = null;
@property(cc.Sprite) zhiye: cc.Sprite = null;
@property(cc.Prefab) buyTip: cc.Prefab = null;
public goodId = 0;
init(data) {
this.goodId = data.goods_id;
this.lb_cost.string = data.price_info.cost_list[0][0].item_num;
//
var cfg = gameConfig.playerConfig[data.item_id];
if (this.lb_name) this.lb_name.string = cfg.name;
var skinres = cc.playerData.getheroSkinbyId(data.item_id, 0);
cc.loader.loadRes(
'spine/heropic/pic_hero' + skinres,
sp.SkeletonData,
function (err, sp) {
this.heroSpine.skeletonData = sp;
this.heroSpine._updateSkeletonData();
this.heroSpine.setAnimation(0, 'animation', true);
}.bind(this)
);
var heroType = gameConfig.playerConfig[data.item_id].herotype;
let url = 'textures/heroType/ht_s_' + heroType;
cc.loader.loadRes(
url,
cc.SpriteFrame,
function (err, res) {
if (!err && this.isValid) {
this.zhiye.spriteFrame = res;
}
}.bind(this)
);
}
onBuy() {
var data = {
cost: this.lb_cost.string,
goods_id: this.goodId,
};
var node = cc.instantiate(this.buyTip);
node.getComponent('PruchaseTip').init(data);
var dd = cc.find('Canvas');
dd.addChild(node);
// uimanger.showUI(PurchaseTip.prefabPath, data);
}
}