Index: binaries/data/config/default.cfg =================================================================== --- binaries/data/config/default.cfg +++ binaries/data/config/default.cfg @@ -176,6 +176,7 @@ chat = Return ; Toggle chat window teamchat = "T" ; Toggle chat window in team chat mode privatechat = "L" ; Toggle chat window and select the previous private chat partner +lobby = "Alt+L" ; Show the multiplayer lobby in a dialog window. ; > QUICKSAVE quicksave = "Shift+F5" Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -1110,6 +1110,8 @@ updateGameAttributes(); sendRegisterGameStanzaImmediate(); + Engine.GetGUIObjectByName("lobbyButton").hidden = !Engine.HasXmppClient(); + if (g_IsTutorial) { launchTutorial(); Index: binaries/data/mods/public/gui/gamesetup/gamesetup.xml =================================================================== --- binaries/data/mods/public/gui/gamesetup/gamesetup.xml +++ binaries/data/mods/public/gui/gamesetup/gamesetup.xml @@ -247,6 +247,21 @@ + + + Show the multiplayer lobby in a dialog window. + + if (Engine.HasXmppClient()) + Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); + + + + + + + + + + Index: binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- binaries/data/mods/public/gui/lobby/lobby.js +++ binaries/data/mods/public/gui/lobby/lobby.js @@ -88,7 +88,7 @@ /** * All games currently running. */ -var g_GameList = {}; +var g_GameList = []; /** * Used to restore the selection after updating the playerlist. @@ -111,6 +111,11 @@ var g_Kicked = false; /** + * Whether already asked, if want to reconnect to the lobby. + */ +var g_AskedReconnect = false; + +/** * Processing of notifications sent by XmppClient.cpp. * * @returns true if the playerlist GUI must be updated. @@ -119,24 +124,30 @@ "system": { // Three cases are handled in prelobby.js "registered": msg => false, - "connected": msg => false, + "connected": msg => { + + g_AskedReconnect = false; + setGUIConnectionState(true); + + return false; + }, "disconnected": msg => { updateGameList(); updateLeaderboard(); - Engine.GetGUIObjectByName("chatInput").hidden = true; - - for (let button of ["host", "leaderboard", "userprofile", "toggleBuddy"]) - Engine.GetGUIObjectByName(button + "Button").enabled = false; - Engine.GetGUIObjectByName("chatInput").hidden = true; + setGUIConnectionState(false); if (!g_Kicked) + { addChatMessage({ "from": "system", "time": msg.time, "text": translate("Disconnected.") + " " + msg.reason }); + reconnectMessageBox(); + } + return true; }, "error": msg => { @@ -363,12 +374,18 @@ "quit": { "description": translate("Return to the main menu."), "handler": args => { - returnToMainMenu(); + leaveLobby(); return false; } } }; +/* + * Indicates, if the lobby is opened in the dialog. + */ +var g_Dialog = false; + + /** * Called after the XmppConnection succeeded and when returning from a game. * @@ -376,9 +393,17 @@ */ function init(attribs) { + g_Dialog = attribs && attribs.dialog; + + g_CallbackSet = g_Dialog && attribs && attribs.callback; + + Engine.LobbySetPlayerPresence("available"); + + initGUIObjects(); + if (!g_Settings) { - returnToMainMenu(); + leaveLobby(); return; } @@ -387,8 +412,6 @@ initGameFilters(); - Engine.LobbySetPlayerPresence("available"); - // When rejoining the lobby after a game, we don't need to process presence changes Engine.LobbyClearPresenceUpdates(); updatePlayerList(); @@ -401,6 +424,59 @@ // Get all messages since the login for (let msg of Engine.LobbyGuiPollHistoricMessages()) g_NetMessageTypes[msg.type][msg.level](msg); + + if (!Engine.IsXmppClientConnected()) + { + reconnectMessageBox(); + setGUIConnectionState(false); + } +} + +function reconnectMessageBox() +{ + if (g_AskedReconnect) + return; + + g_AskedReconnect = true; + messageBox( + 400, 200, + translate("You have been disconnect from the Lobby. Reconnect to it?"), + translate("Confirmation"), + [translate("No"), translate("Yes")], + [null, Engine.ConnectXmppClient ] + ); +} + +/** + * Set style of GUI elements and the window style. + */ +function initGUIObjects() +{ + let lobbyWindow = Engine.GetGUIObjectByName("lobbyWindow"); + lobbyWindow.sprite = g_Dialog ? "ModernDialog" : "ModernWindow"; + lobbyWindow.size = g_Dialog ? "42 42 100%-42 100%-42" : "0 0 100% 100%"; + Engine.GetGUIObjectByName("lobbyWindowTitle").size = g_Dialog ? "50%-128 -16 50%+128 16" : "50%-128 4 50%+128 36"; + + Engine.GetGUIObjectByName("leaveButton").caption = g_Dialog ? translate("Back") : translate("Main Menu"); + Engine.GetGUIObjectByName("lobbyDialogToggle").onPress = g_Dialog ? leaveLobby : () => false; + Engine.GetGUIObjectByName("cancelDialog").onPress = g_Dialog ? leaveLobby : () => false; + Engine.GetGUIObjectByName("hostButton").hidden = g_Dialog; + Engine.GetGUIObjectByName("joinGameButton").hidden = g_Dialog; + Engine.GetGUIObjectByName("gameInfoEmpty").size = "0 0 100% 100%" + (g_Dialog ? "-30" : "-60"); + Engine.GetGUIObjectByName("gameInfo").size = "0 0 100% 100%" + (g_Dialog ? "-30" : "-90"); + + Engine.GetGUIObjectByName("fadeImage").hidden = !g_Dialog; +} + +/** + * Set style of GUI elements when lobby is connected. + */ +function setGUIConnectionState(connected) +{ + Engine.GetGUIObjectByName("chatInput").hidden = !connected; + + for (let button of ["host", "leaderboard", "userprofile", "toggleBuddy"]) + Engine.GetGUIObjectByName(button + "Button").enabled = connected; } function updateLobbyColumns() @@ -426,10 +502,19 @@ playersNumberFilter.size = size; } -function returnToMainMenu() +function leaveLobby() { - Engine.StopXmppClient(); - Engine.SwitchGuiPage("page_pregame.xml"); + if (g_Dialog) + { + Engine.LobbySetPlayerPresence("playing"); + closePage(); + } + else + { + if (Engine.HasXmppClient()) + Engine.StopXmppClient(); + Engine.SwitchGuiPage("page_pregame.xml"); + } } function initGameFilters() @@ -1015,7 +1100,7 @@ let game = selectedGame(); Engine.GetGUIObjectByName("gameInfo").hidden = !game; - Engine.GetGUIObjectByName("joinGameButton").hidden = !game; + Engine.GetGUIObjectByName("joinGameButton").hidden = g_Dialog || !game; Engine.GetGUIObjectByName("gameInfoEmpty").hidden = game; if (!game) @@ -1073,7 +1158,7 @@ function joinButton() { let game = selectedGame(); - if (!game) + if (!game || g_Dialog) return; let rating = getRejoinRating(game); Index: binaries/data/mods/public/gui/lobby/lobby.xml =================================================================== --- binaries/data/mods/public/gui/lobby/lobby.xml +++ binaries/data/mods/public/gui/lobby/lobby.xml @@ -4,10 +4,13 @@