Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor UI refactor with draggable selection box #20226

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 90 additions & 0 deletions OpenRA.Game/Map/CellCoordsRegion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections;
using System.Collections.Generic;

namespace OpenRA
{
public readonly struct CellCoordsRegion : IEnumerable<CPos>
{
public struct CellCoordsEnumerator : IEnumerator<CPos>
{
readonly CellCoordsRegion r;

public CellCoordsEnumerator(CellCoordsRegion region)
: this()
{
r = region;
Reset();
}

public bool MoveNext()
{
var x = Current.X + 1;
var y = Current.Y;

// Check for column overflow.
if (x > r.BottomRight.X)
{
y++;
x = r.TopLeft.X;

// Check for row overflow.
if (y > r.BottomRight.Y)
return false;
}

Current = new CPos(x, y);
return true;
}

public void Reset()
{
Current = new CPos(r.TopLeft.X - 1, r.TopLeft.Y);
}

public CPos Current { get; private set; }

readonly object IEnumerator.Current => Current;
public readonly void Dispose() { }
}

public CellCoordsRegion(CPos topLeft, CPos bottomRight)
{
TopLeft = topLeft;
BottomRight = bottomRight;
}

public override string ToString()
{
return $"{TopLeft}->{BottomRight}";
}

public CellCoordsEnumerator GetEnumerator()
{
return new CellCoordsEnumerator(this);
}

IEnumerator<CPos> IEnumerable<CPos>.GetEnumerator()
{
return GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public CPos TopLeft { get; }
public CPos BottomRight { get; }
}
}
1 change: 1 addition & 0 deletions OpenRA.Game/Map/CellRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public bool Contains(CPos cell)
}

public MapCoordsRegion MapCoords => new(mapTopLeft, mapBottomRight);
public CellCoordsRegion CellCoords => new(TopLeft, BottomRight);

public CellRegionEnumerator GetEnumerator()
{
Expand Down
3 changes: 3 additions & 0 deletions OpenRA.Game/Traits/TraitsInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ public interface ISelectionDecorations
int2 GetDecorationOrigin(Actor self, WorldRenderer wr, string pos, int2 margin);
}

public interface IEditorSelectionLayer : ITraitInfoInterface { }
public interface IEditorPasteLayer : ITraitInfoInterface { }

public interface IMapPreviewSignatureInfo : ITraitInfoInterface
{
void PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos Uv, Color Color)> destinationBuffer);
Expand Down
35 changes: 35 additions & 0 deletions OpenRA.Mods.Common/EditorBrushes/EditorClipboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;

namespace OpenRA.Mods.Common.EditorBrushes
{
public readonly struct ClipboardTile
{
public readonly TerrainTile TerrainTile;
public readonly ResourceTile ResourceTile;
public readonly ResourceLayerContents ResourceLayerContents;
public readonly byte Height;

public ClipboardTile(TerrainTile terrainTile, ResourceTile resourceTile, ResourceLayerContents resourceLayerContents, byte height)
{
TerrainTile = terrainTile;
ResourceTile = resourceTile;
ResourceLayerContents = resourceLayerContents;
Height = height;
}
}
drogoganor marked this conversation as resolved.
Show resolved Hide resolved

public readonly struct EditorClipboard
{
public readonly CellRegion CellRegion;
public readonly Dictionary<string, EditorActorPreview> Actors;
public readonly Dictionary<CPos, ClipboardTile> Tiles;

public EditorClipboard(CellRegion cellRegion, Dictionary<string, EditorActorPreview> actors, Dictionary<CPos, ClipboardTile> tiles)
{
CellRegion = cellRegion;
Actors = actors;
Tiles = tiles;
}
}
drogoganor marked this conversation as resolved.
Show resolved Hide resolved
}