Only allow using path tool when panel is enabled
This commit is contained in:
committed by
Matthias Mailänder
parent
42181d77a5
commit
b2215c6dd1
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<bool> OnSelected;
|
||||
|
||||
readonly List<Widget> toolPanels = [];
|
||||
readonly Dictionary<Widget, string> toolLabels = [];
|
||||
readonly Widget widget;
|
||||
Widget selectedPanel;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MapToolsLogic(Widget widget, World world)
|
||||
{
|
||||
this.widget = widget;
|
||||
var toolDropdownWidget = widget.Get<DropDownButtonWidget>("TOOLS_DROPDOWN");
|
||||
MapEditorTabsLogic.OnTabChanged += SelectedTab;
|
||||
|
||||
var tools = world.WorldActor.TraitsImplementing<IEditorTool>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user