Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | |||||
* ids - Array of identifier strings that indicate the selected value. | * ids - Array of identifier strings that indicate the selected value. | ||||
* default - Returns the index of the default value (not the value itself). | * default - Returns the index of the default value (not the value itself). | ||||
* defined - Whether a value for the setting is actually specified. | * defined - Whether a value for the setting is actually specified. | ||||
* get - The identifier of the currently selected value. | * get - The identifier of the currently selected value. | ||||
* select - Saves and processes the value of the selected index of the ids array. | * select - Saves and processes the value of the selected index of the ids array. | ||||
* | * | ||||
* GUI | * GUI | ||||
* title - The caption shown in the label. | * title - The caption shown in the label. | ||||
* tooltip - A description shown when hovering the option. | * tooltip - A description shown when hovering the dropdown or a specific item. | ||||
* labels - Array of translated strings selectable for this dropdown. | * labels - Array of translated strings selectable for this dropdown. | ||||
* colors - Optional array of colors to tint the according dropdown items with. | * colors - Optional array of colors to tint the according dropdown items with. | ||||
* hidden - If hidden, both the label and dropdown won't be visible. (default: false) | * hidden - If hidden, both the label and dropdown won't be visible. (default: false) | ||||
* enabled - Only the label will be shown if the setting is disabled. (default: true) | * enabled - Only the label will be shown if the setting is disabled. (default: true) | ||||
* autocomplete - Whether to autocomplete translated values of the string. (default: false) | * autocomplete - Whether to autocomplete translated values of the string. (default: false) | ||||
* If disabled, still autocompletes the translated title of the setting. | * If disabled, still autocompletes the translated title of the setting. | ||||
*/ | */ | ||||
var g_Dropdowns = { | var g_Dropdowns = { | ||||
"mapType": { | "mapType": { | ||||
"title": () => translate("Map Type"), | "title": () => translate("Map Type"), | ||||
"tooltip": () => translate("Select a map type."), | "tooltip": (hoverIdx) => g_MapTypes.Description[hoverIdx] || translate("Select a map type."), | ||||
"labels": () => g_MapTypes.Title, | "labels": () => g_MapTypes.Title, | ||||
"ids": () => g_MapTypes.Name, | "ids": () => g_MapTypes.Name, | ||||
"default": () => g_MapTypes.Default, | "default": () => g_MapTypes.Default, | ||||
"defined": () => g_GameAttributes.mapType !== undefined, | "defined": () => g_GameAttributes.mapType !== undefined, | ||||
"get": () => g_GameAttributes.mapType, | "get": () => g_GameAttributes.mapType, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_MapData = {}; | g_MapData = {}; | ||||
g_GameAttributes.mapType = g_MapTypes.Name[idx]; | g_GameAttributes.mapType = g_MapTypes.Name[idx]; | ||||
g_GameAttributes.mapPath = g_MapPath[g_GameAttributes.mapType]; | g_GameAttributes.mapPath = g_MapPath[g_GameAttributes.mapType]; | ||||
delete g_GameAttributes.map; | delete g_GameAttributes.map; | ||||
if (g_GameAttributes.mapType != "scenario") | if (g_GameAttributes.mapType != "scenario") | ||||
g_GameAttributes.settings = { | g_GameAttributes.settings = { | ||||
"PlayerData": g_DefaultPlayerData.slice(0, 4) | "PlayerData": g_DefaultPlayerData.slice(0, 4) | ||||
}; | }; | ||||
reloadMapList(); | reloadMapList(); | ||||
}, | }, | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"mapFilter": { | "mapFilter": { | ||||
"title": () => translate("Map Filter"), | "title": () => translate("Map Filter"), | ||||
"tooltip": () => translate("Select a map filter."), | "tooltip": (hoverIdx) => translate("Select a map filter."), | ||||
"labels": () => g_MapFilterList.name, | "labels": () => g_MapFilterList.name, | ||||
"ids": () => g_MapFilterList.id, | "ids": () => g_MapFilterList.id, | ||||
"default": () => g_MapFilterList.Default, | "default": () => g_MapFilterList.Default, | ||||
"defined": () => g_GameAttributes.mapFilter !== undefined, | "defined": () => g_GameAttributes.mapFilter !== undefined, | ||||
"get": () => g_GameAttributes.mapFilter, | "get": () => g_GameAttributes.mapFilter, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.mapFilter = g_MapFilterList.id[idx]; | g_GameAttributes.mapFilter = g_MapFilterList.id[idx]; | ||||
delete g_GameAttributes.map; | delete g_GameAttributes.map; | ||||
reloadMapList(); | reloadMapList(); | ||||
}, | }, | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"mapSelection": { | "mapSelection": { | ||||
"title": () => translate("Select Map"), | "title": () => translate("Select Map"), | ||||
"tooltip": () => translate("Select a map to play on."), | "tooltip": (hoverIdx) => translate("Select a map to play on."), | ||||
"labels": () => g_MapSelectionList.name, | "labels": () => g_MapSelectionList.name, | ||||
"colors": () => g_MapSelectionList.color, | "colors": () => g_MapSelectionList.color, | ||||
"ids": () => g_MapSelectionList.file, | "ids": () => g_MapSelectionList.file, | ||||
"default": () => 0, | "default": () => 0, | ||||
"defined": () => g_GameAttributes.map !== undefined, | "defined": () => g_GameAttributes.map !== undefined, | ||||
"get": () => g_GameAttributes.map, | "get": () => g_GameAttributes.map, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
selectMap(g_MapSelectionList.file[idx]); | selectMap(g_MapSelectionList.file[idx]); | ||||
}, | }, | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"mapSize": { | "mapSize": { | ||||
"title": () => translate("Map Size"), | "title": () => translate("Map Size"), | ||||
"tooltip": () => translate("Select map size. (Larger sizes may reduce performance.)"), | "tooltip": (hoverIdx) => translate("Select map size. (Larger sizes may reduce performance.)"), | ||||
"labels": () => g_MapSizes.Name, | "labels": () => g_MapSizes.Name, | ||||
"ids": () => g_MapSizes.Tiles, | "ids": () => g_MapSizes.Tiles, | ||||
"default": () => g_MapSizes.Default, | "default": () => g_MapSizes.Default, | ||||
"defined": () => g_GameAttributes.settings.Size !== undefined, | "defined": () => g_GameAttributes.settings.Size !== undefined, | ||||
"get": () => g_GameAttributes.settings.Size, | "get": () => g_GameAttributes.settings.Size, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.Size = g_MapSizes.Tiles[idx]; | g_GameAttributes.settings.Size = g_MapSizes.Tiles[idx]; | ||||
}, | }, | ||||
"hidden": () => g_GameAttributes.mapType != "random", | "hidden": () => g_GameAttributes.mapType != "random", | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"numPlayers": { | "numPlayers": { | ||||
"title": () => translate("Number of Players"), | "title": () => translate("Number of Players"), | ||||
"tooltip": () => translate("Select number of players."), | "tooltip": (hoverIdx) => translate("Select number of players."), | ||||
"labels": () => g_NumPlayersList, | "labels": () => g_NumPlayersList, | ||||
"ids": () => g_NumPlayersList, | "ids": () => g_NumPlayersList, | ||||
"default": () => g_MaxPlayers - 1, | "default": () => g_MaxPlayers - 1, | ||||
"defined": () => g_GameAttributes.settings.PlayerData !== undefined, | "defined": () => g_GameAttributes.settings.PlayerData !== undefined, | ||||
"get": () => g_GameAttributes.settings.PlayerData.length, | "get": () => g_GameAttributes.settings.PlayerData.length, | ||||
"enabled": () => g_GameAttributes.mapType == "random", | "enabled": () => g_GameAttributes.mapType == "random", | ||||
"select": (idx) => { | "select": (idx) => { | ||||
let num = idx + 1; | let num = idx + 1; | ||||
let pData = g_GameAttributes.settings.PlayerData; | let pData = g_GameAttributes.settings.PlayerData; | ||||
g_GameAttributes.settings.PlayerData = | g_GameAttributes.settings.PlayerData = | ||||
num > pData.length ? | num > pData.length ? | ||||
pData.concat(g_DefaultPlayerData.slice(pData.length, num)) : | pData.concat(g_DefaultPlayerData.slice(pData.length, num)) : | ||||
pData.slice(0, num); | pData.slice(0, num); | ||||
unassignInvalidPlayers(num); | unassignInvalidPlayers(num); | ||||
sanitizePlayerData(g_GameAttributes.settings.PlayerData); | sanitizePlayerData(g_GameAttributes.settings.PlayerData); | ||||
}, | }, | ||||
}, | }, | ||||
"populationCap": { | "populationCap": { | ||||
"title": () => translate("Population Cap"), | "title": () => translate("Population Cap"), | ||||
"tooltip": () => translate("Select population cap."), | "tooltip": (hoverIdx) => translate("Select population cap."), | ||||
"labels": () => g_PopulationCapacities.Title, | "labels": () => g_PopulationCapacities.Title, | ||||
"ids": () => g_PopulationCapacities.Population, | "ids": () => g_PopulationCapacities.Population, | ||||
"default": () => g_PopulationCapacities.Default, | "default": () => g_PopulationCapacities.Default, | ||||
"defined": () => g_GameAttributes.settings.PopulationCap !== undefined, | "defined": () => g_GameAttributes.settings.PopulationCap !== undefined, | ||||
"get": () => g_GameAttributes.settings.PopulationCap, | "get": () => g_GameAttributes.settings.PopulationCap, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[idx]; | g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[idx]; | ||||
}, | }, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
}, | }, | ||||
"startingResources": { | "startingResources": { | ||||
"title": () => translate("Starting Resources"), | "title": () => translate("Starting Resources"), | ||||
"tooltip": () => translate("Select the game's starting resources."), | "tooltip": (hoverIdx) => { | ||||
return hoverIdx >= 0 ? | |||||
sprintf(translate("Initial amount of each resource: %(resources)s."), { | |||||
"resources": g_StartingResources.Resources[hoverIdx] | |||||
}) : | |||||
translate("Select the game's starting resources."); | |||||
}, | |||||
"labels": () => g_StartingResources.Title, | "labels": () => g_StartingResources.Title, | ||||
"ids": () => g_StartingResources.Resources, | "ids": () => g_StartingResources.Resources, | ||||
"default": () => g_StartingResources.Default, | "default": () => g_StartingResources.Default, | ||||
"defined": () => g_GameAttributes.settings.StartingResources !== undefined, | "defined": () => g_GameAttributes.settings.StartingResources !== undefined, | ||||
"get": () => g_GameAttributes.settings.StartingResources, | "get": () => g_GameAttributes.settings.StartingResources, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[idx]; | g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[idx]; | ||||
}, | }, | ||||
"hidden": () => g_GameAttributes.mapType == "scenario", | "hidden": () => g_GameAttributes.mapType == "scenario", | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"ceasefire": { | "ceasefire": { | ||||
"title": () => translate("Ceasefire"), | "title": () => translate("Ceasefire"), | ||||
"tooltip": () => translate("Set time where no attacks are possible."), | "tooltip": (hoverIdx) => translate("Set time where no attacks are possible."), | ||||
"labels": () => g_Ceasefire.Title, | "labels": () => g_Ceasefire.Title, | ||||
"ids": () => g_Ceasefire.Duration, | "ids": () => g_Ceasefire.Duration, | ||||
"default": () => g_Ceasefire.Default, | "default": () => g_Ceasefire.Default, | ||||
"defined": () => g_GameAttributes.settings.Ceasefire !== undefined, | "defined": () => g_GameAttributes.settings.Ceasefire !== undefined, | ||||
"get": () => g_GameAttributes.settings.Ceasefire, | "get": () => g_GameAttributes.settings.Ceasefire, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[idx]; | g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[idx]; | ||||
}, | }, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
}, | }, | ||||
"victoryCondition": { | "victoryCondition": { | ||||
"title": () => translate("Victory Condition"), | "title": () => translate("Victory Condition"), | ||||
"tooltip": () => translate("Select victory condition."), | "tooltip": (hoverIdx) => g_VictoryConditions.Description[hoverIdx] || translate("Select victory condition."), | ||||
"labels": () => g_VictoryConditions.Title, | "labels": () => g_VictoryConditions.Title, | ||||
"ids": () => g_VictoryConditions.Name, | "ids": () => g_VictoryConditions.Name, | ||||
"default": () => g_VictoryConditions.Default, | "default": () => g_VictoryConditions.Default, | ||||
"defined": () => g_GameAttributes.settings.GameType !== undefined, | "defined": () => g_GameAttributes.settings.GameType !== undefined, | ||||
"get": () => g_GameAttributes.settings.GameType, | "get": () => g_GameAttributes.settings.GameType, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.GameType = g_VictoryConditions.Name[idx]; | g_GameAttributes.settings.GameType = g_VictoryConditions.Name[idx]; | ||||
g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[idx]; | g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[idx]; | ||||
}, | }, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"relicCount": { | "relicCount": { | ||||
"title": () => translate("Relic Count"), | "title": () => translate("Relic Count"), | ||||
"tooltip": () => translate("Total number of relics spawned on the map."), | "tooltip": (hoverIdx) => translate("Total number of relics spawned on the map."), | ||||
"labels": () => g_RelicCountList, | "labels": () => g_RelicCountList, | ||||
"ids": () => g_RelicCountList, | "ids": () => g_RelicCountList, | ||||
"default": () => g_RelicCountList.indexOf(5), | "default": () => g_RelicCountList.indexOf(5), | ||||
"defined": () => g_GameAttributes.settings.RelicCount !== undefined, | "defined": () => g_GameAttributes.settings.RelicCount !== undefined, | ||||
"get": () => g_GameAttributes.settings.RelicCount, | "get": () => g_GameAttributes.settings.RelicCount, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.RelicCount = g_RelicCountList[idx]; | g_GameAttributes.settings.RelicCount = g_RelicCountList[idx]; | ||||
}, | }, | ||||
"hidden": () => g_GameAttributes.settings.GameType != "capture_the_relic", | "hidden": () => g_GameAttributes.settings.GameType != "capture_the_relic", | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
}, | }, | ||||
"victoryDuration": { | "victoryDuration": { | ||||
"title": () => translate("Victory Duration"), | "title": () => translate("Victory Duration"), | ||||
"tooltip": () => translate("Number of minutes until the player has won."), | "tooltip": (hoverIdx) => translate("Number of minutes until the player has won."), | ||||
"labels": () => g_VictoryDurations.Title, | "labels": () => g_VictoryDurations.Title, | ||||
"ids": () => g_VictoryDurations.Duration, | "ids": () => g_VictoryDurations.Duration, | ||||
"default": () => g_VictoryDurations.Default, | "default": () => g_VictoryDurations.Default, | ||||
"defined": () => g_GameAttributes.settings.VictoryDuration !== undefined, | "defined": () => g_GameAttributes.settings.VictoryDuration !== undefined, | ||||
"get": () => g_GameAttributes.settings.VictoryDuration, | "get": () => g_GameAttributes.settings.VictoryDuration, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.settings.VictoryDuration = g_VictoryDurations.Duration[idx]; | g_GameAttributes.settings.VictoryDuration = g_VictoryDurations.Duration[idx]; | ||||
}, | }, | ||||
"hidden": () => | "hidden": () => | ||||
g_GameAttributes.settings.GameType != "wonder" && | g_GameAttributes.settings.GameType != "wonder" && | ||||
g_GameAttributes.settings.GameType != "capture_the_relic", | g_GameAttributes.settings.GameType != "capture_the_relic", | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
}, | }, | ||||
"gameSpeed": { | "gameSpeed": { | ||||
"title": () => translate("Game Speed"), | "title": () => translate("Game Speed"), | ||||
"tooltip": () => translate("Select game speed."), | "tooltip": (hoverIdx) => translate("Select game speed."), | ||||
"labels": () => g_GameSpeeds.Title, | "labels": () => g_GameSpeeds.Title, | ||||
"ids": () => g_GameSpeeds.Speed, | "ids": () => g_GameSpeeds.Speed, | ||||
"default": () => g_GameSpeeds.Default, | "default": () => g_GameSpeeds.Default, | ||||
"defined": () => g_GameAttributes.gameSpeed !== undefined, | "defined": () => g_GameAttributes.gameSpeed !== undefined, | ||||
"get": () => g_GameAttributes.gameSpeed, | "get": () => g_GameAttributes.gameSpeed, | ||||
"select": (idx) => { | "select": (idx) => { | ||||
g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[idx]; | g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[idx]; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | "cancelGame": { | ||||
"tooltip": () => | "tooltip": () => | ||||
Engine.HasXmppClient() ? | Engine.HasXmppClient() ? | ||||
translate("Return to the lobby.") : | translate("Return to the lobby.") : | ||||
translate("Return to the main menu."), | translate("Return to the main menu."), | ||||
}, | }, | ||||
"startGame": { | "startGame": { | ||||
"caption": () => | "caption": () => | ||||
g_IsController ? translate("Start game!") : g_ReadyData[g_IsReady].caption, | g_IsController ? translate("Start game!") : g_ReadyData[g_IsReady].caption, | ||||
"tooltip": () => | "tooltip": (hoverIdx) => | ||||
!g_IsController ? | !g_IsController ? | ||||
g_ReadyData[g_IsReady].tooltip : | g_ReadyData[g_IsReady].tooltip : | ||||
!g_IsNetworked || Object.keys(g_PlayerAssignments).every(guid => | !g_IsNetworked || Object.keys(g_PlayerAssignments).every(guid => | ||||
g_PlayerAssignments[guid].status || g_PlayerAssignments[guid].player == -1) ? | g_PlayerAssignments[guid].status || g_PlayerAssignments[guid].player == -1) ? | ||||
translate("Start a new game with the current settings.") : | translate("Start a new game with the current settings.") : | ||||
translate("Start a new game with the current settings (disabled until all players are ready)"), | translate("Start a new game with the current settings (disabled until all players are ready)"), | ||||
"enabled": () => !g_IsController || | "enabled": () => !g_IsController || | ||||
Object.keys(g_PlayerAssignments).every(guid => g_PlayerAssignments[guid].status || | Object.keys(g_PlayerAssignments).every(guid => g_PlayerAssignments[guid].status || | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | if (!g_IsController || | ||||
data.enabled && !data.enabled(idx)) | data.enabled && !data.enabled(idx)) | ||||
return; | return; | ||||
data.select(this.selected, idx); | data.select(this.selected, idx); | ||||
supplementDefaults(); | supplementDefaults(); | ||||
updateGameAttributes(); | updateGameAttributes(); | ||||
}; | }; | ||||
if (data.tooltip) | |||||
dropdown.onHoverChange = function() { | |||||
this.tooltip = data.tooltip(this.hovered); | |||||
}; | |||||
} | } | ||||
function initPlayerDropdowns(name) | function initPlayerDropdowns(name) | ||||
{ | { | ||||
for (let i = 0; i < g_MaxPlayers; ++i) | for (let i = 0; i < g_MaxPlayers; ++i) | ||||
initDropdown(name, i); | initDropdown(name, i); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,126 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator