Ticket #3258: t3258_move_map_description_v1.patch

File t3258_move_map_description_v1.patch, 6.0 KB (added by elexis, 9 years ago)

Rebased. This should be committed separately.

  • binaries/data/mods/public/gui/common/functions_utility.js

    function initMapSizes()  
    129129    }
    130130
    131131    return sizes;
    132132}
    133133
     134/**
     135 * Returns title or placeholder. Requires g_mapSizes.
     136 *
     137 * @param mapSize {Number} - tilecount
     138 */
     139function 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 */
     148function 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
    134166// ====================================================================
    135167
    136168// Convert integer color values to string (for use in GUI objects)
    137169function rgbToGuiColor(color, alpha)
    138170{
  • binaries/data/mods/public/gui/lobby/lobby.js

    function updateGameList()  
    483483            else
    484484                name = '[color="255 0 0"]' + name + '[/color]';
    485485            list_name.push(name);
    486486            list_ip.push(g.ip);
    487487            list_mapName.push(translate(g.niceMapName));
    488             list_mapSize.push(translatedMapSize(g.mapSize));
     488            list_mapSize.push(translateMapSize(g.mapSize));
    489489            let mapTypeIdx = g_MapTypes.Name.indexOf(g.mapType);
    490490            list_mapType.push(mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : "");
    491491            list_nPlayers.push(g.nbp + "/" +g.tnbp);
    492492            list.push(name);
    493493            list_data.push(c);
    function formatPlayerListEntry(nickname,  
    561561    // Push this player's name and status onto the list
    562562    return [formattedName, formattedStatus, formattedRating];
    563563}
    564564
    565565/**
    566  * Given a map size, returns that map size translated into the current
    567  * language.
    568  */
    569 function translatedMapSize(mapSize)
    570 {
    571     if (+mapSize !== +mapSize) // NaN
    572         return translate(mapSize);
    573     else
    574         return g_mapSizes.shortNames[g_mapSizes.tiles.indexOf(+mapSize)];
    575 }
    576 
    577 /**
    578566 * Populate the game info area with information on the current game selection.
    579567 */
    580568function updateGameSelection()
    581569{
    582570    var selected = Engine.GetGUIObjectByName("gamesBox").selected;
    function updateGameSelection()  
    587575        Engine.GetGUIObjectByName("joinGameButton").hidden = true;
    588576        Engine.GetGUIObjectByName("gameInfoEmpty").hidden = false;
    589577        return;
    590578    }
    591579
    592     var mapData;
    593580    var g = Engine.GetGUIObjectByName("gamesBox").list_data[selected];
    594581
    595     // Load map data
    596     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     else
    603         // 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 
    606582    // Show the game info panel and join button.
    607583    Engine.GetGUIObjectByName("gameInfo").hidden = false;
    608584    Engine.GetGUIObjectByName("joinGameButton").hidden = false;
    609585    Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true;
    610586
    611587    // Display the map name, number of players, the names of the players, the map size and the map type.
    612588    Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName);
    613589    Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp;
    614590    Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players;
    615     Engine.GetGUIObjectByName("sgMapSize").caption = translatedMapSize(g_GameList[g].mapSize);
     591    Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(g_GameList[g].mapSize);
    616592    let mapTypeIdx = g_MapTypes.Name.indexOf(g_GameList[g].mapType);
    617593    Engine.GetGUIObjectByName("sgMapType").caption = mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : "";
    618594
    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     else
    623         var mapDescription = translate("Sorry, no description available.");
    624595
    625596    // Display map preview if it exists, otherwise display a placeholder.
    626597    if (mapData && mapData.settings.Preview)
    627598        var mapPreview = mapData.settings.Preview;
    628599    else
    629600        var mapPreview = "nopreview.png";
    630601
    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;
    633606}
    634607
    635608/**
    636609 * Start the joining process on the currectly selected game.
    637610 */