125 lines
3.1 KiB
JavaScript
125 lines
3.1 KiB
JavaScript
var gameConfig = require("gameConfig")
|
|
var Utils = require("Utils")
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
nd_info: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
pb_use: {
|
|
default: null,
|
|
type: cc.Prefab
|
|
},
|
|
nd_tableview: {
|
|
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
|
|
},
|
|
btn_use: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
|
|
nd_noitems: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
|
|
|
|
onLoad() {
|
|
cc.Notifier.on('choseitembag', this, this.choseitembag.bind(this));
|
|
cc.Notifier.on('ongetItemList', this, this.ongetItemList.bind(this))
|
|
},
|
|
onDestroy() {
|
|
cc.Notifier.off('choseitembag', this)
|
|
cc.Notifier.off('ongetItemList', this)
|
|
},
|
|
start() {
|
|
this.nowtype = 0
|
|
this.ongetItemList()
|
|
|
|
},
|
|
onclickuse() {
|
|
var cfg = gameConfig.all_ItemConfig[this.itemid]
|
|
if (cfg.type == 9 && cfg.sub_type == 1) {
|
|
cc.uiMain.calleditname(this.itemid)
|
|
} else {
|
|
var nd = cc.instantiate(this.pb_use)
|
|
nd.getComponent("baguse").initdata(this.itemid)
|
|
this.node.addChild(nd)
|
|
}
|
|
},
|
|
checkempty() {
|
|
if (cc.playerData.item_list.length == 0) {
|
|
this.nd_noitems.active = true
|
|
} else {
|
|
this.nd_noitems.active = false
|
|
}
|
|
},
|
|
ongetItemList() {
|
|
this.onclicktype(null, this.nowtype)
|
|
this.checkempty()
|
|
},
|
|
choseitembag(v) {
|
|
if (!v) {
|
|
this.nd_info.active = false
|
|
} else {
|
|
this.nd_info.active = true
|
|
|
|
this.itemid = v.itemid
|
|
this.lb_count.string = cc.playerData.getItemCount(this.itemid)
|
|
var cfg = gameConfig.all_ItemConfig[this.itemid]
|
|
this.lb_name.string = cfg.name
|
|
this.lb_des.string = cfg.des
|
|
if (cfg.use) {
|
|
this.btn_use.active = true
|
|
} else {
|
|
this.btn_use.active = false
|
|
}
|
|
|
|
Utils.setitem(this, this.itemid, this.sp_icon, this.sp_pz)
|
|
|
|
}
|
|
},
|
|
onclickclose() {
|
|
this.node.destroy()
|
|
},
|
|
onclicktype(v1, v2) {
|
|
this.nowtype = v2
|
|
var itemlist = cc.playerData.getItemsByType(Number(v2))
|
|
var newlist = Utils.arrtoarr(itemlist, 5)
|
|
this.nd_tableview.getComponent("tableView").initTableView(newlist.length, {
|
|
array: newlist,
|
|
target: this,
|
|
});
|
|
this.choseitembag(null)
|
|
},
|
|
|
|
// update (dt) {},
|
|
}); |