pubgv3/assets/scripts/UI/guns/guns_single.ts
zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

62 lines
1.4 KiB
TypeScript

import { all_ItemConfig } from '../../game/gameConfig';
import { uimanger } from '../UIManger';
const { ccclass, property } = cc._decorator;
@ccclass
export class guns_single extends cc.Component {
@property(cc.Label) label: cc.Label = null;
@property(cc.Node) imgNode: cc.Node = null;
@property(cc.Prefab) infoPage: cc.Prefab = null;
private curData = {};
private guninfo = {};
init(data) {
if (data == 0) {
this.node.active = false;
return;
}
// console.log(data)
this.node.active = true;
this.curData = data;
const imgConfigs = all_ItemConfig[data.gun_id];
this.label.string = imgConfigs.name;
this.setItemImg(this.imgNode, imgConfigs.icon);
// console.log(imgConfigs)
this.guninfo = {
name: imgConfigs.icon,
weapon_id: parseInt(data.gun_id),
weapon_lv: parseInt(data.fun_lv),
weapon_uniid: data.gun_uniid,
ammo: 30,
volume: 30
}
// console.log(`gungungun---${JSON.stringify(this.guninfo)}`)
this.node.name = JSON.stringify(this.guninfo);
}
showInfo() {
uimanger.showUI(this.infoPage, this.curData);
}
setItemImg(imgNode: cc.Node, itemId: number) {
cc.loader.loadRes(`icons/${itemId}`, cc.SpriteFrame, (err, res) => {
imgNode.getComponent(cc.Sprite).spriteFrame = res;
});
// this.node.name = JSON.stringify(this.guninfo);
}
removeClickEvent() {
this.getComponent(cc.Button).clickEvents.length = 0;
}
}