Skip to content

Commit

Permalink
Alternative area mode (Left Ctrl + Left Shift) to affect all the stat… (
Browse files Browse the repository at this point in the history
#25)

* Alternative area mode (Left Ctrl + Left Shift) to affect all the statics in a tile

* improvements

* fix
  • Loading branch information
DavideRei authored Oct 2, 2024
1 parent b6f6bea commit 224a2c8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
14 changes: 12 additions & 2 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public void RemoveTiles(ushort x, ushort y)
}
}

public IEnumerable<TileObject> GetTopTiles(TileObject? t1, TileObject? t2)
public IEnumerable<TileObject> GetTiles(TileObject? t1, TileObject? t2, bool topTilesOnly)
{
var landOnly = ActiveTool.Name == "Draw" && CEDGame.UIManager.GetWindow<TilesWindow>().LandMode;
if (t1 == null || t2 == null)
Expand All @@ -574,7 +574,17 @@ public IEnumerable<TileObject> GetTopTiles(TileObject? t1, TileObject? t2)
var landTile = LandTiles[x, y];
if (tiles != null && tiles.Any() && !landOnly)
{
yield return tiles.Last();
if (topTilesOnly)
{
yield return tiles.Last();
}
else
{
foreach (var tile in tiles)
{
yield return tile;
}
}
}
else if (landTile != null && CanDrawLand(landTile))
{
Expand Down
29 changes: 22 additions & 7 deletions CentrED/Tools/BaseTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class BaseTool : Tool
protected static int _chance = 100;
protected bool _pressed;
protected bool _areaMode;
protected bool _topTilesOnly = true;
private TileObject? _areaStartTile;

internal override void Draw()
Expand All @@ -26,17 +27,31 @@ internal override void Draw()

public sealed override void OnKeyPressed(Keys key)
{
if (key == Keys.LeftControl && !_pressed)
if (!_pressed)
{
_areaMode = true;
if (key == Keys.LeftControl)
{
_areaMode = true;
}
if (key == Keys.LeftShift)
{
_topTilesOnly = false;
}
}
}

public sealed override void OnKeyReleased(Keys key)
{
if (key == Keys.LeftControl && !_pressed)
if (!_pressed)
{
_areaMode = false;
if (key == Keys.LeftControl)
{
_areaMode = false;
}
if (key == Keys.LeftShift)
{
_topTilesOnly = true;
}
}
}

Expand Down Expand Up @@ -64,7 +79,7 @@ public sealed override void OnMouseReleased(TileObject? o)
{
if (_areaMode)
{
foreach (var to in MapManager.GetTopTiles(_areaStartTile, o))
foreach (var to in MapManager.GetTiles(_areaStartTile, o, _topTilesOnly))
{
TileObject to2 = to;
if (CEDGame.MapManager.UseVirtualLayer && tilesWindow.LandMode && to2 is VirtualLayerTile)
Expand Down Expand Up @@ -101,7 +116,7 @@ public sealed override void OnMouseEnter(TileObject? o)

if (_areaMode && _pressed)
{
foreach (var to in MapManager.GetTopTiles(_areaStartTile, o))
foreach (var to in MapManager.GetTiles(_areaStartTile, o, _topTilesOnly))
{
if (Random.Next(100) < _chance)
{
Expand Down Expand Up @@ -144,7 +159,7 @@ public sealed override void OnMouseLeave(TileObject? o)
}
if (_pressed && _areaMode)
{
foreach (var to in MapManager.GetTopTiles(_areaStartTile, o))
foreach (var to in MapManager.GetTiles(_areaStartTile, o, _topTilesOnly))
{
TileObject to2 = to;
if (CEDGame.MapManager.UseVirtualLayer && tilesWindow.LandMode && to2 is VirtualLayerTile)
Expand Down

0 comments on commit 224a2c8

Please sign in to comment.