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
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -27,6 +28,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
MenuType menuType = MenuType.Tiles;
|
MenuType menuType = MenuType.Tiles;
|
||||||
MenuType lastSelectedTab = MenuType.Tiles;
|
MenuType lastSelectedTab = MenuType.Tiles;
|
||||||
|
|
||||||
|
public static event Action OnTabChanged;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public MapEditorTabsLogic(Widget widget, World world)
|
public MapEditorTabsLogic(Widget widget, World world)
|
||||||
{
|
{
|
||||||
@@ -62,6 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
lastSelectedTab = tabType;
|
lastSelectedTab = tabType;
|
||||||
|
|
||||||
menuType = tabType;
|
menuType = tabType;
|
||||||
|
OnTabChanged?.Invoke();
|
||||||
|
|
||||||
// Clear keyboard focus when switching tabs.
|
// Clear keyboard focus when switching tabs.
|
||||||
Ui.KeyboardFocusWidget = null;
|
Ui.KeyboardFocusWidget = null;
|
||||||
@@ -89,6 +93,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
menuType = MenuType.Select;
|
menuType = MenuType.Select;
|
||||||
else if (menuType == MenuType.Select && !hasSelection)
|
else if (menuType == MenuType.Select && !hasSelection)
|
||||||
menuType = lastSelectedTab;
|
menuType = lastSelectedTab;
|
||||||
|
|
||||||
|
OnTabChanged?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
@@ -18,14 +19,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
public class MapToolsLogic : ChromeLogic
|
public class MapToolsLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
|
public static event Action<bool> OnSelected;
|
||||||
|
|
||||||
readonly List<Widget> toolPanels = [];
|
readonly List<Widget> toolPanels = [];
|
||||||
readonly Dictionary<Widget, string> toolLabels = [];
|
readonly Dictionary<Widget, string> toolLabels = [];
|
||||||
|
readonly Widget widget;
|
||||||
Widget selectedPanel;
|
Widget selectedPanel;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public MapToolsLogic(Widget widget, World world)
|
public MapToolsLogic(Widget widget, World world)
|
||||||
{
|
{
|
||||||
|
this.widget = widget;
|
||||||
var toolDropdownWidget = widget.Get<DropDownButtonWidget>("TOOLS_DROPDOWN");
|
var toolDropdownWidget = widget.Get<DropDownButtonWidget>("TOOLS_DROPDOWN");
|
||||||
|
MapEditorTabsLogic.OnTabChanged += SelectedTab;
|
||||||
|
|
||||||
var tools = world.WorldActor.TraitsImplementing<IEditorTool>();
|
var tools = world.WorldActor.TraitsImplementing<IEditorTool>();
|
||||||
foreach (var tool in tools)
|
foreach (var tool in tools)
|
||||||
{
|
{
|
||||||
@@ -44,6 +51,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
toolDropdownWidget.Disabled = true;
|
toolDropdownWidget.Disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SelectedTab()
|
||||||
|
{
|
||||||
|
OnSelected?.Invoke(widget.IsVisible());
|
||||||
|
}
|
||||||
|
|
||||||
void ShowToolsDropDown(DropDownButtonWidget dropdown)
|
void ShowToolsDropDown(DropDownButtonWidget dropdown)
|
||||||
{
|
{
|
||||||
ScrollItemWidget SetupItem(Widget panel, ScrollItemWidget itemTemplate)
|
ScrollItemWidget SetupItem(Widget panel, ScrollItemWidget itemTemplate)
|
||||||
@@ -68,6 +80,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
selectedPanel = panel;
|
selectedPanel = panel;
|
||||||
if (panel != null)
|
if (panel != null)
|
||||||
selectedPanel.Visible = true;
|
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))]
|
typeof(TilingPathToolInfo))]
|
||||||
public sealed class TilingPathToolLogic : ChromeLogic
|
public sealed class TilingPathToolLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
|
readonly Widget widget;
|
||||||
|
readonly EditorViewportControllerWidget editor;
|
||||||
|
readonly TilingPathTool tool;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public TilingPathToolLogic(
|
public TilingPathToolLogic(
|
||||||
Widget widget,
|
Widget widget,
|
||||||
@@ -32,21 +36,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
WorldRenderer worldRenderer,
|
WorldRenderer worldRenderer,
|
||||||
Dictionary<string, MiniYaml> logicArgs)
|
Dictionary<string, MiniYaml> logicArgs)
|
||||||
{
|
{
|
||||||
var tool = world.WorldActor.Trait<TilingPathTool>();
|
|
||||||
var editorActionManager = world.WorldActor.Trait<EditorActionManager>();
|
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();
|
((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(
|
void SetupDropDown(
|
||||||
DropDownButtonWidget dropDown,
|
DropDownButtonWidget dropDown,
|
||||||
ImmutableArray<string> choices,
|
ImmutableArray<string> choices,
|
||||||
@@ -122,5 +120,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
paintButton.OnClick = () => editorActionManager.Add(
|
paintButton.OnClick = () => editorActionManager.Add(
|
||||||
new PaintTilingPathEditorAction(tool));
|
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
|
Visible: false
|
||||||
Logic: TilingPathToolLogic
|
Logic: TilingPathToolLogic
|
||||||
Children:
|
Children:
|
||||||
Checkbox@EDIT:
|
|
||||||
X: 5
|
|
||||||
Width: PARENT_WIDTH - 35
|
|
||||||
Height: 25
|
|
||||||
Text: checkbox-tiling-path-edit
|
|
||||||
Container@START_TYPE:
|
Container@START_TYPE:
|
||||||
X: 5
|
X: 5
|
||||||
Width: PARENT_WIDTH - 35
|
Width: PARENT_WIDTH - 35
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ label-marker-mirror-mode = Mirror Mode
|
|||||||
label-marker-axis-angle = Axis Angle
|
label-marker-axis-angle = Axis Angle
|
||||||
button-map-generator-generate = Generate
|
button-map-generator-generate = Generate
|
||||||
button-map-generator-generate-random = Generate Random
|
button-map-generator-generate-random = Generate Random
|
||||||
checkbox-tiling-path-edit = Enable editing
|
|
||||||
label-tiling-path-type-start = Start type
|
label-tiling-path-type-start = Start type
|
||||||
label-tiling-path-type-inner = Inner type
|
label-tiling-path-type-inner = Inner type
|
||||||
label-tiling-path-type-end = End type
|
label-tiling-path-type-end = End type
|
||||||
|
|||||||
@@ -1077,11 +1077,6 @@ ScrollPanel@TILING_PATH_TOOL_PANEL:
|
|||||||
Visible: false
|
Visible: false
|
||||||
Logic: TilingPathToolLogic
|
Logic: TilingPathToolLogic
|
||||||
Children:
|
Children:
|
||||||
Checkbox@EDIT:
|
|
||||||
X: 5
|
|
||||||
Width: PARENT_WIDTH - 35
|
|
||||||
Height: 25
|
|
||||||
Text: checkbox-tiling-path-edit
|
|
||||||
Container@START_TYPE:
|
Container@START_TYPE:
|
||||||
X: 5
|
X: 5
|
||||||
Width: PARENT_WIDTH - 35
|
Width: PARENT_WIDTH - 35
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ label-marker-mirror-mode = Mirror Mode
|
|||||||
label-marker-axis-angle = Axis Angle
|
label-marker-axis-angle = Axis Angle
|
||||||
button-map-generator-generate = Generate
|
button-map-generator-generate = Generate
|
||||||
button-map-generator-generate-random = Generate Random
|
button-map-generator-generate-random = Generate Random
|
||||||
checkbox-tiling-path-edit = Enable editing
|
|
||||||
label-tiling-path-type-start = Start type
|
label-tiling-path-type-start = Start type
|
||||||
label-tiling-path-type-inner = Inner type
|
label-tiling-path-type-inner = Inner type
|
||||||
label-tiling-path-type-end = End type
|
label-tiling-path-type-end = End type
|
||||||
|
|||||||
Reference in New Issue
Block a user