Ticket #3355: t3355_move_maptypes_v1.patch

File t3355_move_maptypes_v1.patch, 11.0 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/common/settings.js

     
    3030function loadSettingsValues()
    3131{
    3232    var settings = {
    3333        "Ceasefire": loadCeasefire(),
    3434        "GameSpeeds": loadSettingValuesFile("game_speeds.json"),
     35        "MapTypes": loadMapTypes(),
    3536        "PopulationCapacities": loadPopulationCapacities(),
    3637        "StartingResources": loadSettingValuesFile("starting_resources.json"),
    3738        "VictoryConditions": loadVictoryConditions()
    3839    };
    3940
     
    8889            sprintf(translatePluralWithContext("ceasefire", "%(minutes)s minute", "%(minutes)s minutes", timeout), { "minutes": timeout })
    8990    }));
    9091}
    9192
    9293/**
     94 * Hardcoded, as modding is not supported without major changes.
     95 *
     96 * @returns {Array}
     97 */
     98function loadMapTypes()
     99{
     100    return [
     101        {
     102            "Name": "skirmish",
     103            "Title": translateWithContext("map", "Skirmish"),
     104            "Default": true
     105        },
     106        {
     107            "Name": "random",
     108            "Title": translateWithContext("map", "Random")
     109        },
     110        {
     111            "Name": "scenario",
     112            "Title": translate("Scenario") // TODO: update the translation (but not shortly before a release)
     113        }
     114    ];
     115}
     116
     117/**
    93118 * Loads available gametypes.
    94119 *
    95120 * @returns {Array|undefined}
    96121 */
    97122function loadVictoryConditions()
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    33const DEFAULT_NETWORKED_MAP = "Acropolis 01";
    44const DEFAULT_OFFLINE_MAP = "Acropolis 01";
    55
    66const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined);
    77const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly) : undefined);
    8 const g_VictoryConditions = prepareForDropdown(g_Settings ? g_Settings.VictoryConditions : undefined);
     8const g_MapTypes = prepareForDropdown(g_Settings ? g_Settings.MapTypes : undefined);
    99const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
    1010const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
     11const g_VictoryConditions = prepareForDropdown(g_Settings ? g_Settings.VictoryConditions : undefined);
    1112
    1213////////////////////////////////////////////////////////////////////////////////////////////////
    1314
    1415// Is this is a networked game, or offline
    1516var g_IsNetworked;
     
    126127    // Init civs
    127128    initCivNameList();
    128129
    129130    // Init map types
    130131    var mapTypes = Engine.GetGUIObjectByName("mapTypeSelection");
    131     mapTypes.list = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    132     mapTypes.list_data = ["skirmish","random","scenario"];
     132    mapTypes.list = g_MapTypes.Title;
     133    mapTypes.list_data = g_MapTypes.Name;
    133134
    134135    // Setup map filters - will appear in order they are added
    135136    addFilter("default", translate("Default"), function(settings) { return settings && (settings.Keywords === undefined || !keywordTestOR(settings.Keywords, ["naval", "demo", "hidden"])); });
    136137    addFilter("naval", translate("Naval Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["naval"]); });
    137138    addFilter("demo", translate("Demo Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["demo"]); });
     
    158159    }
    159160
    160161    // Setup controls for host only
    161162    if (g_IsController)
    162163    {
    163         mapTypes.selected = 0;
     164        mapTypes.selected = g_MapTypes.Default;
    164165        mapFilters.selected = 0;
    165166
    166167        // Create a unique ID for this match, to be used for identifying the same game reports
    167168        // for the lobby.
    168169        g_GameAttributes.matchID = Engine.GetMatchID();
     
    738739    }
    739740
    740741    var mapFilterSelection = Engine.GetGUIObjectByName("mapFilterSelection");
    741742    mapFilterSelection.selected = mapFilterSelection.list_data.indexOf(attrs.mapFilter);
    742743
    743     var mapTypeSelection = Engine.GetGUIObjectByName("mapTypeSelection");
    744     mapTypeSelection.selected = mapTypeSelection.list_data.indexOf(attrs.mapType);
     744    Engine.GetGUIObjectByName("mapTypeSelection").selected = g_MapTypes.Name.indexOf(attrs.mapType);
    745745
    746746    initMapNameList();
    747747
    748748    var mapSelectionBox = Engine.GetGUIObjectByName("mapSelection");
    749749    mapSelectionBox.selected = mapSelectionBox.list_data.indexOf(mapName);
     
    11641164    if (!g_IsController)
    11651165    {
    11661166        var mapFilterSelection = Engine.GetGUIObjectByName("mapFilterSelection");
    11671167        var mapFilterId = mapFilterSelection.list_data.indexOf(g_GameAttributes.mapFilter);
    11681168        Engine.GetGUIObjectByName("mapFilterText").caption = mapFilterSelection.list[mapFilterId];
    1169         var mapTypeSelection = Engine.GetGUIObjectByName("mapTypeSelection");
    1170         var idx = mapTypeSelection.list_data.indexOf(g_GameAttributes.mapType);
    1171         Engine.GetGUIObjectByName("mapTypeText").caption = mapTypeSelection.list[idx];
     1169        Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[g_MapTypes.Name.indexOf(g_GameAttributes.mapType)];
    11721170        var mapSelectionBox = Engine.GetGUIObjectByName("mapSelection");
    11731171        mapSelectionBox.selected = mapSelectionBox.list_data.indexOf(mapName);
    11741172        Engine.GetGUIObjectByName("mapSelectionText").caption = translate(getMapDisplayName(mapName));
    11751173        if (mapSettings.PopulationCap)
    11761174        {
  • binaries/data/mods/public/gui/lobby/lobby.js

     
     1const g_MapTypes = prepareForDropdown(g_Settings ? g_Settings.MapTypes : undefined);
     2
    13var g_ChatMessages = [];
    24var g_Name = "unknown";
    35var g_GameList = {}
    46var g_GameListSortBy = "name";
    57var g_PlayerListSortBy = "name";
     
    810var g_specialKey = Math.random();
    911// This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use.
    1012var g_spamMonitor = {};
    1113var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
    1214var g_mapSizes = {};
    13 const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    14 const g_mapTypes = ["skirmish", "random", "scenario"];
    1515var g_userRating = ""; // Rating of user, defaults to Unrated
    1616var g_modPrefix = "@";
    1717// Block spammers for 30 seconds.
    1818var SPAM_BLOCK_LENGTH = 30;
    1919
    2020////////////////////////////////////////////////////////////////////////////////////////////////
    2121
    2222function init(attribs)
    2323{
     24    if (!g_Settings)
     25    {
     26        returnToMainMenu();
     27        return;
     28    }
     29
    2430    // Play menu music
    2531    initMusic();
    2632    global.music.setState(global.music.states.MENU);
    2733
    2834    g_Name = Engine.LobbyGetNick();
     
    4046    var playersNumberFilter = Engine.GetGUIObjectByName("playersNumberFilter");
    4147    playersNumberFilter.list = [translateWithContext("player number", "Any")].concat(playersArray);
    4248    playersNumberFilter.list_data = [""].concat(playersArray);
    4349
    4450    var mapTypeFilter = Engine.GetGUIObjectByName("mapTypeFilter");
    45     mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_mapTypesText);
    46     mapTypeFilter.list_data = [""].concat(g_mapTypes);
     51    mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_MapTypes.Title);
     52    mapTypeFilter.list_data = [""].concat(g_MapTypes.Name);
    4753
    4854    Engine.LobbySetPlayerPresence("available");
    4955    Engine.SendGetGameList();
    5056    Engine.SendGetBoardList();
    5157
     
    5662    updateSubject(Engine.LobbyGetRoomSubject());
    5763
    5864    resetFilters();
    5965}
    6066
     67function returnToMainMenu()
     68{
     69    lobbyStop();
     70    Engine.SwitchGuiPage("page_pregame.xml");
     71}
     72
    6173////////////////////////////////////////////////////////////////////////////////////////////////
    6274// Xmpp client connection management
    6375////////////////////////////////////////////////////////////////////////////////////////////////
    6476
    6577
     
    101113function resetFilters()
    102114{
    103115    // Reset states of gui objects
    104116    Engine.GetGUIObjectByName("mapSizeFilter").selected = 0
    105117    Engine.GetGUIObjectByName("playersNumberFilter").selected = 0;
    106     Engine.GetGUIObjectByName("mapTypeFilter").selected = 0;
     118    Engine.GetGUIObjectByName("mapTypeFilter").selected = g_MapTypes.Default;
    107119    Engine.GetGUIObjectByName("showFullFilter").checked = false;
    108120
    109121    applyFilters();
    110122}
    111123
     
    472484                name = '[color="255 0 0"]' + name + '[/color]';
    473485            list_name.push(name);
    474486            list_ip.push(g.ip);
    475487            list_mapName.push(translate(g.niceMapName));
    476488            list_mapSize.push(translatedMapSize(g.mapSize));
    477             let idx = g_mapTypes.indexOf(g.mapType);
    478             list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
     489            let mapTypeIdx = g_MapTypes.Name.indexOf(g.mapType);
     490            list_mapType.push(mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : "");
    479491            list_nPlayers.push(g.nbp + "/" +g.tnbp);
    480492            list.push(name);
    481493            list_data.push(c);
    482494        }
    483495        c++;
     
    599611    // Display the map name, number of players, the names of the players, the map size and the map type.
    600612    Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName);
    601613    Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp;
    602614    Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players;
    603615    Engine.GetGUIObjectByName("sgMapSize").caption = translatedMapSize(g_GameList[g].mapSize);
    604     let idx = g_mapTypes.indexOf(g_GameList[g].mapType);
    605     Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_mapTypesText[idx] : "";
     616    let mapTypeIdx = g_MapTypes.indexOf(g_GameList[g].mapType);
     617    Engine.GetGUIObjectByName("sgMapType").caption = mapTypeIdx != -1 ? g_MapTypes.Title[mapTypeIdx] : "";
    606618
    607619    // Display map description if it exists, otherwise display a placeholder.
    608620    if (mapData && mapData.settings.Description)
    609621        var mapDescription = translate(mapData.settings.Description);
    610622    else
     
    810822        break;
    811823    case "ban": // TODO: Split reason from nick and pass it too, for now just support "/ban nick"
    812824        Engine.LobbyBan(nick, "");
    813825        break;
    814826    case "quit":
    815         lobbyStop();
    816         Engine.SwitchGuiPage("page_pregame.xml");
     827        returnToMainMenu();
    817828        break;
    818829    case "say":
    819830    case "me":
    820831        return false;
    821832    default:
  • binaries/data/mods/public/gui/lobby/lobby.xml

     
    162162                </action>
    163163            </object>
    164164
    165165            <object type="button" style="ModernButtonRed" size="0 100%-25 100% 100%">
    166166                <translatableAttribute id="caption">Main Menu</translatableAttribute>
    167                 <action on="Press">
    168                     lobbyStop();
    169                     Engine.SwitchGuiPage("page_pregame.xml");
    170                 </action>
     167                <action on="Press">returnToMainMenu();</action>
    171168            </object>
    172169        </object>
    173170
    174171        <!-- Middle panel: Filters, game list, chat box. -->
    175172        <object name="middlePanel" size="20%+5 5% 100%-255 97.2%">