Skip to content
Open
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
12 changes: 10 additions & 2 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,21 @@ public Vector3 Unproject(int x, int y, int z)
);
}

private bool CanDrawLand(LandObject lo)
public bool CanDrawLand(LandObject lo)
{
if(!ShowLand || (lo.Tile.Id <= 2 && !ShowNoDraw))
if(!ShowLand || (lo.Tile.Id <= 2 && !ShowNoDraw))
return false;
return WithinZRange(lo.Tile.Z);
}

// Tiles hidden by the view filter are read-only for tools; the virtual layer is always editable.
public bool CanEdit(TileObject? o) => o switch
{
LandObject lo => CanDrawLand(lo),
StaticObject so => CanDrawStatic(so),
_ => true,
};

public bool CanDrawStatic(StaticObject so)
{
var tile = so.StaticTile;
Expand Down
4 changes: 4 additions & 0 deletions CentrED/Tools/AltitudeGradientTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ private void ApplyGhostCommon(LandObject lo, int targetHeight)

private void CreateGhostTile(LandObject lo, sbyte newZ)
{
// Filtered tiles may be sampled for averages/gradients but never modified.
if (!MapManager.CanDrawLand(lo))
return;

lo.Visible = false;
var newTile = new LandTile(lo.LandTile.Id, lo.Tile.X, lo.Tile.Y, newZ);
var ghostTile = new LandObject(newTile);
Expand Down
18 changes: 13 additions & 5 deletions CentrED/Tools/BaseTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,20 @@ public sealed override void OnMouseReleased(TileObject? o)
{
foreach (var to in MapManager.GetTiles(AreaStartTile, o, TopTilesOnly))
{
InternalApply(to);
if (MapManager.CanEdit(to))
{
InternalApply(to);
}
GhostClear(to);
}
OnAreaOperationEnd();
}
else
{
InternalApply(o);
if (MapManager.CanEdit(o))
{
InternalApply(o);
}
GhostClear(o);
}
}
Expand All @@ -138,15 +144,15 @@ public sealed override void OnMouseEnter(TileObject? o)
OnAreaOperationUpdate(o);
foreach (var to in MapManager.GetTiles(AreaStartTile, o, TopTilesOnly))
{
if (Random.Shared.NextDouble() * 100 < _chance)
if (MapManager.CanEdit(to) && Random.Shared.NextDouble() * 100 < _chance)
{
GhostApply(to);
}
}
}
else
{
if (Random.Shared.NextDouble() * 100 < _chance)
if (MapManager.CanEdit(o) && Random.Shared.NextDouble() * 100 < _chance)
{
GhostApply(o);
}
Expand All @@ -164,7 +170,7 @@ public sealed override void OnMouseLeave(TileObject? o)
GhostClear(to);
}
}
else
else if (MapManager.CanEdit(o))
{
InternalApply(o);
}
Expand All @@ -174,6 +180,8 @@ public sealed override void OnMouseLeave(TileObject? o)

public override void Apply(TileObject? o)
{
if (!MapManager.CanEdit(o))
return;
GhostApply(o);
InternalApply(o);
}
Expand Down
9 changes: 7 additions & 2 deletions CentrED/Tools/CoastlineTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ protected override void GhostApply(TileObject? o)
if (selectedTile == null)
return;

if (!mapManager.CanDrawLand(selectedTile))
return;

if (_terrainWaterTiles.Contains(selectedTile.Tile.Id))
return;

Expand All @@ -161,8 +164,8 @@ protected override void GhostApply(TileObject? o)
if (kvp.Value != null && _terrainWaterTiles.Contains(kvp.Value.Id))
{
var waterLandObject = mapManager.LandTiles[kvp.Value.X, kvp.Value.Y];
if (waterLandObject != null)

if (waterLandObject != null && mapManager.CanDrawLand(waterLandObject))
{
if (!MapManager.GhostLandTiles.ContainsKey(waterLandObject))
{
Expand Down Expand Up @@ -303,6 +306,8 @@ protected override void InternalApply(TileObject? o)
{
foreach (var existingObject in mapManager.StaticsManager.Get(o.Tile.X, o.Tile.Y))
{
if (!mapManager.CanDrawStatic(existingObject))
continue;
Client.Remove(existingObject.StaticTile); //Do we need to create a ghost for this?
}
}
Expand Down
7 changes: 7 additions & 0 deletions CentrED/Tools/DrawTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ protected override void GhostApply(TileObject? o)
if (o == null)
return;

// the virtual layer can resolve to a filtered tile
if (!MapManager.CanEdit(o))
return;

if (!CanDrawOn(o))
return;

Expand Down Expand Up @@ -234,6 +238,9 @@ protected override void InternalApply(TileObject? o)
if (o == null)
return;

if (!MapManager.CanEdit(o))
return;

if (_drawMode == (int)DrawMode.REPLACE && o is StaticObject so)
{
Client.Remove(so.StaticTile);
Expand Down
3 changes: 3 additions & 0 deletions CentrED/Tools/MeshEditTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ protected override void GhostApply(TileObject? o)
if (lo == null)
continue;

if (!MapManager.CanDrawLand(lo))
continue;

// Create ghost tile
sbyte newZ = isBufferZone ? lo.Tile.Z : CalculateNewZ(lo, distance, centerZ);
lo.Visible = false;
Expand Down
Loading