Ticket #3355: t3355_move_ceasefire_v1.2.patch

File t3355_move_ceasefire_v1.2.patch, 13.1 KB (added by elexis, 9 years ago)

Removes unused function translateCeasefire.

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

     
    66
    77/**
    88 * The maximum number of teams allowed.
    99 */
    1010const g_MaxTeams = 4;
    1111
    1212// The following settings will be loaded here:
    1313// AIDifficulties, Ceasefire, GameSpeeds, GameTypes, MapTypes,
    1414// MapSizes, PlayerDefaults, PopulationCapacity, StartingResources
     15
     16/**
     17 * An object containing all values given by setting name.
     18 * Used by lobby, gamesetup, session, summary screen and replay menu.
     19 */
     20const g_Settings = loadAvailableSettings();
     21
     22/**
     23 * Loads and translates all values of all settings which
     24 * can be configured by dropdowns in the gamesetup.
     25 *
     26 * @returns {Object|false}
     27 */
     28function loadAvailableSettings()
     29{
     30    const rootDir = "simulation/data/settings/";
     31    const settingNames = ["Ceasefire"];
     32
     33    var settings = {};
     34    for (let settingName of settingNames)
     35    {
     36        settings[settingName] = loadAvailableSettingsFile(settingName, rootDir + settingName + ".json");
     37        if (!settings[settingName])
     38            return false;
     39    }
     40
     41    return settings;
     42}
     43
     44/**
     45 * Returns all possible values for a given setting.
     46 * Each item of the returned array is an object.
     47 *
     48 * @param {string} settingName
     49 * @param {string} filename
     50 * @see simulation/data/settings/
     51 * @returns {Array|false}
     52 */
     53function loadAvailableSettingsFile(settingName, filename)
     54{
     55    var json = Engine.ReadJSONFile(filename);
     56
     57    if (!json || !json.Data)
     58    {
     59        error("Couldn't load " + settingName + " settings!");
     60        return false;
     61    }
     62
     63    if (json.TranslatedKeys)
     64        translateObjectKeys(json, json.TranslatedKeys);
     65
     66    return json.Data;
     67}
     68
     69/**
     70 * Creates an array with all values of that property of the given setting and
     71 * finds the index of the default value.
     72 *
     73 * This allows easy copying of setting values to dropdown lists.
     74 *
     75 * @param settingsName {string}
     76 * @returns {Object}
     77 */
     78function prepareForDropdown(settingsName)
     79{
     80    var settings = {};
     81    var settingValues = g_Settings[settingsName];
     82
     83    for (let index in settingValues)
     84    {
     85        for (let property in settingValues[index])
     86        {
     87            if (property == "Default")
     88                continue;
     89
     90            if (index == 0)
     91                settings[property] = [];
     92
     93            // Switch property and index
     94            settings[property][index] = settingValues[index][property];
     95        }
     96
     97        // Copy default value
     98        if (settingValues[index].Default)
     99            settings.Default = +index;
     100    }
     101
     102    return settings;
     103}
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    88// TODO: Move these somewhere like simulation\data\game_types.json, Atlas needs them too
    99// Translation: Type of victory condition.
    1010const POPULATION_CAP = ["50", "100", "150", "200", "250", "300", translate("Unlimited")];
    1111const POPULATION_CAP_DATA = [50, 100, 150, 200, 250, 300, 10000];
    1212const POPULATION_CAP_DEFAULTIDX = 5;
    1313// Translation: Amount of starting resources.
    1414const STARTING_RESOURCES = [translateWithContext("startingResources", "Very Low"), translateWithContext("startingResources", "Low"), translateWithContext("startingResources", "Medium"), translateWithContext("startingResources", "High"), translateWithContext("startingResources", "Very High"), translateWithContext("startingResources", "Deathmatch")];
    1515const STARTING_RESOURCES_DATA = [100, 300, 500, 1000, 3000, 50000];
    1616const STARTING_RESOURCES_DEFAULTIDX = 1;
    17 // Translation: Ceasefire.
    18 const CEASEFIRE = [translateWithContext("ceasefire", "No ceasefire"), translateWithContext("ceasefire", "5 minutes"), translateWithContext("ceasefire", "10 minutes"), translateWithContext("ceasefire", "15 minutes"), translateWithContext("ceasefire", "20 minutes"), translateWithContext("ceasefire", "30 minutes"), translateWithContext("ceasefire", "45 minutes"), translateWithContext("ceasefire", "60 minutes")];
    19 const CEASEFIRE_DATA = [0, 5, 10, 15, 20, 30, 45, 60];
    20 const CEASEFIRE_DEFAULTIDX = 0;
    2117
    2218////////////////////////////////////////////////////////////////////////////////////////////////
    2319
    2420// Is this is a networked game, or offline
    2521var g_IsNetworked;
    2622
    2723// Is this user in control of game settings (i.e. is a network server, or offline player)
    2824var g_IsController;
    2925
     
    7369
    7470// To prevent the display locking up while we load the map metadata,
    7571// we'll start with a 'loading' message and switch to the main screen in the
    7672// tick handler
    7773var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded
    7874
    7975// Filled by scripts in victory_conditions/
    8076var g_VictoryConditions = {};
    8177
     78// Contains setting values transformed for the dropdown list
     79var g_Ceasefire = {};
     80
    8281////////////////////////////////////////////////////////////////////////////////////////////////
    8382
    8483function init(attribs)
    8584{
     85    if (!g_Settings)
     86    {
     87        cancelSetup();
     88        return;
     89    }
     90
    8691    switch (attribs.type)
    8792    {
    8893    case "offline":
    8994        g_IsNetworked = false;
    9095        g_IsController = true;
    9196        break;
    9297    case "server":
    9398        g_IsNetworked = true;
    9499        g_IsController = true;
     
    109114    if (!Engine.HasXmppClient())
    110115        cancelButton.tooltip = translate("Return to the main menu.");
    111116    else
    112117        cancelButton.tooltip = translate("Return to the lobby.");
    113118}
    114119
    115120// Called after the map data is loaded and cached
    116121function initMain()
    117122{
     123
     124    if (!g_Settings)
     125        return;
     126
     127    // Transform setting arrays for usage in dropdown list
     128    g_Ceasefire = prepareForDropdown("Ceasefire");
     129
    118130    // Load AI list
    119131    g_AIs = Engine.GetAIs();
    120132
    121133    // Sort AIs by displayed name
    122134    g_AIs.sort(function (a, b) {
    123135        return a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0;
    124136    });
    125137
    126138    // Get default player data - remove gaia
     
    214226        startingResourcesL.selected = STARTING_RESOURCES_DEFAULTIDX;
    215227        startingResourcesL.onSelectionChange = function() {
    216228            if (this.selected != -1)
    217229                g_GameAttributes.settings.StartingResources = STARTING_RESOURCES_DATA[this.selected];
    218230
    219231            updateGameAttributes();
    220232        }
    221233
    222234        var ceasefireL = Engine.GetGUIObjectByName("ceasefire");
    223         ceasefireL.list = CEASEFIRE;
    224         ceasefireL.list_data = CEASEFIRE_DATA;
    225         ceasefireL.selected = CEASEFIRE_DEFAULTIDX;
     235        ceasefireL.list = g_Ceasefire.Title;
     236        ceasefireL.list_data = g_Ceasefire.Duration;
     237        ceasefireL.selected = g_Ceasefire.Default;
    226238        ceasefireL.onSelectionChange = function() {
    227239            if (this.selected != -1)
    228                 g_GameAttributes.settings.Ceasefire = CEASEFIRE_DATA[this.selected];
     240                g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected];
    229241
    230242            updateGameAttributes();
    231243        }
    232244
    233245        var victoryConditions = Engine.GetGUIObjectByName("victoryCondition");
    234246        var victories = getVictoryConditions();
    235247        victoryConditions.list = victories.text;
    236248        victoryConditions.list_data = victories.data;
    237249        victoryConditions.onSelectionChange = function() {
     
    414426        if (g_IsInGuiUpdate)
    415427            warn("initMain() called while in GUI update");
    416428
    417429        updateGameAttributes();
    418430    }
    419431}
    420432
    421433function handleNetMessage(message)
    422434{
     435    if (!g_Settings)
     436        return;
     437
    423438    log("Net message: " + uneval(message));
    424439
    425440    switch (message.type)
    426441    {
    427442    case "netstatus":
    428443        switch (message.status)
    429444        {
    430445        case "disconnected":
    431446            cancelSetup();
    432             if (Engine.HasXmppClient())
    433                 Engine.SwitchGuiPage("page_lobby.xml");
    434             else
    435                 Engine.SwitchGuiPage("page_pregame.xml");
    436447            reportDisconnect(message.reason);
    437448            break;
    438449
    439450        default:
    440451            error("Unrecognised netstatus type " + message.status);
    441452            break;
    442453        }
    443454        break;
    444455
     
    810821function cancelSetup()
    811822{
    812823    if (g_IsController)
    813824        saveGameAttributes();
    814825
    815826    Engine.DisconnectNetworkGame();
    816827
    817828    if (Engine.HasXmppClient())
    818829    {
    819         // Set player presence
    820830        Engine.LobbySetPlayerPresence("available");
    821831
    822         // Unregister the game
    823832        if (g_IsController)
    824833            Engine.SendUnregisterGame();
     834
     835        Engine.SwitchGuiPage("page_lobby.xml");
    825836    }
     837    else
     838        Engine.SwitchGuiPage("page_pregame.xml");
    826839}
    827840
    828841function onTick()
    829842{
    830843    // First tick happens before first render, so don't load yet
    831844    if (g_LoadingState == 0)
    832845    {
    833846        g_LoadingState++;
    834847    }
     
    12461259    observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin;
    12471260    observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No");
    12481261
    12491262    gameSpeedText.caption = g_GameSpeeds.names[speedIdx];
    12501263    gameSpeedBox.selected = speedIdx;
    12511264    populationCap.selected = (mapSettings.PopulationCap !== undefined && POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX);
    12521265    populationCapText.caption = POPULATION_CAP[populationCap.selected];
    12531266    startingResources.selected = (mapSettings.StartingResources !== undefined && STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX);
    12541267    startingResourcesText.caption = STARTING_RESOURCES[startingResources.selected];
    1255     ceasefire.selected = (mapSettings.Ceasefire !== undefined && CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) != -1 ? CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) : CEASEFIRE_DEFAULTIDX);
    1256     ceasefireText.caption = CEASEFIRE[ceasefire.selected];
     1268    ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
     1269    ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected];
    12571270
    12581271    // Update map preview
    12591272    Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:(0.78125,0.5859375)session/icons/mappreview/" + getMapPreview(mapName);
    12601273
    12611274    // Hide/show settings depending on whether we can change them or not
    12621275    var updateDisplay = function(guiObjChg, guiObjDsp, chg) {
    12631276        guiObjChg.hidden = !chg;
    12641277        guiObjDsp.hidden = chg;
    12651278    };
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    234234            <!-- Cancel Button -->
    235235            <object
    236236                name="cancelGame"
    237237                type="button"
    238238                style="StoneButton"
    239239                size="100%-308 100%-52 100%-168 100%-24"
    240240                tooltip_style="onscreenToolTip"
    241241            >
    242242                <translatableAttribute id="caption">Back</translatableAttribute>
    243                 <action on="Press">
    244                     <![CDATA[
    245                         cancelSetup();
    246                         if(!Engine.HasXmppClient())
    247                             Engine.SwitchGuiPage("page_pregame.xml");
    248                         else
    249                             Engine.SwitchGuiPage("page_lobby.xml");
    250                     ]]>
    251                 </action>
     243                <action on="Press">cancelSetup();</action>
    252244            </object>
    253245
    254246            <!-- Options -->
    255247            <object name="gameOptionsBox" size="100%-425 529 100%-25 525">
    256248                <!-- More Options Button -->
    257249                <object
    258250                    name="showMoreOptions"
    259251                    type="button"
    260252                    style="StoneButton"
  • binaries/data/mods/public/l10n/messages.json

     
    447447                    },
    448448                    "commentTags": [
    449449                        "Translation:"
    450450                    ]
    451451                }
    452452            },
    453453            {
    454454                "extractor": "json",
    455455                "filemasks": [
     456                    "simulation/data/settings/Ceasefire.json"
     457                ],
     458                "options": {
     459                    "keywords": ["Title"],
     460                    "context": "ceasefire"
     461                }
     462            },
     463            {
     464                "extractor": "json",
     465                "filemasks": [
    456466                    "simulation/data/game_speeds.json",
    457467                    "simulation/data/player_defaults.json"
    458468                ],
    459469                "options": {
    460470                    "keywords": [
    461471                        "Name"
    462472                    ]
    463473                }
    464474            },
  • binaries/data/mods/public/simulation/data/settings/Ceasefire.json

     
     1{
     2    "TranslatedKeys": { "Title": "ceasefire" },
     3    "Data":
     4    [
     5        {
     6            "Duration": 0,
     7            "Title": "No ceasefire",
     8            "Default": true
     9        },
     10        {
     11            "Duration": 1,
     12            "Title": "1 minute"
     13        },
     14        {
     15            "Duration": 2,
     16            "Title": "2 minutes"
     17        },
     18        {
     19            "Duration": 3,
     20            "Title": "3 minutes"
     21        },
     22        {
     23            "Duration": 4,
     24            "Title": "4 minutes"
     25        },
     26        {
     27            "Duration": 5,
     28            "Title": "5 minutes"
     29        },
     30        {
     31            "Duration": 10,
     32            "Title": "10 minutes"
     33        },
     34        {
     35            "Duration": 15,
     36            "Title": "15 minutes"
     37        },
     38        {
     39            "Duration": 20,
     40            "Title": "20 minutes"
     41        },
     42        {
     43            "Duration": 30,
     44            "Title": "30 minutes"
     45        },
     46        {
     47            "Duration": 45,
     48            "Title": "45 minutes"
     49        },
     50        {
     51            "Duration": 60,
     52            "Title": "60 minutes"
     53        }
     54    ]
     55}