87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
var gameConfig = require("gameConfig")
|
|
var Utils = require("Utils")
|
|
var NetManage = require("NetManage")
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
btn_sub: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
btn_add: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
lb_count: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
lb_name: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
lb_des: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
sp_pz: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
sp_icon: {
|
|
default: null,
|
|
type: cc.Sprite
|
|
},
|
|
lb_count2: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
onLoad() {
|
|
cc.Notifier.on('ongetItemList', this, this.onclose.bind(this))
|
|
},
|
|
onDestroy() {
|
|
cc.Notifier.off('ongetItemList', this)
|
|
},
|
|
initdata(id) {
|
|
this.itemid = id
|
|
this.usedcount = 1
|
|
this.lb_count2.string = this.usedcount
|
|
this.totalcount = cc.playerData.getItemCount(this.itemid)
|
|
this.lb_count.string = this.totalcount
|
|
var cfg = gameConfig.all_ItemConfig[this.itemid]
|
|
this.lb_name.string = cfg.name
|
|
this.lb_des.string = cfg.des
|
|
|
|
|
|
Utils.setitem(this, this.itemid, this.sp_icon,this.sp_pz)
|
|
|
|
},
|
|
fixcount() {
|
|
this.usedcount = Math.max(1, Math.min(this.usedcount, this.totalcount))
|
|
this.lb_count2.string = this.usedcount
|
|
},
|
|
onclose() {
|
|
this.node.destroy()
|
|
},
|
|
onuse() {
|
|
NetManage.useitem(this.itemid, this.usedcount)
|
|
},
|
|
onadd() {
|
|
this.usedcount++;
|
|
this.fixcount()
|
|
|
|
},
|
|
onsub() {
|
|
this.usedcount--;
|
|
this.fixcount()
|
|
},
|
|
|
|
// update (dt) {},
|
|
}); |