168 lines
4.0 KiB
JavaScript
168 lines
4.0 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '6c118bQE2NBnbTEoMojKD2b', 'cmp.main.prompts');
|
||
|
|
// Scripts/mod/mainui/cmp/cmp.main.prompts.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 主界面 --- 底部提示队列
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var BridgeComponent = require("bridge.component");
|
||
|
|
cc.Class({
|
||
|
|
"extends": BridgeComponent,
|
||
|
|
properties: {
|
||
|
|
maxCount: {
|
||
|
|
"default": 4
|
||
|
|
},
|
||
|
|
spaceHor: {
|
||
|
|
"default": 100
|
||
|
|
},
|
||
|
|
nodTemp: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node
|
||
|
|
},
|
||
|
|
nodList: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 显示
|
||
|
|
onEnable: function onEnable() {
|
||
|
|
var _this = this;
|
||
|
|
this.cur = null;
|
||
|
|
|
||
|
|
// 视图监听
|
||
|
|
this.vbind([["Prompts", this.onPromptsUpdate.bind(this)]]);
|
||
|
|
this.scheduleOnce(function () {
|
||
|
|
_this.popNext();
|
||
|
|
}, 2);
|
||
|
|
|
||
|
|
// 全局支持
|
||
|
|
nx.bridge.prompt = this;
|
||
|
|
},
|
||
|
|
// 关闭
|
||
|
|
onDisable: function onDisable() {
|
||
|
|
// 全局支持
|
||
|
|
nx.bridge.prompt = null;
|
||
|
|
|
||
|
|
// 视图监听释放
|
||
|
|
this.vunbind();
|
||
|
|
},
|
||
|
|
// 提示队列更变
|
||
|
|
onPromptsUpdate: function onPromptsUpdate(_arr, _old, _init) {
|
||
|
|
if (_init) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 清理
|
||
|
|
if (nx.dt.arrEmpty(_arr)) {
|
||
|
|
this.nodList.removeAllChildren(true);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.popNext();
|
||
|
|
},
|
||
|
|
// 队列弹出
|
||
|
|
popNext: function popNext() {
|
||
|
|
var _this2 = this;
|
||
|
|
// 无效跳过
|
||
|
|
var arr = nx.bridge.vget("Prompts");
|
||
|
|
if (this.cur || nx.dt.arrEmpty(arr)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 满员跳过
|
||
|
|
if (this.nodList.childrenCount >= this.maxCount) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 弹出
|
||
|
|
this.cur = arr.shift();
|
||
|
|
nx.bridge.vset("Prompts", arr, false);
|
||
|
|
|
||
|
|
// 当前追加
|
||
|
|
var shows = nx.bridge.vget("PromptsShow");
|
||
|
|
shows.push(this.cur);
|
||
|
|
nx.bridge.vset("PromptsShow", shows);
|
||
|
|
|
||
|
|
// 创建
|
||
|
|
var node = cc.instantiate(this.nodTemp);
|
||
|
|
node.info = nx.dt.objClone(this.cur);
|
||
|
|
node.parent = this.nodList;
|
||
|
|
var path = cc.path.join("prefab/mainui/ui", this.cur.icon);
|
||
|
|
nx.gui.setSpriteFrame(node, "icon", path);
|
||
|
|
node.position = cc.v2(200, 0);
|
||
|
|
var tpos = cc.v2((this.nodList.childrenCount - 1) * this.spaceHor, 0);
|
||
|
|
nx.tween.fadeIn(node, "", 0.5);
|
||
|
|
nx.tween.moveTo(node, "", 0.5, tpos, function () {
|
||
|
|
_this2.cur = null;
|
||
|
|
_this2.popNext();
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// 布局更新
|
||
|
|
autoMove: function autoMove(_cb) {
|
||
|
|
var chds = this.nodList.children;
|
||
|
|
for (var i = 0; i < chds.length; ++i) {
|
||
|
|
var node = chds[i];
|
||
|
|
var pos = cc.v2(this.spaceHor * i, 0);
|
||
|
|
nx.tween.moveTo(node, "", 0.2, pos);
|
||
|
|
}
|
||
|
|
;
|
||
|
|
this.scheduleOnce(_cb, 0.2);
|
||
|
|
},
|
||
|
|
// 点击提示
|
||
|
|
onTouchTip: function onTouchTip(_tip) {
|
||
|
|
var _this3 = this;
|
||
|
|
var ifo = _tip ? _tip.info : null;
|
||
|
|
if (nx.dt.objEmpty(ifo)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 执行命令
|
||
|
|
nx.bridge.cmd.doStr(ifo.cmd);
|
||
|
|
|
||
|
|
// 当前移除
|
||
|
|
var shows = nx.bridge.vget("PromptsShow");
|
||
|
|
nx.dt.arrDelete(shows, function (_m) {
|
||
|
|
return _m && _m.id == ifo.id;
|
||
|
|
});
|
||
|
|
nx.bridge.vset("PromptsShow", shows);
|
||
|
|
|
||
|
|
// 消除提示
|
||
|
|
_tip.removeFromParent(true);
|
||
|
|
this.autoMove(function () {
|
||
|
|
_this3.popNext();
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// 下方提示关闭
|
||
|
|
delPrompt: function delPrompt(_id) {
|
||
|
|
// 从当前提示列表中剔除
|
||
|
|
for (var i in this.nodList.children) {
|
||
|
|
var tip = this.nodList.children[i];
|
||
|
|
if (tip && tip.info && tip.info.id == _id) {
|
||
|
|
// 当前移除
|
||
|
|
var shows = nx.bridge.vget("PromptsShow");
|
||
|
|
nx.dt.arrDelete(shows, function (_m) {
|
||
|
|
return _m && _m.id == _id;
|
||
|
|
});
|
||
|
|
nx.bridge.vset("PromptsShow", shows);
|
||
|
|
tip.removeFromParent(true);
|
||
|
|
this.popNext();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 从等待队列中剔除
|
||
|
|
var list = nx.bridge.vget("Prompts");
|
||
|
|
nx.dt.arrDelete(list, function (_m) {
|
||
|
|
return _m && _m.id == _id;
|
||
|
|
});
|
||
|
|
nx.bridge.vset("Prompts", list, false);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|