Skip to content

Commit

Permalink
Undo shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 30, 2023
1 parent 0a16ed1 commit 87d675d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public void RemoveTile(StaticTile staticTile)
}

private MouseState _prevMouseState = Mouse.GetState();
private KeyboardState _prevKeyState = Keyboard.GetState();
public Rectangle ViewRange { get; private set; }

public void Update(GameTime gameTime, bool isActive, bool processMouse, bool processKeyboard)
Expand Down Expand Up @@ -450,9 +451,9 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro

if (isActive && processKeyboard)
{
var keyboard = Keyboard.GetState();
var keyState = Keyboard.GetState();

foreach (var key in keyboard.GetPressedKeys())
foreach (var key in keyState.GetPressedKeys())
{
switch (key)
{
Expand All @@ -474,6 +475,11 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
break;
}
}
if(keyState.IsKeyDown(Keys.LeftControl) && keyState.IsKeyDown(Keys.Z) && _prevKeyState.IsKeyUp(Keys.Z))
{
Client.Undo();
}
_prevKeyState = keyState;
}

Camera.Update();
Expand Down
9 changes: 8 additions & 1 deletion CentrED/UI/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,14 @@ private void DrawMainMenu()
CEDGame.Exit();
ImGui.EndMenu();
}

if (ImGui.BeginMenu("Edit"))
{
if (ImGui.MenuItem("Undo", "Ctrl+Z"))
{
CEDClient.Undo();
}
ImGui.EndMenu();
}
if (ImGui.BeginMenu("Tools"))
{
ToolsWindows.ForEach(w => w.DrawMenuItem());
Expand Down
2 changes: 1 addition & 1 deletion Client/CentrEDClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class CentrEDClient : BaseCentrED, IDisposable
public AccessLevel AccessLevel { get; internal set; }
public ushort X { get; private set; }
public ushort Y { get; private set; }
public Stack<Packet> UndoStack = new();
internal Stack<Packet> UndoStack = new();
public List<String> Clients { get; } = new();
public bool Running;
private string? _status;
Expand Down

0 comments on commit 87d675d

Please sign in to comment.