Ticket #2405: lobby_game_list_sorting_without_arrows.patch
File lobby_game_list_sorting_without_arrows.patch, 4.3 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_GameListSortBy = "default"; 5 var g_GameListOrder = 1; // 1 for ascending sort, and -1 for descending 4 6 var g_specialKey = Math.random(); 5 7 // This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use. 6 8 var g_spamMonitor = {}; … … 74 76 // Update functions 75 77 //////////////////////////////////////////////////////////////////////////////////////////////// 76 78 79 function updateOrderSelection() 80 { 81 var newGameListSortBy = Engine.GetGUIObjectByName("gamesBox").selected_column; 82 if (newGameListSortBy == g_GameListSortBy) 83 g_GameListOrder = -g_GameListOrder; 84 else 85 { 86 g_GameListSortBy = newGameListSortBy; 87 g_GameListOrder = 1; 88 } 89 90 // update the list of games 91 updateGameList(); 92 93 // Update info box about the game currently selected 94 updateGameSelection(); 95 } 96 77 97 function resetFilters() 78 98 { 79 99 // Reset states of gui objects … … 365 385 // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'. 366 386 var gameStatuses = ['waiting', 'init', 'running']; 367 387 g_GameList.sort(function (a,b) { 368 if (gameStatuses.indexOf(a.state) < gameStatuses.indexOf(b.state)) 369 return -1; 370 else if (gameStatuses.indexOf(a.state) > gameStatuses.indexOf(b.state)) 371 return 1; 388 if (g_GameListSortBy == 'name') 389 { 390 // Alphabetical comparison of names. 391 if (a.name < b.name) 392 return -g_GameListOrder; 393 else if (a.name > b.name) 394 return g_GameListOrder; 395 return 0; 396 } 397 else if (g_GameListSortBy == 'mapName') 398 { 399 // Alphabetical comparison of map names. 400 if (translate(a.niceMapName) < translate(b.niceMapName)) 401 return -g_GameListOrder; 402 else if (translate(a.niceMapName) > translate(b.niceMapName)) 403 return g_GameListOrder; 404 return 0; 405 } 406 else if (g_GameListSortBy == 'mapSize') 407 { 408 // Alphabetical comparison of map size. 409 if (translatedMapSize(a.mapSize) < translatedMapSize(b.mapSize)) 410 return -g_GameListOrder; 411 else if (translatedMapSize(a.mapSize) > translatedMapSize(b.mapSize)) 412 return g_GameListOrder; 413 return 0; 414 } 415 else if (g_GameListSortBy == 'mapType') 416 { 417 // Numerical comparison of map types. 418 if (a.mapType < b.mapType) 419 return -g_GameListOrder; 420 else if (a.mapType > b.mapType) 421 return g_GameListOrder; 422 return 0; 423 } 424 else if (g_GameListSortBy == 'nPlayers') 425 { 426 // Numerical comparison of player count ratio. 427 if (a.nbp * b.tnbp < b.nbp * a.tnbp) // ratio a = a.nbp / a.tnbp, ratio b = b.nbp / b.tnbp 428 return -g_GameListOrder; 429 else if (a.nbp * b.tnbp > b.nbp * a.tnbp) 430 return g_GameListOrder; 431 return 0; 432 } 433 else 434 { 435 if (gameStatuses.indexOf(a.state) < gameStatuses.indexOf(b.state)) 436 return -1; 437 else if (gameStatuses.indexOf(a.state) > gameStatuses.indexOf(b.state)) 438 return 1; 372 439 373 // Alphabetical comparison of names as tiebreaker. 374 if (a.name < b.name) 375 return -1; 376 else if (a.name > b.name) 377 return 1; 378 return 0; 440 // Alphabetical comparison of names as tiebreaker. 441 if (a.name < b.name) 442 return -1; 443 else if (a.name > b.name) 444 return 1; 445 return 0; 446 } 379 447 }); 380 448 381 449 var list_name = []; -
binaries/data/mods/public/gui/lobby/lobby.xml
169 169 170 170 <!-- Middle panel: Filters, game list, chat box. --> 171 171 <object name="middlePanel" size="20%+5 5% 100%-255 97.2%"> 172 <object name="gamesBox" style="ModernList" type="olist" s ize="0 25 100% 48%" font="sans-stroke-13">172 <object name="gamesBox" style="ModernList" type="olist" sortable="true" size="0 25 100% 48%" font="sans-stroke-13"> 173 173 <action on="SelectionChange">updateGameSelection();</action> 174 <action on="SelectionColumnChange">updateOrderSelection();</action> 174 175 <def id="name" color="0 60 0" width="27%"> 175 176 <translatableAttribute id="heading">Name</translatableAttribute> 176 177 </def>