Ticket #3234: wonderOptions_v2.patch
File wonderOptions_v2.patch, 22.0 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 : undefined); 7 7 const g_MapTypes = prepareForDropdown(g_Settings ? g_Settings.MapTypes : undefined); 8 8 const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined); 9 9 const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined); 10 10 const g_VictoryConditions = prepareForDropdown(g_Settings ? g_Settings.VictoryConditions : undefined); 11 const g_WonderDurations = prepareForDropdown(g_Settings ? g_Settings.WonderDurations : undefined); 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() 235 236 initNumberOfPlayers(); 236 237 initGameSpeed(); 237 238 initPopulationCaps(); 238 239 initStartingResources(); 239 240 initCeasefire(); 241 initWonderDurations(); 240 242 initVictoryConditions(); 241 243 initMapSizes(); 242 244 initRadioButtons(); 243 245 } 244 246 else … … function initMapFilters() 294 296 function resizeMoreOptionsWindow() 295 297 { 296 298 // For singleplayer reduce the size of more options dialog by three options (cheats, rated game, observer late join = 90px) 297 299 if (!g_IsNetworked) 298 300 { 299 Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+1 60";300 Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 3 10 50%+70 336";301 Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+190"; 302 Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 340 50%+70 366"; 301 303 } 302 304 // For non-lobby multiplayergames reduce the size of the dialog by one option (rated game, 30px) 303 305 else if (!Engine.HasXmppClient()) 304 306 { 305 307 Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+220"; … … function initVictoryConditions() 394 396 updateGameAttributes(); 395 397 }; 396 398 victoryConditions.selected = g_VictoryConditions.Default; 397 399 } 398 400 401 function initWonderDurations() 402 { 403 let wonderConditions = Engine.GetGUIObjectByName("wonderDuration"); 404 wonderConditions.list = g_WonderDurations.Title; 405 wonderConditions.list_data = g_WonderDurations.Duration; 406 wonderConditions.selected = g_WonderDurations.Default; 407 wonderConditions.onSelectionChange = function() 408 { 409 if (this.selected != -1) 410 g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected]; 411 412 updateGameAttributes(); 413 }; 414 } 415 399 416 function initMapSizes() 400 417 { 401 418 let mapSize = Engine.GetGUIObjectByName("mapSize"); 402 419 mapSize.list = g_MapSizes.LongName; 403 420 mapSize.list_data = g_MapSizes.Tiles; … … function updateGUIObjects() 1232 1249 let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; 1233 1250 1234 1251 // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) 1235 1252 let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; 1236 1253 let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; 1254 let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default; 1237 1255 let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; 1238 1256 let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1239 1257 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1240 1258 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1241 1259 … … function updateGUIObjects() 1248 1266 Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1; 1249 1267 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1250 1268 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1251 1269 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1252 1270 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1271 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1253 1272 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1254 1273 } 1255 1274 else 1256 1275 { 1257 1276 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; … … function updateGUIObjects() 1262 1281 1263 1282 // Can be visible to both host and clients 1264 1283 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); 1265 1284 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1266 1285 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1286 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1267 1287 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1268 1288 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1269 1289 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; 1270 1290 Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; 1271 1291 … … function updateGUIObjects() 1275 1295 setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); 1276 1296 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1277 1297 setGUIBoolean("observerLateJoin", "observerLateJoinText", !!mapSettings.ObserverLateJoin); 1278 1298 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1279 1299 1300 Engine.GetGUIObjectByName("optionWonderDuration").hidden = 1301 g_GameAttributes.settings.GameType && 1302 g_GameAttributes.settings.GameType == "wonder"; 1303 1280 1304 Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; 1281 1305 1282 1306 Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; 1283 1307 Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; 1284 1308 … … function updateGUIObjects() 1289 1313 Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; 1290 1314 hideControl("numPlayersSelection", "numPlayersText", isRandom && g_IsController); 1291 1315 1292 1316 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1293 1317 hideControl("victoryCondition", "victoryConditionText", notScenario); 1318 hideControl("wonderDuration", "wonderDurationText", notScenario); 1294 1319 hideControl("populationCap", "populationCapText", notScenario); 1295 1320 hideControl("startingResources", "startingResourcesText", notScenario); 1296 1321 hideControl("ceasefire", "ceasefireText", notScenario); 1297 1322 hideControl("revealMap", "revealMapText", notScenario); 1298 1323 hideControl("exploreMap", "exploreMapText", notScenario); … … function updateGUIObjects() 1346 1371 pColorPickerHeading.hidden = !canChangeColors; 1347 1372 if (canChangeColors) 1348 1373 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1349 1374 } 1350 1375 1376 resizeMoreOptionsWindow(); 1377 1351 1378 g_IsInGuiUpdate = false; 1352 1379 1353 1380 // Game attributes include AI settings, so update the player list 1354 1381 updatePlayerList(); 1355 1382 … … function setMapDescription() 1364 1391 { 1365 1392 let numPlayers = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData.length : 0; 1366 1393 let mapName = g_GameAttributes.map || ""; 1367 1394 1368 1395 let victoryIdx = Math.max(0, g_VictoryConditions.Name.indexOf(g_GameAttributes.settings.GameType || "")); 1369 let victoryTitle = g_VictoryConditions.Title[victoryIdx]; 1396 let victoryTitle; 1397 1398 if (g_VictoryConditions.Name[victoryIdx] == "wonder") 1399 victoryTitle = sprintf( 1400 translatePluralWithContext( 1401 "victory condition", 1402 "Wonder (%(min)s minute)", 1403 "Wonder (%(min)s minutes)", 1404 g_GameAttributes.settings.WonderDuration 1405 ), 1406 { "min": g_GameAttributes.settings.WonderDuration } 1407 ); 1408 else 1409 victoryTitle = g_VictoryConditions.Title[victoryIdx]; 1410 1370 1411 if (victoryIdx != g_VictoryConditions.Default) 1371 1412 victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]"; 1372 1413 1373 1414 let mapDescription = g_GameAttributes.settings.Description ? translate(g_GameAttributes.settings.Description) : translate("Sorry, no description available."); 1374 1415 if (mapName == "random") -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
268 268 <!-- End Options --> 269 269 </object> 270 270 271 271 <!-- More Options --> 272 272 <object hidden="true" name="moreOptionsFade" type="image" z="60" sprite="ModernFade"/> 273 <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-1 9550%+200 50%+250" z="70" hidden="true">273 <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-120 50%+200 50%+250" z="70" hidden="true"> 274 274 <object style="ModernLabelText" type="text" size="50%-128 -18 50%+128 14"> 275 275 <translatableAttribute id="caption">More Options</translatableAttribute> 276 276 </object> 277 277 278 278 <object size="14 38 94% 66"> … … 323 323 <object name="ceasefire" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 324 324 <translatableAttribute id="tooltip">Set time where no attacks are possible.</translatableAttribute> 325 325 </object> 326 326 </object> 327 327 328 <object size="14 188 94% 216"> 328 <object name="optionWonderDuration" size="14 188 94% 216"> 329 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 330 <translatableAttribute id="caption">Wonder:</translatableAttribute> 331 </object> 332 <object name="wonderDurationText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> 333 <object name="wonderDuration" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 334 <translatableAttribute id="tooltip">Number of minuts that the player has to keep the wonder in order to win.</translatableAttribute> 335 </object> 336 </object> 337 338 <object size="14 218 94% 246"> 329 339 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 330 340 <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute> 331 341 </object> 332 342 <object name="revealMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 333 343 <object name="revealMap" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 334 344 <translatableAttribute id="tooltip" comment="Make sure to differentiate between the revealed map and explored map options!">Toggle revealed map (see everything).</translatableAttribute> 335 345 </object> 336 346 </object> 337 347 338 <object size="14 2 18 94% 246">348 <object size="14 248 94% 276"> 339 349 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 340 350 <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Explored Map:</translatableAttribute> 341 351 </object> 342 352 <object name="exploreMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 343 353 <object name="exploreMap" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 344 354 <translatableAttribute id="tooltip" comment="Make sure to differentiate between the revealed map and explored map options!">Toggle explored map (see initial map).</translatableAttribute> 345 355 </object> 346 356 </object> 347 357 348 <object size="14 2 48 94% 276">358 <object size="14 278 94% 306"> 349 359 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 350 360 <translatableAttribute id="caption">Disable Treasures:</translatableAttribute> 351 361 </object> 352 362 <object name="disableTreasuresText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 353 363 <object name="disableTreasures" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 354 364 <translatableAttribute id="tooltip">Disable all treasures on the map.</translatableAttribute> 355 365 </object> 356 366 </object> 357 367 358 <object size="14 278 94% 306">368 <object size="14 308 94% 336"> 359 369 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 360 370 <translatableAttribute id="caption">Teams Locked:</translatableAttribute> 361 371 </object> 362 372 <object name="lockTeamsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 363 373 <object name="lockTeams" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 364 374 <translatableAttribute id="tooltip">Toggle locked teams.</translatableAttribute> 365 375 </object> 366 376 </object> 367 377 368 <object name="optionCheats" size="14 3 08 94% 336" hidden="true">378 <object name="optionCheats" size="14 338 94% 366" hidden="true"> 369 379 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 370 380 <translatableAttribute id="caption">Cheats:</translatableAttribute> 371 381 </object> 372 382 <object name="enableCheatsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 373 383 <object name="enableCheats" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 374 384 <translatableAttribute id="tooltip">Toggle the usability of cheats.</translatableAttribute> 375 385 </object> 376 386 </object> 377 387 378 <object name="optionRating" size="14 3 38 94% 366" hidden="true">388 <object name="optionRating" size="14 368 94% 396" hidden="true"> 379 389 <object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText"> 380 390 <translatableAttribute id="caption">Rated Game:</translatableAttribute> 381 391 </object> 382 392 <object name="enableRatingText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 383 393 <object name="enableRating" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 384 394 <translatableAttribute id="tooltip">Toggle if this game will be rated for the leaderboard.</translatableAttribute> 385 395 </object> 386 396 </object> 387 397 388 <object name="optionObserverLateJoin" size="14 3 68 94% 396" hidden="true">398 <object name="optionObserverLateJoin" size="14 398 94% 426" hidden="true"> 389 399 <object size="0 0 40% 28" type="text" hidden="false" style="ModernRightLabelText"> 390 400 <translatableAttribute id="caption">Late Observer Joins:</translatableAttribute> 391 401 </object> 392 402 <object name="observerLateJoinText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 393 403 <object name="observerLateJoin" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> … … 398 408 <!-- Hide More Options Button --> 399 409 <object 400 410 name="hideMoreOptions" 401 411 type="button" 402 412 style="StoneButton" 403 size="50%-70 4 00 50%+70 426"413 size="50%-70 430 50%+70 456" 404 414 tooltip_style="onscreenToolTip" 405 415 hotkey="cancel" 406 416 > 407 417 <translatableAttribute id="caption">OK</translatableAttribute> 408 418 <translatableAttribute id="tooltip">Close more game options window</translatableAttribute> -
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() * 1000 * 60; // minutes to millisecounds 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.Init = function 17 17 this.gameType = "conquest"; 18 18 19 19 // Allied victory means allied players can win if victory conditions are met for each of them 20 20 // Would be false for a "last man standing" game (when diplomacy is fully implemented) 21 21 this.alliedVictory = true; 22 23 this.wonderDuration = 0; 22 24 }; 23 25 24 26 EndGameManager.prototype.GetGameType = function() 25 27 { 26 28 return this.gameType; … … 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='nonNegative Integer'/>" +4 "<element name='DurationMultiplier'>" + 5 "<data type='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, 5, 10, 15, 20, 25, 30], 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 if (settings.WonderDurations) 53 cmpEndGameManager.SetWonderDuration(settings.WonderDuration); 52 54 53 55 if (settings.Garrison) 54 56 { 55 57 for (let holder in settings.Garrison) 56 58 { -
binaries/data/mods/public/simulation/templates/template_structure_wonder.xml
84 84 </Vision> 85 85 <VisualActor> 86 86 <FoundationActor>structures/fndn_6x6.xml</FoundationActor> 87 87 </VisualActor> 88 88 <Wonder> 89 < TimeTillVictory>300</TimeTillVictory>89 <DurationMultiplier>1</DurationMultiplier> 90 90 </Wonder> 91 91 </Entity>