From 29ecc8946c2ee178786c01cce709a6e40432dadc Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Apr 2020 16:15:55 -0700 Subject: [PATCH] Fix terrain tile hover coordinate display was snapping same way as viewport reticle split things up and add comments --- NHSE.WinForms/Subforms/TerrainEditor.cs | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/NHSE.WinForms/Subforms/TerrainEditor.cs b/NHSE.WinForms/Subforms/TerrainEditor.cs index 3e8d1c0..6975e44 100644 --- a/NHSE.WinForms/Subforms/TerrainEditor.cs +++ b/NHSE.WinForms/Subforms/TerrainEditor.cs @@ -338,7 +338,7 @@ private void ClickMapAt(MouseEventArgs e, bool skipLagCheck) int mX = e.X; int mY = e.Y; bool centerReticle = CHK_SnapToAcre.Checked; - GetCoordinates(centerReticle, mX, mY, out var x, out var y); + GetViewAnchorCoordinates(mX, mY, out var x, out var y, centerReticle); var acre = TerrainManager.GetAcre(x, y); bool sameAcre = AcreIndex == acre; @@ -369,14 +369,33 @@ private void ClickMapAt(MouseEventArgs e, bool skipLagCheck) CB_Acre.SelectedIndex = acre; } - private static void GetCoordinates(bool centerReticle, int mX, int mY, out int x, out int y) + private static void GetCursorCoordinates(int mX, int mY, out int x, out int y) { - int center = centerReticle ? 0 : GridWidth / 2; + x = mX / MapScale; + y = mY / MapScale; + } + + private static void GetViewAnchorCoordinates(int mX, int mY, out int x, out int y, bool centerReticle) + { + GetCursorCoordinates(mX, mY, out x, out y); + + // Clamp to viewport dimensions, and center to nearest acre if desired. const int maxX = ((TerrainManager.AcreWidth - 1) * GridWidth); const int maxY = ((TerrainManager.AcreHeight - 1) * GridHeight); - x = Math.Max(0, Math.Min((mX / MapScale) - center, maxX)); - y = Math.Max(0, Math.Min((mY / MapScale) - center, maxY)); + // If we aren't snapping the reticle to the nearest acre + // we want to put the middle of the reticle rectangle where the cursor is. + // Adjust the view coordinate + if (!centerReticle) + { + // Reticle size is GridWidth, center = /2 + x -= GridWidth / 2; + y -= GridWidth / 2; + } + + // Clamp to boundaries so that we always have 16x16 to view. + x = Math.Max(0, Math.Min(x, maxX)); + y = Math.Max(0, Math.Min(y, maxY)); } private void PB_Map_MouseMove(object sender, MouseEventArgs e) @@ -389,7 +408,7 @@ private void PB_Map_MouseMove(object sender, MouseEventArgs e) { int mX = e.X; int mY = e.Y; - GetCoordinates(false, mX, mY, out var x, out var y); + GetCursorCoordinates(mX, mY, out var x, out var y); L_Coordinates.Text = $"({x:000},{y:000}) = (0x{x:X2},0x{y:X2})"; } }