From e10202d64dc196aa42ed554c08f307c4ac956a18 Mon Sep 17 00:00:00 2001 From: wraitii Date: Tue, 19 Jan 2021 16:14:07 +0000 Subject: [PATCH] Tweaks to the 'auto formation' feature. - Add an option to control the 'null formation' override, so it can be turned off/on independently of having a default formation set. It defaults to "Walk/Patrol only". - Make only 'walk' and 'patrol' orders use the default formation. This makes the system more flexible, and easier to use for competitive play. Differential Revision: https://code.wildfiregames.com/D3413 This was SVN commit r24703. --- binaries/data/config/default.cfg | 2 ++ .../data/mods/public/gui/options/options.json | 18 ++++++++++++++++++ .../mods/public/gui/session/AutoFormation.js | 15 +++++++++++++-- .../mods/public/gui/session/unit_actions.js | 8 ++++---- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 8b65804233..6566c4d022 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -315,6 +315,7 @@ deselectgroup = Ctrl ; Modifier to deselect units when clicking group ic rotate.cw = RightBracket ; Rotate building placement preview clockwise rotate.ccw = LeftBracket ; Rotate building placement preview anticlockwise snaptoedges = Ctrl ; Modifier to align new structures with nearby existing structure +toggledefaultformation = "" ; Switch between null default formation and the last default formation used (defaults to "box") ; Overlays showstatusbars = Tab ; Toggle display of status bars devcommands.toggle = "Alt+D" ; Toggle developer commands panel @@ -392,6 +393,7 @@ snaptoedges = "disabled" ; Possible values: disabled, enabled. snaptoedgesdistancethreshold = 15 ; On which distance we don't snap to edges disjointcontrolgroups = "true" ; Whether control groups are disjoint sets or entities can be in multiple control groups at the same time. defaultformation = "special/formations/box" ; For walking orders, automatically put units into this formation if they don't have one already. +formationwalkonly = "true" ; Formations are disabled when giving gather/attack/... orders. [gui.session.minimap] blinkduration = 1.7 ; The blink duration while pinging diff --git a/binaries/data/mods/public/gui/options/options.json b/binaries/data/mods/public/gui/options/options.json index 3de03caedc..b741c3939b 100644 --- a/binaries/data/mods/public/gui/options/options.json +++ b/binaries/data/mods/public/gui/options/options.json @@ -586,6 +586,24 @@ "tooltip": "Units and Structures can be part of multiple control groups. This is useful to keep control groups for distinct armies and a control group for the entire army simultaneously." } ] + }, + { + "type": "dropdown", + "label": "Formation control", + "tooltip": "Decide whether formations are enabled for all orders or only 'Walk' and 'Patrol'.", + "config": "gui.session.formationwalkonly", + "list": [ + { + "value": "true", + "label": "Walk/Patrol Only", + "tooltip": "Other orders will disband existing formations." + }, + { + "value": "false", + "label": "No Override", + "tooltip": "Units in formations stay in formations." + } + ] } ] } diff --git a/binaries/data/mods/public/gui/session/AutoFormation.js b/binaries/data/mods/public/gui/session/AutoFormation.js index babfff0202..b3a2420149 100644 --- a/binaries/data/mods/public/gui/session/AutoFormation.js +++ b/binaries/data/mods/public/gui/session/AutoFormation.js @@ -18,6 +18,14 @@ class AutoFormation this.defaultFormation = Engine.ConfigDB_GetValue("user", "gui.session.defaultformation"); if (!this.defaultFormation) this.setDefault(NULL_FORMATION); + this.lastDefault = this.defaultFormation === NULL_FORMATION ? + "special/formations/box" : this.defaultFormation; + Engine.SetGlobalHotkey("session.toggledefaultformation", "Press", () => { + if (this.defaultFormation === NULL_FORMATION) + this.setDefault(this.lastDefault); + else + this.setDefault(NULL_FORMATION); + }); } /** @@ -28,6 +36,8 @@ class AutoFormation setDefault(formation) { this.defaultFormation = formation; + if (formation !== NULL_FORMATION) + this.lastDefault = this.defaultFormation; Engine.ConfigDB_CreateValue("user", "gui.session.defaultformation", this.defaultFormation); // TODO: It's extremely terrible that we have to explicitly flush the config... Engine.ConfigDB_SetChanges("user", true); @@ -50,10 +60,11 @@ class AutoFormation } /** - * @return the null formation, or "undefined" if the null formation is the default. + * @return the null formation, or "undefined", depending on "walkOnly" preference. */ getNull() { - return this.defaultFormation == NULL_FORMATION ? undefined : NULL_FORMATION; + let walkOnly = Engine.ConfigDB_GetValue("user", "gui.session.formationwalkonly") === "true"; + return walkOnly ? NULL_FORMATION : undefined; } } diff --git a/binaries/data/mods/public/gui/session/unit_actions.js b/binaries/data/mods/public/gui/session/unit_actions.js index 3087c0aed4..f1eae8b74a 100644 --- a/binaries/data/mods/public/gui/session/unit_actions.js +++ b/binaries/data/mods/public/gui/session/unit_actions.js @@ -104,7 +104,7 @@ var g_UnitActions = "z": target.z, "targetClasses": targetClasses, "queued": queued, - "formation": g_AutoFormation.getDefault() + "formation": g_AutoFormation.getNull() }); DrawTargetMarker(target); @@ -149,7 +149,7 @@ var g_UnitActions = "target": action.target, "allowCapture": true, "queued": queued, - "formation": g_AutoFormation.getDefault() + "formation": g_AutoFormation.getNull() }); Engine.GuiInterfaceCall("PlaySound", { @@ -195,7 +195,7 @@ var g_UnitActions = "target": action.target, "queued": queued, "allowCapture": false, - "formation": g_AutoFormation.getDefault() + "formation": g_AutoFormation.getNull() }); Engine.GuiInterfaceCall("PlaySound", { @@ -758,7 +758,7 @@ var g_UnitActions = "entities": selection, "target": action.target, "queued": queued, - "formation": g_AutoFormation.getDefault() + "formation": g_AutoFormation.getNull() }); Engine.GuiInterfaceCall("PlaySound", {