165 lines
4.2 KiB
JavaScript
165 lines
4.2 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '3ce6b+D30lHVr2+Fd0yRxOE', 'cmp.home.member');
|
|
// Scripts/mod/home/cmps/cmp.home.member.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 家园场景角色
|
|
*
|
|
******************************************************************/
|
|
|
|
var NxSpine = require("nx.fx.spine");
|
|
var HomeMod = require("home.mod");
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {
|
|
spRole: {
|
|
"default": null,
|
|
type: NxSpine
|
|
},
|
|
nodReward: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
// 载入
|
|
onLoad: function onLoad() {
|
|
// 调试关闭
|
|
nx.gui.setActive(this, "dbg", false);
|
|
nx.gui.setActive(this, "role/shadow", false);
|
|
|
|
// 模型放大50%
|
|
this.spRole.node.scale = 1.5;
|
|
this.nodReward.scale = 0.75;
|
|
},
|
|
// 重置
|
|
reset: function reset() {
|
|
this.memKey = "";
|
|
this.reward = null;
|
|
this.spRole.stop(true);
|
|
this.nodReward.active = false;
|
|
nx.gui.setActive(this, "role/shadow", false);
|
|
this.unscheduleAllCallbacks();
|
|
},
|
|
// 新设置
|
|
setMember: function setMember(_info, _reward) {
|
|
var _this = this;
|
|
// 置空
|
|
if (nx.dt.objEmpty(_info)) {
|
|
this.reset();
|
|
return;
|
|
}
|
|
|
|
// 角色
|
|
var key = _info.partner_bid + "_" + _info.init_star;
|
|
if (this.memKey != key) {
|
|
// 资源配置
|
|
var cfgs = gdata("partner_data", "data_partner_star", key);
|
|
if (!cfgs) {
|
|
nx.error("无效家园成员:", key);
|
|
this.reset();
|
|
return;
|
|
}
|
|
|
|
// 动画
|
|
this.memKey = key;
|
|
var path = PathTool.getSpinePath(cfgs.res_id, cfgs.res_id, false);
|
|
this.spRole.load(path, function (_e) {
|
|
if (!_e) {
|
|
_this.spRole.action("stand2", true);
|
|
nx.gui.setActive(_this, "role/shadow", true);
|
|
_this.readyMove();
|
|
} else {
|
|
_this.spRole.stop(true);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 奖励
|
|
nx.gui.setActive(this.nodReward, "", false);
|
|
this.scheduleOnce(function () {
|
|
_this.showReward(_reward);
|
|
}, Math.random() / 2);
|
|
},
|
|
// 显示奖励
|
|
showReward: function showReward(_reward) {
|
|
var _this2 = this;
|
|
// 已经有奖励了
|
|
if (nx.dt.objEmpty(_reward)) {
|
|
return;
|
|
}
|
|
this.reward = _reward;
|
|
nx.gui.setActive(this.nodReward, "", true);
|
|
var path = PathTool.querySmallIconPath(this.reward.icon);
|
|
nx.gui.setSpriteFrame(this.nodReward, "icon", path, function (_ret) {
|
|
if (!_ret) {
|
|
path = PathTool.querySmallIconPath(0);
|
|
nx.gui.setSpriteFrame(_this2.nodReward, "icon", path);
|
|
}
|
|
});
|
|
|
|
// 悬浮展示
|
|
var cmp = nx.gui.getComponent(this.nodReward, "", "nx.actor.suspending", true);
|
|
if (cmp) {
|
|
cmp.start(2, 10);
|
|
}
|
|
},
|
|
// 点击奖励
|
|
onTouchReward: function onTouchReward() {
|
|
var _this3 = this;
|
|
// 无奖励
|
|
if (nx.dt.objEmpty(this.reward)) {
|
|
return;
|
|
}
|
|
HomeMod.getInstance().reqGetReward(this.reward.reward_id, function (_ret, _data) {
|
|
_this3.reward = null;
|
|
nx.gui.setActive(_this3.nodReward, "", false);
|
|
if (!_ret) {
|
|
nx.tbox(_data);
|
|
return;
|
|
}
|
|
});
|
|
},
|
|
// ----------------------------------------------------------------------
|
|
// 原地移动
|
|
// ----------------------------------------------------------------------
|
|
|
|
// 准备移动
|
|
readyMove: function readyMove() {
|
|
var _this4 = this;
|
|
var dbg = nx.gui.find(this, "dbg");
|
|
if (!dbg) {
|
|
return;
|
|
}
|
|
if (this.memKey == "") {
|
|
return;
|
|
}
|
|
if (!this.moveRange) {
|
|
this.moveRange = cc.v2(-dbg.width / 2, dbg.width / 2);
|
|
}
|
|
|
|
// 延迟随机移动
|
|
this.scheduleOnce(function () {
|
|
_this4.randomMove();
|
|
}, nx.dt.randomRange(5, 15));
|
|
},
|
|
// 随机移动
|
|
randomMove: function randomMove() {
|
|
var _this5 = this;
|
|
var x = nx.dt.randomRange(this.moveRange.x, this.moveRange.y);
|
|
var cur = this.spRole.node.position;
|
|
var tar = cc.v2(x, 0);
|
|
var secs = tar.sub(cur).len() / 100;
|
|
var scale = Math.abs(this.spRole.node.scaleX);
|
|
this.spRole.node.scaleX = scale * (tar.x < cur.x ? -1 : 1);
|
|
this.spRole.action("float", true);
|
|
nx.tween.moveTo(this.spRole, "", secs, cc.v2(x, 0), function () {
|
|
_this5.spRole.action("stand2", true);
|
|
_this5.readyMove();
|
|
});
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |