Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | var g_FormatChatMessage = { | ||||
"chat": (msg, user) => sprintf(translate("%(username)s %(message)s"), { | "chat": (msg, user) => sprintf(translate("%(username)s %(message)s"), { | ||||
"username": senderFont(sprintf(translate("<%(username)s>"), { "username": user })), | "username": senderFont(sprintf(translate("<%(username)s>"), { "username": user })), | ||||
"message": escapeText(msg.text || "") | "message": escapeText(msg.text || "") | ||||
}), | }), | ||||
"ready": (msg, user) => sprintf(g_ReadyData[msg.status].chat, { "username": user }), | "ready": (msg, user) => sprintf(g_ReadyData[msg.status].chat, { "username": user }), | ||||
"clientlist": (msg, user) => getUsernameList(), | "clientlist": (msg, user) => getUsernameList(), | ||||
}; | }; | ||||
var g_MapFilterList = prepareForDropdown([ | var g_MapFilters = [ | ||||
{ | { | ||||
"id": "default", | "id": "default", | ||||
"name": translateWithContext("map filter", "Default"), | "name": translateWithContext("map filter", "Default"), | ||||
"tooltip": translateWithContext("map filter", "All maps except naval and demo maps."), | "tooltip": translateWithContext("map filter", "All maps except naval and demo maps."), | ||||
"filter": mapKeywords => mapKeywords.every(keyword => ["naval", "demo", "hidden"].indexOf(keyword) == -1), | "filter": mapKeywords => mapKeywords.every(keyword => ["naval", "demo", "hidden"].indexOf(keyword) == -1), | ||||
"Default": true | "Default": true | ||||
}, | }, | ||||
{ | { | ||||
Show All 21 Lines | var g_MapFilters = [ | ||||
"filter": mapKeywords => mapKeywords.indexOf("trigger") != -1 | "filter": mapKeywords => mapKeywords.indexOf("trigger") != -1 | ||||
}, | }, | ||||
{ | { | ||||
"id": "all", | "id": "all", | ||||
"name": translate("All Maps"), | "name": translate("All Maps"), | ||||
"tooltip": translateWithContext("map filter", "Every map of the chosen maptype."), | "tooltip": translateWithContext("map filter", "Every map of the chosen maptype."), | ||||
"filter": mapKeywords => true | "filter": mapKeywords => true | ||||
}, | }, | ||||
]); | ]; | ||||
/** | |||||
* This contains only filters that have at least one map matching them. | |||||
*/ | |||||
var g_MapFilterList; | |||||
/** | /** | ||||
* Whether this is a single- or multiplayer match. | * Whether this is a single- or multiplayer match. | ||||
*/ | */ | ||||
var g_IsNetworked; | var g_IsNetworked; | ||||
/** | /** | ||||
* Is this user in control of game settings (i.e. singleplayer or host of a multiplayergame). | * Is this user in control of game settings (i.e. singleplayer or host of a multiplayergame). | ||||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | "select": (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(); | reloadMapFilterList(); | ||||
}, | }, | ||||
"autocomplete": true, | "autocomplete": true, | ||||
}, | }, | ||||
"mapFilter": { | "mapFilter": { | ||||
"title": () => translate("Map Filter"), | "title": () => translate("Map Filter"), | ||||
"tooltip": (hoverIdx) => g_MapFilterList.tooltip[hoverIdx] || translate("Select a map filter."), | "tooltip": (hoverIdx) => g_MapFilterList.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_MapFilterList.id.indexOf(g_GameAttributes.mapFilter || "") != -1, | ||||
"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, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 908 Lines • ▼ Show 20 Lines | function getMapPreview(map) | ||||
let mapData = loadMapData(map); | let mapData = loadMapData(map); | ||||
if (!mapData || !mapData.settings || !mapData.settings.Preview) | if (!mapData || !mapData.settings || !mapData.settings.Preview) | ||||
return "nopreview.png"; | return "nopreview.png"; | ||||
return mapData.settings.Preview; | return mapData.settings.Preview; | ||||
} | } | ||||
/** | /** | ||||
* Initialize the dropdown containing all maps for the selected maptype and mapfilter. | * Filter maps with filterFunc and by chosen map type. | ||||
* | |||||
* @param {function} filterFunc - Filter function that should be applied. | |||||
* @return {Array} the maps that match the filterFunc and the chosen map type. | |||||
*/ | */ | ||||
function reloadMapList() | function getFilteredMaps(filterFunc) | ||||
{ | { | ||||
if (!g_MapPath[g_GameAttributes.mapType]) | if (!g_MapPath[g_GameAttributes.mapType]) | ||||
{ | { | ||||
error("Unexpected map type: " + g_GameAttributes.mapType); | error("Unexpected map type: " + g_GameAttributes.mapType); | ||||
return; | return []; | ||||
} | } | ||||
let mapFiles = g_GameAttributes.mapType == "random" ? | let mapFiles = g_GameAttributes.mapType == "random" ? | ||||
getJSONFileList(g_GameAttributes.mapPath) : | getJSONFileList(g_GameAttributes.mapPath) : | ||||
getXMLFileList(g_GameAttributes.mapPath); | getXMLFileList(g_GameAttributes.mapPath); | ||||
// Apply map filter, if any defined | let maps = []; | ||||
let mapList = []; | |||||
// TODO: Should verify these are valid maps before adding to list | // TODO: Should verify these are valid maps before adding to list | ||||
for (let mapFile of mapFiles) | for (let mapFile of mapFiles) | ||||
{ | { | ||||
let file = g_GameAttributes.mapPath + mapFile; | let file = g_GameAttributes.mapPath + mapFile; | ||||
let mapData = loadMapData(file); | let mapData = loadMapData(file); | ||||
let filterID = g_MapFilterList.id.findIndex(id => id == g_GameAttributes.mapFilter); | |||||
let mapFilter = g_MapFilterList.filter[filterID] || undefined; | |||||
if (!mapData.settings || mapFilter && !mapFilter(mapData.settings.Keywords || [])) | if (!mapData.settings || filterFunc && !filterFunc(mapData.settings.Keywords || [])) | ||||
continue; | continue; | ||||
mapList.push({ | maps.push({ | ||||
"file": file, | "file": file, | ||||
"name": translate(getMapDisplayName(file)), | "name": translate(getMapDisplayName(file)), | ||||
"color": g_ColorRegular, | "color": g_ColorRegular, | ||||
"description": translate(mapData.settings.Description) | "description": translate(mapData.settings.Description) | ||||
}); | }); | ||||
} | } | ||||
return maps; | |||||
} | |||||
mapList = mapList.sort(sortNameIgnoreCase); | /** | ||||
* Initialize the dropdown containing all map filters for the selected maptype. | |||||
*/ | |||||
function reloadMapFilterList() | |||||
{ | |||||
g_MapFilterList = prepareForDropdown(g_MapFilters.filter( | |||||
mapFilter => getFilteredMaps(mapFilter.filter).length | |||||
)); | |||||
initDropdown("mapFilter"); | |||||
reloadMapList(); | |||||
} | |||||
/** | |||||
* Initialize the dropdown containing all maps for the selected maptype and mapfilter. | |||||
*/ | |||||
function reloadMapList() | |||||
{ | |||||
let filterID = g_MapFilterList.id.findIndex(id => id == g_GameAttributes.mapFilter); | |||||
let filterFunc = g_MapFilterList.filter[filterID]; | |||||
let mapList = getFilteredMaps(filterFunc).sort(sortNameIgnoreCase); | |||||
if (g_GameAttributes.mapType == "random") | if (g_GameAttributes.mapType == "random") | ||||
mapList.unshift({ | mapList.unshift({ | ||||
"file": "random", | "file": "random", | ||||
"name": translateWithContext("map selection", "Random"), | "name": translateWithContext("map selection", "Random"), | ||||
"color": g_ColorRandom, | "color": g_ColorRandom, | ||||
"description": "Picks one of the maps of the given maptype and filter at random." | "description": "Picks one of the maps of the given maptype and filter at random." | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (newMapData && newMapData.settings) | ||||
if (playerData) | if (playerData) | ||||
mapSettings.PlayerData = playerData; | mapSettings.PlayerData = playerData; | ||||
} | } | ||||
if (mapSettings.PlayerData) | if (mapSettings.PlayerData) | ||||
sanitizePlayerData(mapSettings.PlayerData); | sanitizePlayerData(mapSettings.PlayerData); | ||||
// Reload, as the maptype or mapfilter might have changed | // Reload, as the maptype or mapfilter might have changed | ||||
reloadMapList(); | reloadMapFilterList(); | ||||
g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); | g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); | ||||
Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); | Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); | ||||
supplementDefaults(); | supplementDefaults(); | ||||
g_IsInGuiUpdate = false; | g_IsInGuiUpdate = false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 365 Lines • ▼ Show 20 Lines | |||||
* Don't set any attributes here, just show the changes in the GUI. | * Don't set any attributes here, just show the changes in the GUI. | ||||
* | * | ||||
* Unless the mapsettings don't specify a property and the user didn't set it in g_GameAttributes previously. | * Unless the mapsettings don't specify a property and the user didn't set it in g_GameAttributes previously. | ||||
*/ | */ | ||||
function updateGUIObjects() | function updateGUIObjects() | ||||
{ | { | ||||
g_IsInGuiUpdate = true; | g_IsInGuiUpdate = true; | ||||
reloadMapList(); | reloadMapFilterList(); | ||||
updatePlayerAssignmentChoices(); | updatePlayerAssignmentChoices(); | ||||
// Hide exceeding dropdowns and checkboxes | // Hide exceeding dropdowns and checkboxes | ||||
for (let panel in g_OptionOrderGUI) | for (let panel in g_OptionOrderGUI) | ||||
for (let child of Engine.GetGUIObjectByName(panel + "Options").children) | for (let child of Engine.GetGUIObjectByName(panel + "Options").children) | ||||
child.hidden = true; | child.hidden = true; | ||||
// Show the relevant ones | // Show the relevant ones | ||||
▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator