From b1056a6cd1f7b0d38bc9b0c63a57ea5c50159666 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Mon, 16 May 2022 21:34:19 +0530 Subject: [PATCH] Added chat menu keys to mod config --- stardew-access/Features/TileViewer.cs | 2 +- stardew-access/ModConfig.cs | 50 +++++++++++++++-------- stardew-access/ModEntry.cs | 14 ++----- stardew-access/Patches/ChatMenuPatches.cs | 27 ++++-------- 4 files changed, 44 insertions(+), 49 deletions(-) diff --git a/stardew-access/Features/TileViewer.cs b/stardew-access/Features/TileViewer.cs index 113d74c..ad2d62b 100644 --- a/stardew-access/Features/TileViewer.cs +++ b/stardew-access/Features/TileViewer.cs @@ -133,7 +133,7 @@ namespace stardew_access.Features { this.cursorMoveInput(new Vector2(-Game1.tileSize, 0)); } - else if (MainClass.Config.AutoWalkToTile.JustPressed() && StardewModdingAPI.Context.IsPlayerFree) + else if (MainClass.Config.AutoWalkToTileKey.JustPressed() && StardewModdingAPI.Context.IsPlayerFree) { this.startAutoWalking(); } diff --git a/stardew-access/ModConfig.cs b/stardew-access/ModConfig.cs index 7b22ddc..ecea532 100644 --- a/stardew-access/ModConfig.cs +++ b/stardew-access/ModConfig.cs @@ -4,31 +4,28 @@ namespace stardew_access { internal class ModConfig { - public Boolean VerboseCoordinates { get; set; } = true; - public Boolean ReadTile { get; set; } = true; - public Boolean SnapMouse { get; set; } = true; - public Boolean Radar { get; set; } = false; - public Boolean RadarStereoSound { get; set; } = true; - public Boolean ReadFlooring { get; set; } = false; - - #region KeyBinds - // https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Input#SButton button key codes + + #region Simulate mouse clicks public KeybindList LeftClickMainKey { get; set; } = KeybindList.Parse("LeftControl + Enter"); public KeybindList RightClickMainKey { get; set; } = KeybindList.Parse("LeftShift + Enter"); public KeybindList LeftClickAlternateKey { get; set; } = KeybindList.Parse("OemOpenBrackets"); public KeybindList RightClickAlternateKey { get; set; } = KeybindList.Parse("OemCloseBrackets"); - public KeybindList HealthNStaminaKey { get; set; } = KeybindList.Parse("H"); - public KeybindList PositionKey { get; set; } = KeybindList.Parse("K"); - public KeybindList LocationKey { get; set; } = KeybindList.Parse("LeftAlt + K"); - public KeybindList MoneyKey { get; set; } = KeybindList.Parse("R"); - public KeybindList TimeNSeasonKey { get; set; } = KeybindList.Parse("Q"); + #endregion + + #region Chat menu + public KeybindList ChatMenuNextKey { get; set; } = KeybindList.Parse("PageUp"); + public KeybindList ChatMenuPreviousKey { get; set; } = KeybindList.Parse("PageDown"); + #endregion + + #region Read tile + public Boolean ReadTile { get; set; } = true; public KeybindList ReadTileKey { get; set; } = KeybindList.Parse("J"); public KeybindList ReadStandingTileKey { get; set; } = KeybindList.Parse("LeftAlt + J"); - public bool LimitTileCursorToScreen { get; set; } = false; - public int TileCursorPreciseMovementDistance { get; set; } = 8; + public Boolean ReadFlooring { get; set; } = false; + #endregion - //Tile viewer keys + #region Tile viewer public KeybindList TileCursorUpKey { get; set; } = KeybindList.Parse("Up"); public KeybindList TileCursorRightKey { get; set; } = KeybindList.Parse("Right"); public KeybindList TileCursorDownKey { get; set; } = KeybindList.Parse("Down"); @@ -38,7 +35,24 @@ namespace stardew_access public KeybindList TileCursorPreciseDownKey { get; set; } = KeybindList.Parse("LeftShift + Down"); public KeybindList TileCursorPreciseLeftKey { get; set; } = KeybindList.Parse("LeftShift + Left"); public KeybindList ToggleRelativeCursorLockKey { get; set; } = KeybindList.Parse("L"); - public KeybindList AutoWalkToTile { get; set; } = KeybindList.Parse("LeftControl + Enter"); + public KeybindList AutoWalkToTileKey { get; set; } = KeybindList.Parse("LeftControl + Enter"); + public bool LimitTileCursorToScreen { get; set; } = false; + public int TileCursorPreciseMovementDistance { get; set; } = 8; + #endregion + + #region Radar + public Boolean Radar { get; set; } = false; + public Boolean RadarStereoSound { get; set; } = true; + #endregion + + #region Others + public KeybindList HealthNStaminaKey { get; set; } = KeybindList.Parse("H"); + public KeybindList PositionKey { get; set; } = KeybindList.Parse("K"); + public KeybindList LocationKey { get; set; } = KeybindList.Parse("LeftAlt + K"); + public KeybindList MoneyKey { get; set; } = KeybindList.Parse("R"); + public KeybindList TimeNSeasonKey { get; set; } = KeybindList.Parse("Q"); + public Boolean VerboseCoordinates { get; set; } = true; + public Boolean SnapMouse { get; set; } = true; #endregion // TODO Add the exclusion and focus list too diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 8412b81..f564ed6 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -192,22 +192,18 @@ namespace stardew_access if (e == null) return; - bool isLeftAltPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt); - #region Simulate left and right clicks if (Game1.activeClickableMenu != null) { - bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); - bool isLeftControlPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl); bool isCustomizingChrachter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization); #region Mouse Click Simulation // Main Keybinds - if (isLeftControlPressed && Config.LeftClickMainKey.JustPressed()) + if (Config.LeftClickMainKey.JustPressed()) { Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } - if (isLeftShiftPressed && Config.RightClickMainKey.JustPressed()) + if (Config.RightClickMainKey.JustPressed()) { Game1.activeClickableMenu.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); } @@ -226,17 +222,15 @@ namespace stardew_access if (Game1.currentMinigame != null) { - bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); - bool isLeftControlPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl); bool isCustomizingChrachter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization); #region Mouse Click Simulation // Main Keybinds - if (isLeftControlPressed && Config.LeftClickMainKey.JustPressed()) + if (Config.LeftClickMainKey.JustPressed()) { Game1.currentMinigame.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } - if (isLeftShiftPressed && Config.RightClickMainKey.JustPressed()) + if (Config.RightClickMainKey.JustPressed()) { Game1.currentMinigame.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); } diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs index 6de3d2b..6155a70 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -16,19 +16,19 @@ namespace stardew_access.Patches if (__instance.chatBox.Selected) { - bool isPrevArrowPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.PageUp); - bool isNextArrowPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.PageDown); + bool isPrevButtonPressed = MainClass.Config.ChatMenuNextKey.JustPressed(); + bool isNextButtonPressed = MainClass.Config.ChatMenuPreviousKey.JustPressed(); if (___messages.Count > 0) { #region To narrate previous and next chat messages - if (isNextArrowPressed && !isChatRunning) + if (isNextButtonPressed && !isChatRunning) { isChatRunning = true; CycleThroughChatMessages(true, ___messages); Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); } - else if (isPrevArrowPressed && !isChatRunning) + else if (isPrevButtonPressed && !isChatRunning) { isChatRunning = true; CycleThroughChatMessages(false, ___messages); @@ -58,22 +58,9 @@ namespace stardew_access.Patches private static void CycleThroughChatMessages(bool increase, List ___messages) { string toSpeak = " "; - if (increase) - { - ++currentChatMessageIndex; - if (currentChatMessageIndex > ___messages.Count - 1) - { - currentChatMessageIndex = ___messages.Count - 1; - } - } - else - { - --currentChatMessageIndex; - if (currentChatMessageIndex < 0) - { - currentChatMessageIndex = 0; - } - } + + currentChatMessageIndex = (increase) ? (Math.Min(currentChatMessageIndex + 1, ___messages.Count - 1)) : (currentChatMessageIndex = Math.Max(currentChatMessageIndex - 1, 0)); + ___messages[currentChatMessageIndex].message.ForEach(message => { toSpeak += $"{message.message}, ";