Index: binaries/data/mods/public/gui/common/lobby_notifications.js =================================================================== --- binaries/data/mods/public/gui/common/lobby_notifications.js +++ binaries/data/mods/public/gui/common/lobby_notifications.js @@ -0,0 +1,48 @@ +/** + * Indicates if lobby dialog is opened. + */ +var g_LobbyDialogOpened = false; + +/** + * Function name for call when notification happens in lobby. + */ +var g_UpdateLobbyNotification = notify => {}; + +/** + * Notification sign used in menus. + */ +var g_NofiticationSign = "*"; + +/** + * Lobby net messages, that triggers a notification. + */ +var g_LobbyNetMessageTypeNotification = { + "system": { + "disconnected": msg => true + }, + "chat": { + "subject": msg => true, + "role": msg => true, + "room-message": msg => msg.text.toLowerCase().indexOf(Engine.LobbyGetNick().toLowerCase()) != -1, + "kicked": msg => msg.nick == Engine.LobbyGetNick(), + "banned": msg => msg.nick == Engine.LobbyGetNick(), + "private-message": msg => true + } +}; + +function handleNetLobbyMessagesInBackground() +{ + if (!g_LobbyDialogOpened) + { + let msg = Engine.LobbyGuiPollNewMessage(); // Only poll new messages no historic. + if (msg && g_LobbyNetMessageTypeNotification[msg.type] && + g_LobbyNetMessageTypeNotification[msg.type][msg.level] && + g_LobbyNetMessageTypeNotification[msg.type][msg.level](msg)) + g_UpdateLobbyNotification(true); + } +} + +function setLobbyDialogClosed() +{ + g_LobbyDialogOpened = false; +} 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 @@ -1008,8 +1008,12 @@ }, "lobbyButton": { "onPress": () => function() { - if (Engine.HasXmppClient()) - Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); + if (!Engine.HasXmppClient()) + return; + + setLobbyButtonIcon(false); + g_LobbyDialogOpened = true; + Engine.PushGuiPage("page_lobby.xml", { "dialog": true, "callback": "setLobbyDialogClosed" }); }, "hidden": () => !Engine.HasXmppClient() }, @@ -1087,6 +1091,10 @@ g_ServerPort = attribs.serverPort; g_StunEndpoint = attribs.stunEndpoint; + setLobbyButtonIcon(false); + if (Engine.HasXmppClient()) + g_UpdateLobbyNotification = setLobbyButtonIcon; + if (!g_IsNetworked) g_PlayerAssignments = { "local": { @@ -1105,6 +1113,19 @@ setTimeout(displayGamestateNotifications, 1000); } +function setLobbyButtonIcon(notify) +{ + Engine.GetGUIObjectByName("lobbyButton").sprite = notify ? "iconBubbleWhite" : "iconBubbleGold"; + + Engine.GetGUIObjectByName("lobbyButton").tooltip = + sprintf(translate("Show the multiplayer lobby in a dialog window. %(notification)s"), { + "notification": notify ? translate("(You have new lobby notifications.)") : "" + }); + + if (notify) + Engine.GetGUIObjectByName("onscreenToolTip").caption = translate("You have new lobby notifications. (Click the lobby icon button.)"); +} + function initDefaults() { // Remove gaia from both arrays @@ -1900,7 +1921,10 @@ ++g_LoadingState; } else if (g_LoadingState == 2) + { handleNetMessages(); + handleNetLobbyMessagesInBackground(); + } updateTimers(); 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 @@ -198,7 +198,6 @@