From b2215c6dd1aa86ae83f0874df8f3ad42157e4fe3 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Wed, 23 Jul 2025 20:06:09 +0300 Subject: [PATCH] Only allow using path tool when panel is enabled --- .../Logic/Editor/MapEditorTabsLogic.cs | 6 +++ .../Widgets/Logic/Editor/MapToolsLogic.cs | 21 ++++++++++ .../Logic/Editor/TilingPathToolLogic.cs | 38 ++++++++++++++----- mods/cnc/chrome/editor.yaml | 5 --- mods/cnc/fluent/chrome.ftl | 1 - mods/common/chrome/editor.yaml | 5 --- mods/common/fluent/chrome.ftl | 1 - 7 files changed, 55 insertions(+), 22 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorTabsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorTabsLogic.cs index 1b5fdcec54..6f1464fc51 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorTabsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorTabsLogic.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -27,6 +28,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic MenuType menuType = MenuType.Tiles; MenuType lastSelectedTab = MenuType.Tiles; + public static event Action OnTabChanged; + [ObjectCreator.UseCtor] public MapEditorTabsLogic(Widget widget, World world) { @@ -62,6 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic lastSelectedTab = tabType; menuType = tabType; + OnTabChanged?.Invoke(); // Clear keyboard focus when switching tabs. Ui.KeyboardFocusWidget = null; @@ -89,6 +93,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic menuType = MenuType.Select; else if (menuType == MenuType.Select && !hasSelection) menuType = lastSelectedTab; + + OnTabChanged?.Invoke(); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs index 4946454957..cb7e9d4526 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Traits; @@ -18,14 +19,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class MapToolsLogic : ChromeLogic { + public static event Action OnSelected; + readonly List toolPanels = []; readonly Dictionary toolLabels = []; + readonly Widget widget; Widget selectedPanel; [ObjectCreator.UseCtor] public MapToolsLogic(Widget widget, World world) { + this.widget = widget; var toolDropdownWidget = widget.Get("TOOLS_DROPDOWN"); + MapEditorTabsLogic.OnTabChanged += SelectedTab; + var tools = world.WorldActor.TraitsImplementing(); foreach (var tool in tools) { @@ -44,6 +51,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic toolDropdownWidget.Disabled = true; } + void SelectedTab() + { + OnSelected?.Invoke(widget.IsVisible()); + } + void ShowToolsDropDown(DropDownButtonWidget dropdown) { ScrollItemWidget SetupItem(Widget panel, ScrollItemWidget itemTemplate) @@ -68,6 +80,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic selectedPanel = panel; if (panel != null) selectedPanel.Visible = true; + + OnSelected?.Invoke(widget.IsVisible()); + } + + protected override void Dispose(bool disposing) + { + MapEditorTabsLogic.OnTabChanged -= SelectedTab; + + base.Dispose(disposing); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/TilingPathToolLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/TilingPathToolLogic.cs index dfefaf7158..7eeafbdb47 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/TilingPathToolLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/TilingPathToolLogic.cs @@ -24,6 +24,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic typeof(TilingPathToolInfo))] public sealed class TilingPathToolLogic : ChromeLogic { + readonly Widget widget; + readonly EditorViewportControllerWidget editor; + readonly TilingPathTool tool; + [ObjectCreator.UseCtor] public TilingPathToolLogic( Widget widget, @@ -32,21 +36,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic WorldRenderer worldRenderer, Dictionary logicArgs) { - var tool = world.WorldActor.Trait(); var editorActionManager = world.WorldActor.Trait(); + tool = world.WorldActor.Trait(); + this.widget = widget; + editor = widget.Parent.Parent.Parent.Parent.Get("MAP_EDITOR"); - var editorWidget = widget.Parent.Parent.Parent.Parent.Get("MAP_EDITOR"); + MapToolsLogic.OnSelected += TabSelected; ((ScrollPanelWidget)widget).Layout.AdjustChildren(); - var editCheckbox = widget.Get("EDIT"); - editCheckbox.IsChecked = () => editorWidget.CurrentBrush is EditorTilingPathBrush; - editCheckbox.OnClick = () => - editorWidget.SetBrush( - editCheckbox.IsChecked() - ? null - : new EditorTilingPathBrush(tool)); - void SetupDropDown( DropDownButtonWidget dropDown, ImmutableArray choices, @@ -122,5 +120,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic paintButton.OnClick = () => editorActionManager.Add( new PaintTilingPathEditorAction(tool)); } + + void TabSelected(bool isVisible) + { + if (isVisible && widget.IsVisible()) + { + if (editor.CurrentBrush is not EditorTilingPathBrush) + editor.SetBrush(new EditorTilingPathBrush(tool)); + } + else if (editor.CurrentBrush is EditorTilingPathBrush) + { + editor.ClearBrush(); + } + } + + protected override void Dispose(bool disposing) + { + MapToolsLogic.OnSelected -= TabSelected; + + base.Dispose(disposing); + } } } diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index ec40696bb2..85bafbb569 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -1103,11 +1103,6 @@ ScrollPanel@TILING_PATH_TOOL_PANEL: Visible: false Logic: TilingPathToolLogic Children: - Checkbox@EDIT: - X: 5 - Width: PARENT_WIDTH - 35 - Height: 25 - Text: checkbox-tiling-path-edit Container@START_TYPE: X: 5 Width: PARENT_WIDTH - 35 diff --git a/mods/cnc/fluent/chrome.ftl b/mods/cnc/fluent/chrome.ftl index 39e506cb5f..560cc86f78 100644 --- a/mods/cnc/fluent/chrome.ftl +++ b/mods/cnc/fluent/chrome.ftl @@ -78,7 +78,6 @@ label-marker-mirror-mode = Mirror Mode label-marker-axis-angle = Axis Angle button-map-generator-generate = Generate button-map-generator-generate-random = Generate Random -checkbox-tiling-path-edit = Enable editing label-tiling-path-type-start = Start type label-tiling-path-type-inner = Inner type label-tiling-path-type-end = End type diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index 978be69d06..ce747ce42b 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -1077,11 +1077,6 @@ ScrollPanel@TILING_PATH_TOOL_PANEL: Visible: false Logic: TilingPathToolLogic Children: - Checkbox@EDIT: - X: 5 - Width: PARENT_WIDTH - 35 - Height: 25 - Text: checkbox-tiling-path-edit Container@START_TYPE: X: 5 Width: PARENT_WIDTH - 35 diff --git a/mods/common/fluent/chrome.ftl b/mods/common/fluent/chrome.ftl index 2bec2fd17f..cfd8f871a0 100644 --- a/mods/common/fluent/chrome.ftl +++ b/mods/common/fluent/chrome.ftl @@ -74,7 +74,6 @@ label-marker-mirror-mode = Mirror Mode label-marker-axis-angle = Axis Angle button-map-generator-generate = Generate button-map-generator-generate-random = Generate Random -checkbox-tiling-path-edit = Enable editing label-tiling-path-type-start = Start type label-tiling-path-type-inner = Inner type label-tiling-path-type-end = End type