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