Polish map editor code
This commit is contained in:
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
readonly EditorActorLayer editorLayer;
|
||||
readonly EditorActionManager editorActionManager;
|
||||
readonly IResourceLayer resourceLayer;
|
||||
readonly EditorCursorLayer cursorLayer;
|
||||
readonly EditorActorLayer actorLayer;
|
||||
|
||||
public CellRegion CurrentDragBounds => selectionBounds ?? Selection.Area;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
editorLayer = world.WorldActor.Trait<EditorActorLayer>();
|
||||
editorActionManager = world.WorldActor.Trait<EditorActionManager>();
|
||||
resourceLayer = world.WorldActor.TraitOrDefault<IResourceLayer>();
|
||||
cursorLayer = world.WorldActor.Trait<EditorCursorLayer>();
|
||||
actorLayer = world.WorldActor.Trait<EditorActorLayer>();
|
||||
}
|
||||
|
||||
long CalculateActorSelectionPriority(EditorActorPreview actor)
|
||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var cellViewPx = worldRenderer.Viewport.WorldToViewPx(worldRenderer.ScreenPosition(world.Map.CenterOfCell(cell)));
|
||||
var pixelOffset = cellViewPx - mi.Location;
|
||||
var cellOffset = underCursor.Location - cell;
|
||||
moveAction = new MoveActorAction(underCursor, cursorLayer, worldRenderer, pixelOffset, cellOffset);
|
||||
moveAction = new MoveActorAction(underCursor, actorLayer, worldRenderer, pixelOffset, cellOffset);
|
||||
draggingActor = true;
|
||||
return false;
|
||||
}
|
||||
@@ -408,7 +408,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public string Text { get; private set; }
|
||||
|
||||
readonly EditorActorPreview actor;
|
||||
readonly EditorCursorLayer layer;
|
||||
readonly EditorActorLayer layer;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly int2 pixelOffset;
|
||||
readonly CVec cellOffset;
|
||||
@@ -418,7 +418,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
public MoveActorAction(
|
||||
EditorActorPreview actor,
|
||||
EditorCursorLayer layer,
|
||||
EditorActorLayer layer,
|
||||
WorldRenderer worldRenderer,
|
||||
int2 pixelOffset,
|
||||
CVec cellOffset)
|
||||
|
||||
@@ -39,8 +39,6 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
markerLayerOverlay = world.WorldActor.Trait<MarkerLayerOverlay>();
|
||||
|
||||
Template = id;
|
||||
worldRenderer = wr;
|
||||
world = wr.World;
|
||||
action = new PaintMarkerTileEditorAction(Template, markerLayerOverlay);
|
||||
}
|
||||
|
||||
@@ -60,11 +58,9 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
|
||||
|
||||
if (mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Up)
|
||||
{
|
||||
action.Add(cell);
|
||||
action.Add(worldRenderer.Viewport.ViewToWorld(mi.Location));
|
||||
painting = true;
|
||||
}
|
||||
else if (painting && mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up)
|
||||
|
||||
@@ -45,8 +45,6 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
editorCursor = world.WorldActor.Trait<EditorCursorLayer>();
|
||||
|
||||
Template = id;
|
||||
worldRenderer = wr;
|
||||
world = wr.World;
|
||||
|
||||
var template = terrainInfo.Templates.First(t => t.Value.Id == id).Value;
|
||||
cursorToken = editorCursor.SetTerrainTemplate(wr, template);
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Required for the map editor to work. Attach this to the world actor.")]
|
||||
public class EditorActorLayerInfo : TraitInfo, ICreatePlayersInfo
|
||||
{
|
||||
[Desc("Size of partition bins (world pixels)")]
|
||||
[Desc("Size of partition bins (world pixels).")]
|
||||
public readonly int BinSize = 250;
|
||||
|
||||
void ICreatePlayersInfo.CreateServerPlayers(MapPreview map, Session lobbyInfo, List<GameInformation.Player> players, MersenneTwister playerRandom)
|
||||
{
|
||||
throw new NotImplementedException("EditorActorLayer must not be defined on the world actor");
|
||||
throw new NotImplementedException("EditorActorLayer must not be defined on the world actor.");
|
||||
}
|
||||
|
||||
public override object Create(ActorInitializer init) { return new EditorActorLayer(this); }
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class EditorActorLayer : IWorldLoaded, ITickRender, IRender, IRadarSignature, ICreatePlayers, IRenderAnnotations
|
||||
{
|
||||
readonly EditorActorLayerInfo info;
|
||||
public readonly EditorActorLayerInfo Info;
|
||||
readonly List<EditorActorPreview> previews = new();
|
||||
|
||||
int2 cellOffset;
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public EditorActorLayer(EditorActorLayerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
void ICreatePlayers.CreatePlayers(World w, MersenneTwister playerRandom)
|
||||
@@ -79,12 +79,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var cellOffsetMax = new int2(world.Map.AllCells.Max(c => c.X), world.Map.AllCells.Max((c) => c.Y));
|
||||
var mapCellSize = cellOffsetMax - cellOffset;
|
||||
cellMap = new SpatiallyPartitioned<EditorActorPreview>(
|
||||
mapCellSize.X, mapCellSize.Y, Exts.IntegerDivisionRoundingAwayFromZero(info.BinSize, world.Map.Grid.TileSize.Width));
|
||||
mapCellSize.X, mapCellSize.Y, Exts.IntegerDivisionRoundingAwayFromZero(Info.BinSize, world.Map.Grid.TileSize.Width));
|
||||
|
||||
var ts = world.Map.Grid.TileSize;
|
||||
var width = world.Map.MapSize.X * ts.Width;
|
||||
var height = world.Map.MapSize.Y * ts.Height;
|
||||
screenMap = new SpatiallyPartitioned<EditorActorPreview>(width, height, info.BinSize);
|
||||
screenMap = new SpatiallyPartitioned<EditorActorPreview>(width, height, Info.BinSize);
|
||||
|
||||
foreach (var kv in world.Map.ActorDefinitions)
|
||||
Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.ToDictionary()), true);
|
||||
@@ -191,6 +191,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
SyncMultiplayerCount();
|
||||
}
|
||||
|
||||
public void MoveActor(EditorActorPreview preview, CPos location)
|
||||
{
|
||||
Remove(preview);
|
||||
preview.ReplaceInit(new LocationInit(location));
|
||||
var ios = preview.Info.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios != null && ios.SharesCell)
|
||||
{
|
||||
var actorSubCell = FreeSubCellAt(location);
|
||||
if (actorSubCell == SubCell.Invalid)
|
||||
preview.RemoveInit<SubCellInit>();
|
||||
else
|
||||
preview.ReplaceInit(new SubCellInit(actorSubCell));
|
||||
}
|
||||
|
||||
preview.UpdateFromMove();
|
||||
Add(preview);
|
||||
}
|
||||
|
||||
void SyncMultiplayerCount()
|
||||
{
|
||||
var newCount = previews.Count(p => p.Info.Name == "mpspawn");
|
||||
|
||||
@@ -189,22 +189,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return ++CurrentToken;
|
||||
}
|
||||
|
||||
public void MoveActor(EditorActorPreview preview, CPos location)
|
||||
{
|
||||
editorLayer.Remove(preview);
|
||||
preview.ReplaceInit(new LocationInit(location));
|
||||
var ios = preview.Info.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios != null && ios.SharesCell)
|
||||
{
|
||||
var actorSubCell = editorLayer.FreeSubCellAt(location);
|
||||
if (actorSubCell != SubCell.Invalid)
|
||||
preview.ReplaceInit(new SubCellInit(actorSubCell));
|
||||
}
|
||||
|
||||
preview.UpdateFromMove();
|
||||
editorLayer.Add(preview);
|
||||
}
|
||||
|
||||
public int SetTerrainTemplate(WorldRenderer wr, TerrainTemplateInfo template)
|
||||
{
|
||||
terrainOrResourceCell = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(Viewport.LastMousePos));
|
||||
|
||||
@@ -24,14 +24,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
const string AreaSelection = "label-area-selection";
|
||||
|
||||
readonly EditorViewportControllerWidget editor;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly Map map;
|
||||
|
||||
readonly ContainerWidget actorEditPanel;
|
||||
readonly ContainerWidget areaEditPanel;
|
||||
|
||||
readonly CheckboxWidget copyTerrainCheckbox;
|
||||
readonly CheckboxWidget copyResourcesCheckbox;
|
||||
readonly CheckboxWidget copyActorsCheckbox;
|
||||
readonly EditorActorLayer editorActorLayer;
|
||||
readonly EditorResourceLayer editorResourceLayer;
|
||||
readonly IResourceLayer resourceLayer;
|
||||
@@ -46,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public MapEditorSelectionLogic(Widget widget, World world, WorldRenderer worldRenderer)
|
||||
{
|
||||
this.worldRenderer = worldRenderer;
|
||||
map = worldRenderer.World.Map;
|
||||
|
||||
editorActorLayer = world.WorldActor.Trait<EditorActorLayer>();
|
||||
resourceLayer = world.WorldActor.TraitOrDefault<IResourceLayer>();
|
||||
@@ -55,15 +49,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
editor = widget.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
||||
editor.DefaultBrush.SelectionChanged += HandleSelectionChanged;
|
||||
var selectTabContainer = widget.Get("SELECT_WIDGETS");
|
||||
actorEditPanel = selectTabContainer.Get<ContainerWidget>("ACTOR_EDIT_PANEL");
|
||||
areaEditPanel = selectTabContainer.Get<ContainerWidget>("AREA_EDIT_PANEL");
|
||||
var actorEditPanel = selectTabContainer.Get<ContainerWidget>("ACTOR_EDIT_PANEL");
|
||||
var areaEditPanel = selectTabContainer.Get<ContainerWidget>("AREA_EDIT_PANEL");
|
||||
|
||||
actorEditPanel.IsVisible = () => editor.DefaultBrush.Selection.Actor != null;
|
||||
areaEditPanel.IsVisible = () => editor.DefaultBrush.Selection.Area != null;
|
||||
|
||||
copyTerrainCheckbox = areaEditPanel.Get<CheckboxWidget>("COPY_FILTER_TERRAIN_CHECKBOX");
|
||||
copyResourcesCheckbox = areaEditPanel.Get<CheckboxWidget>("COPY_FILTER_RESOURCES_CHECKBOX");
|
||||
copyActorsCheckbox = areaEditPanel.Get<CheckboxWidget>("COPY_FILTER_ACTORS_CHECKBOX");
|
||||
var copyTerrainCheckbox = areaEditPanel.Get<CheckboxWidget>("COPY_FILTER_TERRAIN_CHECKBOX");
|
||||
var copyResourcesCheckbox = areaEditPanel.Get<CheckboxWidget>("COPY_FILTER_RESOURCES_CHECKBOX");
|
||||
var copyActorsCheckbox = areaEditPanel.Get<CheckboxWidget>("COPY_FILTER_ACTORS_CHECKBOX");
|
||||
|
||||
copyTerrainCheckbox.IsDisabled = () => editor.CurrentBrush is EditorCopyPasteBrush;
|
||||
copyResourcesCheckbox.IsDisabled = () => editor.CurrentBrush is EditorCopyPasteBrush;
|
||||
@@ -107,9 +101,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var selection = editor.DefaultBrush.Selection.Area;
|
||||
var source = new CellCoordsRegion(selection.TopLeft, selection.BottomRight);
|
||||
|
||||
var mapTiles = worldRenderer.World.Map.Tiles;
|
||||
var mapHeight = worldRenderer.World.Map.Height;
|
||||
var mapResources = worldRenderer.World.Map.Resources;
|
||||
var mapTiles = map.Tiles;
|
||||
var mapHeight = map.Height;
|
||||
var mapResources = map.Resources;
|
||||
|
||||
var previews = new Dictionary<string, EditorActorPreview>();
|
||||
var tiles = new Dictionary<CPos, ClipboardTile>();
|
||||
|
||||
@@ -96,15 +96,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
ScrollItemWidget SetupEraseItem(ScrollItemWidget template)
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template,
|
||||
() => markerTile == null && editor.CurrentBrush != null && editor.CurrentBrush is EditorMarkerLayerBrush,
|
||||
return ScrollItemWidget.Setup(template,
|
||||
() => markerTile == null && editor.CurrentBrush is EditorMarkerLayerBrush,
|
||||
() =>
|
||||
{
|
||||
markerTile = null;
|
||||
editor.SetBrush(new EditorMarkerLayerBrush(editor, null, worldRenderer));
|
||||
});
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user