Ticket #3234: wonderOptions_V2.5.patch
File wonderOptions_V2.5.patch, 15.7 KB (added by , 8 years ago) |
---|
-
gui/common/settings.js
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"), … … 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} -
gui/gamesetup/gamesetup.js
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. … … 140 141 */ 141 142 const g_RandomCiv = '[color="' + g_ColorRandom + '"]' + translateWithContext("civilization", "Random") + '[/color]'; 142 143 144 /** 145 * Button height in the option dialog 146 */ 147 const g_optionButtonHeight = 30; 148 143 149 // Is this is a networked game, or offline 144 150 var g_IsNetworked; 145 151 … … 248 254 initPopulationCaps(); 249 255 initStartingResources(); 250 256 initCeasefire(); 257 initWonderDurations(); 251 258 initVictoryConditions(); 252 259 initMapSizes(); 253 260 initRadioButtons(); … … 303 310 * Sets the size of the more-options dialog. 304 311 */ 305 312 function 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; 312 320 } 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); 319 337 } 320 338 339 340 321 341 function initNumberOfPlayers() 322 342 { 323 343 let playersArray = Array(g_MaxPlayers).fill(0).map((v, i) => i + 1); // 1, 2, ..., MaxPlayers … … 406 426 victoryConditions.selected = g_VictoryConditions.Default; 407 427 } 408 428 429 function 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 409 444 function initMapSizes() 410 445 { 411 446 let mapSize = Engine.GetGUIObjectByName("mapSize"); … … 1243 1278 // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) 1244 1279 let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; 1245 1280 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; 1246 1282 let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; 1247 1283 let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1248 1284 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; … … 1259 1295 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1260 1296 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1261 1297 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1298 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1262 1299 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1263 1300 } 1264 1301 else … … 1273 1310 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); 1274 1311 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1275 1312 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1313 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1276 1314 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1277 1315 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1278 1316 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; … … 1285 1323 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1286 1324 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1287 1325 1326 Engine.GetGUIObjectByName("optionWonderDuration").hidden = 1327 g_GameAttributes.settings.GameType && 1328 g_GameAttributes.settings.GameType != "wonder"; 1329 1288 1330 Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; 1289 1331 1290 1332 Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; … … 1299 1341 1300 1342 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1301 1343 hideControl("victoryCondition", "victoryConditionText", notScenario); 1344 hideControl("wonderDuration", "wonderDurationText", notScenario); 1302 1345 hideControl("populationCap", "populationCapText", notScenario); 1303 1346 hideControl("startingResources", "startingResourcesText", notScenario); 1304 1347 hideControl("ceasefire", "ceasefireText", notScenario); … … 1356 1399 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1357 1400 } 1358 1401 1402 resizeMoreOptionsWindow(); 1403 1359 1404 g_IsInGuiUpdate = false; 1360 1405 1361 1406 // Game attributes include AI settings, so update the player list … … 1374 1419 let mapName = g_GameAttributes.map || ""; 1375 1420 1376 1421 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 1378 1437 if (victoryIdx != g_VictoryConditions.Default) 1379 1438 victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]"; 1380 1439 -
gui/gamesetup/gamesetup.xml
271 271 272 272 <!-- More Options --> 273 273 <object hidden="true" name="moreOptionsFade" type="image" z="60" sprite="ModernFade"/> 274 <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-1 9550%+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"> 275 275 <object style="ModernLabelText" type="text" size="50%-128 -18 50%+128 14"> 276 276 <translatableAttribute id="caption">More Options</translatableAttribute> 277 277 </object> … … 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 330 <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"> 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"/> … … 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> … … 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> … … 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> … … 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> … … 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> -
maps/scripts/WonderVictory.js
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, -
simulation/components/EndGameManager.js
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 = 5; 22 24 }; 23 25 24 26 EndGameManager.prototype.GetGameType = function() … … 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); -
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() … … 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); -
simulation/helpers/Setup.js
49 49 var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 50 50 if (settings.GameType) 51 51 cmpEndGameManager.SetGameType(settings.GameType); 52 if (settings.WonderDuration) 53 cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000); 52 54 53 55 if (settings.Garrison) 54 56 {