Index: ps/trunk/binaries/data/mods/public/gui/options/options.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/options/options.js
+++ ps/trunk/binaries/data/mods/public/gui/options/options.js
@@ -4,9 +4,9 @@
var g_Options;
/**
- * Names of session functions to be called after closing the page.
+ * Names of config keys that have changed, value returned when closing the page.
*/
-var g_CloseCallbacks;
+var g_ChangedKeys;
/**
* Vertical size of a tab button.
@@ -165,7 +165,7 @@
function init(data, hotloadData)
{
- g_CloseCallbacks = hotloadData ? hotloadData.closeCallbacks : new Set();
+ g_ChangedKeys = hotloadData ? hotloadData.changedKeys : new Set();
g_TabCategorySelected = hotloadData ? hotloadData.tabCategorySelected : 0;
g_Options = Engine.ReadJSONFile("gui/options/options.json");
@@ -184,7 +184,7 @@
{
return {
"tabCategorySelected": g_TabCategorySelected,
- "closeCallbacks": g_CloseCallbacks
+ "changedKeys": g_ChangedKeys
};
}
@@ -242,12 +242,11 @@
Engine.ConfigDB_CreateValue("user", option.config, String(value));
Engine.ConfigDB_SetChanges("user", true);
+ g_ChangedKeys.add(option.config);
+
if (option.function)
Engine[option.function](value);
- if (option.callback)
- g_CloseCallbacks.add(option.callback);
-
enableButtons();
};
@@ -301,7 +300,10 @@
{
for (let category in g_Options)
for (let option of g_Options[category].options)
+ {
Engine.ConfigDB_RemoveValue("user", option.config);
+ g_ChangedKeys.add(option.config);
+ }
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
revertChanges();
@@ -359,7 +361,7 @@
}
/**
- * Close GUI page and call callbacks if they exist.
+ * Close GUI page and inform the parent GUI page which options changed.
**/
function closePage()
{
@@ -376,5 +378,5 @@
function closePageWithoutConfirmation()
{
- Engine.PopGuiPage(g_CloseCallbacks);
+ Engine.PopGuiPage(g_ChangedKeys);
}
Index: ps/trunk/binaries/data/mods/public/gui/options/options.json
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/options/options.json
+++ ps/trunk/binaries/data/mods/public/gui/options/options.json
@@ -422,7 +422,6 @@
"label": "Batch Training Size",
"tooltip": "Number of units trained per batch by default.",
"config": "gui.session.batchtrainingsize",
- "callback": "updateDefaultBatchSize",
"min": 1,
"max": 20
},
@@ -467,22 +466,19 @@
"type": "boolean",
"label": "Attack Range Visualization",
"tooltip": "Display the attack range of selected defensive structures (can also be toggled in-game with the hotkey).",
- "config": "gui.session.attackrange",
- "callback": "updateEnabledRangeOverlayTypes"
+ "config": "gui.session.attackrange"
},
{
"type": "boolean",
"label": "Aura Range Visualization",
"tooltip": "Display the range of auras of selected units and structures (can also be toggled in-game with the hotkey).",
- "config": "gui.session.aurasrange",
- "callback": "updateEnabledRangeOverlayTypes"
+ "config": "gui.session.aurasrange"
},
{
"type": "boolean",
"label": "Heal Range Visualization",
"tooltip": "Display the healing range of selected units (can also be toggled in-game with the hotkey).",
- "config": "gui.session.healrange",
- "callback": "updateEnabledRangeOverlayTypes"
+ "config": "gui.session.healrange"
},
{
"type": "boolean",
@@ -517,29 +513,25 @@
"type": "color",
"label": "Diplomacy Colors: Self",
"tooltip": "Color of your units when diplomacy colors are enabled.",
- "config": "gui.session.diplomacycolors.self",
- "callback": "updateDisplayedPlayerColors"
+ "config": "gui.session.diplomacycolors.self"
},
{
"type": "color",
"label": "Diplomacy Colors: Ally",
"tooltip": "Color of allies when diplomacy colors are enabled.",
- "config": "gui.session.diplomacycolors.ally",
- "callback": "updateDisplayedPlayerColors"
+ "config": "gui.session.diplomacycolors.ally"
},
{
"type": "color",
"label": "Diplomacy Colors: Neutral",
"tooltip": "Color of neutral players when diplomacy colors are enabled.",
- "config": "gui.session.diplomacycolors.neutral",
- "callback": "updateDisplayedPlayerColors"
+ "config": "gui.session.diplomacycolors.neutral"
},
{
"type": "color",
"label": "Diplomacy Colors: Enemy",
"tooltip": "Color of enemies when diplomacy colors are enabled.",
- "config": "gui.session.diplomacycolors.enemy",
- "callback": "updateDisplayedPlayerColors"
+ "config": "gui.session.diplomacycolors.enemy"
}
]
}
Index: ps/trunk/binaries/data/mods/public/gui/session/DiplomacyColors.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/DiplomacyColors.js
+++ ps/trunk/binaries/data/mods/public/gui/session/DiplomacyColors.js
@@ -16,6 +16,7 @@
this.diplomacyColorsChangeHandlers = [];
registerPlayersInitHandler(this.onPlayersInit.bind(this));
+ registerConfigChangeHandler(this.onConfigChange.bind(this));
}
registerDiplomacyColorsChangeHandler(handler)
@@ -40,6 +41,16 @@
this.updateDisplayedPlayerColors();
}
+ onConfigChange(changes)
+ {
+ for (let change of changes)
+ if (change.startsWith("gui.session.diplomacycolors."))
+ {
+ this.updateDisplayedPlayerColors();
+ return;
+ }
+ }
+
isEnabled()
{
return this.enabled;
Index: ps/trunk/binaries/data/mods/public/gui/session/MenuButtons.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/MenuButtons.js
+++ ps/trunk/binaries/data/mods/public/gui/session/MenuButtons.js
@@ -168,11 +168,8 @@
Engine.PushGuiPage(
"page_options.xml",
{},
- callbackFunctionNames => {
- for (let functionName of callbackFunctionNames)
- if (global[functionName])
- global[functionName]();
-
+ changes => {
+ fireConfigChangeHandlers(changes);
resumeGame();
});
}
Index: ps/trunk/binaries/data/mods/public/gui/session/RangeOverlayManager.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/RangeOverlayManager.js
+++ ps/trunk/binaries/data/mods/public/gui/session/RangeOverlayManager.js
@@ -0,0 +1,80 @@
+/**
+ * This class informs:
+ * - the GuiInterface of which components of entities are to display range overlays and
+ * - the RangeOverlayManager entity component which entities are to display range overlays.
+ */
+class RangeOverlayManager
+{
+ constructor(selection)
+ {
+ this.selection = selection;
+
+ for (let type of this.Types)
+ {
+ this.setEnabled(type, this.isEnabled(type));
+ Engine.SetGlobalHotkey(type.hotkey, this.toggle.bind(this, type));
+ }
+
+ registerConfigChangeHandler(this.onConfigChange.bind(this));
+ }
+
+ onConfigChange(changes)
+ {
+ for (let type of this.Types)
+ if (changes.has(type.config))
+ this.setEnabled(type, this.isEnabled(type));
+ }
+
+ isEnabled(type)
+ {
+ return Engine.ConfigDB_GetValue("user", type.config) == "true";
+ }
+
+ setEnabled(type, enabled)
+ {
+ Engine.GuiInterfaceCall("EnableVisualRangeOverlayType", {
+ "type": type.component,
+ "enabled": enabled
+ });
+
+ let selected = this.selection.toList();
+ for (let ent in this.selection.highlighted)
+ selected.push(this.selection.highlighted[ent]);
+
+ Engine.GuiInterfaceCall("SetRangeOverlays", {
+ "entities": selected,
+ "enabled": enabled
+ });
+ }
+
+ toggle(type)
+ {
+ let enabled = !this.isEnabled(type);
+
+ Engine.ConfigDB_CreateAndWriteValueToFile(
+ "user",
+ type.config,
+ String(enabled),
+ "config/user.cfg");
+
+ this.setEnabled(type, enabled);
+ }
+}
+
+RangeOverlayManager.prototype.Types = [
+ {
+ "component": "Attack",
+ "config": "gui.session.attackrange",
+ "hotkey": "session.toggleattackrange"
+ },
+ {
+ "component": "Auras",
+ "config": "gui.session.aurasrange",
+ "hotkey": "session.toggleaurasrange"
+ },
+ {
+ "component": "Heal",
+ "config": "gui.session.healrange",
+ "hotkey": "session.togglehealrange"
+ }
+];
Index: ps/trunk/binaries/data/mods/public/gui/session/hotkeys/misc.xml
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/hotkeys/misc.xml
+++ ps/trunk/binaries/data/mods/public/gui/session/hotkeys/misc.xml
@@ -65,18 +65,6 @@
clearSelection();
-
-
-
-
-
-