From c716d8b285e548f579c1f194934b075d0b473281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janis=20Sch=C3=B6ck?= Date: Tue, 26 Apr 2016 00:37:31 +0200 Subject: [PATCH] Ingame Chat - Basic --- index.html | 82 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 53330a8..4dcf0c4 100644 --- a/index.html +++ b/index.html @@ -99,6 +99,15 @@ .playername { font-weight: bold; } + .shoutmessage { + color: #000000; + } + .observermessage { + color: #866e40; + } + .playermessage { + color: #864040; + } .bold { font-weight: bold; } @@ -514,7 +523,7 @@
- +
@@ -896,7 +905,8 @@ }); } var camera, scene, renderer, light, canvas, controls = null; - + var chat_mode = "Shout"; + // antialiasing must be disabled per default, so slower devices are not impaired. var antialiasing_mode = false; @@ -2570,6 +2580,42 @@ $('#gameoveralert-text').html(msg); $('#gameoveralert').modal('show'); } + else if (spl[1] === "ObserverChat" || spl[1] === "PlayerChat") { + var msg = ""; + for (var i = 2; i < spl.length; ++i) + { + msg = msg + " " + spl[i]; + } + var name = msg.split('<')[1].split('>')[0]; + var txt = msg.split('<' + name + '>')[1]; + var clsname = 'chatname'; + var chatmode = (spl[1] === "ObserverChat" ? "observermessage" : "playermessage"); + + var $cs = $('#chat-server'); + + var now = new Date(); + var hours = now.getHours(); + var mins = now.getMinutes(); + var cls = 'chattime' + if (localStorage.getItem('hide-chat-time')==='true') { + cls = cls + ' hidden'; + } + $cs.append('[' + getZero(hours) + ':' + getZero(mins) + '] '); + $cs.append('' + name + ':'); + var options = {/* ... */}; + + txt = txt.linkify(options); + + //someone said our name + if(txt.indexOf(this.myname) > -1) { + var tmp = txt.split(this.myname); + txt = tmp[0] + ''+this.myname+'' + tmp[1]; + } + + $cs.append(txt+'
'); + + $cs.scrollTop($cs[0].scrollHeight); + } } } else if (e.startsWith("Login or Register")) { @@ -2670,7 +2716,7 @@ cls = cls + ' hidden'; } $cs.append('['+getZero(hours)+':'+getZero(mins)+'] '); - $cs.append(''+name+':'); + $cs.append(''+name+':'); var options = {/* ... */}; txt = txt.linkify(options); @@ -2734,11 +2780,22 @@ }, chat: function () { var msg = $('#chat-me').val(); - console.log('msg= '+msg); - if(msg.startsWith('.')) - this.send(msg.slice(1)); - else - this.send('Shout '+msg); + if (msg.startsWith('/a ') || msg.startsWith('/s ') + || msg.startsWith('/g ') || msg.startsWith('/i ')) { + msg = msg.substring(3); + } + switch (chat_mode) { + case "Shout": + console.log('msg= '+msg); + if(msg.startsWith('.')) + this.send(msg.slice(1)); + else + this.send('Shout '+msg); + break; + case "Ingame": + this.send('Game#' + board.gameno + " Chat " + msg); + break; + } $('#chat-me').val(''); }, send: function (e) { @@ -3022,6 +3079,15 @@ $('#chat-toggle-text').html('<<
c
h
a
t'); $('#chat').addClass('hidden'); } + function checkChatMode() { + var msg = $('#chat-me').val(); + if (msg.startsWith('/s ') || msg.startsWith('/a ')) { + chat_mode = "Shout"; + } + else if (msg.startsWith('/g ') || msg.startsWith('/i ')) { + chat_mode = "Ingame"; + } + } function isBreakpoint( alias ) { return $('.device-' + alias).is(':hidden'); }