Lobby cleanup. Fixes #3383

This was SVN commit r17371.
This commit is contained in:
elexis 2015-12-04 00:22:15 +00:00
parent 76a1a84a58
commit d50075adc4
2 changed files with 42 additions and 48 deletions

View File

@ -431,9 +431,8 @@ function updateLeaderboard()
function updateGameList() function updateGameList()
{ {
var gamesBox = Engine.GetGUIObjectByName("gamesBox"); var gamesBox = Engine.GetGUIObjectByName("gamesBox");
var gameList = Engine.GetGameList();
g_GameList = gameList.sort((a, b) => { g_GameList = Engine.GetGameList().filter(game => !filterGame(game)).sort((a, b) => {
switch (g_GameListSortBy) switch (g_GameListSortBy)
{ {
case 'name': case 'name':
@ -466,13 +465,11 @@ function updateGameList()
var list = []; var list = [];
var list_data = []; var list_data = [];
for (let i in gameList) for (let i in g_GameList)
{ {
let game = gameList[i]; let game = g_GameList[i];
if (filterGame(game))
continue;
let gameName = escapeText(game.name); let gameName = escapeText(game.name);
list_name.push('[color="' + g_GameColors[game.state] + '"]' + gameName); list_name.push('[color="' + g_GameColors[game.state] + '"]' + gameName);
list_ip.push(game.ip); list_ip.push(game.ip);
list_mapName.push(translate(game.niceMapName)); list_mapName.push(translate(game.niceMapName));
@ -513,27 +510,21 @@ function updateGameSelection()
return; return;
} }
var g = Engine.GetGUIObjectByName("gamesBox").list_data[selected];
// Show the game info panel and join button. // Show the game info panel and join button.
Engine.GetGUIObjectByName("gameInfo").hidden = false; Engine.GetGUIObjectByName("gameInfo").hidden = false;
Engine.GetGUIObjectByName("joinGameButton").hidden = false; Engine.GetGUIObjectByName("joinGameButton").hidden = false;
Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true; Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true;
// Display the map name, number of players, the names of the players, the map size and the map type. // Display the map name, number of players, the names of the players, the map size and the map type.
Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName); var game = g_GameList[selected];
Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp; Engine.GetGUIObjectByName("sgMapName").caption = translate(game.niceMapName);
Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players; Engine.GetGUIObjectByName("sgNbPlayers").caption = game.nbp + "/" + game.tnbp;
Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(g_GameList[g].mapSize); Engine.GetGUIObjectByName("sgPlayersNames").caption = game.players;
let mapTypeIdx = g_MapTypes.Name.indexOf(g_GameList[g].mapType); Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(game.mapSize);
let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType);
Engine.GetGUIObjectByName("sgMapType").caption = mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : ""; Engine.GetGUIObjectByName("sgMapType").caption = mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : "";
if (mapData && mapData.settings.Preview) var mapData = getMapDescriptionAndPreview(game.mapType, game.mapName);
var mapPreview = mapData.settings.Preview;
else
var mapPreview = "nopreview.png";
var mapData = getMapDescriptionAndPreview(g_GameList[g].mapType, g_GameList[g].mapName);
Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description; Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description;
Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview; Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview;
} }
@ -566,7 +557,7 @@ function hostGame()
} }
/** /**
* Processes one GUI message sent by the XmppClient. * Processes GUI messages sent by the XmppClient.
*/ */
function onTick() function onTick()
{ {
@ -652,6 +643,9 @@ function onTick()
} }
} }
/**
* Executes a lobby command or sends GUI input directly as chat.
*/
function submitChatInput() function submitChatInput()
{ {
var input = Engine.GetGUIObjectByName("chatInput"); var input = Engine.GetGUIObjectByName("chatInput");

View File

@ -3,7 +3,7 @@ var g_EncrytedPassword = "";
var g_PasswordInputIsHidden = false; var g_PasswordInputIsHidden = false;
var g_TermsOfServiceRead = false; var g_TermsOfServiceRead = false;
var g_TermsOfUseRead = false; var g_TermsOfUseRead = false;
var g_hasSystemMessage = false; var g_HasSystemMessage = false;
function init() function init()
{ {
@ -113,7 +113,7 @@ function onTick()
// Allow them to connect if tests pass up to this point. // Allow them to connect if tests pass up to this point.
else if (pageRegisterHidden) else if (pageRegisterHidden)
{ {
if (!g_hasSystemMessage) if (!g_HasSystemMessage)
feedback.caption = ""; feedback.caption = "";
continueButton.enabled = true; continueButton.enabled = true;
} }
@ -150,7 +150,7 @@ function onTick()
// Allow them to register. // Allow them to register.
else else
{ {
if (!g_hasSystemMessage) if (!g_HasSystemMessage)
feedback.caption = ""; feedback.caption = "";
continueButton.enabled = true; continueButton.enabled = true;
} }
@ -199,7 +199,7 @@ function onTick()
} }
else if(message.type == "system" && (message.level == "error" || message.text == "disconnected")) else if(message.type == "system" && (message.level == "error" || message.text == "disconnected"))
{ {
g_hasSystemMessage = true; g_HasSystemMessage = true;
feedback.caption = message.text == "disconnected" ? translate("Disconnected") : message.text; feedback.caption = message.text == "disconnected" ? translate("Disconnected") : message.text;
Engine.StopXmppClient(); Engine.StopXmppClient();
g_LobbyIsConnecting = false; g_LobbyIsConnecting = false;
@ -232,40 +232,40 @@ function switchPage(page)
// Then show appropriate page. // Then show appropriate page.
switch(page) switch(page)
{ {
case "welcome": case "welcome":
Engine.GetGUIObjectByName("pageWelcome").hidden = false; Engine.GetGUIObjectByName("pageWelcome").hidden = false;
break; break;
case "register": case "register":
var dialog = Engine.GetGUIObjectByName("dialog"); var dialog = Engine.GetGUIObjectByName("dialog");
var newSize = dialog.size; var newSize = dialog.size;
newSize.bottom += 150; newSize.bottom += 150;
dialog.size = newSize; dialog.size = newSize;
Engine.GetGUIObjectByName("pageRegister").hidden = false; Engine.GetGUIObjectByName("pageRegister").hidden = false;
Engine.GetGUIObjectByName("continue").caption = translate("Register"); Engine.GetGUIObjectByName("continue").caption = translate("Register");
Engine.GetGUIObjectByName("continue").hidden = false; Engine.GetGUIObjectByName("continue").hidden = false;
break; break;
case "connect": case "connect":
Engine.GetGUIObjectByName("pageConnect").hidden = false; Engine.GetGUIObjectByName("pageConnect").hidden = false;
Engine.GetGUIObjectByName("continue").caption = translate("Connect"); Engine.GetGUIObjectByName("continue").caption = translate("Connect");
Engine.GetGUIObjectByName("continue").hidden = false; Engine.GetGUIObjectByName("continue").hidden = false;
break; break;
} }
} }
function openTermsOfService() function openTermsOfService()
{ {
g_TermsOfServiceRead = true; g_TermsOfServiceRead = true;
Engine.PushGuiPage("page_manual.xml", { Engine.PushGuiPage("page_manual.xml", {
"page":"lobby/Terms_of_Service", "page": "lobby/Terms_of_Service",
"title":translate("Terms of Service"), "title": translate("Terms of Service"),
}); });
} }
function openTermsOfUse() function openTermsOfUse()
{ {
g_TermsOfUseRead = true; g_TermsOfUseRead = true;
Engine.PushGuiPage("page_manual.xml", { Engine.PushGuiPage("page_manual.xml", {
"page":"lobby/Terms_of_Use", "page": "lobby/Terms_of_Use",
"title":translate("Terms of Use"), "title": translate("Terms of Use"),
}); });
} }