From 04b456d6c21c9b5cbb7e645c713d0222824bbe34 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+Punsho@users.noreply.github.com> Date: Sun, 23 Jan 2022 12:39:05 +0200 Subject: [PATCH] Create overlays dropdown --- .../Widgets/Logic/Editor/MapEditorLogic.cs | 82 ++++++++++++++----- mods/cnc/chrome/editor.yaml | 44 +++++----- mods/common/chrome/editor.yaml | 41 +++++----- 3 files changed, 100 insertions(+), 67 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs index 50e042a642..c76986bf09 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs @@ -22,32 +22,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic { MapCopyFilters copyFilters = MapCopyFilters.All; + enum MapOverlays + { + None = 0, + Grid = 1, + Buildable = 2, + } + + MapOverlays overlays = MapOverlays.None; + [ObjectCreator.UseCtor] public MapEditorLogic(Widget widget, World world, WorldRenderer worldRenderer) { var editorViewport = widget.Get("MAP_EDITOR"); - var gridButton = widget.GetOrNull("GRID_BUTTON"); - if (gridButton != null) - { - var terrainGeometryTrait = world.WorldActor.Trait(); - gridButton.OnClick = () => terrainGeometryTrait.Enabled ^= true; - gridButton.IsHighlighted = () => terrainGeometryTrait.Enabled; - } - - var lockButton = widget.GetOrNull("BUILDABLE_BUTTON"); - if (lockButton != null) - { - var buildableTerrainTrait = world.WorldActor.TraitOrDefault(); - if (buildableTerrainTrait != null) - { - lockButton.OnClick = () => buildableTerrainTrait.Enabled ^= true; - lockButton.IsHighlighted = () => buildableTerrainTrait.Enabled; - } - else - lockButton.Disabled = true; - } - var copypasteButton = widget.GetOrNull("COPYPASTE_BUTTON"); if (copypasteButton != null) { @@ -83,6 +71,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; } + var copyOverlayDropdown = widget.Get("OVERLAY_BUTTON"); + copyOverlayDropdown.OnMouseDown = _ => + { + copyOverlayDropdown.RemovePanel(); + copyOverlayDropdown.AttachPanel(CreateOverlaysPanel(world)); + }; + var cashLabel = widget.GetOrNull("CASH_LABEL"); if (cashLabel != null) { @@ -122,5 +117,50 @@ namespace OpenRA.Mods.Common.Widgets.Logic return categoriesPanel; } + + Widget CreateOverlaysPanel(World world) + { + var categoriesPanel = Ui.LoadWidget("OVERLAY_PANEL", null, new WidgetArgs()); + var categoryTemplate = categoriesPanel.Get("CATEGORY_TEMPLATE"); + + MapOverlays[] allCategories = { MapOverlays.Grid, MapOverlays.Buildable }; + foreach (var cat in allCategories) + { + var category = (CheckboxWidget)categoryTemplate.Clone(); + category.GetText = () => cat.ToString(); + category.IsChecked = () => overlays.HasFlag(cat); + category.IsVisible = () => true; + category.OnClick = () => overlays ^= cat; + + if (cat.HasFlag(MapOverlays.Grid)) + { + var terrainGeometryTrait = world.WorldActor.Trait(); + category.OnClick = () => + { + overlays ^= cat; + terrainGeometryTrait.Enabled = overlays.HasFlag(MapOverlays.Grid); + }; + } + + if (cat.HasFlag(MapOverlays.Buildable)) + { + var buildableTerrainTrait = world.WorldActor.TraitOrDefault(); + if (buildableTerrainTrait != null) + { + category.OnClick = () => + { + overlays ^= cat; + buildableTerrainTrait.Enabled = overlays.HasFlag(MapOverlays.Buildable); + }; + } + else + continue; + } + + categoriesPanel.AddChild(category); + } + + return categoriesPanel; + } } } diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 38db0c2655..6eb9e54298 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -584,19 +584,8 @@ Container@EDITOR_WORLD_ROOT: Height: 25 Text: History Font: Bold - Button@BUILDABLE_BUTTON: - X: WINDOW_RIGHT - 1020 - Y: 5 - Width: 100 - Height: 25 - Text: Buildable - Font: Bold - Key: f2 - TooltipTemplate: BUTTON_TOOLTIP - TooltipText: Toggle unbuildable cells - TooltipContainer: TOOLTIP_CONTAINER Button@UNDO_BUTTON: - X: WINDOW_RIGHT - 910 + X: WINDOW_RIGHT - 800 Y: 5 Height: 25 Width: 100 @@ -607,7 +596,7 @@ Container@EDITOR_WORLD_ROOT: TooltipText: Undo last step TooltipContainer: TOOLTIP_CONTAINER Button@REDO_BUTTON: - X: WINDOW_RIGHT - 800 + X: WINDOW_RIGHT - 690 Y: 5 Height: 25 Width: 100 @@ -617,17 +606,6 @@ Container@EDITOR_WORLD_ROOT: TooltipTemplate: BUTTON_TOOLTIP TooltipText: Redo last step TooltipContainer: TOOLTIP_CONTAINER - Button@GRID_BUTTON: - X: WINDOW_RIGHT - 690 - Y: 5 - Width: 100 - Height: 25 - Text: Grid - Font: Bold - Key: f1 - TooltipTemplate: BUTTON_TOOLTIP - TooltipText: Toggle the terrain grid - TooltipContainer: TOOLTIP_CONTAINER Button@COPYPASTE_BUTTON: X: WINDOW_RIGHT - 580 Y: 5 @@ -645,6 +623,13 @@ Container@EDITOR_WORLD_ROOT: Height: 25 Text: Copy Filters Font: Bold + DropDownButton@OVERLAY_BUTTON: + X: WINDOW_RIGHT - 950 + Y: 5 + Width: 140 + Height: 25 + Text: Overlays + Font: Bold Label@COORDINATE_LABEL: X: 10 Width: 50 @@ -697,3 +682,14 @@ ScrollPanel@COPY_FILTER_PANEL: Width: PARENT_RIGHT - 29 Height: 20 Visible: false + +ScrollPanel@OVERLAY_PANEL: + Width: 140 + Height: 45 + Children: + Checkbox@CATEGORY_TEMPLATE: + X: 5 + Y: 5 + Width: PARENT_RIGHT - 29 + Height: 20 + Visible: false diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index 516094b452..9efc11aa2c 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -580,18 +580,8 @@ Container@EDITOR_WORLD_ROOT: Height: 25 Text: Copy Filters Font: Bold - Button@GRID_BUTTON: - X: 420 - Width: 70 - Height: 25 - Text: Grid - TooltipTemplate: BUTTON_TOOLTIP - TooltipText: Toggle the terrain grid - TooltipContainer: TOOLTIP_CONTAINER - Font: Bold - Key: f1 Button@UNDO_BUTTON: - X: 500 + X: 420 Height: 25 Width: 90 Text: Undo @@ -601,7 +591,7 @@ Container@EDITOR_WORLD_ROOT: TooltipText: Undo last step TooltipContainer: TOOLTIP_CONTAINER Button@REDO_BUTTON: - X: 600 + X: 520 Height: 25 Width: 90 Text: Redo @@ -610,25 +600,21 @@ Container@EDITOR_WORLD_ROOT: TooltipTemplate: BUTTON_TOOLTIP TooltipText: Redo last step TooltipContainer: TOOLTIP_CONTAINER - Button@BUILDABLE_BUTTON: - X: 700 - Width: 90 + DropDownButton@OVERLAY_BUTTON: + X: 620 + Width: 140 Height: 25 - Text: Buildable + Text: Overlays Font: Bold - Key: f2 - TooltipTemplate: BUTTON_TOOLTIP - TooltipText: Toggle unbuildable cells - TooltipContainer: TOOLTIP_CONTAINER Label@COORDINATE_LABEL: - X: 835 + X: 770 Width: 50 Height: 25 Align: Left Font: Bold Contrast: true Label@CASH_LABEL: - X: 950 + X: 885 Width: 50 Height: 25 Align: Left @@ -674,3 +660,14 @@ ScrollPanel@COPY_FILTER_PANEL: Width: PARENT_RIGHT - 29 Height: 20 Visible: false + +ScrollPanel@OVERLAY_PANEL: + Width: 140 + Height: 45 + Children: + Checkbox@CATEGORY_TEMPLATE: + X: 5 + Y: 5 + Width: PARENT_RIGHT - 29 + Height: 20 + Visible: false