Ticket #3234: wonderOptions_V3.patch
File wonderOptions_V3.patch, 20.8 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/common/settings.js
function loadSettingsValues() 30 30 { 31 31 var settings = { 32 32 "AIDescriptions": loadAIDescriptions(), 33 33 "AIDifficulties": loadAIDifficulties(), 34 34 "Ceasefire": loadCeasefire(), 35 "WonderDurations": loadWonderDuration(), 35 36 "GameSpeeds": loadSettingValuesFile("game_speeds.json"), 36 37 "MapTypes": loadMapTypes(), 37 38 "MapSizes": loadSettingValuesFile("map_sizes.json"), 38 39 "PlayerDefaults": loadPlayerDefaults(), 39 40 "PopulationCapacities": loadPopulationCapacities(), … … function loadAIDifficulties() 129 130 } 130 131 ]; 131 132 } 132 133 133 134 /** 135 * Loads available wonder-victory times 136 */ 137 function 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 /** 134 156 * Loads available ceasefire settings. 135 157 * 136 158 * @returns {Array|undefined} 137 159 */ 138 160 function loadCeasefire() -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
const g_GameSpeeds = prepareForDropdown( 6 6 const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); 7 7 const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); 8 8 const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); 9 9 const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); 10 10 const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions); 11 const g_WonderDurations = prepareForDropdown(g_Settings && g_Settings.WonderDurations); 11 12 12 13 /** 13 14 * All selectable playercolors except gaia. 14 15 */ 15 16 const g_PlayerColors = g_Settings ? g_Settings.PlayerDefaults.slice(1).map(pData => pData.Color) : undefined; … … function initGUIObjects() 246 247 initNumberOfPlayers(); 247 248 initGameSpeed(); 248 249 initPopulationCaps(); 249 250 initStartingResources(); 250 251 initCeasefire(); 252 initWonderDurations(); 251 253 initVictoryConditions(); 252 254 initMapSizes(); 253 255 initRadioButtons(); 254 256 } 255 257 else … … function initMapFilters() 298 300 mapFilters.selected = 0; 299 301 g_GameAttributes.mapFilter = "default"; 300 302 } 301 303 302 304 /** 303 * Sets the size of the more-options dialog.305 * Remove empty space in case of hidden options (like cheats, rating or wonder duration) 304 306 */ 305 307 function resizeMoreOptionsWindow() 306 308 { 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"; 312 } 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"; 309 const elementHeight = 30; 310 const elements = [ 311 "optionWonderDuration", 312 "optionRevealMap", 313 "optionExploreMapText", 314 "optionDisableTreasuresText", 315 "optionLockTeams", 316 "optionCheats", 317 "optionRating", 318 "hideMoreOptions" 319 ]; 320 321 let yPos = undefined; 322 for (let element of elements) 323 { 324 let guiOption = Engine.GetGUIObjectByName(element); 325 let gSize = guiOption.size; 326 yPos = yPos || gSize.top; 327 328 if (guiOption.hidden) 329 continue; 330 331 gSize.top = yPos; 332 gSize.bottom = yPos + elementHeight - 2; 333 guiOption.size = gSize; 334 335 yPos += elementHeight; 318 336 } 337 338 // Resize the vertically centered window containing the options 339 let moreOptions = Engine.GetGUIObjectByName("moreOptions"); 340 let mSize = moreOptions.size; 341 mSize.bottom = yPos + mSize.top + 20; 342 moreOptions.size = mSize; 319 343 } 320 344 321 345 function initNumberOfPlayers() 322 346 { 323 347 let playersArray = Array(g_MaxPlayers).fill(0).map((v, i) => i + 1); // 1, 2, ..., MaxPlayers … … function initVictoryConditions() 404 428 updateGameAttributes(); 405 429 }; 406 430 victoryConditions.selected = g_VictoryConditions.Default; 407 431 } 408 432 433 function initWonderDurations() 434 { 435 let wonderConditions = Engine.GetGUIObjectByName("wonderDuration"); 436 wonderConditions.list = g_WonderDurations.Title; 437 wonderConditions.list_data = g_WonderDurations.Duration; 438 wonderConditions.selected = g_WonderDurations.Default; 439 wonderConditions.onSelectionChange = function() 440 { 441 if (this.selected != -1) 442 g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected]; 443 444 updateGameAttributes(); 445 }; 446 } 447 409 448 function initMapSizes() 410 449 { 411 450 let mapSize = Engine.GetGUIObjectByName("mapSize"); 412 451 mapSize.list = g_MapSizes.LongName; 413 452 mapSize.list_data = g_MapSizes.Tiles; … … function updateGUIObjects() 1241 1280 let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; 1242 1281 1243 1282 // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) 1244 1283 let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; 1245 1284 let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; 1285 let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default; 1246 1286 let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; 1247 1287 let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1248 1288 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1249 1289 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1250 1290 … … function updateGUIObjects() 1257 1297 Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1; 1258 1298 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1259 1299 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1260 1300 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1261 1301 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1302 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1262 1303 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1263 1304 } 1264 1305 else 1265 1306 { 1266 1307 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; … … function updateGUIObjects() 1271 1312 1272 1313 // Can be visible to both host and clients 1273 1314 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); 1274 1315 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1275 1316 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1317 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1276 1318 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1277 1319 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1278 1320 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; 1279 1321 Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; 1280 1322 … … function updateGUIObjects() 1283 1325 setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap); 1284 1326 setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); 1285 1327 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1286 1328 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1287 1329 1330 Engine.GetGUIObjectByName("optionWonderDuration").hidden = 1331 g_GameAttributes.settings.GameType && 1332 g_GameAttributes.settings.GameType != "wonder"; 1333 1288 1334 Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; 1289 1335 1290 1336 Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; 1291 1337 Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; 1292 1338 … … function updateGUIObjects() 1297 1343 Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; 1298 1344 hideControl("numPlayersSelection", "numPlayersText", isRandom && g_IsController); 1299 1345 1300 1346 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1301 1347 hideControl("victoryCondition", "victoryConditionText", notScenario); 1348 hideControl("wonderDuration", "wonderDurationText", notScenario); 1302 1349 hideControl("populationCap", "populationCapText", notScenario); 1303 1350 hideControl("startingResources", "startingResourcesText", notScenario); 1304 1351 hideControl("ceasefire", "ceasefireText", notScenario); 1305 1352 hideControl("revealMap", "revealMapText", notScenario); 1306 1353 hideControl("exploreMap", "exploreMapText", notScenario); … … function updateGUIObjects() 1354 1401 pColorPickerHeading.hidden = !canChangeColors; 1355 1402 if (canChangeColors) 1356 1403 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1357 1404 } 1358 1405 1406 resizeMoreOptionsWindow(); 1407 1359 1408 g_IsInGuiUpdate = false; 1360 1409 1361 1410 // Game attributes include AI settings, so update the player list 1362 1411 updatePlayerList(); 1363 1412 … … function setMapDescription() 1372 1421 { 1373 1422 let numPlayers = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData.length : 0; 1374 1423 let mapName = g_GameAttributes.map || ""; 1375 1424 1376 1425 let victoryIdx = Math.max(0, g_VictoryConditions.Name.indexOf(g_GameAttributes.settings.GameType || "")); 1377 let victoryTitle = g_VictoryConditions.Title[victoryIdx]; 1426 let victoryTitle; 1427 1428 if (g_VictoryConditions.Name[victoryIdx] == "wonder") 1429 victoryTitle = sprintf( 1430 translatePluralWithContext( 1431 "victory condition", 1432 "Wonder (%(min)s minute)", 1433 "Wonder (%(min)s minutes)", 1434 g_GameAttributes.settings.WonderDuration 1435 ), 1436 { "min": g_GameAttributes.settings.WonderDuration } 1437 ); 1438 else 1439 victoryTitle = g_VictoryConditions.Title[victoryIdx]; 1440 1378 1441 if (victoryIdx != g_VictoryConditions.Default) 1379 1442 victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]"; 1380 1443 1381 1444 let mapDescription = g_GameAttributes.settings.Description ? translate(g_GameAttributes.settings.Description) : translate("Sorry, no description available."); 1382 1445 if (mapName == "random") -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
324 324 <object name="ceasefire" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 325 325 <translatableAttribute id="tooltip">Set time where no attacks are possible.</translatableAttribute> 326 326 </object> 327 327 </object> 328 328 329 <object size="14 188 94% 216"> 329 <object name="optionWonderDuration" size="14 188 94% 216"> 330 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 331 <translatableAttribute id="caption">Wonder Victory:</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"> 330 340 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 331 341 <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute> 332 342 </object> 333 343 <object name="revealMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 334 344 <object name="revealMap" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 335 345 <translatableAttribute id="tooltip" comment="Make sure to differentiate between the revealed map and explored map options!">Toggle revealed map (see everything).</translatableAttribute> 336 346 </object> 337 347 </object> 338 348 339 <object size="14 218 94% 246">349 <object name="optionExploreMapText" size="14 248 94% 276"> 340 350 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 341 351 <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Explored Map:</translatableAttribute> 342 352 </object> 343 353 <object name="exploreMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 344 354 <object name="exploreMap" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 345 355 <translatableAttribute id="tooltip" comment="Make sure to differentiate between the revealed map and explored map options!">Toggle explored map (see initial map).</translatableAttribute> 346 356 </object> 347 357 </object> 348 358 349 <object size="14 248 94% 276">359 <object name="optionDisableTreasuresText" size="14 278 94% 306"> 350 360 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 351 361 <translatableAttribute id="caption">Disable Treasures:</translatableAttribute> 352 362 </object> 353 363 <object name="disableTreasuresText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 354 364 <object name="disableTreasures" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 355 365 <translatableAttribute id="tooltip">Disable all treasures on the map.</translatableAttribute> 356 366 </object> 357 367 </object> 358 368 359 <object size="14 278 94% 306">369 <object name="optionLockTeams" size="14 308 94% 336"> 360 370 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 361 371 <translatableAttribute id="caption">Teams Locked:</translatableAttribute> 362 372 </object> 363 373 <object name="lockTeamsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 364 374 <object name="lockTeams" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 365 375 <translatableAttribute id="tooltip">Toggle locked teams.</translatableAttribute> 366 376 </object> 367 377 </object> 368 378 369 <object name="optionCheats" size="14 3 08 94% 336" hidden="true">379 <object name="optionCheats" size="14 338 94% 366" hidden="true"> 370 380 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 371 381 <translatableAttribute id="caption">Cheats:</translatableAttribute> 372 382 </object> 373 383 <object name="enableCheatsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 374 384 <object name="enableCheats" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 375 385 <translatableAttribute id="tooltip">Toggle the usability of cheats.</translatableAttribute> 376 386 </object> 377 387 </object> 378 388 379 <object name="optionRating" size="14 3 38 94% 366" hidden="true">389 <object name="optionRating" size="14 368 94% 396" hidden="true"> 380 390 <object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText"> 381 391 <translatableAttribute id="caption">Rated Game:</translatableAttribute> 382 392 </object> 383 393 <object name="enableRatingText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 384 394 <object name="enableRating" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> -
binaries/data/mods/public/maps/scripts/WonderVictory.js
Trigger.prototype.CheckWonderVictory = f 29 29 var players = [-1]; 30 30 for (var i = 1; i < numPlayers; i++) 31 31 if (i != data.to) 32 32 players.push(i); 33 33 34 var time = cmpWonder.Get TimeTillVictory()*1000;34 var time = cmpWonder.GetVictoryDuration(); 35 35 messages.otherMessage = cmpGuiInterface.AddTimeNotification({ 36 36 "message": markForTranslation("%(player)s will have won in %(time)s"), 37 37 "players": players, 38 38 "parameters": {"player": cmpPlayer.GetName()}, 39 39 "translateMessage": true, -
binaries/data/mods/public/simulation/components/EndGameManager.js
EndGameManager.prototype.Schema = 13 13 EndGameManager.prototype.Init = function() 14 14 { 15 15 // Game type, initialised from the map settings. 16 16 // One of: "conquest" (default) and "endless" 17 17 this.gameType = "conquest"; 18 18 19 this.wonderDuration = 10 * 60 * 1000; 20 19 21 // Allied victory means allied players can win if victory conditions are met for each of them 20 22 // Would be false for a "last man standing" game (when diplomacy is fully implemented) 21 23 this.alliedVictory = true; 22 24 }; 23 25 … … EndGameManager.prototype.SetGameType = f 35 37 EndGameManager.prototype.CheckGameType = function(type) 36 38 { 37 39 return this.gameType == type; 38 40 }; 39 41 42 EndGameManager.prototype.SetWonderDuration = function(wonderDuration) 43 { 44 this.wonderDuration = wonderDuration; 45 }; 46 47 EndGameManager.prototype.GetWonderDuration = function() 48 { 49 return this.wonderDuration; 50 }; 51 40 52 EndGameManager.prototype.MarkPlayerAsWon = function(playerID) 41 53 { 42 54 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 43 55 var numPlayers = cmpPlayerManager.GetNumPlayers(); 44 56 for (var i = 1; i < numPlayers; i++) -
binaries/data/mods/public/simulation/components/Wonder.js
1 1 function Wonder() {} 2 2 3 3 Wonder.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'/>" + 6 6 "</element>"; 7 7 8 8 Wonder.prototype.Init = function() 9 9 { 10 10 }; 11 11 12 12 Wonder.prototype.Serialize = null; 13 13 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 */ 17 Wonder.prototype.GetVictoryDuration = function() 15 18 { 16 return +this.template.TimeTillVictory; 19 var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 20 return cmpEndGameManager.GetWonderDuration() * this.template.DurationMultiplier; 17 21 }; 18 22 19 23 Engine.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
function LoadMapSettings(settings) 47 47 } 48 48 49 49 var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 50 50 if (settings.GameType) 51 51 cmpEndGameManager.SetGameType(settings.GameType); 52 warn(cmpEndGameManager.GetWonderDuration()); 53 if (settings.WonderDuration) 54 cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000); 52 55 53 56 if (settings.Garrison) 54 57 { 55 58 for (let holder in settings.Garrison) 56 59 {