150 lines
4.8 KiB
JavaScript
150 lines
4.8 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'd1e71WNra1NiJH1LBnDKrMf', 'cmp.chat.wnd.input');
|
|
// Scripts/mod/chat/cmp/cmp.chat.wnd.input.js
|
|
|
|
"use strict";
|
|
|
|
var BridgeComp = require("bridge.component");
|
|
var ChatEvent = require("chat_event");
|
|
var RoleController = require("role_controller");
|
|
var ChatItemController = require("chat_item_controller");
|
|
var ChatConst = require("chat_const");
|
|
var ChatCtrl = require("chat_controller");
|
|
cc.Class({
|
|
"extends": BridgeComp,
|
|
properties: {
|
|
input_ed: {
|
|
"default": null,
|
|
type: cc.EditBox
|
|
},
|
|
chat_input_list: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
// LIFE-CYCLE CALLBACKS:
|
|
onLoad: function onLoad() {
|
|
this._super();
|
|
this.chat_item_ctrl = ChatItemController.getInstance();
|
|
this.ctrl = ChatCtrl.getInstance();
|
|
this.item_code_list = {}; // item eqip存储信息
|
|
this.item_desc_list = {};
|
|
this.select_face = [];
|
|
this.input_ed.placeholderLabel.string = nx.text.getKey("CHatEmpTips");
|
|
this.bindGEvent(ChatEvent.CHAT_SELECT_ITEM, this.onEditTextAddItem.bind(this));
|
|
},
|
|
start: function start() {},
|
|
onEnable: function onEnable() {},
|
|
onDisable: function onDisable() {},
|
|
setSendCallback: function setSendCallback(send_cb) {
|
|
this.send_cb = send_cb;
|
|
},
|
|
repleaceAtPeopleText: function repleaceAtPeopleText(text, srv_id) {
|
|
var num1 = text.search(/@/);
|
|
var num2 = text.search(/ /);
|
|
if (num1 != -1 && num2 != -1) {
|
|
var at = text.substring(num1, num2);
|
|
var rep = cc.js.formatStr("<on click='handler' param='atpeople srvid=%s'><u>%s</u></on>", srv_id, at + " ");
|
|
text = text.replace(at, rep);
|
|
}
|
|
return text;
|
|
},
|
|
setChannel: function setChannel(channel) {
|
|
this.channel = channel;
|
|
},
|
|
didClickSendBtn: function didClickSendBtn() {
|
|
var seedMesageArr = this.getInputText();
|
|
if (nx.dt.arrEmpty(seedMesageArr)) return;
|
|
var seedMesage = seedMesageArr[0] || "";
|
|
var srv_id = seedMesageArr[1] || "";
|
|
if (seedMesage.length > 0 && this.send_cb) {
|
|
// 替换表情
|
|
var message = this.chat_item_ctrl.relapceFaceIconTag(seedMesage); // 替换表情
|
|
// 替换teim
|
|
for (var item_i in this.item_code_list) {
|
|
var item_info = this.item_code_list[item_i];
|
|
message = message.replace(new RegExp(item_info.key, 'i'), item_info.desc);
|
|
}
|
|
if (this.channel == ChatConst.Channel.World || this.channel == ChatConst.Channel.Cross || this.channel == ChatConst.Channel.Province || this.channel == ChatConst.Channel.Gang) {
|
|
//世界聊天 跨服聊天 同省聊天 帮派聊天
|
|
message = this.repleaceAtPeopleText(message, srv_id);
|
|
}
|
|
if (this.ctrl.canSend(this.channel)) {
|
|
this.input_ed.string = "";
|
|
}
|
|
this.send_cb(message);
|
|
this.chat_input_list.active = false;
|
|
this.select_face = [];
|
|
}
|
|
},
|
|
onClickFaceBtn: function onClickFaceBtn() {
|
|
var cmp = this.chat_input_list.getComponent("cmp.chat.wnd.inputlist");
|
|
cmp.setSelectCB(this.onEditTextAddFace.bind(this));
|
|
this.chat_input_list.active = !this.chat_input_list.active;
|
|
},
|
|
// 选中表情返回
|
|
onEditTextAddFace: function onEditTextAddFace(face_txt) {
|
|
if (face_txt) {
|
|
if (this.select_face.length < 5) {
|
|
this.select_face.push(face_txt);
|
|
this.input_ed.string += face_txt;
|
|
} else {
|
|
nx.tbox(nx.text.getKey("ChatFaceLimit"));
|
|
}
|
|
}
|
|
},
|
|
onEditTextAddItem: function onEditTextAddItem(data) {
|
|
if (!data) return;
|
|
var text = this.input_ed.string;
|
|
if (text == "") {
|
|
this.item_code_list = {};
|
|
this.item_desc_list = {};
|
|
}
|
|
var base_id = data.base_id;
|
|
var share_id = data.share_id;
|
|
var count = data.count;
|
|
var role_vo = RoleController.getInstance().getRoleVo();
|
|
var item_config = Utils.getItemConfig(base_id);
|
|
var code = data.code;
|
|
if (item_config) {
|
|
var key = cc.js.formatStr("{%s,%s}", share_id, item_config.name);
|
|
var desc = this.chat_item_ctrl.buildItemMsg(base_id, role_vo.srv_id, share_id, count);
|
|
if (this.item_code_list[code]) {
|
|
var cur_object = this.item_code_list[code];
|
|
var cur_key = cur_object.key;
|
|
var cur_desc = cur_object.desc;
|
|
// 获取原有的
|
|
text = text.replace(cur_key, key);
|
|
} else {
|
|
text = text + key;
|
|
}
|
|
this.item_code_list[code] = {
|
|
key: key,
|
|
desc: desc
|
|
};
|
|
this.input_ed.string = text;
|
|
}
|
|
},
|
|
setPlacholderLabel: function setPlacholderLabel(str) {
|
|
if (this.input_ed.placholderLabel && str) {
|
|
this.input_ed.placholderLabel.string = str;
|
|
}
|
|
},
|
|
// 文本框内容
|
|
getInputText: function getInputText() {
|
|
return [this.input_ed.string, this.extend];
|
|
},
|
|
setInputText: function setInputText(str, extend) {
|
|
this.extend = extend;
|
|
if (this.input_ed) {
|
|
if (!str) {
|
|
str = "";
|
|
}
|
|
this.input_ed.string = str;
|
|
}
|
|
}
|
|
|
|
// update (dt) {},
|
|
});
|
|
|
|
cc._RF.pop(); |