Add delete button to the map editor
(cherry picked from commit f820adab51734020600d9758c4b78a1f6585b133)
This commit is contained in:
@@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.EditorBrushes;
|
||||||
using OpenRA.Mods.Common.Graphics;
|
using OpenRA.Mods.Common.Graphics;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -87,6 +89,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return ((long)pixelDistance << 32) + worldZPosition;
|
return ((long)pixelDistance << 32) + worldZPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DeleteSelection(MapBlitFilters filters)
|
||||||
|
{
|
||||||
|
if (Selection.Area != null)
|
||||||
|
editorActionManager.Add(new DeleteAreaAction(world.Map, filters, Selection.Area, resourceLayer, actorLayer));
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearSelection(bool updateSelectedTab = false)
|
public void ClearSelection(bool updateSelectedTab = false)
|
||||||
{
|
{
|
||||||
if (Selection.HasSelection)
|
if (Selection.HasSelection)
|
||||||
@@ -335,6 +343,114 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class DeleteAreaAction : IEditorAction
|
||||||
|
{
|
||||||
|
[FluentReference("x", "y", "width", "height")]
|
||||||
|
const string RemovedArea = "notification-removed-area";
|
||||||
|
|
||||||
|
public string Text { get; }
|
||||||
|
|
||||||
|
readonly EditorBlitSource editorBlitSource;
|
||||||
|
readonly MapBlitFilters blitFilters;
|
||||||
|
readonly IResourceLayer resourceLayer;
|
||||||
|
readonly EditorActorLayer editorActorLayer;
|
||||||
|
readonly CellRegion area;
|
||||||
|
readonly Map map;
|
||||||
|
|
||||||
|
public DeleteAreaAction(Map map, MapBlitFilters blitFilters, CellRegion area, IResourceLayer resourceLayer, EditorActorLayer editorActorLayer)
|
||||||
|
{
|
||||||
|
this.map = map;
|
||||||
|
this.blitFilters = blitFilters;
|
||||||
|
this.resourceLayer = resourceLayer;
|
||||||
|
this.editorActorLayer = editorActorLayer;
|
||||||
|
this.area = area;
|
||||||
|
|
||||||
|
editorBlitSource = EditorBlit.CopyRegionContents(map, editorActorLayer, resourceLayer, area, blitFilters);
|
||||||
|
|
||||||
|
Text = FluentProvider.GetMessage(RemovedArea,
|
||||||
|
"x", area.TopLeft.X,
|
||||||
|
"y", area.TopLeft.Y,
|
||||||
|
"width", area.BottomRight.X - area.TopLeft.X,
|
||||||
|
"height", area.BottomRight.Y - area.TopLeft.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
Do();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Do()
|
||||||
|
{
|
||||||
|
if (blitFilters.HasFlag(MapBlitFilters.Actors))
|
||||||
|
{
|
||||||
|
// Clear any existing actors in the paste cells.
|
||||||
|
foreach (var regionActor in editorActorLayer.PreviewsInCellRegion(area.CellCoords).ToList())
|
||||||
|
editorActorLayer.Remove(regionActor);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var tileKeyValuePair in editorBlitSource.Tiles)
|
||||||
|
{
|
||||||
|
var position = tileKeyValuePair.Key;
|
||||||
|
if (!map.Tiles.Contains(position))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Clear any existing resources.
|
||||||
|
if (resourceLayer != null && blitFilters.HasFlag(MapBlitFilters.Resources))
|
||||||
|
resourceLayer.ClearResources(position);
|
||||||
|
|
||||||
|
if (blitFilters.HasFlag(MapBlitFilters.Terrain))
|
||||||
|
{
|
||||||
|
map.Tiles[position] = map.Rules.TerrainInfo.DefaultTerrainTile;
|
||||||
|
map.Height[position] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Undo()
|
||||||
|
{
|
||||||
|
foreach (var tileKeyValuePair in editorBlitSource.Tiles)
|
||||||
|
{
|
||||||
|
var position = tileKeyValuePair.Key;
|
||||||
|
if (!map.Tiles.Contains(position))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var tile = tileKeyValuePair.Value;
|
||||||
|
var resourceLayerContents = tile.ResourceLayerContents;
|
||||||
|
|
||||||
|
if (blitFilters.HasFlag(MapBlitFilters.Terrain))
|
||||||
|
{
|
||||||
|
map.Tiles[position] = tile.TerrainTile;
|
||||||
|
map.Height[position] = tile.Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blitFilters.HasFlag(MapBlitFilters.Resources) &&
|
||||||
|
resourceLayerContents.HasValue &&
|
||||||
|
!string.IsNullOrWhiteSpace(resourceLayerContents.Value.Type))
|
||||||
|
resourceLayer.AddResource(resourceLayerContents.Value.Type, position, resourceLayerContents.Value.Density);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blitFilters.HasFlag(MapBlitFilters.Actors))
|
||||||
|
{
|
||||||
|
// Create copies of the original actors, update their locations, and place.
|
||||||
|
foreach (var actorKeyValuePair in editorBlitSource.Actors)
|
||||||
|
{
|
||||||
|
var copy = actorKeyValuePair.Value.Export();
|
||||||
|
var locationInit = copy.GetOrDefault<LocationInit>();
|
||||||
|
if (locationInit != null)
|
||||||
|
{
|
||||||
|
if (!map.Tiles.Contains(locationInit.Value))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
copy.RemoveAll<LocationInit>();
|
||||||
|
copy.Add(new LocationInit(locationInit.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
editorActorLayer.Add(copy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sealed class RemoveSelectedActorAction : IEditorAction
|
sealed class RemoveSelectedActorAction : IEditorAction
|
||||||
{
|
{
|
||||||
[FluentReference("name", "id")]
|
[FluentReference("name", "id")]
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public LabelWidget DiagonalLabel;
|
public LabelWidget DiagonalLabel;
|
||||||
public LabelWidget ResourceCounterLabel;
|
public LabelWidget ResourceCounterLabel;
|
||||||
|
|
||||||
MapBlitFilters copyFilters = MapBlitFilters.All;
|
MapBlitFilters selectionFilters = MapBlitFilters.All;
|
||||||
EditorBlitSource? clipboard;
|
EditorBlitSource? clipboard;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
@@ -81,12 +81,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
worldRenderer,
|
worldRenderer,
|
||||||
clipboard.Value,
|
clipboard.Value,
|
||||||
resourceLayer,
|
resourceLayer,
|
||||||
() => copyFilters));
|
() => selectionFilters));
|
||||||
};
|
};
|
||||||
|
|
||||||
pasteButton.IsDisabled = () => clipboard == null;
|
pasteButton.IsDisabled = () => clipboard == null;
|
||||||
pasteButton.IsHighlighted = () => editor.CurrentBrush is EditorCopyPasteBrush;
|
pasteButton.IsHighlighted = () => editor.CurrentBrush is EditorCopyPasteBrush;
|
||||||
|
|
||||||
|
var deleteAreaSelectionButton = areaEditPanel.Get<ButtonWidget>("SELECTION_DELETE_BUTTON");
|
||||||
|
deleteAreaSelectionButton.OnClick = () => editor.DefaultBrush.DeleteSelection(selectionFilters);
|
||||||
|
|
||||||
var closeAreaSelectionButton = areaEditPanel.Get<ButtonWidget>("SELECTION_CANCEL_BUTTON");
|
var closeAreaSelectionButton = areaEditPanel.Get<ButtonWidget>("SELECTION_CANCEL_BUTTON");
|
||||||
closeAreaSelectionButton.OnClick = () => editor.DefaultBrush.ClearSelection(updateSelectedTab: true);
|
closeAreaSelectionButton.OnClick = () => editor.DefaultBrush.ClearSelection(updateSelectedTab: true);
|
||||||
|
|
||||||
@@ -102,15 +105,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
editorActorLayer,
|
editorActorLayer,
|
||||||
resourceLayer,
|
resourceLayer,
|
||||||
editor.DefaultBrush.Selection.Area,
|
editor.DefaultBrush.Selection.Area,
|
||||||
copyFilters);
|
selectionFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateCategoryPanel(MapBlitFilters copyFilter, CheckboxWidget checkbox)
|
void CreateCategoryPanel(MapBlitFilters copyFilter, CheckboxWidget checkbox)
|
||||||
{
|
{
|
||||||
checkbox.GetText = () => copyFilter.ToString();
|
checkbox.GetText = () => copyFilter.ToString();
|
||||||
checkbox.IsChecked = () => copyFilters.HasFlag(copyFilter);
|
checkbox.IsChecked = () => selectionFilters.HasFlag(copyFilter);
|
||||||
checkbox.IsVisible = () => true;
|
checkbox.IsVisible = () => true;
|
||||||
checkbox.OnClick = () => copyFilters ^= copyFilter;
|
checkbox.OnClick = () => selectionFilters ^= copyFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Left
|
Align: Left
|
||||||
Text: label-copy-filters
|
Text: label-selection-filters
|
||||||
Checkbox@COPY_FILTER_TERRAIN_CHECKBOX:
|
Checkbox@COPY_FILTER_TERRAIN_CHECKBOX:
|
||||||
X: 7
|
X: 7
|
||||||
Y: 70
|
Y: 70
|
||||||
@@ -688,6 +688,13 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Width: 55
|
Width: 55
|
||||||
Height: 22
|
Height: 22
|
||||||
Align: Left
|
Align: Left
|
||||||
|
Button@SELECTION_DELETE_BUTTON:
|
||||||
|
X: 7
|
||||||
|
Y: 222
|
||||||
|
Width: 75
|
||||||
|
Height: 25
|
||||||
|
Text: button-delete-area.label
|
||||||
|
Font: Bold
|
||||||
Button@SELECTION_CANCEL_BUTTON:
|
Button@SELECTION_CANCEL_BUTTON:
|
||||||
X: 208
|
X: 208
|
||||||
Y: 222
|
Y: 222
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ label-area-selection = Area Selection
|
|||||||
label-area-info = Area Info
|
label-area-info = Area Info
|
||||||
label-selected-area-diagonal = Diagonal:
|
label-selected-area-diagonal = Diagonal:
|
||||||
label-selected-area-resources = Resources:
|
label-selected-area-resources = Resources:
|
||||||
label-copy-filters = Copy Filters
|
label-selection-filters = Filters
|
||||||
label-filter-terrain = Terrain
|
label-filter-terrain = Terrain
|
||||||
label-filter-resources = Resources
|
label-filter-resources = Resources
|
||||||
label-filter-actors = Actors
|
label-filter-actors = Actors
|
||||||
@@ -85,6 +85,9 @@ button-map-editor-tab-container-actors-tooltip = Actors
|
|||||||
button-map-editor-tab-container-tools-tooltip = Tools
|
button-map-editor-tab-container-tools-tooltip = Tools
|
||||||
button-map-editor-tab-container-history-tooltip = History
|
button-map-editor-tab-container-history-tooltip = History
|
||||||
|
|
||||||
|
button-delete-area =
|
||||||
|
.label = Delete
|
||||||
|
|
||||||
button-editor-world-root-copy =
|
button-editor-world-root-copy =
|
||||||
.label = Copy
|
.label = Copy
|
||||||
.tooltip = Copy the selected area
|
.tooltip = Copy the selected area
|
||||||
|
|||||||
@@ -600,7 +600,7 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Left
|
Align: Left
|
||||||
Text: label-copy-filters
|
Text: label-selection-filters
|
||||||
Checkbox@COPY_FILTER_TERRAIN_CHECKBOX:
|
Checkbox@COPY_FILTER_TERRAIN_CHECKBOX:
|
||||||
X: 5
|
X: 5
|
||||||
Y: 70
|
Y: 70
|
||||||
@@ -654,6 +654,13 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Width: 55
|
Width: 55
|
||||||
Height: 22
|
Height: 22
|
||||||
Align: Left
|
Align: Left
|
||||||
|
Button@SELECTION_DELETE_BUTTON:
|
||||||
|
X: 5
|
||||||
|
Y: 222
|
||||||
|
Width: 75
|
||||||
|
Height: 25
|
||||||
|
Text: button-delete-area.label
|
||||||
|
Font: Bold
|
||||||
Button@SELECTION_CANCEL_BUTTON:
|
Button@SELECTION_CANCEL_BUTTON:
|
||||||
X: 208
|
X: 208
|
||||||
Y: 222
|
Y: 222
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ label-area-selection = Area Selection
|
|||||||
label-area-info = Area Info
|
label-area-info = Area Info
|
||||||
label-selected-area-diagonal = Diagonal:
|
label-selected-area-diagonal = Diagonal:
|
||||||
label-selected-area-resources = Resources:
|
label-selected-area-resources = Resources:
|
||||||
label-copy-filters = Copy Filters
|
label-selection-filters = Filters
|
||||||
label-filter-terrain = Terrain
|
label-filter-terrain = Terrain
|
||||||
label-filter-resources = Resources
|
label-filter-resources = Resources
|
||||||
label-filter-actors = Actors
|
label-filter-actors = Actors
|
||||||
@@ -81,6 +81,9 @@ button-map-editor-tab-container-actors-tooltip = Actors
|
|||||||
button-map-editor-tab-container-tools-tooltip = Tools
|
button-map-editor-tab-container-tools-tooltip = Tools
|
||||||
button-map-editor-tab-container-history-tooltip = History
|
button-map-editor-tab-container-history-tooltip = History
|
||||||
|
|
||||||
|
button-delete-area =
|
||||||
|
.label = Delete
|
||||||
|
|
||||||
button-editor-world-root-options =
|
button-editor-world-root-options =
|
||||||
.label = Menu
|
.label = Menu
|
||||||
.tooltip = Menu
|
.tooltip = Menu
|
||||||
|
|||||||
@@ -804,6 +804,7 @@ notification-copied-tiles =
|
|||||||
|
|
||||||
## EditorDefaultBrush
|
## EditorDefaultBrush
|
||||||
notification-selected-area = Selected area { $x },{ $y } ({ $width },{ $height })
|
notification-selected-area = Selected area { $x },{ $y } ({ $width },{ $height })
|
||||||
|
notification-removed-area = Removed area { $x },{ $y } ({ $width },{ $height })
|
||||||
notification-selected-actor = Selected actor { $id }
|
notification-selected-actor = Selected actor { $id }
|
||||||
notification-cleared-selection = Cleared selection
|
notification-cleared-selection = Cleared selection
|
||||||
notification-removed-actor = Removed { $name } ({ $id })
|
notification-removed-actor = Removed { $name } ({ $id })
|
||||||
|
|||||||
Reference in New Issue
Block a user