Ticket #3244: t3244_keep_gamelist_selection_a18.patch

File t3244_keep_gamelist_selection_a18.patch, 2.3 KB (added by elexis, 9 years ago)

Same patch, but for a18.

  • lobby.js

    old new  
    22var g_Name = "unknown";
    33var g_GameList = {};
    44var g_specialKey = Math.random();
    55// This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use.
    66var g_spamMonitor = {};
     7var g_selectedGameIP = "";
    78var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
    89var g_mapSizes = {};
    910const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    1011const g_mapTypes = ["skirmish", "random", "scenario"];
    1112var g_userRating = ""; // Rating of user, defaults to Unrated
     
    355356 */
    356357function updateGameList()
    357358{
    358359    var gamesBox = Engine.GetGUIObjectByName("gamesBox");
    359360    var gameList = Engine.GetGameList();
     361    if (gamesBox.selected > -1)
     362        g_selectedGameIP = g_GameList[gamesBox.selected].ip;
     363   
    360364    // Store the game whole game list data so that we can access it later
    361365    // to update the game info panel.
    362366    g_GameList = gameList;
    363367
    364368    // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'.
     
    384388    var list_mapType = [];
    385389    var list_nPlayers = [];
    386390    var list = [];
    387391    var list_data = [];
    388392
     393    var selectedIndex = -1;
    389394    var c = 0;
    390395    for each (var g in gameList)
    391396    {
    392397        if(!filterGame(g))
    393398        {
     
    399404                name = '[color="255 127 0"]' + g.name + '[/color]';
    400405            else
    401406                name = '[color="255 0 0"]' + g.name + '[/color]';
    402407            list_name.push(name);
    403408            list_ip.push(g.ip);
     409            if (g.ip == g_selectedGameIP)
     410                selectedIndex = list_ip.length - 1;
    404411            list_mapName.push(translate(g.niceMapName));
    405412            list_mapSize.push(translatedMapSize(g.mapSize));
    406413            let idx = g_mapTypes.indexOf(g.mapType);
    407414            list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
    408415            list_nPlayers.push(g.nbp + "/" +g.tnbp);
     
    418425    gamesBox.list_mapType = list_mapType;
    419426    gamesBox.list_nPlayers = list_nPlayers;
    420427    gamesBox.list = list;
    421428    gamesBox.list_data = list_data;
    422429
    423     if (gamesBox.selected >= gamesBox.list_name.length)
    424         gamesBox.selected = -1;
    425 
     430    // Select previously selected game
     431    gamesBox.selected = selectedIndex;
     432   
    426433    // Update info box about the game currently selected
    427434    updateGameSelection();
    428435}
    429436
    430437/**