Ticket #3244: t3244_keep_player_selection_r16665.patch

File t3244_keep_player_selection_r16665.patch, 2.9 KB (added by elexis, 9 years ago)

Fixes the second part of the bug. This patch can be tested with svn and two lobby accounts. If a player goes online or offline, the previously selected player will be selected again. If a player goes offline, then no player will be selected and the rating information will be hidden automatically. If the player comes online again, and no different player was selected meanwhile, then that previously selected player will be selected again (feature). Test the patch by selecting players with the first connected lobby account and change the playerlist by rejoining the lobby with the second account. To make sure that it works correctly, try selecting the first, the last, the rejoined player and another player from the list. If you change the lobby.js file, make sure to reconnect to the lobby. Either the hotloading doesn't work properly, or it is #3171.

  • 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 = {};
    78var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
    89var g_mapSizes = {};
     
    154155 * @return Array containing the player, presence, nickname, and rating listings.
    155156 */
    156157function updatePlayerList()
    157158{
    158159    var playersBox = Engine.GetGUIObjectByName("playersBox");
     160   
     161    if (playersBox.selected > -1)
     162        g_selectedNick = playersBox.list[playersBox.selected];
     163       
    159164    var playerList = [];
    160165    var presenceList = [];
    161166    var nickList = [];
    162167    var ratingList = [];
    163168    var cleanPlayerList = Engine.GetPlayerList();
     
    189194    }
    190195    playersBox.list_name = playerList;
    191196    playersBox.list_status = presenceList;
    192197    playersBox.list_rating = ratingList;
    193198    playersBox.list = nickList;
    194     if (playersBox.selected >= playersBox.list.length)
    195         playersBox.selected = -1;
     199   
     200    // Select the previously selected player
     201    playersBox.selected = nickList.indexOf(g_selectedNick);
     202   
    196203    return [playerList, presenceList, nickList, ratingList];
    197204}
    198205
    199206/**
    200207 * Display the profile of the selected player.
     
    627634            var playerList = playersBox.list_name;
    628635            var presenceList = playersBox.list_status;
    629636            var nickList = playersBox.list;
    630637            var ratingList = playersBox.list_rating;
    631638            var nickIndex = nickList.indexOf(nick);
     639
     640            if (playersBox.selected > -1)
     641                g_selectedNick = nickList[playersBox.selected];
     642
    632643            switch(message.level)
    633644            {
    634645            case "join":
    635646                if (nick == g_Name)
    636647                {
     
    662673                addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey });
    663674                break;
    664675            case "nick":
    665676                if (nickIndex == -1) // This shouldn't ever happen
    666677                    break;
     678               
    667679                if (!isValidNick(message.data))
    668680                {
    669681                    addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })});
    670682                    break;
    671683                }
     
    694706            // Push new data to GUI
    695707            playersBox.list_name = playerList;
    696708            playersBox.list_status = presenceList;
    697709            playersBox.list_rating = ratingList;
    698710            playersBox.list = nickList;     
    699             if (playersBox.selected >= playersBox.list.length)
    700                 playersBox.selected = -1;
     711            // Select the previously selected player
     712            playersBox.selected = nickList.indexOf(g_selectedNick);
    701713            break;
    702714        case "system":
    703715            switch (message.level)
    704716            {
    705717            case "standard":