Skip to content

Commit

Permalink
Moving with right mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Dec 28, 2023
1 parent 86f89cb commit adf688d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
var delta = (mouseState.ScrollWheelValue - _prevMouseState.ScrollWheelValue) / WHEEL_DELTA;
Camera.ZoomIn(delta);
}
if (mouseState.LeftButton == ButtonState.Pressed && ActiveTool == DefaultTool)
if (mouseState.RightButton == ButtonState.Pressed)
{
var oldPos = new Vector2(_prevMouseState.X - mouseState.X, _prevMouseState.Y - mouseState.Y);
if (oldPos != Vector2.Zero)
Expand All @@ -403,6 +403,10 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
_mouseDrag = true;
}
}
if (!_mouseDrag && mouseState.RightButton == ButtonState.Released && _prevMouseState.RightButton == ButtonState.Pressed)
{
CEDGame.UIManager.OpenContextMenu();
}
if (Client.Running && _gfxDevice.Viewport.Bounds.Contains(new Point(mouseState.X, mouseState.Y)))
{
var newTilePos = Unproject(mouseState.X, mouseState.Y, VirtualLayerZ);
Expand Down Expand Up @@ -437,7 +441,7 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
}
}
}
if (_mouseDrag && mouseState.LeftButton == ButtonState.Released)
if (_mouseDrag && mouseState.RightButton == ButtonState.Released)
{
_mouseDrag = false;
}
Expand Down
10 changes: 8 additions & 2 deletions CentrED/UI/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public UIManager(GraphicsDevice gd)
public bool CapturingKeyboard => ImGui.GetIO().WantCaptureKeyboard;

internal double FramesPerSecond;
public bool OpenContextMenu;
private bool openContextMenu;

private bool TryMapKeys(Keys key, out ImGuiKey imguikey)
{
Expand Down Expand Up @@ -196,6 +196,11 @@ public void Draw(GameTime gameTime)
Metrics.Stop("DrawUI");
}

public void OpenContextMenu()
{
openContextMenu = true;
}

protected virtual void DrawUI()
{
ShowCrashInfo();
Expand All @@ -215,9 +220,10 @@ protected virtual void DrawUI()

private void DrawContextMenu()
{
if (ImGui.IsMouseReleased(ImGuiMouseButton.Right) && !ImGui.GetIO().WantCaptureMouse)
if (openContextMenu)
{
ImGui.OpenPopup("MainPopup");
openContextMenu = false;
}
if (ImGui.BeginPopup("MainPopup"))
{
Expand Down

0 comments on commit adf688d

Please sign in to comment.