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,12 @@ /** * All games currently running. */ -var g_GameList = {}; +var g_GameList = { "uninitialized": true }; + +/** + * Filtered and sorted list of currently running games. + */ +var g_GameListPrevious = []; /** * Used to restore the selection after updating the playerlist. @@ -273,6 +278,8 @@ }, "game": { "gamelist": msg => { + if (g_GameList.uninitialized) + g_GameList = { "initial": true }; updateGameList(); return false; }, @@ -894,6 +901,9 @@ */ function updateGameList() { + if (g_GameList.uninitialized) + return; + let gamesBox = Engine.GetGUIObjectByName("gamesBox"); let sortBy = gamesBox.selected_column; let sortOrder = gamesBox.selected_column_order; @@ -904,13 +914,25 @@ g_SelectedGamePort = g_GameList[gamesBox.selected].port; } - g_GameList = Engine.GetGameList().map(game => { + let previousGameIndex = 0; + g_GameListPrevious = Engine.GetGameList().map(game => { + let previousGame = g_GameListPrevious[previousGameIndex] && g_GameListPrevious[previousGameIndex].name == game.name ? + g_GameListPrevious[previousGameIndex++] : g_GameListPrevious.find( + (previousGame, foundPreviousGameIndex) => previousGame.name == game.name && (previousGameIndex = ++foundPreviousGameIndex) + ); + + game.joinedBuddies = previousGame ? previousGame.joinedBuddies : []; game.hasBuddies = 0; // Compute average rating of participating players let playerRatings = []; + let buddyJoined = nick => g_Buddies.indexOf(nick) != -1 && game.joinedBuddies.indexOf(nick) == -1 && game.joinedBuddies.push(nick); + + if (game.state == "init" && buddyJoined(game.hostUsername) && !g_GameList.initial) + addInfoBuddyJoinedGame(translate("%(buddy)s has opened new game %(game)s."), game, game.hostUsername); + for (let player of stringifiedTeamListToPlayerData(game.players)) { let [nick, rating] = splitRatingFromNick(player.Name); @@ -921,6 +943,9 @@ // Sort games with playing buddies above games with spectating buddies if (game.hasBuddies < 2 && g_Buddies.indexOf(nick) != -1) game.hasBuddies = player.Team == "observer" ? 1 : 2; + + if (buddyJoined(playerNickRating.nick) && !g_GameList.initial) + addInfoBuddyJoinedGame(translate("%(buddy)s has joined game %(game)s."), game, playerNickRating.nick); } game.gameRating = @@ -929,7 +954,9 @@ g_DefaultLobbyRating; return game; - }).filter(game => !filterGame(game)).sort((a, b) => { + }); + + g_GameList = g_GameListPrevious.filter(game => !filterGame(game)).sort((a, b) => { let sortA, sortB; switch (sortBy) { @@ -1287,6 +1314,15 @@ Engine.GetGUIObjectByName("chatText").caption = g_ChatMessages.join("\n"); } +function addInfoBuddyJoinedGame(text, game, nickName) +{ + addChatMessage({ "info": true, "text": sprintf(text, { + "buddy": coloredText(g_BuddySymbol + " " + nickName, getPlayerColor(nickName)), + "game": coloredText(g_BuddySymbol + " " + game.name, g_GameColors[game.state]) + }) + }); +} + /** * Splits given input into command and argument. */ @@ -1371,6 +1407,10 @@ return ""; } } + else if (msg.info) + formattedMessage = sprintf(translate("%(info)s"), { + "info": senderFont('* ') + msg.text + }); else { let senderString;