Only allow using path tool when panel is enabled

This commit is contained in:
Gustas
2025-07-23 20:06:09 +03:00
committed by Matthias Mailänder
parent 42181d77a5
commit b2215c6dd1
7 changed files with 55 additions and 22 deletions

View File

@@ -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<string, MiniYaml> logicArgs)
{
var tool = world.WorldActor.Trait<TilingPathTool>();
var editorActionManager = world.WorldActor.Trait<EditorActionManager>();
tool = world.WorldActor.Trait<TilingPathTool>();
this.widget = widget;
editor = widget.Parent.Parent.Parent.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
var editorWidget = widget.Parent.Parent.Parent.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
MapToolsLogic.OnSelected += TabSelected;
((ScrollPanelWidget)widget).Layout.AdjustChildren();
var editCheckbox = widget.Get<CheckboxWidget>("EDIT");
editCheckbox.IsChecked = () => editorWidget.CurrentBrush is EditorTilingPathBrush;
editCheckbox.OnClick = () =>
editorWidget.SetBrush(
editCheckbox.IsChecked()
? null
: new EditorTilingPathBrush(tool));
void SetupDropDown(
DropDownButtonWidget dropDown,
ImmutableArray<string> 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);
}
}
}