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 @@ -44,7 +44,7 @@ "available": { "color": "0 219 0", "status": translate("Online") }, "away": { "color": "229 76 13", "status": translate("Away") }, "playing": { "color": "200 0 0", "status": translate("Busy") }, - "offline": { "color": "0 0 0", "status": translate("Offline") }, + "offline": { "color": "66 66 66", "status": translate("Offline") }, "unknown": { "color": "178 178 178", "status": translateWithContext("lobby presence", "Unknown") } }; @@ -111,6 +111,14 @@ var g_Kicked = false; /** + * Search players and accounts. + */ +var g_Search = { + "player": "", + "found": undefined +}; + +/** * Processing of notifications sent by XmppClient.cpp. * * @returns true if the playerlist GUI must be updated. @@ -127,7 +135,7 @@ Engine.GetGUIObjectByName("chatInput").hidden = true; - for (let button of ["host", "leaderboard", "userprofile", "toggleBuddy"]) + for (let button of ["host", "leaderboard", "toggleBuddy"]) Engine.GetGUIObjectByName(button + "Button").enabled = false; Engine.GetGUIObjectByName("chatInput").hidden = true; @@ -597,6 +605,17 @@ } /** + * Filter player names based on search name + * @returns {boolean} false if name not matchs, true vice versa + */ +function filterPlayer(name) +{ + if (g_Search.player && name.toLowerCase().search(g_Search.player.toLowerCase()) != 0) + return true; + return false; +} + +/** * Do a full update of the player listing, including ratings from cached C++ information. */ function updatePlayerList() @@ -610,8 +629,12 @@ let presenceList = []; let nickList = []; let ratingList = []; + let addFoundPlayer = g_Search.found ? true : false; - let cleanPlayerList = Engine.GetPlayerList().map(player => { + let cleanPlayerList = Engine.GetPlayerList().filter(player => { + addFoundPlayer = !addFoundPlayer ? false : player.name != g_Search.found.name; + return !filterPlayer(player.name) + }).concat(addFoundPlayer ? g_Search.found : []).map(player => { player.isBuddy = g_Buddies.indexOf(player.name) != -1; return player; }).sort((a, b) => { @@ -668,6 +691,23 @@ nickList.push(player.name); } + function addPlayerListState(entry, name) + { + for (let list of [buddyStatusList, presenceList, ratingList]) + list.push(""); + playerList.push(entry); + nickList.push(name); + } + + if (g_Search.player && g_Search.found == undefined) + addPlayerListState('[color="128 128 128"]- ' + translate("searching") + ' -[/color]', 'search'); + + if (g_Search.player && g_Search.found == "" && cleanPlayerList.length == 0) + addPlayerListState('[color="128 128 128"]- ' + translate("not found") + ' -[/color]', 'not_found'); + + if (cleanPlayerList.length != Engine.GetPlayerList().length) + addPlayerListState('[color="0 128 128"]- ' + translate('filtered') + ' -[/color]', 'filtered'); + playersBox.list_buddy = buddyStatusList; playersBox.list_name = playerList; playersBox.list_status = presenceList; @@ -742,7 +782,9 @@ function onPlayerListSelection() { let playerList = Engine.GetGUIObjectByName("playersBox"); - if (playerList.selected == playerList.list.indexOf(g_SelectedPlayer)) + if (playerList.selected == playerList.list.indexOf(g_SelectedPlayer) || + playerList.list[playerList.selected] == 'not_found' || + playerList.list[playerList.selected] == 'filtered') return; g_SelectedPlayer = playerList.list[playerList.selected]; @@ -761,12 +803,6 @@ Engine.GetGUIObjectByName("fade").hidden = !visible; } -function setUserProfileVisibility(visible) -{ - Engine.GetGUIObjectByName("profileFetch").hidden = !visible; - Engine.GetGUIObjectByName("fade").hidden = !visible; -} - /** * Display the profile of the player in the user profile window. */ @@ -816,36 +852,21 @@ let user = colorPlayerName(attributes.player, attributes.rating); - if (!Engine.GetGUIObjectByName("profileFetch").hidden) - { - let profileFound = attributes.rating != "-2"; - Engine.GetGUIObjectByName("profileWindowArea").hidden = !profileFound; - Engine.GetGUIObjectByName("profileErrorText").hidden = profileFound; - - if (!profileFound) - { - Engine.GetGUIObjectByName("profileErrorText").caption = sprintf( - translate("Player \"%(nick)s\" not found."), - { "nick": attributes.player } - ); - return; - } + if (g_Search.player && attributes.rating != "-2") + g_Search.found = {"name": attributes.player, "rating": attributes.rating, "presence": "offline", "role": "participant"} + else + g_Search.found = ""; - Engine.GetGUIObjectByName("profileUsernameText").caption = user; - Engine.GetGUIObjectByName("profileRankText").caption = attributes.rank; - Engine.GetGUIObjectByName("profileHighestRatingText").caption = attributes.highestRating; - Engine.GetGUIObjectByName("profileTotalGamesText").caption = attributes.totalGamesPlayed; - Engine.GetGUIObjectByName("profileWinsText").caption = attributes.wins; - Engine.GetGUIObjectByName("profileLossesText").caption = attributes.losses; - Engine.GetGUIObjectByName("profileRatioText").caption = formatWinRate(attributes); - return; - } + updatePlayerList(); + let playersBox = Engine.GetGUIObjectByName("playersBox") + if (g_Search.found) + playersBox.selected = playersBox.list.length-2; let playerList; if (!Engine.GetGUIObjectByName("leaderboard").hidden) playerList = Engine.GetGUIObjectByName("leaderboardBox"); else - playerList = Engine.GetGUIObjectByName("playersBox"); + playerList = playersBox; if (attributes.rating == "-2") return; @@ -902,7 +923,7 @@ let sortBy = gamesBox.selected_column; let sortOrder = gamesBox.selected_column_order; - if (gamesBox.selected > -1) + if (gamesBox.selected > -1 && gamesBox.selected < g_GameList.length) { g_SelectedGameIP = g_GameList[gamesBox.selected].ip; g_SelectedGamePort = g_GameList[gamesBox.selected].port; @@ -996,6 +1017,15 @@ list_data.push(i); } + if (Engine.GetGameList().length != g_GameList.length) + { + for (let list of [list_buddy, list_mapName, list_mapSize, list_mapType, list_nPlayers, list_gameRating]) + list.push(""); + list_name.push('[color="0 128 128"]- ' + translate('filtered') + ' -[/color]'); + list_data.push(g_GameList.length); + list.push('filtered'); + } + gamesBox.list_buddy = list_buddy; gamesBox.list_name = list_name; gamesBox.list_mapName = list_mapName; @@ -1066,7 +1096,8 @@ function selectedGame() { let gamesBox = Engine.GetGUIObjectByName("gamesBox"); - if (gamesBox.selected < 0) + if (gamesBox.selected < 0 || + gamesBox.list[gamesBox.selected] == 'filtered') return undefined; return g_GameList[gamesBox.list_data[gamesBox.selected]]; Index: binaries/data/mods/public/gui/lobby/lobby_panels.xml =================================================================== --- binaries/data/mods/public/gui/lobby/lobby_panels.xml +++ binaries/data/mods/public/gui/lobby/lobby_panels.xml @@ -75,21 +75,27 @@ - + + Search player - toggleBuddy(); + g_Search.found = undefined; + g_Search.player = this.caption; + Engine.SendGetProfile(this.caption); + updatePlayerList(); + + + autoCompleteNick(this, Engine.GetPlayerList().map(player => player.name)); - - Leaderboard + - setLeaderboardVisibility(true); + toggleBuddy(); - - User Profile Lookup + + Leaderboard - setUserProfileVisibility(true); + setLeaderboardVisibility(true); @@ -303,62 +309,4 @@ - -