Create overlays dropdown
This commit is contained in:
@@ -22,32 +22,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
MapCopyFilters copyFilters = MapCopyFilters.All;
|
MapCopyFilters copyFilters = MapCopyFilters.All;
|
||||||
|
|
||||||
|
enum MapOverlays
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Grid = 1,
|
||||||
|
Buildable = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
MapOverlays overlays = MapOverlays.None;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public MapEditorLogic(Widget widget, World world, WorldRenderer worldRenderer)
|
public MapEditorLogic(Widget widget, World world, WorldRenderer worldRenderer)
|
||||||
{
|
{
|
||||||
var editorViewport = widget.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
var editorViewport = widget.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
||||||
|
|
||||||
var gridButton = widget.GetOrNull<ButtonWidget>("GRID_BUTTON");
|
|
||||||
if (gridButton != null)
|
|
||||||
{
|
|
||||||
var terrainGeometryTrait = world.WorldActor.Trait<TerrainGeometryOverlay>();
|
|
||||||
gridButton.OnClick = () => terrainGeometryTrait.Enabled ^= true;
|
|
||||||
gridButton.IsHighlighted = () => terrainGeometryTrait.Enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lockButton = widget.GetOrNull<ButtonWidget>("BUILDABLE_BUTTON");
|
|
||||||
if (lockButton != null)
|
|
||||||
{
|
|
||||||
var buildableTerrainTrait = world.WorldActor.TraitOrDefault<BuildableTerrainOverlay>();
|
|
||||||
if (buildableTerrainTrait != null)
|
|
||||||
{
|
|
||||||
lockButton.OnClick = () => buildableTerrainTrait.Enabled ^= true;
|
|
||||||
lockButton.IsHighlighted = () => buildableTerrainTrait.Enabled;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
lockButton.Disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var copypasteButton = widget.GetOrNull<ButtonWidget>("COPYPASTE_BUTTON");
|
var copypasteButton = widget.GetOrNull<ButtonWidget>("COPYPASTE_BUTTON");
|
||||||
if (copypasteButton != null)
|
if (copypasteButton != null)
|
||||||
{
|
{
|
||||||
@@ -83,6 +71,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var copyOverlayDropdown = widget.Get<DropDownButtonWidget>("OVERLAY_BUTTON");
|
||||||
|
copyOverlayDropdown.OnMouseDown = _ =>
|
||||||
|
{
|
||||||
|
copyOverlayDropdown.RemovePanel();
|
||||||
|
copyOverlayDropdown.AttachPanel(CreateOverlaysPanel(world));
|
||||||
|
};
|
||||||
|
|
||||||
var cashLabel = widget.GetOrNull<LabelWidget>("CASH_LABEL");
|
var cashLabel = widget.GetOrNull<LabelWidget>("CASH_LABEL");
|
||||||
if (cashLabel != null)
|
if (cashLabel != null)
|
||||||
{
|
{
|
||||||
@@ -122,5 +117,50 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
return categoriesPanel;
|
return categoriesPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget CreateOverlaysPanel(World world)
|
||||||
|
{
|
||||||
|
var categoriesPanel = Ui.LoadWidget("OVERLAY_PANEL", null, new WidgetArgs());
|
||||||
|
var categoryTemplate = categoriesPanel.Get<CheckboxWidget>("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<TerrainGeometryOverlay>();
|
||||||
|
category.OnClick = () =>
|
||||||
|
{
|
||||||
|
overlays ^= cat;
|
||||||
|
terrainGeometryTrait.Enabled = overlays.HasFlag(MapOverlays.Grid);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cat.HasFlag(MapOverlays.Buildable))
|
||||||
|
{
|
||||||
|
var buildableTerrainTrait = world.WorldActor.TraitOrDefault<BuildableTerrainOverlay>();
|
||||||
|
if (buildableTerrainTrait != null)
|
||||||
|
{
|
||||||
|
category.OnClick = () =>
|
||||||
|
{
|
||||||
|
overlays ^= cat;
|
||||||
|
buildableTerrainTrait.Enabled = overlays.HasFlag(MapOverlays.Buildable);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
categoriesPanel.AddChild(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return categoriesPanel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -584,19 +584,8 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: History
|
Text: History
|
||||||
Font: Bold
|
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:
|
Button@UNDO_BUTTON:
|
||||||
X: WINDOW_RIGHT - 910
|
X: WINDOW_RIGHT - 800
|
||||||
Y: 5
|
Y: 5
|
||||||
Height: 25
|
Height: 25
|
||||||
Width: 100
|
Width: 100
|
||||||
@@ -607,7 +596,7 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
TooltipText: Undo last step
|
TooltipText: Undo last step
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Button@REDO_BUTTON:
|
Button@REDO_BUTTON:
|
||||||
X: WINDOW_RIGHT - 800
|
X: WINDOW_RIGHT - 690
|
||||||
Y: 5
|
Y: 5
|
||||||
Height: 25
|
Height: 25
|
||||||
Width: 100
|
Width: 100
|
||||||
@@ -617,17 +606,6 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
TooltipTemplate: BUTTON_TOOLTIP
|
TooltipTemplate: BUTTON_TOOLTIP
|
||||||
TooltipText: Redo last step
|
TooltipText: Redo last step
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
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:
|
Button@COPYPASTE_BUTTON:
|
||||||
X: WINDOW_RIGHT - 580
|
X: WINDOW_RIGHT - 580
|
||||||
Y: 5
|
Y: 5
|
||||||
@@ -645,6 +623,13 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Copy Filters
|
Text: Copy Filters
|
||||||
Font: Bold
|
Font: Bold
|
||||||
|
DropDownButton@OVERLAY_BUTTON:
|
||||||
|
X: WINDOW_RIGHT - 950
|
||||||
|
Y: 5
|
||||||
|
Width: 140
|
||||||
|
Height: 25
|
||||||
|
Text: Overlays
|
||||||
|
Font: Bold
|
||||||
Label@COORDINATE_LABEL:
|
Label@COORDINATE_LABEL:
|
||||||
X: 10
|
X: 10
|
||||||
Width: 50
|
Width: 50
|
||||||
@@ -697,3 +682,14 @@ ScrollPanel@COPY_FILTER_PANEL:
|
|||||||
Width: PARENT_RIGHT - 29
|
Width: PARENT_RIGHT - 29
|
||||||
Height: 20
|
Height: 20
|
||||||
Visible: false
|
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
|
||||||
|
|||||||
@@ -580,18 +580,8 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Copy Filters
|
Text: Copy Filters
|
||||||
Font: Bold
|
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:
|
Button@UNDO_BUTTON:
|
||||||
X: 500
|
X: 420
|
||||||
Height: 25
|
Height: 25
|
||||||
Width: 90
|
Width: 90
|
||||||
Text: Undo
|
Text: Undo
|
||||||
@@ -601,7 +591,7 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
TooltipText: Undo last step
|
TooltipText: Undo last step
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Button@REDO_BUTTON:
|
Button@REDO_BUTTON:
|
||||||
X: 600
|
X: 520
|
||||||
Height: 25
|
Height: 25
|
||||||
Width: 90
|
Width: 90
|
||||||
Text: Redo
|
Text: Redo
|
||||||
@@ -610,25 +600,21 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
TooltipTemplate: BUTTON_TOOLTIP
|
TooltipTemplate: BUTTON_TOOLTIP
|
||||||
TooltipText: Redo last step
|
TooltipText: Redo last step
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Button@BUILDABLE_BUTTON:
|
DropDownButton@OVERLAY_BUTTON:
|
||||||
X: 700
|
X: 620
|
||||||
Width: 90
|
Width: 140
|
||||||
Height: 25
|
Height: 25
|
||||||
Text: Buildable
|
Text: Overlays
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: f2
|
|
||||||
TooltipTemplate: BUTTON_TOOLTIP
|
|
||||||
TooltipText: Toggle unbuildable cells
|
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
|
||||||
Label@COORDINATE_LABEL:
|
Label@COORDINATE_LABEL:
|
||||||
X: 835
|
X: 770
|
||||||
Width: 50
|
Width: 50
|
||||||
Height: 25
|
Height: 25
|
||||||
Align: Left
|
Align: Left
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Contrast: true
|
Contrast: true
|
||||||
Label@CASH_LABEL:
|
Label@CASH_LABEL:
|
||||||
X: 950
|
X: 885
|
||||||
Width: 50
|
Width: 50
|
||||||
Height: 25
|
Height: 25
|
||||||
Align: Left
|
Align: Left
|
||||||
@@ -674,3 +660,14 @@ ScrollPanel@COPY_FILTER_PANEL:
|
|||||||
Width: PARENT_RIGHT - 29
|
Width: PARENT_RIGHT - 29
|
||||||
Height: 20
|
Height: 20
|
||||||
Visible: false
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user