Changeset View
Standalone View
binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Initializes some globals without touching the GUI. | * Initializes some globals without touching the GUI. | ||||
* | * | ||||
* @param {Object} attribs - context data sent by the lobby / mainmenu | * @param {Object} attribs - context data sent by the lobby / mainmenu | ||||
*/ | */ | ||||
function init(attribs) | function init(attribs) | ||||
{ | { | ||||
if (!g_Settings) | if (!g_Settings) | ||||
{ | { | ||||
elexis: (This will keep the setting saved even if the victory condition is changed again, but fixing… | |||||
Not Done Inline Actions(Yes, also an issue for RelicCount and VictoryDuration, and it's not so nice when these are written to the commands.txt for no reason.) Sandarac: (Yes, also an issue for `RelicCount` and `VictoryDuration`, and it's not so nice when these are… | |||||
cancelSetup(); | cancelSetup(); | ||||
return; | return; | ||||
} | } | ||||
if (["offline", "server", "client"].indexOf(attribs.type) == -1) | if (["offline", "server", "client"].indexOf(attribs.type) == -1) | ||||
{ | { | ||||
error("Unexpected 'type' in gamesetup init: " + attribs.type); | error("Unexpected 'type' in gamesetup init: " + attribs.type); | ||||
cancelSetup(); | cancelSetup(); | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
function initRadioButtons() | function initRadioButtons() | ||||
{ | { | ||||
let options = { | let options = { | ||||
"RevealMap": "revealMap", | "RevealMap": "revealMap", | ||||
"ExploreMap": "exploreMap", | "ExploreMap": "exploreMap", | ||||
"DisableTreasures": "disableTreasures", | "DisableTreasures": "disableTreasures", | ||||
"LockTeams": "lockTeams", | "LockTeams": "lockTeams", | ||||
"LastManStanding" : "lastManStanding", | "LastManStanding": "lastManStanding", | ||||
"RegicideGarrison": "regicideGarrison", | |||||
"CheatsEnabled": "enableCheats" | "CheatsEnabled": "enableCheats" | ||||
}; | }; | ||||
Object.keys(options).forEach(attribute => { | Object.keys(options).forEach(attribute => { | ||||
Engine.GetGUIObjectByName(options[attribute]).onPress = function() { | Engine.GetGUIObjectByName(options[attribute]).onPress = function() { | ||||
g_GameAttributes.settings[attribute] = this.checked; | g_GameAttributes.settings[attribute] = this.checked; | ||||
updateGameAttributes(); | updateGameAttributes(); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 705 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.RegicideGarrison; | |||||
Not Done Inline Actionsdelete is slow and messes up some structure information internally, if we have to do that (which I think we do here, but this diff is lacking context) we might want to reorder the structure so we delete the last property added (or defined). leper: `delete` is slow and messes up some structure information internally, if we have to do that… | |||||
Not Done Inline ActionsContext should be clear, when changing the map, these settings can be persisted unless it is a scenario map. elexis: Context should be clear, when changing the map, these settings can be persisted unless it is a… | |||||
Not Done Inline Actions(Correct, must be in this check because it's a user setting, as opposed to the properties deleted in the loop above.) elexis: (Correct, must be in this check because it's a user setting, as opposed to the properties… | |||||
} | } | ||||
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 168 Lines • ▼ Show 20 Lines | function updateGUIObjects() | ||||
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("regicideGarrison", "regicideGarrisonText", !!mapSettings.RegicideGarrison); | |||||
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("optionRegicideGarrison").hidden = | |||||
g_GameAttributes.settings.GameType && | |||||
g_GameAttributes.settings.GameType != "regicide"; | |||||
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", "populationCap", | ||||
"startingResources", "ceasefire", "revealMap", | "startingResources", "ceasefire", "revealMap", | ||||
"exploreMap", "disableTreasures", "lockTeams", "lastManStanding"]) | "exploreMap", "disableTreasures", "lockTeams", | ||||
"lastManStanding", "regicideGarrison"]) | |||||
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) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("playerBox["+i+"]").hidden = (i >= numPlayers); | Engine.GetGUIObjectByName("playerBox["+i+"]").hidden = (i >= numPlayers); | ||||
▲ Show 20 Lines • Show All 560 Lines • Show Last 20 Lines |
(This will keep the setting saved even if the victory condition is changed again, but fixing this is out-of-scope as it isn't trivial.)