Ticket #3244: t3244_keep_player_and_gamelist_selection_v4_16839.patch
File t3244_keep_player_and_gamelist_selection_v4_16839.patch, 4.7 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/lobby/lobby.js
1 1 var g_ChatMessages = []; 2 2 var g_Name = "unknown"; 3 3 var g_GameList = {} 4 var g_filteredGameListIPs = []; 5 var g_selectedGameIP = ""; 6 var g_selectedNick = ""; 4 7 var g_GameListSortBy = "name"; 5 8 var g_PlayerListSortBy = "name"; 6 9 var g_GameListOrder = 1; // 1 for ascending sort, and -1 for descending 7 10 var g_PlayerListOrder = 1; 8 11 var g_specialKey = Math.random(); … … 170 173 * @return Array containing the player, presence, nickname, and rating listings. 171 174 */ 172 175 function updatePlayerList() 173 176 { 174 177 var playersBox = Engine.GetGUIObjectByName("playersBox"); 178 179 // Save previously selected player 180 if (playersBox.selected > -1) 181 g_selectedNick = playersBox.list[playersBox.selected]; 182 175 183 var playerList = []; 176 184 var presenceList = []; 177 185 var nickList = []; 178 186 var ratingList = []; 179 187 var cleanPlayerList = Engine.GetPlayerList(); … … 229 237 } 230 238 playersBox.list_name = playerList; 231 239 playersBox.list_status = presenceList; 232 240 playersBox.list_rating = ratingList; 233 241 playersBox.list = nickList; 234 if (playersBox.selected >= playersBox.list.length) 235 playersBox.selected = -1; 242 243 // Select the previously selected player 244 playersBox.selected = playersBox.list.indexOf(g_selectedNick); 245 236 246 return [playerList, presenceList, nickList, ratingList]; 237 247 } 238 248 239 249 /** 240 250 * Display the profile of the selected player. … … 395 405 * Update the game listing from data cached in C++. 396 406 */ 397 407 function updateGameList() 398 408 { 399 409 var gamesBox = Engine.GetGUIObjectByName("gamesBox"); 400 var gameList = Engine.GetGameList(); 410 411 // Save previously selected game by ip 412 if (gamesBox.selected > -1) 413 g_selectedGameIP = g_filteredGameListIPs[gamesBox.selected]; 414 401 415 // Store the game whole game list data so that we can access it later 402 416 // to update the game info panel. 403 g_GameList = gameList;417 g_GameList = Engine.GetGameList(); 404 418 405 419 // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'. 406 420 var gameStatuses = ['waiting', 'init', 'running']; 407 421 g_GameList.sort(function (a,b) { 408 422 switch (g_GameListSortBy) … … 453 467 var list_nPlayers = []; 454 468 var list = []; 455 469 var list_data = []; 456 470 457 471 var c = 0; 458 for (var g of gameList) 472 var selectedIndex = -1; 473 g_filteredGameListIPs = []; 474 for (var g of g_GameList) 459 475 { 460 476 if (!filterGame(g)) 461 477 { 462 478 // 'waiting' games are highlighted in orange, 'running' in red, and 'init' in green. 463 479 let name = escapeText(g.name); … … 467 483 name = '[color="255 127 0"]' + name + '[/color]'; 468 484 else 469 485 name = '[color="255 0 0"]' + name + '[/color]'; 470 486 list_name.push(name); 471 487 list_ip.push(g.ip); 488 if (g.ip == g_selectedGameIP) 489 selectedIndex = list_ip.length - 1; 472 490 list_mapName.push(translate(g.niceMapName)); 473 491 list_mapSize.push(translatedMapSize(g.mapSize)); 474 492 let idx = g_mapTypes.indexOf(g.mapType); 475 493 list_mapType.push(idx != -1 ? g_mapTypesText[idx] : ""); 476 494 list_nPlayers.push(g.nbp + "/" +g.tnbp); 477 495 list.push(name); 478 496 list_data.push(c); 497 g_filteredGameListIPs.push(g.ip); 479 498 } 480 499 c++; 481 500 } 482 501 483 502 gamesBox.list_name = list_name; … … 486 505 gamesBox.list_mapType = list_mapType; 487 506 gamesBox.list_nPlayers = list_nPlayers; 488 507 gamesBox.list = list; 489 508 gamesBox.list_data = list_data; 490 509 491 if (gamesBox.selected >= gamesBox.list_name.length)492 gamesBox.selected = -1;493 510 // Select previously selected game 511 gamesBox.selected = selectedIndex; 512 494 513 // Update info box about the game currently selected 495 514 updateGameSelection(); 496 515 } 497 516 498 517 /** … … 694 713 var playerList = playersBox.list_name; 695 714 var presenceList = playersBox.list_status; 696 715 var nickList = playersBox.list; 697 716 var ratingList = playersBox.list_rating; 698 717 var nickIndex = nickList.indexOf(nick); 718 719 // Save the previously selected nickname 720 if (playersBox.selected > -1) 721 g_selectedNick = playersBox.list[playersBox.selected]; 722 699 723 switch(message.level) 700 724 { 701 725 case "join": 702 726 if (nick == g_Name) 703 727 { … … 760 784 } 761 785 // Push new data to GUI 762 786 playersBox.list_name = playerList; 763 787 playersBox.list_status = presenceList; 764 788 playersBox.list_rating = ratingList; 765 playersBox.list = nickList; 766 if (playersBox.selected >= playersBox.list.length)767 playersBox.selected = -1;789 playersBox.list = nickList; 790 // Select the previously selected player 791 playersBox.selected = nickList.indexOf(g_selectedNick); 768 792 break; 769 793 case "system": 770 794 switch (message.level) 771 795 { 772 796 case "standard":