pubgv3/assets/scripts/UI/UIShop/ShopItem.ts
guoqing.zhu 067c712f62 udpate
2022-06-14 13:51:53 +08:00

54 lines
1.4 KiB
TypeScript

import { PurchaseTip } from '../../tips/PurchaseTip';
import { uimanger } from '../UIManger';
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;
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];
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,
};
uimanger.showUI(PurchaseTip.prefabPath, data);
}
}