Ticket #3244: t3244_keep_player_and_gamelist_selection_a18.patch
File t3244_keep_player_and_gamelist_selection_a18.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_selectedNick = ""; 4 5 var g_specialKey = Math.random(); 5 6 // This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use. 6 7 var g_spamMonitor = {}; 8 var g_selectedGameIP = ""; 7 9 var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true"; 8 10 var g_mapSizes = {}; 9 11 const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")]; 10 12 const g_mapTypes = ["skirmish", "random", "scenario"]; 11 13 var g_userRating = ""; // Rating of user, defaults to Unrated … … 153 155 * @return Array containing the player, presence, nickname, and rating listings. 154 156 */ 155 157 function updatePlayerList() 156 158 { 157 159 var playersBox = Engine.GetGUIObjectByName("playersBox"); 160 161 if (playersBox.selected > -1) 162 g_selectedNick = playersBox.list[playersBox.selected]; 163 158 164 var playerList = []; 159 165 var presenceList = []; 160 166 var nickList = []; 161 167 var ratingList = []; 162 168 var cleanPlayerList = Engine.GetPlayerList(); … … 188 194 } 189 195 playersBox.list_name = playerList; 190 196 playersBox.list_status = presenceList; 191 197 playersBox.list_rating = ratingList; 192 198 playersBox.list = nickList; 193 if (playersBox.selected >= playersBox.list.length) 194 playersBox.selected = -1; 199 200 // Select the previously selected player 201 playersBox.selected = nickList.indexOf(g_selectedNick); 202 195 203 return [playerList, presenceList, nickList, ratingList]; 196 204 } 197 205 198 206 /** 199 207 * Display the profile of the selected player. … … 355 363 */ 356 364 function updateGameList() 357 365 { 358 366 var gamesBox = Engine.GetGUIObjectByName("gamesBox"); 359 367 var gameList = Engine.GetGameList(); 368 if (gamesBox.selected > -1) 369 g_selectedGameIP = g_GameList[gamesBox.selected].ip; 370 360 371 // Store the game whole game list data so that we can access it later 361 372 // to update the game info panel. 362 373 g_GameList = gameList; 363 374 364 375 // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'. … … 384 395 var list_mapType = []; 385 396 var list_nPlayers = []; 386 397 var list = []; 387 398 var list_data = []; 388 399 400 var selectedIndex = -1; 389 401 var c = 0; 390 402 for each (var g in gameList) 391 403 { 392 404 if(!filterGame(g)) 393 405 { … … 399 411 name = '[color="255 127 0"]' + g.name + '[/color]'; 400 412 else 401 413 name = '[color="255 0 0"]' + g.name + '[/color]'; 402 414 list_name.push(name); 403 415 list_ip.push(g.ip); 416 if (g.ip == g_selectedGameIP) 417 selectedIndex = list_ip.length - 1; 404 418 list_mapName.push(translate(g.niceMapName)); 405 419 list_mapSize.push(translatedMapSize(g.mapSize)); 406 420 let idx = g_mapTypes.indexOf(g.mapType); 407 421 list_mapType.push(idx != -1 ? g_mapTypesText[idx] : ""); 408 422 list_nPlayers.push(g.nbp + "/" +g.tnbp); … … 418 432 gamesBox.list_mapType = list_mapType; 419 433 gamesBox.list_nPlayers = list_nPlayers; 420 434 gamesBox.list = list; 421 435 gamesBox.list_data = list_data; 422 436 423 if (gamesBox.selected >= gamesBox.list_name.length)424 gamesBox.selected = -1;425 437 // Select previously selected game 438 gamesBox.selected = selectedIndex; 439 426 440 // Update info box about the game currently selected 427 441 updateGameSelection(); 428 442 } 429 443 430 444 /** … … 626 640 var playerList = playersBox.list_name; 627 641 var presenceList = playersBox.list_status; 628 642 var nickList = playersBox.list; 629 643 var ratingList = playersBox.list_rating; 630 644 var nickIndex = nickList.indexOf(nick); 645 646 if (playersBox.selected > -1) 647 g_selectedNick = nickList[playersBox.selected]; 648 631 649 switch(message.level) 632 650 { 633 651 case "join": 634 652 if (nick == g_Name) 635 653 { … … 655 673 addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey }); 656 674 break; 657 675 case "nick": 658 676 if (nickIndex == -1) // This shouldn't ever happen 659 677 break; 678 660 679 if (!isValidNick(message.data)) 661 680 { 662 681 addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })}); 663 682 break; 664 683 } … … 687 706 // Push new data to GUI 688 707 playersBox.list_name = playerList; 689 708 playersBox.list_status = presenceList; 690 709 playersBox.list_rating = ratingList; 691 710 playersBox.list = nickList; 692 if (playersBox.selected >= playersBox.list.length)693 playersBox.selected = -1;711 // Select the previously selected player 712 playersBox.selected = nickList.indexOf(g_selectedNick); 694 713 break; 695 714 case "system": 696 715 switch (message.level) 697 716 { 698 717 case "standard":