pubgv3/assets/scripts/chat/dalabachat.js
zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

151 lines
4.2 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()
},
// showstrlen(){
// if (30 - this.editbox.string.length < 0) {
// this.lb_strlength.string = '剩余可输入字数: 0'
// this.editbox.string = this.editbox.string.slice(0, 30)
// } else {
// this.lb_strlength.string = '剩余可输入字数: ' + (30 - this.editbox.string.length)
// }
// },
callbackbegin(editbox) {
// 回调的参数是 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) {
console.log("使用道具=======",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()
//console.log("dalaba_say", "使用大喇叭计次")
SDKManage.logEvent("dalaba_say", "使用大喇叭计次")
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()
},
});