GameSetup GUI cleanup - Renaming.
- rename 'Controls' class to 'Controllers' to avoid ambiguity and mimic MVC lingo. - rename GameRegisterStanza into LobbyGameRegistration, and make it explicitly a controller. - rename GameSettingsFile to PersistentMatchSettings & move it to its own folder (since it could be reused independently of the controllers) - remove the StartGameController & move `launchGame` to the GameSettingsController (simplifies the control flow) - the GUI Object "setupWindow" was actually the GameSettingsPage, this is corrected. - the LoadingPage was showing the GameSettingsPage -> in the current code, it makes more sense to have both handle their own visibility. - make the NetMessages class independent of other gamesetup logic, so that it can be reused by other code. Remove the custom XML object. Differential Revision: https://code.wildfiregames.com/D3719 This was SVN commit r25101.
This commit is contained in:
parent
293cd95ccb
commit
72f0fdb41b
@ -1,14 +1,13 @@
|
||||
/**
|
||||
* 'Controller' for the GUI handling of gamesettings.
|
||||
* Controller for the GUI handling of gamesettings.
|
||||
*/
|
||||
class GameSettingsControl
|
||||
class GameSettingsController
|
||||
{
|
||||
constructor(setupWindow, netMessages, startGameControl, playerAssignmentsControl, mapCache)
|
||||
constructor(setupWindow, netMessages, playerAssignmentsController, mapCache)
|
||||
{
|
||||
this.setupWindow = setupWindow;
|
||||
this.startGameControl = startGameControl;
|
||||
this.mapCache = mapCache;
|
||||
this.gameSettingsFile = new GameSettingsFile(this);
|
||||
this.persistentMatchSettings = new PersistentMatchSettings(this);
|
||||
|
||||
this.guiData = new GameSettingsGuiData();
|
||||
|
||||
@ -16,6 +15,11 @@ class GameSettingsControl
|
||||
// may not have been received yet.
|
||||
this.loading = true;
|
||||
|
||||
// If this is true, the ready controller won't reset readiness.
|
||||
// TODO: ideally the ready controller would be somewhat independent from this one,
|
||||
// possibly by listening to gamesetup messages itself.
|
||||
this.gameStarted = false;
|
||||
|
||||
this.updateLayoutHandlers = new Set();
|
||||
this.settingsChangeHandlers = new Set();
|
||||
this.loadingChangeHandlers = new Set();
|
||||
@ -23,16 +27,19 @@ class GameSettingsControl
|
||||
setupWindow.registerLoadHandler(this.onLoad.bind(this));
|
||||
setupWindow.registerGetHotloadDataHandler(this.onGetHotloadData.bind(this));
|
||||
|
||||
startGameControl.registerLaunchGameHandler(this.onLaunchGame.bind(this));
|
||||
|
||||
setupWindow.registerClosePageHandler(this.onClose.bind(this));
|
||||
|
||||
if (g_IsController && g_IsNetworked)
|
||||
playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
|
||||
if (g_IsNetworked)
|
||||
{
|
||||
if (g_IsController)
|
||||
playerAssignmentsController.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
else
|
||||
// In MP, the host launches the game and switches right away,
|
||||
// clients switch when they receive the appropriate message.
|
||||
netMessages.registerNetMessageHandler("start", this.switchToLoadingPage.bind(this));
|
||||
netMessages.registerNetMessageHandler("gamesetup", this.onGamesetupMessage.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param handler will be called when the layout needs to be updated.
|
||||
@ -63,9 +70,9 @@ class GameSettingsControl
|
||||
{
|
||||
if (hotloadData)
|
||||
this.parseSettings(hotloadData.initAttributes);
|
||||
else if (g_IsController && this.gameSettingsFile.enabled)
|
||||
else if (g_IsController && this.persistentMatchSettings.enabled)
|
||||
{
|
||||
let settings = this.gameSettingsFile.loadFile();
|
||||
let settings = this.persistentMatchSettings.loadFile();
|
||||
if (settings)
|
||||
this.parseSettings(settings);
|
||||
}
|
||||
@ -78,11 +85,6 @@ class GameSettingsControl
|
||||
this.setLoading(false);
|
||||
}
|
||||
|
||||
onClose()
|
||||
{
|
||||
this.gameSettingsFile.saveFile();
|
||||
}
|
||||
|
||||
onClientJoin()
|
||||
{
|
||||
/**
|
||||
@ -226,10 +228,52 @@ class GameSettingsControl
|
||||
});
|
||||
}
|
||||
|
||||
onLaunchGame()
|
||||
/**
|
||||
* Cheat prevention:
|
||||
*
|
||||
* 1. Ensure that the host cannot start the game unless all clients agreed on the game settings using the ready system.
|
||||
*
|
||||
* TODO:
|
||||
* 2. Ensure that the host cannot start the game with InitAttributes different from the agreed ones.
|
||||
* This may be achieved by:
|
||||
* - Determining the seed collectively.
|
||||
* - passing the agreed game settings to the engine when starting the game instance
|
||||
* - rejecting new game settings from the server after the game launch event
|
||||
*/
|
||||
launchGame()
|
||||
{
|
||||
// Save the file before random settings are resolved.
|
||||
this.gameSettingsFile.saveFile();
|
||||
this.savePersistentMatchSettings();
|
||||
|
||||
// Mark the game as started so the readyController won't reset state.
|
||||
this.gameStarted = true;
|
||||
|
||||
// This will resolve random settings & send game start messages.
|
||||
// TODO: this will trigger observers, which is somewhat wasteful.
|
||||
g_GameSettings.launchGame(g_PlayerAssignments);
|
||||
|
||||
// Switch to the loading page right away,
|
||||
// the GUI will otherwise show the unrandomised settings.
|
||||
this.switchToLoadingPage();
|
||||
}
|
||||
|
||||
switchToLoadingPage()
|
||||
{
|
||||
Engine.SwitchGuiPage("page_loading.xml", {
|
||||
"attribs": g_GameSettings.toInitAttributes(),
|
||||
"playerAssignments": g_PlayerAssignments
|
||||
});
|
||||
}
|
||||
|
||||
onClose()
|
||||
{
|
||||
this.savePersistentMatchSettings();
|
||||
}
|
||||
|
||||
savePersistentMatchSettings()
|
||||
{
|
||||
// TODO: ought to only save a subset of settings.
|
||||
this.persistentMatchSettings.saveFile(this.getSettings());
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,4 +281,4 @@ class GameSettingsControl
|
||||
/**
|
||||
* Wait (at most) this many milliseconds before sending network messages.
|
||||
*/
|
||||
GameSettingsControl.prototype.Timeout = 400;
|
||||
GameSettingsController.prototype.Timeout = 400;
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* This class contains GUI-specific gamesetting data.
|
||||
* This class contains network-synchronized data specific to GameSettingsController.
|
||||
* It's split from GameSettingsController for convenience.
|
||||
*/
|
||||
class GameSettingsGuiData
|
||||
{
|
||||
@ -10,7 +11,7 @@ class GameSettingsGuiData
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize for network transmission, settings persistence or convenience in other GUI files.
|
||||
* Serialize for network transmission & settings persistence.
|
||||
*/
|
||||
Serialize()
|
||||
{
|
@ -3,9 +3,9 @@
|
||||
* this match is being setup so that others can join.
|
||||
* It informs of the lobby of some setting values and the participating clients.
|
||||
*/
|
||||
class GameRegisterStanza
|
||||
class LobbyGameRegistrationController
|
||||
{
|
||||
constructor(initData, setupWindow, netMessages, mapCache)
|
||||
constructor(initData, setupWindow, netMessages, mapCache, playerAssignmentsController)
|
||||
{
|
||||
this.mapCache = mapCache;
|
||||
|
||||
@ -21,6 +21,7 @@ class GameRegisterStanza
|
||||
// Events
|
||||
setupWindow.registerClosePageHandler(this.onClosePage.bind(this));
|
||||
netMessages.registerNetMessageHandler("start", this.onGameStart.bind(this));
|
||||
playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.sendImmediately.bind(this));
|
||||
|
||||
g_GameSettings.map.watch(() => this.onSettingsChange(), ["map", "type"]);
|
||||
g_GameSettings.mapSize.watch(() => this.onSettingsChange(), ["size"]);
|
||||
@ -38,9 +39,6 @@ class GameRegisterStanza
|
||||
|
||||
onGameStart()
|
||||
{
|
||||
if (!g_IsController || !Engine.HasXmppClient())
|
||||
return;
|
||||
|
||||
this.sendImmediately();
|
||||
let clients = this.formatClientsForStanza();
|
||||
Engine.SendChangeStateGame(clients.connectedPlayers, clients.list);
|
||||
@ -60,8 +58,9 @@ class GameRegisterStanza
|
||||
if (!g_IsController || !Engine.HasXmppClient())
|
||||
return;
|
||||
|
||||
// Already sending an update - do nothing.
|
||||
if (this.timer !== undefined)
|
||||
clearTimeout(this.timer);
|
||||
return;
|
||||
|
||||
this.timer = setTimeout(this.sendImmediately.bind(this), this.Timeout);
|
||||
}
|
||||
@ -88,6 +87,7 @@ class GameRegisterStanza
|
||||
"name": this.serverName,
|
||||
"hostUsername": Engine.LobbyGetNick(),
|
||||
"mapName": g_GameSettings.map.map,
|
||||
// TODO: if the map name was always up-to-date we wouldn't need the mapcache here.
|
||||
"niceMapName": this.mapCache.getTranslatableMapName(g_GameSettings.map.type, g_GameSettings.map.map),
|
||||
"mapSize": g_GameSettings.map.type == "random" ? g_GameSettings.mapSize.size : "Default",
|
||||
"mapType": g_GameSettings.map.type,
|
||||
@ -139,4 +139,4 @@ class GameRegisterStanza
|
||||
/**
|
||||
* Send the current game settings to the lobby bot if the settings didn't change for this number of milliseconds.
|
||||
*/
|
||||
GameRegisterStanza.prototype.Timeout = 2000;
|
||||
LobbyGameRegistrationController.prototype.Timeout = 2000;
|
@ -1,14 +1,13 @@
|
||||
/**
|
||||
* This class provides a property independent interface to g_PlayerAssignment events and actions.
|
||||
*/
|
||||
class PlayerAssignmentsControl
|
||||
class PlayerAssignmentsController
|
||||
{
|
||||
constructor(setupWindow, netMessages, gameRegisterStanza)
|
||||
constructor(setupWindow, netMessages)
|
||||
{
|
||||
this.clientJoinHandlers = new Set();
|
||||
this.clientLeaveHandlers = new Set();
|
||||
this.playerAssignmentsChangeHandlers = new Set();
|
||||
this.gameRegisterStanza = gameRegisterStanza;
|
||||
|
||||
if (!g_IsNetworked)
|
||||
{
|
||||
@ -147,9 +146,6 @@ class PlayerAssignmentsControl
|
||||
|
||||
g_PlayerAssignments = newAssignments;
|
||||
this.updatePlayerAssignments();
|
||||
// Send at most one gameRegisterStanza after all handlers run in case a
|
||||
// joining observer has been assigned to a playerslot.
|
||||
this.gameRegisterStanza.sendImmediately?.();
|
||||
}
|
||||
|
||||
assignClient(guid, playerIndex)
|
||||
@ -207,8 +203,8 @@ class PlayerAssignmentsControl
|
||||
}
|
||||
}
|
||||
|
||||
PlayerAssignmentsControl.prototype.ConfigNameSingleplayer =
|
||||
PlayerAssignmentsController.prototype.ConfigNameSingleplayer =
|
||||
"playername.singleplayer";
|
||||
|
||||
PlayerAssignmentsControl.prototype.ConfigAssignPlayers =
|
||||
PlayerAssignmentsController.prototype.ConfigAssignPlayers =
|
||||
"gui.gamesetup.assignplayers";
|
@ -7,14 +7,14 @@
|
||||
* Therefore assume the readystate from the user interface rather than trusting the server whether the current player is ready.
|
||||
* The server may set readiness to false but not to true.
|
||||
*
|
||||
* The ReadyControl class stores the ready state of the current player and fires an event if the agreed settings changed.
|
||||
* The ReadyController class stores the ready state of the current player and fires an event if the agreed settings changed.
|
||||
*/
|
||||
class ReadyControl
|
||||
class ReadyController
|
||||
{
|
||||
constructor(netMessages, gameSettingsControl, startGameControl, playerAssignmentsControl)
|
||||
constructor(netMessages, gameSettingsController, playerAssignmentsController)
|
||||
{
|
||||
this.startGameControl = startGameControl;
|
||||
this.playerAssignmentsControl = playerAssignmentsControl;
|
||||
this.playerAssignmentsController = playerAssignmentsController;
|
||||
this.gameSettingsController = gameSettingsController;
|
||||
|
||||
this.resetReadyHandlers = new Set();
|
||||
this.previousAssignments = {};
|
||||
@ -25,9 +25,9 @@ class ReadyControl
|
||||
this.readyState = this.NotReady;
|
||||
|
||||
netMessages.registerNetMessageHandler("ready", this.onReadyMessage.bind(this));
|
||||
gameSettingsControl.registerSettingsChangeHandler(this.onSettingsChange.bind(this));
|
||||
playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
playerAssignmentsControl.registerClientLeaveHandler(this.onClientLeave.bind(this));
|
||||
gameSettingsController.registerSettingsChangeHandler(this.onSettingsChange.bind(this));
|
||||
playerAssignmentsController.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
playerAssignmentsController.registerClientLeaveHandler(this.onClientLeave.bind(this));
|
||||
}
|
||||
|
||||
registerResetReadyHandler(handler)
|
||||
@ -53,7 +53,7 @@ class ReadyControl
|
||||
if (playerAssignment)
|
||||
{
|
||||
playerAssignment.status = message.status;
|
||||
this.playerAssignmentsControl.updatePlayerAssignments();
|
||||
this.playerAssignmentsController.updatePlayerAssignments();
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,15 +90,15 @@ class ReadyControl
|
||||
if (playerAssignment)
|
||||
{
|
||||
playerAssignment.status = ready;
|
||||
this.playerAssignmentsControl.updatePlayerAssignments();
|
||||
this.playerAssignmentsController.updatePlayerAssignments();
|
||||
}
|
||||
}
|
||||
|
||||
resetReady()
|
||||
{
|
||||
// The gameStarted check is only necessary to allow the host to
|
||||
// determine the Seed and random items after clicking start
|
||||
if (!g_IsNetworked || this.startGameControl.gameStarted)
|
||||
// determine random items after clicking start.
|
||||
if (!g_IsNetworked || this.gameSettingsController.gameStarted)
|
||||
return;
|
||||
|
||||
for (let handler of this.resetReadyHandlers)
|
||||
@ -107,7 +107,7 @@ class ReadyControl
|
||||
if (g_IsController)
|
||||
{
|
||||
Engine.ClearAllPlayerReady();
|
||||
this.playerAssignmentsControl.updatePlayerAssignments();
|
||||
this.playerAssignmentsController.updatePlayerAssignments();
|
||||
}
|
||||
else if (this.readyState != this.StayReady)
|
||||
this.setReady(this.NotReady, false);
|
||||
@ -119,8 +119,8 @@ class ReadyControl
|
||||
}
|
||||
}
|
||||
|
||||
ReadyControl.prototype.NotReady = 0;
|
||||
ReadyController.prototype.NotReady = 0;
|
||||
|
||||
ReadyControl.prototype.Ready = 1;
|
||||
ReadyController.prototype.Ready = 1;
|
||||
|
||||
ReadyControl.prototype.StayReady = 2;
|
||||
ReadyController.prototype.StayReady = 2;
|
@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Cheat prevention:
|
||||
*
|
||||
* 1. Ensure that the host cannot start the game unless all clients agreed on the game settings using the ready system.
|
||||
*
|
||||
* TODO:
|
||||
* 2. Ensure that the host cannot start the game with InitAttributes different from the agreed ones.
|
||||
* This may be achieved by:
|
||||
* - Determining the seed collectively.
|
||||
* - passing the agreed game settings to the engine when starting the game instance
|
||||
* - rejecting new game settings from the server after the game launch event
|
||||
*/
|
||||
class StartGameControl
|
||||
{
|
||||
constructor(netMessages)
|
||||
{
|
||||
this.gameLaunchHandlers = new Set();
|
||||
|
||||
// This may be read from publicly
|
||||
this.gameStarted = false;
|
||||
|
||||
// In MP, the host launches the game and switches right away,
|
||||
// clients switch when they receive the appropriate message.
|
||||
netMessages.registerNetMessageHandler("start", this.switchToLoadingPage.bind(this));
|
||||
}
|
||||
|
||||
registerLaunchGameHandler(handler)
|
||||
{
|
||||
this.gameLaunchHandlers.add(handler);
|
||||
}
|
||||
|
||||
launchGame()
|
||||
{
|
||||
this.gameStarted = true;
|
||||
|
||||
for (let handler of this.gameLaunchHandlers)
|
||||
handler();
|
||||
|
||||
g_GameSettings.launchGame(g_PlayerAssignments);
|
||||
|
||||
// Switch to the loading page right away,
|
||||
// the GUI will otherwise show the unrandomised settings.
|
||||
this.switchToLoadingPage();
|
||||
}
|
||||
|
||||
switchToLoadingPage()
|
||||
{
|
||||
Engine.SwitchGuiPage("page_loading.xml", {
|
||||
"attribs": g_GameSettings.toInitAttributes(),
|
||||
"playerAssignments": g_PlayerAssignments
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* This class enables other classes to subscribe to specific CNetMessage types (see NetMessage.h, NetMessages.h) sent by the CNetServer.
|
||||
* Convenience wrapper to poll messages from the C++ NetClient.
|
||||
*/
|
||||
class NetMessages
|
||||
{
|
||||
@ -9,11 +9,6 @@ class NetMessages
|
||||
|
||||
for (let messageType of this.MessageTypes)
|
||||
this.netMessageHandlers[messageType] = new Set();
|
||||
|
||||
this.registerNetMessageHandler("netwarn", addNetworkWarning);
|
||||
|
||||
Engine.GetGUIObjectByName("netMessages").onTick = this.onTick.bind(this);
|
||||
setupWindow.registerClosePageHandler(this.onClosePage.bind(this));
|
||||
}
|
||||
|
||||
registerNetMessageHandler(messageType, handler)
|
||||
@ -32,7 +27,7 @@ class NetMessages
|
||||
error("Unknown net message type: " + uneval(messageType));
|
||||
}
|
||||
|
||||
onTick()
|
||||
pollPendingMessages()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@ -49,15 +44,10 @@ class NetMessages
|
||||
error("Unrecognized net message type " + message.type);
|
||||
}
|
||||
}
|
||||
|
||||
onClosePage()
|
||||
{
|
||||
Engine.DisconnectNetworkGame();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Messages types are present here if and only if they are sent by NetClient.cpp.
|
||||
* List of message types sent by C++ (keep this in sync with NetClient.cpp).
|
||||
*/
|
||||
NetMessages.prototype.MessageTypes = [
|
||||
"chat",
|
||||
|
@ -9,7 +9,7 @@ SetupWindowPages.AIConfigPage = class
|
||||
{
|
||||
constructor(setupWindow)
|
||||
{
|
||||
this.gameSettingsControl = setupWindow.controls.gameSettingsControl;
|
||||
this.gameSettingsController = setupWindow.controls.gameSettingsController;
|
||||
|
||||
this.playerIndex = undefined;
|
||||
this.row = 0;
|
||||
|
@ -21,7 +21,7 @@ AIGameSettingControls.AIBehavior = class extends AIGameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerAI.setBehavior(this.playerIndex, this.dropdown.list_data[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,7 @@ AIGameSettingControls.AIDifficulty = class extends AIGameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerAI.setDifficulty(this.playerIndex, this.dropdown.list_data[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -31,7 +31,7 @@ AIGameSettingControls.AISelection = class extends AIGameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerAI.setAI(this.playerIndex, this.dropdown.list_data[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -21,11 +21,11 @@ class GameSettingControl /* extends Profilable /* Uncomment to profile controls
|
||||
this.playerIndex = playerIndex;
|
||||
|
||||
this.setupWindow = setupWindow;
|
||||
this.gameSettingsControl = setupWindow.controls.gameSettingsControl;
|
||||
this.gameSettingsController = setupWindow.controls.gameSettingsController;
|
||||
this.mapCache = setupWindow.controls.mapCache;
|
||||
this.mapFilters = setupWindow.controls.mapFilters;
|
||||
this.netMessages = setupWindow.controls.netMessages;
|
||||
this.playerAssignmentsControl = setupWindow.controls.playerAssignmentsControl;
|
||||
this.playerAssignmentsController = setupWindow.controls.playerAssignmentsController;
|
||||
}
|
||||
|
||||
// enabled and hidden should only be modified through their setters or
|
||||
@ -51,7 +51,7 @@ class GameSettingControl /* extends Profilable /* Uncomment to profile controls
|
||||
this.setupWindow.registerLoadHandler(this.onLoad.bind(this));
|
||||
|
||||
if (this.onPlayerAssignmentsChange)
|
||||
this.playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
|
||||
this.playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
|
||||
}
|
||||
|
||||
setTitle(titleCaption)
|
||||
@ -84,7 +84,7 @@ class GameSettingControl /* extends Profilable /* Uncomment to profile controls
|
||||
{
|
||||
this.hidden = hidden;
|
||||
// Trigger a layout update to reposition items.
|
||||
this.gameSettingsControl.updateLayout();
|
||||
this.gameSettingsController.updateLayout();
|
||||
}
|
||||
|
||||
updateVisibility()
|
||||
|
@ -73,7 +73,7 @@ PlayerSettingControls.PlayerAssignment = class PlayerAssignment extends GameSett
|
||||
if (this.assignedGUID && g_GameSettings.playerAI.get(this.playerIndex))
|
||||
{
|
||||
g_GameSettings.playerAI.setAI(this.playerIndex, undefined);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
this.render();
|
||||
}
|
||||
@ -118,8 +118,8 @@ PlayerSettingControls.PlayerAssignment = class PlayerAssignment extends GameSett
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
this.values.Handler[itemIdx].onSelectionChange(
|
||||
this.gameSettingsControl,
|
||||
this.playerAssignmentsControl,
|
||||
this.gameSettingsController,
|
||||
this.playerAssignmentsController,
|
||||
this.playerIndex,
|
||||
this.values.Value[itemIdx]);
|
||||
}
|
||||
@ -150,7 +150,7 @@ PlayerSettingControls.PlayerAssignment.prototype.AutocompleteOrder = 100;
|
||||
};
|
||||
}
|
||||
|
||||
onSelectionChange(gameSettingsControl, playerAssignmentsControl, playerIndex, guidToAssign)
|
||||
onSelectionChange(gameSettingsController, playerAssignmentsController, playerIndex, guidToAssign)
|
||||
{
|
||||
let sourcePlayer = g_PlayerAssignments[guidToAssign].player - 1;
|
||||
if (sourcePlayer >= 0)
|
||||
@ -167,8 +167,8 @@ PlayerSettingControls.PlayerAssignment.prototype.AutocompleteOrder = 100;
|
||||
}
|
||||
}
|
||||
|
||||
playerAssignmentsControl.assignPlayer(guidToAssign, playerIndex);
|
||||
gameSettingsControl.setNetworkInitAttributes();
|
||||
playerAssignmentsController.assignPlayer(guidToAssign, playerIndex);
|
||||
gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
|
||||
isSelected(pData, guid, value)
|
||||
@ -198,9 +198,9 @@ PlayerSettingControls.PlayerAssignment.prototype.AutocompleteOrder = 100;
|
||||
};
|
||||
}
|
||||
|
||||
onSelectionChange(gameSettingsControl, playerAssignmentsControl, playerIndex, value)
|
||||
onSelectionChange(gameSettingsController, playerAssignmentsController, playerIndex, value)
|
||||
{
|
||||
playerAssignmentsControl.unassignClient(playerIndex + 1);
|
||||
playerAssignmentsController.unassignClient(playerIndex + 1);
|
||||
|
||||
g_GameSettings.playerAI.set(playerIndex, {
|
||||
"bot": value,
|
||||
@ -208,7 +208,7 @@ PlayerSettingControls.PlayerAssignment.prototype.AutocompleteOrder = 100;
|
||||
"behavior": Engine.ConfigDB_GetValue("user", "gui.gamesetup.aibehavior"),
|
||||
});
|
||||
|
||||
gameSettingsControl.setNetworkInitAttributes();
|
||||
gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
|
||||
isSelected(pData, guid, value)
|
||||
@ -237,13 +237,13 @@ PlayerSettingControls.PlayerAssignment.prototype.AutocompleteOrder = 100;
|
||||
};
|
||||
}
|
||||
|
||||
onSelectionChange(gameSettingsControl, playerAssignmentsControl, playerIndex)
|
||||
onSelectionChange(gameSettingsController, playerAssignmentsController, playerIndex)
|
||||
{
|
||||
playerAssignmentsControl.unassignClient(playerIndex + 1);
|
||||
playerAssignmentsController.unassignClient(playerIndex + 1);
|
||||
|
||||
g_GameSettings.playerAI.setAI(playerIndex, undefined);
|
||||
|
||||
gameSettingsControl.setNetworkInitAttributes();
|
||||
gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
|
||||
isSelected(pData, guid, value)
|
||||
|
@ -63,7 +63,7 @@ PlayerSettingControls.PlayerCiv = class PlayerCiv extends GameSettingControlDrop
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerCiv.setValue(this.playerIndex, this.values.civ[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,7 @@ PlayerSettingControls.PlayerColor = class PlayerColor extends GameSettingControl
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerColor.setColor(this.playerIndex, this.values[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -39,7 +39,7 @@ PlayerSettingControls.PlayerTeam = class PlayerTeam extends GameSettingControlDr
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerTeam.setValue(this.playerIndex, itemIdx - 1);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ GameSettingControls.Cheats = class Cheats extends GameSettingControlCheckbox
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.cheats.setEnabled(!g_IsNetworked || checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ GameSettingControls.ExploredMap = class ExploredMap extends GameSettingControlCh
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.mapExploration.setExplored(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@ GameSettingControls.LastManStanding = class LastManStanding extends GameSettingC
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.lastManStanding.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,7 @@ GameSettingControls.LockedTeams = class LockedTeams extends GameSettingControlCh
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.lockedTeams.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ GameSettingControls.Nomad = class Nomad extends GameSettingControlCheckbox
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.nomad.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,7 @@ GameSettingControls.Rating = class Rating extends GameSettingControlCheckbox
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.rating.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,7 @@ GameSettingControls.RegicideGarrison = class RegicideGarrison extends GameSettin
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.regicideGarrison.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ GameSettingControls.RevealedMap = class RevealedMap extends GameSettingControlCh
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.mapExploration.setRevealed(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@ GameSettingControls.Spies = class Spies extends GameSettingControlCheckbox
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.disableSpies.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ GameSettingControls.Treasures = class Treasures extends GameSettingControlCheckb
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.disableTreasures.setEnabled(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ GameSettingControls.WorldPopulation = class WorldPopulation extends GameSettingC
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.population.setPopCap(checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,7 @@ GameSettingControls.Biome = class Biome extends GameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.biome.setBiome(this.dropdown.list_data[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -49,7 +49,7 @@ GameSettingControls.Daytime = class Daytime extends GameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.daytime.setValue(this.values.Id[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ GameSettingControls.GameSpeed = class GameSpeed extends GameSettingControlDropdo
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.gameSpeed.setSpeed(this.dropdown.list_data[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -70,7 +70,7 @@ GameSettingControls.Landscape = class Landscape extends GameSettingControlDropdo
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.landscape.setValue(this.values.Id[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@ GameSettingControls.MapFilter = class MapFilter extends GameSettingControlDropdo
|
||||
|
||||
this.values = undefined;
|
||||
|
||||
this.gameSettingsControl.guiData.mapFilter.watch(() => this.render(), ["filter"]);
|
||||
this.gameSettingsController.guiData.mapFilter.watch(() => this.render(), ["filter"]);
|
||||
g_GameSettings.map.watch(() => this.checkMapTypeChange(), ["type"]);
|
||||
}
|
||||
|
||||
@ -33,10 +33,10 @@ GameSettingControls.MapFilter = class MapFilter extends GameSettingControlDropdo
|
||||
else
|
||||
this.values = undefined;
|
||||
|
||||
if (this.values && this.values.Name.indexOf(this.gameSettingsControl.guiData.mapFilter.filter) === -1)
|
||||
if (this.values && this.values.Name.indexOf(this.gameSettingsController.guiData.mapFilter.filter) === -1)
|
||||
{
|
||||
this.gameSettingsControl.guiData.mapFilter.filter = this.values.Name[this.values.Default];
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.guiData.mapFilter.filter = this.values.Name[this.values.Default];
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
this.render();
|
||||
}
|
||||
@ -44,7 +44,7 @@ GameSettingControls.MapFilter = class MapFilter extends GameSettingControlDropdo
|
||||
render()
|
||||
{
|
||||
// Index may have changed, reset.
|
||||
this.setSelectedValue(this.gameSettingsControl.guiData.mapFilter.filter);
|
||||
this.setSelectedValue(this.gameSettingsController.guiData.mapFilter.filter);
|
||||
this.setHidden(!this.values);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ GameSettingControls.MapFilter = class MapFilter extends GameSettingControlDropdo
|
||||
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
this.gameSettingsControl.guiData.mapFilter.filter = this.values.Name[itemIdx];
|
||||
this.gameSettingsController.guiData.mapFilter.filter = this.values.Name[itemIdx];
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,7 @@ GameSettingControls.MapSelection = class MapSelection extends GameSettingControl
|
||||
g_GameSettings.map.watch(() => this.render(), ["map"]);
|
||||
g_GameSettings.map.watch(() => this.updateMapList(), ["type"]);
|
||||
|
||||
this.gameSettingsControl.guiData.mapFilter.watch(() => this.updateMapList(), ["filter"]);
|
||||
this.gameSettingsController.guiData.mapFilter.watch(() => this.updateMapList(), ["filter"]);
|
||||
|
||||
this.randomItem = {
|
||||
"file": this.RandomMapId,
|
||||
@ -45,7 +45,7 @@ GameSettingControls.MapSelection = class MapSelection extends GameSettingControl
|
||||
let values =
|
||||
this.mapFilters.getFilteredMaps(
|
||||
g_GameSettings.map.type,
|
||||
this.gameSettingsControl.guiData.mapFilter.filter,
|
||||
this.gameSettingsController.guiData.mapFilter.filter,
|
||||
false);
|
||||
|
||||
values.sort(sortNameIgnoreCase);
|
||||
@ -65,7 +65,7 @@ GameSettingControls.MapSelection = class MapSelection extends GameSettingControl
|
||||
if (this.values.file.indexOf(g_GameSettings.map.map) === -1)
|
||||
{
|
||||
g_GameSettings.map.selectMap(this.values.file[this.values.Default]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
// The index may have changed: reset.
|
||||
this.setSelectedValue(g_GameSettings.map.map);
|
||||
@ -87,7 +87,7 @@ GameSettingControls.MapSelection = class MapSelection extends GameSettingControl
|
||||
return;
|
||||
this.reRenderTimeout = setTimeout(() => {
|
||||
g_GameSettings.map.selectMap(this.values.file[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
delete this.reRenderTimeout;
|
||||
}, 0);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ GameSettingControls.MapSize = class MapSize extends GameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.mapSize.setSize(g_MapSizes.Tiles[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ GameSettingControls.MapType = class MapType extends GameSettingControlDropdown
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.map.setType(g_MapTypes.Name[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ GameSettingControls.PlayerCount = class PlayerCount extends GameSettingControlDr
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.playerCount.setNb(this.values[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,7 @@ GameSettingControls.PopulationCap = class PopulationCap extends GameSettingContr
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.population.setPopCap(false, g_PopulationCapacities.Population[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ GameSettingControls.StartingResources = class StartingResources extends GameSett
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.startingResources.setResources(g_StartingResources.Resources[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -45,7 +45,7 @@ GameSettingControls.TeamPlacement = class TeamPlacement extends GameSettingContr
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.teamPlacement.setValue(this.values.Id[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ GameSettingControls.TriggerDifficulty = class TriggerDifficulty extends GameSett
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.triggerDifficulty.setValue(this.values.Difficulty[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -39,7 +39,7 @@ GameSettingControls.WorldPopulationCap = class WorldPopulationCap extends GameSe
|
||||
onSelectionChange(itemIdx)
|
||||
{
|
||||
g_GameSettings.population.setPopCap(true, g_WorldPopulationCapacities.Population[itemIdx]);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -27,7 +27,7 @@ GameSettingControls.Ceasefire = class Ceasefire extends GameSettingControlSlider
|
||||
onValueChange(value)
|
||||
{
|
||||
g_GameSettings.ceasefire.setValue(value);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ GameSettingControls.RelicCount = class RelicCount extends GameSettingControlSlid
|
||||
onValueChange(value)
|
||||
{
|
||||
g_GameSettings.relic.setCount(value);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ GameSettingControls.RelicDuration = class RelicDuration extends GameSettingContr
|
||||
onValueChange(value)
|
||||
{
|
||||
g_GameSettings.relic.setDuration(value);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -27,7 +27,7 @@ GameSettingControls.SeaLevelRiseTime = class SeaLevelRiseTime extends GameSettin
|
||||
onValueChange(value)
|
||||
{
|
||||
g_GameSettings.seaLevelRise.setValue(value);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ GameSettingControls.WonderDuration = class WonderDuration extends GameSettingCon
|
||||
onValueChange(value)
|
||||
{
|
||||
g_GameSettings.wonder.setDuration(value);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,6 @@ class VictoryConditionCheckbox extends GameSettingControlCheckbox
|
||||
onPress(checked)
|
||||
{
|
||||
g_GameSettings.victoryConditions.setEnabled(this.victoryCondition, checked);
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,13 @@ SetupWindowPages.GameSetupPage = class
|
||||
};
|
||||
}
|
||||
|
||||
setupWindow.controls.gameSettingsController.registerLoadingChangeHandler((loading) => this.onLoadingChange(loading));
|
||||
|
||||
Engine.ProfileStop();
|
||||
}
|
||||
}
|
||||
|
||||
onLoadingChange(loading)
|
||||
{
|
||||
Engine.GetGUIObjectByName("gameSetupPage").hidden = loading;
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<object hidden="true" name="setupWindow">
|
||||
<object hidden="true" name="gameSetupPage">
|
||||
|
||||
<script directory="gui/gamesetup/Pages/GameSetupPage/"/>
|
||||
<script directory="gui/gamesetup/Pages/GameSetupPage/GameSettings/"/>
|
||||
@ -16,9 +16,6 @@
|
||||
<script directory="gui/gamesetup/Pages/GameSetupPage/Panels/Chat/"/>
|
||||
<script directory="gui/gamesetup/Pages/GameSetupPage/Panels/Chat/ChatMessages/"/>
|
||||
|
||||
<!-- TODO: Implement Engine.SetNetMessageHandler(msg => handlerFunction); instead of pulling onTick -->
|
||||
<object name="netMessages"/>
|
||||
|
||||
<object name="topPanel" size="24 40 100%-24 336">
|
||||
|
||||
<object size="0 0 100%-416 100%">
|
||||
|
@ -2,7 +2,7 @@ class ReadyButton
|
||||
{
|
||||
constructor(setupWindow)
|
||||
{
|
||||
this.readyControl = setupWindow.controls.readyControl;
|
||||
this.readyController = setupWindow.controls.readyController;
|
||||
|
||||
this.hidden = undefined;
|
||||
|
||||
@ -13,11 +13,11 @@ class ReadyButton
|
||||
this.readyButton.onPress = this.onPress.bind(this);
|
||||
this.readyButton.onPressRight = this.onPressRight.bind(this);
|
||||
|
||||
setupWindow.controls.playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
|
||||
setupWindow.controls.playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
|
||||
setupWindow.controls.netMessages.registerNetMessageHandler("netstatus", this.onNetStatusMessage.bind(this));
|
||||
|
||||
if (g_IsController && g_IsNetworked)
|
||||
this.readyControl.setReady(this.readyControl.StayReady, true);
|
||||
this.readyController.setReady(this.readyController.StayReady, true);
|
||||
}
|
||||
|
||||
registerButtonHiddenChangeHandler(handler)
|
||||
@ -60,18 +60,18 @@ class ReadyButton
|
||||
onPress()
|
||||
{
|
||||
let newState =
|
||||
(g_PlayerAssignments[Engine.GetPlayerGUID()].status + 1) % (this.readyControl.StayReady + 1);
|
||||
(g_PlayerAssignments[Engine.GetPlayerGUID()].status + 1) % (this.readyController.StayReady + 1);
|
||||
|
||||
for (let handler of this.readyButtonPressHandlers)
|
||||
handler(newState);
|
||||
|
||||
this.readyControl.setReady(newState, true);
|
||||
this.readyController.setReady(newState, true);
|
||||
}
|
||||
|
||||
onPressRight()
|
||||
{
|
||||
if (g_PlayerAssignments[Engine.GetPlayerGUID()].status != this.readyControl.NotReady)
|
||||
this.readyControl.setReady(this.readyControl.NotReady, true);
|
||||
if (g_PlayerAssignments[Engine.GetPlayerGUID()].status != this.readyController.NotReady)
|
||||
this.readyController.setReady(this.readyController.NotReady, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ class ResetCivsButton
|
||||
{
|
||||
constructor(setupWindow)
|
||||
{
|
||||
this.gameSettingsControl = setupWindow.controls.gameSettingsControl;
|
||||
this.gameSettingsController = setupWindow.controls.gameSettingsController;
|
||||
|
||||
this.civResetButton = Engine.GetGUIObjectByName("civResetButton");
|
||||
this.civResetButton.tooltip = this.Tooltip;
|
||||
@ -21,7 +21,7 @@ class ResetCivsButton
|
||||
for (let i = 0; i < g_GameSettings.playerCount.nbPlayers; ++i)
|
||||
g_GameSettings.playerCiv.setValue(i, "random");
|
||||
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ class ResetTeamsButton
|
||||
{
|
||||
constructor(setupWindow)
|
||||
{
|
||||
this.gameSettingsControl = setupWindow.controls.gameSettingsControl;
|
||||
this.gameSettingsController = setupWindow.controls.gameSettingsController;
|
||||
|
||||
this.teamResetButton = Engine.GetGUIObjectByName("teamResetButton");
|
||||
this.teamResetButton.tooltip = this.Tooltip;
|
||||
@ -21,7 +21,7 @@ class ResetTeamsButton
|
||||
for (let i = 0; i < g_GameSettings.playerCount.nbPlayers; ++i)
|
||||
g_GameSettings.playerTeam.setValue(i, -1);
|
||||
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ class StartGameButton
|
||||
this.startGameButton.onPress = this.onPress.bind(this);
|
||||
|
||||
setupWindow.registerLoadHandler(this.onLoad.bind(this));
|
||||
setupWindow.controls.playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.update.bind(this));
|
||||
setupWindow.controls.playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.update.bind(this));
|
||||
}
|
||||
|
||||
registerButtonHiddenChangeHandler(handler)
|
||||
@ -44,7 +44,7 @@ class StartGameButton
|
||||
|
||||
for (let guid in g_PlayerAssignments)
|
||||
if (g_PlayerAssignments[guid].player != -1 &&
|
||||
g_PlayerAssignments[guid].status == this.setupWindow.controls.readyControl.NotReady)
|
||||
g_PlayerAssignments[guid].status == this.setupWindow.controls.readyController.NotReady)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -57,7 +57,7 @@ class StartGameButton
|
||||
|
||||
this.gameStarted = true;
|
||||
this.update();
|
||||
this.setupWindow.controls.startGameControl.launchGame();
|
||||
this.setupWindow.controls.gameSettingsController.launchGame();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
class ChatInputAutocomplete
|
||||
{
|
||||
constructor(gameSettingControlManager, gameSettingsControl, playerAssignmentsControl)
|
||||
constructor(gameSettingControlManager, gameSettingsController, playerAssignmentsController)
|
||||
{
|
||||
this.gameSettingControlManager = gameSettingControlManager;
|
||||
this.entries = undefined;
|
||||
|
||||
playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onAutocompleteChange.bind(this));
|
||||
gameSettingsControl.registerSettingsChangeHandler(this.onAutocompleteChange.bind(this));
|
||||
playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.onAutocompleteChange.bind(this));
|
||||
gameSettingsController.registerSettingsChangeHandler(this.onAutocompleteChange.bind(this));
|
||||
}
|
||||
|
||||
onAutocompleteChange()
|
||||
|
@ -4,8 +4,8 @@ ChatMessageEvents.ClientConnection = class
|
||||
{
|
||||
this.chatMessagesPanel = chatMessagesPanel;
|
||||
|
||||
setupWindow.controls.playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
setupWindow.controls.playerAssignmentsControl.registerClientLeaveHandler(this.onClientLeave.bind(this));
|
||||
setupWindow.controls.playerAssignmentsController.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
setupWindow.controls.playerAssignmentsController.registerClientLeaveHandler(this.onClientLeave.bind(this));
|
||||
|
||||
this.args = {};
|
||||
}
|
||||
|
@ -5,15 +5,15 @@ ChatMessageEvents.GameSettingsChanged = class
|
||||
{
|
||||
constructor(setupWindow, chatMessagesPanel)
|
||||
{
|
||||
this.readyControl = setupWindow.controls.readyControl;
|
||||
this.readyController = setupWindow.controls.readyController;
|
||||
this.chatMessagesPanel = chatMessagesPanel;
|
||||
|
||||
this.readyControl.registerResetReadyHandler(this.onResetReady.bind(this));
|
||||
this.readyController.registerResetReadyHandler(this.onResetReady.bind(this));
|
||||
}
|
||||
|
||||
onResetReady()
|
||||
{
|
||||
if (this.readyControl.getLocalReadyState() == this.readyControl.Ready)
|
||||
if (this.readyController.getLocalReadyState() == this.readyController.Ready)
|
||||
this.chatMessagesPanel.addStatusMessage(this.MessageText);
|
||||
}
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ class ChatPanel
|
||||
this.chatMessagesPanel = new ChatMessagesPanel(gameSettingsPanel);
|
||||
|
||||
this.chatInputAutocomplete = new ChatInputAutocomplete(
|
||||
gameSettingControlManager, setupWindow.controls.gameSettingsControl, setupWindow.controls.playerAssignmentsControl);
|
||||
gameSettingControlManager, setupWindow.controls.gameSettingsController, setupWindow.controls.playerAssignmentsController);
|
||||
|
||||
this.chatInputPanel = new ChatInputPanel(
|
||||
setupWindow.controls.netMessages, this.chatInputAutocomplete);
|
||||
|
@ -9,8 +9,8 @@ class GameSettingsPanel
|
||||
this.gameSettingControlManager = gameSettingControlManager;
|
||||
this.gameSettingsPanelResizeHandlers = new Set();
|
||||
|
||||
this.setupWindow = Engine.GetGUIObjectByName("setupWindow");
|
||||
this.setupWindow.onWindowResized = this.onWindowResized.bind(this);
|
||||
this.gameSetupPage = Engine.GetGUIObjectByName("gameSetupPage");
|
||||
this.gameSetupPage.onWindowResized = this.onWindowResized.bind(this);
|
||||
|
||||
this.settingsPanel = Engine.GetGUIObjectByName("settingsPanel");
|
||||
|
||||
@ -19,7 +19,7 @@ class GameSettingsPanel
|
||||
this.lastTickTime = undefined;
|
||||
|
||||
gameSettingTabs.registerTabSelectHandler(this.updateSize.bind(this));
|
||||
setupWindow.controls.gameSettingsControl.registerUpdateLayoutHandler(this.updateSize.bind(this));
|
||||
setupWindow.controls.gameSettingsController.registerUpdateLayoutHandler(this.updateSize.bind(this));
|
||||
setupWindow.registerLoadHandler(this.triggerResizeHandlers.bind(this));
|
||||
}
|
||||
|
||||
@ -106,11 +106,11 @@ class GameSettingsPanel
|
||||
*/
|
||||
positionSettings()
|
||||
{
|
||||
let setupWindowSize = this.setupWindow.getComputedSize();
|
||||
let gameSetupPageSize = this.gameSetupPage.getComputedSize();
|
||||
|
||||
let columnWidth = Math.min(
|
||||
this.MaxColumnWidth,
|
||||
(setupWindowSize.right - setupWindowSize.left + this.centerRightPanel.size.left) / 2);
|
||||
(gameSetupPageSize.right - gameSetupPageSize.left + this.centerRightPanel.size.left) / 2);
|
||||
|
||||
let settingsPerColumn;
|
||||
{
|
||||
|
@ -3,7 +3,7 @@ class MapPreview
|
||||
constructor(setupWindow)
|
||||
{
|
||||
this.setupWindow = setupWindow;
|
||||
this.gameSettingsControl = setupWindow.controls.gameSettingsControl;
|
||||
this.gameSettingsController = setupWindow.controls.gameSettingsController;
|
||||
this.mapCache = setupWindow.controls.mapCache;
|
||||
|
||||
this.mapInfoName = Engine.GetGUIObjectByName("mapInfoName");
|
||||
|
@ -3,7 +3,7 @@ class SoundNotification
|
||||
constructor(setupWindow)
|
||||
{
|
||||
setupWindow.controls.netMessages.registerNetMessageHandler("chat", this.onClientChat.bind(this));
|
||||
setupWindow.controls.playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
setupWindow.controls.playerAssignmentsController.registerClientJoinHandler(this.onClientJoin.bind(this));
|
||||
}
|
||||
|
||||
onClientJoin(guid)
|
||||
|
@ -7,16 +7,11 @@ SetupWindowPages.LoadingPage = class
|
||||
{
|
||||
constructor(setupWindow)
|
||||
{
|
||||
setupWindow.controls.gameSettingsControl.registerLoadingChangeHandler((loading) => this.onLoadingChange(loading));
|
||||
setupWindow.controls.gameSettingsController.registerLoadingChangeHandler((loading) => this.onLoadingChange(loading));
|
||||
}
|
||||
|
||||
onLoadingChange(loading)
|
||||
{
|
||||
let loadingPage = Engine.GetGUIObjectByName("loadingPage");
|
||||
if (loadingPage.hidden === !loading)
|
||||
return;
|
||||
|
||||
loadingPage.hidden = !loading;
|
||||
Engine.GetGUIObjectByName("setupWindow").hidden = loading;
|
||||
Engine.GetGUIObjectByName("loadingPage").hidden = !loading;
|
||||
}
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ SetupWindowPages.MapBrowserPage = class extends MapBrowser
|
||||
super(setupWindow.controls.mapCache, setupWindow.controls.mapFilters, setupWindow);
|
||||
this.mapBrowserPage.hidden = true;
|
||||
|
||||
this.gameSettingsControl = setupWindow.controls.gameSettingsControl;
|
||||
this.gameSettingsController = setupWindow.controls.gameSettingsController;
|
||||
}
|
||||
|
||||
onSubmitMapSelection(map, type, filter)
|
||||
@ -17,12 +17,12 @@ SetupWindowPages.MapBrowserPage = class extends MapBrowser
|
||||
g_GameSettings.map.setType(type);
|
||||
|
||||
if (filter)
|
||||
this.gameSettingsControl.guiData.mapFilter.filter = filter;
|
||||
this.gameSettingsController.guiData.mapFilter.filter = filter;
|
||||
|
||||
if (map)
|
||||
g_GameSettings.map.selectMap(map);
|
||||
|
||||
this.gameSettingsControl.setNetworkInitAttributes();
|
||||
this.gameSettingsController.setNetworkInitAttributes();
|
||||
}
|
||||
|
||||
openPage()
|
||||
@ -30,7 +30,7 @@ SetupWindowPages.MapBrowserPage = class extends MapBrowser
|
||||
super.openPage();
|
||||
|
||||
this.controls.MapFiltering.select(
|
||||
this.gameSettingsControl.guiData.mapFilter.filter,
|
||||
this.gameSettingsController.guiData.mapFilter.filter,
|
||||
g_GameSettings.map.type || g_MapTypes.Name[g_MapTypes.Default]
|
||||
);
|
||||
if (g_GameSettings.map.map)
|
||||
|
@ -1,27 +1,26 @@
|
||||
/**
|
||||
* This class provides a way to save game settings to a file and load them.
|
||||
*/
|
||||
class GameSettingsFile
|
||||
class PersistentMatchSettings
|
||||
{
|
||||
constructor(GameSettingsControl)
|
||||
constructor(isNetworked)
|
||||
{
|
||||
this.filename = g_IsNetworked ?
|
||||
this.filename = isNetworked ?
|
||||
this.PersistedSettingsFileMultiplayer :
|
||||
this.PersistedSettingsFileSingleplayer;
|
||||
|
||||
this.gameSettingsControl = GameSettingsControl;
|
||||
|
||||
this.engineInfo = Engine.GetEngineInfo();
|
||||
this.enabled = Engine.ConfigDB_GetValue("user", this.ConfigName) == "true";
|
||||
}
|
||||
|
||||
loadFile()
|
||||
{
|
||||
if (!this.enabled)
|
||||
return {};
|
||||
|
||||
Engine.ProfileStart("loadPersistMatchSettingsFile");
|
||||
|
||||
let data =
|
||||
this.enabled &&
|
||||
g_IsController &&
|
||||
Engine.FileExists(this.filename) &&
|
||||
Engine.ReadJSONFile(this.filename);
|
||||
|
||||
@ -34,27 +33,25 @@ class GameSettingsFile
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete settings if disabled, so that players are not confronted with old settings after enabling the setting again.
|
||||
* Delete settings if disabled, so that players are not confronted
|
||||
* with old settings after enabling the setting again.
|
||||
*/
|
||||
saveFile()
|
||||
saveFile(settings)
|
||||
{
|
||||
if (!g_IsController)
|
||||
return;
|
||||
|
||||
Engine.ProfileStart("savePersistMatchSettingsFile");
|
||||
Engine.WriteJSONFile(this.filename, {
|
||||
"attributes": this.enabled ? this.gameSettingsControl.getSettings() : {},
|
||||
"attributes": this.enabled ? settings : {},
|
||||
"engine_info": this.engineInfo
|
||||
});
|
||||
Engine.ProfileStop();
|
||||
}
|
||||
}
|
||||
|
||||
GameSettingsFile.prototype.ConfigName =
|
||||
PersistentMatchSettings.prototype.ConfigName =
|
||||
"persistmatchsettings";
|
||||
|
||||
GameSettingsFile.prototype.PersistedSettingsFileSingleplayer =
|
||||
PersistentMatchSettings.prototype.PersistedSettingsFileSingleplayer =
|
||||
"config/matchsettings.json";
|
||||
|
||||
GameSettingsFile.prototype.PersistedSettingsFileMultiplayer =
|
||||
PersistentMatchSettings.prototype.PersistedSettingsFileMultiplayer =
|
||||
"config/matchsettings.mp.json";
|
@ -26,25 +26,23 @@ class SetupWindow
|
||||
let mapCache = new MapCache();
|
||||
g_GameSettings = new GameSettings().init(mapCache);
|
||||
|
||||
let netMessages = new NetMessages(this);
|
||||
let startGameControl = new StartGameControl(netMessages);
|
||||
let netMessages = new NetMessages();
|
||||
let mapFilters = new MapFilters(mapCache);
|
||||
let gameRegisterStanza = Engine.HasXmppClient() &&
|
||||
new GameRegisterStanza(initData, this, netMessages, mapCache);
|
||||
let playerAssignmentsControl = new PlayerAssignmentsControl(this, netMessages, gameRegisterStanza);
|
||||
let gameSettingsControl = new GameSettingsControl(this, netMessages, startGameControl, playerAssignmentsControl, mapCache);
|
||||
let readyControl = new ReadyControl(netMessages, gameSettingsControl, startGameControl, playerAssignmentsControl);
|
||||
let playerAssignmentsController = new PlayerAssignmentsController(this, netMessages);
|
||||
let gameSettingsController = new GameSettingsController(this, netMessages, playerAssignmentsController, mapCache);
|
||||
let readyController = new ReadyController(netMessages, gameSettingsController, playerAssignmentsController);
|
||||
let lobbyGameRegistrationController = Engine.HasXmppClient() &&
|
||||
new LobbyGameRegistrationController(initData, this, netMessages, mapCache, playerAssignmentsController);
|
||||
|
||||
// These class instances control central data and do not manage any GUI Object.
|
||||
this.controls = {
|
||||
"gameSettingsControl": gameSettingsControl,
|
||||
"playerAssignmentsControl": playerAssignmentsControl,
|
||||
"gameSettingsController": gameSettingsController,
|
||||
"playerAssignmentsController": playerAssignmentsController,
|
||||
"mapCache": mapCache,
|
||||
"mapFilters": mapFilters,
|
||||
"readyControl": readyControl,
|
||||
"startGameControl": startGameControl,
|
||||
"readyController": readyController,
|
||||
"netMessages": netMessages,
|
||||
"gameRegisterStanza": gameRegisterStanza
|
||||
"lobbyGameRegistrationController": lobbyGameRegistrationController
|
||||
};
|
||||
|
||||
// These are the pages within the setup window that may use the controls defined above
|
||||
@ -52,8 +50,9 @@ class SetupWindow
|
||||
for (let name in SetupWindowPages)
|
||||
this.pages[name] = new SetupWindowPages[name](this);
|
||||
|
||||
netMessages.registerNetMessageHandler("netwarn", addNetworkWarning);
|
||||
setTimeout(displayGamestateNotifications, 1000);
|
||||
Engine.GetGUIObjectByName("setupWindow").onTick = updateTimers;
|
||||
Engine.GetGUIObjectByName("setupWindow").onTick = () => this.onTick();
|
||||
|
||||
// This event is triggered after all classes have been instantiated and subscribed to each others events
|
||||
for (let handler of this.loadHandlers)
|
||||
@ -100,11 +99,19 @@ class SetupWindow
|
||||
return object;
|
||||
}
|
||||
|
||||
onTick()
|
||||
{
|
||||
this.controls.netMessages.pollPendingMessages();
|
||||
updateTimers();
|
||||
}
|
||||
|
||||
closePage()
|
||||
{
|
||||
for (let handler of this.closePageHandlers)
|
||||
handler();
|
||||
|
||||
Engine.DisconnectNetworkGame();
|
||||
|
||||
if (Engine.HasXmppClient())
|
||||
Engine.SwitchGuiPage("page_lobby.xml", { "dialog": false });
|
||||
else
|
||||
|
@ -6,11 +6,12 @@
|
||||
<script directory="gui/gamesettings/"/>
|
||||
<script directory="gui/gamesettings/attributes/"/>
|
||||
<script directory="gui/gamesetup/"/>
|
||||
<script directory="gui/gamesetup/Controls/"/>
|
||||
<script directory="gui/gamesetup/Controllers/"/>
|
||||
<script directory="gui/gamesetup/NetMessages/"/>
|
||||
<script directory="gui/gamesetup/Persistence/"/>
|
||||
|
||||
|
||||
<object type="image" style="ModernWindow">
|
||||
<object type="image" style="ModernWindow" name="setupWindow">
|
||||
|
||||
<object style="TitleText" type="text" size="50%-128 4 50%+128 36">
|
||||
<translatableAttribute id="caption">Match Setup</translatableAttribute>
|
||||
|
Loading…
Reference in New Issue
Block a user