Index: binaries/data/mods/public/gui/aiconfig/aiconfig.js
===================================================================
--- binaries/data/mods/public/gui/aiconfig/aiconfig.js
+++ binaries/data/mods/public/gui/aiconfig/aiconfig.js
@@ -1,82 +0,0 @@
-/**
- * Is this user in control of game settings (i.e. is a network server, or offline player).
- */
-const g_IsController = !Engine.HasNetClient() || Engine.HasNetServer();
-
-var g_PlayerSlot;
-
-var g_AIDescriptions = [{
- "id": "",
- "data": {
- "name": translateWithContext("ai", "None"),
- "description": translate("AI will be disabled for this player.")
- }
-}].concat(g_Settings.AIDescriptions);
-
-var g_AIControls = {
- "aiSelection": {
- "labels": g_AIDescriptions.map(ai => ai.data.name),
- "selected": settings => g_AIDescriptions.findIndex(ai => ai.id == settings.id)
- },
- "aiDifficulty": {
- "labels": prepareForDropdown(g_Settings.AIDifficulties).Title,
- "selected": settings => settings.difficulty
- },
- "aiBehavior": {
- "labels": prepareForDropdown(g_Settings.AIBehaviors).Title,
- "selected": settings => g_Settings.AIBehaviors.findIndex(b => b.Name == settings.behavior)
- }
-};
-
-function init(settings)
-{
- // Remember the player ID that we change the AI settings for
- g_PlayerSlot = settings.playerSlot;
-
- let enabled = g_IsController && !settings.fixed;
-
- for (let name in g_AIControls)
- {
- let control = Engine.GetGUIObjectByName(name);
- control.list = g_AIControls[name].labels;
- control.selected = g_AIControls[name].selected(settings);
- control.hidden = !enabled;
-
- let label = Engine.GetGUIObjectByName(name + "Text");
- label.caption = control.list[control.selected];
- label.hidden = enabled;
- }
-
- checkBehavior();
-}
-
-function selectAI(idx)
-{
- Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description;
-}
-
-/** Behavior choice does not apply for Sandbox level */
-function checkBehavior()
-{
- if (g_Settings.AIDifficulties[Engine.GetGUIObjectByName("aiDifficulty").selected].Name != "sandbox")
- {
- Engine.GetGUIObjectByName("aiBehavior").enabled = true;
- return;
- }
- let aiBehavior = Engine.GetGUIObjectByName("aiBehavior");
- aiBehavior.enabled = false;
- aiBehavior.selected = g_Settings.AIBehaviors.findIndex(b => b.Name == "balanced");
-}
-
-function returnAI(save = true)
-{
- let idx = Engine.GetGUIObjectByName("aiSelection").selected;
- Engine.PopGuiPage({
- "save": save,
- "id": g_AIDescriptions[idx].id,
- "name": g_AIDescriptions[idx].data.name,
- "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
- "behavior": g_Settings.AIBehaviors[Engine.GetGUIObjectByName("aiBehavior").selected].Name,
- "playerSlot": g_PlayerSlot
- });
-}
Index: binaries/data/mods/public/gui/aiconfig/aiconfig.xml
===================================================================
--- binaries/data/mods/public/gui/aiconfig/aiconfig.xml
+++ binaries/data/mods/public/gui/aiconfig/aiconfig.xml
@@ -1,56 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControl.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControl.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControl.js
@@ -1,178 +0,0 @@
-/**
- * The GameSettingControl is an abstract class that is inherited by gamesetting control classes specific to a GUI object type,
- * 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 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.
- *
- * A GameSettingControl may depend on and read from other g_GameAttribute values,
- * but the class instance is to be the sole instance writing to its setting value in g_GameAttributes and
- * shall not write to setting values of other logical settings.
- *
- * The derived classes shall not make assumptions on the validity of g_GameAttributes,
- * sanitize or delete their value if it is incompatible.
- *
- * 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
-{
- // The constructor and inherited constructors shall not modify game attributes,
- // since all GameSettingControl shall be able to subscribe to any gamesetting change.
- constructor(gameSettingControlManager, category, playerIndex, gamesetupPage, gameSettingsControl, mapCache, mapFilters, netMessages, playerAssignmentsControl)
- {
- // Store arguments
- {
- this.category = category;
- if (playerIndex !== undefined)
- this.playerIndex = playerIndex;
- this.gamesetupPage = gamesetupPage;
- this.gameSettingsControl = gameSettingsControl;
- this.mapCache = mapCache;
- this.mapFilters = mapFilters;
- this.netMessages = netMessages;
- this.playerAssignmentsControl = playerAssignmentsControl;
- }
-
- // enabled and hidden should only be modified through their setters or
- // by calling updateVisibility after modification.
- this.enabled = true;
- this.hidden = false;
-
- if (this.setControl)
- this.setControl(gameSettingControlManager);
-
- // This variable also used for autocompleting chat.
- this.autocompleteTitle = undefined;
-
- if (this.title && this.TitleCaption)
- this.setTitle(this.TitleCaption);
-
- if (this.Tooltip)
- this.setTooltip(this.Tooltip);
-
- this.setHidden(false);
-
- if (this.onMapChange)
- gameSettingsControl.registerMapChangeHandler(this.onMapChange.bind(this));
-
- if (this.onLoad)
- gamesetupPage.registerLoadHandler(this.onLoad.bind(this));
-
- if (this.onGameAttributesChange)
- gameSettingsControl.registerGameAttributesChangeHandler(this.onGameAttributesChange.bind(this));
-
- if (this.onGameAttributesBatchChange)
- gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
-
- if (this.onAssignPlayer && this.playerIndex === 0)
- this.gameSettingsControl.registerAssignPlayerHandler(this.onAssignPlayer.bind(this));
-
- if (this.onPickRandomItems)
- gameSettingsControl.registerPickRandomItemsHandler(this.onPickRandomItems.bind(this));
-
- if (this.onGameAttributesFinalize)
- gameSettingsControl.registerGameAttributesFinalizeHandler(this.onGameAttributesFinalize.bind(this));
-
- if (this.onPlayerAssignmentsChange)
- playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
- }
-
- setTitle(titleCaption)
- {
- this.autocompleteTitle = titleCaption;
- this.title.caption = sprintf(this.TitleCaptionFormat, {
- "setting": titleCaption
- });
- }
-
- setTooltip(tooltip)
- {
- if (this.title)
- this.title.tooltip = tooltip;
-
- if (this.label)
- this.label.tooltip = tooltip;
-
- if (this.setControlTooltip)
- 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)
- {
- this.enabled = enabled;
- this.updateVisibility();
- }
-
- setHidden(hidden)
- {
- this.hidden = hidden;
- this.updateVisibility();
- }
-
- updateVisibility()
- {
- let hidden =
- this.hidden ||
- this.playerIndex === undefined &&
- this.category != g_TabCategorySelected ||
- this.playerIndex !== undefined &&
- g_GameAttributes.settings && this.playerIndex >= g_GameAttributes.settings.PlayerData.length;
-
- if (this.frame)
- this.frame.hidden = hidden;
-
- if (hidden)
- return;
-
- let enabled = g_IsController && this.enabled;
-
- if (this.setControlHidden)
- this.setControlHidden(!enabled);
-
- if (this.label)
- this.label.hidden = !!enabled;
- }
-
- /**
- * Returns whether the control specifies an order but didn't implement the function.
- */
- addAutocompleteEntries(name, autocomplete)
- {
- if (this.autocompleteTitle)
- autocomplete[0].push(this.autocompleteTitle);
-
- if (!Number.isInteger(this.AutocompleteOrder))
- return;
-
- if (!this.getAutocompleteEntries)
- {
- error(name + " specifies AutocompleteOrder but didn't implement getAutocompleteEntries");
- return;
- }
-
- let newEntries = this.getAutocompleteEntries();
- if (newEntries)
- autocomplete[this.AutocompleteOrder] =
- (autocomplete[this.AutocompleteOrder] || []).concat(newEntries);
- }
-}
-
-GameSettingControl.prototype.TitleCaptionFormat =
- translateWithContext("Title for specific setting", "%(setting)s:");
-
-/**
- * Derived classes can set this to a number to enable chat autocompleting of setting values.
- * Higher numbers are autocompleted first.
- */
-GameSettingControl.prototype.AutocompleteOrder = undefined;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlCheckbox.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlCheckbox.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlCheckbox.js
@@ -1,60 +0,0 @@
-/**
- * This class is implemented by gamesettings that are controlled by a checkbox.
- */
-class GameSettingControlCheckbox extends GameSettingControl
-{
- constructor(...args)
- {
- super(...args);
-
- this.isInGuiUpdate = false;
- this.previousSelectedValue = undefined;
- }
-
- setControl(gameSettingControlManager)
- {
- let row = gameSettingControlManager.getNextRow("checkboxSettingFrame");
- this.frame = Engine.GetGUIObjectByName("checkboxSettingFrame[" + row + "]");
- this.checkbox = Engine.GetGUIObjectByName("checkboxSettingControl[" + row + "]");
- this.checkbox.onPress = this.onPressSuper.bind(this);
-
- let labels = this.frame.children[0].children;
- this.title = labels[0];
- this.label = labels[1];
- }
-
- setControlTooltip(tooltip)
- {
- this.checkbox.tooltip = tooltip;
- }
-
- setControlHidden(hidden)
- {
- this.checkbox.hidden = hidden;
- }
-
- setChecked(checked)
- {
- if (this.previousSelectedValue == checked)
- return;
-
- this.isInGuiUpdate = true;
- this.checkbox.checked = checked;
- this.isInGuiUpdate = false;
-
- if (this.label)
- this.label.caption = checked ? this.Checked : this.Unchecked;
- }
-
- onPressSuper()
- {
- if (!this.isInGuiUpdate)
- this.onPress(this.checkbox.checked);
- }
-}
-
-GameSettingControlCheckbox.prototype.Checked =
- translate("Yes");
-
-GameSettingControlCheckbox.prototype.Unchecked =
- translate("No");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlCheckbox.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlCheckbox.xml
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlCheckbox.xml
@@ -1,14 +0,0 @@
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlDropdown.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlDropdown.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlDropdown.js
@@ -1,64 +0,0 @@
-/**
- * This class is implemented by gamesettings that are controlled by a dropdown.
- */
-class GameSettingControlDropdown extends GameSettingControl
-{
- constructor(...args)
- {
- super(...args);
-
- this.isInGuiUpdate = false;
- this.dropdown.onSelectionChange = this.onSelectionChangeSuper.bind(this);
- if (this.onHoverChange)
- this.dropdown.onHoverChange = this.onHoverChange.bind(this);
- }
-
- setControl(gameSettingControlManager)
- {
- let row = gameSettingControlManager.getNextRow("dropdownSettingFrame");
- this.frame = Engine.GetGUIObjectByName("dropdownSettingFrame[" + row + "]");
- this.dropdown = Engine.GetGUIObjectByName("dropdownSettingControl[" + row + "]");
-
- let labels = this.frame.children[0].children;
- this.title = labels[0];
- this.label = labels[1];
- }
-
- setControlTooltip(tooltip)
- {
- this.dropdown.tooltip = tooltip;
- }
-
- setControlHidden(hidden)
- {
- this.dropdown.hidden = hidden;
- }
-
- setSelectedValue(value)
- {
- let index = this.dropdown.list_data.indexOf(String(value));
-
- this.isInGuiUpdate = true;
- this.dropdown.selected = index;
- this.isInGuiUpdate = false;
-
- if (this.label)
- this.label.caption = index == -1 ? this.UnknownValue : this.dropdown.list[index];
- }
-
- onSelectionChangeSuper()
- {
- if (!this.isInGuiUpdate)
- this.onSelectionChange(this.dropdown.selected);
- }
-}
-
-/**
- * Highlight the "random" dropdownlist item.
- */
-GameSettingControlDropdown.prototype.RandomItemTags = {
- "color": "orange"
-};
-
-GameSettingControlDropdown.prototype.UnknownValue =
- translateWithContext("settings value", "Unknown");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlDropdown.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlDropdown.xml
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlDropdown.xml
@@ -1,14 +0,0 @@
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlLabels.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlLabels.xml
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlLabels.xml
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlManager.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlManager.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingControlManager.js
@@ -1,66 +0,0 @@
-/**
- * Each property of this class is a class that inherits GameSettingControl and is
- * instantiated by the GameSettingControlManager.
- */
-class GameSettingControls
-{
-}
-
-/**
- * The GameSettingControlManager owns all classes that handle a logical property of g_GameAttributes.
- */
-class GameSettingControlManager
-{
- constructor(gamesetupPage, gameSettingsControl, mapCache, mapFilters, netMessages, playerAssignmentsControl)
- {
- this.gameSettingsControl = gameSettingsControl;
-
- this.rows = {};
- this.gameSettingControls = {};
-
- let args = Array.from(arguments);
-
- let getCategory = name =>
- g_GameSettingsLayout.findIndex(category => category.settings.indexOf(name) != -1);
-
- for (let name in GameSettingControls)
- this.gameSettingControls[name] =
- new GameSettingControls[name](
- this, getCategory(name), undefined, ...args);
-
- for (let victoryCondition of g_VictoryConditions)
- this.gameSettingControls[victoryCondition.Name] =
- new VictoryConditionCheckbox(
- victoryCondition, this, getCategory(victoryCondition.Name), undefined, ...args);
-
- this.playerSettingControlManagers = Array.from(
- new Array(g_MaxPlayers),
- (value, playerIndex) =>
- new PlayerSettingControlManager(playerIndex, ...args));
- }
-
- getNextRow(name)
- {
- if (this.rows[name] === undefined)
- this.rows[name] = 0;
- else
- ++this.rows[name];
-
- return this.rows[name];
- }
-
- updateSettingVisibility()
- {
- for (let name in this.gameSettingControls)
- this.gameSettingControls[name].updateVisibility();
- }
-
- addAutocompleteEntries(entries)
- {
- for (let name in this.gameSettingControls)
- this.gameSettingControls[name].addAutocompleteEntries(name, entries);
-
- for (let playerSettingControlManager of this.playerSettingControlManagers)
- playerSettingControlManager.addAutocompleteEntries(entries);
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingsLayout.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingsLayout.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/GameSettingsLayout.js
@@ -1,48 +0,0 @@
-/**
- * This array determines the order in which the GUI controls are shown in the GameSettingTabs panel.
- * The names correspond to property names of the GameSettingControls prototype.
- */
-var g_GameSettingsLayout = [
- {
- "label": translateWithContext("Match settings tab name", "Map"),
- "settings": [
- "MapType",
- "MapFilter",
- "MapSelection",
- "MapSize",
- "Landscape",
- "Biome",
- "Daytime",
- "TriggerDifficulty",
- "Nomad",
- "Treasures",
- "ExploredMap",
- "RevealedMap"
- ]
- },
- {
- "label": translateWithContext("Match settings tab name", "Player"),
- "settings": [
- "PlayerCount",
- "PopulationCap",
- "StartingResources",
- "Spies",
- "Cheats"
- ]
- },
- {
- "label": translateWithContext("Match settings tab name", "Game Type"),
- "settings": [
- ...g_VictoryConditions.map(victoryCondition => victoryCondition.Name),
- "RelicCount",
- "RelicDuration",
- "WonderDuration",
- "RegicideGarrison",
- "GameSpeed",
- "Ceasefire",
- "LockedTeams",
- "LastManStanding",
- "Rating"
- ]
- }
-];
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/AIConfigButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/AIConfigButton.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/AIConfigButton.js
@@ -1,188 +0,0 @@
-PlayerSettingControls.AIConfigButton = class extends GameSettingControl
-{
- constructor(...args)
- {
- super(...args);
-
- this.playerConfig = Engine.GetGUIObjectByName("playerConfig[" + this.playerIndex + "]");
-
- this.isPageOpen = false;
- this.guid = undefined;
- this.fixedAI = undefined;
-
- this.defaultAIDiff = +Engine.ConfigDB_GetValue("user", this.ConfigDifficulty);
- this.defaultBehavior = Engine.ConfigDB_GetValue("user", this.ConfigBehavior);
-
- // Save little performance by not reallocating every call
- this.sprintfArgs = {};
-
- this.playerConfig.onPress = this.openConfigPage.bind(this, this.playerIndex);
- }
-
- onMapChange(mapData)
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- let isScenario = g_GameAttributes.mapType == "scenario";
-
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- if (mapPData && mapPData.AI)
- {
- let defaultPData = g_Settings.PlayerDefaults[this.playerIndex + 1];
-
- this.fixedAI = {
- "AI": mapPData.AI,
- "AIDiff":
- mapPData.AIDiff !== undefined ?
- mapPData.AIDiff :
- defaultPData.AIDiff,
- "AIBehavior":
- mapPData.AIBehavior !== undefined ?
- mapPData.AIBehavior :
- defaultPData.AIBehavior
- };
- }
- else
- this.fixedAI = undefined;
- }
-
- onAssignPlayer(source, target)
- {
- if (source && target.AI)
- {
- source.AI = target.AI;
- source.AIDiff = target.AIDiff;
- source.AIBehavior = target.AIBehavior;
- }
-
- target.AI = false;
- delete target.AIDiff;
- delete target.AIBehavior;
- }
-
- onPlayerAssignmentsChange()
- {
- this.guid = undefined;
-
- for (let guid in g_PlayerAssignments)
- if (g_PlayerAssignments[guid].player == this.playerIndex + 1)
- this.guid = guid;
- }
-
- onGameAttributesChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- // Enforce map specified AI
- if (this.fixedAI &&
- (pData.AI !== this.fixedAI.AI ||
- pData.AIDiff !== this.fixedAI.AIDiff ||
- pData.AIBehavior !== this.fixedAI.AIBehavior))
- {
- pData.AI = this.fixedAI.AI;
- pData.AIDiff = this.fixedAI.AIDiff;
- pData.AIBehavior = this.fixedAI.AIBehavior;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- // Sanitize, make AI state self-consistent
- if (pData.AI)
- {
- if (pData.AIDiff === undefined || pData.AIBehavior === undefined)
- {
- if (pData.AIDiff === undefined)
- pData.AIDiff = this.defaultAIDiff;
-
- if (pData.AIBehavior === undefined)
- pData.AIBehavior = this.defaultBehavior;
-
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (pData.AI === undefined)
- {
- if (this.guid)
- pData.AI = false;
- else
- {
- pData.AI = g_Settings.PlayerDefaults[this.playerIndex + 1].AI;
- pData.AIDiff = this.defaultAIDiff;
- pData.AIBehavior = this.defaultBehavior;
- }
- this.gameSettingsControl.updateGameAttributes();
- }
- else if (pData.AIBehavior !== undefined || pData.AIDiff !== undefined)
- {
- pData.AI = false;
- delete pData.AIBehavior;
- delete pData.AIDiff;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- let isPageOpen = this.isPageOpen;
- if (isPageOpen)
- Engine.PopGuiPage();
-
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- this.sprintfArgs.description = translateAISettings(pData);
- this.playerConfig.tooltip = sprintf(this.Tooltip, this.sprintfArgs);
- this.playerConfig.hidden = !pData.AI;
-
- if (isPageOpen)
- this.openConfigPage();
- }
-
- openConfigPage()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData || !pData.AI)
- return;
-
- this.isPageOpen = true;
- Engine.PushGuiPage(
- "page_aiconfig.xml",
- {
- "playerSlot": this.playerIndex,
- "id": pData.AI,
- "difficulty": pData.AIDiff,
- "behavior": pData.AIBehavior,
- "fixed": !!this.fixedAI
- },
- this.onConfigPageClosed.bind(this));
- }
-
- onConfigPageClosed(data)
- {
- this.isPageOpen = false;
-
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!data || !data.save || !g_IsController || !pData)
- return;
-
- pData.AI = data.id;
- pData.AIDiff = data.difficulty;
- pData.AIBehavior = data.behavior;
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-PlayerSettingControls.AIConfigButton.prototype.Tooltip =
- translate("Configure AI: %(description)s.");
-
-PlayerSettingControls.AIConfigButton.prototype.ConfigDifficulty =
- "gui.gamesetup.aidifficulty";
-
-PlayerSettingControls.AIConfigButton.prototype.ConfigBehavior =
- "gui.gamesetup.aibehavior";
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerAssignment.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerAssignment.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerAssignment.js
@@ -1,269 +0,0 @@
-PlayerSettingControls.PlayerAssignment = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.clientItemFactory = new PlayerAssignmentItem.Client();
- this.aiItemFactory = new PlayerAssignmentItem.AI();
- this.unassignedItem = new PlayerAssignmentItem.Unassigned().createItem();
-
- this.aiItems =
- g_Settings.AIDescriptions.filter(ai => !ai.data.hidden).map(
- this.aiItemFactory.createItem.bind(this.aiItemFactory));
-
- this.values = undefined;
- this.assignedGUID = undefined;
- this.fixedAI = undefined;
-
- this.playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
- }
-
- setControl()
- {
- this.dropdown = Engine.GetGUIObjectByName("playerAssignment[" + this.playerIndex + "]");
- this.label = Engine.GetGUIObjectByName("playerAssignmentText[" + this.playerIndex + "]");
- }
-
- onLoad(initData, hotloadData)
- {
- if (!hotloadData && !g_IsNetworked)
- this.onClientJoin("local", g_PlayerAssignments);
- }
-
- onClientJoin(newGUID, newAssignments)
- {
- if (!g_IsController || this.fixedAI || newAssignments[newGUID].player != -1)
- return;
-
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- // Assign the client (or only buddies if prefered) to a free slot
- if (newGUID != Engine.GetPlayerGUID())
- {
- let assignOption = Engine.ConfigDB_GetValue("user", this.ConfigAssignPlayers);
- if (assignOption == "disabled" ||
- assignOption == "buddies" && g_Buddies.indexOf(splitRatingFromNick(newAssignments[newGUID].name).nick) == -1)
- return;
- }
-
- for (let guid in newAssignments)
- if (newAssignments[guid].player == this.playerIndex + 1)
- return;
-
- if (pData.AI)
- {
- pData.AI = false;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- newAssignments[newGUID].player = this.playerIndex + 1;
- this.playerAssignmentsControl.assignClient(newGUID, this.playerIndex + 1);
- }
-
- onPlayerAssignmentsChange()
- {
- this.assignedGUID = undefined;
- for (let guid in g_PlayerAssignments)
- if (g_PlayerAssignments[guid].player == this.playerIndex + 1)
- {
- this.assignedGUID = guid;
- break;
- }
-
- this.playerItems = sortGUIDsByPlayerID().map(
- this.clientItemFactory.createItem.bind(this.clientItemFactory));
-
- this.rebuildList();
- this.updateSelection();
- }
-
- onMapChange(mapData)
- {
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- this.fixedAI = mapPData && mapPData.AI || undefined;
- }
-
- onGameAttributesChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- if (this.fixedAI && pData.AI != this.fixedAI)
- {
- pData.AI = this.fixedAI;
- this.gameSettingsControl.updateGameAttributes();
- this.playerAssignmentsControl.unassignClient(this.playerIndex + 1);
- }
- }
-
- onGameAttributesBatchChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- this.setEnabled(!this.fixedAI);
- this.updateSelection();
- }
-
- updateSelection()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (pData && this.values)
- this.setSelectedValue(
- this.values.Value.findIndex((value, i) =>
- this.values.Handler[i].isSelected(pData, this.assignedGUID, value)));
- }
-
- rebuildList()
- {
- Engine.ProfileStart("updatePlayerAssignmentsList");
- this.values = prepareForDropdown([
- ...this.playerItems,
- ...this.aiItems,
- this.unassignedItem
- ]);
-
- this.dropdown.list = this.values.Caption;
- this.dropdown.list_data = this.values.Value.map((value, i) => i);
- Engine.ProfileStop();
- }
-
- onSelectionChange(itemIdx)
- {
- this.values.Handler[itemIdx].onSelectionChange(
- this.gameSettingsControl,
- this.playerAssignmentsControl,
- this.playerIndex,
- this.values.Value[itemIdx]);
- }
-
- getAutocompleteEntries()
- {
- return this.values.Autocomplete;
- }
-};
-
-PlayerSettingControls.PlayerAssignment.prototype.Tooltip =
- translate("Select player.");
-
-PlayerSettingControls.PlayerAssignment.prototype.AutocompleteOrder = 100;
-
-PlayerSettingControls.PlayerAssignment.prototype.ConfigAssignPlayers =
- "gui.gamesetup.assignplayers";
-
-class PlayerAssignmentItem
-{
-}
-
-{
- PlayerAssignmentItem.Client = class
- {
- createItem(guid)
- {
- return {
- "Handler": this,
- "Value": guid,
- "Autocomplete": g_PlayerAssignments[guid].name,
- "Caption": setStringTags(
- g_PlayerAssignments[guid].name,
- g_PlayerAssignments[guid].player == -1 ? this.ObserverTags : this.PlayerTags)
- };
- }
-
- onSelectionChange(gameSettingsControl, playerAssignmentsControl, playerIndex, guidToAssign)
- {
- let sourcePlayer = g_PlayerAssignments[guidToAssign].player - 1;
- playerAssignmentsControl.assignPlayer(guidToAssign, playerIndex);
- gameSettingsControl.assignPlayer(sourcePlayer, playerIndex);
- }
-
- isSelected(pData, guid, value)
- {
- return guid !== undefined && guid == value;
- }
- };
-
- PlayerAssignmentItem.Client.prototype.PlayerTags =
- { "color": "white" };
-
- PlayerAssignmentItem.Client.prototype.ObserverTags =
- { "color": "170 170 250" };
-}
-
-{
- PlayerAssignmentItem.AI = class
- {
- createItem(ai)
- {
- let aiName = translate(ai.data.name);
- return {
- "Handler": this,
- "Value": ai.id,
- "Autocomplete": aiName,
- "Caption": setStringTags(sprintf(this.Label, { "ai": aiName }), this.Tags)
- };
- }
-
- onSelectionChange(gameSettingsControl, playerAssignmentsControl, playerIndex, value)
- {
- playerAssignmentsControl.unassignClient(playerIndex + 1);
-
- g_GameAttributes.settings.PlayerData[playerIndex].AI = value;
-
- gameSettingsControl.updateGameAttributes();
- gameSettingsControl.setNetworkGameAttributes();
- }
-
- isSelected(pData, guid, value)
- {
- return !guid && pData.AI && pData.AI == value;
- }
- };
-
- PlayerAssignmentItem.AI.prototype.Label =
- translate("AI: %(ai)s");
-
- PlayerAssignmentItem.AI.prototype.Tags =
- { "color": "70 150 70" };
-}
-
-{
- PlayerAssignmentItem.Unassigned = class
- {
- createItem()
- {
- return {
- "Handler": this,
- "Value": undefined,
- "Autocomplete": this.Label,
- "Caption": setStringTags(this.Label, this.Tags)
- };
- }
-
- onSelectionChange(gameSettingsControl, playerAssignmentsControl, playerIndex)
- {
- playerAssignmentsControl.unassignClient(playerIndex + 1);
-
- g_GameAttributes.settings.PlayerData[playerIndex].AI = false;
- gameSettingsControl.updateGameAttributes();
- gameSettingsControl.setNetworkGameAttributes();
- }
-
- isSelected(pData, guid, value)
- {
- return !guid && !pData.AI;
- }
- };
-
- PlayerAssignmentItem.Unassigned.prototype.Label =
- translate("Unassigned");
-
- PlayerAssignmentItem.Unassigned.prototype.Tags =
- { "color": "140 140 140" };
-}
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js
@@ -1,142 +0,0 @@
-PlayerSettingControls.PlayerCiv = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.fixedCiv = undefined;
- this.values = prepareForDropdown(this.getItems());
-
- this.dropdown.list = this.values.name;
- this.dropdown.list_data = this.values.civ;
- }
-
- setControl()
- {
- this.label = Engine.GetGUIObjectByName("playerCivText[" + this.playerIndex + "]");
- this.dropdown = Engine.GetGUIObjectByName("playerCiv[" + this.playerIndex + "]");
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = this.values && this.values.tooltip[this.dropdown.hovered] || this.Tooltip;
- }
-
- onMapChange(mapData)
- {
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- this.fixedCiv = mapPData && mapPData.Civ || undefined;
- }
-
- onAssignPlayer(source, target)
- {
- if (g_GameAttributes.mapType != "scenario" && source && target)
- [source.Civ, target.Civ] = [target.Civ, source.Civ];
- }
-
- onGameAttributesChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData || !g_GameAttributes.mapType)
- return;
-
- if (this.fixedCiv)
- {
- if (!pData.Civ || this.fixedCiv != pData.Civ)
- {
- pData.Civ = this.fixedCiv;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (this.values.civ.indexOf(pData.Civ || undefined) == -1)
- {
- pData.Civ =
- g_GameAttributes.mapType == "scenario" ?
- g_Settings.PlayerDefaults[this.playerIndex + 1].Civ :
- this.RandomCivId;
-
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData || !g_GameAttributes.mapType)
- return;
-
- this.setEnabled(!this.fixedCiv);
- this.setSelectedValue(pData.Civ);
- }
-
- getItems()
- {
- let values = [];
-
- for (let civ in g_CivData)
- if (g_CivData[civ].SelectableInGameSetup)
- values.push({
- "name": g_CivData[civ].Name,
- "autocomplete": g_CivData[civ].Name,
- "tooltip": g_CivData[civ].History,
- "civ": civ
- });
-
- values.sort(sortNameIgnoreCase);
-
- values.unshift({
- "name": setStringTags(this.RandomCivCaption, this.RandomItemTags),
- "autocomplete": this.RandomCivCaption,
- "tooltip": this.RandomCivTooltip,
- "civ": this.RandomCivId
- });
-
- return values;
- }
-
- getAutocompleteEntries()
- {
- return this.values.autocomplete;
- }
-
- onSelectionChange(itemIdx)
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- pData.Civ = this.values.civ[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- onPickRandomItems()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData || pData.Civ != this.RandomCivId)
- return;
-
- // Get a unique array of selectable cultures
- let cultures = Object.keys(g_CivData).filter(civ => g_CivData[civ].SelectableInGameSetup).map(civ => g_CivData[civ].Culture);
- cultures = cultures.filter((culture, index) => cultures.indexOf(culture) === index);
-
- // Pick a random civ of a random culture
- let culture = pickRandom(cultures);
- pData.Civ = pickRandom(Object.keys(g_CivData).filter(civ =>
- g_CivData[civ].Culture == culture && g_CivData[civ].SelectableInGameSetup));
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.pickRandomItems();
- }
-};
-
-PlayerSettingControls.PlayerCiv.prototype.Tooltip =
- translate("Choose the civilization for this player.");
-
-PlayerSettingControls.PlayerCiv.prototype.RandomCivCaption =
- translateWithContext("civilization", "Random");
-
-PlayerSettingControls.PlayerCiv.prototype.RandomCivId =
- "random";
-
-PlayerSettingControls.PlayerCiv.prototype.RandomCivTooltip =
- translate("Picks one civilization at random when the game starts.");
-
-PlayerSettingControls.PlayerCiv.prototype.AutocompleteOrder = 90;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerColor.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerColor.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerColor.js
@@ -1,175 +0,0 @@
-PlayerSettingControls.PlayerColor = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.defaultColors = g_Settings.PlayerDefaults.slice(1).map(pData => pData.Color);
- }
-
- setControl()
- {
- this.dropdown = Engine.GetGUIObjectByName("playerColor[" + this.playerIndex + "]");
- this.playerBackgroundColor = Engine.GetGUIObjectByName("playerBackgroundColor[" + this.playerIndex + "]");
- this.playerColorHeading = Engine.GetGUIObjectByName("playerColorHeading");
- }
-
- onMapChange(mapData)
- {
- Engine.ProfileStart("updatePlayerColorList");
- let hidden = !g_IsController || g_GameAttributes.mapType == "scenario";
- this.dropdown.hidden = hidden;
- this.playerColorHeading.hidden = hidden;
-
- // Step 1: Pick colors that the map specifies, add most unsimilar default colors
- // Provide the access to g_MaxPlayers different colors, regardless of current playercount.
- let values = [];
- for (let i = 0; i < g_MaxPlayers; ++i)
- {
- let pData = this.gameSettingsControl.getPlayerData(mapData, i);
- values.push(pData && pData.Color || this.findFarthestUnusedColor(values));
- }
-
- // Step 2: Sort these colors so that the order is most reminiscent of the default colors
- this.values = [];
- for (let i = 0; i < g_MaxPlayers; ++i)
- {
- let closestColor;
- let smallestDistance = Infinity;
- for (let color of values)
- {
- if (this.values.some(col => sameColor(col, color)))
- continue;
-
- let distance = colorDistance(color, this.defaultColors[i]);
- if (distance <= smallestDistance)
- {
- closestColor = color;
- smallestDistance = distance;
- }
- }
- this.values.push(closestColor);
- }
-
- this.dropdown.list = this.values.map(color => coloredText(this.ColorIcon, rgbToGuiColor(color)));
- this.dropdown.list_data = this.values.map((color, i) => i);
-
- // If the map specified a color for this slot, use that
- let mapPlayerData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- let playerData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
-
- if (playerData && mapPlayerData && mapPlayerData.Color &&
- (!playerData.Color || !sameColor(playerData.Color, mapPlayerData.Color)))
- {
- playerData.Color = mapPlayerData.Color;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- Engine.ProfileStop();
- }
-
- onGameAttributesChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData || !this.values)
- return;
-
- let inUse =
- pData.Color &&
- g_GameAttributes.settings.PlayerData.some((otherPData, i) =>
- i < this.playerIndex &&
- otherPData.Color &&
- sameColor(pData.Color, otherPData.Color));
-
- if (!pData.Color || this.values.indexOf(pData.Color) == -1 || inUse)
- {
- pData.Color =
- (pData.Color && !inUse) ?
- this.findClosestColor(pData.Color, this.values) :
- this.getUnusedColor();
-
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData || !this.values)
- return;
-
- this.setSelectedValue(this.values.indexOf(pData.Color));
- this.playerBackgroundColor.sprite = "color:" + rgbToGuiColor(pData.Color, 100);
- }
-
- onAssignPlayer(source, target)
- {
- if (g_GameAttributes.mapType != "scenario" && source && target)
- [source.Color, target.Color] = [target.Color, source.Color];
- }
-
- onSelectionChange(itemIdx)
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
-
- // If someone else has that color, give that player the old color
- let otherPData = g_GameAttributes.settings.PlayerData.find(data =>
- sameColor(this.values[itemIdx], data.Color));
-
- if (otherPData)
- otherPData.Color = pData.Color;
-
- pData.Color = this.values[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- findClosestColor(targetColor, colors)
- {
- let colorDistances = colors.map(color => colorDistance(color, targetColor));
-
- let smallestDistance = colorDistances.find(
- distance => colorDistances.every(distance2 => distance2 >= distance));
-
- return colors.find(color => colorDistance(color, targetColor) == smallestDistance);
- }
-
- findFarthestUnusedColor(values)
- {
- let farthestColor;
- let farthestDistance = 0;
-
- for (let defaultColor of this.defaultColors)
- {
- let smallestDistance = Infinity;
- for (let usedColor of values)
- {
- let distance = colorDistance(usedColor, defaultColor);
- if (distance < smallestDistance)
- smallestDistance = distance;
- }
-
- if (smallestDistance >= farthestDistance)
- {
- farthestColor = defaultColor;
- farthestDistance = smallestDistance;
- }
- }
- return farthestColor;
- }
-
- getUnusedColor()
- {
- return this.values.find(color =>
- g_GameAttributes &&
- g_GameAttributes.settings &&
- g_GameAttributes.settings.PlayerData &&
- g_GameAttributes.settings.PlayerData.every(pData => !pData.Color || !sameColor(color, pData.Color)));
- }
-};
-
-PlayerSettingControls.PlayerColor.prototype.Tooltip =
- translate("Pick a color.");
-
-PlayerSettingControls.PlayerColor.prototype.ColorIcon =
- "■";
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerTeam.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerTeam.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/Dropdowns/PlayerTeam.js
@@ -1,78 +0,0 @@
-PlayerSettingControls.PlayerTeam = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = prepareForDropdown([
- {
- "label": this.NoTeam,
- "id": this.NoTeamId
- },
- ...Array.from(
- new Array(g_MaxTeams),
- (v, i) => ({
- "label": i + 1,
- "id": i
- }))
- ]);
- this.dropdown.list = this.values.label;
- this.dropdown.list_data = this.values.id;
- }
-
- setControl()
- {
- this.label = Engine.GetGUIObjectByName("playerTeamText[" + this.playerIndex + "]");
- this.dropdown = Engine.GetGUIObjectByName("playerTeam[" + this.playerIndex + "]");
- }
-
- onMapChange(mapData)
- {
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
-
- if (pData && mapPData && mapPData.Team !== undefined)
- {
- pData.Team = mapPData.Team;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- if (pData.Team === undefined)
- {
- pData.Team = this.NoTeamId;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- this.setEnabled(g_GameAttributes.mapType != "scenario");
- this.setSelectedValue(pData.Team);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.PlayerData[this.playerIndex].Team = itemIdx - 1;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-PlayerSettingControls.PlayerTeam.prototype.Tooltip =
- translate("Select player's team.");
-
-PlayerSettingControls.PlayerTeam.prototype.NoTeam =
- translateWithContext("team", "None");
-
-PlayerSettingControls.PlayerTeam.prototype.NoTeamId = -1;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerFrame.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerFrame.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerFrame.js
@@ -1,23 +0,0 @@
-PlayerSettingControls.PlayerFrame = class extends GameSettingControl
-{
- constructor(...args)
- {
- super(...args);
-
- this.playerFrame = Engine.GetGUIObjectByName("playerFrame[" + this.playerIndex + "]");
-
- {
- let size = this.playerFrame.size;
- size.top = this.Height * this.playerIndex;
- size.bottom = this.Height * (this.playerIndex + 1);
- this.playerFrame.size = size;
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.playerFrame.hidden = !this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- }
-}
-
-PlayerSettingControls.PlayerFrame.prototype.Height = 32;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerName.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerName.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerName.js
@@ -1,129 +0,0 @@
-// TODO: There should be an indication which player is not ready yet
-// The color does not indicate it's meaning and is insufficient to inform many players.
-PlayerSettingControls.PlayerName = class extends GameSettingControl
-{
- constructor(...args)
- {
- super(...args);
-
- this.playerName = Engine.GetGUIObjectByName("playerName[" + this.playerIndex + "]");
-
- this.displayedName = undefined;
- this.guid = undefined;
- }
-
- onMapChange(mapData)
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- pData.Name = mapPData && mapPData.Name || g_Settings.PlayerDefaults[this.playerIndex + 1].Name;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- onGameAttributesChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- if (!pData.Name)
- {
- pData.Name = g_Settings.PlayerDefaults[this.playerIndex + 1].Name;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- this.displayedName = g_IsNetworked ? pData.Name : translate(pData.Name);
- this.rebuild();
- }
-
- onPlayerAssignmentsChange()
- {
- this.guid = undefined;
-
- for (let guid in g_PlayerAssignments)
- if (g_PlayerAssignments[guid].player == this.playerIndex + 1)
- {
- this.guid = guid;
- break;
- }
-
- this.rebuild();
- }
-
- rebuild()
- {
- let name = this.displayedName;
- if (!name)
- return;
-
- if (g_IsNetworked)
- {
- let status = this.guid ? g_PlayerAssignments[this.guid].status : this.ReadyTags.length - 1;
- name = setStringTags(this.displayedName, this.ReadyTags[status]);
- }
-
- this.playerName.caption = name;
- }
-
- onGameAttributesFinalize()
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- if (g_GameAttributes.mapType != "scenario" && pData.AI)
- {
- // Pick one of the available botnames for the chosen civ
- // Determine botnames
- let chosenName = pickRandom(g_CivData[pData.Civ].AINames);
-
- if (!g_IsNetworked)
- chosenName = translate(chosenName);
-
- // Count how many players use the chosenName
- let usedName = g_GameAttributes.settings.PlayerData.filter(otherPData =>
- otherPData.Name && otherPData.Name.indexOf(chosenName) !== -1).length;
-
- pData.Name =
- usedName ?
- sprintf(this.RomanLabel, {
- "playerName": chosenName,
- "romanNumber": this.RomanNumbers[usedName + 1]
- }) :
- chosenName;
- }
- else
- // Copy client playernames so they appear in replays
- for (let guid in g_PlayerAssignments)
- if (g_PlayerAssignments[guid].player == this.playerIndex + 1)
- pData.Name = g_PlayerAssignments[guid].name;
- }
-};
-
-PlayerSettingControls.PlayerName.prototype.RomanLabel =
- translate("%(playerName)s %(romanNumber)s");
-
-PlayerSettingControls.PlayerName.prototype.RomanNumbers =
- [undefined, "I", "II", "III", "IV", "V", "VI", "VII", "VIII"];
-
-PlayerSettingControls.PlayerName.prototype.ReadyTags = [
- {
- "color": "white",
- },
- {
- "color": "green",
- },
- {
- "color": "150 150 250",
- }
-];
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerSettings.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerSettings.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerSettings.js
@@ -1,45 +0,0 @@
-// TODO: There should be a dialog allowing to specify starting resources and population capacity per player
-PlayerSettingControls.PlayerSettings = class extends GameSettingControl
-{
- onMapChange(mapData)
- {
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- if (!pData)
- return;
-
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- let isScenario = mapPData && g_GameAttributes.mapType == "scenario";
-
- if (isScenario && mapPData.Resources)
- pData.Resources = mapPData.Resources;
- else
- delete pData.Resources;
-
- if (isScenario && mapPData.PopulationLimit)
- pData.PopulationLimit = mapPData.PopulationLimit;
- else
- delete pData.PopulationLimit;
- }
-
- onGameAttributesFinalize()
- {
- // Copy map well known properties (and only well known properties)
- let mapData = this.mapCache.getMapData(g_GameAttributes.mapType, g_GameAttributes.map);
-
- let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
- let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex);
- if (!pData || !mapPData)
- return;
-
- for (let property of this.MapSettings)
- if (mapPData[property] !== undefined)
- pData[property] = mapPData[property];
- }
-};
-
-PlayerSettingControls.PlayerSettings.prototype.MapSettings = [
- "StartingTechnologies",
- "DisabledTechnologies",
- "DisabledTemplates",
- "StartingCamera"
-];
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayersPanel.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayersPanel.xml
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayersPanel.xml
@@ -1,55 +0,0 @@
-
-
-
-
-
- Player Name
-
-
-
- Color
-
-
-
- Player Placement
-
-
-
- Civilization
-
-
-
-
-
-
- Team
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/PlayerSettingControlManager.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/PlayerSettingControlManager.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/PlayerSettingControlManager.js
@@ -1,29 +0,0 @@
-/**
- * Each property of this class is a class that inherits GameSettingControl and is
- * instantiated by the PlayerSettingControlManager.
- */
-class PlayerSettingControls
-{
-}
-
-/**
- * The purpose of the PlayerSettingControlManager is to own all controls that handle a property of g_GameAttributes.settings.PlayerData.
- */
-class PlayerSettingControlManager
-{
- constructor(playerIndex, gamesetupPage, gameSettingsControl, mapCache, mapFilters, netMessages, playerAssignmentsControl)
- {
- this.playerSettingControls = {};
-
- for (let name in PlayerSettingControls)
- this.playerSettingControls[name] =
- new PlayerSettingControls[name](
- undefined, undefined, playerIndex, gamesetupPage, gameSettingsControl, mapCache, mapFilters, netMessages, playerAssignmentsControl);
- }
-
- addAutocompleteEntries(autocomplete)
- {
- for (let name in this.playerSettingControls)
- this.playerSettingControls[name].addAutocompleteEntries(name, autocomplete);
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Cheats.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Cheats.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Cheats.js
@@ -1,43 +0,0 @@
-/**
- * Cheats are always enabled in singleplayer mode, since they are the choice of that one player.
- */
-GameSettingControls.Cheats = class extends GameSettingControlCheckbox
-{
- constructor(...args)
- {
- super(...args);
- this.setHidden(!g_IsNetworked);
- }
-
- onGameAttributesChange()
- {
- if (g_GameAttributes.settings.CheatsEnabled === undefined ||
- g_GameAttributes.settings.CheatsEnabled && g_GameAttributes.settings.RatingEnabled ||
- !g_GameAttributes.settings.CheatsEnabled && !g_IsNetworked)
- {
- g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setChecked(g_GameAttributes.settings.CheatsEnabled);
- this.setEnabled(!g_GameAttributes.settings.RatingEnabled);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.CheatsEnabled =
- !g_IsNetworked ||
- checked && !g_GameAttributes.settings.RatingEnabled;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.Cheats.prototype.TitleCaption =
- translate("Cheats");
-
-GameSettingControls.Cheats.prototype.Tooltip =
- translate("Toggle the usability of cheats.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/ExploredMap.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/ExploredMap.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/ExploredMap.js
@@ -1,58 +0,0 @@
-GameSettingControls.ExploredMap = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.ExploreMap || undefined;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.ExploreMap)
- {
- g_GameAttributes.settings.ExploreMap = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- if (g_GameAttributes.settings.ExploreMap === undefined)
- {
- g_GameAttributes.settings.ExploreMap = !!g_GameAttributes.settings.RevealMap;
- this.gameSettingsControl.updateGameAttributes();
- }
- else if (g_GameAttributes.settings.RevealMap &&
- !g_GameAttributes.settings.ExploreMap)
- {
- g_GameAttributes.settings.ExploreMap = true;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- this.setChecked(g_GameAttributes.settings.ExploreMap);
- this.setEnabled(g_GameAttributes.mapType != "scenario" && !g_GameAttributes.settings.RevealMap);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.ExploreMap = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.ExploredMap.prototype.TitleCaption =
- // Translation: Make sure to differentiate between the revealed map and explored map settings!
- translate("Explored Map");
-
-GameSettingControls.ExploredMap.prototype.Tooltip =
- // Translation: Make sure to differentiate between the revealed map and explored map settings!
- translate("Toggle explored map (see initial map).");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/LastManStanding.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/LastManStanding.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/LastManStanding.js
@@ -1,61 +0,0 @@
-GameSettingControls.LastManStanding = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- !mapData.settings.LockTeams &&
- mapData.settings.LastManStanding;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.LastManStanding)
- {
- g_GameAttributes.settings.LastManStanding = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- this.available = !g_GameAttributes.settings.LockTeams;
- if (this.available)
- {
- if (g_GameAttributes.settings.LastManStanding === undefined)
- {
- g_GameAttributes.settings.LastManStanding = false;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.LastManStanding !== undefined)
- {
- delete g_GameAttributes.settings.LastManStanding;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- // Always display this, so that players are aware that there is this gamemode
- this.setChecked(!!g_GameAttributes.settings.LastManStanding);
- this.setEnabled(g_GameAttributes.mapType != "scenario" && !g_GameAttributes.settings.LockTeams);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.LastManStanding = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.LastManStanding.prototype.TitleCaption =
- translate("Last Man Standing");
-
-GameSettingControls.LastManStanding.prototype.Tooltip =
- translate("Toggle whether the last remaining player or the last remaining set of allies wins.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/LockedTeams.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/LockedTeams.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/LockedTeams.js
@@ -1,62 +0,0 @@
-GameSettingControls.LockedTeams = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- !mapData.settings.LockTeams &&
- mapData.settings.LastManStanding;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.LastManStanding)
- {
- g_GameAttributes.settings.LastManStanding = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- if (g_GameAttributes.settings.LockTeams === undefined ||
- g_GameAttributes.settings.RatingEnabled && !g_GameAttributes.settings.LockTeams)
- {
- g_GameAttributes.settings.LockTeams = g_IsNetworked;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- this.setChecked(g_GameAttributes.settings.LockTeams);
-
- this.setEnabled(
- g_GameAttributes.mapType != "scenario" &&
- !g_GameAttributes.settings.RatingEnabled);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.LockTeams = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.LockedTeams.prototype.TitleCaption =
- translate("Teams Locked");
-
-GameSettingControls.LockedTeams.prototype.Tooltip =
- translate("Toggle locked teams.");
-
-/**
- * In multiplayer mode, players negotiate teams before starting the match and
- * expect to play the match with these teams unless explicitly stated otherwise during the match settings.
- * For singleplayermode, preserve the historic default of open diplomacies.
- */
-GameSettingControls.LockedTeams.prototype.DefaultValue = Engine.HasNetClient();
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Nomad.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Nomad.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Nomad.js
@@ -1,63 +0,0 @@
-GameSettingControls.Nomad = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let available = g_GameAttributes.mapType == "random";
- this.setHidden(!available);
- if (!available)
- return;
-
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.Nomad;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.Nomad)
- {
- g_GameAttributes.settings.Nomad = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- if (g_GameAttributes.mapType == "random")
- {
- if (g_GameAttributes.settings.Nomad === undefined)
- {
- g_GameAttributes.settings.Nomad = false;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.Nomad !== undefined)
- {
- delete g_GameAttributes.settings.Nomad;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- if (g_GameAttributes.mapType == "random")
- this.setChecked(g_GameAttributes.settings.Nomad);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.Nomad = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.Nomad.prototype.TitleCaption =
- translate("Nomad");
-
-GameSettingControls.Nomad.prototype.Tooltip =
- translate("In Nomad mode, players start with only few units and have to find a suitable place to build their city. Ceasefire is recommended.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Rating.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Rating.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Rating.js
@@ -1,54 +0,0 @@
-GameSettingControls.Rating = class extends GameSettingControlCheckbox
-{
- constructor(...args)
- {
- super(...args);
-
- this.hasXmppClient = Engine.HasXmppClient();
- this.available = false;
- }
-
- onGameAttributesChange()
- {
- this.available = this.hasXmppClient && g_GameAttributes.settings.PlayerData.length == 2;
- if (this.available)
- {
- if (g_GameAttributes.settings.RatingEnabled === undefined)
- {
- g_GameAttributes.settings.RatingEnabled = true;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.RatingEnabled !== undefined)
- {
- delete g_GameAttributes.settings.RatingEnabled;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setHidden(!this.available);
- if (this.available)
- this.setChecked(g_GameAttributes.settings.RatingEnabled);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.RatingEnabled = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- onGameAttributesFinalize()
- {
- if (this.hasXmppClient)
- Engine.SetRankedGame(!!g_GameAttributes.settings.RatingEnabled);
- }
-};
-
-GameSettingControls.Rating.prototype.TitleCaption =
- translate("Rated Game");
-
-GameSettingControls.Rating.prototype.Tooltip =
- translate("Toggle if this game will be rated for the leaderboard.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/RegicideGarrison.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/RegicideGarrison.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/RegicideGarrison.js
@@ -1,67 +0,0 @@
-GameSettingControls.RegicideGarrison = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- this.setEnabled(g_GameAttributes.mapType != "scenario");
-
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.VictoryConditions &&
- mapData.settings.VictoryConditions.indexOf(this.RegicideName) != -1 &&
- mapData.settings.RegicideGarrison;
-
- if (mapValue !== undefined || !g_GameAttributes.settings || mapValue == g_GameAttributes.settings.RegicideGarrison)
- return;
-
- if (!g_GameAttributes.settings.VictoryConditions)
- g_GameAttributes.settings.VictoryConditions = [];
-
- if (g_GameAttributes.settings.VictoryConditions.indexOf(this.RegicideName) == -1)
- g_GameAttributes.settings.VictoryConditions.push(this.RegicideName);
-
- g_GameAttributes.settings.RegicideGarrison = mapValue;
-
- this.gameSettingsControl.updateGameAttributes();
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.settings.VictoryConditions)
- return;
-
- let available = g_GameAttributes.settings.VictoryConditions.indexOf(this.RegicideName) != -1;
- this.setHidden(!available);
-
- if (available)
- {
- if (g_GameAttributes.settings.RegicideGarrison === undefined)
- {
- g_GameAttributes.settings.RegicideGarrison = false;
- this.gameSettingsControl.updateGameAttributes();
- }
- this.setChecked(g_GameAttributes.settings.RegicideGarrison);
- }
- else if (g_GameAttributes.settings.RegicideGarrison !== undefined)
- {
- delete g_GameAttributes.settings.RegicideGarrison;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.RegicideGarrison = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.RegicideGarrison.prototype.TitleCaption =
- translate("Hero Garrison");
-
-GameSettingControls.RegicideGarrison.prototype.Tooltip =
- translate("Toggle whether heroes can be garrisoned.");
-
-GameSettingControls.RegicideGarrison.prototype.RegicideName =
- "regicide";
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/RevealedMap.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/RevealedMap.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/RevealedMap.js
@@ -1,53 +0,0 @@
-GameSettingControls.RevealedMap = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.RevealMap || undefined;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.RevealMap)
- {
- g_GameAttributes.settings.RevealMap = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- this.setEnabled(g_GameAttributes.mapType != "scenario");
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- if (g_GameAttributes.settings.RevealMap === undefined)
- {
- g_GameAttributes.settings.RevealMap = false;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- this.setChecked(g_GameAttributes.settings.RevealMap);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.RevealMap = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.RevealedMap.prototype.TitleCaption =
- // Translation: Make sure to differentiate between the revealed map and explored map settings!
- translate("Revealed Map");
-
-GameSettingControls.RevealedMap.prototype.Tooltip =
- // Translation: Make sure to differentiate between the revealed map and explored map settings!
- translate("Toggle revealed map (see everything).");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Spies.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Spies.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Spies.js
@@ -1,45 +0,0 @@
-GameSettingControls.Spies = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.DisableSpies;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.DisableSpies)
- {
- g_GameAttributes.settings.DisableSpies = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- this.setEnabled(g_GameAttributes.mapType != "scenario");
- }
-
- onGameAttributesChange()
- {
- if (g_GameAttributes.settings.DisableSpies === undefined)
- {
- g_GameAttributes.settings.DisableSpies = false;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setChecked(g_GameAttributes.settings.DisableSpies);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.DisableSpies = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.Spies.prototype.TitleCaption =
- translate("Disable Spies");
-
-GameSettingControls.Spies.prototype.Tooltip =
- translate("Disable spies during the game.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Treasures.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Treasures.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Checkboxes/Treasures.js
@@ -1,45 +0,0 @@
-GameSettingControls.Treasures = class extends GameSettingControlCheckbox
-{
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.DisableTreasures;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.DisableTreasures)
- {
- g_GameAttributes.settings.DisableTreasures = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- this.setEnabled(g_GameAttributes.mapType != "scenario");
- }
-
- onGameAttributesChange()
- {
- if (g_GameAttributes.settings.DisableTreasures === undefined)
- {
- g_GameAttributes.settings.DisableTreasures = false;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setChecked(g_GameAttributes.settings.DisableTreasures);
- }
-
- onPress(checked)
- {
- g_GameAttributes.settings.DisableTreasures = checked;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.Treasures.prototype.TitleCaption =
- translate("Disable Treasures");
-
-GameSettingControls.Treasures.prototype.Tooltip =
- translate("Do not add treasures to the map.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Biome.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Biome.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Biome.js
@@ -1,149 +0,0 @@
-GameSettingControls.Biome = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = undefined;
- this.biomeValues = undefined;
-
- this.lastBiome = undefined;
-
- this.randomItem = {
- "Id": this.RandomBiomeId,
- "Title": setStringTags(this.RandomBiome, this.RandomItemTags),
- "Autocomplete": this.RandomBiome,
- "Description": this.RandomDescription
- };
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip =
- this.values && this.values.Description && this.values.Description[this.dropdown.hovered] ||
- this.Tooltip;
- }
-
- onMapChange(mapData)
- {
- let available = g_GameAttributes.mapType == "random" &&
- mapData && mapData.settings && mapData.settings.SupportedBiomes || undefined;
-
- this.setHidden(!available);
-
- if (available)
- {
- Engine.ProfileStart("updateBiomeList");
- this.biomeValues =
- g_Settings.Biomes.filter(this.filterBiome(available)).map(this.createBiomeItem);
-
- this.values = prepareForDropdown([
- this.randomItem,
- ...this.biomeValues
- ]);
-
- this.dropdown.list = this.values.Title;
- this.dropdown.list_data = this.values.Id;
- Engine.ProfileStop();
- }
- else
- this.values = undefined;
-
- this.lastBiome = undefined;
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType || !g_GameAttributes.map)
- return;
-
- if (this.values)
- {
- if (this.values.Id.indexOf(g_GameAttributes.settings.Biome || undefined) == -1)
- {
- g_GameAttributes.settings.Biome = this.RandomBiomeId;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- if (this.lastBiome != g_GameAttributes.settings.Biome)
- {
- let biomePreviewFile =
- basename(g_GameAttributes.map) + "_" +
- basename(g_GameAttributes.settings.Biome || "") + ".png";
-
- if (Engine.TextureExists(this.mapCache.TexturesPath + this.mapCache.PreviewsPath + biomePreviewFile))
- g_GameAttributes.settings.Preview = biomePreviewFile;
-
- this.lastBiome = g_GameAttributes.settings.Biome;
- }
- }
- else if (g_GameAttributes.settings.Biome)
- {
- delete g_GameAttributes.settings.Biome;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (this.values)
- this.setSelectedValue(g_GameAttributes.settings.Biome);
- }
-
- filterBiome(available)
- {
- if (typeof available == "string")
- return biome => biome.Id.startsWith(available);
-
- return biome => available.indexOf(biome.Id) != -1;
- }
-
- createBiomeItem(biome)
- {
- return {
- "Id": biome.Id,
- "Title": biome.Title,
- "Autocomplete": biome.Title,
- "Description": biome.Description
- };
- }
-
- getAutocompleteEntries()
- {
- return this.values && this.values.Autocomplete;
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.Biome = this.values.Id[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- onPickRandomItems()
- {
- if (this.values && g_GameAttributes.settings.Biome == this.RandomBiomeId)
- {
- g_GameAttributes.settings.Biome = pickRandom(this.biomeValues).Id;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.pickRandomItems();
- }
- }
-};
-
-GameSettingControls.Biome.prototype.TitleCaption =
- translate("Biome");
-
-GameSettingControls.Biome.prototype.RandomBiomeId =
- "random";
-
-GameSettingControls.Biome.prototype.Tooltip =
- translate("Select the flora and fauna.");
-
-GameSettingControls.Biome.prototype.RandomBiome =
- translateWithContext("biome", "Random");
-
-GameSettingControls.Biome.prototype.RandomDescription =
- translate("Pick a biome at random.");
-
-GameSettingControls.Biome.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Ceasefire.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Ceasefire.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Ceasefire.js
@@ -1,55 +0,0 @@
-GameSettingControls.Ceasefire = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = prepareForDropdown(g_Settings.Ceasefire);
-
- this.dropdown.list = this.values.Title;
- this.dropdown.list_data = this.values.Duration;
- }
-
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.Ceasefire || undefined;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.Ceasefire)
- {
- g_GameAttributes.settings.Ceasefire = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- this.setEnabled(g_GameAttributes.mapType != "scenario");
- }
-
- onGameAttributesChange()
- {
- if (g_GameAttributes.settings.Ceasefire == undefined)
- {
- g_GameAttributes.settings.Ceasefire = this.values.Default;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setSelectedValue(g_GameAttributes.settings.Ceasefire);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.Ceasefire = this.values.Duration[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.Ceasefire.prototype.TitleCaption =
- translate("Ceasefire");
-
-GameSettingControls.Ceasefire.prototype.Tooltip =
- translate("Set time where no attacks are possible.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Daytime.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Daytime.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Daytime.js
@@ -1,107 +0,0 @@
-GameSettingControls.Daytime = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = undefined;
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = this.values.Description[this.dropdown.hovered] || this.Tooltip;
- }
-
- onMapChange(mapData)
- {
- if (mapData && mapData.settings && mapData.settings.Daytime)
- {
- this.values = prepareForDropdown([
- {
- "Id": "random",
- "Name": setStringTags(this.RandomTitle, this.RandomItemTags),
- "Description": this.RandomDescription,
- "Preview": mapData.settings.Preview
- },
- ...mapData.settings.Daytime
- ]);
-
- this.dropdown.list = this.values.Name;
- this.dropdown.list_data = this.values.Id;
- }
- else
- this.values = undefined;
-
- this.setHidden(!this.values);
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.map)
- return;
-
- if (this.values)
- {
- if (this.values.Id.indexOf(g_GameAttributes.settings.Daytime || undefined) == -1)
- {
- g_GameAttributes.settings.Daytime = "random";
- this.gameSettingsControl.updateGameAttributes();
- }
-
- let preview = this.values.Preview[this.values.Id.indexOf(g_GameAttributes.settings.Daytime)];
- if (!g_GameAttributes.settings.Preview || g_GameAttributes.settings.Preview != preview)
- {
- g_GameAttributes.settings.Preview = preview;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.Daytime !== undefined)
- {
- delete g_GameAttributes.settings.Daytime;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (g_GameAttributes.settings.Daytime)
- this.setSelectedValue(g_GameAttributes.settings.Daytime);
- }
-
- getAutocompleteEntries()
- {
- return this.values.Name;
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.Daytime = this.values.Id[itemIdx];
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- onPickRandomItems()
- {
- if (this.values && g_GameAttributes.settings.Daytime == "random")
- {
- g_GameAttributes.settings.Daytime = pickRandom(this.values.Id.slice(1));
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.pickRandomItems();
- }
- }
-};
-
-GameSettingControls.Daytime.prototype.TitleCaption =
- translate("Daytime");
-
-GameSettingControls.Daytime.prototype.Tooltip =
- translate("Select whether the match takes place at daylight or night.");
-
-GameSettingControls.Daytime.prototype.RandomTitle =
- translateWithContext("daytime selection", "Random");
-
-GameSettingControls.Daytime.prototype.RandomDescription =
- translateWithContext("daytime selection", "Randomly pick a time of the day.");
-
-GameSettingControls.Daytime.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/GameSpeed.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/GameSpeed.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/GameSpeed.js
@@ -1,76 +0,0 @@
-GameSettingControls.GameSpeed = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.previousAllowFastForward = undefined;
- }
-
- onMapChange(mapData)
- {
- let mapValue = mapData && mapData.gameSpeed || undefined;
- if (mapValue !== undefined && mapValue != g_GameAttributes.gameSpeed)
- {
- g_GameAttributes.gameSpeed = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onPlayerAssignmentsChange()
- {
- this.update();
- }
-
- onGameAttributesChange()
- {
- this.update();
- }
-
- update()
- {
- let allowFastForward = true;
- for (let guid in g_PlayerAssignments)
- if (g_PlayerAssignments[guid].player != -1)
- {
- allowFastForward = false;
- break;
- }
-
- if (this.previousAllowFastForward !== allowFastForward)
- {
- Engine.ProfileStart("updateGameSpeedList");
- this.previousAllowFastForward = allowFastForward;
- this.values = prepareForDropdown(
- g_Settings.GameSpeeds.filter(speed => !speed.FastForward || allowFastForward));
-
- this.dropdown.list = this.values.Title;
- this.dropdown.list_data = this.values.Speed;
- Engine.ProfileStop();
- }
-
- if (this.values.Speed.indexOf(g_GameAttributes.gameSpeed || undefined) == -1)
- {
- g_GameAttributes.gameSpeed = this.values.Speed[this.values.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setSelectedValue(g_GameAttributes.gameSpeed);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.gameSpeed = this.values.Speed[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.GameSpeed.prototype.TitleCaption =
- translate("Game Speed");
-
-GameSettingControls.GameSpeed.prototype.Tooltip =
- translate("Select game speed.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Landscape.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Landscape.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/Landscape.js
@@ -1,148 +0,0 @@
-GameSettingControls.Landscape = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = undefined;
- this.lastLandscape = undefined;
- this.mapData = undefined;
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = this.values.Description[this.dropdown.hovered] || this.Tooltip;
- }
-
- onMapChange(mapData)
- {
- this.mapData = mapData;
-
- if (mapData && mapData.settings && mapData.settings.Landscapes)
- {
- let randomItems = [];
- for (let item of this.RandomItems)
- if (item.Id == "random" || mapData.settings.Landscapes.land && mapData.settings.Landscapes.naval)
- randomItems.push({
- "Id": item.Id,
- "Name": setStringTags(item.Name, this.RandomItemTags),
- "Description": item.Description,
- "Preview": mapData.settings.Preview || this.mapCache.DefaultPreview
- });
-
- let sort = (item1, item2) => item1.Name > item2.Name;
-
- this.values = prepareForDropdown([
- ...randomItems,
- ...mapData.settings.Landscapes.land.sort(sort),
- ...mapData.settings.Landscapes.naval.sort(sort)
- ]);
-
- this.dropdown.list = this.values.Name;
- this.dropdown.list_data = this.values.Id;
- }
- else
- this.values = undefined;
-
- this.lastLandscape = undefined;
-
- this.setHidden(!this.values);
- }
-
- onGameAttributesChange()
- {
- if (this.values)
- {
- if (this.values.Id.indexOf(g_GameAttributes.settings.Landscape || undefined) == -1)
- {
- g_GameAttributes.settings.Landscape = "random";
- this.gameSettingsControl.updateGameAttributes();
- }
-
- if (this.lastLandscape != g_GameAttributes.settings.Landscape)
- {
- g_GameAttributes.settings.Preview = this.values.Preview[this.values.Id.indexOf(g_GameAttributes.settings.Landscape)];
- this.lastLandscape = g_GameAttributes.settings.Biome;
- }
- }
- else if (g_GameAttributes.settings.Landscape !== undefined)
- {
- delete g_GameAttributes.settings.Landscape;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (g_GameAttributes.settings.Landscape)
- this.setSelectedValue(g_GameAttributes.settings.Landscape);
- }
-
- getAutocompleteEntries()
- {
- return this.values.Name;
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.Landscape = this.values.Id[itemIdx];
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- onPickRandomItems()
- {
- if (!this.mapData)
- return;
-
- let items;
- let landscapes = this.mapData.settings.Landscapes;
-
- switch (g_GameAttributes.settings.Landscape || undefined)
- {
- case "random":
- items = [...landscapes.land, ...landscapes.naval];
- break;
- case "random_land":
- items = landscapes.land;
- break;
- case "random_naval":
- items = landscapes.naval;
- break;
- default:
- return;
- }
-
- g_GameAttributes.settings.Landscape = pickRandom(items).Id;
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.pickRandomItems();
- }
-};
-
-GameSettingControls.Landscape.prototype.TitleCaption =
- translate("Landscape");
-
-GameSettingControls.Landscape.prototype.Tooltip =
- translate("Select one of the landscapes of this map.");
-
-GameSettingControls.Landscape.prototype.RandomItems =
-[
- {
- "Id": "random",
- "Name": translateWithContext("landscape selection", "Random Land or Naval"),
- "Description": translateWithContext("landscape selection", "Select a random land or naval map generation.")
- },
- {
- "Id": "random_land",
- "Name": translateWithContext("landscape selection", "Random Land"),
- "Description": translateWithContext("landscape selection", "Select a random land map generation.")
- },
- {
- "Id": "random_naval",
- "Name": translateWithContext("landscape selection", "Random Naval"),
- "Description": translateWithContext("landscape selection", "Select a random naval map generation.")
- }
-];
-
-GameSettingControls.Landscape.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapFilter.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapFilter.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapFilter.js
@@ -1,94 +0,0 @@
-GameSettingControls.MapFilter = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = undefined;
- this.previousMapType = undefined;
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = this.values.Description[this.dropdown.hovered] || this.Tooltip;
- }
-
- onGameAttributesChange()
- {
- this.checkMapTypeChange();
-
- if (this.values)
- {
- if (this.values.Name.indexOf(g_GameAttributes.mapFilter || undefined) == -1)
- {
- g_GameAttributes.mapFilter = this.values.Name[this.values.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.mapFilter !== undefined)
- {
- delete g_GameAttributes.mapFilter;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- checkMapTypeChange()
- {
- if (!g_GameAttributes.mapType || this.previousMapType == g_GameAttributes.mapType)
- return;
-
- Engine.ProfileStart("updateMapFilterList");
- this.previousMapType = g_GameAttributes.mapType;
-
- let values = prepareForDropdown(
- this.mapFilters.getAvailableMapFilters(
- g_GameAttributes.mapType));
-
- if (values.Name.length)
- {
- this.dropdown.list = values.Title;
- this.dropdown.list_data = values.Name;
- this.values = values;
- }
- else
- this.values = undefined;
-
- this.setHidden(!this.values);
- Engine.ProfileStop();
- }
-
- onGameAttributesBatchChange()
- {
- if (this.values && g_GameAttributes.mapFilter)
- this.setSelectedValue(g_GameAttributes.mapFilter);
- }
-
- getAutocompleteEntries()
- {
- return this.values && this.values.Title;
- }
-
- onSelectionChange(itemIdx)
- {
- if (this.values)
- {
- g_GameAttributes.mapFilter = this.values.Name[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
- }
-
- onGameAttributesFinalize()
- {
- // The setting is only relevant to the gamesetup stage!
- delete g_GameAttributes.mapFilter;
- }
-};
-
-GameSettingControls.MapFilter.prototype.TitleCaption =
- translate("Map Filter");
-
-GameSettingControls.MapFilter.prototype.Tooltip =
- translate("Select a map filter.");
-
-GameSettingControls.MapFilter.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapSelection.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapSelection.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapSelection.js
@@ -1,171 +0,0 @@
-GameSettingControls.MapSelection = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = undefined;
-
- this.previousMapType = undefined;
- this.previousMapFilter = undefined;
-
- this.randomItem = {
- "file": this.RandomMapId,
- "name": setStringTags(this.RandomMapCaption, this.RandomItemTags),
- "description": this.RandomMapDescription
- };
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = this.values.description[this.dropdown.hovered] || this.Tooltip;
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType || !g_GameAttributes.mapFilter)
- return;
-
- this.updateMapList();
-
- if (!this.gameSettingsControl.autostart &&
- this.values &&
- this.values.file.indexOf(g_GameAttributes.map || undefined) == -1)
- {
- g_GameAttributes.map = this.values.file[0];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (g_GameAttributes.map)
- this.setSelectedValue(g_GameAttributes.map);
- }
-
- updateMapList()
- {
- if (this.previousMapType &&
- this.previousMapType == g_GameAttributes.mapType &&
- this.previousMapFilter &&
- this.previousMapFilter == g_GameAttributes.mapFilter)
- return;
-
- Engine.ProfileStart("updateMapSelectionList");
-
- this.previousMapType = g_GameAttributes.mapType;
- this.previousMapFilter = g_GameAttributes.mapFilter;
-
- {
- let values =
- this.mapFilters.getFilteredMaps(
- g_GameAttributes.mapType,
- g_GameAttributes.mapFilter,
- false);
-
- values.sort(sortNameIgnoreCase);
-
- if (g_GameAttributes.mapType == "random")
- values.unshift(this.randomItem);
-
- this.values = prepareForDropdown(values);
- }
-
- this.dropdown.list = this.values.name;
- this.dropdown.list_data = this.values.file;
- Engine.ProfileStop();
- }
-
- onSelectionChange(itemIdx)
- {
- this.selectMap(this.values.file[itemIdx]);
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- /**
- * @param mapPath - for example "maps/skirmishes/Acropolis Bay (2)"
- */
- selectMap(mapPath)
- {
- if (g_GameAttributes.map == mapPath)
- return;
-
- Engine.ProfileStart("selectMap");
-
- // For scenario map, reset every setting per map selection
- // For skirmish and random maps, persist player choices
- if (g_GameAttributes.mapType == "scenario")
- g_GameAttributes = {
- "mapType": g_GameAttributes.mapType,
- "mapFilter": g_GameAttributes.mapFilter
- };
-
- g_GameAttributes.map = mapPath;
- this.gameSettingsControl.updateGameAttributes();
-
- Engine.ProfileStop();
- }
-
- getAutocompleteEntries()
- {
- return this.values.name;
- }
-
- onPickRandomItems()
- {
- if (g_GameAttributes.map == this.RandomMapId)
- {
- this.selectMap(pickRandom(this.values.file.slice(1)));
- this.gameSettingsControl.pickRandomItems();
- }
- }
-
- onGameAttributesFinalize()
- {
- // Copy map well known properties (and only well known properties)
- let mapData = this.mapCache.getMapData(g_GameAttributes.mapType, g_GameAttributes.map);
-
- g_GameAttributes.settings.CircularMap =
- mapData.settings.CircularMap || true;
-
- if (g_GameAttributes.mapType == "random")
- g_GameAttributes.script = mapData.settings.Script;
-
- g_GameAttributes.settings.TriggerScripts = Array.from(new Set([
- ...(g_GameAttributes.settings.TriggerScripts || []),
- ...(mapData.settings.TriggerScripts || [])
- ]));
-
- for (let property of this.MapSettings)
- if (mapData.settings[property] !== undefined)
- g_GameAttributes.settings[property] = mapData.settings[property];
- }
-};
-
-GameSettingControls.MapSelection.prototype.TitleCaption =
- translate("Select Map");
-
-GameSettingControls.MapSelection.prototype.Tooltip =
- translate("Select a map to play on.");
-
-GameSettingControls.MapSelection.prototype.RandomMapId =
- "random";
-
-GameSettingControls.MapSelection.prototype.RandomMapCaption =
- translateWithContext("map selection", "Random");
-
-GameSettingControls.MapSelection.prototype.RandomMapDescription =
- translate("Pick any of the given maps at random.");
-
-GameSettingControls.MapSelection.prototype.AutocompleteOrder = 0;
-
-GameSettingControls.MapSelection.prototype.MapSettings = [
- "StartingTechnologies",
- "DisabledTechnologies",
- "DisabledTemplates",
- "StartingCamera",
- "Garrison",
- // Copy the map name so that the replay menu doesn't have to load hundreds of map descriptions on init
- // Also it allows determining the english mapname from the replay file if the map is not available.
- "Name"
-];
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapSize.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapSize.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapSize.js
@@ -1,79 +0,0 @@
-GameSettingControls.MapSize = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.previousMapType = undefined;
-
- this.dropdown.list = g_MapSizes.Name;
- this.dropdown.list_data = g_MapSizes.Tiles;
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = g_MapSizes.Tooltip[this.dropdown.hovered] || this.Tooltip;
- }
-
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.Size || undefined;
-
- if (g_GameAttributes.mapType == "random" && mapValue !== undefined && mapValue != g_GameAttributes.settings.Size)
- {
- g_GameAttributes.settings.Size = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType ||
- !g_GameAttributes.settings ||
- this.previousMapType == g_GameAttributes.mapType)
- return;
-
- this.previousMapType = g_GameAttributes.mapType;
-
- let available = g_GameAttributes.mapType == "random";
- this.setHidden(!available);
-
- if (available)
- {
- if (g_GameAttributes.settings.Size === undefined)
- {
- g_GameAttributes.settings.Size = g_MapSizes.Tiles[g_MapSizes.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- this.setSelectedValue(g_GameAttributes.settings.Size);
- }
- else if (g_GameAttributes.settings.Size !== undefined)
- {
- delete g_GameAttributes.settings.Size;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- getAutocompleteEntries()
- {
- return g_MapSizes.Name;
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.Size = g_MapSizes.Tiles[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.MapSize.prototype.TitleCaption =
- translate("Map Size");
-
-GameSettingControls.MapSize.prototype.Tooltip =
- translate("Select map size. (Larger sizes may reduce performance.)");
-
-GameSettingControls.MapSize.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapType.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapType.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/MapType.js
@@ -1,66 +0,0 @@
-/**
- * Maptype design:
- * Scenario maps have fixed terrain and all settings predetermined.
- * Skirmish maps have fixed terrain, playercount but settings are free.
- * For random maps, settings are fully determined by the player and the terrain is generated based on them.
- */
-GameSettingControls.MapType = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.dropdown.list = g_MapTypes.Title;
- this.dropdown.list_data = g_MapTypes.Name;
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip = g_MapTypes.Description[this.dropdown.hovered] || this.Tooltip;
- }
-
- onGameAttributesChange()
- {
- if (g_MapTypes.Name.indexOf(g_GameAttributes.mapType || undefined) == -1)
- {
- g_GameAttributes.mapType = g_MapTypes.Name[g_MapTypes.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setSelectedValue(g_GameAttributes.mapType);
- }
-
- getAutocompleteEntries()
- {
- return g_MapTypes.Title;
- }
-
- onSelectionChange(itemIdx)
- {
- let mapType = g_MapTypes.Name[itemIdx];
-
- if (g_GameAttributes.mapType == mapType)
- return;
-
- if (mapType == "scenario")
- g_GameAttributes = {
- "mapFilter": g_GameAttributes.mapFilter
- };
-
- g_GameAttributes.mapType = mapType;
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.MapType.prototype.TitleCaption =
- translate("Map Type");
-
-GameSettingControls.MapType.prototype.Tooltip =
- translate("Select a map type.");
-
-GameSettingControls.MapType.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/PlayerCount.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/PlayerCount.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/PlayerCount.js
@@ -1,52 +0,0 @@
-GameSettingControls.PlayerCount = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = Array.from(
- new Array(g_MaxPlayers),
- (v, i) => i + 1);
-
- this.dropdown.list = this.values;
- this.dropdown.list_data = this.values;
- }
-
- onMapChange(mapData)
- {
- if (mapData &&
- mapData.settings &&
- mapData.settings.PlayerData &&
- mapData.settings.PlayerData.length != g_GameAttributes.settings.PlayerData.length)
- {
- this.onSelectionChange(this.values.indexOf(mapData.settings.PlayerData.length));
- }
-
- this.setEnabled(g_GameAttributes.mapType == "random");
- }
-
- onGameAttributesBatchChange()
- {
- this.setSelectedValue(g_GameAttributes.settings.PlayerData.length);
- }
-
- onSelectionChange(itemIdx)
- {
- let length = this.values[itemIdx];
- if (g_GameAttributes.settings.PlayerData.length == length)
- return;
-
- g_GameAttributes.settings.PlayerData.length = length;
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
-
- this.playerAssignmentsControl.unassignInvalidPlayers();
- }
-};
-
-GameSettingControls.PlayerCount.prototype.TitleCaption =
- translate("Number of Players");
-
-GameSettingControls.PlayerCount.prototype.Tooltip =
- translate("Select number of players.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/PopulationCap.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/PopulationCap.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/PopulationCap.js
@@ -1,101 +0,0 @@
-GameSettingControls.PopulationCap = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.perPlayer = false;
-
- this.dropdown.list = g_PopulationCapacities.Title;
- this.dropdown.list_data = g_PopulationCapacities.Population;
-
- this.sprintfArgs = {};
- }
-
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.PopulationCap || undefined;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.PopulationCap)
- {
- g_GameAttributes.settings.PopulationCap = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- let isScenario = g_GameAttributes.mapType == "scenario";
-
- this.perPlayer =
- isScenario &&
- mapData.settings.PlayerData &&
- mapData.settings.PlayerData.some(pData => pData && pData.PopulationLimit !== undefined);
-
- this.setEnabled(!isScenario && !this.perPlayer);
-
- if (this.perPlayer)
- this.label.caption = this.PerPlayerCaption;
- }
-
- onGameAttributesChange()
- {
- if (g_GameAttributes.settings.PopulationCap === undefined)
- {
- g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[g_PopulationCapacities.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!this.perPlayer)
- this.setSelectedValue(g_GameAttributes.settings.PopulationCap);
- }
-
- onHoverChange()
- {
- let tooltip = this.Tooltip;
- if (this.dropdown.hovered != -1)
- {
- let popCap = g_PopulationCapacities.Population[this.dropdown.hovered];
- let players = g_GameAttributes.settings.PlayerData.length;
- if (popCap * players >= this.PopulationCapacityRecommendation)
- {
- this.sprintfArgs.players = players;
- this.sprintfArgs.popCap = popCap;
- tooltip = setStringTags(sprintf(this.HoverTooltip, this.sprintfArgs), this.HoverTags);
- }
- }
- this.dropdown.tooltip = tooltip;
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.PopulationCap.prototype.TitleCaption =
- translate("Population Cap");
-
-GameSettingControls.PopulationCap.prototype.Tooltip =
- translate("Select population limit.");
-
-GameSettingControls.PopulationCap.prototype.PerPlayerCaption =
- translateWithContext("population limit", "Per Player");
-
-GameSettingControls.PopulationCap.prototype.HoverTooltip =
- translate("Warning: There might be performance issues if all %(players)s players reach %(popCap)s population.");
-
-GameSettingControls.PopulationCap.prototype.HoverTags = {
- "color": "orange"
-};
-
-/**
- * Total number of units that the engine can run with smoothly.
- * It means a 4v4 with 150 population can still run nicely, but more than that might "lag".
- */
-GameSettingControls.PopulationCap.prototype.PopulationCapacityRecommendation = 1200;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/RelicCount.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/RelicCount.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/RelicCount.js
@@ -1,86 +0,0 @@
-GameSettingControls.RelicCount = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = Object.keys(g_CivData).map((v, i) => i + 1);
-
- this.dropdown.list = this.values;
- this.dropdown.list_data = this.values;
-
- this.available = false;
- }
-
- onMapChange(mapData)
- {
- this.setEnabled(g_GameAttributes.mapType != "scenario");
-
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.VictoryConditions &&
- mapData.settings.VictoryConditions.indexOf(this.NameCaptureTheRelic) != -1 &&
- mapData.settings.RelicCount || undefined;
-
- if (mapValue === undefined || mapValue == g_GameAttributes.settings.RelicCount)
- return;
-
- if (!g_GameAttributes.settings.VictoryConditions)
- g_GameAttributes.settings.VictoryConditions = [];
-
- if (g_GameAttributes.settings.VictoryConditions.indexOf(this.NameCaptureTheRelic) == -1)
- g_GameAttributes.settings.VictoryConditions.push(this.NameCaptureTheRelic);
-
- g_GameAttributes.settings.RelicCount = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.settings.VictoryConditions)
- return;
-
- this.available = g_GameAttributes.settings.VictoryConditions.indexOf(this.NameCaptureTheRelic) != -1;
-
- if (this.available)
- {
- if (g_GameAttributes.settings.RelicCount === undefined)
- {
- g_GameAttributes.settings.RelicCount = this.DefaultRelicCount;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.RelicCount !== undefined)
- {
- delete g_GameAttributes.settings.RelicCount;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setHidden(!this.available);
-
- if (this.available)
- this.setSelectedValue(g_GameAttributes.settings.RelicCount);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.RelicCount = this.values[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.RelicCount.prototype.TitleCaption =
- translate("Relic Count");
-
-GameSettingControls.RelicCount.prototype.Tooltip =
- translate("Total number of relics spawned on the map. Relic victory is most realistic with only one or two relics. With greater numbers, the relics are important to capture to receive aura bonuses.");
-
-GameSettingControls.RelicCount.prototype.NameCaptureTheRelic =
- "capture_the_relic";
-
-GameSettingControls.RelicCount.prototype.DefaultRelicCount = 2;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/RelicDuration.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/RelicDuration.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/RelicDuration.js
@@ -1,85 +0,0 @@
-GameSettingControls.RelicDuration = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = prepareForDropdown(g_Settings.VictoryDurations);
-
- this.dropdown.list = this.values.Title;
- this.dropdown.list_data = this.values.Duration;
-
- this.available = false;
- }
-
- onMapChange(mapData)
- {
- this.setEnabled(g_GameAttributes.mapType != "scenario");
-
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.VictoryConditions &&
- mapData.settings.VictoryConditions.indexOf(this.NameCaptureTheRelic) != -1 &&
- mapData.settings.RelicDuration || undefined;
-
- if (mapValue === undefined || mapValue == g_GameAttributes.settings.RelicDuration)
- return;
-
- if (!g_GameAttributes.settings.VictoryConditions)
- g_GameAttributes.settings.VictoryConditions = [];
-
- if (g_GameAttributes.settings.VictoryConditions.indexOf(this.NameCaptureTheRelic) == -1)
- g_GameAttributes.settings.VictoryConditions.push(this.NameCaptureTheRelic);
-
- g_GameAttributes.settings.RelicDuration = mapValue;
-
- this.gameSettingsControl.updateGameAttributes();
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.settings.VictoryConditions)
- return;
-
- this.available = g_GameAttributes.settings.VictoryConditions.indexOf(this.NameCaptureTheRelic) != -1;
-
- if (this.available)
- {
- if (g_GameAttributes.settings.RelicDuration === undefined)
- {
- g_GameAttributes.settings.RelicDuration = this.values.Duration[this.values.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.RelicDuration !== undefined)
- {
- delete g_GameAttributes.settings.RelicDuration;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setHidden(!this.available);
-
- if (this.available)
- this.setSelectedValue(g_GameAttributes.settings.RelicDuration);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.RelicDuration = this.values.Duration[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.RelicDuration.prototype.TitleCaption =
- translate("Relic Duration");
-
-GameSettingControls.RelicDuration.prototype.Tooltip =
- translate("Minutes until the player has achieved Relic Victory.");
-
-GameSettingControls.RelicDuration.prototype.NameCaptureTheRelic =
- "capture_the_relic";
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/StartingResources.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/StartingResources.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/StartingResources.js
@@ -1,92 +0,0 @@
-GameSettingControls.StartingResources = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.dropdown.list = g_StartingResources.Title;
- this.dropdown.list_data = g_StartingResources.Resources;
-
- this.perPlayer = false;
- this.sprintfArgs = {};
- }
-
- onHoverChange()
- {
- let tooltip = this.Tooltip;
- if (this.dropdown.hovered != -1)
- {
- this.sprintfArgs.resources = g_StartingResources.Resources[this.dropdown.hovered];
- tooltip = sprintf(this.HoverTooltip, this.sprintfArgs);
- }
- this.dropdown.tooltip = tooltip;
- }
-
- onMapChange(mapData)
- {
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.StartingResources || undefined;
-
- if (mapValue !== undefined && mapValue != g_GameAttributes.settings.StartingResources)
- {
- g_GameAttributes.settings.StartingResources = mapValue;
- this.gameSettingsControl.updateGameAttributes();
- }
-
- let isScenario = g_GameAttributes.mapType == "scenario";
-
- this.perPlayer =
- isScenario &&
- mapData.settings.PlayerData &&
- mapData.settings.PlayerData.some(pData => pData && pData.Resources !== undefined);
-
- this.setEnabled(!isScenario && !this.perPlayer);
-
- if (this.perPlayer)
- this.label.caption = this.PerPlayerCaption;
- }
-
- onGameAttributesChange()
- {
- if (g_GameAttributes.settings.StartingResources === undefined)
- {
- g_GameAttributes.settings.StartingResources =
- g_StartingResources.Resources[g_StartingResources.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!this.perPlayer)
- this.setSelectedValue(g_GameAttributes.settings.StartingResources);
- }
-
- getAutocompleteEntries()
- {
- return g_StartingResources.Title;
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.StartingResources.prototype.TitleCaption =
- translate("Starting Resources");
-
-GameSettingControls.StartingResources.prototype.Tooltip =
- translate("Select the game's starting resources.");
-
-GameSettingControls.StartingResources.prototype.HoverTooltip =
- translate("Initial amount of each resource: %(resources)s.");
-
-GameSettingControls.StartingResources.prototype.PerPlayerCaption =
- translateWithContext("starting resources", "Per Player");
-
-GameSettingControls.StartingResources.prototype.AutocompleteOrder = 0;
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/TriggerDifficulty.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/TriggerDifficulty.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/TriggerDifficulty.js
@@ -1,84 +0,0 @@
-GameSettingControls.TriggerDifficulty = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = undefined;
- }
-
- onHoverChange()
- {
- this.dropdown.tooltip =
- this.values && this.values.Tooltip[this.dropdown.hovered] ||
- this.Tooltip;
- }
-
- onMapChange(mapData)
- {
- let available = mapData && mapData.settings && mapData.settings.SupportedTriggerDifficulties || undefined;
- this.setHidden(!available);
-
- if (available)
- {
- Engine.ProfileStart("updateTriggerDifficultyList");
- let values = g_Settings.TriggerDifficulties;
- if (Array.isArray(available.Values))
- values = values.filter(diff => available.Values.indexOf(diff.Name) != -1);
-
- this.values = prepareForDropdown(values);
-
- this.dropdown.list = this.values.Title;
- this.dropdown.list_data = this.values.Difficulty;
-
- if (mapData.settings.TriggerDifficulty &&
- this.values.Difficulty.indexOf(mapData.settings.TriggerDifficulty) != -1)
- g_GameAttributes.settings.TriggerDifficulty = mapData.settings.TriggerDifficulty;
- Engine.ProfileStop();
- }
- else
- {
- this.values = undefined;
- this.defaultValue = undefined;
- }
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- if (this.values)
- {
- if (this.values.Difficulty.indexOf(g_GameAttributes.settings.TriggerDifficulty || undefined) == -1)
- {
- g_GameAttributes.settings.TriggerDifficulty = this.values.Difficulty[this.values.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.TriggerDifficulty !== undefined)
- {
- delete g_GameAttributes.settings.TriggerDifficulty;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (this.values)
- this.setSelectedValue(g_GameAttributes.settings.TriggerDifficulty);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.TriggerDifficulty = this.values.Difficulty[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.TriggerDifficulty.prototype.TitleCaption =
- translate("Difficulty");
-
-GameSettingControls.TriggerDifficulty.prototype.Tooltip =
- translate("Select the difficulty of this scenario.");
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/WonderDuration.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/WonderDuration.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Dropdowns/WonderDuration.js
@@ -1,85 +0,0 @@
-GameSettingControls.WonderDuration = class extends GameSettingControlDropdown
-{
- constructor(...args)
- {
- super(...args);
-
- this.values = prepareForDropdown(g_Settings.VictoryDurations);
-
- this.dropdown.list = this.values.Title;
- this.dropdown.list_data = this.values.Duration;
-
- this.available = false;
- }
-
- onMapChange(mapData)
- {
- this.setEnabled(g_GameAttributes.mapType != "scenario");
-
- let mapValue =
- mapData &&
- mapData.settings &&
- mapData.settings.VictoryConditions &&
- mapData.settings.VictoryConditions.indexOf(this.NameWonderVictory) != -1 &&
- mapData.settings.WonderDuration || undefined;
-
- if (mapValue === undefined || mapValue == g_GameAttributes.settings.WonderDuration)
- return;
-
- if (!g_GameAttributes.settings.VictoryConditions)
- g_GameAttributes.settings.VictoryConditions = [];
-
- if (g_GameAttributes.settings.VictoryConditions.indexOf(this.NameWonderVictory) == -1)
- g_GameAttributes.settings.VictoryConditions.push(this.NameWonderVictory);
-
- g_GameAttributes.settings.WonderDuration = mapValue;
-
- this.gameSettingsControl.updateGameAttributes();
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.settings.VictoryConditions)
- return;
-
- this.available = g_GameAttributes.settings.VictoryConditions.indexOf(this.NameWonderVictory) != -1;
-
- if (this.available)
- {
- if (g_GameAttributes.settings.WonderDuration === undefined)
- {
- g_GameAttributes.settings.WonderDuration = this.values.Duration[this.values.Default];
- this.gameSettingsControl.updateGameAttributes();
- }
- }
- else if (g_GameAttributes.settings.WonderDuration !== undefined)
- {
- delete g_GameAttributes.settings.WonderDuration;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setHidden(!this.available);
-
- if (this.available)
- this.setSelectedValue(g_GameAttributes.settings.WonderDuration);
- }
-
- onSelectionChange(itemIdx)
- {
- g_GameAttributes.settings.WonderDuration = this.values.Duration[itemIdx];
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-};
-
-GameSettingControls.WonderDuration.prototype.TitleCaption =
- translate("Wonder Duration");
-
-GameSettingControls.WonderDuration.prototype.Tooltip =
- translate("Minutes until the player has achieved Wonder Victory");
-
-GameSettingControls.WonderDuration.prototype.NameWonderVictory =
- "wonder";
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Seed.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Seed.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/Single/Seed.js
@@ -1,12 +0,0 @@
-GameSettingControls.Seed = class extends GameSettingControl
-{
- onGameAttributesFinalize()
- {
- // The matchID is used for identifying rated game reports for the lobby and possibly when sharing replays.
- g_GameAttributes.matchID = Engine.GetMatchID();
-
- // Seed is used for map generation and simulation.
- g_GameAttributes.settings.Seed = randIntExclusive(0, Math.pow(2, 32));
- g_GameAttributes.settings.AISeed = randIntExclusive(0, Math.pow(2, 32));
- }
-};
Index: binaries/data/mods/public/gui/gamesetup/GameSettings/VictoryConditionCheckbox.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSettings/VictoryConditionCheckbox.js
+++ binaries/data/mods/public/gui/gamesetup/GameSettings/VictoryConditionCheckbox.js
@@ -1,105 +0,0 @@
-/**
- * This is an abstract class instantiated per defined VictoryCondition.
- */
-class VictoryConditionCheckbox extends GameSettingControlCheckbox
-{
- constructor(victoryCondition, ...args)
- {
- super(...args);
-
- this.victoryCondition = victoryCondition;
-
- this.setTitle(this.victoryCondition.Title);
- this.setTooltip(this.victoryCondition.Description);
- }
-
- onMapChange(mapData)
- {
- let mapIndex =
- mapData &&
- mapData.settings &&
- mapData.settings.VictoryConditions &&
- mapData.settings.VictoryConditions.indexOf(this.victoryCondition.Name);
-
- if (mapIndex === undefined)
- return;
-
- let index =
- g_GameAttributes.settings &&
- g_GameAttributes.settings.VictoryConditions &&
- g_GameAttributes.settings.VictoryConditions.indexOf(this.victoryCondition.Name);
-
- if (index !== undefined && (mapIndex == -1) == (index == -1))
- return;
-
- if (!g_GameAttributes.settings.VictoryConditions)
- g_GameAttributes.settings.VictoryConditions = [];
-
- if (mapIndex == -1)
- {
- if (index !== undefined)
- g_GameAttributes.settings.VictoryConditions.splice(index, 1);
- }
- else
- g_GameAttributes.settings.VictoryConditions.push(this.victoryCondition.Name);
-
- this.gameSettingsControl.updateGameAttributes();
- }
-
- onGameAttributesChange()
- {
- if (!g_GameAttributes.settings.VictoryConditions)
- {
- g_GameAttributes.settings.VictoryConditions = [];
- for (let victoryCondition of g_VictoryConditions)
- if (victoryCondition.Default)
- g_GameAttributes.settings.VictoryConditions.push(victoryCondition.Name);
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- this.setEnabled(
- g_GameAttributes.mapType != "scenario" &&
- (!this.victoryCondition.DisabledWhenChecked ||
- this.victoryCondition.DisabledWhenChecked.every(name =>
- g_GameAttributes.settings.VictoryConditions.indexOf(name) == -1)));
-
- this.setChecked(g_GameAttributes.settings.VictoryConditions.indexOf(this.victoryCondition.Name) != -1);
- }
-
- onPress(checked)
- {
- let victoryCondition = new Set(g_GameAttributes.settings.VictoryConditions);
-
- if (checked)
- {
- victoryCondition.add(this.victoryCondition.Name);
-
- if (this.victoryCondition.ChangeOnChecked)
- for (let name in this.victoryCondition.ChangeOnChecked)
- if (this.victoryCondition.ChangeOnChecked[name])
- victoryCondition.add(name);
- else
- victoryCondition.delete(name);
- }
- else
- victoryCondition.delete(this.victoryCondition.Name);
-
- g_GameAttributes.settings.VictoryConditions = Array.from(victoryCondition);
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-
- onGameAttributesFinalize()
- {
- if (!g_GameAttributes.settings.TriggerScripts)
- g_GameAttributes.settings.TriggerScripts = [];
-
- if (g_GameAttributes.settings.VictoryConditions.indexOf(this.victoryCondition.Name) != -1)
- for (let script of this.victoryCondition.Scripts)
- if (g_GameAttributes.settings.TriggerScripts.indexOf(script) == -1)
- g_GameAttributes.settings.TriggerScripts.push(script);
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/GameSetupPage.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSetupPage.js
+++ binaries/data/mods/public/gui/gamesetup/GameSetupPage.js
@@ -1,147 +0,0 @@
-/**
- * The GamesetupPage is the root class owning all other class instances.
- * The class shall be ineligible to perform any GUI object logic and shall defer that task to owned classes.
- */
-class GamesetupPage
-{
- constructor(initData, hotloadData)
- {
- if (!g_Settings)
- return;
-
- Engine.ProfileStart("GamesetupPage");
-
- this.loadHandlers = new Set();
- this.closePageHandlers = new Set();
- this.getHotloadDataHandlers = new Set();
-
- let netMessages = new NetMessages(this);
- let startGameControl = new StartGameControl(netMessages);
- let mapCache = new MapCache();
- let mapFilters = new MapFilters(mapCache);
- let gameSettingsControl = new GameSettingsControl(this, netMessages, startGameControl, mapCache);
- let playerAssignmentsControl = new PlayerAssignmentsControl(this, netMessages);
- let readyControl = new ReadyControl(netMessages, gameSettingsControl, startGameControl, playerAssignmentsControl);
-
- // These class instances control central data and do not manage any GUI Object.
- this.controls = {
- "gameSettingsControl": gameSettingsControl,
- "playerAssignmentsControl": playerAssignmentsControl,
- "mapCache": mapCache,
- "mapFilters": mapFilters,
- "readyControl": readyControl,
- "startGameControl": startGameControl
- };
-
- // These class instances are interfaces to networked messages and do not manage any GUI Object.
- this.netMessages = {
- "netMessages": netMessages,
- "gameRegisterStanza":
- Engine.HasXmppClient() &&
- new GameRegisterStanza(
- initData, this, netMessages, gameSettingsControl, playerAssignmentsControl, mapCache)
- };
-
- // This class instance owns all gamesetting GUI controls such as dropdowns and checkboxes.
- // The controls also deterministically sanitize g_GameAttributes and g_PlayerAssignments
- // without broadcasting the change.
- this.gameSettingControlManager =
- new GameSettingControlManager(this, gameSettingsControl, mapCache, mapFilters, netMessages, playerAssignmentsControl);
-
- // These classes manage GUI buttons.
- {
- let startGameButton = new StartGameButton(this, startGameControl, netMessages, readyControl, playerAssignmentsControl);
- let readyButton = new ReadyButton(readyControl, netMessages, playerAssignmentsControl);
- this.panelButtons = {
- "cancelButton": new CancelButton(this, startGameButton, readyButton, this.netMessages.gameRegisterStanza),
- "civInfoButton": new CivInfoButton(),
- "lobbyButton": new LobbyButton(),
- "readyButton": readyButton,
- "startGameButton": startGameButton
- };
- }
-
- // These classes manage GUI Objects.
- {
- let gameSettingTabs = new GameSettingTabs(this, this.panelButtons.lobbyButton);
- let gameSettingsPanel = new GameSettingsPanel(
- this, gameSettingTabs, gameSettingsControl, this.gameSettingControlManager);
-
- this.panels = {
- "chatPanel": new ChatPanel(this.gameSettingControlManager, gameSettingsControl, netMessages, playerAssignmentsControl, readyControl, gameSettingsPanel),
- "gameSettingWarning": new GameSettingWarning(gameSettingsControl, this.panelButtons.cancelButton),
- "gameDescription": new GameDescription(mapCache, gameSettingTabs, gameSettingsControl),
- "gameSettingsPanel": gameSettingsPanel,
- "gameSettingsTabs": gameSettingTabs,
- "loadingWindow": new LoadingWindow(netMessages),
- "mapPreview": new MapPreview(gameSettingsControl, mapCache),
- "resetCivsButton": new ResetCivsButton(gameSettingsControl),
- "resetTeamsButton": new ResetTeamsButton(gameSettingsControl),
- "soundNotification": new SoundNotification(netMessages, playerAssignmentsControl),
- "tipsPanel": new TipsPanel(gameSettingsPanel),
- "tooltip": new Tooltip(this.panelButtons.cancelButton)
- };
- }
-
- setTimeout(displayGamestateNotifications, 1000);
- Engine.GetGUIObjectByName("setupWindow").onTick = updateTimers;
-
- // This event is triggered after all classes have been instantiated and subscribed to each others events
- for (let handler of this.loadHandlers)
- handler(initData, hotloadData);
-
- Engine.ProfileStop();
-
- if (gameSettingsControl.autostart)
- startGameControl.launchGame();
- }
-
- registerLoadHandler(handler)
- {
- this.loadHandlers.add(handler);
- }
-
- unregisterLoadHandler(handler)
- {
- this.loadHandlers.delete(handler);
- }
-
- registerClosePageHandler(handler)
- {
- this.closePageHandlers.add(handler);
- }
-
- unregisterClosePageHandler(handler)
- {
- this.closePageHandlers.delete(handler);
- }
-
- registerGetHotloadDataHandler(handler)
- {
- this.getHotloadDataHandlers.add(handler);
- }
-
- unregisterGetHotloadDataHandler(handler)
- {
- this.getHotloadDataHandlers.delete(handler);
- }
-
- getHotloadData()
- {
- let object = {};
- for (let handler of this.getHotloadDataHandlers)
- handler(object);
- return object;
- }
-
- closePage()
- {
- for (let handler of this.closePageHandlers)
- handler();
-
- if (Engine.HasXmppClient())
- Engine.SwitchGuiPage("page_lobby.xml", { "dialog": false });
- else
- Engine.SwitchGuiPage("page_pregame.xml");
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/GameSetupPage.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/GameSetupPage.xml
+++ binaries/data/mods/public/gui/gamesetup/GameSetupPage.xml
@@ -1,82 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIBehavior.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIBehavior.js
@@ -0,0 +1,112 @@
+class AIBehavior extends GameSettingControlDropdown
+{
+ constructor(...args)
+ {
+ super(...args);
+
+ this.fixedAIBehavior = [];
+ this.defaultBehavior = Engine.ConfigDB_GetValue("user", this.ConfigBehavior);
+
+ this.dropdown.list = g_Settings.AIBehaviors.map(AIBehavior => AIBehavior.Title);
+ this.dropdown.list_data = g_Settings.AIBehaviors.map(AIBehavior => AIBehavior.Name);
+ }
+
+ setControl(gameSettingControlManager)
+ {
+ this.frame = Engine.GetGUIObjectByName("aiBehaviorFrame");
+ this.title = Engine.GetGUIObjectByName("aiBehaviorTitle");
+ this.dropdown = Engine.GetGUIObjectByName("aiBehavior");
+ this.label = Engine.GetGUIObjectByName("aiBehaviorText");
+ }
+
+ onAssignPlayer(source, target)
+ {
+ if (source && target.AIBehavior)
+ source.AIBehavior = target.AIBehavior;
+
+ delete target.AIBehavior;
+ }
+
+ onMapChange(mapData)
+ {
+ for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex)
+ {
+ let mapPData = this.gameSettingsControl.getPlayerData(mapData, playerIndex);
+ this.fixedAIBehavior[playerIndex] =
+ mapPData && mapPData.AI ?
+ (mapPData.AIBehavior !== undefined ?
+ mapPData.AIBehavior :
+ g_Settings.PlayerDefaults[this.playerIndex + 1].AIBehavior) :
+ undefined;
+ }
+ }
+
+ onGameAttributesChange()
+ {
+ for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex)
+ this.onGameAttributesChangePlayer(playerIndex);
+ }
+
+ onGameAttributesChangePlayer(playerIndex)
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, playerIndex);
+ if (!pData)
+ return;
+
+ if (pData.AI)
+ {
+ if (this.fixedAIBehavior[playerIndex] && pData.AIBehavior !== this.fixedAIBehavior[playerIndex])
+ {
+ pData.AIBehavior = this.fixedAIBehavior[playerIndex];
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ else if (pData.AIDiff !== undefined &&
+ g_Settings.AIDifficulties[pData.AIDiff].Name == "sandbox" &&
+ pData.AIBehavior != "balanced")
+ {
+ pData.AIBehavior = "balanced";
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ else if (pData.AIBehavior === undefined)
+ {
+ pData.AIBehavior = this.defaultBehavior;
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ }
+ else if (pData.AIBehavior !== undefined)
+ {
+ delete pData.AIBehavior;
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ }
+
+ onGameAttributesBatchChange()
+ {
+ this.updateSelectedValue();
+ }
+
+ updateSelectedValue()
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ this.setHidden(!pData || !pData.AI || g_Settings.AIDifficulties[pData.AIDiff].Name == "sandbox");
+ if (pData && pData.AI && pData.AIDiff !== undefined && pData.AIBehavior !== undefined)
+ this.setSelectedValue(pData.AIBehavior);
+ }
+
+ onSelectionChange(itemIdx)
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ if (!g_IsController || !pData)
+ return;
+
+ pData.AIBehavior = g_Settings.AIBehaviors[itemIdx].Name;
+ this.gameSettingsControl.updateGameAttributes();
+ this.gameSettingsControl.setNetworkGameAttributes();
+ }
+}
+
+AIBehavior.prototype.ConfigBehavior =
+ "gui.gamesetup.aibehavior";
+
+AIBehavior.prototype.TitleCaption =
+ translate("AI Behavior");
Index: binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIConfigPage.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIConfigPage.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIConfigPage.js
@@ -1,82 +1,44 @@
-/**
- * Is this user in control of game settings (i.e. is a network server, or offline player).
- */
-const g_IsController = !Engine.HasNetClient() || Engine.HasNetServer();
-
-var g_PlayerSlot;
-
-var g_AIDescriptions = [{
- "id": "",
- "data": {
- "name": translateWithContext("ai", "None"),
- "description": translate("AI will be disabled for this player.")
- }
-}].concat(g_Settings.AIDescriptions);
-
-var g_AIControls = {
- "aiSelection": {
- "labels": g_AIDescriptions.map(ai => ai.data.name),
- "selected": settings => g_AIDescriptions.findIndex(ai => ai.id == settings.id)
- },
- "aiDifficulty": {
- "labels": prepareForDropdown(g_Settings.AIDifficulties).Title,
- "selected": settings => settings.difficulty
- },
- "aiBehavior": {
- "labels": prepareForDropdown(g_Settings.AIBehaviors).Title,
- "selected": settings => g_Settings.AIBehaviors.findIndex(b => b.Name == settings.behavior)
- }
-};
-
-function init(settings)
+class AIConfigPage extends GameSettingControl
{
- // Remember the player ID that we change the AI settings for
- g_PlayerSlot = settings.playerSlot;
+ constructor(...args)
+ {
+ super(...args);
- let enabled = g_IsController && !settings.fixed;
+ this.gameSettingControls = {
+ "aiSelection": new AISelection(...args),
+ "aiDifficulty": new AIDifficulty(...args),
+ "aiBehavior": new AIBehavior(...args),
+ "aiDescription": new AIDescription(this.gameSettingsControl)
+ };
- for (let name in g_AIControls)
- {
- let control = Engine.GetGUIObjectByName(name);
- control.list = g_AIControls[name].labels;
- control.selected = g_AIControls[name].selected(settings);
- control.hidden = !enabled;
-
- let label = Engine.GetGUIObjectByName(name + "Text");
- label.caption = control.list[control.selected];
- label.hidden = enabled;
+ this.aiConfigPage = Engine.GetGUIObjectByName("aiConfigPage");
+ Engine.GetGUIObjectByName("aiConfigOkButton").onPress = this.closePage.bind(this);
}
- checkBehavior();
-}
+ openPage(playerIndex)
+ {
+ this.playerIndex = playerIndex;
-function selectAI(idx)
-{
- Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description;
-}
+ for (let name in this.gameSettingControls)
+ {
+ let control = this.gameSettingControls[name];
+ control.playerIndex = playerIndex;
+ control.updateSelectedValue();
+ if (control.updateVisibility)
+ control.updateVisibility();
+ }
+ this.aiConfigPage.hidden = false;
+ }
-/** Behavior choice does not apply for Sandbox level */
-function checkBehavior()
-{
- if (g_Settings.AIDifficulties[Engine.GetGUIObjectByName("aiDifficulty").selected].Name != "sandbox")
+ onGameAttributesBatchChange()
{
- Engine.GetGUIObjectByName("aiBehavior").enabled = true;
- return;
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ if (!pData)
+ this.closePage();
}
- let aiBehavior = Engine.GetGUIObjectByName("aiBehavior");
- aiBehavior.enabled = false;
- aiBehavior.selected = g_Settings.AIBehaviors.findIndex(b => b.Name == "balanced");
-}
-function returnAI(save = true)
-{
- let idx = Engine.GetGUIObjectByName("aiSelection").selected;
- Engine.PopGuiPage({
- "save": save,
- "id": g_AIDescriptions[idx].id,
- "name": g_AIDescriptions[idx].data.name,
- "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
- "behavior": g_Settings.AIBehaviors[Engine.GetGUIObjectByName("aiBehavior").selected].Name,
- "playerSlot": g_PlayerSlot
- });
+ closePage()
+ {
+ this.aiConfigPage.hidden = true;
+ }
}
Index: binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIConfigPage.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIConfigPage.xml
+++ binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIConfigPage.xml
@@ -1,9 +1,6 @@
-
-
-
-
+
@@ -15,42 +12,32 @@
-
- AI Player:
-
-
-
- selectAI(this.selected);
-
-
-
- AI Difficulty:
+
+
+
+
-
- checkBehavior();
+
+
+
+
-
-
- AI Behavior:
+
+
+
+
-
-
-
- Cancel
- returnAI(false);
-
-
-
+
OK
- returnAI(true);
+
-
+
Index: binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIDescription.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIDescription.js
@@ -0,0 +1,29 @@
+class AIDescription
+{
+ constructor(gameSettingsControl)
+ {
+ this.playerIndex = undefined;
+
+ this.aiDescription = Engine.GetGUIObjectByName("aiDescription");
+
+ this.gameSettingsControl = gameSettingsControl;
+ this.gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
+ }
+
+ onGameAttributesBatchChange()
+ {
+ this.updateSelectedValue();
+ }
+
+ updateSelectedValue()
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ if (!pData)
+ return;
+ let AI = g_Settings.AIDescriptions.find(AI => AI.id == pData.AI);
+ this.aiDescription.caption = AI ? AI.data.description : this.NoAIDescription;
+ }
+}
+
+AIDescription.prototype.NoAIDescription =
+ translate("AI will be disabled for this player.");
Index: binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIDifficulty.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AIDifficulty.js
@@ -0,0 +1,106 @@
+class AIDifficulty extends GameSettingControlDropdown
+{
+ constructor(...args)
+ {
+ super(...args);
+
+ this.fixedAIDiff = [];
+ this.defaultAIDiff = +Engine.ConfigDB_GetValue("user", this.ConfigDifficulty);
+
+ this.dropdown.list = g_Settings.AIDifficulties.map(AI => AI.Title);
+ this.dropdown.list_data = g_Settings.AIDifficulties.map((AI, i) => i);
+ }
+
+ setControl(gameSettingControlManager)
+ {
+ this.frame = Engine.GetGUIObjectByName("aiDifficultyFrame");
+ this.title = Engine.GetGUIObjectByName("aiDifficultyTitle");
+ this.dropdown = Engine.GetGUIObjectByName("aiDifficulty");
+ this.label = Engine.GetGUIObjectByName("aiDifficultyText");
+ }
+
+ onAssignPlayer(source, target)
+ {
+ if (source && target.AIDiff !== undefined)
+ source.AIDiff = target.AIDiff;
+
+ delete target.AIDiff;
+ }
+
+ onMapChange(mapData)
+ {
+ for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex)
+ {
+ let mapPData = this.gameSettingsControl.getPlayerData(mapData, playerIndex);
+ this.fixedAIDiff[playerIndex] =
+ mapPData && mapPData.AI ?
+ (mapPData.AIDiff !== undefined ?
+ mapPData.AIDiff :
+ g_Settings.PlayerDefaults[this.playerIndex + 1].AIDiff) :
+ undefined;
+ }
+ }
+
+ onGameAttributesChange()
+ {
+ for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex)
+ this.onGameAttributesChangePlayer(playerIndex);
+ }
+
+ onGameAttributesChangePlayer(playerIndex)
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, playerIndex);
+ if (!pData)
+ return;
+
+ if (pData.AI)
+ {
+ if (this.fixedAIDiff[playerIndex] !== undefined && pData.AIDiff !== this.fixedAIDiff[playerIndex])
+ {
+ pData.AIDiff = this.fixedAIDiff[playerIndex];
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ else if (pData.AIDiff === undefined)
+ {
+ pData.AIDiff = this.defaultAIDiff;
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ }
+ else if (pData.AIDiff !== undefined)
+ {
+ delete pData.AIDiff;
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ }
+
+ onGameAttributesBatchChange()
+ {
+ this.updateSelectedValue();
+ }
+
+ updateSelectedValue()
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ this.setHidden(!pData || !pData.AI);
+
+ if (pData && pData.AIDiff !== undefined)
+ this.setSelectedValue(pData.AIDiff);
+ }
+
+ onSelectionChange(itemIdx)
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ if (!g_IsController || !pData)
+ return;
+
+ pData.AIDiff = itemIdx;
+ this.gameSettingsControl.updateGameAttributes();
+ this.gameSettingsControl.setNetworkGameAttributes();
+ }
+};
+
+AIDifficulty.prototype.ConfigDifficulty =
+ "gui.gamesetup.aidifficulty";
+
+AIDifficulty.prototype.TitleCaption =
+ translate("AI Difficulty");
Index: binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AISelection.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/AISelection.js
@@ -0,0 +1,110 @@
+class AISelection extends GameSettingControlDropdown
+{
+ constructor(...args)
+ {
+ super(...args);
+
+ this.fixedAI = [];
+
+ this.values = prepareForDropdown([
+ this.NoAI,
+ ...g_Settings.AIDescriptions.map(AI => ({
+ "Title": AI.data.name,
+ "Id": AI.id
+ }))
+ ]);
+
+ this.dropdown.list = this.values.Title;
+ this.dropdown.list_data = this.values.Id.map((v, i) => i);
+ }
+
+ setControl(gameSettingControlManager)
+ {
+ this.frame = Engine.GetGUIObjectByName("aiSelectionFrame");
+ this.title = Engine.GetGUIObjectByName("aiSelectionTitle");
+ this.dropdown = Engine.GetGUIObjectByName("aiSelection");
+ this.label = Engine.GetGUIObjectByName("aiSelectionText");
+ }
+
+ onAssignPlayer(source, target)
+ {
+ if (source && target.AI)
+ source.AI = target.AI;
+
+ target.AI = false;
+ }
+
+ onMapChange(mapData)
+ {
+ for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex)
+ {
+ let mapPData = this.gameSettingsControl.getPlayerData(mapData, playerIndex);
+ this.fixedAI[playerIndex] = mapPData && mapPData.AI || undefined;
+ }
+ }
+
+ onGameAttributesChange()
+ {
+ for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex)
+ this.onGameAttributesChangePlayer(playerIndex);
+ }
+
+ onGameAttributesChangePlayer(playerIndex)
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, playerIndex);
+ if (!pData)
+ return;
+
+ if (this.fixedAI[playerIndex] && pData.AI !== this.fixedAI[playerIndex])
+ {
+ pData.AI = this.fixedAI[playerIndex];
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ else if (pData.AI === undefined)
+ {
+ let assignedGUID;
+ for (let guid in g_PlayerAssignments)
+ if (g_PlayerAssignments[guid].player == playerIndex + 1)
+ {
+ assignedGUID = guid;
+ break;
+ }
+
+ pData.AI = assignedGUID ? false : g_Settings.PlayerDefaults[playerIndex + 1].AI;
+ this.gameSettingsControl.updateGameAttributes();
+ }
+ }
+
+ onGameAttributesBatchChange()
+ {
+ this.updateSelectedValue();
+ }
+
+ updateSelectedValue()
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ if (!pData || pData.AI === undefined)
+ return;
+
+ this.setSelectedValue(this.values.Id.indexOf(pData.AI));
+ }
+
+ onSelectionChange(itemIdx)
+ {
+ let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex);
+ if (!pData)
+ return;
+
+ pData.AI = this.values.Id[itemIdx];
+ this.gameSettingsControl.updateGameAttributes();
+ this.gameSettingsControl.setNetworkGameAttributes();
+ }
+}
+
+AISelection.prototype.NoAI = {
+ "Title": translateWithContext("ai", "None"),
+ "Id": false
+};
+
+AISelection.prototype.TitleCaption =
+ translate("AI Player");
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js
@@ -30,8 +30,7 @@
// Store arguments
{
this.category = category;
- if (playerIndex !== undefined)
- this.playerIndex = playerIndex;
+ this.playerIndex = playerIndex;
this.gamesetupPage = gamesetupPage;
this.gameSettingsControl = gameSettingsControl;
this.mapCache = mapCache;
@@ -71,7 +70,7 @@
if (this.onGameAttributesBatchChange)
gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
- if (this.onAssignPlayer && this.playerIndex === 0)
+ if (this.onAssignPlayer)
this.gameSettingsControl.registerAssignPlayerHandler(this.onAssignPlayer.bind(this));
if (this.onPickRandomItems)
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControlCheckbox.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControlCheckbox.xml
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControlCheckbox.xml
@@ -1,7 +1,7 @@
-
+
-
+
-
+
-
+
@@ -19,16 +19,16 @@
-
+
-
+
-
+
@@ -37,15 +37,15 @@
-
+
-
+
-
+
@@ -56,11 +56,11 @@
-
+
-
+
@@ -68,12 +68,12 @@
-
+
-
-
+
+
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/GameSettingsPanel.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/GameSettingsPanel.xml
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/GameSettingsPanel.xml
@@ -7,13 +7,13 @@
-
+
-
+
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/TipsPanel.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/TipsPanel.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/TipsPanel.js
@@ -39,7 +39,7 @@
}
TipsPanel.prototype.File =
- "gui/gamesetup/Panels/Tips.txt";
+ "gui/gamesetup/Pages/GameSetupPage/Panels/Tips.txt";
TipsPanel.prototype.Config =
"gui.gamesetup.enabletips";
Index: binaries/data/mods/public/gui/gamesetup/Pages/LoadingPage/LoadingPage.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/LoadingPage/LoadingPage.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/LoadingPage/LoadingPage.js
@@ -3,17 +3,17 @@
* This is not technically necessary, but only performed to avoid confusion or irritation when showing the clients first the
* default settings and then switching to the server settings quickly thereafter.
*/
-class LoadingWindow
+class LoadingPage
{
constructor(netMessages)
{
if (g_IsNetworked)
- netMessages.registerNetMessageHandler("gamesetup", this.hideLoadingWindow.bind(this));
+ netMessages.registerNetMessageHandler("gamesetup", this.hideLoadingPage.bind(this));
else
- this.hideLoadingWindow();
+ this.hideLoadingPage();
}
- hideLoadingWindow()
+ hideLoadingPage()
{
let loadingWindow = Engine.GetGUIObjectByName("loadingWindow");
if (loadingWindow.hidden)
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CancelButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CancelButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CancelButton.js
@@ -1,47 +0,0 @@
-class CancelButton
-{
- constructor(gamesetupPage, startGameButton, readyButton, gameSettingsControl)
- {
- this.gamesetupPage = gamesetupPage;
- this.startGameButton = startGameButton;
- this.readyButton = readyButton;
- this.gameSettingsControl = gameSettingsControl;
-
- this.cancelButtonResizeHandlers = new Set();
-
- this.buttonPositions = Engine.GetGUIObjectByName("bottomRightPanel").children;
-
- this.cancelButton = Engine.GetGUIObjectByName("cancelButton");
- this.cancelButton.caption = this.Caption;
- this.cancelButton.tooltip = Engine.HasXmppClient() ? this.TooltipLobby : this.TooltipMenu;
- this.cancelButton.onPress = gamesetupPage.closePage.bind(gamesetupPage);
-
- readyButton.registerButtonHiddenChangeHandler(this.onNeighborButtonHiddenChange.bind(this));
- startGameButton.registerButtonHiddenChangeHandler(this.onNeighborButtonHiddenChange.bind(this));
- }
-
- registerCancelButtonResizeHandler(handler)
- {
- this.cancelButtonResizeHandlers.add(handler);
- }
-
- onNeighborButtonHiddenChange()
- {
- this.cancelButton.size = this.buttonPositions[
- this.buttonPositions[1].children.every(button => button.hidden) ? 1 : 0].size;
-
- for (let handler of this.cancelButtonResizeHandlers)
- handler(this.cancelButton);
- }
-}
-
-CancelButton.prototype.Caption =
- translate("Back");
-
-CancelButton.prototype.TooltipLobby =
- translate("Return to the lobby.");
-
-CancelButton.prototype.TooltipMenu =
- translate("Return to the main menu.");
-
-CancelButton.prototype.Margin = 0;
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CancelButton.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CancelButton.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CancelButton.xml
@@ -1,8 +0,0 @@
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CivInfoButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CivInfoButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/CivInfoButton.js
@@ -1,48 +0,0 @@
-class CivInfoButton
-{
- constructor()
- {
- this.civInfo = {
- "civ": "",
- "page": "page_civinfo.xml"
- };
-
- let civInfoButton = Engine.GetGUIObjectByName("civInfoButton");
- civInfoButton.onPress = this.onPress.bind(this);
- civInfoButton.tooltip =
- sprintf(translate(this.Tooltip), {
- "hotkey_civinfo": colorizeHotkey("%(hotkey)s", "civinfo"),
- "hotkey_structree": colorizeHotkey("%(hotkey)s", "structree")
- });
-
- Engine.SetGlobalHotkey("structree", this.openPage.bind(this, "page_structree.xml"));
- Engine.SetGlobalHotkey("civinfo", this.openPage.bind(this, "page_civinfo.xml"));
- }
-
- onPress()
- {
- this.openPage(this.civInfo.page);
- }
-
- openPage(page)
- {
- Engine.PushGuiPage(
- page,
- { "civ": this.civInfo.civ },
- this.storeCivInfoPage.bind(this));
- }
-
- storeCivInfoPage(data)
- {
- if (data.nextPage)
- Engine.PushGuiPage(
- data.nextPage,
- { "civ": data.civ },
- this.storeCivInfoPage.bind(this));
- else
- this.civInfo = data;
- }
-}
-
-CivInfoButton.prototype.Tooltip =
- translate("%(hotkey_civinfo)s / %(hotkey_structree)s: View History / Structure Tree\nLast opened will be reopened on click.");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/LobbyButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/LobbyButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/LobbyButton.js
@@ -1,19 +0,0 @@
-class LobbyButton
-{
- constructor()
- {
- this.lobbyButton = Engine.GetGUIObjectByName("lobbyButton");
- this.lobbyButton.tooltip = this.Tooltip;
- this.lobbyButton.onPress = this.onPress.bind(this);
- this.lobbyButton.hidden = !Engine.HasXmppClient();
- }
-
- onPress()
- {
- if (Engine.HasXmppClient())
- Engine.PushGuiPage("page_lobby.xml", { "dialog": true });
- }
-}
-
-LobbyButton.prototype.Tooltip =
- translate("Show the multiplayer lobby in a dialog window.");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/LobbyButton.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/LobbyButton.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/LobbyButton.xml
@@ -1,11 +0,0 @@
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ReadyButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ReadyButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ReadyButton.js
@@ -1,88 +0,0 @@
-class ReadyButton
-{
- constructor(readyControl, netMessages, playerAssignmentsControl)
- {
- this.readyControl = readyControl;
-
- this.hidden = undefined;
-
- this.buttonHiddenChangeHandlers = new Set();
- this.readyButtonPressHandlers = new Set();
-
- this.readyButton = Engine.GetGUIObjectByName("readyButton");
- this.readyButton.onPress = this.onPress.bind(this);
- this.readyButton.onPressRight = this.onPressRight.bind(this);
-
- playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
- netMessages.registerNetMessageHandler("netstatus", this.onNetStatusMessage.bind(this));
-
- if (g_IsController && g_IsNetworked)
- this.readyControl.setReady(this.readyControl.StayReady, true);
- }
-
- registerButtonHiddenChangeHandler(handler)
- {
- this.buttonHiddenChangeHandlers.add(handler);
- }
-
- onNetStatusMessage(message)
- {
- if (message.status == "disconnected")
- this.readyButton.enabled = false;
- }
-
- onPlayerAssignmentsChange()
- {
- let playerAssignment = g_PlayerAssignments[Engine.GetPlayerGUID()];
- let hidden = g_IsController || !playerAssignment || playerAssignment.player == -1;
-
- if (!hidden)
- {
- this.readyButton.caption = this.Caption[playerAssignment.status];
- this.readyButton.tooltip = this.Tooltip[playerAssignment.status];
- }
-
- if (hidden == this.hidden)
- return;
-
- this.hidden = hidden;
- this.readyButton.hidden = hidden;
-
- for (let handler of this.buttonHiddenChangeHandlers)
- handler(this.readyButton);
- }
-
- registerReadyButtonPressHandler(handler)
- {
- this.readyButtonPressHandlers.add(handler);
- }
-
- onPress()
- {
- let newState =
- (g_PlayerAssignments[Engine.GetPlayerGUID()].status + 1) % (this.readyControl.StayReady + 1);
-
- for (let handler of this.readyButtonPressHandlers)
- handler(newState);
-
- this.readyControl.setReady(newState, true);
- }
-
- onPressRight()
- {
- if (g_PlayerAssignments[Engine.GetPlayerGUID()].status != this.readyControl.NotReady)
- this.readyControl.setReady(this.readyControl.NotReady, true);
- }
-}
-
-ReadyButton.prototype.Caption = [
- translate("I'm ready"),
- translate("Stay ready"),
- translate("I'm not ready!")
-];
-
-ReadyButton.prototype.Tooltip = [
- translate("State that you are ready to play."),
- translate("Stay ready even when the game settings change."),
- translate("State that you are not ready to play.")
-];
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ReadyButton.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ReadyButton.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ReadyButton.xml
@@ -1,8 +0,0 @@
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ResetCivsButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ResetCivsButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ResetCivsButton.js
@@ -1,36 +0,0 @@
-class ResetCivsButton
-{
- constructor(gameSettingsControl)
- {
- this.gameSettingsControl = gameSettingsControl;
- this.gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
-
- this.civResetButton = Engine.GetGUIObjectByName("civResetButton");
- this.civResetButton.tooltip = this.Tooltip;
- this.civResetButton.onPress = this.onPress.bind(this);
- }
-
- onGameAttributesBatchChange()
- {
- if (g_GameAttributes.mapType)
- this.civResetButton.hidden = g_GameAttributes.mapType == "scenario" || !g_IsController;
- }
-
- onPress()
- {
- if (!g_GameAttributes.settings || !g_GameAttributes.settings.PlayerData)
- return;
-
- for (let pData of g_GameAttributes.settings.PlayerData)
- pData.Civ = this.RandomCivId;
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-}
-
-ResetCivsButton.prototype.Tooltip =
- translate("Reset any civilizations that have been selected to the default (random).");
-
-ResetCivsButton.prototype.RandomCivId =
- "random";
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ResetTeamsButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ResetTeamsButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/ResetTeamsButton.js
@@ -1,35 +0,0 @@
-class ResetTeamsButton
-{
- constructor(gameSettingsControl)
- {
- this.gameSettingsControl = gameSettingsControl;
- this.gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
-
- this.teamResetButton = Engine.GetGUIObjectByName("teamResetButton");
- this.teamResetButton.tooltip = this.Tooltip;
- this.teamResetButton.onPress = this.onPress.bind(this);
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.mapType)
- return;
-
- this.teamResetButton.hidden = g_GameAttributes.mapType == "scenario" || !g_IsController;
- }
-
- onPress()
- {
- if (!g_GameAttributes.settings || !g_GameAttributes.settings.PlayerData)
- return;
-
- for (let pData of g_GameAttributes.settings.PlayerData)
- pData.Team = -1;
-
- this.gameSettingsControl.updateGameAttributes();
- this.gameSettingsControl.setNetworkGameAttributes();
- }
-}
-
-ResetTeamsButton.prototype.Tooltip =
- translate("Reset all teams to the default.");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/StartGameButton.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/StartGameButton.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/StartGameButton.js
@@ -1,72 +0,0 @@
-class StartGameButton
-{
- constructor(gamesetupPage, startGameControl, netMessages, readyControl, playerAssignmentsControl)
- {
- this.startGameControl = startGameControl;
- this.readyControl = readyControl;
- this.gameStarted = false;
-
- this.buttonHiddenChangeHandlers = new Set();
-
- this.startGameButton = Engine.GetGUIObjectByName("startGameButton");
- this.startGameButton.caption = this.Caption;
- this.startGameButton.onPress = this.onPress.bind(this);
-
- gamesetupPage.registerLoadHandler(this.onLoad.bind(this));
- playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.update.bind(this));
- }
-
- registerButtonHiddenChangeHandler(handler)
- {
- this.buttonHiddenChangeHandlers.add(handler);
- }
-
- onLoad()
- {
- this.startGameButton.hidden = !g_IsController;
- for (let handler of this.buttonHiddenChangeHandlers)
- handler();
- }
-
- update()
- {
- let isEveryoneReady = this.isEveryoneReady();
- this.startGameButton.enabled = !this.gameStarted && isEveryoneReady;
- this.startGameButton.tooltip =
- !g_IsNetworked || isEveryoneReady ?
- this.ReadyTooltip :
- this.ReadyTooltipWaiting;
- }
-
- isEveryoneReady()
- {
- if (!g_IsNetworked)
- return true;
-
- for (let guid in g_PlayerAssignments)
- if (g_PlayerAssignments[guid].player != -1 &&
- g_PlayerAssignments[guid].status == this.readyControl.NotReady)
- return false;
-
- return true;
- }
-
- onPress()
- {
- if (this.gameStarted)
- return;
-
- this.gameStarted = true;
- this.update();
- this.startGameControl.launchGame();
- }
-}
-
-StartGameButton.prototype.Caption =
- translate("Start Game!");
-
-StartGameButton.prototype.ReadyTooltip =
- translate("Start a new game with the current settings.");
-
-StartGameButton.prototype.ReadyTooltipWaiting =
- translate("Start a new game with the current settings (disabled until all players are ready).");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Buttons/StartGameButton.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Buttons/StartGameButton.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/Buttons/StartGameButton.xml
@@ -1,8 +0,0 @@
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatInputAutocomplete.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatInputAutocomplete.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatInputAutocomplete.js
@@ -1,37 +0,0 @@
-class ChatInputAutocomplete
-{
- constructor(gameSettingControlManager, gameSettingsControl, playerAssignmentsControl)
- {
- this.gameSettingControlManager = gameSettingControlManager;
- this.entries = undefined;
-
- playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onAutocompleteChange.bind(this));
- gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onAutocompleteChange.bind(this));
- }
-
- onAutocompleteChange()
- {
- this.entries = undefined;
- }
-
- // Collects all strings that can be autocompleted and
- // sorts them by priority (so that playernames are always autocompleted first).
- getAutocompleteEntries()
- {
- if (this.entries)
- return this.entries;
-
- // Maps from priority to autocompletable strings
- let entries = { "0": [] };
-
- this.gameSettingControlManager.addAutocompleteEntries(entries);
-
- let allEntries = Object.keys(entries).sort((a, b) => +b - +a).reduce(
- (all, priority) => all.concat(entries[priority]),
- []);
-
- this.entries = Array.from(new Set(allEntries));
-
- return this.entries;
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatInputPanel.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatInputPanel.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatInputPanel.js
@@ -1,55 +0,0 @@
-class ChatInputPanel
-{
- constructor(netMessages, chatInputAutocomplete)
- {
- this.chatInputAutocomplete = chatInputAutocomplete;
-
- this.chatInput = Engine.GetGUIObjectByName("chatInput");
- this.chatInput.tooltip = colorizeAutocompleteHotkey(this.Tooltip);
- this.chatInput.onPress = this.onPress.bind(this);
- this.chatInput.onTab = this.onTab.bind(this);
- this.chatInput.focus();
-
- this.chatSubmitButton = Engine.GetGUIObjectByName("chatSubmitButton");
- this.chatSubmitButton.onPress = this.onPress.bind(this);
-
- netMessages.registerNetMessageHandler("netstatus", this.onNetStatusMessage.bind(this));
- }
-
- onNetStatusMessage(message)
- {
- if (message.status == "disconnected")
- {
- reportDisconnect(message.reason, true);
- this.chatInput.hidden = true;
- this.chatSubmitButton.hidden = true;
- }
- }
-
- onTab()
- {
- autoCompleteText(
- this.chatInput,
- this.chatInputAutocomplete.getAutocompleteEntries());
- }
-
- onPress()
- {
- if (!g_IsNetworked)
- return;
-
- let text = this.chatInput.caption;
- if (!text.length)
- return;
-
- this.chatInput.caption = "";
-
- if (!executeNetworkCommand(text))
- Engine.SendNetworkChat(text);
-
- this.chatInput.focus();
- }
-}
-
-ChatInputPanel.prototype.Tooltip =
- translate("Press %(hotkey)s to autocomplete player names or settings.");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientChat.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientChat.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientChat.js
@@ -1,53 +0,0 @@
-ChatMessageEvents.ClientChat = class
-{
- constructor(chatMessagesPanel, netMessages)
- {
- this.chatMessagesPanel = chatMessagesPanel;
-
- netMessages.registerNetMessageHandler("chat", this.onClientChat.bind(this));
- this.usernameArgs = {};
- this.messageArgs = {};
-
- // TODO: Remove this global required by gui/common/
- global.colorizePlayernameByGUID = this.colorizePlayernameByGUID.bind(this);
- }
-
- onClientChat(message)
- {
- this.usernameArgs.username = this.colorizePlayernameByGUID(message.guid);
- this.messageArgs.username = setStringTags(sprintf(this.SenderFormat, this.usernameArgs), this.SenderTags);
- this.messageArgs.message = escapeText(message.text);
- this.chatMessagesPanel.addText(sprintf(this.MessageFormat, this.messageArgs));
- }
-
- colorizePlayernameByGUID(guid)
- {
- // TODO: Controllers should have the moderator-prefix
- let username = g_PlayerAssignments[guid] ? escapeText(g_PlayerAssignments[guid].name) : translate("Unknown Player");
- let playerID = g_PlayerAssignments[guid] ? g_PlayerAssignments[guid].player : -1;
-
- let color = "white";
- if (playerID > 0)
- {
- color = g_GameAttributes.settings.PlayerData[playerID - 1].Color;
-
- // Enlighten playercolor to improve readability
- let [h, s, l] = rgbToHsl(color.r, color.g, color.b);
- let [r, g, b] = hslToRgb(h, s, Math.max(0.6, l));
-
- color = rgbToGuiColor({ "r": r, "g": g, "b": b });
- }
-
- return coloredText(username, color);
- }
-};
-
-ChatMessageEvents.ClientChat.prototype.SenderFormat =
- translate("<%(username)s>");
-
-ChatMessageEvents.ClientChat.prototype.MessageFormat =
- translate("%(username)s %(message)s");
-
-ChatMessageEvents.ClientChat.prototype.SenderTags = {
- "font": "sans-bold-13"
-};
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientConnection.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientConnection.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientConnection.js
@@ -1,30 +0,0 @@
-ChatMessageEvents.ClientConnection = class
-{
- constructor(chatMessagesPanel, netMessages, gameSettingsControl, playerAssignmentsControl)
- {
- this.chatMessagesPanel = chatMessagesPanel;
-
- playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
- playerAssignmentsControl.registerClientLeaveHandler(this.onClientLeave.bind(this));
-
- this.args = {};
- }
-
- onClientJoin(newGUID, newAssignments)
- {
- this.args.username = newAssignments[newGUID].name;
- this.chatMessagesPanel.addStatusMessage(sprintf(this.JoinText, this.args));
- }
-
- onClientLeave(guid)
- {
- this.args.username = g_PlayerAssignments[guid].name;
- this.chatMessagesPanel.addStatusMessage(sprintf(this.LeaveText, this.args));
- }
-};
-
-ChatMessageEvents.ClientConnection.prototype.JoinText =
- translate("%(username)s has joined");
-
-ChatMessageEvents.ClientConnection.prototype.LeaveText =
- translate("%(username)s has left");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientKicked.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientKicked.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientKicked.js
@@ -1,25 +0,0 @@
-ChatMessageEvents.ClientKicked = class
-{
- constructor(chatMessagesPanel, netMessages)
- {
- this.chatMessagesPanel = chatMessagesPanel;
-
- this.messageArgs = {};
-
- netMessages.registerNetMessageHandler("kicked", this.onClientKicked.bind(this));
- }
-
- onClientKicked(message)
- {
- this.messageArgs.username = message.username;
- this.chatMessagesPanel.addStatusMessage(sprintf(
- message.banned ? this.BannedMessage : this.KickedMessage,
- this.messageArgs));
- }
-};
-
-ChatMessageEvents.ClientKicked.prototype.KickedMessage =
- translate("%(username)s has been kicked");
-
-ChatMessageEvents.ClientKicked.prototype.BannedMessage =
- translate("%(username)s has been banned");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientReady.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientReady.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/ClientReady.js
@@ -1,30 +0,0 @@
-ChatMessageEvents.ClientReady = class
-{
- constructor(chatMessagesPanel, netMessages, gameSettingsControl, playerAssignmentsControl, readyControl)
- {
- this.chatMessagesPanel = chatMessagesPanel;
-
- this.args = {};
-
- netMessages.registerNetMessageHandler("ready", this.onReadyMessage.bind(this));
- }
-
- onReadyMessage(message)
- {
- let playerAssignment = g_PlayerAssignments[message.guid];
- if (!playerAssignment || playerAssignment.player == -1)
- return;
-
- let text = this.ReadyMessage[message.status] || undefined;
- if (!text)
- return;
-
- this.args.username = playerAssignment.name;
- this.chatMessagesPanel.addText(sprintf(text, this.args));
- }
-};
-
-ChatMessageEvents.ClientReady.prototype.ReadyMessage = [
- translate("* %(username)s is not ready."),
- translate("* %(username)s is ready!")
-];
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/GameSettingsChanged.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/GameSettingsChanged.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessages/GameSettingsChanged.js
@@ -1,22 +0,0 @@
-/**
- * The purpose of this message is to indicate to the local player when settings they had agreed on changed.
- */
-ChatMessageEvents.GameSettingsChanged = class
-{
- constructor(chatMessagesPanel, netMessages, gameSettingsControl, playerAssignmentsControl, readyControl)
- {
- this.readyControl = readyControl;
- this.chatMessagesPanel = chatMessagesPanel;
-
- readyControl.registerResetReadyHandler(this.onResetReady.bind(this));
- }
-
- onResetReady()
- {
- if (this.readyControl.getLocalReadyState() == this.readyControl.Ready)
- this.chatMessagesPanel.addStatusMessage(this.MessageText);
- }
-};
-
-ChatMessageEvents.GameSettingsChanged.prototype.MessageText =
- translate("Game settings have been changed");
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessagesPanel.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessagesPanel.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatMessagesPanel.js
@@ -1,81 +0,0 @@
-/**
- * This class stores and displays the chat history since the login and
- * displays timestamps if enabled.
- */
-class ChatMessagesPanel
-{
- constructor(gameSettingsPanel)
- {
- this.gameSettingsPanel = gameSettingsPanel;
-
- this.chatHistory = "";
-
- this.statusMessageFormat = new StatusMessageFormat();
-
- if (Engine.ConfigDB_GetValue("user", this.ConfigTimestamp) == "true")
- this.timestampWrapper = new TimestampWrapper();
-
- this.chatText = Engine.GetGUIObjectByName("chatText");
- this.chatPanel = Engine.GetGUIObjectByName("chatPanel");
- this.chatPanel.onWindowResized = this.onWindowResized.bind(this);
- gameSettingsPanel.registerGameSettingsPanelResizeHandler(this.onGameSettingsPanelResize.bind(this));
-
- // TODO: Remove global requirements by gui/common/network.js
- g_NetworkCommands["/list"] = () => { this.addText(getUsernameList()); };
- g_NetworkCommands["/clear"] = this.clearChatMessages.bind(this);
- global.kickError = () => {};
- }
-
- addText(text)
- {
- if (this.timestampWrapper)
- text = this.timestampWrapper.format(text);
-
- this.chatHistory += this.chatHistory ? "\n" + text : text;
- this.chatText.caption = this.chatHistory;
- }
-
- addStatusMessage(text)
- {
- this.addText(this.statusMessageFormat.format(text));
- }
-
- clearChatMessages()
- {
- this.chatHistory = "";
- this.chatText.caption = "";
- }
-
- updateHidden()
- {
- let size = this.chatPanel.getComputedSize();
- this.chatPanel.hidden = !g_IsNetworked || size.right - size.left < this.MinimumWidth;
- }
-
- onWindowResized()
- {
- this.updateHidden();
- }
-
- onGameSettingsPanelResize(settingsPanel)
- {
- let size = this.chatPanel.size;
- size.right = settingsPanel.size.left + this.gameSettingsPanel.MaxColumnWidth + this.Margin;
- this.chatPanel.size = size;
-
- this.updateHidden();
- }
-}
-
-/**
- * Minimum amount of pixels required for the chat panel to be visible.
- */
-ChatMessagesPanel.prototype.MinimumWidth = 96;
-
-/**
- * Horizontal space between the chat window and the settings panel.
- */
-ChatMessagesPanel.prototype.Margin = 10;
-
-ChatMessagesPanel.prototype.ConfigTimestamp =
- "chat.timestamp";
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatPanel.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatPanel.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatPanel.js
@@ -1,26 +0,0 @@
-/**
- * Properties of this prototype are classes that subscribe to one or more events and
- * construct a formatted chat message to be displayed on that event.
- *
- * Important: Apply escapeText on player provided input to avoid players breaking the game for everybody.
- */
-class ChatMessageEvents
-{
-}
-
-class ChatPanel
-{
- constructor(gameSettingControlManager, gameSettingsControl, netMessages, playerAssignmentsControl, readyControl, gameSettingsPanel)
- {
- this.statusMessageFormat = new StatusMessageFormat();
-
- this.chatMessagesPanel = new ChatMessagesPanel(gameSettingsPanel);
- this.chatInputAutocomplete = new ChatInputAutocomplete(gameSettingControlManager, gameSettingsControl, playerAssignmentsControl);
- this.chatInputPanel = new ChatInputPanel(netMessages, this.chatInputAutocomplete);
-
- this.chatMessageEvents = [];
- for (let name in ChatMessageEvents)
- this.chatMessageEvents.push(new ChatMessageEvents[name](
- this.chatMessagesPanel, netMessages, gameSettingsControl, playerAssignmentsControl, readyControl));
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatPanel.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatPanel.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/ChatPanel.xml
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
- Send
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/StatusMessageFormat.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/StatusMessageFormat.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/StatusMessageFormat.js
@@ -1,28 +0,0 @@
-/**
- * Status messages are textual event notifications triggered by multi-user chat room actions.
- */
-class StatusMessageFormat
-{
- constructor()
- {
- this.args = {};
- }
-
- /**
- * escapeText is the responsibility of the caller.
- */
- format(text)
- {
- this.args.message = text;
- return setStringTags(
- sprintf(this.MessageFormat, this.args),
- this.MessageTags);
- }
-}
-
-StatusMessageFormat.prototype.MessageFormat =
- translate("== %(message)s");
-
-StatusMessageFormat.prototype.MessageTags = {
- "font": "sans-bold-13"
-};
Index: binaries/data/mods/public/gui/gamesetup/Panels/Chat/TimestampWrapper.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Chat/TimestampWrapper.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Chat/TimestampWrapper.js
@@ -1,31 +0,0 @@
-/**
- * This class wraps a string with a timestamp dating to when the message was sent.
- */
-class TimestampWrapper
-{
- constructor()
- {
- this.timeArgs = {};
- this.timestampArgs = {};
- }
-
- format(text)
- {
- this.timeArgs.time =
- Engine.FormatMillisecondsIntoDateStringLocal(Date.now(), this.TimeFormat);
-
- this.timestampArgs.time = sprintf(this.TimestampFormat, this.timeArgs);
- this.timestampArgs.message = text;
-
- return sprintf(this.TimestampedMessageFormat, this.timestampArgs);
- }
-}
-
-TimestampWrapper.prototype.TimestampedMessageFormat =
- translate("%(time)s %(message)s");
-
-TimestampWrapper.prototype.TimestampFormat =
- translate("\\[%(time)s]");
-
-TimestampWrapper.prototype.TimeFormat =
- translate("HH:mm");
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameDescription.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameDescription.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameDescription.js
@@ -1,27 +0,0 @@
-class GameDescription
-{
- constructor(mapCache, gameSettingTabs, gameSettingsControl)
- {
- this.mapCache = mapCache;
-
- this.gameDescriptionFrame = Engine.GetGUIObjectByName("gameDescriptionFrame");
- this.gameDescription = Engine.GetGUIObjectByName("gameDescription");
-
- gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
- gameSettingTabs.registerTabsResizeHandler(this.onTabsResize.bind(this));
- }
-
- onTabsResize(settingsTabButtonsFrame)
- {
- let size = this.gameDescriptionFrame.size;
- size.top = settingsTabButtonsFrame.size.bottom + this.Margin;
- this.gameDescriptionFrame.size = size;
- }
-
- onGameAttributesBatchChange()
- {
- this.gameDescription.caption = getGameDescription(this.mapCache);
- }
-}
-
-GameDescription.prototype.Margin = 3;
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameDescription.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameDescription.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameDescription.xml
@@ -1,4 +0,0 @@
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameSettingWarning.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameSettingWarning.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameSettingWarning.js
@@ -1,41 +0,0 @@
-class GameSettingWarning
-{
- constructor(gameSettingsControl, cancelButton)
- {
- if (!g_IsNetworked)
- return;
-
- this.gameSettingWarning = Engine.GetGUIObjectByName("gameSettingWarning");
-
- gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
- cancelButton.registerCancelButtonResizeHandler(this.onCancelButtonResize.bind(this));
- }
-
- onGameAttributesBatchChange()
- {
- let caption =
- g_GameAttributes.settings.CheatsEnabled ?
- this.CheatsEnabled :
- g_GameAttributes.settings.RatingEnabled ?
- this.RatingEnabled :
- "";
-
- this.gameSettingWarning.caption = caption;
- this.gameSettingWarning.hidden = !caption;
- }
-
- onCancelButtonResize(cancelButton)
- {
- let size = this.gameSettingWarning.size;
- size.right = cancelButton.size.left - this.Margin;
- this.gameSettingWarning.size = size;
- }
-}
-
-GameSettingWarning.prototype.Margin = 10;
-
-GameSettingWarning.prototype.CheatsEnabled =
- translate("Cheats enabled.");
-
-GameSettingWarning.prototype.RatingEnabled =
- translate("Rated game.");
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameSettingWarning.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameSettingWarning.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameSettingWarning.xml
@@ -1,2 +0,0 @@
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsPanel.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsPanel.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsPanel.js
@@ -1,188 +0,0 @@
-class GameSettingsPanel
-{
- constructor(gamesetupPage, gameSettingTabs, gameSettingsControl, gameSettingControlManager)
- {
- this.centerRightPanel = Engine.GetGUIObjectByName("centerRightPanel");
- this.settingTabButtonsFrame = Engine.GetGUIObjectByName("settingTabButtonsFrame");
- this.settingsPanelFrame = Engine.GetGUIObjectByName("settingsPanelFrame");
-
- this.gameSettingControlManager = gameSettingControlManager;
- this.gameSettingsPanelResizeHandlers = new Set();
-
- this.setupWindow = Engine.GetGUIObjectByName("setupWindow");
- this.setupWindow.onWindowResized = this.onWindowResized.bind(this);
-
- this.settingsPanel = Engine.GetGUIObjectByName("settingsPanel");
-
- this.enabled = Engine.ConfigDB_GetValue("user", this.ConfigNameSlide) == "true";
- this.slideSpeed = this.enabled ? this.SlideSpeed : Infinity;
- this.lastTickTime = undefined;
-
- gameSettingTabs.registerTabSelectHandler(this.updateSize.bind(this));
- gameSettingsControl.registerGameAttributesBatchChangeHandler(this.updateSize.bind(this));
- gamesetupPage.registerLoadHandler(this.triggerResizeHandlers.bind(this));
- }
-
- registerGameSettingsPanelResizeHandler(handler)
- {
- this.gameSettingsPanelResizeHandlers.add(handler);
- }
-
- triggerResizeHandlers()
- {
- for (let handler of this.gameSettingsPanelResizeHandlers)
- handler(this.settingsPanelFrame);
- }
-
- onWindowResized()
- {
- this.updateSize();
- this.triggerResizeHandlers();
- }
-
- updateSize()
- {
- this.gameSettingControlManager.updateSettingVisibility();
- this.positionSettings();
-
- this.lastTickTime = undefined;
- this.settingsPanelFrame.onTick = this.onTick.bind(this);
- }
-
- onTick()
- {
- let now = Date.now();
- let tickLength = now - this.lastTickTime;
- let previousTime = this.lastTickTime;
- this.lastTickTime = now;
- if (previousTime === undefined)
- return;
-
- let distance = this.slideSpeed * tickLength;
- let rightBorder = this.settingTabButtonsFrame.size.left;
- let offset = 0;
- if (g_TabCategorySelected === undefined)
- {
- let maxOffset = rightBorder - this.settingsPanelFrame.size.left;
- if (maxOffset > 0)
- offset = Math.min(distance, maxOffset);
- }
- else if (rightBorder > this.settingsPanelFrame.size.right)
- {
- offset = Math.min(distance, rightBorder - this.settingsPanelFrame.size.right);
- }
- else
- {
- let maxOffset = this.settingsPanelFrame.size.left - rightBorder + (this.settingsPanelFrame.size.right - this.settingsPanelFrame.size.left);
- if (maxOffset > 0)
- offset = -Math.min(distance, maxOffset);
- }
-
- if (offset)
- this.changePanelWidth(offset);
- else
- {
- delete this.settingsPanelFrame.onTick;
- this.lastTickTime = undefined;
- }
- }
-
- changePanelWidth(offset)
- {
- if (!offset)
- return;
-
- let size = this.settingsPanelFrame.size;
- size.left += offset;
- size.right += offset;
- this.settingsPanelFrame.size = size;
-
- this.triggerResizeHandlers();
- }
-
- /**
- * Distribute the currently visible settings over the settings panel.
- * First calculate the number of columns required, then place the setting frames.
- */
- positionSettings()
- {
- let setupWindowSize = this.setupWindow.getComputedSize();
-
- let columnWidth = Math.min(
- this.MaxColumnWidth,
- (setupWindowSize.right - setupWindowSize.left + this.centerRightPanel.size.left) / 2);
-
- let settingsPerColumn;
- {
- let settingPanelSize = this.settingsPanel.getComputedSize();
- let maxSettingsPerColumn = Math.floor((settingPanelSize.bottom - settingPanelSize.top) / this.SettingHeight);
- let settingCount = this.settingsPanel.children.filter(child => !child.children[0].hidden).length;
- settingsPerColumn = settingCount / Math.ceil(settingCount / maxSettingsPerColumn);
- }
-
- let yPos = this.SettingMarginBottom;
- let column = 0;
- let settingsThisColumn = 0;
-
- let selectedTab = g_GameSettingsLayout[g_TabCategorySelected];
- if (!selectedTab)
- return;
-
- for (let name of selectedTab.settings)
- {
- let settingFrame = this.gameSettingControlManager.gameSettingControls[name].frame;
- if (settingFrame.hidden)
- continue;
-
- if (settingsThisColumn >= settingsPerColumn)
- {
- yPos = this.SettingMarginBottom;
- ++column;
- settingsThisColumn = 0;
- }
-
- settingFrame.size = new GUISize(
- columnWidth * column,
- yPos,
- columnWidth * (column + 1) - this.SettingMarginRight,
- yPos + this.SettingHeight - this.SettingMarginBottom);
-
- yPos += this.SettingHeight;
- ++settingsThisColumn;
- }
-
- {
- let size = this.settingsPanelFrame.size;
- size.right = size.left + (column + 1) * columnWidth;
- this.settingsPanelFrame.size = size;
- }
- }
-}
-
-GameSettingsPanel.prototype.ConfigNameSlide =
- "gui.gamesetup.settingsslide";
-
-/**
- * Maximum width of a column in the settings panel.
- */
-GameSettingsPanel.prototype.MaxColumnWidth = 470;
-
-/**
- * Pixels per millisecond the settings panel slides when opening/closing.
- */
-GameSettingsPanel.prototype.SlideSpeed = 1.2;
-
-/**
- * Vertical size of a setting frame.
- */
-GameSettingsPanel.prototype.SettingHeight = 32;
-
-/**
- * Horizontal space between two setting frames.
- */
-GameSettingsPanel.prototype.SettingMarginRight = 10;
-
-/**
- * Vertical space between two setting frames.
- */
-GameSettingsPanel.prototype.SettingMarginBottom = 2;
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsPanel.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsPanel.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsPanel.xml
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsTabs.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsTabs.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsTabs.js
@@ -1,97 +0,0 @@
-class GameSettingTabs
-{
- constructor(gamesetupPage, lobbyButton)
- {
- this.lobbyButton = lobbyButton;
-
- this.tabSelectHandlers = new Set();
- this.tabsResizeHandlers = new Set();
-
- this.settingsTabButtonsFrame = Engine.GetGUIObjectByName("settingTabButtonsFrame");
-
- for (let tab in g_GameSettingsLayout)
- g_GameSettingsLayout[tab].tooltip =
- sprintf(this.ToggleTooltip, { "name": g_GameSettingsLayout[tab].label }) +
- colorizeHotkey("\n" + this.HotkeyDownTooltip, this.ConfigNameHotkeyDown) +
- colorizeHotkey("\n" + this.HotkeyUpTooltip, this.ConfigNameHotkeyUp);
-
- gamesetupPage.registerLoadHandler(this.onLoad.bind(this));
- Engine.SetGlobalHotkey("cancel", selectPanel);
- }
-
- registerTabsResizeHandler(handler)
- {
- this.tabsResizeHandlers.add(handler);
- }
-
- registerTabSelectHandler(handler)
- {
- this.tabSelectHandlers.add(handler);
- }
-
- onLoad()
- {
- placeTabButtons(
- g_GameSettingsLayout,
- this.TabButtonHeight,
- this.TabButtonMargin,
- this.onTabPress.bind(this),
- this.onTabSelect.bind(this));
-
- this.resize();
-
- if (!g_IsController)
- selectPanel();
- }
-
- resize()
- {
- let size = this.settingsTabButtonsFrame.size;
- size.bottom = size.top + g_GameSettingsLayout.length * (this.TabButtonHeight + this.TabButtonMargin);
-
- if (!this.lobbyButton.lobbyButton.hidden)
- {
- let lobbyButtonSize = this.lobbyButton.lobbyButton.parent.size;
- size.right -= lobbyButtonSize.right - lobbyButtonSize.left + this.LobbyButtonMargin;
- }
- this.settingsTabButtonsFrame.size = size;
-
- for (let handler of this.tabsResizeHandlers)
- handler(this.settingsTabButtonsFrame);
- }
-
- onTabPress(category)
- {
- selectPanel(category == g_TabCategorySelected ? undefined : category);
- }
-
- onTabSelect()
- {
- for (let handler of this.tabSelectHandlers)
- handler();
- }
-}
-
-GameSettingTabs.prototype.ToggleTooltip =
- translate("Toggle the %(name)s settings tab.");
-
-GameSettingTabs.prototype.HotkeyUpTooltip =
- translate("Use %(hotkey)s to move a settings tab up.");
-
-GameSettingTabs.prototype.HotkeyDownTooltip =
- translate("Use %(hotkey)s to move a settings tab down.");
-
-GameSettingTabs.prototype.ConfigNameHotkeyUp =
- "tab.next";
-
-GameSettingTabs.prototype.ConfigNameHotkeyDown =
- "tab.prev";
-
-GameSettingTabs.prototype.TabButtonHeight = 30;
-
-GameSettingTabs.prototype.TabButtonMargin = 4;
-
-/**
- * Horizontal space between tab buttons and lobby button.
- */
-GameSettingTabs.prototype.LobbyButtonMargin = 8;
Index: binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsTabs.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsTabs.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/GameSettingsTabs.xml
@@ -1,5 +0,0 @@
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/LoadingWindow.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/LoadingWindow.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/LoadingWindow.js
@@ -1,25 +0,0 @@
-/**
- * The purpose of this page is to display a placeholder in multiplayer until the settings from the server have been received.
- * This is not technically necessary, but only performed to avoid confusion or irritation when showing the clients first the
- * default settings and then switching to the server settings quickly thereafter.
- */
-class LoadingWindow
-{
- constructor(netMessages)
- {
- if (g_IsNetworked)
- netMessages.registerNetMessageHandler("gamesetup", this.hideLoadingWindow.bind(this));
- else
- this.hideLoadingWindow();
- }
-
- hideLoadingWindow()
- {
- let loadingWindow = Engine.GetGUIObjectByName("loadingWindow");
- if (loadingWindow.hidden)
- return;
-
- loadingWindow.hidden = true;
- Engine.GetGUIObjectByName("setupWindow").hidden = false;
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/Panels/LoadingWindow.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/LoadingWindow.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/LoadingWindow.xml
@@ -1,11 +0,0 @@
-
-
-
-
- Loading
-
-
-
- Loading map data. Please wait…
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/MapPreview.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/MapPreview.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/MapPreview.js
@@ -1,36 +0,0 @@
-class MapPreview
-{
- constructor(gameSettingsControl, mapCache)
- {
- this.gameSettingsControl = gameSettingsControl;
- this.mapCache = mapCache;
-
- this.mapInfoName = Engine.GetGUIObjectByName("mapInfoName");
- this.mapPreview = Engine.GetGUIObjectByName("mapPreview");
-
- gameSettingsControl.registerMapChangeHandler(this.onMapChange.bind(this));
- gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
- }
-
- onMapChange(mapData)
- {
- let preview = mapData && mapData.settings && mapData.settings.Preview;
- if (!g_GameAttributes.settings.Preview || g_GameAttributes.settings.Preview != preview)
- {
- g_GameAttributes.settings.Preview = preview;
- this.gameSettingsControl.updateGameAttributes();
- }
- }
-
- onGameAttributesBatchChange()
- {
- if (!g_GameAttributes.map || !g_GameAttributes.mapType)
- return;
-
- this.mapInfoName.caption = this.mapCache.translateMapName(
- this.mapCache.getTranslatableMapName(g_GameAttributes.mapType, g_GameAttributes.map));
-
- this.mapPreview.sprite =
- this.mapCache.getMapPreview(g_GameAttributes.mapType, g_GameAttributes.map, g_GameAttributes);
- }
-}
Index: binaries/data/mods/public/gui/gamesetup/Panels/MapPreview.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/MapPreview.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/MapPreview.xml
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/SoundNotification.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/SoundNotification.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/SoundNotification.js
@@ -1,28 +0,0 @@
-class SoundNotification
-{
- constructor(netMessages, playerAssignmentsControl)
- {
- netMessages.registerNetMessageHandler("chat", this.onClientChat.bind(this));
- playerAssignmentsControl.registerClientJoinHandler(this.onClientJoin.bind(this));
- }
-
- onClientJoin(guid)
- {
- if (guid != Engine.GetPlayerGUID())
- soundNotification(this.ConfigJoinNotification);
- }
-
- onClientChat(message)
- {
- if (message.guid != Engine.GetPlayerGUID() &&
- message.text.toLowerCase().indexOf(
- splitRatingFromNick(g_PlayerAssignments[Engine.GetPlayerGUID()].name).nick.toLowerCase()) != -1)
- soundNotification(this.ConfigNickNotification);
- }
-}
-
-SoundNotification.prototype.ConfigJoinNotification =
- "gamesetup.join";
-
-SoundNotification.prototype.ConfigNickNotification =
- "nick";
Index: binaries/data/mods/public/gui/gamesetup/Panels/Tips.txt
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Tips.txt
+++ binaries/data/mods/public/gui/gamesetup/Panels/Tips.txt
@@ -1 +0,0 @@
-Although reasonably easy for an experienced player, the default AI level is quite challenging for new players yet to master the basic mechanisms of the game. Beginners are advised to start by playing against a lower level AI (Sandbox or Very Easy). Change the AI level by clicking the gear icon next to the player you want to modify in the selection panel above.
Index: binaries/data/mods/public/gui/gamesetup/Panels/TipsPanel.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/TipsPanel.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/TipsPanel.js
@@ -1,45 +0,0 @@
-/**
- * The TipsPanel shows some hints to newcomers.
- * It is only shown in Singleplayer mode since the chat is shown instead in multiplayer mode.
- */
-class TipsPanel
-{
- constructor(gameSettingsPanel)
- {
- let available = !g_IsNetworked && Engine.ConfigDB_GetValue("user", this.Config) == "true";
-
- this.spTips = Engine.GetGUIObjectByName("spTips");
- this.spTips.hidden = !available;
- if (!available)
- return;
-
- this.displaySPTips = Engine.GetGUIObjectByName("displaySPTips");
- this.displaySPTips.onPress = this.onPress.bind(this);
-
- Engine.GetGUIObjectByName("aiTips").caption =
- Engine.TranslateLines(Engine.ReadFile(this.File));
-
- gameSettingsPanel.registerGameSettingsPanelResizeHandler(this.onGameSettingsPanelResize.bind(this));
- }
-
- onPress()
- {
- Engine.ConfigDB_CreateAndWriteValueToFile(
- "user",
- this.Config,
- String(this.displaySPTips.checked),
- "config/user.cfg");
- }
-
- onGameSettingsPanelResize(settingsPanel)
- {
- this.spTips.hidden =
- this.spTips.getComputedSize().right > settingsPanel.getComputedSize().left;
- }
-}
-
-TipsPanel.prototype.File =
- "gui/gamesetup/Panels/Tips.txt";
-
-TipsPanel.prototype.Config =
- "gui.gamesetup.enabletips";
Index: binaries/data/mods/public/gui/gamesetup/Panels/TipsPanel.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/TipsPanel.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/TipsPanel.xml
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
- Show this message in the future.
-
-
-
-
-
Index: binaries/data/mods/public/gui/gamesetup/Panels/Tooltip.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Tooltip.js
+++ binaries/data/mods/public/gui/gamesetup/Panels/Tooltip.js
@@ -1,17 +0,0 @@
-class Tooltip
-{
- constructor(cancelButton)
- {
- this.onscreenToolTip = Engine.GetGUIObjectByName("onscreenToolTip");
- cancelButton.registerCancelButtonResizeHandler(this.onCancelButtonResize.bind(this));
- }
-
- onCancelButtonResize(cancelButton)
- {
- let size = this.onscreenToolTip.size;
- size.right = cancelButton.size.left - this.Margin;
- this.onscreenToolTip.size = size;
- }
-}
-
-Tooltip.prototype.Margin = 10;
Index: binaries/data/mods/public/gui/gamesetup/Panels/Tooltip.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Panels/Tooltip.xml
+++ binaries/data/mods/public/gui/gamesetup/Panels/Tooltip.xml
@@ -1,7 +0,0 @@
-
-
Index: binaries/data/mods/public/gui/gamesetup/gamesetup.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/gamesetup.xml
+++ binaries/data/mods/public/gui/gamesetup/gamesetup.xml
@@ -4,17 +4,20 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -22,9 +25,12 @@
Match Setup
-
+
+
+
+
+
-
Index: binaries/data/mods/public/gui/page_aiconfig.xml
===================================================================
--- binaries/data/mods/public/gui/page_aiconfig.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- common/modern/setup.xml
- common/modern/styles.xml
- common/modern/sprites.xml
-
- aiconfig/aiconfig.xml
-
Index: binaries/data/mods/public/l10n/messages.json
===================================================================
--- binaries/data/mods/public/l10n/messages.json
+++ binaries/data/mods/public/l10n/messages.json
@@ -74,7 +74,6 @@
{
"extractor": "javascript",
"filemasks": [
- "gui/aiconfig/**.js",
"gui/gamesetup/**.js",
"gui/gamesetup_mp/**.js",
"gui/loading/**.js"
@@ -98,7 +97,6 @@
{
"extractor": "xml",
"filemasks": [
- "gui/aiconfig/**.xml",
"gui/gamesetup/**.xml",
"gui/gamesetup_mp/**.xml",
"gui/loading/**.xml"
Index: source/gui/ObjectBases/IGUIObject.cpp
===================================================================
--- source/gui/ObjectBases/IGUIObject.cpp
+++ source/gui/ObjectBases/IGUIObject.cpp
@@ -418,8 +418,7 @@
JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
JS::RootedValue result(cx);
- if (!JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result))
- JS_ReportError(cx, "Errors executing script event \"%s\"", eventName.c_str());
+ JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
}
void IGUIObject::CreateJSObject()