mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-02 07:29:34 +08:00
完善pomelo客户端
This commit is contained in:
5
PomeloClient/assets/Script/view/chat.meta
Normal file
5
PomeloClient/assets/Script/view/chat.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "33659f56-7756-4b3d-b02d-aa1deff9729e",
|
||||
"subMetas": {}
|
||||
}
|
||||
26
PomeloClient/assets/Script/view/chat/ChatItem.js
Normal file
26
PomeloClient/assets/Script/view/chat/ChatItem.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const timeUtil = require('TimeUtil');
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
timeLabel: cc.Label,
|
||||
nameLabel: cc.Label,
|
||||
contextLabel: cc.Label
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
|
||||
init(data) {
|
||||
this.contextLabel.node.active = false;
|
||||
this.timeLabel.string = timeUtil.timeString(new Date());
|
||||
this.nameLabel.string = data.name + ' : ' + data.msg;
|
||||
}
|
||||
|
||||
// start () {
|
||||
|
||||
// },
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
PomeloClient/assets/Script/view/chat/ChatItem.js.meta
Normal file
9
PomeloClient/assets/Script/view/chat/ChatItem.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "4fde3bae-aba9-4942-9679-3a8c5ac97448",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
28
PomeloClient/assets/Script/view/chat/ChatUi.js
Normal file
28
PomeloClient/assets/Script/view/chat/ChatUi.js
Normal file
@@ -0,0 +1,28 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodeContent: cc.Node,
|
||||
prefabItem: cc.Prefab,
|
||||
editBoxInput: cc.EditBox
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.nodeContent.removeAllChildren();
|
||||
},
|
||||
|
||||
createItem(data, componentName) {
|
||||
let node = cc.instantiate(this.prefabItem);
|
||||
node.script = node.getComponent(componentName);
|
||||
node.script.init();
|
||||
this.nodeContent.addChild(node);
|
||||
},
|
||||
|
||||
onEventClicked_send() {
|
||||
if (!this.editBoxInput.string) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
PomeloClient/assets/Script/view/chat/ChatUi.js.meta
Normal file
9
PomeloClient/assets/Script/view/chat/ChatUi.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "022bc4ef-5334-4a19-a38b-0238660ddabc",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
22
PomeloClient/assets/Script/view/chat/ChatUserItem.js
Normal file
22
PomeloClient/assets/Script/view/chat/ChatUserItem.js
Normal file
@@ -0,0 +1,22 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
labelName: cc.Label
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
|
||||
init(name) {
|
||||
|
||||
this.labelName.string = name;
|
||||
}
|
||||
|
||||
// start () {
|
||||
|
||||
// },
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "5ee70e85-f69b-4fcf-b209-e9d12a0ebeea",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
14
PomeloClient/assets/Script/view/chat/ChatUserUi.js
Normal file
14
PomeloClient/assets/Script/view/chat/ChatUserUi.js
Normal file
@@ -0,0 +1,14 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodeContext: cc.Node
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.nodeContext.removeAllChildren();
|
||||
},
|
||||
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
PomeloClient/assets/Script/view/chat/ChatUserUi.js.meta
Normal file
9
PomeloClient/assets/Script/view/chat/ChatUserUi.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "2092b3d2-067d-47f5-93f0-033a06008068",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
5
PomeloClient/assets/Script/view/common.meta
Normal file
5
PomeloClient/assets/Script/view/common.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "be92e8c5-4737-4f45-a958-7afcca0015c5",
|
||||
"subMetas": {}
|
||||
}
|
||||
44
PomeloClient/assets/Script/view/common/ScrollViewMgr.js
Normal file
44
PomeloClient/assets/Script/view/common/ScrollViewMgr.js
Normal file
@@ -0,0 +1,44 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodeContent: cc.Node,
|
||||
prefabItem: cc.Prefab,
|
||||
itemName: ''
|
||||
},
|
||||
|
||||
// onLoad() {
|
||||
|
||||
// },
|
||||
|
||||
init(args = {}) {
|
||||
this.clear();
|
||||
let data = args.data || [];
|
||||
let len = data.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
this.createItem({
|
||||
data: data[i],
|
||||
fn: args.fn
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
createItem(args) {
|
||||
let data = args.data
|
||||
let node = cc.instantiate(this.prefabItem);
|
||||
node.script = node.getComponent(this.itemName);
|
||||
this.nodeContent.addChild(node);
|
||||
node.script.init(data);
|
||||
args.fn && args.fn(node.script)
|
||||
},
|
||||
|
||||
clear() {
|
||||
this.nodeContent.removeAllChildren();
|
||||
},
|
||||
|
||||
childrenCount() {
|
||||
return this.nodeContent.childrenCount;
|
||||
}
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "b2a96011-d6e0-447f-b6b9-1dd3bbb3df35",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
5
PomeloClient/assets/Script/view/scene.meta
Normal file
5
PomeloClient/assets/Script/view/scene.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "48dfcc38-233e-499e-9681-7a182fa0c907",
|
||||
"subMetas": {}
|
||||
}
|
||||
69
PomeloClient/assets/Script/view/scene/ChatScene.js
Normal file
69
PomeloClient/assets/Script/view/scene/ChatScene.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const chatRoomApi = require('ChatRoomApi');
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodeScrollViewChat: cc.Node,
|
||||
nodeScrollViewUser: cc.Node,
|
||||
editBoxInput: cc.EditBox
|
||||
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
console.log('ChatRoomApi');
|
||||
this.nodeScrollViewChatScript = this.nodeScrollViewChat.getComponent('ScrollViewMgr');
|
||||
this.nodeScrollViewUserScript = this.nodeScrollViewUser.getComponent('ScrollViewMgr');
|
||||
console.log(this.chatUiScript);
|
||||
this.nodeScrollViewChatScript.init();
|
||||
this.nodeScrollViewUserScript.init({
|
||||
data: myModel.chatUserModel.getUser()
|
||||
});
|
||||
let opts = {};
|
||||
opts.onAdd = this.onAdd.bind(this);
|
||||
opts.onChat = this.onChat.bind(this);
|
||||
chatRoomApi.init(opts);
|
||||
|
||||
},
|
||||
|
||||
onDisconnect() {
|
||||
console.log('disconnect data');
|
||||
},
|
||||
|
||||
onChat(data) {
|
||||
console.log(this);
|
||||
console.log('onChat data', data);
|
||||
this.nodeScrollViewChatScript.createItem({
|
||||
data: {
|
||||
name: data.from,
|
||||
msg: data.msg
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onAdd(data) {
|
||||
console.log('onAdd data=', data);
|
||||
},
|
||||
|
||||
onLeave(data) {
|
||||
console.log('onLeave data=', data);
|
||||
},
|
||||
|
||||
onEventClicked_send() {
|
||||
let msg = this.editBoxInput.string || '';
|
||||
if (!msg) {
|
||||
return;
|
||||
}
|
||||
console.log('msg=', msg);
|
||||
chatRoomApi.sendMsg(msg).then(() => {
|
||||
this.editBoxInput.string = '';
|
||||
}).catch((err) => {
|
||||
console.log('err', err);
|
||||
});
|
||||
},
|
||||
|
||||
onDestroy() {
|
||||
this.chatRoomApi.destroy();
|
||||
}
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
PomeloClient/assets/Script/view/scene/ChatScene.js.meta
Normal file
9
PomeloClient/assets/Script/view/scene/ChatScene.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "a7c42b43-b7e9-49ef-9418-22a527429647",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
49
PomeloClient/assets/Script/view/scene/LoginScene.js
Normal file
49
PomeloClient/assets/Script/view/scene/LoginScene.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const loginApi = require('LoginApi');
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
editBoxID: cc.EditBox,
|
||||
editBoxRoom: cc.EditBox,
|
||||
},
|
||||
|
||||
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
onEventClicked_login() {
|
||||
console.log('onEventClicked_login');
|
||||
let id = this.editBoxID.string || Date.now();
|
||||
let room = this.editBoxRoom.string || 'room_1';
|
||||
//
|
||||
loginApi.queryEntry(id).then((data) => {
|
||||
return loginApi.loginEntry(data, {
|
||||
username: id,
|
||||
rid: room
|
||||
});
|
||||
}).then((data) => {
|
||||
myModel.chatInfoModel.setName(id);
|
||||
myModel.chatInfoModel.setRoomId(room);
|
||||
this.onLogin(data);
|
||||
}).catch((err) => {
|
||||
console.log('err=', err);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} data
|
||||
*/
|
||||
onLogin(data) {
|
||||
console.log('login data', data);
|
||||
myModel.chatUserModel.setUsers(data.users);
|
||||
cc.director.loadScene('Chat');
|
||||
}
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
PomeloClient/assets/Script/view/scene/LoginScene.js.meta
Normal file
9
PomeloClient/assets/Script/view/scene/LoginScene.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "403797af-36fa-4bac-8ef1-4ede1c05cd01",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
5
PomeloClient/assets/Script/view/utils.meta
Normal file
5
PomeloClient/assets/Script/view/utils.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "31cc75cb-0083-4372-90fd-3f5df0297410",
|
||||
"subMetas": {}
|
||||
}
|
||||
25
PomeloClient/assets/Script/view/utils/TimeUtil.js
Normal file
25
PomeloClient/assets/Script/view/utils/TimeUtil.js
Normal file
@@ -0,0 +1,25 @@
|
||||
function TimeUtil() {
|
||||
console.log('TimeUtil');
|
||||
}
|
||||
|
||||
//pads n with zeros on the left,
|
||||
//digits is minimum length of output
|
||||
//zeroPad(3, 5); returns "005"
|
||||
//zeroPad(2, 500); returns "500"
|
||||
function zeroPad(digits, n) {
|
||||
n = n.toString();
|
||||
while (n.length < digits)
|
||||
n = '0' + n;
|
||||
return n;
|
||||
};
|
||||
|
||||
//it is almost 8 o'clock PM here
|
||||
//timeString(new Date); returns "19:49"
|
||||
TimeUtil.prototype.timeString = function (date) {
|
||||
console.log('timeString');
|
||||
var minutes = date.getMinutes().toString();
|
||||
var hours = date.getHours().toString();
|
||||
return zeroPad(2, hours) + ":" + zeroPad(2, minutes);
|
||||
};
|
||||
|
||||
module.exports = new TimeUtil();
|
||||
9
PomeloClient/assets/Script/view/utils/TimeUtil.js.meta
Normal file
9
PomeloClient/assets/Script/view/utils/TimeUtil.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "04425e17-a421-408e-8891-81835fce9781",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user