Player stops auto walking if WASD is pressed
This commit is contained in:
		| @@ -20,9 +20,10 @@ namespace stardew_access.Features | |||||||
|         private Vector2 relativeOffsetLockPosition = Vector2.Zero; |         private Vector2 relativeOffsetLockPosition = Vector2.Zero; | ||||||
|         private Boolean relativeOffsetLock = false; |         private Boolean relativeOffsetLock = false; | ||||||
|         private Vector2 prevPlayerPosition = Vector2.Zero, prevFacing = Vector2.Zero; |         private Vector2 prevPlayerPosition = Vector2.Zero, prevFacing = Vector2.Zero; | ||||||
|         private Boolean isAutoWalking = false; |  | ||||||
|         private Vector2 finalTile = Vector2.Zero; |         private Vector2 finalTile = Vector2.Zero; | ||||||
|  |  | ||||||
|  |         public Boolean isAutoWalking = false; | ||||||
|  |  | ||||||
|         private Vector2 PlayerFacingVector |         private Vector2 PlayerFacingVector | ||||||
|         { |         { | ||||||
|             get |             get | ||||||
| @@ -133,22 +134,40 @@ namespace stardew_access.Features | |||||||
|             } |             } | ||||||
|             else if (MainClass.Config.AutoWalkToTile.JustPressed() && StardewModdingAPI.Context.IsPlayerFree) |             else if (MainClass.Config.AutoWalkToTile.JustPressed() && StardewModdingAPI.Context.IsPlayerFree) | ||||||
|             { |             { | ||||||
|                 PathFindController controller = new PathFindController(Game1.player, Game1.currentLocation, this.GetViewingTile().ToPoint(), Game1.player.FacingDirection); |                 this.startAutoWalking(); | ||||||
|                 controller.allowPlayerPathingInEvent = true; |  | ||||||
|                 if (controller.pathToEndPoint != null && controller.pathToEndPoint.Count > 0) |  | ||||||
|                 { |  | ||||||
|                     Game1.player.controller = controller; |  | ||||||
|                     this.isAutoWalking = true; |  | ||||||
|                     this.finalTile = this.GetViewingTile(); |  | ||||||
|                     MainClass.ScreenReader.Say($"Moving to {this.finalTile.X}x {this.finalTile.Y}y", true); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     MainClass.ScreenReader.Say($"Cannot move to {this.finalTile.X}x {this.finalTile.Y}y", true); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         private void startAutoWalking() | ||||||
|  |         { | ||||||
|  |             PathFindController controller = new PathFindController(Game1.player, Game1.currentLocation, this.GetViewingTile().ToPoint(), Game1.player.FacingDirection); | ||||||
|  |             controller.allowPlayerPathingInEvent = true; | ||||||
|  |             if (controller.pathToEndPoint != null && controller.pathToEndPoint.Count > 0) | ||||||
|  |             { | ||||||
|  |                 Game1.player.controller = controller; | ||||||
|  |                 this.isAutoWalking = true; | ||||||
|  |                 this.finalTile = this.GetViewingTile(); | ||||||
|  |                 MainClass.ScreenReader.Say($"Moving to {this.finalTile.X}x {this.finalTile.Y}y", true); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 MainClass.ScreenReader.Say($"Cannot move to {this.finalTile.X}x {this.finalTile.Y}y", true); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Stop the auto walk controller and reset variables  | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="wasForced">Narrates a message if set to true.</param> | ||||||
|  |         public void stopAutoWalking(bool wasForced = false) | ||||||
|  |         { | ||||||
|  |             this.finalTile = Vector2.Zero; | ||||||
|  |             this.isAutoWalking = false; | ||||||
|  |             Game1.player.controller = null; | ||||||
|  |             if (wasForced) | ||||||
|  |                 MainClass.ScreenReader.Say("Stopped moving", true); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         private void cursorMoveInput(Vector2 delta, Boolean precise = false) |         private void cursorMoveInput(Vector2 delta, Boolean precise = false) | ||||||
|         { |         { | ||||||
|             if (!tryMoveTileView(delta)) return; |             if (!tryMoveTileView(delta)) return; | ||||||
| @@ -219,11 +238,13 @@ namespace stardew_access.Features | |||||||
|             if (MainClass.Config.SnapMouse) |             if (MainClass.Config.SnapMouse) | ||||||
|                 this.SnapMouseToPlayer(); |                 this.SnapMouseToPlayer(); | ||||||
|  |  | ||||||
|             if (this.isAutoWalking && this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position) |             if (this.isAutoWalking) | ||||||
|             { |             { | ||||||
|                 MainClass.ScreenReader.Say("Reached destination", true); |                 if (this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position) | ||||||
|                 this.finalTile = Vector2.Zero; |                 { | ||||||
|                 this.isAutoWalking = false; |                     MainClass.ScreenReader.Say("Reached destination", true); | ||||||
|  |                     this.stopAutoWalking(); | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -226,6 +226,16 @@ namespace stardew_access | |||||||
|             if (!Context.IsPlayerFree) |             if (!Context.IsPlayerFree) | ||||||
|                 return; |                 return; | ||||||
|  |  | ||||||
|  |             // Stops the auto walk controller if any movement key(WASD) is pressed | ||||||
|  |             if (TileViewerFeature.isAutoWalking && | ||||||
|  |             (e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveUpButton[0])) | ||||||
|  |             || e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveDownButton[0])) | ||||||
|  |             || e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveLeftButton[0])) | ||||||
|  |             || e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveRightButton[0])))) | ||||||
|  |             { | ||||||
|  |                 TileViewerFeature.stopAutoWalking(wasForced: true); | ||||||
|  |             } | ||||||
|  |  | ||||||
|             // Narrate Current Location |             // Narrate Current Location | ||||||
|             if (Config.LocationKey.JustPressed()) |             if (Config.LocationKey.JustPressed()) | ||||||
|             { |             { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user