Ticket #3355: t3355_move_ceasefire_v2.1.patch
File t3355_move_ceasefire_v2.1.patch, 11.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 const g_SettingsDirectory = "simulation/data/settings/"; 17 18 /** 19 * An object containing all values given by setting name. 20 * Used by lobby, gamesetup, session, summary screen and replay menu. 21 */ 22 const g_Settings = loadAvailableSettings(); 23 24 /** 25 * Loads and translates all values of all settings which 26 * can be configured by dropdowns in the gamesetup. 27 * 28 * @returns {Object|undefined} 29 */ 30 function loadAvailableSettings() 31 { 32 var settings = {}; 33 34 settings.Ceasefire = loadCeasefire(); 35 if (!settings.Ceasefire) 36 return undefined; 37 38 return settings; 39 } 40 41 /** 42 * Loads available ceasefire settings. 43 * 44 * @returns {Array|undefined} 45 */ 46 function loadCeasefire() 47 { 48 var json = Engine.ReadJSONFile(g_SettingsDirectory + "Ceasefire.json"); 49 50 if (!json || json.Default === undefined || !json.Times || !Array.isArray(json.Times)) 51 { 52 error("Could not load Ceasefire.json"); 53 return undefined; 54 } 55 56 return json.Times.map(timeout => { return { 57 "Duration": timeout, 58 "Default": timeout == json.Default, 59 "Title": timeout == 0 ? translateWithContext("ceasefire", "No ceasefire") : 60 sprintf(translatePluralWithContext("ceasefire", "%(minutes)s minute", "%(minutes)s minutes", timeout), { "minutes": timeout }) 61 }}); 62 } 63 64 /** 65 * Creates an array with all values of that property of the given setting and 66 * finds the index of the default value. 67 * 68 * This allows easy copying of setting values to dropdown lists. 69 * 70 * @param settingValues {Array} 71 * @returns {Object|undefined} 72 */ 73 function prepareForDropdown(settingValues) 74 { 75 if (!settingValues) 76 return undefined; 77 78 var settings = { "Default": 0 }; 79 for (let index in settingValues) 80 { 81 for (let property in settingValues[index]) 82 { 83 if (property == "Default") 84 continue; 85 86 if (index == 0) 87 settings[property] = []; 88 89 // Switch property and index 90 settings[property][index] = settingValues[index][property]; 91 } 92 93 // Copy default value 94 if (settingValues[index].Default) 95 settings.Default = +index; 96 } 97 return settings; 98 } -
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; 17 18 const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined); 21 19 22 20 //////////////////////////////////////////////////////////////////////////////////////////////// 23 21 24 22 // Is this is a networked game, or offline 25 23 var g_IsNetworked; 26 24 27 25 // Is this user in control of game settings (i.e. is a network server, or offline player) 28 26 var g_IsController; 29 27 … … 77 75 var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded 78 76 79 77 // Filled by scripts in victory_conditions/ 80 78 var g_VictoryConditions = {}; 81 79 82 80 //////////////////////////////////////////////////////////////////////////////////////////////// 83 81 84 82 function init(attribs) 85 83 { 84 if (!g_Settings) 85 { 86 cancelSetup(); 87 return; 88 } 89 86 90 switch (attribs.type) 87 91 { 88 92 case "offline": 89 93 g_IsNetworked = false; 90 94 g_IsController = true; 91 95 break; 92 96 case "server": 93 97 g_IsNetworked = true; 94 98 g_IsController = true; … … 214 218 startingResourcesL.selected = STARTING_RESOURCES_DEFAULTIDX; 215 219 startingResourcesL.onSelectionChange = function() { 216 220 if (this.selected != -1) 217 221 g_GameAttributes.settings.StartingResources = STARTING_RESOURCES_DATA[this.selected]; 218 222 219 223 updateGameAttributes(); 220 224 } 221 225 222 226 var ceasefireL = Engine.GetGUIObjectByName("ceasefire"); 223 ceasefireL.list = CEASEFIRE;224 ceasefireL.list_data = CEASEFIRE_DATA;225 ceasefireL.selected = CEASEFIRE_DEFAULTIDX;227 ceasefireL.list = g_Ceasefire.Title; 228 ceasefireL.list_data = g_Ceasefire.Duration; 229 ceasefireL.selected = g_Ceasefire.Default; 226 230 ceasefireL.onSelectionChange = function() { 227 231 if (this.selected != -1) 228 g_GameAttributes.settings.Ceasefire = CEASEFIRE_DATA[this.selected];232 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected]; 229 233 230 234 updateGameAttributes(); 231 235 } 232 236 233 237 var victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); 234 238 var victories = getVictoryConditions(); 235 239 victoryConditions.list = victories.text; 236 240 victoryConditions.list_data = victories.data; 237 241 victoryConditions.onSelectionChange = function() { … … 423 427 log("Net message: " + uneval(message)); 424 428 425 429 switch (message.type) 426 430 { 427 431 case "netstatus": 428 432 switch (message.status) 429 433 { 430 434 case "disconnected": 431 435 cancelSetup(); 432 if (Engine.HasXmppClient())433 Engine.SwitchGuiPage("page_lobby.xml");434 else435 Engine.SwitchGuiPage("page_pregame.xml");436 436 reportDisconnect(message.reason); 437 437 break; 438 438 439 439 default: 440 440 error("Unrecognised netstatus type " + message.status); 441 441 break; 442 442 } 443 443 break; 444 444 … … 810 810 function cancelSetup() 811 811 { 812 812 if (g_IsController) 813 813 saveGameAttributes(); 814 814 815 815 Engine.DisconnectNetworkGame(); 816 816 817 817 if (Engine.HasXmppClient()) 818 818 { 819 // Set player presence820 819 Engine.LobbySetPlayerPresence("available"); 821 820 822 // Unregister the game823 821 if (g_IsController) 824 822 Engine.SendUnregisterGame(); 823 824 Engine.SwitchGuiPage("page_lobby.xml"); 825 825 } 826 else 827 Engine.SwitchGuiPage("page_pregame.xml"); 826 828 } 827 829 828 830 function onTick() 829 831 { 832 if (!g_Settings) 833 return; 834 830 835 // First tick happens before first render, so don't load yet 831 836 if (g_LoadingState == 0) 832 837 { 833 838 g_LoadingState++; 834 839 } 835 840 else if (g_LoadingState == 1) 836 841 { 837 842 Engine.GetGUIObjectByName("loadingWindow").hidden = true; 838 843 Engine.GetGUIObjectByName("setupWindow").hidden = false; … … 1246 1251 observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin; 1247 1252 observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No"); 1248 1253 1249 1254 gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; 1250 1255 gameSpeedBox.selected = speedIdx; 1251 1256 populationCap.selected = (mapSettings.PopulationCap !== undefined && POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX); 1252 1257 populationCapText.caption = POPULATION_CAP[populationCap.selected]; 1253 1258 startingResources.selected = (mapSettings.StartingResources !== undefined && STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX); 1254 1259 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];1260 ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1261 ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected]; 1257 1262 1258 1263 // Update map preview 1259 1264 Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:(0.78125,0.5859375)session/icons/mappreview/" + getMapPreview(mapName); 1260 1265 1261 1266 // Hide/show settings depending on whether we can change them or not 1262 1267 var updateDisplay = function(guiObjChg, guiObjDsp, chg) { 1263 1268 guiObjChg.hidden = !chg; 1264 1269 guiObjDsp.hidden = chg; 1265 1270 }; -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 3 3 <objects> 4 4 5 5 <script file="gui/common/functions_civinfo.js"/> 6 6 <script file="gui/common/functions_global_object.js"/> 7 7 <script file="gui/common/functions_utility.js"/> 8 8 <script file="gui/common/network.js"/> 9 9 <script file="gui/common/settings.js"/> 10 11 <!-- After settings.js, which defines g_Settings --> 10 12 <script file="gui/gamesetup/gamesetup.js"/> 13 11 14 <!-- After gamesetup.js which defines g_VictoryConditions --> 12 15 <script directory="gui/gamesetup/victory_conditions/"/> 13 16 14 17 <!-- Add a translucent black background to fade out the menu page --> 15 18 <object type="image" style="ModernWindow" size="0 0 100% 100%"> 16 19 17 20 <object style="TitleText" type="text" size="50%-128 4 50%+128 36"> 18 21 <translatableAttribute id="caption">Match Setup</translatableAttribute> 19 22 </object> … … 234 237 <!-- Cancel Button --> 235 238 <object 236 239 name="cancelGame" 237 240 type="button" 238 241 style="StoneButton" 239 242 size="100%-308 100%-52 100%-168 100%-24" 240 243 tooltip_style="onscreenToolTip" 241 244 > 242 245 <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> 246 <action on="Press">cancelSetup();</action> 252 247 </object> 253 248 254 249 <!-- Options --> 255 250 <object name="gameOptionsBox" size="100%-425 529 100%-25 525"> 256 251 <!-- More Options Button --> 257 252 <object 258 253 name="showMoreOptions" 259 254 type="button" 260 255 style="StoneButton" -
binaries/data/mods/public/simulation/data/settings/Ceasefire.json
1 { 2 "Default": 0, 3 "Times": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60] 4 }