Skip to content

Commit

Permalink
Area operation for all the other tools
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Dec 31, 2023
1 parent 72959d4 commit 44fa3ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 80 deletions.
47 changes: 17 additions & 30 deletions CentrED/Tools/ElevateTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace CentrED.Tools;

public class ElevateTool : Tool
public class ElevateTool : BaseTool
{

public override string Name => "Elevate";
public override Keys Shortcut => Keys.F4;

private static Random _random = new();
private static readonly Random _random = new();

enum ZMode
{
Expand All @@ -24,8 +24,6 @@ enum ZMode
private int zMode;
private int value;

private bool _pressed;

internal override void Draw()
{
ImGui.RadioButton("Add", ref zMode, (int)ZMode.ADD);
Expand All @@ -46,7 +44,7 @@ internal override void Draw()
_ => throw new ArgumentOutOfRangeException()
});

public override void OnMouseEnter(TileObject? o)
protected override void GhostApply(TileObject? o)
{
if (o is StaticObject so)
{
Expand All @@ -64,41 +62,30 @@ public override void OnMouseEnter(TileObject? o)
}
}

public override void OnMouseLeave(TileObject? o)
protected override void GhostClear(TileObject? o)
{
if (o is StaticObject so)
if (o is StaticObject)
{
so.Alpha = 1f;
CEDGame.MapManager.GhostStaticTiles.Clear();
o.Alpha = 1f;
CEDGame.MapManager.GhostStaticTiles.Remove(o);
}
else if (o is LandObject lo)
{
lo.Visible = true;
CEDGame.MapManager.GhostLandTiles.Clear();
}
if (_pressed)
{
Apply(o);
o.Visible = true;
CEDGame.MapManager.GhostLandTiles.Remove(lo);
}
}

public override void OnMousePressed(TileObject? o)
{
_pressed = true;
}

public override void OnMouseReleased(TileObject? o)
protected override void Apply(TileObject? o)
{
if (_pressed && o != null)
if (o is StaticObject)
{
Apply(o);
o.Tile.Z = CEDGame.MapManager.GhostStaticTiles[o].Tile.Z;

}
else if (o is LandObject lo)
{
o.Tile.Z = CEDGame.MapManager.GhostLandTiles[lo].Tile.Z;
}
_pressed = false;
}

private void Apply(TileObject? o)
{
if(o != null)
o.Tile.Z = NewZ(o.Tile);
}
}
32 changes: 7 additions & 25 deletions CentrED/Tools/MoveTool.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using CentrED.Map;
using CentrED.UI;
using ImGuiNET;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using static CentrED.Application;
using Vector2 = System.Numerics.Vector2;

namespace CentrED.Tools;

public class MoveTool : Tool
public class MoveTool : BaseTool
{
public override string Name => "Move";
public override Keys Shortcut => Keys.F3;

private int _xDelta;
private int _yDelta;

private bool _pressed;
private Vector2 _dragDelta = Vector2.Zero;
private int _xDragDelta;
private int _yDragDelta;
Expand Down Expand Up @@ -140,7 +138,7 @@ internal override void Draw()
ImGui.InputInt("Y", ref _yDelta);
}

public override void OnMouseEnter(TileObject? o)
protected override void GhostApply(TileObject? o)
{
if (o is StaticObject so)
{
Expand All @@ -157,37 +155,21 @@ public override void OnMouseEnter(TileObject? o)
}
}

public override void OnMouseLeave(TileObject? o)
protected override void GhostClear(TileObject? o)
{
if(_pressed)
Apply(o);
if (o is StaticObject so)
{
so.Alpha = 1f;
CEDGame.MapManager.GhostStaticTiles.Clear();
CEDGame.MapManager.GhostStaticTiles.Remove(o);
}
}

public override void OnMousePressed(TileObject? o)
{
_pressed = true;
}

public override void OnMouseReleased(TileObject? o)
{
if (_pressed)
{
Apply(o);
}
_pressed = false;
}

private void Apply(TileObject? o)
protected override void Apply(TileObject? o)
{
if (o is StaticObject so)
{
so.StaticTile.UpdatePos
((ushort)(so.StaticTile.X + _xDelta), (ushort)(so.StaticTile.Y + _yDelta), so.StaticTile.Z);
var ghostTile = CEDGame.MapManager.GhostStaticTiles[o];
so.StaticTile.UpdatePos(ghostTile.Tile.X, ghostTile.Tile.Y, so.StaticTile.Z);
}
}
}
30 changes: 5 additions & 25 deletions CentrED/Tools/RemoveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,28 @@

namespace CentrED.Tools;

public class RemoveTool : Tool
public class RemoveTool : BaseTool
{
public override string Name => "Remove";
public override Keys Shortcut => Keys.F5;

private bool _pressed;

public override void OnMouseEnter(TileObject? o)

protected override void GhostApply(TileObject? o)
{
if (o is StaticObject so)
{
so.Alpha = 0.2f;
}
}

public override void OnMouseLeave(TileObject? o)
protected override void GhostClear(TileObject? o)
{
if (o is StaticObject so)
{
so.Alpha = 1.0f;
}
if (_pressed)
{
Apply(o);
}
}

public override void OnMousePressed(TileObject? o)
{
_pressed = true;
}

public override void OnMouseReleased(TileObject? o)
{
if (_pressed)
{
Apply(o);
}
_pressed = false;
}

private void Apply(TileObject? o)
protected override void Apply(TileObject? o)
{
if(o is StaticObject so)
CEDClient.Remove(so.StaticTile);
Expand Down

0 comments on commit 44fa3ef

Please sign in to comment.