Ticket #3258: t3258_move_map_description_v1.patch
File t3258_move_map_description_v1.patch, 6.0 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility.js
function initMapSizes() 129 129 } 130 130 131 131 return sizes; 132 132 } 133 133 134 /** 135 * Returns title or placeholder. Requires g_mapSizes. 136 * 137 * @param mapSize {Number} - tilecount 138 */ 139 function translateMapSize(tiles) 140 { 141 var idx = g_mapSizes.tiles.findIndex(tileCount => tileCount == tiles); 142 return (idx == -1) ? translateWithContext("map size", "Default") : g_mapSizes.shortNames[idx]; 143 } 144 145 /** 146 * Returns map description and preview image or placeholder. 147 */ 148 function getMapDescriptionAndPreview(mapType, mapName) 149 { 150 var mapData; 151 if (mapType == "random" && mapName == "random") 152 mapData = { "settings": { "Description": translate("A randomly selected map.") } }; 153 else if (mapType == "random" && Engine.FileExists(mapName + ".json")) 154 mapData = Engine.ReadJSONFile(mapName + ".json"); 155 else if (Engine.FileExists(mapName + ".xml")) 156 mapData = Engine.LoadMapSettings(mapName + ".xml"); 157 else 158 warn(sprintf("Map '%(mapName)s' not found locally.", { "mapName": mapName })); 159 160 return { 161 "description": mapData && mapData.settings.Description ? translate(mapData.settings.Description) : translate("Sorry, no description available."), 162 "preview": mapData && mapData.settings.Preview ? mapData.settings.Preview : "nopreview.png" 163 }; 164 } 165 134 166 // ==================================================================== 135 167 136 168 // Convert integer color values to string (for use in GUI objects) 137 169 function rgbToGuiColor(color, alpha) 138 170 { -
binaries/data/mods/public/gui/lobby/lobby.js
function updateGameList() 483 483 else 484 484 name = '[color="255 0 0"]' + name + '[/color]'; 485 485 list_name.push(name); 486 486 list_ip.push(g.ip); 487 487 list_mapName.push(translate(g.niceMapName)); 488 list_mapSize.push(translate dMapSize(g.mapSize));488 list_mapSize.push(translateMapSize(g.mapSize)); 489 489 let mapTypeIdx = g_MapTypes.Name.indexOf(g.mapType); 490 490 list_mapType.push(mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : ""); 491 491 list_nPlayers.push(g.nbp + "/" +g.tnbp); 492 492 list.push(name); 493 493 list_data.push(c); … … function formatPlayerListEntry(nickname, 561 561 // Push this player's name and status onto the list 562 562 return [formattedName, formattedStatus, formattedRating]; 563 563 } 564 564 565 565 /** 566 * Given a map size, returns that map size translated into the current567 * language.568 */569 function translatedMapSize(mapSize)570 {571 if (+mapSize !== +mapSize) // NaN572 return translate(mapSize);573 else574 return g_mapSizes.shortNames[g_mapSizes.tiles.indexOf(+mapSize)];575 }576 577 /**578 566 * Populate the game info area with information on the current game selection. 579 567 */ 580 568 function updateGameSelection() 581 569 { 582 570 var selected = Engine.GetGUIObjectByName("gamesBox").selected; … … function updateGameSelection() 587 575 Engine.GetGUIObjectByName("joinGameButton").hidden = true; 588 576 Engine.GetGUIObjectByName("gameInfoEmpty").hidden = false; 589 577 return; 590 578 } 591 579 592 var mapData;593 580 var g = Engine.GetGUIObjectByName("gamesBox").list_data[selected]; 594 581 595 // Load map data596 if (g_GameList[g].mapType == "random" && g_GameList[g].mapName == "random")597 mapData = {"settings": {"Description": translate("A randomly selected map.")}};598 else if (g_GameList[g].mapType == "random" && Engine.FileExists(g_GameList[g].mapName + ".json"))599 mapData = Engine.ReadJSONFile(g_GameList[g].mapName + ".json");600 else if (Engine.FileExists(g_GameList[g].mapName + ".xml"))601 mapData = Engine.LoadMapSettings(g_GameList[g].mapName + ".xml");602 else603 // Warn the player if we can't find the map.604 warn(sprintf("Map '%(mapName)s' not found locally.", { mapName: g_GameList[g].mapName }));605 606 582 // Show the game info panel and join button. 607 583 Engine.GetGUIObjectByName("gameInfo").hidden = false; 608 584 Engine.GetGUIObjectByName("joinGameButton").hidden = false; 609 585 Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true; 610 586 611 587 // Display the map name, number of players, the names of the players, the map size and the map type. 612 588 Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName); 613 589 Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp; 614 590 Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players; 615 Engine.GetGUIObjectByName("sgMapSize").caption = translate dMapSize(g_GameList[g].mapSize);591 Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(g_GameList[g].mapSize); 616 592 let mapTypeIdx = g_MapTypes.Name.indexOf(g_GameList[g].mapType); 617 593 Engine.GetGUIObjectByName("sgMapType").caption = mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : ""; 618 594 619 // Display map description if it exists, otherwise display a placeholder.620 if (mapData && mapData.settings.Description)621 var mapDescription = translate(mapData.settings.Description);622 else623 var mapDescription = translate("Sorry, no description available.");624 595 625 596 // Display map preview if it exists, otherwise display a placeholder. 626 597 if (mapData && mapData.settings.Preview) 627 598 var mapPreview = mapData.settings.Preview; 628 599 else 629 600 var mapPreview = "nopreview.png"; 630 601 631 Engine.GetGUIObjectByName("sgMapDescription").caption = mapDescription; 632 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapPreview; 602 // Display map description and preview (or placeholder) 603 var mapData = getMapDescriptionAndPreview(g_GameList[g].mapType, g_GameList[g].mapName); 604 Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description; 605 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview; 633 606 } 634 607 635 608 /** 636 609 * Start the joining process on the currectly selected game. 637 610 */