zhuguoqing 53febf2dc4 update
2022-05-28 10:31:45 +08:00

134 lines
3.6 KiB
JavaScript

let viewCell = require("viewCell")
var gameConfig = require("gameConfig")
var NetManage = require("NetManage")
var Utils = require("Utils")
cc.Class({
extends: viewCell,
properties: {
nd_head: {
default: null,
type: cc.Node,
},
nd_headframe: {
default: null,
type: cc.Node,
},
nd_hero: {
default: null,
type: cc.Node,
},
sp_head: {
default: null,
type: cc.Sprite,
},
sp_frame: {
default: null,
type: cc.Sprite,
},
spine_hero: {
default: null,
type: sp.Skeleton
},
lb_name: {
default: null,
type: cc.Label,
},
nd_using: {
default: null,
type: cc.Node,
},
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
init: function(index, data, reload, group) {
if (index >= data.array.length) {
this.node.active = false
return;
}
this.target = data.target
var sdata = data.array[index]
this.initdata(sdata)
},
initdata(v) {
this.itemid = v
var cfg = gameConfig.all_ItemConfig[v]
this.lb_name.string = cfg.name
this.nd_head.active = this.nd_headframe.active = this.nd_hero.active = false
var type = cfg.type
var usedid = 0
if (type == 3) {
this.nd_hero.active = true
usedid = cc.playerData.hero_id
var skinres = cc.playerData.getheroSkinbyId(v, 0)
cc.loader.loadRes("spine/heropic/pic_hero" + skinres, sp.SkeletonData, function(err, sp) {
this.spine_hero.skeletonData = sp;
this.spine_hero._updateSkeletonData();
this.spine_hero.setAnimation(0, "animation", true);
}.bind(this));
} else if (type == 5) {
this.nd_head.active = true
usedid = cc.playerData.head_id
Utils.setitem(this, this.itemid, this.sp_head)
} else if (type == 6) {
this.nd_headframe.active = true
usedid = cc.playerData.head_frame
Utils.setitem(this, this.itemid, this.sp_frame)
}
if (this.itemid == usedid) {
this.nd_using.active = true
} else {
this.nd_using.active = false
}
this.itemtype = type
},
onDisable() {
cc.Notifier.off('choseiteminfo', this);
this.inited = false
},
onEnable() {
if (!this.inited) {
cc.Notifier.on('choseiteminfo', this, this.choseiteminfo.bind(this));
this.inited = true
}
},
choseiteminfo(v) {
if (this.itemtype != v.itemtype) {
return
}
if (this.itemid == v.usedid) {
this.nd_using.active = true
} else {
this.nd_using.active = false
}
},
onclickuse() {
cc.Notifier.emit('choseiteminfo', {
usedid: this.itemid,
itemtype: this.itemtype,
});
var kname
if (this.itemtype == 3) {
kname = "hero_id"
} else if (this.itemtype == 5) {
kname = "head_id"
} else if (this.itemtype == 6) {
kname = "head_frame"
}
NetManage.updateuseinfo({
[kname]:this.itemid
})
},
// update (dt) {},
});