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_VictoryDurations = prepareForDropdown(g_Settings && g_Settings.VictoryDurations); | ||||
/** | /** | ||||
* 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 281 Lines • ▼ Show 20 Lines | if (g_IsController) | ||||
g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined; | g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined; | ||||
initMapNameList(); | initMapNameList(); | ||||
initNumberOfPlayers(); | initNumberOfPlayers(); | ||||
initGameSpeed(); | initGameSpeed(); | ||||
initPopulationCaps(); | initPopulationCaps(); | ||||
initStartingResources(); | initStartingResources(); | ||||
initCeasefire(); | initCeasefire(); | ||||
initWonderDurations(); | |||||
initVictoryConditions(); | initVictoryConditions(); | ||||
initVictoryDurations(); | |||||
initMapSizes(); | initMapSizes(); | ||||
initRadioButtons(); | initRadioButtons(); | ||||
} | } | ||||
else | else | ||||
hideControls(); | hideControls(); | ||||
initMultiplayerSettings(); | initMultiplayerSettings(); | ||||
initPlayerAssignments(); | initPlayerAssignments(); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
function saveSPTipsSetting() | function saveSPTipsSetting() | ||||
{ | { | ||||
let enabled = String(Engine.GetGUIObjectByName("displaySPTips").checked); | let enabled = String(Engine.GetGUIObjectByName("displaySPTips").checked); | ||||
Engine.ConfigDB_CreateValue("user", "gui.gamesetup.enabletips", enabled); | Engine.ConfigDB_CreateValue("user", "gui.gamesetup.enabletips", enabled); | ||||
Engine.ConfigDB_WriteValueToFile("user", "gui.gamesetup.enabletips", enabled, "config/user.cfg"); | Engine.ConfigDB_WriteValueToFile("user", "gui.gamesetup.enabletips", enabled, "config/user.cfg"); | ||||
} | } | ||||
/** | /** | ||||
* Remove empty space in case of hidden options (like cheats, rating or wonder duration) | * Remove empty space in case of hidden options (like cheats, rating or victory duration) | ||||
*/ | */ | ||||
function resizeMoreOptionsWindow() | function resizeMoreOptionsWindow() | ||||
{ | { | ||||
const elementHeight = 30; | const elementHeight = 30; | ||||
let yPos = undefined; | let yPos = undefined; | ||||
for (let guiOption of Engine.GetGUIObjectByName("moreOptions").children) | for (let guiOption of Engine.GetGUIObjectByName("moreOptions").children) | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | if (this.selected != -1) | ||||
g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[this.selected]; | g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[this.selected]; | ||||
} | } | ||||
updateGameAttributes(); | updateGameAttributes(); | ||||
}; | }; | ||||
victoryConditions.selected = g_VictoryConditions.Default; | victoryConditions.selected = g_VictoryConditions.Default; | ||||
} | } | ||||
function initWonderDurations() | function initVictoryDurations() | ||||
{ | { | ||||
let wonderConditions = Engine.GetGUIObjectByName("wonderDuration"); | let victoryDurationsConditions = Engine.GetGUIObjectByName("victoryDuration"); | ||||
wonderConditions.list = g_WonderDurations.Title; | victoryDurationsConditions.list = g_VictoryDurations.Title; | ||||
wonderConditions.list_data = g_WonderDurations.Duration; | victoryDurationsConditions.list_data = g_VictoryDurations.Duration; | ||||
wonderConditions.onSelectionChange = function() | victoryDurationsConditions.onSelectionChange = function() | ||||
{ | { | ||||
if (this.selected != -1) | if (this.selected != -1) | ||||
g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected]; | g_GameAttributes.settings.VictoryDuration = g_VictoryDurations.Duration[this.selected]; | ||||
updateGameAttributes(); | updateGameAttributes(); | ||||
}; | }; | ||||
wonderConditions.selected = g_WonderDurations.Default; | victoryDurationsConditions.selected = g_VictoryDurations.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() { | ||||
▲ Show 20 Lines • Show All 731 Lines • ▼ Show 20 Lines | function selectMap(name) | ||||
{ | { | ||||
let victoryIdx = g_VictoryConditions.Name.indexOf(mapSettings.GameType || "") != -1 ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; | let victoryIdx = g_VictoryConditions.Name.indexOf(mapSettings.GameType || "") != -1 ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; | ||||
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.VictoryDuration; | ||||
delete g_GameAttributes.settings.LastManStanding; | delete g_GameAttributes.settings.LastManStanding; | ||||
} | } | ||||
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; | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | function updateGUIObjects() | ||||
let mapName = g_GameAttributes.map || ""; | let mapName = g_GameAttributes.map || ""; | ||||
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 victoryDurationIdx = mapSettings.VictoryDuration !== undefined ? g_VictoryDurations.Duration.indexOf(mapSettings.VictoryDuration) : g_VictoryDurations.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("victoryDuration").selected = victoryDurationIdx; | ||||
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("victoryDurationText").caption = g_VictoryDurations.Title[victoryDurationIdx]; | ||||
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("disableSpies", "disableSpiesText", !!mapSettings.DisableSpies); | setGUIBoolean("disableSpies", "disableSpiesText", !!mapSettings.DisableSpies); | ||||
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("optionVictoryDuration").hidden = | ||||
g_GameAttributes.settings.GameType && | g_GameAttributes.settings.GameType && | ||||
g_GameAttributes.settings.GameType != "wonder"; | g_GameAttributes.settings.GameType != "wonder" && g_GameAttributes.settings.GameType != "capture_the_relic"; | ||||
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", "victoryDuration", "populationCap", | ||||
bb: Move `populationCap` to next line to hold lines of "equal" length. | |||||
"startingResources", "ceasefire", "revealMap", | "startingResources", "ceasefire", "revealMap", | ||||
"exploreMap", "disableTreasures", "disableSpies", "lockTeams", "lastManStanding"]) | "exploreMap", "disableTreasures", "disableSpies", "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.