Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/gamesetup.js
const g_MatchSettings_SP = "config/matchsettings.json"; | const g_MatchSettings_SP = "config/matchsettings.json"; | ||||
const g_MatchSettings_MP = "config/matchsettings.mp.json"; | const g_MatchSettings_MP = "config/matchsettings.mp.json"; | ||||
const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire); | const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire); | ||||
const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly)); | const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly)); | ||||
const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); | const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); | ||||
const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); | const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); | ||||
const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); | const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); | ||||
const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); | const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); | ||||
const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions); | const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions); | ||||
const g_WonderDurations = prepareForDropdown(g_Settings && g_Settings.WonderDurations); | const g_WonderDurations = prepareForDropdown(g_Settings && g_Settings.WonderDurations); | ||||
const g_CaptureTheFlagDurations = prepareForDropdown(g_Settings && g_Settings.CaptureTheFlagDurations); | |||||
/** | /** | ||||
* All selectable playercolors except gaia. | * All selectable playercolors except gaia. | ||||
*/ | */ | ||||
const g_PlayerColors = g_Settings && g_Settings.PlayerDefaults.slice(1).map(pData => pData.Color); | const g_PlayerColors = g_Settings && g_Settings.PlayerDefaults.slice(1).map(pData => pData.Color); | ||||
/** | /** | ||||
* Directory containing all maps of the given type. | * Directory containing all maps of the given type. | ||||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | if (g_IsController) | ||||
initMapNameList(); | initMapNameList(); | ||||
initNumberOfPlayers(); | initNumberOfPlayers(); | ||||
initGameSpeed(); | initGameSpeed(); | ||||
initPopulationCaps(); | initPopulationCaps(); | ||||
initStartingResources(); | initStartingResources(); | ||||
initCeasefire(); | initCeasefire(); | ||||
initWonderDurations(); | initWonderDurations(); | ||||
initCaptureTheFlagDurations(); | |||||
initVictoryConditions(); | initVictoryConditions(); | ||||
initMapSizes(); | initMapSizes(); | ||||
initRadioButtons(); | initRadioButtons(); | ||||
} | } | ||||
else | else | ||||
hideControls(); | hideControls(); | ||||
initMultiplayerSettings(); | initMultiplayerSettings(); | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | wonderConditions.onSelectionChange = function() | ||||
if (this.selected != -1) | if (this.selected != -1) | ||||
g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected]; | g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected]; | ||||
updateGameAttributes(); | updateGameAttributes(); | ||||
}; | }; | ||||
wonderConditions.selected = g_WonderDurations.Default; | wonderConditions.selected = g_WonderDurations.Default; | ||||
} | } | ||||
function initCaptureTheFlagDurations() | |||||
{ | |||||
let captureTheFlagConditions = Engine.GetGUIObjectByName("captureTheFlagDuration"); | |||||
captureTheFlagConditions.list = g_CaptureTheFlagDurations.Title; | |||||
captureTheFlagConditions.list_data = g_CaptureTheFlagDurations.Duration; | |||||
captureTheFlagConditions.onSelectionChange = function() | |||||
{ | |||||
if (this.selected != -1) | |||||
g_GameAttributes.settings.CaptureTheFlagDuration = g_CaptureTheFlagDurations.Duration[this.selected]; | |||||
updateGameAttributes(); | |||||
}; | |||||
captureTheFlagConditions.selected = g_CaptureTheFlagDurations.Default; | |||||
} | |||||
function initMapSizes() | function initMapSizes() | ||||
{ | { | ||||
let mapSize = Engine.GetGUIObjectByName("mapSize"); | let mapSize = Engine.GetGUIObjectByName("mapSize"); | ||||
mapSize.list = g_MapSizes.Name; | mapSize.list = g_MapSizes.Name; | ||||
mapSize.list_data = g_MapSizes.Tiles; | mapSize.list_data = g_MapSizes.Tiles; | ||||
mapSize.onSelectionChange = function() { | mapSize.onSelectionChange = function() { | ||||
if (this.selected != -1) | if (this.selected != -1) | ||||
g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected]; | g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected]; | ||||
▲ Show 20 Lines • Show All 730 Lines • ▼ Show 20 Lines | if (g_GameAttributes.mapType != "random") | ||||
g_GameAttributes.settings.GameType = g_VictoryConditions.Name[victoryIdx]; | g_GameAttributes.settings.GameType = g_VictoryConditions.Name[victoryIdx]; | ||||
g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[victoryIdx]; | g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[victoryIdx]; | ||||
} | } | ||||
if (g_GameAttributes.mapType == "scenario") | if (g_GameAttributes.mapType == "scenario") | ||||
{ | { | ||||
delete g_GameAttributes.settings.WonderDuration; | delete g_GameAttributes.settings.WonderDuration; | ||||
delete g_GameAttributes.settings.LastManStanding; | delete g_GameAttributes.settings.LastManStanding; | ||||
delete g_GameAttributes.settings.CaptureTheFlagDuration; | |||||
} | } | ||||
if (mapSettings.PlayerData) | if (mapSettings.PlayerData) | ||||
sanitizePlayerData(mapSettings.PlayerData); | sanitizePlayerData(mapSettings.PlayerData); | ||||
// Copy any new settings | // Copy any new settings | ||||
g_GameAttributes.map = name; | g_GameAttributes.map = name; | ||||
g_GameAttributes.script = mapSettings.Script; | g_GameAttributes.script = mapSettings.Script; | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | function updateGUIObjects() | ||||
let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default")); | let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default")); | ||||
let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default; | let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default; | ||||
let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; | let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; | ||||
// These dropdowns might set the default (as they ignore g_IsInGuiUpdate) | // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) | ||||
let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; | let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; | ||||
let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; | let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; | ||||
let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default; | let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default; | ||||
let captureTheFlagDurationIdx = mapSettings.CaptureTheFlagDuration !== undefined ? | |||||
g_CaptureTheFlagDurations.Duration.indexOf(mapSettings.CaptureTheFlagDuration) : g_CaptureTheFlagDurations.Default; | |||||
let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; | let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; | ||||
let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; | let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; | ||||
let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; | let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; | ||||
let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; | let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; | ||||
if (g_IsController) | if (g_IsController) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; | Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; | ||||
Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; | Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; | ||||
Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); | Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); | ||||
Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; | Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; | ||||
Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; | Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; | ||||
Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; | Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; | ||||
Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; | Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; | ||||
Engine.GetGUIObjectByName("captureTheFlagDuration").selected = captureTheFlagDurationIdx; | |||||
Engine.GetGUIObjectByName("populationCap").selected = popIdx; | Engine.GetGUIObjectByName("populationCap").selected = popIdx; | ||||
Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; | Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; | ||||
Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; | Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; | ||||
Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; | Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; | Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; | ||||
Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; | Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; | ||||
Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); | Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); | ||||
initMapNameList(); | initMapNameList(); | ||||
} | } | ||||
// Can be visible to both host and clients | // Can be visible to both host and clients | ||||
Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.Name[mapSizeIdx] : translateWithContext("map size", "Default"); | Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.Name[mapSizeIdx] : translateWithContext("map size", "Default"); | ||||
Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; | Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; | ||||
Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; | Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; | ||||
Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; | Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; | ||||
Engine.GetGUIObjectByName("captureTheFlagDurationText").caption = g_CaptureTheFlagDurations.Title[captureTheFlagDurationIdx]; | |||||
Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; | Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; | ||||
Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; | Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; | ||||
Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; | Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; | ||||
Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; | Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; | ||||
setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled); | setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled); | ||||
setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); | setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); | ||||
setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap); | setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap); | ||||
setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); | setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); | ||||
setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); | setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); | ||||
setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding); | setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding); | ||||
setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); | setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); | ||||
Engine.GetGUIObjectByName("optionWonderDuration").hidden = | Engine.GetGUIObjectByName("optionWonderDuration").hidden = | ||||
g_GameAttributes.settings.GameType && | g_GameAttributes.settings.GameType && | ||||
g_GameAttributes.settings.GameType != "wonder"; | g_GameAttributes.settings.GameType != "wonder"; | ||||
Engine.GetGUIObjectByName("optionCaptureTheFlagDuration").hidden = | |||||
g_GameAttributes.settings.GameType && | |||||
g_GameAttributes.settings.GameType != "capture_the_flag"; | |||||
Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; | Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; | ||||
Engine.GetGUIObjectByName("lastManStanding").enabled = !mapSettings.LockTeams; | Engine.GetGUIObjectByName("lastManStanding").enabled = !mapSettings.LockTeams; | ||||
Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; | Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; | ||||
Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; | Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; | ||||
// Mapsize completely hidden for non-random maps | // Mapsize completely hidden for non-random maps | ||||
let isRandom = g_GameAttributes.mapType == "random"; | let isRandom = g_GameAttributes.mapType == "random"; | ||||
Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom; | Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom; | ||||
Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController; | Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController; | ||||
Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; | Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; | ||||
hideControl("numPlayers", "numPlayersText", isRandom && g_IsController); | hideControl("numPlayers", "numPlayersText", isRandom && g_IsController); | ||||
let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; | let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; | ||||
for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", | for (let ctrl of ["victoryCondition", "wonderDuration", "captureTheFlagDuration", "populationCap", | ||||
bb: Move `populationCap` to next line to hold lines of "equal" length. | |||||
"startingResources", "ceasefire", "revealMap", | "startingResources", "ceasefire", "revealMap", | ||||
"exploreMap", "disableTreasures", "lockTeams", "lastManStanding"]) | "exploreMap", "disableTreasures", "lockTeams", "lastManStanding"]) | ||||
hideControl(ctrl, ctrl + "Text", notScenario); | hideControl(ctrl, ctrl + "Text", notScenario); | ||||
Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario; | Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario; | ||||
Engine.GetGUIObjectByName("teamResetButton").hidden = !notScenario; | Engine.GetGUIObjectByName("teamResetButton").hidden = !notScenario; | ||||
for (let i = 0; i < g_MaxPlayers; ++i) | for (let i = 0; i < g_MaxPlayers; ++i) | ||||
▲ Show 20 Lines • Show All 562 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Move populationCap to next line to hold lines of "equal" length.