Permalink
Browse files

Added more talkbox

  • Loading branch information...
1 parent f8613c3 commit c5fbad5489e14fb92d163bb75dcf8b12fb11f86e @robrighter committed Jan 7, 2012
Showing with 55 additions and 2 deletions.
  1. +13 −0 server.js
  2. +16 −0 static/css/style.css
  3. +24 −2 static/js/script.js
  4. +2 −0 views/index.jade
View
@@ -58,6 +58,19 @@ io.sockets.on('connection', function(socket){
socket.emit('server_move_character',movedata);
}
});
+
+ socket.on('talk_character', function(data){
+ if(keylookups.hasOwnProperty(data.requestkey)){
+ //TODO: ADD STRIP TABS
+ var message = {
+ character: keylookups[data.requestkey],
+ message: data.message,
+ }
+ socket.broadcast.emit('server_talk_character',message);
+ socket.emit('server_talk_character',message);
+ }
+ });
+
socket.on('disconnect', function(){
console.log('Client Disconnected.');
});
View
@@ -319,6 +319,22 @@ body {
color: #444;
}
+#talks {
+ position: absolute;
+}
+
+#talks .talkbubble {
+ background-color: #bbbbbb;
+ opacity: 0.9;
+ font-size: 10px;
+ width: 300px;
+ padding: 7px;
+ border: 1px solid #aaaaaa;
+ border-radius: 3px;
+ padding-left: 35px;
+ min-height: 45px;
+}
+
View
@@ -46,6 +46,7 @@ $(document).ready(function() {
sps[handle].offset(0,0);
sps[handle].move(chardict.location.x,chardict.location.y);
sps[handle].update();
+ sps[handle].talkHistory = [];
}
function setupSocket(){
@@ -58,6 +59,11 @@ $(document).ready(function() {
}
});
+ socket.on('server_talk_character', function(data){
+ spriteSpeak(data.character, data.message);
+
+ });
+
socket.on('server_add_character', function(data){
addCharacter(data.handle, data.details);
});
@@ -143,8 +149,24 @@ $(document).ready(function() {
}
function sendMessage(texttosend){
- console.log('Need to send this:');
- console.log(texttosend);
+ socket.emit('talk_character', {requestkey: requestkey, message: texttosend });
}
+
+ function spriteSpeak(sprite, message){
+ sps[sprite].talkHistory.push(message);
+ var formattedmessages = sps[sprite].talkHistory.join('<br>');
+ if($('#talk'+sprite).length === 0 ){
+ var html = "<div class='talkbubble' id='talk"+sprite+"'><div class='message'>"+formattedmessages+"</div></div>";
+ $('#talks').append(html);
+ }
+ else{
+ $('#talk'+sprite+' .message').html(formattedmessages);
+ }
+
+ $('#talk'+sprite).setStyle('left', '400px');
+ $('#talk'+sprite).setStyle('top', '400px');
+ console.log('CHARACTER: ' + sprite + " says: " + message);
+ }
+
});
View
@@ -1,3 +1,5 @@
+#talks
+
#controlbox
.instructions
span='Sign in with twitter to talk to the '

0 comments on commit c5fbad5

Please sign in to comment.