Ticket #3355: t3355_move_ceasefire_v1.1.patch
File t3355_move_ceasefire_v1.1.patch, 13.4 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/common/settings.js
6 6 7 7 /** 8 8 * The maximum number of teams allowed. 9 9 */ 10 10 const g_MaxTeams = 4; 11 11 12 12 // The following settings will be loaded here: 13 13 // AIDifficulties, Ceasefire, GameSpeeds, GameTypes, MapTypes, 14 14 // MapSizes, PlayerDefaults, PopulationCapacity, StartingResources 15 16 /** 17 * An object containing all values given by setting name. 18 * Used by lobby, gamesetup, session, summary screen and replay menu. 19 */ 20 const g_Settings = loadAvailableSettings(); 21 22 /** 23 * Loads and translates all values of all settings which 24 * can be configured by dropdowns in the gamesetup. 25 * 26 * @returns {Object|false} 27 */ 28 function loadAvailableSettings() 29 { 30 const rootDir = "simulation/data/settings/"; 31 const settingNames = ["Ceasefire"]; 32 33 var settings = {}; 34 for (let settingName of settingNames) 35 { 36 settings[settingName] = loadAvailableSettingsFile(settingName, rootDir + settingName + ".json"); 37 if (!settings[settingName]) 38 return false; 39 } 40 41 return settings; 42 } 43 44 /** 45 * Returns all possible values for a given setting. 46 * Each item of the returned array is an object. 47 * 48 * @param {string} settingName 49 * @param {string} filename 50 * @see simulation/data/settings/ 51 * @returns {Array|false} 52 */ 53 function loadAvailableSettingsFile(settingName, filename) 54 { 55 var json = Engine.ReadJSONFile(filename); 56 57 if (!json || !json.Data) 58 { 59 error("Couldn't load " + settingName + " settings!"); 60 return false; 61 } 62 63 if (json.TranslatedKeys) 64 translateObjectKeys(json, json.TranslatedKeys); 65 66 return json.Data; 67 } 68 69 /** 70 * Creates an array with all values of that property of the given setting and 71 * finds the index of the default value. 72 * 73 * This allows easy copying of setting values to dropdown lists. 74 * 75 * @param settingsName {string} 76 * @returns {Object} 77 */ 78 function prepareForDropdown(settingsName) 79 { 80 var settings = {}; 81 var settingValues = g_Settings[settingsName]; 82 83 for (let index in settingValues) 84 { 85 for (let property in settingValues[index]) 86 { 87 if (property == "Default") 88 continue; 89 90 if (index == 0) 91 settings[property] = []; 92 93 // Switch property and index 94 settings[property][index] = settingValues[index][property]; 95 } 96 97 // Copy default value 98 if (settingValues[index].Default) 99 settings.Default = +index; 100 } 101 102 return settings; 103 } 104 105 /** 106 * Returns the translated title for the given ceasefire time. 107 * 108 * @param {Number} duration - in minutes 109 * @returns {string} 110 */ 111 function translateCeasefire(duration) 112 { 113 var ceasefire = g_Settings.Ceasefire.find(c => c.Duration == duration); 114 return ceasefire ? ceasefire.Title : translateWithContext("ceasefire", "Unknown"); 115 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
8 8 // TODO: Move these somewhere like simulation\data\game_types.json, Atlas needs them too 9 9 // Translation: Type of victory condition. 10 10 const POPULATION_CAP = ["50", "100", "150", "200", "250", "300", translate("Unlimited")]; 11 11 const POPULATION_CAP_DATA = [50, 100, 150, 200, 250, 300, 10000]; 12 12 const POPULATION_CAP_DEFAULTIDX = 5; 13 13 // Translation: Amount of starting resources. 14 14 const STARTING_RESOURCES = [translateWithContext("startingResources", "Very Low"), translateWithContext("startingResources", "Low"), translateWithContext("startingResources", "Medium"), translateWithContext("startingResources", "High"), translateWithContext("startingResources", "Very High"), translateWithContext("startingResources", "Deathmatch")]; 15 15 const STARTING_RESOURCES_DATA = [100, 300, 500, 1000, 3000, 50000]; 16 16 const STARTING_RESOURCES_DEFAULTIDX = 1; 17 // Translation: Ceasefire.18 const CEASEFIRE = [translateWithContext("ceasefire", "No ceasefire"), translateWithContext("ceasefire", "5 minutes"), translateWithContext("ceasefire", "10 minutes"), translateWithContext("ceasefire", "15 minutes"), translateWithContext("ceasefire", "20 minutes"), translateWithContext("ceasefire", "30 minutes"), translateWithContext("ceasefire", "45 minutes"), translateWithContext("ceasefire", "60 minutes")];19 const CEASEFIRE_DATA = [0, 5, 10, 15, 20, 30, 45, 60];20 const CEASEFIRE_DEFAULTIDX = 0;21 17 22 18 //////////////////////////////////////////////////////////////////////////////////////////////// 23 19 24 20 // Is this is a networked game, or offline 25 21 var g_IsNetworked; 26 22 27 23 // Is this user in control of game settings (i.e. is a network server, or offline player) 28 24 var g_IsController; 29 25 … … 73 69 74 70 // To prevent the display locking up while we load the map metadata, 75 71 // we'll start with a 'loading' message and switch to the main screen in the 76 72 // tick handler 77 73 var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded 78 74 79 75 // Filled by scripts in victory_conditions/ 80 76 var g_VictoryConditions = {}; 81 77 78 // Contains setting values transformed for the dropdown list 79 var g_Ceasefire = {}; 80 82 81 //////////////////////////////////////////////////////////////////////////////////////////////// 83 82 84 83 function init(attribs) 85 84 { 85 if (!g_Settings) 86 { 87 cancelSetup(); 88 return; 89 } 90 86 91 switch (attribs.type) 87 92 { 88 93 case "offline": 89 94 g_IsNetworked = false; 90 95 g_IsController = true; 91 96 break; 92 97 case "server": 93 98 g_IsNetworked = true; 94 99 g_IsController = true; … … 109 114 if (!Engine.HasXmppClient()) 110 115 cancelButton.tooltip = translate("Return to the main menu."); 111 116 else 112 117 cancelButton.tooltip = translate("Return to the lobby."); 113 118 } 114 119 115 120 // Called after the map data is loaded and cached 116 121 function initMain() 117 122 { 123 124 if (!g_Settings) 125 return; 126 127 // Transform setting arrays for usage in dropdown list 128 g_Ceasefire = prepareForDropdown("Ceasefire"); 129 118 130 // Load AI list 119 131 g_AIs = Engine.GetAIs(); 120 132 121 133 // Sort AIs by displayed name 122 134 g_AIs.sort(function (a, b) { 123 135 return a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0; 124 136 }); 125 137 126 138 // Get default player data - remove gaia … … 214 226 startingResourcesL.selected = STARTING_RESOURCES_DEFAULTIDX; 215 227 startingResourcesL.onSelectionChange = function() { 216 228 if (this.selected != -1) 217 229 g_GameAttributes.settings.StartingResources = STARTING_RESOURCES_DATA[this.selected]; 218 230 219 231 updateGameAttributes(); 220 232 } 221 233 222 234 var ceasefireL = Engine.GetGUIObjectByName("ceasefire"); 223 ceasefireL.list = CEASEFIRE;224 ceasefireL.list_data = CEASEFIRE_DATA;225 ceasefireL.selected = CEASEFIRE_DEFAULTIDX;235 ceasefireL.list = g_Ceasefire.Title; 236 ceasefireL.list_data = g_Ceasefire.Duration; 237 ceasefireL.selected = g_Ceasefire.Default; 226 238 ceasefireL.onSelectionChange = function() { 227 239 if (this.selected != -1) 228 g_GameAttributes.settings.Ceasefire = CEASEFIRE_DATA[this.selected];240 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected]; 229 241 230 242 updateGameAttributes(); 231 243 } 232 244 233 245 var victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); 234 246 var victories = getVictoryConditions(); 235 247 victoryConditions.list = victories.text; 236 248 victoryConditions.list_data = victories.data; 237 249 victoryConditions.onSelectionChange = function() { … … 414 426 if (g_IsInGuiUpdate) 415 427 warn("initMain() called while in GUI update"); 416 428 417 429 updateGameAttributes(); 418 430 } 419 431 } 420 432 421 433 function handleNetMessage(message) 422 434 { 435 if (!g_Settings) 436 return; 437 423 438 log("Net message: " + uneval(message)); 424 439 425 440 switch (message.type) 426 441 { 427 442 case "netstatus": 428 443 switch (message.status) 429 444 { 430 445 case "disconnected": 431 446 cancelSetup(); 432 if (Engine.HasXmppClient())433 Engine.SwitchGuiPage("page_lobby.xml");434 else435 Engine.SwitchGuiPage("page_pregame.xml");436 447 reportDisconnect(message.reason); 437 448 break; 438 449 439 450 default: 440 451 error("Unrecognised netstatus type " + message.status); 441 452 break; 442 453 } 443 454 break; 444 455 … … 810 821 function cancelSetup() 811 822 { 812 823 if (g_IsController) 813 824 saveGameAttributes(); 814 825 815 826 Engine.DisconnectNetworkGame(); 816 827 817 828 if (Engine.HasXmppClient()) 818 829 { 819 // Set player presence820 830 Engine.LobbySetPlayerPresence("available"); 821 831 822 // Unregister the game823 832 if (g_IsController) 824 833 Engine.SendUnregisterGame(); 834 835 Engine.SwitchGuiPage("page_lobby.xml"); 825 836 } 837 else 838 Engine.SwitchGuiPage("page_pregame.xml"); 826 839 } 827 840 828 841 function onTick() 829 842 { 830 843 // First tick happens before first render, so don't load yet 831 844 if (g_LoadingState == 0) 832 845 { 833 846 g_LoadingState++; 834 847 } … … 1246 1259 observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin; 1247 1260 observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No"); 1248 1261 1249 1262 gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; 1250 1263 gameSpeedBox.selected = speedIdx; 1251 1264 populationCap.selected = (mapSettings.PopulationCap !== undefined && POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX); 1252 1265 populationCapText.caption = POPULATION_CAP[populationCap.selected]; 1253 1266 startingResources.selected = (mapSettings.StartingResources !== undefined && STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX); 1254 1267 startingResourcesText.caption = STARTING_RESOURCES[startingResources.selected]; 1255 ceasefire.selected = (mapSettings.Ceasefire !== undefined && CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) != -1 ? CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) : CEASEFIRE_DEFAULTIDX);1256 ceasefireText.caption = CEASEFIRE[ceasefire.selected];1268 ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1269 ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected]; 1257 1270 1258 1271 // Update map preview 1259 1272 Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:(0.78125,0.5859375)session/icons/mappreview/" + getMapPreview(mapName); 1260 1273 1261 1274 // Hide/show settings depending on whether we can change them or not 1262 1275 var updateDisplay = function(guiObjChg, guiObjDsp, chg) { 1263 1276 guiObjChg.hidden = !chg; 1264 1277 guiObjDsp.hidden = chg; 1265 1278 }; -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
234 234 <!-- Cancel Button --> 235 235 <object 236 236 name="cancelGame" 237 237 type="button" 238 238 style="StoneButton" 239 239 size="100%-308 100%-52 100%-168 100%-24" 240 240 tooltip_style="onscreenToolTip" 241 241 > 242 242 <translatableAttribute id="caption">Back</translatableAttribute> 243 <action on="Press"> 244 <![CDATA[ 245 cancelSetup(); 246 if(!Engine.HasXmppClient()) 247 Engine.SwitchGuiPage("page_pregame.xml"); 248 else 249 Engine.SwitchGuiPage("page_lobby.xml"); 250 ]]> 251 </action> 243 <action on="Press">cancelSetup();</action> 252 244 </object> 253 245 254 246 <!-- Options --> 255 247 <object name="gameOptionsBox" size="100%-425 529 100%-25 525"> 256 248 <!-- More Options Button --> 257 249 <object 258 250 name="showMoreOptions" 259 251 type="button" 260 252 style="StoneButton" -
binaries/data/mods/public/l10n/messages.json
447 447 }, 448 448 "commentTags": [ 449 449 "Translation:" 450 450 ] 451 451 } 452 452 }, 453 453 { 454 454 "extractor": "json", 455 455 "filemasks": [ 456 "simulation/data/settings/Ceasefire.json" 457 ], 458 "options": { 459 "keywords": ["Title"], 460 "context": "ceasefire" 461 } 462 }, 463 { 464 "extractor": "json", 465 "filemasks": [ 456 466 "simulation/data/game_speeds.json", 457 467 "simulation/data/player_defaults.json" 458 468 ], 459 469 "options": { 460 470 "keywords": [ 461 471 "Name" 462 472 ] 463 473 } 464 474 }, -
binaries/data/mods/public/simulation/data/settings/Ceasefire.json
1 { 2 "TranslatedKeys": { "Title": "ceasefire" }, 3 "Data": 4 [ 5 { 6 "Duration": 0, 7 "Title": "No ceasefire", 8 "Default": true 9 }, 10 { 11 "Duration": 1, 12 "Title": "1 minute" 13 }, 14 { 15 "Duration": 2, 16 "Title": "2 minutes" 17 }, 18 { 19 "Duration": 3, 20 "Title": "3 minutes" 21 }, 22 { 23 "Duration": 4, 24 "Title": "4 minutes" 25 }, 26 { 27 "Duration": 5, 28 "Title": "5 minutes" 29 }, 30 { 31 "Duration": 10, 32 "Title": "10 minutes" 33 }, 34 { 35 "Duration": 15, 36 "Title": "15 minutes" 37 }, 38 { 39 "Duration": 20, 40 "Title": "20 minutes" 41 }, 42 { 43 "Duration": 30, 44 "Title": "30 minutes" 45 }, 46 { 47 "Duration": 45, 48 "Title": "45 minutes" 49 }, 50 { 51 "Duration": 60, 52 "Title": "60 minutes" 53 } 54 ] 55 }