RLG-Web: add a new message framework.
Add a message() function meant for UI messages, not debugging info.
This commit is contained in:
parent
06614ac0aa
commit
5af0160769
3 changed files with 37 additions and 3 deletions
|
|
@ -130,6 +130,8 @@
|
||||||
<div class="centerb"><a href="/about.html">Information</a></div>
|
<div class="centerb"><a href="/about.html">Information</a></div>
|
||||||
<div class="centerb"><span class="ibutton" onclick="toggleBlock('debug')">Messages</span></div>
|
<div class="centerb"><span class="ibutton" onclick="toggleBlock('debug')">Messages</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="modal" id="messages">
|
||||||
|
</div>
|
||||||
<div id="debug">
|
<div id="debug">
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
24
rlgterm.js
24
rlgterm.js
|
|
@ -261,7 +261,8 @@ function postResponseHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function errHandler() {
|
function errHandler() {
|
||||||
debug(1, "Server unavailable?");
|
//debug(1, "Server unavailable?");
|
||||||
|
message("Unable to connect to the server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendback(str) {
|
function sendback(str) {
|
||||||
|
|
@ -445,11 +446,13 @@ function formlogin(ev) {
|
||||||
session.lcred = reply.k;
|
session.lcred = reply.k;
|
||||||
session.lname = reply.u;
|
session.lname = reply.u;
|
||||||
setTitle("Logged in as " + reply.u);
|
setTitle("Logged in as " + reply.u);
|
||||||
debug(1, "Logged in as " + reply.u + " with id " + reply.k);
|
debug(0, "Logged in as " + reply.u + " with id " + reply.k);
|
||||||
|
message("You are now logged in as " + reply.u + ".");
|
||||||
setmode("choose");
|
setmode("choose");
|
||||||
}
|
}
|
||||||
else if (reply.t == 'E') {
|
else if (reply.t == 'E') {
|
||||||
debug(1, "Could not log in: " + reply.s);
|
debug(0, "Could not log in: " + reply.s);
|
||||||
|
message("Logging in failed: " + reply.s);
|
||||||
document.getElementById("input_name").value = "";
|
document.getElementById("input_name").value = "";
|
||||||
document.getElementById("input_pw").value = "";
|
document.getElementById("input_pw").value = "";
|
||||||
}
|
}
|
||||||
|
|
@ -622,11 +625,13 @@ function startgame(game) {
|
||||||
termemu.resize(reply.h, reply.w);
|
termemu.resize(reply.h, reply.w);
|
||||||
setTitle("Playing as " + session.lname);
|
setTitle("Playing as " + session.lname);
|
||||||
debug(1, "Playing with id " + session.id);
|
debug(1, "Playing with id " + session.id);
|
||||||
|
message("Your game has started.");
|
||||||
setmode("play");
|
setmode("play");
|
||||||
getData();
|
getData();
|
||||||
}
|
}
|
||||||
else if (reply.t == 'E') {
|
else if (reply.t == 'E') {
|
||||||
debug(1, "Could not start game: " + reply.s);
|
debug(1, "Could not start game: " + reply.s);
|
||||||
|
message("Your game could not be started: " + reply.s);
|
||||||
if (reply.c == 1) {
|
if (reply.c == 1) {
|
||||||
logout();
|
logout();
|
||||||
}
|
}
|
||||||
|
|
@ -656,11 +661,13 @@ function startwatching(gamenumber) {
|
||||||
termemu.toAltBuf();
|
termemu.toAltBuf();
|
||||||
setTitle("Watching");
|
setTitle("Watching");
|
||||||
debug(1, "Watching with id " + session.id);
|
debug(1, "Watching with id " + session.id);
|
||||||
|
message("You are now watching.");
|
||||||
setmode("play");
|
setmode("play");
|
||||||
getData();
|
getData();
|
||||||
}
|
}
|
||||||
else if (reply.t == 'E') {
|
else if (reply.t == 'E') {
|
||||||
debug(1, "Could not watch game " + gamenumber + ": " + reply.s);
|
debug(1, "Could not watch game " + gamenumber + ": " + reply.s);
|
||||||
|
message("The game could not be watched: " + reply.s);
|
||||||
getcurrent();
|
getcurrent();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -693,14 +700,17 @@ function formreg(ev) {
|
||||||
if (reply.t == 'r') {
|
if (reply.t == 'r') {
|
||||||
/* Success */
|
/* Success */
|
||||||
debug(1, "Registered account: " + reply.u);
|
debug(1, "Registered account: " + reply.u);
|
||||||
|
message("Welcome " + reply.u + ", you are now registered.");
|
||||||
session.lcred = reply.k;
|
session.lcred = reply.k;
|
||||||
session.lname = reply.u;
|
session.lname = reply.u;
|
||||||
setTitle("Logged in as " + session.lname);
|
setTitle("Logged in as " + session.lname);
|
||||||
debug(1, "Logged in as " + session.lname + " with id " + session.lcred);
|
debug(1, "Logged in as " + session.lname + " with id " + session.lcred);
|
||||||
|
message("You are now logged in as " + reply.u + ".");
|
||||||
setmode("choose");
|
setmode("choose");
|
||||||
}
|
}
|
||||||
else if (reply.t == 'E') {
|
else if (reply.t == 'E') {
|
||||||
debug(1, "Could not register: " + reply.s);
|
debug(1, "Could not register: " + reply.s);
|
||||||
|
message("Registration failed.");
|
||||||
document.getElementById("regin_name").value = "";
|
document.getElementById("regin_name").value = "";
|
||||||
document.getElementById("regin_pw").value = "";
|
document.getElementById("regin_pw").value = "";
|
||||||
document.getElementById("regin_email").value = "";
|
document.getElementById("regin_email").value = "";
|
||||||
|
|
@ -797,6 +807,14 @@ function toggleBlock(id) {
|
||||||
element.style.display = "none";
|
element.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function message(msg, type) {
|
||||||
|
var msgdiv = document.createElement("div");
|
||||||
|
var msgtext = document.createTextNode(msg);
|
||||||
|
msgdiv.appendChild(msgtext);
|
||||||
|
var msgcontainer = document.getElementById("messages");
|
||||||
|
msgcontainer.insertBefore(msgdiv, msgcontainer.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
function debug(level, msg) {
|
function debug(level, msg) {
|
||||||
if (level < debugSuppress)
|
if (level < debugSuppress)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,20 @@ div#keys {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div#messages {
|
||||||
|
width: 100%;
|
||||||
|
max-height: 10em;
|
||||||
|
overflow: scroll;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#messages div {
|
||||||
|
margin: 0.4em 0.8em;
|
||||||
|
padding: 0.4em 0.4em;
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
div#debug {
|
div#debug {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue