add game name to the game setup screen

This commit is contained in:
Jonny McCullagh 2026-08-03 13:37:14 +01:00
parent b9c23b511a
commit 2fa849a1fc
5 changed files with 32 additions and 5 deletions

View file

@ -0,0 +1,19 @@
GameSettings.prototype.Attributes.GameName = class GameName extends GameSetting
{
init()
{
this.value = "";
}
toInitAttributes(attribs)
{
if (this.value)
attribs.gameName = this.value;
}
fromInitAttributes(attribs)
{
if (attribs.gameName !== undefined)
this.value = attribs.gameName;
}
};

View file

@ -184,10 +184,12 @@ function formatPlayerInfo(playerDataArray, playerStates)
function getGameDescription(initAttributes, mapCache)
{
const titles = [];
const gameDescription = initAttributes.gameName ?
coloredText(translate("Game:"), g_DescriptionHighlight) + " " +
escapeText(initAttributes.gameName) : "";
const hostDescription = initAttributes.hostName ?
sprintf(translate("Host: %(playername)s"), {
"playername": escapeText(initAttributes.hostName)
}) : "";
coloredText(translate("Host:"), g_DescriptionHighlight) + " " +
escapeText(initAttributes.hostName) : "";
if (!initAttributes.settings.VictoryConditions.length)
titles.push({
@ -439,7 +441,8 @@ function getGameDescription(initAttributes, mapCache)
title.value || translateWithContext("game setup option", "disabled")
})).join("\n");
return hostDescription + (hostDescription && settingsDescription ? "\n" : "") + settingsDescription;
const descriptions = [gameDescription, hostDescription, settingsDescription].filter(description => description);
return descriptions.join("\n");
}
/**

View file

@ -31,6 +31,8 @@ class SetupWindow
const mapCache = new MapCache();
g_GameSettings = new GameSettings();
g_GameSettings.init(mapCache, g_IsController ? savedGame : undefined);
if (initData?.gameName)
g_GameSettings.gameName.value = initData.gameName;
if (initData?.hostName)
g_GameSettings.hostName.value = initData.hostName;

View file

@ -100,7 +100,7 @@ async function init(attribs)
}
if (attribs.hasPassword)
{
g_ServerName = attribs.name;
g_ServerName = attribs.gameName || "";
switchSetupPage("pagePassword");
const passwordResult = await cancelOr(new Promise(resolve =>
{
@ -111,6 +111,7 @@ async function init(attribs)
}
try
{
g_ServerName = attribs.gameName || "";
startJoinFromLobby(attribs.name, attribs.hostJID,
attribs.hasPassword ? Engine.GetGUIObjectByName("clientPassword").caption : "");
switchSetupPage("pageConnecting");
@ -398,6 +399,7 @@ async function handleAuthenticated(message, loadSavedGame)
"argument": {
"savedGame": savegameID, // Undefined or the savegame ID
"serverName": g_ServerName,
"gameName": g_ServerName,
"hasPassword": g_ServerHasPassword,
"hostName": message.hostName
}

View file

@ -78,6 +78,7 @@ class JoinButton
Engine.OpenChildPage("page_gamesetup_mp.xml", {
"multiplayerGameType": "join",
"name": g_Nickname,
"gameName": stanza.name,
"rating": this.getRejoinRating(stanza),
"hasPassword": !!stanza.hasPassword,
"hostJID": stanza.hostJID