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

Alternative area mode (Left Ctrl + Left Shift) to affect all the stat… #25

Merged
merged 3 commits into from
Oct 2, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,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 @@ -570,7 +570,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
Loading