Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
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). | ||||
*/ | */ | ||||
var g_IsController; | var g_IsController; | ||||
/** | /** | ||||
* Whether this is a tutorial. | |||||
*/ | |||||
var g_IsTutorial; | |||||
/** | |||||
* To report the game to the lobby bot. | * To report the game to the lobby bot. | ||||
*/ | */ | ||||
var g_ServerName; | var g_ServerName; | ||||
var g_ServerPort; | var g_ServerPort; | ||||
/** | /** | ||||
* States whether the GUI is currently updated in response to network messages instead of user input | * States whether the GUI is currently updated in response to network messages instead of user input | ||||
* and therefore shouldn't send further messages to the network. | * and therefore shouldn't send further messages to the network. | ||||
▲ Show 20 Lines • Show All 655 Lines • ▼ Show 20 Lines | function init(attribs) | ||||
{ | { | ||||
error("Unexpected 'type' in gamesetup init: " + attribs.type); | error("Unexpected 'type' in gamesetup init: " + attribs.type); | ||||
cancelSetup(); | cancelSetup(); | ||||
return; | return; | ||||
} | } | ||||
g_IsNetworked = attribs.type != "offline"; | g_IsNetworked = attribs.type != "offline"; | ||||
g_IsController = attribs.type != "client"; | g_IsController = attribs.type != "client"; | ||||
g_IsTutorial = attribs.tutorial && attribs.tutorial == true; | |||||
g_ServerName = attribs.serverName; | g_ServerName = attribs.serverName; | ||||
g_ServerPort = attribs.serverPort; | g_ServerPort = attribs.serverPort; | ||||
if (!g_IsNetworked) | if (!g_IsNetworked) | ||||
g_PlayerAssignments = { | g_PlayerAssignments = { | ||||
"local": { | "local": { | ||||
"name": singleplayerName(), | "name": singleplayerName(), | ||||
"player": 1 | "player": 1 | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | function initGUIObjects() | ||||
resizeMoreOptionsWindow(); | resizeMoreOptionsWindow(); | ||||
initSPTips(); | initSPTips(); | ||||
loadPersistMatchSettings(); | loadPersistMatchSettings(); | ||||
updateGameAttributes(); | updateGameAttributes(); | ||||
if (g_IsTutorial) | |||||
{ | |||||
launchTutorial(); | |||||
return; | |||||
} | |||||
Engine.GetGUIObjectByName("loadingWindow").hidden = true; | Engine.GetGUIObjectByName("loadingWindow").hidden = true; | ||||
Engine.GetGUIObjectByName("setupWindow").hidden = false; | Engine.GetGUIObjectByName("setupWindow").hidden = false; | ||||
if (g_IsNetworked) | if (g_IsNetworked) | ||||
Engine.GetGUIObjectByName("chatInput").focus(); | Engine.GetGUIObjectByName("chatInput").focus(); | ||||
} | } | ||||
/** | /** | ||||
* The main options (like map selection) and player arrays have specific names. | * The main options (like map selection) and player arrays have specific names. | ||||
* Options in the "More Options" dialog use a generic name. | * Options in the "More Options" dialog use a generic name. | ||||
*/ | */ | ||||
function getGUIObjectNameFromSetting(name) | function getGUIObjectNameFromSetting(name) | ||||
{ | { | ||||
for (let panel in g_OptionOrderGUI) | for (let panel in g_OptionOrderGUI) | ||||
for (let type in g_OptionOrderGUI[panel]) | for (let type in g_OptionOrderGUI[panel]) | ||||
{ | { | ||||
let idx = g_OptionOrderGUI[panel][type].indexOf(name); | let idx = g_OptionOrderGUI[panel][type].indexOf(name); | ||||
if (idx != -1) | if (idx != -1) | ||||
return [panel + "Option" + type, "[" + idx + "]"] | return [panel + "Option" + type, "[" + idx + "]"]; | ||||
} | } | ||||
// Assume there is a GUI object with exactly that setting name | // Assume there is a GUI object with exactly that setting name | ||||
return [name, ""]; | return [name, ""]; | ||||
} | } | ||||
function initDropdown(name, idx) | function initDropdown(name, idx) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | for (let mapFile of mapFiles) | ||||
mapList.push({ | mapList.push({ | ||||
"file": file, | "file": file, | ||||
"color": g_ColorRegular, | "color": g_ColorRegular, | ||||
"name": translate(getMapDisplayName(file)) | "name": translate(getMapDisplayName(file)) | ||||
}); | }); | ||||
} | } | ||||
mapList = mapList.sort(sortNameIgnoreCase) | mapList = mapList.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 | ||||
}); | }); | ||||
Show All 17 Lines | function loadMapData(name) | ||||
return g_MapData[name]; | return g_MapData[name]; | ||||
} | } | ||||
/** | /** | ||||
* Sets the gameattributes the way they were the last time the user left the gamesetup. | * Sets the gameattributes the way they were the last time the user left the gamesetup. | ||||
*/ | */ | ||||
function loadPersistMatchSettings() | function loadPersistMatchSettings() | ||||
{ | { | ||||
if (!g_IsController || Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true") | if (!g_IsController || Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true" || g_IsTutorial) | ||||
return; | return; | ||||
let settingsFile = g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP; | let settingsFile = g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP; | ||||
if (!Engine.FileExists(settingsFile)) | if (!Engine.FileExists(settingsFile)) | ||||
return; | return; | ||||
let attrs = Engine.ReadJSONFile(settingsFile); | let attrs = Engine.ReadJSONFile(settingsFile); | ||||
if (!attrs || !attrs.settings) | if (!attrs || !attrs.settings) | ||||
Show All 38 Lines | function loadPersistMatchSettings() | ||||
supplementDefaults(); | supplementDefaults(); | ||||
g_IsInGuiUpdate = false; | g_IsInGuiUpdate = false; | ||||
} | } | ||||
function savePersistMatchSettings() | function savePersistMatchSettings() | ||||
{ | { | ||||
if (g_IsTutorial) | |||||
return; | |||||
let attributes = Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true" ? g_GameAttributes : {}; | let attributes = Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true" ? g_GameAttributes : {}; | ||||
Engine.WriteJSONFile(g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP, attributes); | Engine.WriteJSONFile(g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP, attributes); | ||||
} | } | ||||
function sanitizePlayerData(playerData) | function sanitizePlayerData(playerData) | ||||
{ | { | ||||
// Remove gaia | // Remove gaia | ||||
if (playerData.length && !playerData[0]) | if (playerData.length && !playerData[0]) | ||||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | for (let i in g_GameAttributes.settings.PlayerData) | ||||
let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); | let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); | ||||
if (assignBox.list_data[assignBox.selected] == "guid:local") | if (assignBox.list_data[assignBox.selected] == "guid:local") | ||||
playerID = +i+1; | playerID = +i+1; | ||||
} | } | ||||
Engine.StartGame(g_GameAttributes, playerID); | Engine.StartGame(g_GameAttributes, playerID); | ||||
Engine.SwitchGuiPage("page_loading.xml", { | Engine.SwitchGuiPage("page_loading.xml", { | ||||
"attribs": g_GameAttributes, | "attribs": g_GameAttributes, | ||||
"isNetworked" : g_IsNetworked, | "isNetworked": g_IsNetworked, | ||||
"playerAssignments": g_PlayerAssignments | "playerAssignments": g_PlayerAssignments | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
function launchTutorial() | |||||
{ | |||||
selectMap("maps/tutorials/starting_economy_walkthrough"); | |||||
launchGame(); | |||||
} | |||||
/** | /** | ||||
* 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; | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator