pubgv3/assets/scripts/chat/dalabachat.js
2022-05-26 11:46:36 +08:00

137 lines
3.0 KiB
JavaScript

var gameConfig = require('gameConfig');
var playerData = require('playerData');
var SDKManage = require('SDKManage');
var NetManage = require('NetManage');
var Main = require('Main');
cc.Class({
extends: cc.Component,
properties: {
editbox: {
default: null,
type: cc.EditBox,
},
lb_labanum: {
default: null,
type: cc.Label,
},
lb_strlength: {
default: null,
type: cc.Label,
},
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
onLoad() {
cc.Notifier.on('deleteItem', this, this.deleteItem.bind(this));
this.editbox.node.on('editing-did-began', this.callbackbegin, this);
this.editbox.node.on('editing-did-ended', this.callbackreturn, this);
this.editbox.node.on('editing-return', this.callbackreturn, this);
cc.Notifier.on('clickemote', this, this.doemot.bind(this));
this.close_status = true;
},
onDestroy() {
cc.Notifier.off('deleteItem', this);
cc.Notifier.off('clickemote', this);
},
start() {
cc.Notifier.emit('setemotepos', {
x: 25,
y: -61,
});
this.num = tonyInfo.instance().m_10105ItemNum;
this.lb_labanum.string = cc.language.stringformat('sylb') + this.num;
//this.showstrlen()
},
callbackbegin(editbox) {
// do whatever you want with the editbox
this.close_status = false;
},
callbackreturn(editbox) {
this.close_status = true;
//this.showstrlen()
},
onBtnSend() {
if (this.editbox.string == '') {
cc.uiHelper.showTips(cc.language.stringformat('neitongweikong'));
return;
}
if (this.num == 0) {
cc.uiHelper.showTips(cc.language.stringformat('lbbz'));
this.editbox.string = '';
//this.showstrlen()
return;
}
NetManage.deleteItem(10105);
cc.chatMgr.sendmsg('CMSendChatMsg', {
chat_channel: 5,
target: '',
msg_type: 2,
msg_body: this.editbox.string,
members: [],
});
this.editbox.string = '';
},
calldalabaemote() {
cc.Notifier.emit('callemote');
},
doemot(v2) {
var temp = this.editbox;
//this.nd_emot.active = false
cc.Notifier.emit('closeemote');
var add = '(' + v2 + ')';
var str1 = temp.string;
var str2 = temp.string + add;
temp.string = str2;
if (temp.string != str2) {
temp.string = str1;
}
},
deleteItem(obj) {
if (obj.errcode != 0) {
this.id = obj.id;
this.num = 2; //obj.num
this.lb_labanum.string =
cc.language.stringformat('sylb2') + this.num;
cc.chatMgr.sendmsg('CMSendChatMsg', {
chat_channel: 5,
target: '',
msg_type: 2,
msg_body: this.editbox.string,
members: [],
});
} else if (obj.errcode == 102) {
cc.uiHelper.showTips(cc.language.stringformat('lbbz'));
}
this.editbox.string = '';
//this.showstrlen()
SDKManage.logEvent('dalaba_say', 'dalabajishu');
if (tonyInfo.instance().m_10105ItemNum > 0) {
tonyInfo.instance().m_10105ItemNum--;
cc.Notifier.emit('update10105Cnt');
}
this.close();
},
close() {
cc.Notifier.emit('setemotepos', {
x: -232,
y: -172,
});
this.node.destroy();
},
});