Ticket #3234: wonderOptions_V3.2.patch

File wonderOptions_V3.2.patch, 17.8 KB (added by svott, 8 years ago)
  • binaries/data/mods/public/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}
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    88const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities);
    99const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources);
    1010const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions);
     11const g_WonderDurations = prepareForDropdown(g_Settings && g_Settings.WonderDurations);
    1112
    1213/**
    1314 * All selectable playercolors except gaia.
     
    248249        initPopulationCaps();
    249250        initStartingResources();
    250251        initCeasefire();
     252        initWonderDurations();
    251253        initVictoryConditions();
    252254        initMapSizes();
    253255        initRadioButtons();
     
    300302}
    301303
    302304/**
    303  * Sets the size of the more-options dialog.
     305 * Remove empty space in case of hidden options (like cheats, rating or wonder duration)
    304306 */
    305307function resizeMoreOptionsWindow()
    306308{
    307     // For singleplayer reduce the size of more options dialog by two options (cheats, rated game = 60px)
    308     if (!g_IsNetworked)
     309    const elementHeight = 30;
     310    const elements = [
     311        "optionGameSpeed",
     312        "optionVictoryCondition",
     313        "optionWonderDuration",
     314        "optionPopulationCap",
     315        "optionStartingResources",
     316        "optionCeasefireText",
     317        "optionRevealMap",
     318        "optionExploreMapText",
     319        "optionDisableTreasuresText",
     320        "optionLockTeams",
     321        "optionCheats",
     322        "optionRating",
     323        "hideMoreOptions"
     324    ];
     325
     326    let yPos = undefined;
     327    for (let element of elements)
    309328    {
    310         Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+160";
    311         Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 310 50%+70 336";
     329        let guiOption = Engine.GetGUIObjectByName(element);
     330        let gSize = guiOption.size;
     331        yPos = yPos || gSize.top;
     332
     333        if (guiOption.hidden)
     334            continue;
     335
     336        gSize.top = yPos;
     337        gSize.bottom = yPos + elementHeight - 2;
     338        guiOption.size = gSize;
     339
     340        yPos += elementHeight;
    312341    }
    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     }
     342
     343    // Resize the vertically centered window containing the options
     344    let moreOptions = Engine.GetGUIObjectByName("moreOptions");
     345    let mSize = moreOptions.size;
     346    mSize.bottom = yPos + mSize.top + 20;
     347    moreOptions.size = mSize;
    319348}
    320349
    321350function initNumberOfPlayers()
     
    406435    victoryConditions.selected = g_VictoryConditions.Default;
    407436}
    408437
     438function initWonderDurations()
     439{
     440    let wonderConditions = Engine.GetGUIObjectByName("wonderDuration");
     441    wonderConditions.list = g_WonderDurations.Title;
     442    wonderConditions.list_data = g_WonderDurations.Duration;
     443    wonderConditions.selected = g_WonderDurations.Default;
     444    wonderConditions.onSelectionChange = function()
     445    {
     446        if (this.selected != -1)
     447            g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected];
     448
     449        updateGameAttributes();
     450    };
     451}
     452
    409453function initMapSizes()
    410454{
    411455    let mapSize = Engine.GetGUIObjectByName("mapSize");
     
    12431287    // These dropdowns might set the default (as they ignore g_IsInGuiUpdate)
    12441288    let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default;
    12451289    let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default;
     1290    let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default;
    12461291    let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default;
    12471292    let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    12481293    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
     
    12591304        Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    12601305        Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    12611306        Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     1307        Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
    12621308        Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
    12631309    }
    12641310    else
     
    12731319    Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
    12741320    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    12751321    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
     1322    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
    12761323    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    12771324    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    12781325    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
     
    12851332    setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
    12861333    setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
    12871334
     1335    Engine.GetGUIObjectByName("optionWonderDuration").hidden =
     1336        g_GameAttributes.settings.GameType &&
     1337        g_GameAttributes.settings.GameType != "wonder";
     1338
    12881339    Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled;
    12891340
    12901341    Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled;
     
    12991350
    13001351    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
    13011352    hideControl("victoryCondition", "victoryConditionText", notScenario);
     1353    hideControl("wonderDuration", "wonderDurationText", notScenario);
    13021354    hideControl("populationCap", "populationCapText", notScenario);
    13031355    hideControl("startingResources", "startingResourcesText", notScenario);
    13041356    hideControl("ceasefire", "ceasefireText", notScenario);
     
    13561408            pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
    13571409    }
    13581410
     1411    resizeMoreOptionsWindow();
     1412
    13591413    g_IsInGuiUpdate = false;
    13601414
    13611415    // Game attributes include AI settings, so update the player list
     
    13741428    let mapName = g_GameAttributes.map || "";
    13751429
    13761430    let victoryIdx = Math.max(0, g_VictoryConditions.Name.indexOf(g_GameAttributes.settings.GameType || ""));
    1377     let victoryTitle = g_VictoryConditions.Title[victoryIdx];
     1431    let victoryTitle;
     1432
     1433    if (g_VictoryConditions.Name[victoryIdx] == "wonder")
     1434        victoryTitle = sprintf(
     1435            translatePluralWithContext(
     1436                "victory condition",
     1437                "Wonder (%(min)s minute)",
     1438                "Wonder (%(min)s minutes)",
     1439                g_GameAttributes.settings.WonderDuration
     1440            ),
     1441            { "min": g_GameAttributes.settings.WonderDuration }
     1442        );
     1443    else
     1444        victoryTitle = g_VictoryConditions.Title[victoryIdx];
     1445
    13781446    if (victoryIdx != g_VictoryConditions.Default)
    13791447        victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]";
    13801448
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    276276                    <translatableAttribute id="caption">More Options</translatableAttribute>
    277277                </object>
    278278
    279                 <object size="14 38 94% 66">
     279                <object name="optionGameSpeed" size="14 38 94% 66">
    280280                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    281281                        <translatableAttribute id="caption">Game Speed:</translatableAttribute>
    282282                    </object>
     
    286286                    </object>
    287287                </object>
    288288
    289                 <object size="14 68 94% 96">
     289                <object name="optionVictoryCondition" size="14 68 94% 96">
    290290                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    291291                        <translatableAttribute id="caption">Victory Condition:</translatableAttribute>
    292292                    </object>
     
    296296                    </object>
    297297                </object>
    298298
    299                 <object size="14 98 94% 126">
     299                <object name="optionWonderDuration" size="14 188 94% 216">
    300300                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     301                        <translatableAttribute id="caption">Wonder Victory:</translatableAttribute>
     302                    </object>
     303                    <object name="wonderDurationText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     304                    <object name="wonderDuration" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     305                        <translatableAttribute id="tooltip">Number of minutes that the player has to keep the wonder in order to win.</translatableAttribute>
     306                    </object>
     307                </object>
     308
     309                <object name="optionPopulationCap" size="14 98 94% 126">
     310                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    301311                        <translatableAttribute id="caption">Population Cap:</translatableAttribute>
    302312                    </object>
    303313                    <object name="populationCapText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     
    306316                    </object>
    307317                </object>
    308318
    309                 <object size="14 128 94% 156">
     319                <object name="optionStartingResources" size="14 128 94% 156">
    310320                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    311321                        <translatableAttribute id="caption">Starting Resources:</translatableAttribute>
    312322                    </object>
     
    316326                    </object>
    317327                </object>
    318328
    319                 <object size="14 158 94% 186">
     329                <object name="optionCeasefireText" size="14 158 94% 186">
    320330                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    321331                        <translatableAttribute id="caption">Ceasefire:</translatableAttribute>
    322332                    </object>
     
    326336                    </object>
    327337                </object>
    328338
    329                 <object size="14 188 94% 216">
     339                <object name="optionRevealMap" size="14 218 94% 246">
    330340                    <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>
     
    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>
  • binaries/data/mods/public/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,
  • binaries/data/mods/public/simulation/components/EndGameManager.js

     
    1515    // Game type, initialised from the map settings.
    1616    // One of: "conquest" (default) and "endless"
    1717    this.gameType = "conquest";
    18    
     18
     19    this.wonderDuration = 10 * 60 * 1000;
     20
    1921    // Allied victory means allied players can win if victory conditions are met for each of them
    2022    // Would be false for a "last man standing" game (when diplomacy is fully implemented)
    2123    this.alliedVictory = true;
     
    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);
  • binaries/data/mods/public/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);
  • binaries/data/mods/public/simulation/data/settings/wonder_times.json

     
     1{
     2    "Times": [1, 3, 5, 10, 15, 20, 25, 30, 45, 60],
     3    "Default": 15
     4}
  • binaries/data/mods/public/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    {
  • binaries/data/mods/public/simulation/templates/template_structure_wonder.xml

     
    9191    <FoundationActor>structures/fndn_6x6.xml</FoundationActor>
    9292  </VisualActor>
    9393  <Wonder>
    94     <TimeTillVictory>600</TimeTillVictory>
     94    <DurationMultiplier>1</DurationMultiplier>
    9595  </Wonder>
    9696</Entity>