Ticket #3244: t3244_keep_player_and_gamelist_selection_v2_r16728.patch

File t3244_keep_player_and_gamelist_selection_v2_r16728.patch, 5.2 KB (added by elexis, 9 years ago)

Same patch for svn. Diff the patches to see that they are equal.

  • binaries/data/mods/public/gui/lobby/lobby.js

     
    11var g_ChatMessages = [];
    22var g_Name = "unknown";
    33var g_GameList = {};
     4var g_filteredGameList = {};
     5var g_selectedGameIP = "";
     6var g_selectedNick = "";
    47var g_specialKey = Math.random();
    58// This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use.
    69var g_spamMonitor = {};
    710var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
    811var g_mapSizes = {};
     
    154157 * @return Array containing the player, presence, nickname, and rating listings.
    155158 */
    156159function updatePlayerList()
    157160{
    158161    var playersBox = Engine.GetGUIObjectByName("playersBox");
     162   
     163    // Save previously selected player
     164    if (playersBox.selected > -1)
     165        g_selectedNick = playersBox.list[playersBox.selected];
     166       
    159167    var playerList = [];
    160168    var presenceList = [];
    161169    var nickList = [];
    162170    var ratingList = [];
    163171    var cleanPlayerList = Engine.GetPlayerList();
     
    189197    }
    190198    playersBox.list_name = playerList;
    191199    playersBox.list_status = presenceList;
    192200    playersBox.list_rating = ratingList;
    193201    playersBox.list = nickList;
    194     if (playersBox.selected >= playersBox.list.length)
    195         playersBox.selected = -1;
     202   
     203    // Select the previously selected player
     204    playersBox.selected = playersBox.list.indexOf(g_selectedNick);
     205   
    196206    return [playerList, presenceList, nickList, ratingList];
    197207}
    198208
    199209/**
    200210 * Display the profile of the selected player.
     
    355365 * Update the game listing from data cached in C++.
    356366 */
    357367function updateGameList()
    358368{
    359369    var gamesBox = Engine.GetGUIObjectByName("gamesBox");
    360     var gameList = Engine.GetGameList();
     370   
     371    // Save previously selected game by ip
     372    if (gamesBox.selected > -1)
     373        g_selectedGameIP = g_filteredGameList[gamesBox.selected].ip;
     374   
    361375    // Store the game whole game list data so that we can access it later
    362376    // to update the game info panel.
    363     g_GameList = gameList;
     377    g_GameList = Engine.GetGameList();
    364378
    365379    // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'.
    366380    var gameStatuses = ['waiting', 'init', 'running'];
    367381    g_GameList.sort(function (a,b) {
    368382        if (gameStatuses.indexOf(a.state) < gameStatuses.indexOf(b.state))
     
    386400    var list_nPlayers = [];
    387401    var list = [];
    388402    var list_data = [];
    389403
    390404    var c = 0;
    391     for (var g of gameList)
     405    var selectedIndex = -1;
     406    for (var g of g_GameList)
    392407    {
    393408        if (!filterGame(g))
    394409        {
    395410            // 'waiting' games are highlighted in orange, 'running' in red, and 'init' in green.
    396411            let name = escapeText(g.name);
     
    400415                name = '[color="255 127 0"]' + name + '[/color]';
    401416            else
    402417                name = '[color="255 0 0"]' + name + '[/color]';
    403418            list_name.push(name);
    404419            list_ip.push(g.ip);
     420            if (g.ip == g_selectedGameIP)
     421                selectedIndex = list_ip.length - 1;
    405422            list_mapName.push(translate(g.niceMapName));
    406423            list_mapSize.push(translatedMapSize(g.mapSize));
    407424            let idx = g_mapTypes.indexOf(g.mapType);
    408425            list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
    409426            list_nPlayers.push(g.nbp + "/" +g.tnbp);
    410427            list.push(name);
    411428            list_data.push(c);
    412429        }
    413430        c++;
    414431    }
    415 
     432    g_filteredGameList = g_GameList.filter(g => !filterGame(g));
     433   
    416434    gamesBox.list_name = list_name;
    417435    gamesBox.list_mapName = list_mapName;
    418436    gamesBox.list_mapSize = list_mapSize;
    419437    gamesBox.list_mapType = list_mapType;
    420438    gamesBox.list_nPlayers = list_nPlayers;
    421439    gamesBox.list = list;
    422440    gamesBox.list_data = list_data;
    423441
    424     if (gamesBox.selected >= gamesBox.list_name.length)
    425         gamesBox.selected = -1;
    426 
     442    // Select previously selected game
     443    gamesBox.selected = selectedIndex;
     444   
    427445    // Update info box about the game currently selected
    428446    updateGameSelection();
    429447}
    430448
    431449/**
     
    627645            var playerList = playersBox.list_name;
    628646            var presenceList = playersBox.list_status;
    629647            var nickList = playersBox.list;
    630648            var ratingList = playersBox.list_rating;
    631649            var nickIndex = nickList.indexOf(nick);
     650
     651            // Save the previously selected nickname
     652            if (playersBox.selected > -1)
     653                g_selectedNick = playersBox.list[playersBox.selected];
     654
    632655            switch(message.level)
    633656            {
    634657            case "join":
    635658                if (nick == g_Name)
    636659                {
     
    662685                addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey });
    663686                break;
    664687            case "nick":
    665688                if (nickIndex == -1) // This shouldn't ever happen
    666689                    break;
     690               
    667691                if (!isValidNick(message.data))
    668692                {
    669693                    addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })});
    670694                    break;
    671695                }
     
    693717            }
    694718            // Push new data to GUI
    695719            playersBox.list_name = playerList;
    696720            playersBox.list_status = presenceList;
    697721            playersBox.list_rating = ratingList;
    698             playersBox.list = nickList;     
    699             if (playersBox.selected >= playersBox.list.length)
    700                 playersBox.selected = -1;
     722            playersBox.list = nickList;
     723            // Select the previously selected player
     724            playersBox.selected = nickList.indexOf(g_selectedNick);
    701725            break;
    702726        case "system":
    703727            switch (message.level)
    704728            {
    705729            case "standard":