Ticket #3244: t3244_keep_player_and_gamelist_selection_a18.patch

File t3244_keep_player_and_gamelist_selection_a18.patch, 4.7 KB (added by elexis, 9 years ago)

Both patches combined to a single file and made compatible to a18.

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

     
    11var g_ChatMessages = [];
    22var g_Name = "unknown";
    33var g_GameList = {};
     4var g_selectedNick = "";
    45var g_specialKey = Math.random();
    56// This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use.
    67var g_spamMonitor = {};
     8var g_selectedGameIP = "";
    79var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
    810var g_mapSizes = {};
    911const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    1012const g_mapTypes = ["skirmish", "random", "scenario"];
    1113var g_userRating = ""; // Rating of user, defaults to Unrated
     
    153155 * @return Array containing the player, presence, nickname, and rating listings.
    154156 */
    155157function updatePlayerList()
    156158{
    157159    var playersBox = Engine.GetGUIObjectByName("playersBox");
     160   
     161    if (playersBox.selected > -1)
     162        g_selectedNick = playersBox.list[playersBox.selected];
     163       
    158164    var playerList = [];
    159165    var presenceList = [];
    160166    var nickList = [];
    161167    var ratingList = [];
    162168    var cleanPlayerList = Engine.GetPlayerList();
     
    188194    }
    189195    playersBox.list_name = playerList;
    190196    playersBox.list_status = presenceList;
    191197    playersBox.list_rating = ratingList;
    192198    playersBox.list = nickList;
    193     if (playersBox.selected >= playersBox.list.length)
    194         playersBox.selected = -1;
     199   
     200    // Select the previously selected player
     201    playersBox.selected = nickList.indexOf(g_selectedNick);
     202   
    195203    return [playerList, presenceList, nickList, ratingList];
    196204}
    197205
    198206/**
    199207 * Display the profile of the selected player.
     
    355363 */
    356364function updateGameList()
    357365{
    358366    var gamesBox = Engine.GetGUIObjectByName("gamesBox");
    359367    var gameList = Engine.GetGameList();
     368    if (gamesBox.selected > -1)
     369        g_selectedGameIP = g_GameList[gamesBox.selected].ip;
     370   
    360371    // Store the game whole game list data so that we can access it later
    361372    // to update the game info panel.
    362373    g_GameList = gameList;
    363374
    364375    // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'.
     
    384395    var list_mapType = [];
    385396    var list_nPlayers = [];
    386397    var list = [];
    387398    var list_data = [];
    388399
     400    var selectedIndex = -1;
    389401    var c = 0;
    390402    for each (var g in gameList)
    391403    {
    392404        if(!filterGame(g))
    393405        {
     
    399411                name = '[color="255 127 0"]' + g.name + '[/color]';
    400412            else
    401413                name = '[color="255 0 0"]' + g.name + '[/color]';
    402414            list_name.push(name);
    403415            list_ip.push(g.ip);
     416            if (g.ip == g_selectedGameIP)
     417                selectedIndex = list_ip.length - 1;
    404418            list_mapName.push(translate(g.niceMapName));
    405419            list_mapSize.push(translatedMapSize(g.mapSize));
    406420            let idx = g_mapTypes.indexOf(g.mapType);
    407421            list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
    408422            list_nPlayers.push(g.nbp + "/" +g.tnbp);
     
    418432    gamesBox.list_mapType = list_mapType;
    419433    gamesBox.list_nPlayers = list_nPlayers;
    420434    gamesBox.list = list;
    421435    gamesBox.list_data = list_data;
    422436
    423     if (gamesBox.selected >= gamesBox.list_name.length)
    424         gamesBox.selected = -1;
    425 
     437    // Select previously selected game
     438    gamesBox.selected = selectedIndex;
     439   
    426440    // Update info box about the game currently selected
    427441    updateGameSelection();
    428442}
    429443
    430444/**
     
    626640            var playerList = playersBox.list_name;
    627641            var presenceList = playersBox.list_status;
    628642            var nickList = playersBox.list;
    629643            var ratingList = playersBox.list_rating;
    630644            var nickIndex = nickList.indexOf(nick);
     645
     646            if (playersBox.selected > -1)
     647                g_selectedNick = nickList[playersBox.selected];
     648
    631649            switch(message.level)
    632650            {
    633651            case "join":
    634652                if (nick == g_Name)
    635653                {
     
    655673                addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey });
    656674                break;
    657675            case "nick":
    658676                if (nickIndex == -1) // This shouldn't ever happen
    659677                    break;
     678               
    660679                if (!isValidNick(message.data))
    661680                {
    662681                    addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })});
    663682                    break;
    664683                }
     
    687706            // Push new data to GUI
    688707            playersBox.list_name = playerList;
    689708            playersBox.list_status = presenceList;
    690709            playersBox.list_rating = ratingList;
    691710            playersBox.list = nickList;     
    692             if (playersBox.selected >= playersBox.list.length)
    693                 playersBox.selected = -1;
     711            // Select the previously selected player
     712            playersBox.selected = nickList.indexOf(g_selectedNick);
    694713            break;
    695714        case "system":
    696715            switch (message.level)
    697716            {
    698717            case "standard":