diff --git a/CentrED/Map/MapManager.cs b/CentrED/Map/MapManager.cs index b9c03fc..9256cc1 100644 --- a/CentrED/Map/MapManager.cs +++ b/CentrED/Map/MapManager.cs @@ -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) @@ -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) { @@ -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(); diff --git a/CentrED/UI/UIManager.cs b/CentrED/UI/UIManager.cs index 797a460..9a7f7b6 100644 --- a/CentrED/UI/UIManager.cs +++ b/CentrED/UI/UIManager.cs @@ -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()); diff --git a/Client/CentrEDClient.cs b/Client/CentrEDClient.cs index 085ff20..fd742f2 100644 --- a/Client/CentrEDClient.cs +++ b/Client/CentrEDClient.cs @@ -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 UndoStack = new(); + internal Stack UndoStack = new(); public List Clients { get; } = new(); public bool Running; private string? _status;