Ticket #3355: t3355_move_gamesetup_strings_v1.patch
File t3355_move_gamesetup_strings_v1.patch, 81.7 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/aiconfig/aiconfig.js
3 3 4 4 function init(settings) 5 5 { 6 6 g_PlayerSlot = settings.playerSlot; 7 7 8 translateObjectKeys(settings.ais, ["name", "description"]);9 8 g_AIs = [ 10 9 {id: "", data: {name: translateWithContext("ai", "None"), description: translate("AI will be disabled for this player.")}} 11 ].concat(settings. ais);10 ].concat(settings.AIs); 12 11 13 12 var aiSelection = Engine.GetGUIObjectByName("aiSelection"); 14 aiSelection.list = [ translate(ai.data.name) for each (ai in g_AIs) ];13 aiSelection.list = g_AIs.map(ai => translate(ai.data.name)); 15 14 16 15 var selected = 0; 17 16 for (var i = 0; i < g_AIs.length; ++i) 18 17 { 19 18 if (g_AIs[i].id == settings.id) … … 23 22 } 24 23 } 25 24 aiSelection.selected = selected; 26 25 27 26 var aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); 28 // Translation: AI difficulty level. 29 aiDiff.list = [translateWithContext("aiDiff", "Sandbox"), translateWithContext("aiDiff", "Very Easy"), translateWithContext("aiDiff", "Easy"), translateWithContext("aiDiff", "Medium"), translateWithContext("aiDiff", "Hard"), translateWithContext("aiDiff", "Very Hard")]; 27 aiDiff.list = settings.difficulties.Title; 30 28 aiDiff.selected = settings.difficulty; 31 29 } 32 30 33 31 function selectAI(idx) 34 32 { -
binaries/data/mods/public/gui/common/functions_utility.js
83 83 return text.substr(0, 255).replace(/\\/g, "\\\\").replace(/\[/g, "\\["); 84 84 } 85 85 86 86 // ==================================================================== 87 87 88 // Load default player data, for when it's not otherwise specified89 function initPlayerDefaults()90 {91 var data = Engine.ReadJSONFile("simulation/data/player_defaults.json");92 if (!data || !data.PlayerData)93 {94 error("Failed to parse player defaults in player_defaults.json (check for valid JSON data)");95 return [];96 }97 98 return data.PlayerData;99 }100 101 // ====================================================================102 103 // Load map size data104 function initMapSizes()105 {106 var sizes = {107 "shortNames":[],108 "names":[],109 "tiles": [],110 "default": 0111 };112 88 113 var data = Engine.ReadJSONFile("simulation/data/map_sizes.json"); 114 if (!data || !data.Sizes) 115 { 116 error("Failed to parse map sizes in map_sizes.json (check for valid JSON data)"); 117 return sizes; 118 } 119 120 translateObjectKeys(data, ["Name", "LongName"]); 121 for (var i = 0; i < data.Sizes.length; ++i) 122 { 123 sizes.shortNames.push(data.Sizes[i].Name); 124 sizes.names.push(data.Sizes[i].LongName); 125 sizes.tiles.push(data.Sizes[i].Tiles); 126 127 if (data.Sizes[i].Default) 128 sizes["default"] = i; 129 } 130 131 return sizes; 132 } 133 134 // ==================================================================== 135 136 // Load game speed data 137 function initGameSpeeds() 89 // Loads the translated description and filename of the preview image of the map (or a placeholder for random map). 90 function getMapDescriptionAndPreview(mapType, mapName) 138 91 { 139 var gameSpeeds = { 140 "names": [], 141 "speeds": [], 142 "default": 0 92 let mapData; 93 if (mapType == "random" && mapName == "random") 94 mapData = {"settings": {"Description": translate("A randomly selected map.")}}; 95 else if (mapType == "random" && Engine.FileExists(mapName + ".json")) 96 mapData = Engine.ReadJSONFile(mapName + ".json"); 97 else if (Engine.FileExists(mapName + ".xml")) 98 mapData = Engine.LoadMapSettings(mapName + ".xml"); 99 else 100 // Warn the player if we can't find the map. 101 warn(sprintf("Map '%(mapName)s' not found locally.", { mapName: mapName })); 102 103 return { 104 "description": translate(mapData && mapData.settings.Description ? mapData.settings.Description : "Sorry, no description available."), 105 "preview": mapData && mapData.settings.Preview ? mapData.settings.Preview : "nopreview.png" 143 106 }; 144 145 var data = Engine.ReadJSONFile("simulation/data/game_speeds.json");146 if (!data || !data.Speeds)147 {148 error("Failed to parse game speeds in game_speeds.json (check for valid JSON data)");149 return gameSpeeds;150 }151 152 translateObjectKeys(data, ["Name"]);153 for (var i = 0; i < data.Speeds.length; ++i)154 {155 gameSpeeds.names.push(data.Speeds[i].Name);156 gameSpeeds.speeds.push(data.Speeds[i].Speed);157 158 if (data.Speeds[i].Default)159 gameSpeeds["default"] = i;160 }161 162 return gameSpeeds;163 107 } 164 108 165 166 109 // ==================================================================== 167 110 168 111 // Convert integer color values to string (for use in GUI objects) 169 112 function rgbToGuiColor(color, alpha) 170 113 { -
binaries/data/mods/public/gui/common/settings.js
1 // Used by lobby, gamesetup, session, and replay GUI 2 const g_Settings = loadAvailableSettings(); 3 4 function loadAvailableSettings() 5 { 6 let settings = Engine.ReadJSONFile("simulation/data/settings/PlayerLimit.json"); 7 if (!settings) 8 return false; 9 10 const settingNames = ["AI_Difficulties", "Ceasefire", "GameSpeeds", "GameTypes", "MapTypes", 11 "MapSizes", "PlayerDefaults", "PopulationCapacity", "StartingResources"]; 12 13 for (let settingName of settingNames) 14 { 15 // Read json file 16 let file = "simulation/data/settings/" + settingName + ".json"; 17 let json = Engine.ReadJSONFile(file); 18 if (!json || !json[settingName]) 19 { 20 error("Couldn't load " + settingName + " settings!"); 21 return false; 22 } 23 24 // Translate setting values 25 let settingValues = json[settingName]; 26 if (json.TranslatedKeys) 27 translateObjectKeys(settingValues, json.TranslatedKeys); 28 29 settings[settingName] = settingValues; 30 } 31 return settings; 32 } 33 34 function initAIDescription() 35 { 36 let AIs = Engine.GetAIs(); 37 translateObjectKeys(AIs, ["name", "description"]); 38 // Sort AIs by displayed name 39 AIs.sort((a, b) => a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0); 40 return AIs; 41 } 42 43 // Shows a message box and calls a function if the setting files couldn't be parsed 44 function validSettings(callback) 45 { 46 if (!g_Settings) 47 messageBox(400, 200, translate("Can't load game settings!"), translate("ERROR!"), 0, [translate("OK")], [callback]); 48 return g_Settings; 49 } 50 51 // Transforms array to easily copy values to the dropdownlist. 52 function prepareForDropdown(settingsName) 53 { 54 let settings = {}; 55 let settingValues = g_Settings[settingsName]; 56 for (let index in settingValues) 57 { 58 for (let property in settingValues[index]) 59 { 60 if (property == "Default") 61 continue; 62 63 if (index == 0) 64 settings[property] = []; 65 66 // Switch property and index 67 settings[property][index] = settingValues[index][property]; 68 } 69 70 if (settingValues[index].Default) 71 settings.default = +index; 72 } 73 return settings; 74 } 75 76 //Returns the translation of the given AI difficulty. Requires g_Settings. 77 function translateAIDifficulty(index) 78 { 79 let difficuly = g_Settings.AI_Difficulties[index]; 80 return difficuly ? difficuly[0].Title : translateWithContext("AI difficulty", "Unknown"); 81 } 82 83 //Returns the translation of the given AI name (like "petra"). Requires g_AIs to be present. 84 function translateAIName(aiName) 85 { 86 let AI_description = g_AIs.filter(ai => ai.id == aiName); 87 return AI_description.length > 0 ? translate(AI_description[0].data.name) : translateWithContext("AI name", "Unknown"); 88 } 89 90 //Returns the translation of the given map type. Requires g_Settings. 91 function translateCeasefire(duration) 92 { 93 let ceasefire = g_Settings.Ceasefire.filter(c => c.Duration == duration); 94 return ceasefire.length > 0 ? ceasefire[0].Title : translateWithContext("ceasefire duration", "Unknown"); 95 } 96 // translateGameSpeeds not needed for now 97 98 //Returns the translation of the given map type. Requires g_Settings. 99 function translateGameType(gameType) 100 { 101 let type = g_Settings.GameTypes.filter(t => t.Name == gameType); 102 return type.length > 0 ? type[0].Title : translateWithContext("game type", "Unknown"); 103 } 104 105 //Returns the translation of the given map type. Requires g_Settings. 106 function translateMapType(mapType) 107 { 108 let type = g_Settings.MapTypes.filter(t => t.Name == mapType); 109 return type.length > 0 ? type[0].Title : translateWithContext("map type", "Unknown"); 110 } 111 112 // Returns translated map size for a given a numeric size. Requires g_Settings. 113 function translateMapSize(tiles) 114 { 115 let size = g_Settings.MapSizes.filter(s => s.Tiles == tiles); 116 return size.length > 0 ? size[0].Name : translateWithContext("map size", "Default"); 117 } 118 119 // Returns the translation for a given numeric value. Requires g_Settings. 120 function translatePopulationCapacity(population) 121 { 122 let popCap = g_Settings.PopulationCapacity.filter(p => p.Population == population); 123 return popCap.length > 0 ? popCap[0].Title : translateWithContext("population capacity", "Unknown"); 124 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
1 ////////////////////////////////////////////////////////////////////////////////////////////////2 1 // Constants 3 2 const DEFAULT_NETWORKED_MAP = "Acropolis 01"; 4 3 const DEFAULT_OFFLINE_MAP = "Acropolis 01"; 5 4 6 const VICTORY_DEFAULTIDX = 1; 7 8 // TODO: Move these somewhere like simulation\data\game_types.json, Atlas needs them too 9 // Translation: Type of victory condition. 10 const POPULATION_CAP = ["50", "100", "150", "200", "250", "300", translate("Unlimited")]; 11 const POPULATION_CAP_DATA = [50, 100, 150, 200, 250, 300, 10000]; 12 const POPULATION_CAP_DEFAULTIDX = 5; 13 // Translation: Amount of starting resources. 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 const STARTING_RESOURCES_DATA = [100, 300, 500, 1000, 3000, 50000]; 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 // Max number of players for any map 22 const MAX_PLAYERS = 8; 23 24 //////////////////////////////////////////////////////////////////////////////////////////////// 5 // Contains settings transformed for the dropdown lists 6 var g_PlayerDefaults = [], g_AIDiffs = {}, g_Ceasefire = {}, g_GameSpeeds = {}; 7 var g_GameTypes = {}, g_MapTypes = {}, g_MapSizes = {}; 8 var g_PopulationCapacity = {}, g_StartingResources = {}; 25 9 26 10 // Is this is a networked game, or offline 27 11 var g_IsNetworked; 28 12 29 13 // Is this user in control of game settings (i.e. is a network server, or offline player) … … 50 34 var g_GameStarted = false; 51 35 52 36 var g_PlayerAssignments = {}; 53 37 54 38 // Default game setup attributes 55 var g_DefaultPlayerData = [];56 39 var g_GameAttributes = { 57 40 settings: {} 58 41 }; 59 42 60 var g_GameSpeeds = {};61 var g_MapSizes = {};62 63 var g_AIs = [];64 65 43 var g_ChatMessages = []; 66 44 67 45 // Data caches 68 46 var g_MapData = {}; 69 47 var g_CivData = {}; … … 76 54 // To prevent the display locking up while we load the map metadata, 77 55 // we'll start with a 'loading' message and switch to the main screen in the 78 56 // tick handler 79 57 var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded 80 58 81 // Filled by scripts in victory_conditions/82 var g_VictoryConditions = {};83 84 59 //////////////////////////////////////////////////////////////////////////////////////////////// 85 60 86 61 function init(attribs) 87 62 { 88 63 switch (attribs.type) … … 115 90 } 116 91 117 92 // Called after the map data is loaded and cached 118 93 function initMain() 119 94 { 120 // Load AI list 121 g_AIs = Engine.GetAIs(); 122 123 // Sort AIs by displayed name 124 g_AIs.sort(function (a, b) { 125 return a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0; 126 }); 127 128 // Get default player data - remove gaia 129 g_DefaultPlayerData = initPlayerDefaults(); 130 g_DefaultPlayerData.shift(); 131 for (var i = 0; i < g_DefaultPlayerData.length; ++i) 132 g_DefaultPlayerData[i].Civ = "random"; 95 if (!validSettings(cancelAndReturn)) 96 return; 133 97 134 g_GameSpeeds = initGameSpeeds(); 135 g_MapSizes = initMapSizes(); 98 // Transform setting arrays for usage in dropdown lists 99 g_AIDiffs = prepareForDropdown("AI_Difficulties"); 100 g_Ceasefire = prepareForDropdown("Ceasefire"); 101 g_GameSpeeds = prepareForDropdown("GameSpeeds"); 102 g_GameTypes = prepareForDropdown("GameTypes"); 103 g_MapSizes = prepareForDropdown("MapSizes"); 104 g_MapTypes = prepareForDropdown("MapTypes"); 105 g_PopulationCapacity = prepareForDropdown("PopulationCapacity"); 106 g_StartingResources = prepareForDropdown("StartingResources"); 107 108 // Modify player defaults for later usage 109 g_PlayerDefaults = g_Settings.PlayerDefaults.map(player => { player.Civ = "random"; return player; }); 110 g_PlayerDefaults.shift() 136 111 137 112 // Init civs 138 113 initCivNameList(); 139 114 140 115 // Init map types 141 116 var mapTypes = Engine.GetGUIObjectByName("mapTypeSelection"); 142 mapTypes.list = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];143 mapTypes.list_data = ["skirmish","random","scenario"];117 mapTypes.list = g_MapTypes.Title; 118 mapTypes.list_data = g_MapTypes.Name; 144 119 145 120 // Setup map filters - will appear in order they are added 146 121 addFilter("default", translate("Default"), function(settings) { return settings && (settings.Keywords === undefined || !keywordTestOR(settings.Keywords, ["naval", "demo", "hidden"])); }); 147 122 addFilter("naval", translate("Naval Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["naval"]); }); 148 123 addFilter("demo", translate("Demo Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["demo"]); }); … … 165 140 g_GameAttributes.matchID = Engine.GetMatchID(); 166 141 167 142 initMapNameList(); 168 143 169 144 var numPlayersSelection = Engine.GetGUIObjectByName("numPlayersSelection"); 170 var players = []; 171 for (var i = 1; i <= MAX_PLAYERS; ++i) 172 players.push(i); 173 numPlayersSelection.list = players; 174 numPlayersSelection.list_data = players; 175 numPlayersSelection.selected = MAX_PLAYERS - 1; 145 let playersArray = Array(g_Settings.MaxPlayers).fill(0).map((value, index) => index + 1); 146 numPlayersSelection.list = playersArray; 147 numPlayersSelection.list_data = playersArray; 148 numPlayersSelection.selected = g_Settings.MaxPlayers - 1; 176 149 177 150 var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 178 151 gameSpeed.hidden = false; 179 152 Engine.GetGUIObjectByName("gameSpeedText").hidden = true; 180 gameSpeed.list = g_GameSpeeds. names;181 gameSpeed.list_data = g_GameSpeeds. speeds;153 gameSpeed.list = g_GameSpeeds.Title; 154 gameSpeed.list_data = g_GameSpeeds.Speed; 182 155 gameSpeed.onSelectionChange = function() { 183 156 if (this.selected != -1) 184 g_GameAttributes.gameSpeed = g_GameSpeeds. speeds[this.selected];157 g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected]; 185 158 186 159 updateGameAttributes(); 187 160 } 188 gameSpeed.selected = g_GameSpeeds ["default"];161 gameSpeed.selected = g_GameSpeeds.default; 189 162 190 163 var populationCaps = Engine.GetGUIObjectByName("populationCap"); 191 populationCaps.list = POPULATION_CAP;192 populationCaps.list_data = POPULATION_CAP_DATA;193 populationCaps.selected = POPULATION_CAP_DEFAULTIDX;164 populationCaps.list = g_PopulationCapacity.Title; 165 populationCaps.list_data = g_PopulationCapacity.Population; 166 populationCaps.selected = g_PopulationCapacity.default; 194 167 populationCaps.onSelectionChange = function() { 195 168 if (this.selected != -1) 196 g_GameAttributes.settings.PopulationCap = POPULATION_CAP_DATA[this.selected];169 g_GameAttributes.settings.PopulationCap = g_PopulationCapacity.Population[this.selected]; 197 170 198 171 updateGameAttributes(); 199 172 } 200 173 201 174 var startingResourcesL = Engine.GetGUIObjectByName("startingResources"); 202 startingResourcesL.list = STARTING_RESOURCES;203 startingResourcesL.list_data = STARTING_RESOURCES_DATA;204 startingResourcesL.selected = STARTING_RESOURCES_DEFAULTIDX;175 startingResourcesL.list = g_StartingResources.Title; 176 startingResourcesL.list_data = g_StartingResources.Resources; 177 startingResourcesL.selected = g_StartingResources.default; 205 178 startingResourcesL.onSelectionChange = function() { 206 179 if (this.selected != -1) 207 g_GameAttributes.settings.StartingResources = STARTING_RESOURCES_DATA[this.selected];180 g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[this.selected]; 208 181 209 182 updateGameAttributes(); 210 183 } 211 184 212 185 var ceasefireL = Engine.GetGUIObjectByName("ceasefire"); 213 ceasefireL.list = CEASEFIRE;214 ceasefireL.list_data = CEASEFIRE_DATA;215 ceasefireL.selected = CEASEFIRE_DEFAULTIDX;186 ceasefireL.list = g_Ceasefire.Title; 187 ceasefireL.list_data = g_Ceasefire.Duration; 188 ceasefireL.selected = g_Ceasefire.default; 216 189 ceasefireL.onSelectionChange = function() { 217 190 if (this.selected != -1) 218 g_GameAttributes.settings.Ceasefire = CEASEFIRE_DATA[this.selected];191 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected]; 219 192 220 193 updateGameAttributes(); 221 194 } 222 195 223 196 var victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); 224 var victories = getVictoryConditions(); 225 victoryConditions.list = victories.text; 226 victoryConditions.list_data = victories.data; 197 victoryConditions.list = g_GameTypes.Title; 198 victoryConditions.list_data = g_GameTypes.Name; 227 199 victoryConditions.onSelectionChange = function() { 228 200 if (this.selected != -1) 229 201 { 230 g_GameAttributes.settings.GameType = victories.data[this.selected];231 g_GameAttributes.settings.VictoryScripts = victories.scripts[this.selected];202 g_GameAttributes.settings.GameType = g_GameTypes.Name[this.selected]; 203 g_GameAttributes.settings.VictoryScripts = g_GameTypes.Scripts[this.selected]; 232 204 } 233 205 234 206 updateGameAttributes(); 235 207 }; 236 victoryConditions.selected = VICTORY_DEFAULTIDX;208 victoryConditions.selected = g_GameTypes.default; 237 209 238 210 var mapSize = Engine.GetGUIObjectByName("mapSize"); 239 mapSize.list = g_MapSizes. names;240 mapSize.list_data = g_MapSizes. tiles;211 mapSize.list = g_MapSizes.LongName; 212 mapSize.list_data = g_MapSizes.Tiles; 241 213 mapSize.onSelectionChange = function() { 242 214 if (this.selected != -1) 243 g_GameAttributes.settings.Size = g_MapSizes. tiles[this.selected];215 g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected]; 244 216 updateGameAttributes(); 245 217 }; 246 218 mapSize.selected = 0; 247 219 248 220 Engine.GetGUIObjectByName("revealMap").onPress = function() { … … 292 264 Engine.GetGUIObjectByName("gameSpeedText").hidden = false; 293 265 Engine.GetGUIObjectByName("gameSpeed").hidden = true; 294 266 295 267 // Disable player and game options controls 296 268 // TODO: Shouldn't players be able to choose their own assignment? 297 for ( var i = 0; i < MAX_PLAYERS; ++i)269 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 298 270 { 299 271 Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true; 300 272 Engine.GetGUIObjectByName("playerCiv["+i+"]").hidden = true; 301 273 Engine.GetGUIObjectByName("playerTeam["+i+"]").hidden = true; 302 274 } … … 339 311 } 340 312 } 341 313 342 314 // Settings for all possible player slots 343 315 var boxSpacing = 32; 344 for ( var i = 0; i < MAX_PLAYERS; ++i)316 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 345 317 { 346 318 // Space player boxes 347 319 var box = Engine.GetGUIObjectByName("playerBox["+i+"]"); 348 320 var boxSize = box.size; 349 321 var h = boxSize.bottom - boxSize.top; 350 322 boxSize.top = i * boxSpacing; 351 323 boxSize.bottom = i * boxSpacing + h; 352 324 box.size = boxSize; 353 325 354 326 // Populate team dropdowns 355 var team = Engine.GetGUIObjectByName("playerTeam["+i+"]"); 356 team.list = [translateWithContext("team", "None"), "1", "2", "3", "4"]; 357 team.list_data = [-1, 0, 1, 2, 3]; 327 let team = Engine.GetGUIObjectByName("playerTeam["+i+"]"); 328 let teamsArray = Array(g_Settings.MaxTeams).fill(0).map((v, i) => i + 1); // 1, 2, ... MaxTeams 329 team.list = [translateWithContext("team", "None")].concat(teamsArray); // "None", 1, 2, ..., maxTeams 330 team.list_data = [-1].concat(teamsArray.map(player => player - 1)); // -1, 0, ..., (maxTeams-1) 358 331 team.selected = 0; 359 332 360 333 let playerSlot = i; // declare for inner function use 361 334 team.onSelectionChange = function() { 362 335 if (this.selected != -1) … … 398 371 } 399 372 } 400 373 401 374 function handleNetMessage(message) 402 375 { 376 if (!g_Settings) 377 return; 378 403 379 log("Net message: "+uneval(message)); 404 380 405 381 switch (message.type) 406 382 { 407 383 case "netstatus": … … 571 547 // Add random civ to beginning of list 572 548 civListNames.unshift('[color="orange"]' + translateWithContext("civilization", "Random") + '[/color]'); 573 549 civListCodes.unshift("random"); 574 550 575 551 // Update the dropdowns 576 for ( var i = 0; i < MAX_PLAYERS; ++i)552 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 577 553 { 578 554 var civ = Engine.GetGUIObjectByName("playerCiv["+i+"]"); 579 555 civ.list = civListNames; 580 556 civ.list_data = civListCodes; 581 557 civ.selected = 0; … … 703 679 704 680 // Ensure that cheats are enabled in singleplayer 705 681 if (!g_IsNetworked) 706 682 mapSettings.CheatsEnabled = true; 707 683 708 var aiCodes = [ ai.id for each (ai in g_AIs) ];709 684 var civListCodes = [ civ.Code for each (civ in g_CivData) if (civ.SelectableInGameSetup !== false) ]; 710 685 civListCodes.push("random"); 711 686 712 687 var playerData = mapSettings.PlayerData; 713 688 … … 762 737 } 763 738 764 739 if (attrs.gameSpeed) 765 740 { 766 741 var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); 767 gameSpeedBox.selected = g_GameSpeeds. speeds.indexOf(attrs.gameSpeed);742 gameSpeedBox.selected = g_GameSpeeds.Speed.indexOf(attrs.gameSpeed); 768 743 } 769 744 770 745 if (!Engine.HasXmppClient()) 771 746 { 772 747 g_GameAttributes.settings.RatingEnabled = false; … … 787 762 Engine.WriteJSONFile(g_IsNetworked ? FILEPATH_MATCHSETTINGS_MP : FILEPATH_MATCHSETTINGS_SP, attributes); 788 763 } 789 764 //////////////////////////////////////////////////////////////////////////////////////////////// 790 765 // GUI event handlers 791 766 767 function cancelAndReturn() 768 { 769 cancelSetup(); 770 if(Engine.HasXmppClient()) 771 Engine.SwitchGuiPage("page_lobby.xml"); 772 else 773 Engine.SwitchGuiPage("page_pregame.xml"); 774 } 775 792 776 function cancelSetup() 793 777 { 794 778 if (g_IsController) 795 779 saveGameAttributes(); 796 780 … … 858 842 } 859 843 else 860 844 { 861 845 // Add player data from defaults 862 846 for (var i = pData.length; i < num; ++i) 863 g_GameAttributes.settings.PlayerData.push(g_ DefaultPlayerData[i]);847 g_GameAttributes.settings.PlayerData.push(g_PlayerDefaults[i]); 864 848 } 865 849 866 850 // Some players may have lost their assigned slot 867 851 for (var guid in g_PlayerAssignments) 868 852 { … … 908 892 break; 909 893 910 894 case "skirmish": 911 895 g_GameAttributes.mapPath = "maps/skirmishes/"; 912 896 g_GameAttributes.settings = { 913 PlayerData: g_ DefaultPlayerData.slice(0, 4),897 PlayerData: g_PlayerDefaults.slice(0, 4), 914 898 Seed: Math.floor(Math.random() * 65536), 915 899 AISeed: Math.floor(Math.random() * 65536), 916 900 CheatsEnabled: g_GameAttributes.settings.CheatsEnabled 917 901 }; 918 902 break; 919 903 920 904 case "random": 921 905 g_GameAttributes.mapPath = "maps/random/"; 922 906 g_GameAttributes.settings = { 923 PlayerData: g_ DefaultPlayerData.slice(0, 4),907 PlayerData: g_PlayerDefaults.slice(0, 4), 924 908 Seed: Math.floor(Math.random() * 65536), 925 909 AISeed: Math.floor(Math.random() * 65536), 926 910 CheatsEnabled: g_GameAttributes.settings.CheatsEnabled 927 911 }; 928 912 break; … … 975 959 g_GameAttributes.settings[prop] = undefined; 976 960 977 961 var mapData = loadMapData(name); 978 962 var mapSettings = (mapData && mapData.settings ? deepcopy(mapData.settings) : {}); 979 963 964 // Reset victory conditions 965 if (g_GameAttributes.mapType != "random") 966 { 967 let victoryIdx = mapSettings.GameType && g_GameTypes.Name.indexOf(mapSettings.GameType) != -1 ? g_GameTypes.Name.indexOf(mapSettings.GameType) : g_GameTypes.default; 968 g_GameAttributes.settings.GameType = g_GameTypes.Name[victoryIdx]; 969 g_GameAttributes.settings.VictoryScripts = g_GameTypes.Scripts[victoryIdx]; 970 } 971 980 972 // Copy any new settings 981 973 g_GameAttributes.map = name; 982 974 g_GameAttributes.script = mapSettings.Script; 983 975 if (g_GameAttributes.map !== "random") 984 976 for (var prop in mapSettings) … … 990 982 991 983 // Use default AI if the map doesn't specify any explicitly 992 984 for (var i = 0; i < g_GameAttributes.settings.PlayerData.length; ++i) 993 985 { 994 986 if (!('AI' in g_GameAttributes.settings.PlayerData[i])) 995 g_GameAttributes.settings.PlayerData[i].AI = g_ DefaultPlayerData[i].AI;987 g_GameAttributes.settings.PlayerData[i].AI = g_PlayerDefaults[i].AI; 996 988 if (!('AIDiff' in g_GameAttributes.settings.PlayerData[i])) 997 g_GameAttributes.settings.PlayerData[i].AIDiff = g_ DefaultPlayerData[i].AIDiff;989 g_GameAttributes.settings.PlayerData[i].AIDiff = g_PlayerDefaults[i].AIDiff; 998 990 } 999 991 1000 992 // Reset player assignments on map change 1001 993 if (!g_IsNetworked) 1002 994 { // Slot 1 … … 1008 1000 1009 1001 for (var guid in g_PlayerAssignments) 1010 1002 { // Unassign extra players 1011 1003 var player = g_PlayerAssignments[guid].player; 1012 1004 1013 if (player <= MAX_PLAYERS&& player > numPlayers)1005 if (player <= g_Settings.MaxPlayers && player > numPlayers) 1014 1006 Engine.AssignNetworkPlayer(player, ""); 1015 1007 } 1016 1008 } 1017 1009 1018 1010 updateGameAttributes(); … … 1133 1125 1134 1126 //////////////////////////////////////////////////////////////////////////////////////////////// 1135 1127 1136 1128 function onGameAttributesChange() 1137 1129 { 1130 if (!g_Settings) 1131 return; 1132 1138 1133 g_IsInGuiUpdate = true; 1139 1134 1140 1135 // Don't set any attributes here, just show the changes in GUI 1141 1136 1142 1137 var mapName = g_GameAttributes.map || ""; 1143 1138 var mapSettings = g_GameAttributes.settings; 1144 var numPlayers = (mapSettings.PlayerData ? mapSettings.PlayerData.length : MAX_PLAYERS);1139 var numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_Settings.MaxPlayers; 1145 1140 1146 1141 // Update some controls for clients 1147 1142 if (!g_IsController) 1148 1143 { 1149 1144 var mapFilterSelection = Engine.GetGUIObjectByName("mapFilterSelection"); … … 1157 1152 Engine.GetGUIObjectByName("mapSelectionText").caption = translate(getMapDisplayName(mapName)); 1158 1153 if (mapSettings.PopulationCap) 1159 1154 { 1160 1155 var populationCapBox = Engine.GetGUIObjectByName("populationCap"); 1161 1156 populationCapBox.selected = populationCapBox.list_data.indexOf(mapSettings.PopulationCap); 1162 } 1157 } 1163 1158 if (mapSettings.StartingResources) 1164 1159 { 1165 1160 var startingResourcesBox = Engine.GetGUIObjectByName("startingResources"); 1166 1161 startingResourcesBox.selected = startingResourcesBox.list_data.indexOf(mapSettings.StartingResources); 1167 1162 } … … 1204 1199 var ceasefireText = Engine.GetGUIObjectByName("ceasefireText"); 1205 1200 var gameSpeedText = Engine.GetGUIObjectByName("gameSpeedText"); 1206 1201 var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); 1207 1202 1208 1203 // We have to check for undefined on these properties as not all maps define them. 1209 var sizeIdx = (mapSettings.Size !== undefined && g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes["default"]); 1210 var speedIdx = (g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) != -1) ? g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds["default"]; 1211 var victories = getVictoryConditions(); 1212 var victoryIdx = (mapSettings.GameType !== undefined && victories.data.indexOf(mapSettings.GameType) != -1 ? victories.data.indexOf(mapSettings.GameType) : VICTORY_DEFAULTIDX); 1213 enableCheats.checked = (mapSettings.CheatsEnabled === undefined || !mapSettings.CheatsEnabled ? false : true) 1204 var sizeIdx = mapSettings.Size && g_MapSizes.Tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.default; 1205 var speedIdx = g_GameAttributes.gameSpeed && g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) != -1 ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.default; 1206 var victoryIdx = mapSettings.GameType && g_GameTypes.Name.indexOf(mapSettings.GameType) != -1 ? g_GameTypes.Name.indexOf(mapSettings.GameType) : g_GameTypes.default; 1207 enableCheats.checked = mapSettings.CheatsEnabled == true; 1214 1208 enableCheatsText.caption = (enableCheats.checked ? translate("Yes") : translate("No")); 1215 if (mapSettings.RatingEnabled !== undefined)1209 if (mapSettings.RatingEnabled) 1216 1210 { 1217 1211 enableRating.checked = mapSettings.RatingEnabled; 1218 1212 Engine.SetRankedGame(enableRating.checked); 1219 1213 enableRatingText.caption = (enableRating.checked ? translate("Yes") : translate("No")); 1220 1214 enableCheats.enabled = !enableRating.checked; 1221 1215 lockTeams.enabled = !enableRating.checked; 1222 1216 } 1223 1217 else 1224 1218 enableRatingText.caption = "Unknown"; 1225 gameSpeedText.caption = g_GameSpeeds. names[speedIdx];1219 gameSpeedText.caption = g_GameSpeeds.Title[speedIdx]; 1226 1220 gameSpeedBox.selected = speedIdx; 1227 populationCap.selected = (mapSettings.PopulationCap !== undefined && POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX);1228 populationCapText.caption = POPULATION_CAP[populationCap.selected];1229 startingResources.selected = (mapSettings.StartingResources !== undefined && STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX);1230 startingResourcesText.caption = STARTING_RESOURCES[startingResources.selected];1231 ceasefire.selected = (mapSettings.Ceasefire !== undefined && CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) != -1 ? CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) : CEASEFIRE_DEFAULTIDX);1232 ceasefireText.caption = CEASEFIRE[ceasefire.selected];1221 populationCap.selected = mapSettings.PopulationCap && g_PopulationCapacity.Population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopulationCapacity.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacity.default; 1222 populationCapText.caption = g_PopulationCapacity.Title[populationCap.selected]; 1223 startingResources.selected = mapSettings.StartingResources && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.default; 1224 startingResourcesText.caption = g_StartingResources.Title[startingResources.selected]; 1225 ceasefire.selected = mapSettings.hasOwnProperty("Ceasefire") && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.default; 1226 ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected]; 1233 1227 1234 1228 // Update map preview 1235 1229 Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:(0.78125,0.5859375)session/icons/mappreview/" + getMapPreview(mapName); 1236 1230 1237 1231 // Hide/show settings depending on whether we can change them or not … … 1270 1264 } 1271 1265 else 1272 1266 { 1273 1267 // Client 1274 1268 numPlayersText.caption = numPlayers; 1275 mapSizeText.caption = g_MapSizes. names[sizeIdx];1269 mapSizeText.caption = g_MapSizes.LongName[sizeIdx]; 1276 1270 revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No")); 1277 1271 exploreMapText.caption = (mapSettings.ExporeMap ? translate("Yes") : translate("No")); 1278 1272 disableTreasuresText.caption = (mapSettings.DisableTreasures ? translate("Yes") : translate("No")); 1279 victoryConditionText.caption = victories.text[victoryIdx];1273 victoryConditionText.caption = g_GameTypes.Title[victoryIdx]; 1280 1274 lockTeamsText.caption = (mapSettings.LockTeams ? translate("Yes") : translate("No")); 1281 1275 } 1282 1276 1283 1277 break; 1284 1278 … … 1313 1307 { 1314 1308 // Client 1315 1309 revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No")); 1316 1310 exploreMapText.caption = (mapSettings.ExploreMap ? translate("Yes") : translate("No")); 1317 1311 disableTreasuresText.caption = (mapSettings.DisableTreasures ? translate("Yes") : translate("No")); 1318 victoryConditionText.caption = victories.text[victoryIdx];1312 victoryConditionText.caption = g_GameTypes.Title[victoryIdx]; 1319 1313 lockTeamsText.caption = (mapSettings.LockTeams ? translate("Yes") : translate("No")); 1320 1314 } 1321 1315 1322 1316 break; 1323 1317 … … 1343 1337 startingResourcesText.hidden = false; 1344 1338 populationCap.hidden = true; 1345 1339 populationCapText.hidden = false; 1346 1340 ceasefire.hidden = true; 1347 1341 ceasefireText.hidden = false; 1348 1342 1349 1343 numPlayersText.caption = numPlayers; 1350 1344 mapSizeText.caption = translate("Default"); 1351 1345 revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No")); 1352 1346 exploreMapText.caption = (mapSettings.ExploreMap ? translate("Yes") : translate("No")); 1353 1347 disableTreasuresText.caption = translate("No"); 1354 victoryConditionText.caption = victories.text[victoryIdx];1348 victoryConditionText.caption = g_GameTypes.Title[victoryIdx]; 1355 1349 lockTeamsText.caption = (mapSettings.LockTeams ? translate("Yes") : translate("No")); 1356 1350 1357 1351 startingResourcesText.caption = translate("Determined by scenario"); 1358 1352 populationCapText.caption = translate("Determined by scenario"); 1359 1353 ceasefireText.caption = translate("Determined by scenario"); … … 1377 1371 // Load the description from the map file, if there is one 1378 1372 var description = mapSettings.Description ? translate(mapSettings.Description) : translate("Sorry, no description available."); 1379 1373 1380 1374 // Describe the number of players and the victory conditions 1381 1375 var playerString = sprintf(translatePlural("%(number)s player. ", "%(number)s players. ", numPlayers), { number: numPlayers }); 1382 let victory = translate( victories.text[victoryIdx]);1383 if (victoryIdx != VICTORY_DEFAULTIDX)1376 let victory = translate(g_GameTypes.Title[victoryIdx]); 1377 if (victoryIdx != g_GameTypes.default) 1384 1378 victory = "[color=\"orange\"]" + victory + "[/color]"; 1385 1379 playerString += translate("Victory Condition:") + " " + victory + ".\n\n" + description; 1386 1380 1387 for ( var i = 0; i < MAX_PLAYERS; ++i)1381 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 1388 1382 { 1389 1383 // Show only needed player slots 1390 1384 Engine.GetGUIObjectByName("playerBox["+i+"]").hidden = (i >= numPlayers); 1391 1385 1392 1386 // Show player data or defaults as necessary … … 1402 1396 var pTeamText = Engine.GetGUIObjectByName("playerTeamText["+i+"]"); 1403 1397 var pColor = Engine.GetGUIObjectByName("playerColor["+i+"]"); 1404 1398 1405 1399 // Player data / defaults 1406 1400 var pData = mapSettings.PlayerData ? mapSettings.PlayerData[i] : {}; 1407 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[i] : {};1401 var pDefs = g_PlayerDefaults[i];; 1408 1402 1409 1403 // Common to all game types 1410 1404 var color = rgbToGuiColor(getSetting(pData, pDefs, "Color")); 1411 1405 pColor.sprite = "color:" + color + " 100"; 1412 1406 pName.caption = translate(getSetting(pData, pDefs, "Name")); … … 1513 1507 1514 1508 // Only enable start button if we have enough assigned players 1515 1509 if (g_IsController) 1516 1510 Engine.GetGUIObjectByName("startGame").enabled = (g_AssignedCount > 0); 1517 1511 1518 for each (var ai in g_AIs) 1512 var AIs = initAIDescription(); 1513 for (let ai of AIs) 1519 1514 { 1520 1515 if (ai.data.hidden) 1521 1516 { 1522 1517 // If the map uses a hidden AI then don't hide it 1523 1518 var usedByMap = false; 1524 for ( var i = 0; i < MAX_PLAYERS; ++i)1519 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 1525 1520 if (i < g_GameAttributes.settings.PlayerData.length && 1526 1521 g_GameAttributes.settings.PlayerData[i].AI == ai.id) 1527 1522 { 1528 1523 usedByMap = true; 1529 1524 break; … … 1540 1535 1541 1536 noAssignment = hostNameList.length; 1542 1537 hostNameList.push("[color=\"140 140 140 255\"]" + translate("Unassigned")); 1543 1538 hostGuidList.push(""); 1544 1539 1545 for ( var i = 0; i < MAX_PLAYERS; ++i)1540 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 1546 1541 { 1547 1542 let playerSlot = i; 1548 1543 let playerID = i+1; // we don't show Gaia, so first slot is ID 1 1549 1544 1550 1545 var selection = assignments[playerID]; … … 1579 1574 if (g_IsController) 1580 1575 { 1581 1576 configButton.hidden = false; 1582 1577 configButton.onpress = function() { 1583 1578 Engine.PushGuiPage("page_aiconfig.xml", { 1584 ais: g_AIs, 1585 id: g_GameAttributes.settings.PlayerData[playerSlot].AI, 1586 difficulty: g_GameAttributes.settings.PlayerData[playerSlot].AIDiff, 1587 callback: "AIConfigCallback", 1588 playerSlot: playerSlot // required by the callback function 1579 "AIs": AIs, 1580 "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, 1581 "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff, 1582 "difficulties" : g_AIDiffs, 1583 "callback": "AIConfigCallback", 1584 "playerSlot": playerSlot // required by the callback function 1589 1585 }); 1590 1586 }; 1591 1587 } 1592 1588 } 1593 1589 // There was a human, so make sure we don't have any AI left … … 1711 1707 var player = g_PlayerAssignments[msg.guid].player - 1; 1712 1708 var mapName = g_GameAttributes.map; 1713 1709 var mapData = loadMapData(mapName); 1714 1710 var mapSettings = (mapData && mapData.settings ? mapData.settings : {}); 1715 1711 var pData = mapSettings.PlayerData ? mapSettings.PlayerData[player] : {}; 1716 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[player] : {};1712 var pDefs = g_PlayerDefaults[player]; 1717 1713 1718 1714 color = rgbToGuiColor(getSetting(pData, pDefs, "Color")); 1719 1715 } 1720 1716 1721 1717 var formatted; … … 1784 1780 1785 1781 function updateReadyUI() 1786 1782 { 1787 1783 if (!g_IsNetworked) 1788 1784 return; // Disabled for single-player games. 1789 var isAI = new Array( MAX_PLAYERS+ 1);1785 var isAI = new Array(g_Settings.MaxPlayers + 1); 1790 1786 for (var i = 0; i < isAI.length; ++i) 1791 1787 isAI[i] = true; 1792 1788 var allReady = true; 1793 1789 for (var guid in g_PlayerAssignments) 1794 1790 { 1795 1791 // We don't really care whether observers are ready. 1796 1792 if (g_PlayerAssignments[guid].player == -1 || !g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1]) 1797 1793 continue; 1798 1794 var pData = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1] : {}; 1799 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[g_PlayerAssignments[guid].player - 1] : {};1795 var pDefs = g_PlayerDefaults[g_PlayerAssignments[guid].player - 1]; 1800 1796 isAI[g_PlayerAssignments[guid].player] = false; 1801 1797 if (g_PlayerAssignments[guid].status || !g_IsNetworked) 1802 1798 Engine.GetGUIObjectByName("playerName[" + (g_PlayerAssignments[guid].player - 1) + "]").caption = '[color="0 255 0"]' + translate(getSetting(pData, pDefs, "Name")) + '[/color]'; 1803 1799 else 1804 1800 { 1805 1801 Engine.GetGUIObjectByName("playerName[" + (g_PlayerAssignments[guid].player - 1) + "]").caption = translate(getSetting(pData, pDefs, "Name")); 1806 1802 allReady = false; 1807 1803 } 1808 1804 } 1809 1805 // AIs are always ready. 1810 for ( var playerid = 0; playerid < MAX_PLAYERS; ++playerid)1811 { 1806 for (let playerid = 0; playerid < g_Settings.MaxPlayers; ++playerid) 1807 { 1812 1808 if (!g_GameAttributes.settings.PlayerData[playerid]) 1813 1809 continue; 1814 1810 var pData = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData[playerid] : {}; 1815 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[playerid] : {};1811 var pDefs = g_PlayerDefaults[playerid]; 1816 1812 if (isAI[playerid + 1]) 1817 1813 Engine.GetGUIObjectByName("playerName[" + playerid + "]").caption = '[color="0 255 0"]' + translate(getSetting(pData, pDefs, "Name")) + '[/color]'; 1818 1814 } 1819 1815 1820 1816 // The host is not allowed to start until everyone is ready. … … 1967 1963 "nbp":nbp, 1968 1964 "tnbp":tnbp, 1969 1965 "players":players 1970 1966 }; 1971 1967 Engine.SendRegisterGame(gameData); 1972 } 1973 1974 function getVictoryConditions() 1975 { 1976 var r = {}; 1977 r.text = [translate("None")]; 1978 r.data = ["endless"]; 1979 r.scripts = [[]]; 1980 for (var vc in g_VictoryConditions) 1981 { 1982 r.data.push(vc); 1983 r.text.push(g_VictoryConditions[vc].name); 1984 r.scripts.push(g_VictoryConditions[vc].scripts); 1985 } 1986 return r; 1987 } 1968 } 1969 No newline at end of file -
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 <script file="gui/common/network.js"/>6 5 <script file="gui/common/functions_civinfo.js"/> 7 6 <script file="gui/common/functions_global_object.js"/> 8 7 <script file="gui/common/functions_utility.js"/> 8 <script file="gui/common/network.js"/> 9 <script file="gui/common/settings.js"/> 9 10 <script file="gui/gamesetup/gamesetup.js"/> 10 <!-- After gamesetup.js which defines g_VictoryConditions -->11 <script directory="gui/gamesetup/victory_conditions/"/>12 11 13 12 <!-- Add a translucent black background to fade out the menu page --> 14 13 <object type="image" style="ModernWindow" size="0 0 100% 100%"> 15 14 16 15 <object style="TitleText" type="text" size="50%-128 4 50%+128 36"> … … 237 236 style="StoneButton" 238 237 size="100%-308 100%-52 100%-168 100%-24" 239 238 tooltip_style="onscreenToolTip" 240 239 > 241 240 <translatableAttribute id="caption">Back</translatableAttribute> 242 <action on="Press"> 243 <![CDATA[ 244 cancelSetup(); 245 if(!Engine.HasXmppClient()) 246 Engine.SwitchGuiPage("page_pregame.xml"); 247 else 248 Engine.SwitchGuiPage("page_lobby.xml"); 249 ]]> 250 </action> 241 <action on="Press">cancelAndReturn();</action> 251 242 </object> 252 243 253 244 <!-- Options --> 254 245 <object name="gameOptionsBox" size="100%-425 529 100%-25 525"> 255 246 <!-- More Options Button --> -
binaries/data/mods/public/gui/gamesetup/victory_conditions/conquest.js
1 g_VictoryConditions.conquest = {2 "name" : translate("Conquest"),3 "description" : translate("Defeat all opponents"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/Conquest.js"]5 }; -
binaries/data/mods/public/gui/gamesetup/victory_conditions/conquestStructures.js
1 g_VictoryConditions.conquestStructure = {2 "name" : translate("Conquest Structures"),3 "description" : translate("Destroy all structures of enemies"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/ConquestStructures.js"]5 }; -
binaries/data/mods/public/gui/gamesetup/victory_conditions/conquestUnits.js
1 g_VictoryConditions.conquestUnits = {2 "name" : translate("Conquest Units"),3 "description" : translate("Destroy all units of enemies"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/ConquestUnits.js"]5 }; -
binaries/data/mods/public/gui/gamesetup/victory_conditions/wonder.js
1 g_VictoryConditions.wonder = {2 "name" : translate("Wonder"),3 "description" : translate("Build a wonder to win"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/Conquest.js", "scripts/WonderVictory.js"]5 }; -
binaries/data/mods/public/gui/lobby/lobby.js
1 const g_specialKey = Math.random(); 2 const g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true"; 3 const g_modPrefix = "@"; 4 const SPAM_BLOCK_LENGTH = 30; 5 1 6 var g_ChatMessages = []; 2 7 var g_Name = "unknown"; 3 8 var g_GameList = {} 4 9 var g_GameListSortBy = "name"; 5 10 var g_PlayerListSortBy = "name"; 6 11 var g_GameListOrder = 1; // 1 for ascending sort, and -1 for descending 7 12 var g_PlayerListOrder = 1; 8 var g_specialKey = Math.random();9 13 // This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use. 10 14 var g_spamMonitor = {}; 11 var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";12 var g_mapSizes = {};13 const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];14 const g_mapTypes = ["skirmish", "random", "scenario"];15 15 var g_userRating = ""; // Rating of user, defaults to Unrated 16 var g_modPrefix = "@";17 16 var g_joined = false; 18 // Block spammers for 30 seconds.19 var SPAM_BLOCK_LENGTH = 30;20 17 21 18 //////////////////////////////////////////////////////////////////////////////////////////////// 22 19 23 20 function init(attribs) 24 21 { 22 if (!validSettings(returnToMainMenu)) 23 return; 24 25 25 // Play menu music 26 26 initMusic(); 27 27 global.music.setState(global.music.states.MENU); 28 28 29 g_Name = Engine.LobbyGetNick(); 30 31 g_mapSizes = initMapSizes(); 32 g_mapSizes.shortNames.splice(0, 0, translateWithContext("map size", "Any")); 33 g_mapSizes.tiles.splice(0, 0, ""); 34 29 // Setup mapsize filter 35 30 var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 36 mapSizeFilter.list = g_mapSizes.shortNames; 37 mapSizeFilter.list_data = g_mapSizes.tiles; 31 var mapSizes = prepareForDropdown("MapSizes"); 32 mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(mapSizes.Name); 33 mapSizeFilter.list_data = [""].concat(mapSizes.Tiles); 38 34 35 // Setup playercount filter 36 var playersArray = Array(g_Settings.MaxPlayers - 1).fill(0).map((value, index) => index + 2); // 2, 3, ... MaxPlayers 39 37 var playersNumberFilter = Engine.GetGUIObjectByName("playersNumberFilter"); 40 playersNumberFilter.list = [translateWithContext("player number", "Any") ,2,3,4,5,6,7,8];41 playersNumberFilter.list_data = ["" ,2,3,4,5,6,7,8];38 playersNumberFilter.list = [translateWithContext("player number", "Any")].concat(playersArray); 39 playersNumberFilter.list_data = [""].concat(playersArray); 42 40 41 // Setup maptype filter 43 42 var mapTypeFilter = Engine.GetGUIObjectByName("mapTypeFilter"); 44 mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_mapTypesText); 45 mapTypeFilter.list_data = [""].concat(g_mapTypes); 43 var mapTypes = prepareForDropdown("MapTypes"); 44 mapTypeFilter.list = [translateWithContext("map type", "Any")].concat(mapTypes.Title); 45 mapTypeFilter.list_data = [""].concat(mapTypes.Name); 46 46 47 // Init GUI elements 48 g_Name = Engine.LobbyGetNick(); 47 49 Engine.LobbySetPlayerPresence("available"); 48 50 Engine.SendGetGameList(); 49 51 Engine.SendGetBoardList(); 50 52 Engine.SendGetRatingList(); 51 53 updatePlayerList(); … … 468 470 else 469 471 name = '[color="255 0 0"]' + name + '[/color]'; 470 472 list_name.push(name); 471 473 list_ip.push(g.ip); 472 474 list_mapName.push(translate(g.niceMapName)); 473 list_mapSize.push(translatedMapSize(g.mapSize)); 474 let idx = g_mapTypes.indexOf(g.mapType); 475 list_mapType.push(idx != -1 ? g_mapTypesText[idx] : ""); 475 list_mapSize.push(translateMapSize(g.mapSize)); 476 list_mapType.push(translateMapType(g.mapType)); 476 477 list_nPlayers.push(g.nbp + "/" +g.tnbp); 477 478 list.push(name); 478 479 list_data.push(c); 479 480 } 480 481 c++; … … 546 547 // Push this player's name and status onto the list 547 548 return [formattedName, formattedStatus, formattedRating]; 548 549 } 549 550 550 551 /** 551 * Given a map size, returns that map size translated into the current552 * language.553 */554 function translatedMapSize(mapSize)555 {556 if (+mapSize !== +mapSize) // NaN557 return translate(mapSize);558 else559 return g_mapSizes.shortNames[g_mapSizes.tiles.indexOf(+mapSize)];560 }561 562 /**563 552 * Populate the game info area with information on the current game selection. 564 553 */ 565 554 function updateGameSelection() 566 555 { 567 556 var selected = Engine.GetGUIObjectByName("gamesBox").selected; … … 572 561 Engine.GetGUIObjectByName("joinGameButton").hidden = true; 573 562 Engine.GetGUIObjectByName("gameInfoEmpty").hidden = false; 574 563 return; 575 564 } 576 565 577 var mapData;578 566 var g = Engine.GetGUIObjectByName("gamesBox").list_data[selected]; 579 567 580 // Load map data581 if (g_GameList[g].mapType == "random" && g_GameList[g].mapName == "random")582 mapData = {"settings": {"Description": translate("A randomly selected map.")}};583 else if (g_GameList[g].mapType == "random" && Engine.FileExists(g_GameList[g].mapName + ".json"))584 mapData = Engine.ReadJSONFile(g_GameList[g].mapName + ".json");585 else if (Engine.FileExists(g_GameList[g].mapName + ".xml"))586 mapData = Engine.LoadMapSettings(g_GameList[g].mapName + ".xml");587 else588 // Warn the player if we can't find the map.589 warn(sprintf("Map '%(mapName)s' not found locally.", { mapName: g_GameList[g].mapName }));590 591 568 // Show the game info panel and join button. 592 569 Engine.GetGUIObjectByName("gameInfo").hidden = false; 593 570 Engine.GetGUIObjectByName("joinGameButton").hidden = false; 594 571 Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true; 595 572 596 573 // Display the map name, number of players, the names of the players, the map size and the map type. 597 574 Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName); 598 575 Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp; 599 576 Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players; 600 Engine.GetGUIObjectByName("sgMapSize").caption = translatedMapSize(g_GameList[g].mapSize); 601 let idx = g_mapTypes.indexOf(g_GameList[g].mapType); 602 Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_mapTypesText[idx] : ""; 603 604 // Display map description if it exists, otherwise display a placeholder. 605 if (mapData && mapData.settings.Description) 606 var mapDescription = translate(mapData.settings.Description); 607 else 608 var mapDescription = translate("Sorry, no description available."); 577 Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(g_GameList[g].mapSize); 578 Engine.GetGUIObjectByName("sgMapType").caption = translateMapType(g_GameList[g].mapType); 609 579 610 // Display map preview if it exists, otherwise display a placeholder. 611 if (mapData && mapData.settings.Preview) 612 var mapPreview = mapData.settings.Preview; 613 else 614 var mapPreview = "nopreview.png"; 615 616 Engine.GetGUIObjectByName("sgMapDescription").caption = mapDescription; 617 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapPreview; 580 // Display map description & preview (or placeholder) 581 let mapData = getMapDescriptionAndPreview(g_GameList[g].mapType, g_GameList[g].mapName); 582 Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description; 583 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview; 618 584 } 619 585 620 586 /** 621 587 * Start the joining process on the currectly selected game. 622 588 */ … … 859 825 break; 860 826 case "ban": // TODO: Split reason from nick and pass it too, for now just support "/ban nick" 861 827 Engine.LobbyBan(nick, ""); 862 828 break; 863 829 case "quit": 864 lobbyStop(); 865 Engine.SwitchGuiPage("page_pregame.xml"); 830 returnToMainMenu(); 866 831 break; 867 832 case "say": 868 833 case "me": 869 834 return false; 870 835 default: … … 1088 1053 } 1089 1054 } 1090 1055 1091 1056 } 1092 1057 1058 function returnToMainMenu() 1059 { 1060 lobbyStop(); 1061 Engine.SwitchGuiPage("page_pregame.xml"); 1062 } 1063 1093 1064 /* Utilities */ 1094 1065 // Generate a (mostly) unique color for this player based on their name. 1095 1066 // See http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-jquery-javascript 1096 1067 function getPlayerColor(playername) 1097 1068 { -
binaries/data/mods/public/gui/lobby/lobby.xml
3 3 <objects> 4 4 <script file="gui/common/functions_global_object.js"/> 5 5 <script file="gui/common/functions_utility.js"/> 6 6 <script file="gui/common/timer.js"/> 7 7 <script file="gui/common/music.js"/> 8 <script file="gui/common/settings.js"/> 8 9 9 10 <script file="gui/lobby/lobby.js"/> 10 11 11 12 <object type="image" style="ModernWindow" size="0 0 100% 100%" name="lobbyWindow"> 12 13 … … 161 162 </action> 162 163 </object> 163 164 164 165 <object type="button" style="ModernButtonRed" size="0 100%-25 100% 100%"> 165 166 <translatableAttribute id="caption">Main Menu</translatableAttribute> 166 <action on="Press"> 167 lobbyStop(); 168 Engine.SwitchGuiPage("page_pregame.xml"); 169 </action> 167 <action on="Press">returnToMainMenu();</action> 170 168 </object> 171 169 </object> 172 170 173 171 <!-- Middle panel: Filters, game list, chat box. --> 174 172 <object name="middlePanel" size="20%+5 5% 100%-255 97.2%"> -
binaries/data/mods/public/gui/session/session.js
11 11 // Cache the basic player data (name, civ, color) 12 12 var g_Players = []; 13 13 // Cache the useful civ data 14 14 var g_CivData = {}; 15 15 16 var g_GameSpeeds = {};17 var g_CurrentSpeed;18 19 16 var g_PlayerAssignments = { "local": { "name": translate("You"), "player": 1 } }; 20 17 21 18 // Cache dev-mode settings that are frequently or widely used 22 19 var g_DevSettings = { 23 20 controlAll: false … … 145 142 } 146 143 147 144 // Init 148 145 function init(initData, hotloadData) 149 146 { 147 initMusic(); 148 149 if (!validSettings(function() { leaveGame(true); })) 150 return; 151 150 152 if (initData) 151 153 { 152 154 g_IsNetworked = initData.isNetworked; // Set network mode 153 155 g_IsController = initData.isController; // Set controller mode 154 156 g_PlayerAssignments = initData.playerAssignments; … … 175 177 if (Engine.GetPlayerID() <= 0) 176 178 g_IsObserver = true; 177 179 178 180 updateTopPanel(); 179 181 180 g_GameSpeeds = initGameSpeeds();181 g_CurrentSpeed = Engine.GetSimRate();182 182 var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 183 gameSpeed.list = g_GameSpeeds.names; 184 gameSpeed.list_data = g_GameSpeeds.speeds; 185 var idx = g_GameSpeeds.speeds.indexOf(g_CurrentSpeed); 186 gameSpeed.selected = idx != -1 ? idx : g_GameSpeeds["default"]; 183 var gameSpeeds = prepareForDropdown("GameSpeeds"); 184 gameSpeed.list = gameSpeeds.Title; 185 gameSpeed.list_data = gameSpeeds.Speed; 186 var idx = gameSpeed.list_data.indexOf(Engine.GetSimRate()); 187 gameSpeed.selected = idx != -1 ? idx : gameSpeeds.default; 187 188 gameSpeed.onSelectionChange = function() { changeGameSpeed(+this.list_data[this.selected]); } 188 189 initMenuPosition(); // set initial position 189 190 190 191 // Populate player selection dropdown 191 192 var playerNames = []; … … 207 208 208 209 if (hotloadData) 209 210 g_Selection.selected = hotloadData.selection; 210 211 211 212 // Starting for the first time: 212 initMusic();213 213 if (!g_IsObserver) 214 214 { 215 215 var civMusic = g_CivData[g_Players[Engine.GetPlayerID()].civ].Music; 216 216 global.music.storeTracks(civMusic); 217 217 } … … 356 356 "players": g_Players, 357 357 "mapSettings": mapSettings 358 358 }); 359 359 } 360 360 361 361 362 // Return some data that we'll use when hotloading this file after changes 362 363 function getHotloadData() 363 364 { 364 365 return { selection: g_Selection.selected }; 365 366 } … … 398 399 /** 399 400 * Called every frame. 400 401 */ 401 402 function onTick() 402 403 { 404 if (!g_Settings) 405 return; 406 403 407 var now = new Date; 404 408 var tickLength = new Date - lastTickTime; 405 409 lastTickTime = now; 406 410 407 411 checkPlayerState(); … … 507 511 508 512 function changeGameSpeed(speed) 509 513 { 510 514 // For non-networked games only 511 515 if (!g_IsNetworked) 512 {513 516 Engine.SetSimRate(speed); 514 g_CurrentSpeed = speed;515 }516 517 } 517 518 518 519 /** 519 520 * Recomputes GUI state that depends on simulation state or selection state. Called directly every simulation 520 521 * update (see session.xml), or from onTick when the selection has changed. -
binaries/data/mods/public/gui/session/session.xml
6 6 <script file="gui/common/functions_civinfo.js"/> 7 7 <script file="gui/common/functions_global_object.js"/> 8 8 <script file="gui/common/functions_utility.js"/> 9 9 <script file="gui/common/l10n.js"/> 10 10 <script file="gui/common/music.js"/> 11 <script file="gui/common/settings.js"/> 11 12 <script file="gui/common/timer.js"/> 12 13 <script file="gui/common/tooltips.js"/> 13 14 <!-- load all scripts in this directory --> 14 15 <script directory="gui/session/"/> 15 16 -
binaries/data/mods/public/gui/summary/layout.js
137 137 { 138 138 for (var h = 0; h < MAX_HEADINGTITLE; ++h) 139 139 { 140 140 Engine.GetGUIObjectByName("titleHeading["+ h +"]").hidden = true; 141 141 Engine.GetGUIObjectByName("Heading[" + h + "]").hidden = true; 142 for ( var p = 0; p < MAX_SLOTS; ++p)142 for (let p = 0; p < g_Settings.MaxPlayers; ++p) 143 143 { 144 144 Engine.GetGUIObjectByName("valueData[" + p + "][" + h + "]").hidden = true; 145 for ( var t = 0; t < MAX_TEAMS; ++t)145 for (let t = 0; t < g_Settings.MaxTeams; ++t) 146 146 { 147 147 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + h + "]").hidden = true; 148 148 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + h + "]").hidden = true; 149 149 } 150 150 } … … 187 187 188 188 function updateGeneralPanelCounter(counters) 189 189 { 190 190 var rowPlayerObjectWidth = 0; 191 191 var left = 0; 192 for ( var p = 0; p < MAX_SLOTS; ++p)192 for (let p = 0; p < g_Settings.MaxPlayers; ++p) 193 193 { 194 194 left = 240; 195 195 var counterObject; 196 196 for (var w in counters) 197 197 { … … 202 202 } 203 203 if (rowPlayerObjectWidth == 0) 204 204 rowPlayerObjectWidth = left; 205 205 206 206 var counterTotalObject; 207 for (var t = 0; t < MAX_TEAMS; ++t)207 for (var t = 0; t < g_Settings.MaxTeams; ++t) 208 208 { 209 209 left = 240; 210 210 for (var w in counters) 211 211 { 212 212 counterObject = Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]"); … … 262 262 Engine.GetGUIObjectByName("playerNameHeading").caption = ""; 263 263 } 264 264 265 265 function updateObjectPlayerPosition() 266 266 { 267 for ( var h = 0; h < MAX_SLOTS; ++h)267 for (let h = 0; h < g_Settings.MaxPlayers; ++h) 268 268 { 269 269 var playerBox = Engine.GetGUIObjectByName("playerBox[" + h + "]"); 270 270 var boxSize = playerBox.size; 271 271 boxSize.top += h * (PLAYER_BOX_Y_SIZE + PLAYER_BOX_GAP); 272 272 boxSize.bottom = boxSize.top + PLAYER_BOX_Y_SIZE; 273 273 playerBox.size = boxSize; 274 274 275 for ( var i = 0; i < MAX_TEAMS; ++i)275 for (let i = 0; i < g_Settings.MaxTeams; ++i) 276 276 { 277 277 var playerBoxt = Engine.GetGUIObjectByName("playerBoxt[" + i + "][" + h + "]"); 278 278 boxSize = playerBoxt.size; 279 279 boxSize.top += h * (PLAYER_BOX_Y_SIZE + PLAYER_BOX_GAP); 280 280 boxSize.bottom = boxSize.top + PLAYER_BOX_Y_SIZE; -
binaries/data/mods/public/gui/summary/summary.js
1 // Max player slots for any map (TODO: should read from config)2 const MAX_SLOTS = 8;3 const MAX_TEAMS = 4;4 1 const MAX_HEADINGTITLE = 8; 5 2 6 3 // const for filtering long collective headings 7 4 const LONG_HEADING_WIDTH = 250; 8 5 // Vertical size of player box … … 43 40 * Select active panel 44 41 * @param panelNumber Number of panel, which should get active state (integer) 45 42 */ 46 43 function selectPanel(panelNumber) 47 44 { 45 if (!g_Settings) 46 return; 47 48 48 var panelNames = [ 'scorePanel', 'buildingsPanel', 'unitsPanel', 'resourcesPanel', 'marketPanel', 'miscPanel']; 49 49 50 50 function adjustTabDividers(tabSize) 51 51 { 52 52 var leftSpacer = Engine.GetGUIObjectByName("tabDividerLeft"); … … 130 130 teamCounterFn(panelInfo.counters); 131 131 } 132 132 133 133 function init(data) 134 134 { 135 if (!g_Settings) 136 return; 137 135 138 updateObjectPlayerPosition(); 136 139 g_GameData = data; 137 140 138 // Map139 var mapDisplayType = translate("Scenario");140 141 141 Engine.GetGUIObjectByName("timeElapsed").caption = sprintf(translate("Game time elapsed: %(time)s"), { time: timeToString(data.timeElapsed) }); 142 142 143 143 Engine.GetGUIObjectByName("summaryText").caption = data.gameResult; 144 144 145 // This is only defined for random maps 146 if (data.mapSettings.Size) 147 { 148 // load the map sizes from the JSON file 149 var mapSizes = initMapSizes(); 150 151 // retrieve the index of the map size 152 for (var mapSizeIndex in mapSizes.tiles) 153 { 154 if (mapSizes.tiles[mapSizeIndex] == data.mapSettings.Size) 155 { 156 mapDisplayType = mapSizes.names[mapSizeIndex]; 157 break; 158 } 159 } 160 } 161 162 Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), { mapName: translate(data.mapSettings.Name), mapType: mapDisplayType}); 145 var mapDisplayType = data.mapSettings.mapType == "random" ? translateMapSize(data.mapSettings.Size) : translateMapType(data.mapSettings.mapType); 146 Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), 147 { mapName: translate(data.mapSettings.Name), mapType: mapDisplayType}); 163 148 164 149 // Panels 165 150 g_MaxPlayers = data.playerStates.length - 1; 166 151 167 152 if (data.mapSettings.LockTeams) // teams ARE locked -
binaries/data/mods/public/gui/summary/summary.xml
8 8 9 9 <objects> 10 10 <script file="gui/common/functions_global_object.js"/> 11 11 <script file="gui/common/functions_civinfo.js"/> 12 12 <script file="gui/common/functions_utility.js"/> 13 <script file="gui/common/settings.js"/> 13 14 <script file="gui/summary/counters.js"/> 14 15 <script file="gui/summary/layout.js"/> 15 16 <script file="gui/summary/summary.js"/> 16 17 17 18 <object type="image" -
binaries/data/mods/public/l10n/messages.json
451 451 } 452 452 }, 453 453 { 454 454 "extractor": "json", 455 455 "filemasks": [ 456 "simulation/data/game_speeds.json", 457 "simulation/data/player_defaults.json" 456 "simulation/data/settings/PlayerDefaults.json" 458 457 ], 459 458 "options": { 460 459 "keywords": [ 461 460 "Name" 462 461 ] 463 462 } 464 463 }, 465 464 { 466 465 "extractor": "json", 467 466 "filemasks": [ 468 "simulation/data/ map_sizes.json"467 "simulation/data/settings/MapSizes.json" 469 468 ], 470 469 "options": { 471 470 "keywords": [ 472 471 "Name", 473 472 "LongName" 474 473 ] 475 474 } 476 475 }, 477 476 { 478 477 "extractor": "json", 478 "filemasks": [ 479 "simulation/data/settings/GameTypes.json" 480 ], 481 "options": { 482 "keywords": [ 483 "Title", 484 "Description" 485 ] 486 } 487 }, 488 { 489 "extractor": "json", 490 "filemasks": [ 491 "simulation/data/settings/AI_Difficulties.json", 492 "simulation/data/settings/Ceasefire.json", 493 "simulation/data/settings/GameSpeeds.json", 494 "simulation/data/settings/MapTypes.json", 495 "simulation/data/settings/PopulationCapacity.json", 496 "simulation/data/settings/StartingResources.json" 497 ], 498 "options": { 499 "keywords": [ 500 "Title" 501 ] 502 } 503 }, 504 { 505 "extractor": "json", 479 506 "filemasks": [ 480 507 "simulation/ai/**.json" 481 508 ], 482 509 "options": { 483 510 "keywords": [ -
binaries/data/mods/public/simulation/data/game_speeds.json
1 {2 "Speeds":3 [4 {5 "Name": "Turtle (0.1x)",6 "Speed": 0.107 },8 {9 "Name": "Slow (0.25x)",10 "Speed": 0.2511 },12 {13 "Name": "Leisurely (0.5x)",14 "Speed": 0.5015 },16 {17 "Name": "Relaxed (0.75x)",18 "Speed": 0.7519 },20 {21 "Name": "Normal (1x)",22 "Speed": 1.0,23 "Default": true24 },25 {26 "Name": "Fast (1.25x)",27 "Speed": 1.2528 },29 {30 "Name": "Very Fast (1.5x)",31 "Speed": 1.532 },33 {34 "Name": "Insane (2x)",35 "Speed": 2.036 }37 ]38 } -
binaries/data/mods/public/simulation/data/map_sizes.json
1 {2 "Sizes":3 [4 {5 "Name": "Tiny",6 "LongName": "Tiny",7 "Tiles": 1288 },9 {10 "Name": "Small",11 "LongName": "Small (2 players)",12 "Tiles": 19213 },14 {15 "Name": "Medium",16 "LongName": "Medium (3 players)",17 "Tiles": 256,18 "Default": true19 },20 {21 "Name": "Normal",22 "LongName": "Normal (4 players)",23 "Tiles": 32024 },25 {26 "Name": "Large",27 "LongName": "Large (6 players)",28 "Tiles": 38429 },30 {31 "Name": "Very Large",32 "LongName": "Very Large (8 players)",33 "Tiles": 44834 },35 {36 "Name": "Giant",37 "LongName": "Giant",38 "Tiles": 51239 }40 ]41 } -
binaries/data/mods/public/simulation/data/player_defaults.json
1 {2 "PlayerData":3 [4 {5 "Name": "Gaia",6 "Civ": "gaia",7 "Color": { "r": 255, "g": 255, "b": 255 },8 "AI": "",9 "AIDiff": 310 },11 {12 "Name": "Player 1",13 "Civ": "athen",14 "Color": { "r": 46, "g": 46, "b": 200 },15 "AI": "",16 "AIDiff": 317 },18 {19 "Name": "Player 2",20 "Civ": "cart",21 "Color": { "r": 150, "g": 20, "b": 20 },22 "AI": "petra",23 "AIDiff": 324 },25 {26 "Name": "Player 3",27 "Civ": "gaul",28 "Color": { "r": 50, "g": 165, "b": 5 },29 "AI": "petra",30 "AIDiff": 331 },32 {33 "Name": "Player 4",34 "Civ": "iber",35 "Color": { "r": 230, "g": 230, "b": 75 },36 "AI": "petra",37 "AIDiff": 338 },39 {40 "Name": "Player 5",41 "Civ": "mace",42 "Color": { "r": 50, "g": 170, "b": 170 },43 "AI": "petra",44 "AIDiff": 345 },46 {47 "Name": "Player 6",48 "Civ": "maur",49 "Color": { "r": 160, "g": 80, "b": 200 },50 "AI": "petra",51 "AIDiff": 352 },53 {54 "Name": "Player 7",55 "Civ": "pers",56 "Color": { "r": 235, "g": 120, "b": 20 },57 "AI": "petra",58 "AIDiff": 359 },60 {61 "Name": "Player 8",62 "Civ": "rome",63 "Color": { "r": 64, "g": 64, "b": 64 },64 "AI": "petra",65 "AIDiff": 366 }67 ]68 } -
binaries/data/mods/public/simulation/data/settings/AI_Difficulties.json
1 { 2 "TranslatedKeys": ["Title"], 3 "AI_Difficulties": 4 [ 5 { 6 "Name": "sandbox", 7 "Title": "Sandbox" 8 }, 9 { 10 "Name": "very easy", 11 "Title": "Very Easy" 12 }, 13 { 14 "Name": "easy", 15 "Title": "Easy" 16 }, 17 { 18 "Name": "medium", 19 "Title": "Medium", 20 "Default": true 21 }, 22 { 23 "Name": "hard", 24 "Title": "Hard" 25 }, 26 { 27 "Name": "very hard", 28 "Title": "Very Hard" 29 } 30 ] 31 } 32 No newline at end of file -
binaries/data/mods/public/simulation/data/settings/Ceasefire.json
1 { 2 "TranslatedKeys": ["Title"], 3 "Ceasefire": 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": 5, 24 "Title": "5 minutes" 25 }, 26 { 27 "Duration": 10, 28 "Title": "10 minutes" 29 }, 30 { 31 "Duration": 15, 32 "Title": "15 minutes" 33 }, 34 { 35 "Duration": 20, 36 "Title": "20 minutes" 37 }, 38 { 39 "Duration": 30, 40 "Title": "30 minutes" 41 }, 42 { 43 "Duration": 45, 44 "Title": "45 minutes" 45 }, 46 { 47 "Duration": 60, 48 "Title": "60 minutes" 49 } 50 ] 51 } -
binaries/data/mods/public/simulation/data/settings/GameSpeeds.json
1 { 2 "TranslatedKeys": ["Title"], 3 "GameSpeeds": 4 [ 5 { 6 "Speed": 0.10, 7 "Title": "Turtle (0.1x)" 8 }, 9 { 10 "Speed": 0.25, 11 "Title": "Slow (0.25x)" 12 }, 13 { 14 "Speed": 0.50, 15 "Title": "Leisurely (0.5x)" 16 }, 17 { 18 "Speed": 0.75, 19 "Title": "Relaxed (0.75x)" 20 }, 21 { 22 "Speed": 1.0, 23 "Title": "Normal (1x)", 24 "Default": true 25 }, 26 { 27 "Speed": 1.25, 28 "Title": "Fast (1.25x)" 29 }, 30 { 31 "Speed": 1.5, 32 "Title": "Very Fast (1.5x)" 33 }, 34 { 35 "Speed": 2.0, 36 "Title": "Insane (2x)" 37 } 38 ] 39 } -
binaries/data/mods/public/simulation/data/settings/GameTypes.json
1 { 2 "TranslatedKeys": ["Title"], 3 "GameTypes": 4 [ 5 { 6 "Name": "endless", 7 "Title": "None", 8 "Description": "Endless Game", 9 "Scripts": [] 10 }, 11 { 12 "Name": "conquest", 13 "Title": "Conquest", 14 "Description": "Defeat all opponents", 15 "Scripts": 16 [ 17 "scripts/TriggerHelper.js", 18 "scripts/ConquestCommon.js", 19 "scripts/Conquest.js" 20 ], 21 "Default": true 22 }, 23 { 24 "Name": "conquestStructures", 25 "Title": "Conquest Structures", 26 "Description": "Destroy all structures of enemies", 27 "Scripts": 28 [ 29 "scripts/TriggerHelper.js", 30 "scripts/ConquestCommon.js", 31 "scripts/ConquestStructures.js" 32 ] 33 }, 34 { 35 "Name": "conquestUnits", 36 "Title": "Conquest Units", 37 "Description": "Kill all enemy units", 38 "Scripts": 39 [ 40 "scripts/TriggerHelper.js", 41 "scripts/ConquestCommon.js", 42 "scripts/ConquestUnits.js" 43 ] 44 }, 45 { 46 "Name": "wonder", 47 "Title": "Wonder", 48 "Description": "Build and protect a wonder to win", 49 "Scripts": 50 [ 51 "scripts/TriggerHelper.js", 52 "scripts/ConquestCommon.js", 53 "scripts/Conquest.js", 54 "scripts/WonderVictory.js" 55 ] 56 } 57 ] 58 } -
binaries/data/mods/public/simulation/data/settings/MapSizes.json
1 { 2 "TranslatedKeys": ["Name", "LongName"], 3 "MapSizes": 4 [ 5 { 6 "Tiles": 128, 7 "Name": "Tiny", 8 "LongName": "Tiny" 9 }, 10 { 11 "Tiles": 192, 12 "Name": "Small", 13 "LongName": "Small (2 players)" 14 }, 15 { 16 "Tiles": 256, 17 "Name": "Medium", 18 "LongName": "Medium (3 players)", 19 "Default": true 20 }, 21 { 22 "Tiles": 320, 23 "Name": "Normal", 24 "LongName": "Normal (4 players)" 25 }, 26 { 27 "Tiles": 384, 28 "Name": "Large", 29 "LongName": "Large (6 players)" 30 }, 31 { 32 "Tiles": 448, 33 "Name": "Very Large", 34 "LongName": "Very Large (8 players)" 35 }, 36 { 37 "Tiles": 512, 38 "Name": "Giant", 39 "LongName": "Giant" 40 } 41 ] 42 } -
binaries/data/mods/public/simulation/data/settings/MapTypes.json
1 { 2 "TranslatedKeys": ["Title"], 3 "MapTypes": 4 [ 5 { 6 "Name": "skirmish", 7 "Title": "Skirmish", 8 "Default": true 9 }, 10 { 11 "Name": "random", 12 "Title": "Random" 13 }, 14 { 15 "Name": "scenario", 16 "Title": "Scenario" 17 } 18 ] 19 } 20 No newline at end of file -
binaries/data/mods/public/simulation/data/settings/PlayerDefaults.json
1 { 2 "TranslatedKeys": ["Name"], 3 "PlayerDefaults": 4 [ 5 { 6 "Name": "Gaia", 7 "Civ": "gaia", 8 "Color": { "r": 255, "g": 255, "b": 255 }, 9 "AI": "", 10 "AIDiff": 3 11 }, 12 { 13 "Name": "Player 1", 14 "Civ": "athen", 15 "Color": { "r": 46, "g": 46, "b": 200 }, 16 "AI": "", 17 "AIDiff": 3 18 }, 19 { 20 "Name": "Player 2", 21 "Civ": "cart", 22 "Color": { "r": 150, "g": 20, "b": 20 }, 23 "AI": "petra", 24 "AIDiff": 3 25 }, 26 { 27 "Name": "Player 3", 28 "Civ": "gaul", 29 "Color": { "r": 50, "g": 165, "b": 5 }, 30 "AI": "petra", 31 "AIDiff": 3 32 }, 33 { 34 "Name": "Player 4", 35 "Civ": "iber", 36 "Color": { "r": 230, "g": 230, "b": 75 }, 37 "AI": "petra", 38 "AIDiff": 3 39 }, 40 { 41 "Name": "Player 5", 42 "Civ": "mace", 43 "Color": { "r": 50, "g": 170, "b": 170 }, 44 "AI": "petra", 45 "AIDiff": 3 46 }, 47 { 48 "Name": "Player 6", 49 "Civ": "maur", 50 "Color": { "r": 160, "g": 80, "b": 200 }, 51 "AI": "petra", 52 "AIDiff": 3 53 }, 54 { 55 "Name": "Player 7", 56 "Civ": "pers", 57 "Color": { "r": 235, "g": 120, "b": 20 }, 58 "AI": "petra", 59 "AIDiff": 3 60 }, 61 { 62 "Name": "Player 8", 63 "Civ": "rome", 64 "Color": { "r": 64, "g": 64, "b": 64 }, 65 "AI": "petra", 66 "AIDiff": 3 67 } 68 ] 69 } -
binaries/data/mods/public/simulation/data/settings/PlayerLimit.json
1 { 2 "MaxPlayers": 8, 3 "MaxTeams": 4 4 } -
binaries/data/mods/public/simulation/data/settings/PopulationCapacity.json
1 { 2 "TranslatedKeys": ["Title"], 3 "PopulationCapacity": 4 [ 5 { 6 "Population": 50, 7 "Title": "50" 8 }, 9 { 10 "Population": 100, 11 "Title": "100" 12 }, 13 { 14 "Population": 150, 15 "Title": "150" 16 }, 17 { 18 "Population": 200, 19 "Title": "200" 20 }, 21 { 22 "Population": 250, 23 "Title": "250" 24 }, 25 { 26 "Population": 300, 27 "Title": "300", 28 "Default": true 29 }, 30 { 31 "Population": 10000, 32 "Title": "Unlimited" 33 } 34 ] 35 } -
binaries/data/mods/public/simulation/data/settings/StartingResources.json
1 { 2 "TranslatedKeys": ["Title"], 3 "StartingResources": 4 [ 5 { 6 "Resources": 100, 7 "Title": "Very Low" 8 }, 9 { 10 "Resources": 300, 11 "Title": "Low", 12 "Default": true 13 }, 14 { 15 "Resources": 500, 16 "Title": "Medium" 17 }, 18 { 19 "Resources": 1000, 20 "Title": "High" 21 }, 22 { 23 "Resources": 3000, 24 "Title": "Very High" 25 }, 26 { 27 "Resources": 50000, 28 "Title": "Deathmatch" 29 } 30 ] 31 } -
binaries/data/mods/public/simulation/helpers/Player.js
13 13 // Default settings 14 14 if (!settings) 15 15 settings = {}; 16 16 17 17 // Get default player data 18 var rawData = Engine.ReadJSONFile(" player_defaults.json");19 if (! (rawData && rawData.PlayerData))20 throw("Player.js: Error reading player_defaults.json");18 var rawData = Engine.ReadJSONFile("settings/PlayerDefaults.json"); 19 if (!rawData || !rawData.PlayerDefaults) 20 throw("Player.js: Error reading PlayerDefaults.json"); 21 21 22 22 // Add gaia to simplify iteration 23 23 if (settings.PlayerData && settings.PlayerData[0]) 24 24 settings.PlayerData.unshift(null); 25 25 26 var playerDefaults = rawData.PlayerD ata;26 var playerDefaults = rawData.PlayerDefaults; 27 27 var playerData = settings.PlayerData; 28 28 29 29 // Get player manager 30 30 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 31 31 var numPlayers = cmpPlayerManager.GetNumPlayers(); … … 168 168 var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player); 169 169 cmpPlayer.SetLockTeams(true); 170 170 } 171 171 172 172 // Disable the AIIinterface when no AI players are present 173 if (playerData && !playerData.some(function(v) { return v && v.AI ? true : false; }))173 if (playerData && playerData.every(player => !player || !player.AI)) 174 174 Engine.QueryInterface(SYSTEM_ENTITY, IID_AIInterface).Disable(); 175 175 } 176 176 177 177 // Get a setting if it exists or return default 178 178 function getSetting(settings, defaults, idx, property) -
source/simulation2/Simulation2.cpp
878 878 return file.DecodeUTF8(); // assume it's UTF-8 879 879 } 880 880 881 881 std::string CSimulation2::GetPlayerDefaults() 882 882 { 883 return ReadJSON(L"simulation/data/ player_defaults.json");883 return ReadJSON(L"simulation/data/settings/PlayerDefaults.json"); 884 884 } 885 885 886 886 std::string CSimulation2::GetMapSizes() 887 887 { 888 return ReadJSON(L"simulation/data/ map_sizes.json");888 return ReadJSON(L"simulation/data/settings/MapSizes.json"); 889 889 } 890 890 891 891 std::string CSimulation2::GetAIData() 892 892 { 893 893 ScriptInterface& scriptInterface = GetScriptInterface(); -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp
139 139 sizer->Add(Tooltipped(new wxTextCtrl(this, ID_MapDescription, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE), 140 140 _("Short description used on the map selection screen")), wxSizerFlags().Expand()); 141 141 142 142 sizer->AddSpacer(5); 143 143 144 // TODO: load from GameTypes.json 144 145 wxArrayString gameTypes; 145 146 gameTypes.Add(_T("conquest")); 147 gameTypes.Add(_T("conquestStructures")); 148 gameTypes.Add(_T("conquestUnits")); 146 149 gameTypes.Add(_T("wonder")); 147 150 gameTypes.Add(_T("endless")); 148 151 149 152 wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5); 150 153 gridSizer->AddGrowableCol(1); -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp
535 535 // Get player names 536 536 wxArrayString players; 537 537 AtlasMessage::qGetPlayerDefaults qryPlayers; 538 538 qryPlayers.Post(); 539 539 AtObj playerData = AtlasObject::LoadFromJSON(*qryPlayers.defaults); 540 AtObj playerDefs = *playerData["PlayerD ata"];540 AtObj playerDefs = *playerData["PlayerDefaults"]; 541 541 for (AtIter p = playerDefs["item"]; p.defined(); ++p) 542 542 { 543 543 players.Add(wxString(p["Name"])); 544 544 } 545 545 wxDynamicCast(FindWindow(ID_PlayerSelect), PlayerComboBox)->SetPlayers(players); -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp
517 517 POST_MESSAGE(LoadPlayerSettings, (true)); 518 518 m_MapSettings.NotifyObservers(); 519 519 } 520 520 } 521 521 522 // TODO: we shouldn't hardcode this, but instead dynamically create 523 // new player notebook pages on demand; of course the default data 524 // will be limited by the entries in player_defaults.json 522 // TODO: Load value from PlayerLimit.json 525 523 static const size_t MAX_NUM_PLAYERS = 8; 526 524 527 525 bool m_InGUIUpdate; 528 526 AtObj m_PlayerDefaults; 529 527 PlayerNotebook* m_Players; … … 640 638 void PlayerSettingsControl::LoadDefaults() 641 639 { 642 640 AtlasMessage::qGetPlayerDefaults qryPlayers; 643 641 qryPlayers.Post(); 644 642 AtObj playerData = AtlasObject::LoadFromJSON(*qryPlayers.defaults); 645 m_PlayerDefaults = *playerData["PlayerD ata"];643 m_PlayerDefaults = *playerData["PlayerDefaults"]; 646 644 } 647 645 648 646 void PlayerSettingsControl::ReadFromEngine() 649 647 { 650 648 AtlasMessage::qGetMapSettings qry;