diff --git a/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs b/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs index 1c3487ab..872e4772 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs +++ b/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs @@ -7,6 +7,8 @@ using StardewValley.Menus; using System.Reflection; using Microsoft.Xna.Framework.Input; using static StardewModdingAPI.Mods.VirtualKeyboard.ModConfig; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Mods.VirtualKeyboard { @@ -48,7 +50,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard } this.transparency = buttonDefine.transparency; - helper.Events.Display.RenderingHud += this.OnRenderingHud; + helper.Events.Display.Rendered += this.OnRendered; helper.Events.Input.ButtonReleased += this.EventInputButtonReleased; helper.Events.Input.ButtonPressed += this.EventInputButtonPressed; @@ -118,22 +120,18 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard { if (this.buttonKey == SButton.RightWindows) { - Game1.activeClickableMenu = new NamingMenu(command => - { + KeyboardInput.Show("Command", "", "", false).ContinueWith(delegate (Task s) { + string command; + command = s.Result; if (command.Length > 0) { object score = this.GetSCore(this.helper); object sgame = score.GetType().GetField("GameInstance", BindingFlags.Public | BindingFlags.Instance)?.GetValue(score); ConcurrentQueue commandQueue = sgame.GetType().GetProperty("CommandQueue", BindingFlags.Public | BindingFlags.Instance)?.GetValue(sgame) as ConcurrentQueue; commandQueue?.Enqueue(command); - Game1.activeClickableMenu.exitThisMenu(); } - - }, "Command", "") - { - randomButton = new ClickableTextureComponent(new Rectangle(-100, -100, 0, 0), - Game1.mobileSpriteSheet, new Rectangle(87, 22, 20, 20), 4f, false) - }; + return command; + }); return; } if (this.buttonKey == SButton.RightControl) @@ -158,7 +156,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard /// Raised before drawing the HUD (item toolbar, clock, etc) to the screen. /// The event sender. /// The event arguments. - private void OnRenderingHud(object sender, EventArgs e) + private void OnRendered(object sender, EventArgs e) { if (!this.hidden) { @@ -167,7 +165,22 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard { scale *= 0.5f; } - IClickableMenu.drawButtonWithText(Game1.spriteBatch, Game1.smallFont, this.alias, this.buttonRectangle.X, this.buttonRectangle.Y, this.buttonRectangle.Width, this.buttonRectangle.Height, Color.BurlyWood * scale); + System.Reflection.FieldInfo matrixField = Game1.spriteBatch.GetType().GetField("_matrix", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + object originMatrix = matrixField.GetValue(Game1.spriteBatch); + Game1.spriteBatch.End(); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, Microsoft.Xna.Framework.Matrix.CreateScale(1f)); + IClickableMenu.drawTextureBoxWithIconAndText(Game1.spriteBatch, Game1.smallFont, Game1.mouseCursors, new Rectangle(0x100, 0x100, 10, 10), null, new Rectangle(0, 0, 1, 1), + this.alias, this.buttonRectangle.X, this.buttonRectangle.Y, this.buttonRectangle.Width, this.buttonRectangle.Height, Color.BurlyWood * scale, 4f, + true, false, true, false, false, false, false); // Remove bold to fix the text position issue + Game1.spriteBatch.End(); + if(originMatrix != null) + { + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, (Matrix)originMatrix); + } + else + { + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); + } } } } diff --git a/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs b/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs index d1cf4b29..70009c33 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs +++ b/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs @@ -4,15 +4,15 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard { public Toggle vToggle = new Toggle(new Rect(36, 12, 64, 64)); public VirtualButton[] buttons { get; set;} = new VirtualButton[] { - new VirtualButton(SButton.Q, new Rect(192, 80, 90, 90), 0.5f), - new VirtualButton(SButton.I, new Rect(288, 80, 90, 90), 0.5f), - new VirtualButton(SButton.O, new Rect(384, 80, 90, 90), 0.5f), - new VirtualButton(SButton.P, new Rect(480, 80, 90, 90), 0.5f) + new VirtualButton(SButton.Q, new Rect(190, 80, 90, 90), 0.5f), + new VirtualButton(SButton.I, new Rect(290, 80, 90, 90), 0.5f), + new VirtualButton(SButton.O, new Rect(390, 80, 90, 90), 0.5f), + new VirtualButton(SButton.P, new Rect(490, 80, 90, 90), 0.5f) }; public VirtualButton[] buttonsExtend { get; set; } = new VirtualButton[] { - new VirtualButton(SButton.MouseRight, new Rect(192, 170, 162, 90), 0.5f, "RightMouse"), - new VirtualButton(SButton.RightWindows, new Rect(362, 170, 162, 90), 0.5f, "Command"), - new VirtualButton(SButton.RightControl, new Rect(532, 170, 162, 90), 0.5f, "Console") + new VirtualButton(SButton.MouseRight, new Rect(190, 170, 162, 90), 0.5f, "RightMouse"), + new VirtualButton(SButton.RightWindows, new Rect(360, 170, 162, 90), 0.5f, "Command"), + new VirtualButton(SButton.RightControl, new Rect(530, 170, 162, 90), 0.5f, "Console") }; internal class VirtualButton { public SButton key; diff --git a/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs b/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs index 4164cb6e..fb5ea177 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs +++ b/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs @@ -40,7 +40,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard this.virtualToggleButton = new ClickableTextureComponent(new Rectangle(Game1.toolbarPaddingX + 64, 12, 128, 128), this.texture, new Rectangle(0, 0, 16, 16), 5.75f, false); helper.WriteConfig(this.modConfig); - this.helper.Events.Display.RenderingHud += this.OnRenderingHUD; + this.helper.Events.Display.Rendered += this.OnRendered; this.helper.Events.Input.ButtonPressed += this.VirtualToggleButtonPressed; } @@ -99,7 +99,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard return false; } - private void OnRenderingHUD(object sender, EventArgs e) + private void OnRendered(object sender, EventArgs e) { if (this.isDefault) { @@ -131,7 +131,21 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard } if (!Game1.eventUp && Game1.activeClickableMenu is GameMenu == false && Game1.activeClickableMenu is ShopMenu == false) scale = 0.25f; + + System.Reflection.FieldInfo matrixField = Game1.spriteBatch.GetType().GetField("_matrix", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + object originMatrix = matrixField.GetValue(Game1.spriteBatch); + Game1.spriteBatch.End(); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, Microsoft.Xna.Framework.Matrix.CreateScale(1f)); this.virtualToggleButton.draw(Game1.spriteBatch, Color.White * scale, 0.000001f); + Game1.spriteBatch.End(); + if (originMatrix != null) + { + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, (Matrix)originMatrix); + } + else + { + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); + } } } } diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index f0ae2545..6eb0299c 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.2.0.3", allowNonStandard: true); + public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.3.0.1", allowNonStandard: true); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.4.1"); diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 66e320e1..c86a4479 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -1887,7 +1887,6 @@ label_168: string s = content.LoadString("Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10378"); SpriteText.drawStringWithScrollBackground(spriteBatch, s, 96, 32); } - events.Rendered.RaiseEmpty(); _spriteBatchEnd.Invoke(); this.drawOverlays(spriteBatch); this.renderScreenBuffer(BlendState.Opaque, toBuffer); @@ -1927,10 +1926,19 @@ label_168: DrawDialogueBoxForPinchZoom.Invoke(); DrawUnscaledActiveClickableMenuForPinchZoom.Invoke(); DrawNativeScaledActiveClickableMenuForPinchZoom.Invoke(); + if(IsActiveClickableMenuNativeScaled) + SpriteBatchBegin.Invoke(NativeZoomLevel); + else + SpriteBatchBegin.Invoke(1f); + events.Rendered.RaiseEmpty(); + _spriteBatchEnd.Invoke(); + } + else + { + SpriteBatchBegin.Invoke(1f); + events.Rendered.RaiseEmpty(); + _spriteBatchEnd.Invoke(); } - SpriteBatchBegin.Invoke(Game1.options.zoomLevel); - events.Rendered.RaiseEmpty(); - _spriteBatchEnd.Invoke(); if (_drawHUD.GetValue() && hudMessages.Count > 0 && (!eventUp || isFestival())) { SetSpriteBatchBeginNextID("A-F"); diff --git a/src/SMAPI/SGameConsole.cs b/src/SMAPI/SGameConsole.cs index 252d49cd..48edebca 100644 --- a/src/SMAPI/SGameConsole.cs +++ b/src/SMAPI/SGameConsole.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; +using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; using StardewModdingAPI.Framework; using StardewModdingAPI.Internal.ConsoleWriting; using StardewValley; @@ -64,12 +66,12 @@ namespace StardewModdingAPI } else if (this.commandButton.bounds.Contains(x, y)) { - Game1.activeClickableMenu = new NamingMenu(this.textBoxEnter, "Command", "") - { - randomButton = new ClickableTextureComponent(new Rectangle(-100, -100, 0, 0), Game1.mobileSpriteSheet, new Rectangle(87, 22, 20, 20), 4f, false) - }; - this.isVisible = false; - Game1.playSound("bigDeSelect"); + KeyboardInput.Show("Command", "", "", false).ContinueWith(delegate (Task s) { + string str; + str = s.Result; + this.textBoxEnter(str); + return str; + }); } else { @@ -88,14 +90,14 @@ namespace StardewModdingAPI if (command.EndsWith(";")) { command = command.TrimEnd(';'); + this.isVisible = false; + Game1.activeClickableMenu = null; + Game1.playSound("bigDeSelect"); SGame.instance.CommandQueue.Enqueue(command); - this.exitThisMenu(); return; } SGame.instance.CommandQueue.Enqueue(command); } - this.isVisible = true; - Game1.activeClickableMenu = this; } public override void leftClickHeld(int x, int y) diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 8f765e41..e64a288c 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -349,7 +349,6 @@ - @@ -373,6 +372,7 @@ +