From a8bcaf6cef30fe5832f7be838d9c560459c68aa9 Mon Sep 17 00:00:00 2001 From: bradjrenshaw Date: Tue, 10 May 2022 14:37:43 -0400 Subject: [PATCH] Refactored keyboard tile cursor input to be triggered at the same time as the rest of keyboard input; fix bug in reading UI components with tile cursor. --- stardew-access/Features/MouseHandler.cs | 43 ++++++++++++------------- stardew-access/ModEntry.cs | 3 ++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/stardew-access/Features/MouseHandler.cs b/stardew-access/Features/MouseHandler.cs index ecdcf7d..678b8c4 100644 --- a/stardew-access/Features/MouseHandler.cs +++ b/stardew-access/Features/MouseHandler.cs @@ -61,6 +61,26 @@ namespace stardew_access.Features return target; } + public void HandleInput() + { + if (MainClass.Config.TileCursorUpKey.JustPressed()) + { + this.cursorMoveInput(new Vector2(0, -Game1.tileSize)); + } + else if (MainClass.Config.TileCursorRightKey.JustPressed()) + { + this.cursorMoveInput(new Vector2(Game1.tileSize, 0)); + } + else if (MainClass.Config.TileCursorDownKey.JustPressed()) + { + this.cursorMoveInput(new Vector2(0, Game1.tileSize)); + } + else if (MainClass.Config.TileCursorLeftKey.JustPressed()) + { + this.cursorMoveInput(new Vector2(-Game1.tileSize, 0)); + } + } + private void cursorMoveInput(Vector2 delta, Boolean precise = false) { if (!tryMoveTileView(delta)) return; @@ -120,23 +140,6 @@ namespace stardew_access.Features this.prevPlayerPosition = this.PlayerPosition; if (MainClass.Config.SnapMouse) this.SnapMouseToPlayer(); - - if (MainClass.Config.TileCursorUpKey.JustPressed()) - { - this.cursorMoveInput(new Vector2(0, -Game1.tileSize)); - } - else if (MainClass.Config.TileCursorRightKey.JustPressed()) - { - this.cursorMoveInput(new Vector2(Game1.tileSize, 0)); - } - else if (MainClass.Config.TileCursorDownKey.JustPressed()) - { - this.cursorMoveInput(new Vector2(0, Game1.tileSize)); - } - else if (MainClass.Config.TileCursorLeftKey.JustPressed()) - { - this.cursorMoveInput(new Vector2(-Game1.tileSize, 0)); - } } private static bool allowMouseSnap(Vector2 point) @@ -146,11 +149,7 @@ namespace stardew_access.Features //prevent mousing over the toolbar or any other UI component with the tile cursor foreach (IClickableMenu menu in Game1.onScreenMenus) { - if (menu.allClickableComponents == null) continue; - foreach (ClickableComponent component in menu.allClickableComponents) - { - if (component.containsPoint((int)point.X, (int)point.Y)) return false; - } + if (menu.isWithinBounds((int)point.X - Game1.viewport.X, (int)point.Y - Game1.viewport.Y)) return false; } return true; } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 28c19fe..2dd3899 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -267,6 +267,9 @@ get ReadTile.run(manuallyTriggered: true); return; } + + // Tile viewing cursor keys + Mouse.HandleInput(); } public static void ErrorLog(string message)