Ticket #3234: wonderOptions_V2.5.patch

File wonderOptions_V2.5.patch, 15.7 KB (added by svott, 8 years ago)

relating to comment 22 and 23

  • gui/common/settings.js

     
    3232        "AIDescriptions": loadAIDescriptions(),
    3333        "AIDifficulties": loadAIDifficulties(),
    3434        "Ceasefire": loadCeasefire(),
     35        "WonderDurations": loadWonderDuration(),
    3536        "GameSpeeds": loadSettingValuesFile("game_speeds.json"),
    3637        "MapTypes": loadMapTypes(),
    3738        "MapSizes": loadSettingValuesFile("map_sizes.json"),
     
    131132}
    132133
    133134/**
     135 * Loads available wonder-victory times
     136 */
     137function loadWonderDuration()
     138{
     139    var jsonFile = "wonder_times.json";
     140    var json = Engine.ReadJSONFile(g_SettingsDirectory + jsonFile);
     141
     142    if (!json || json.Default === undefined || !json.Times || !Array.isArray(json.Times))
     143    {
     144        error("Could not load " + jsonFile);
     145        return undefined;
     146    }
     147
     148    return json.Times.map(duration => ({
     149        "Duration": duration,
     150        "Default": duration == json.Default,
     151        "Title": sprintf(translatePluralWithContext("wonder victory", "%(min)s minute", "%(min)s minutes", duration), { "min": duration })
     152    }));
     153}
     154
     155/**
    134156 * Loads available ceasefire settings.
    135157 *
    136158 * @returns {Array|undefined}
  • gui/gamesetup/gamesetup.js

     
    88const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
    99const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
    1010const g_VictoryConditions = prepareForDropdown(g_Settings ? g_Settings.VictoryConditions : undefined);
     11const g_WonderDurations = prepareForDropdown(g_Settings ? g_Settings.WonderDurations : undefined);
    1112
    1213/**
    1314 * All selectable playercolors except gaia.
     
    140141 */
    141142const g_RandomCiv = '[color="' + g_ColorRandom + '"]' + translateWithContext("civilization", "Random") + '[/color]';
    142143
     144/**
     145 * Button height in the option dialog
     146 */
     147const g_optionButtonHeight = 30;
     148
    143149// Is this is a networked game, or offline
    144150var g_IsNetworked;
    145151
     
    248254        initPopulationCaps();
    249255        initStartingResources();
    250256        initCeasefire();
     257        initWonderDurations();
    251258        initVictoryConditions();
    252259        initMapSizes();
    253260        initRadioButtons();
     
    303310 * Sets the size of the more-options dialog.
    304311 */
    305312function resizeMoreOptionsWindow()
    306 {
    307     // For singleplayer reduce the size of more options dialog by two options (cheats, rated game = 60px)
    308     if (!g_IsNetworked)
    309     {
    310         Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+160";
    311         Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 310 50%+70 336";
     313{   
     314    let wonderDurationHidden = Engine.GetGUIObjectByName("optionWonderDuration").hidden;
     315
     316    function resizeOptionEntry(name, yPos, offsetIdx) {
     317        let y1 = yPos + g_optionButtonHeight * offsetIdx - (wonderDurationHidden ? g_optionButtonHeight : 0);
     318        let y2 = y1 + g_optionButtonHeight - 2;
     319        Engine.GetGUIObjectByName(name).size = "14 " + y1 + " 94% " + y2;
    312320    }
    313     // For non-lobby multiplayergames reduce the size of the dialog by one option (rated game, 30px)
    314     else if (!Engine.HasXmppClient())
    315     {
    316         Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+190";
    317         Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 340 50%+70 366";
    318     }
     321   
     322    let yPos = 218
     323    resizeOptionEntry("optionRevealMap", yPos, 0);
     324    resizeOptionEntry("optionExploreMapText", yPos, 1);
     325    resizeOptionEntry("optionDisableTreasuresText", yPos, 2);
     326    resizeOptionEntry("optionLockTeams", yPos, 3);
     327    resizeOptionEntry("optionCheats", yPos, 4);
     328    resizeOptionEntry("optionRating", yPos, 5);
     329
     330    // Reduce the size of the dialog by up to three options (wonderduration, cheats and rated game)
     331    let reductionOffset = (wonderDurationHidden + !g_IsNetworked + !Engine.HasXmppClient()) * g_optionButtonHeight;
     332
     333    // resize option button
     334    Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 " + (400-reductionOffset) + " 50%+70 " + (426-reductionOffset);
     335    // resize option dialog
     336    Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-" + (195) + " 50%+200 50%+" + (250-reductionOffset);
    319337}
    320338
     339
     340
    321341function initNumberOfPlayers()
    322342{
    323343    let playersArray = Array(g_MaxPlayers).fill(0).map((v, i) => i + 1); // 1, 2, ..., MaxPlayers
     
    406426    victoryConditions.selected = g_VictoryConditions.Default;
    407427}
    408428
     429function initWonderDurations()
     430{
     431    let wonderConditions = Engine.GetGUIObjectByName("wonderDuration");
     432    wonderConditions.list = g_WonderDurations.Title;
     433    wonderConditions.list_data = g_WonderDurations.Duration;
     434    wonderConditions.selected = g_WonderDurations.Default;
     435    wonderConditions.onSelectionChange = function()
     436    {
     437        if (this.selected != -1)
     438            g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected];
     439
     440        updateGameAttributes();
     441    };
     442}
     443
    409444function initMapSizes()
    410445{
    411446    let mapSize = Engine.GetGUIObjectByName("mapSize");
     
    12431278    // These dropdowns might set the default (as they ignore g_IsInGuiUpdate)
    12441279    let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default;
    12451280    let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default;
     1281    let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default;
    12461282    let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default;
    12471283    let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    12481284    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
     
    12591295        Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    12601296        Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    12611297        Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     1298        Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
    12621299        Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
    12631300    }
    12641301    else
     
    12731310    Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
    12741311    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    12751312    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
     1313    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
    12761314    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    12771315    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    12781316    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
     
    12851323    setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
    12861324    setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
    12871325
     1326    Engine.GetGUIObjectByName("optionWonderDuration").hidden =
     1327        g_GameAttributes.settings.GameType &&
     1328        g_GameAttributes.settings.GameType != "wonder";
     1329
    12881330    Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled;
    12891331
    12901332    Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled;
     
    12991341
    13001342    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
    13011343    hideControl("victoryCondition", "victoryConditionText", notScenario);
     1344    hideControl("wonderDuration", "wonderDurationText", notScenario);
    13021345    hideControl("populationCap", "populationCapText", notScenario);
    13031346    hideControl("startingResources", "startingResourcesText", notScenario);
    13041347    hideControl("ceasefire", "ceasefireText", notScenario);
     
    13561399            pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
    13571400    }
    13581401
     1402    resizeMoreOptionsWindow();
     1403
    13591404    g_IsInGuiUpdate = false;
    13601405
    13611406    // Game attributes include AI settings, so update the player list
     
    13741419    let mapName = g_GameAttributes.map || "";
    13751420
    13761421    let victoryIdx = Math.max(0, g_VictoryConditions.Name.indexOf(g_GameAttributes.settings.GameType || ""));
    1377     let victoryTitle = g_VictoryConditions.Title[victoryIdx];
     1422    let victoryTitle;
     1423
     1424    if (g_VictoryConditions.Name[victoryIdx] == "wonder")
     1425        victoryTitle = sprintf(
     1426                translatePluralWithContext(
     1427                    "victory condition",
     1428                    "Wonder (%(min)s minute)",
     1429                    "Wonder (%(min)s minutes)",
     1430                    g_GameAttributes.settings.WonderDuration
     1431                ),
     1432                { "min": g_GameAttributes.settings.WonderDuration }
     1433        );
     1434    else
     1435        victoryTitle = g_VictoryConditions.Title[victoryIdx];
     1436
    13781437    if (victoryIdx != g_VictoryConditions.Default)
    13791438        victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]";
    13801439
  • gui/gamesetup/gamesetup.xml

     
    271271
    272272            <!-- More Options -->
    273273            <object hidden="true" name="moreOptionsFade" type="image" z="60" sprite="ModernFade"/>
    274             <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-195 50%+200 50%+220" z="70" hidden="true">
     274            <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-120 50%+200 50%+220" z="70" hidden="true">
    275275                <object style="ModernLabelText" type="text" size="50%-128 -18 50%+128 14">
    276276                    <translatableAttribute id="caption">More Options</translatableAttribute>
    277277                </object>
     
    326326                    </object>
    327327                </object>
    328328
    329                 <object size="14 188 94% 216">
     329                <object name="optionWonderDuration" size="14 188 94% 216">
    330330                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     331                        <translatableAttribute id="caption">Wonder:</translatableAttribute>
     332                    </object>
     333                    <object name="wonderDurationText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     334                    <object name="wonderDuration" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     335                        <translatableAttribute id="tooltip">Number of minutes that the player has to keep the wonder in order to win.</translatableAttribute>
     336                    </object>
     337                </object>
     338
     339                <object name="optionRevealMap" size="14 218 94% 246">
     340                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    331341                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute>
    332342                    </object>
    333343                    <object name="revealMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
     
    336346                    </object>
    337347                </object>
    338348
    339                 <object size="14 218 94% 246">
     349                <object name="optionExploreMapText" size="14 248 94% 276">
    340350                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    341351                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Explored Map:</translatableAttribute>
    342352                    </object>
     
    346356                    </object>
    347357                </object>
    348358
    349                 <object size="14 248 94% 276">
     359                <object name="optionDisableTreasuresText" size="14 278 94% 306">
    350360                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    351361                        <translatableAttribute id="caption">Disable Treasures:</translatableAttribute>
    352362                    </object>
     
    356366                    </object>
    357367                </object>
    358368
    359                 <object size="14 278 94% 306">
     369                <object name="optionLockTeams" size="14 308 94% 336">
    360370                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    361371                        <translatableAttribute id="caption">Teams Locked:</translatableAttribute>
    362372                    </object>
     
    366376                    </object>
    367377                </object>
    368378
    369                 <object name="optionCheats" size="14 308 94% 336" hidden="true">
     379                <object name="optionCheats" size="14 338 94% 366" hidden="true">
    370380                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    371381                        <translatableAttribute id="caption">Cheats:</translatableAttribute>
    372382                    </object>
     
    376386                    </object>
    377387                </object>
    378388
    379                 <object name="optionRating" size="14 338 94% 366" hidden="true">
     389                <object name="optionRating" size="14 368 94% 396" hidden="true">
    380390                    <object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText">
    381391                        <translatableAttribute id="caption">Rated Game:</translatableAttribute>
    382392                    </object>
  • maps/scripts/WonderVictory.js

     
    3131        if (i != data.to)
    3232            players.push(i);
    3333
    34     var time = cmpWonder.GetTimeTillVictory()*1000;
     34    var time = cmpWonder.GetVictoryDuration();
    3535    messages.otherMessage = cmpGuiInterface.AddTimeNotification({
    3636        "message": markForTranslation("%(player)s will have won in %(time)s"),
    3737        "players": players,
  • simulation/components/EndGameManager.js

     
    1919    // Allied victory means allied players can win if victory conditions are met for each of them
    2020    // Would be false for a "last man standing" game (when diplomacy is fully implemented)
    2121    this.alliedVictory = true;
     22
     23    this.wonderDuration = 5;
    2224};
    2325
    2426EndGameManager.prototype.GetGameType = function()
     
    3739    return this.gameType == type;
    3840};
    3941
     42EndGameManager.prototype.SetWonderDuration = function(wonderDuration)
     43{
     44    this.wonderDuration = wonderDuration;
     45};
     46
     47EndGameManager.prototype.GetWonderDuration = function()
     48{
     49    return this.wonderDuration;
     50};
     51
    4052EndGameManager.prototype.MarkPlayerAsWon = function(playerID)
    4153{
    4254    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
  • simulation/components/Wonder.js

     
    11function Wonder() {}
    22
    33Wonder.prototype.Schema =
    4     "<element name='TimeTillVictory'>" +
    5         "<data type='nonNegativeInteger'/>" +
     4    "<element name='DurationMultiplier' a:help='A civ-specific time-bonus/handicap for the wonder-victory-condition.'>" +
     5        "<ref name='nonNegativeDecimal'/>" +
    66    "</element>";
    77
    88Wonder.prototype.Init = function()
     
    1111
    1212Wonder.prototype.Serialize = null;
    1313
    14 Wonder.prototype.GetTimeTillVictory = function()
     14/**
     15 * Returns the number of minutes that a player has to keep the wonder in order to win.
     16 */
     17Wonder.prototype.GetVictoryDuration = function()
    1518{
    16     return +this.template.TimeTillVictory;
     19    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
     20    return cmpEndGameManager.GetWonderDuration() * this.template.DurationMultiplier;
    1721};
    1822
    1923Engine.RegisterComponentType(IID_Wonder, "Wonder", Wonder);
  • simulation/helpers/Setup.js

     
    4949    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
    5050    if (settings.GameType)
    5151        cmpEndGameManager.SetGameType(settings.GameType);
     52    if (settings.WonderDuration)
     53        cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000);
    5254
    5355    if (settings.Garrison)
    5456    {