Differential D3243 Diff 16556 ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js
/** | /** | ||||
* The GameSettingControl is an abstract class that is inherited by game-setting control classes specific to a GUI-object type, | * The GameSettingControl is an abstract class that is inherited by game-setting control classes specific to a GUI-object type, | ||||
* such as the GameSettingControlCheckbox or GameSettingControlDropdown. | * such as the GameSettingControlCheckbox or GameSettingControlDropdown. | ||||
* | * | ||||
* These classes are abstract classes too and are implemented by each handler class specific to one logical setting of g_GameAttributes. | * The purpose of these classes is to control one logical game setting. | ||||
* The purpose of these classes is to control precisely one logical setting of g_GameAttributes. | |||||
* Having one class per logical setting allows to handle each setting without making a restriction as to how the property should be written to g_GameAttributes or g_PlayerAssignments. | |||||
* The base classes allow implementing that while avoiding duplication. | * The base classes allow implementing that while avoiding duplication. | ||||
* | * | ||||
* A GameSettingControl may depend on and read from other g_GameAttribute values, | * GameSettingControl classes watch for g_GameSettings property changes, | ||||
* but the class instance is to be the sole instance writing to its setting value in g_GameAttributes and | * and re-render accordingly. They also trigger changes in g_GameSettings. | ||||
* shall not write to setting values of other logical settings. | |||||
* | * | ||||
* The derived classes shall not make assumptions on the validity of g_GameAttributes, | * The GameSettingControl classes are responsible for triggering network synchronisation, | ||||
* sanitize or delete their value if it is incompatible. | * and for updating the whole gamesetup layout when necessary. | ||||
* | |||||
* A class should only write values to g_GameAttributes that it itself has confirmed to be accurate. | |||||
* This means that handlers may not copy an entire object or array of values, for example on mapchange. | |||||
* This avoids writing a setting value to g_GameAttributes that is not tracked and deleted when it becomes invalid. | |||||
* | |||||
* Since GameSettingControls shall be able to subscribe to g_GameAttributes changes, | |||||
* it is an obligation of the derived GameSettingControl class to broadcast the GameAttributesChange event each time it changes g_GameAttributes. | |||||
*/ | */ | ||||
class GameSettingControl | class GameSettingControl /* extends Profilable /* Uncomment to profile controls without hassle. */ | ||||
{ | { | ||||
// The constructor and inherited constructors shall not modify game attributes, | |||||
// since all GameSettingControl shall be able to subscribe to any game-setting change. | |||||
constructor(gameSettingControlManager, category, playerIndex, setupWindow) | constructor(gameSettingControlManager, category, playerIndex, setupWindow) | ||||
{ | { | ||||
// Store arguments | // Store arguments | ||||
{ | { | ||||
this.category = category; | this.category = category; | ||||
this.playerIndex = playerIndex; | this.playerIndex = playerIndex; | ||||
this.setupWindow = setupWindow; | this.setupWindow = setupWindow; | ||||
Show All 18 Lines | constructor(gameSettingControlManager, category, playerIndex, setupWindow) | ||||
if (this.title && this.TitleCaption) | if (this.title && this.TitleCaption) | ||||
this.setTitle(this.TitleCaption); | this.setTitle(this.TitleCaption); | ||||
if (this.Tooltip) | if (this.Tooltip) | ||||
this.setTooltip(this.Tooltip); | this.setTooltip(this.Tooltip); | ||||
this.setHidden(false); | this.setHidden(false); | ||||
if (this.onMapChange) | |||||
this.gameSettingsControl.registerMapChangeHandler(this.onMapChange.bind(this)); | |||||
if (this.onLoad) | if (this.onLoad) | ||||
this.setupWindow.registerLoadHandler(this.onLoad.bind(this)); | this.setupWindow.registerLoadHandler(this.onLoad.bind(this)); | ||||
if (this.onGameAttributesChange) | |||||
this.gameSettingsControl.registerGameAttributesChangeHandler(this.onGameAttributesChange.bind(this)); | |||||
if (this.onGameAttributesBatchChange) | |||||
this.gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this)); | |||||
if (this.onAssignPlayer && this.playerIndex === 0) | |||||
this.gameSettingsControl.registerAssignPlayerHandler(this.onAssignPlayer.bind(this)); | |||||
if (this.onPickRandomItems) | |||||
this.gameSettingsControl.registerPickRandomItemsHandler(this.onPickRandomItems.bind(this)); | |||||
if (this.onGameAttributesFinalize) | |||||
this.gameSettingsControl.registerGameAttributesFinalizeHandler(this.onGameAttributesFinalize.bind(this)); | |||||
if (this.onPlayerAssignmentsChange) | if (this.onPlayerAssignmentsChange) | ||||
this.playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this)); | this.playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this)); | ||||
} | } | ||||
setTitle(titleCaption) | setTitle(titleCaption) | ||||
{ | { | ||||
this.autocompleteTitle = titleCaption; | this.autocompleteTitle = titleCaption; | ||||
this.title.caption = sprintf(this.TitleCaptionFormat, { | this.title.caption = sprintf(this.TitleCaptionFormat, { | ||||
"setting": titleCaption | "setting": titleCaption | ||||
}); | }); | ||||
} | } | ||||
setTooltip(tooltip) | setTooltip(tooltip) | ||||
{ | { | ||||
if (this.title) | if (this.title) | ||||
this.title.tooltip = tooltip; | this.title.tooltip = tooltip; | ||||
if (this.label) | if (this.label) | ||||
this.label.tooltip = tooltip; | this.label.tooltip = tooltip; | ||||
if (this.setControlTooltip) | if (this.setControlTooltip) | ||||
this.setControlTooltip(tooltip); | this.setControlTooltip(tooltip); | ||||
} | } | ||||
/** | |||||
* Do not call functions calling updateVisibility onMapChange but onGameAttributesChange, | |||||
* so that changes take effect when increasing the playercount as well. | |||||
*/ | |||||
setEnabled(enabled) | setEnabled(enabled) | ||||
{ | { | ||||
this.enabled = enabled; | this.enabled = enabled; | ||||
this.updateVisibility(); | this.updateVisibility(); | ||||
} | } | ||||
setHidden(hidden) | setHidden(hidden) | ||||
{ | { | ||||
this.hidden = hidden; | this.hidden = hidden; | ||||
this.updateVisibility(); | // Trigger a layout update to reposition items. | ||||
this.gameSettingsControl.updateLayout(); | |||||
} | } | ||||
updateVisibility() | updateVisibility() | ||||
{ | { | ||||
let hidden = | let hidden = | ||||
this.hidden || | this.hidden || | ||||
this.playerIndex === undefined && | this.playerIndex === undefined && | ||||
this.category != g_TabCategorySelected || | this.category != g_TabCategorySelected || | ||||
this.playerIndex !== undefined && | this.playerIndex !== undefined && | ||||
g_GameAttributes.settings && this.playerIndex >= g_GameAttributes.settings.PlayerData.length; | this.playerIndex >= g_GameSettings.playerCount.nbPlayers; | ||||
if (this.frame) | if (this.frame) | ||||
this.frame.hidden = hidden; | this.frame.hidden = hidden; | ||||
if (hidden) | if (hidden) | ||||
return; | return; | ||||
let enabled = g_IsController && this.enabled; | let enabled = g_IsController && this.enabled; | ||||
Show All 40 Lines |
Wildfire Games · Phabricator