Ticket #3244: t3244_keep_player_and_gamelist_selection_v2_r16728.patch
File t3244_keep_player_and_gamelist_selection_v2_r16728.patch, 5.2 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_specialKey = Math.random(); 5 8 // This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use. 6 9 var g_spamMonitor = {}; 7 10 var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true"; 8 11 var g_mapSizes = {}; … … 154 157 * @return Array containing the player, presence, nickname, and rating listings. 155 158 */ 156 159 function updatePlayerList() 157 160 { 158 161 var playersBox = Engine.GetGUIObjectByName("playersBox"); 162 163 // Save previously selected player 164 if (playersBox.selected > -1) 165 g_selectedNick = playersBox.list[playersBox.selected]; 166 159 167 var playerList = []; 160 168 var presenceList = []; 161 169 var nickList = []; 162 170 var ratingList = []; 163 171 var cleanPlayerList = Engine.GetPlayerList(); … … 189 197 } 190 198 playersBox.list_name = playerList; 191 199 playersBox.list_status = presenceList; 192 200 playersBox.list_rating = ratingList; 193 201 playersBox.list = nickList; 194 if (playersBox.selected >= playersBox.list.length) 195 playersBox.selected = -1; 202 203 // Select the previously selected player 204 playersBox.selected = playersBox.list.indexOf(g_selectedNick); 205 196 206 return [playerList, presenceList, nickList, ratingList]; 197 207 } 198 208 199 209 /** 200 210 * Display the profile of the selected player. … … 355 365 * Update the game listing from data cached in C++. 356 366 */ 357 367 function updateGameList() 358 368 { 359 369 var gamesBox = Engine.GetGUIObjectByName("gamesBox"); 360 var gameList = Engine.GetGameList(); 370 371 // Save previously selected game by ip 372 if (gamesBox.selected > -1) 373 g_selectedGameIP = g_filteredGameList[gamesBox.selected].ip; 374 361 375 // Store the game whole game list data so that we can access it later 362 376 // to update the game info panel. 363 g_GameList = gameList;377 g_GameList = Engine.GetGameList(); 364 378 365 379 // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'. 366 380 var gameStatuses = ['waiting', 'init', 'running']; 367 381 g_GameList.sort(function (a,b) { 368 382 if (gameStatuses.indexOf(a.state) < gameStatuses.indexOf(b.state)) … … 386 400 var list_nPlayers = []; 387 401 var list = []; 388 402 var list_data = []; 389 403 390 404 var c = 0; 391 for (var g of gameList) 405 var selectedIndex = -1; 406 for (var g of g_GameList) 392 407 { 393 408 if (!filterGame(g)) 394 409 { 395 410 // 'waiting' games are highlighted in orange, 'running' in red, and 'init' in green. 396 411 let name = escapeText(g.name); … … 400 415 name = '[color="255 127 0"]' + name + '[/color]'; 401 416 else 402 417 name = '[color="255 0 0"]' + name + '[/color]'; 403 418 list_name.push(name); 404 419 list_ip.push(g.ip); 420 if (g.ip == g_selectedGameIP) 421 selectedIndex = list_ip.length - 1; 405 422 list_mapName.push(translate(g.niceMapName)); 406 423 list_mapSize.push(translatedMapSize(g.mapSize)); 407 424 let idx = g_mapTypes.indexOf(g.mapType); 408 425 list_mapType.push(idx != -1 ? g_mapTypesText[idx] : ""); 409 426 list_nPlayers.push(g.nbp + "/" +g.tnbp); 410 427 list.push(name); 411 428 list_data.push(c); 412 429 } 413 430 c++; 414 431 } 415 432 g_filteredGameList = g_GameList.filter(g => !filterGame(g)); 433 416 434 gamesBox.list_name = list_name; 417 435 gamesBox.list_mapName = list_mapName; 418 436 gamesBox.list_mapSize = list_mapSize; 419 437 gamesBox.list_mapType = list_mapType; 420 438 gamesBox.list_nPlayers = list_nPlayers; 421 439 gamesBox.list = list; 422 440 gamesBox.list_data = list_data; 423 441 424 if (gamesBox.selected >= gamesBox.list_name.length)425 gamesBox.selected = -1;426 442 // Select previously selected game 443 gamesBox.selected = selectedIndex; 444 427 445 // Update info box about the game currently selected 428 446 updateGameSelection(); 429 447 } 430 448 431 449 /** … … 627 645 var playerList = playersBox.list_name; 628 646 var presenceList = playersBox.list_status; 629 647 var nickList = playersBox.list; 630 648 var ratingList = playersBox.list_rating; 631 649 var nickIndex = nickList.indexOf(nick); 650 651 // Save the previously selected nickname 652 if (playersBox.selected > -1) 653 g_selectedNick = playersBox.list[playersBox.selected]; 654 632 655 switch(message.level) 633 656 { 634 657 case "join": 635 658 if (nick == g_Name) 636 659 { … … 662 685 addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey }); 663 686 break; 664 687 case "nick": 665 688 if (nickIndex == -1) // This shouldn't ever happen 666 689 break; 690 667 691 if (!isValidNick(message.data)) 668 692 { 669 693 addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })}); 670 694 break; 671 695 } … … 693 717 } 694 718 // Push new data to GUI 695 719 playersBox.list_name = playerList; 696 720 playersBox.list_status = presenceList; 697 721 playersBox.list_rating = ratingList; 698 playersBox.list = nickList; 699 if (playersBox.selected >= playersBox.list.length)700 playersBox.selected = -1;722 playersBox.list = nickList; 723 // Select the previously selected player 724 playersBox.selected = nickList.indexOf(g_selectedNick); 701 725 break; 702 726 case "system": 703 727 switch (message.level) 704 728 { 705 729 case "standard":