Added prompt functionality to webclient using the msg 'prompt' keyword functionality
This commit is contained in:
parent
6ebde92448
commit
40e9a149d6
4 changed files with 26 additions and 4 deletions
|
|
@ -122,6 +122,8 @@ class WebSocketClient(Protocol, Session):
|
||||||
oobstruct = self.sessionhandler.oobstruct_parser(kwargs.pop("oob"))
|
oobstruct = self.sessionhandler.oobstruct_parser(kwargs.pop("oob"))
|
||||||
#print "oob data_out:", "OOB" + json.dumps(oobstruct)
|
#print "oob data_out:", "OOB" + json.dumps(oobstruct)
|
||||||
self.sendLine("OOB" + json.dumps(oobstruct))
|
self.sendLine("OOB" + json.dumps(oobstruct))
|
||||||
|
if "prompt" in kwargs:
|
||||||
|
self.sendLine("PROMPT" + kwargs["prompt"])
|
||||||
raw = kwargs.get("raw", False)
|
raw = kwargs.get("raw", False)
|
||||||
nomarkup = kwargs.get("nomarkup", False)
|
nomarkup = kwargs.get("nomarkup", False)
|
||||||
if raw:
|
if raw:
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@ div {margin:0px;}
|
||||||
/* Error messages (red) */
|
/* Error messages (red) */
|
||||||
.err { color: #f00 }
|
.err { color: #f00 }
|
||||||
|
|
||||||
|
/* Prompt base (white) */
|
||||||
|
.prompt {color: #fff }
|
||||||
|
|
||||||
/* Style specific classes corresponding to formatted, narative text. */
|
/* Style specific classes corresponding to formatted, narative text. */
|
||||||
.red { color: red; }
|
.red { color: red; }
|
||||||
.maroon { color: maroon; }
|
.maroon { color: maroon; }
|
||||||
|
|
@ -107,7 +110,6 @@ div {margin:0px;}
|
||||||
float: left;
|
float: left;
|
||||||
width: 87%;}
|
width: 87%;}
|
||||||
|
|
||||||
|
|
||||||
#inputfield:focus {
|
#inputfield:focus {
|
||||||
outline: 0 }
|
outline: 0 }
|
||||||
|
|
||||||
|
|
@ -126,6 +128,10 @@ div {margin:0px;}
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
font-family: 'DejaVu Sans Mono', Consolas, Inconsolata, 'Lucida Console', monospace }
|
font-family: 'DejaVu Sans Mono', Consolas, Inconsolata, 'Lucida Console', monospace }
|
||||||
|
|
||||||
|
/* prompt area above input field */
|
||||||
|
#prompt {
|
||||||
|
margin-top: .8em;}
|
||||||
|
|
||||||
/* No javascript warning */
|
/* No javascript warning */
|
||||||
#connecting {
|
#connecting {
|
||||||
padding: .5em .9em }
|
padding: .5em .9em }
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ function onOpen(evt) {
|
||||||
doShow("sys", "Using websockets - connected to " + wsurl + ".")
|
doShow("sys", "Using websockets - connected to " + wsurl + ".")
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$("#playercount").fadeOut('slow', doSetSizes);
|
$("#numplayers").fadeOut('slow', doSetSizes);
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,6 +106,11 @@ function onMessage(evt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (inmsg.length >= 6 && inmsg.substr(0, 6) == "PROMPT") {
|
||||||
|
// handle prompt
|
||||||
|
var game_prompt = inmsg.slice(6);
|
||||||
|
doPrompt("prompt", game_prompt);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// normal message
|
// normal message
|
||||||
doShow('out', inmsg); }
|
doShow('out', inmsg); }
|
||||||
|
|
@ -172,6 +177,11 @@ function doShow(type, msg){
|
||||||
$('#messagewindow').animate({scrollTop: $('#messagewindow')[0].scrollHeight});
|
$('#messagewindow').animate({scrollTop: $('#messagewindow')[0].scrollHeight});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doPrompt(type, msg){
|
||||||
|
// Display prompt
|
||||||
|
$('#prompt').replaceWith(
|
||||||
|
"<div id='prompt' class='msg "+ type +"'>" + msg + "</div>");
|
||||||
|
}
|
||||||
|
|
||||||
function doSetSizes() {
|
function doSetSizes() {
|
||||||
// Sets the size of the message window
|
// Sets the size of the message window
|
||||||
|
|
@ -179,7 +189,6 @@ function doSetSizes() {
|
||||||
//var win_w = $('#wrapper').width();
|
//var win_w = $('#wrapper').width();
|
||||||
var inp_h = $('#inputform').outerHeight(true);
|
var inp_h = $('#inputform').outerHeight(true);
|
||||||
//var inp_w = $('#inputsend').outerWidth(true);
|
//var inp_w = $('#inputsend').outerWidth(true);
|
||||||
|
|
||||||
$("#messagewindow").css({'height': win_h - inp_h - 1});
|
$("#messagewindow").css({'height': win_h - inp_h - 1});
|
||||||
//$("#inputfield").css({'width': win_w - inp_w - 20});
|
//$("#inputfield").css({'width': win_w - inp_w - 20});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@
|
||||||
<!--for offline testing, download the jquery library from jquery.com-->
|
<!--for offline testing, download the jquery library from jquery.com-->
|
||||||
<!--script src="/media/javascript/jquery-1.11.1.js" type="text/javascript" charset="utf-8"></script-->
|
<!--script src="/media/javascript/jquery-1.11.1.js" type="text/javascript" charset="utf-8"></script-->
|
||||||
|
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
if(!window.jQuery){document.write("<div class='err'>jQuery library not found or the online version could not be reached.</div>");}
|
||||||
|
</script>
|
||||||
|
|
||||||
{% if websocket_enabled %}
|
{% if websocket_enabled %}
|
||||||
<script language="javascript" type="text/javascript">
|
<script language="javascript" type="text/javascript">
|
||||||
if ("WebSocket" in window) {
|
if ("WebSocket" in window) {
|
||||||
|
|
@ -51,7 +55,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form id="inputform" action="javascript:void(0);">
|
<form id="inputform" action="javascript:void(0);">
|
||||||
<div id="playercount">Logged in Players: {{num_players_connected}}</div>
|
<div id="prompt"></div>
|
||||||
|
<div id="numplayers">Logged in Players: {{num_players_connected}}</div>
|
||||||
<div id="inputcontrol"><input type="text" id="inputfield" autocomplete="off"><input id="inputsend" type="button" value="send" onClick="doSend()"/></div>
|
<div id="inputcontrol"><input type="text" id="inputfield" autocomplete="off"><input id="inputsend" type="button" value="send" onClick="doSend()"/></div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue