Ticket #3244: t3244_keep_player_and_gamelist_selection_v3_16789.patch
File t3244_keep_player_and_gamelist_selection_v3_16789.patch, 5.1 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_filteredGameList = []; 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_filteredGameList[gamesBox.selected].ip; 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 var g_filteredGameList = []; 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_filteredGameList.push(g); 479 498 } 480 499 c++; 481 500 } 482 501 483 502 gamesBox.list_name = list_name; 484 503 gamesBox.list_mapName = list_mapName; 485 504 gamesBox.list_mapSize = list_mapSize; 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 { … … 729 753 addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey }); 730 754 break; 731 755 case "nick": 732 756 if (nickIndex == -1) // This shouldn't ever happen 733 757 break; 758 734 759 if (!isValidNick(message.data)) 735 760 { 736 761 addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })}); 737 762 break; 738 763 } … … 760 785 } 761 786 // Push new data to GUI 762 787 playersBox.list_name = playerList; 763 788 playersBox.list_status = presenceList; 764 789 playersBox.list_rating = ratingList; 765 playersBox.list = nickList; 766 if (playersBox.selected >= playersBox.list.length)767 playersBox.selected = -1;790 playersBox.list = nickList; 791 // Select the previously selected player 792 playersBox.selected = nickList.indexOf(g_selectedNick); 768 793 break; 769 794 case "system": 770 795 switch (message.level) 771 796 { 772 797 case "standard":