From c465e437a4da3dc96a301b3d14b6c986280f4a85 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 10:57:50 -0500 Subject: [PATCH 1/8] VK, fix for https://github.com/MartyrPher/SMAPI-Android-Installer/issues/50 --- src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs b/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs index 7671b875..1dd7ce7f 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs +++ b/src/SMAPI.Mods.VirtualKeyboard/KeyButton.cs @@ -5,7 +5,6 @@ using StardewValley; using StardewValley.Menus; using static StardewModdingAPI.Mods.VirtualKeyboard.ModConfig; using System.Reflection; -using Microsoft.Xna.Framework.Input; namespace StardewModdingAPI.Mods.VirtualKeyboard { @@ -17,13 +16,9 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard private object buttonPressed; private object buttonReleased; - private object legacyButtonPressed; - private object legacyButtonReleased; private readonly MethodBase RaiseButtonPressed; private readonly MethodBase RaiseButtonReleased; - private readonly MethodBase Legacy_KeyPressed; - private readonly MethodBase Legacy_KeyReleased; private readonly SButton buttonKey; private readonly float transparency; @@ -70,7 +65,8 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard { if (this.buttonRectangle.Contains(screenPixels.X * Game1.options.zoomLevel, screenPixels.Y * Game1.options.zoomLevel)) { - Toolbar.toolbarPressed = true; + if (!this.hidden) + Toolbar.toolbarPressed = true; return true; } return false; From 59ffb3c57b70e81275ac34a42a58f9b09712eba2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:04:41 -0500 Subject: [PATCH 2/8] Remove AndroidApiVersion Constant and bump version to 3.2.0.1 --- src/SMAPI/Constants.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 7e17f7e5..64b7182f 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -20,10 +20,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.2.0"); - - /// Android SMAPI's current semantic version. - public static ISemanticVersion AndroidApiVersion { get; } = new Toolkit.SemanticVersion("3.1.0-experimental"); + public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.2.0.1", allowNonStandard: true); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.4.1"); @@ -98,7 +95,7 @@ namespace StardewModdingAPI internal static string ModsPath { get; set; } /// The game's current semantic version. - internal static ISemanticVersion GameVersion { get; } = new GameVersion("1.3.36"); + internal static ISemanticVersion GameVersion { get; } = new GameVersion("1.4.4.122"); /// The target game platform. internal static Platform Platform { get; } = Platform.Android; From 1aeaece3715d6ce6f0bdbe63a5ff0493d8c69578 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:05:04 -0500 Subject: [PATCH 3/8] Add IClickableMenu Rewrites --- .../Framework/RewriteFacades/IClickableMenuMethods.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/SMAPI/Framework/RewriteFacades/IClickableMenuMethods.cs b/src/SMAPI/Framework/RewriteFacades/IClickableMenuMethods.cs index 42101ffd..1f700099 100644 --- a/src/SMAPI/Framework/RewriteFacades/IClickableMenuMethods.cs +++ b/src/SMAPI/Framework/RewriteFacades/IClickableMenuMethods.cs @@ -14,30 +14,41 @@ namespace StardewModdingAPI.Framework.RewriteFacades { drawHoverText(b, text, font, xOffset, yOffset, moneyAmounttoDisplayAtBottom, boldTitleText, healAmountToDisplay, buffIconsToDsiplay, hoveredItem, currencySymbol, extraItemToShowIndex, extraItemToShowAmount, overideX, overrideY, alpha, craftingIngrediants, -1, 80, -1, additional_craft_materials); } + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] public static new void drawTextureBox(SpriteBatch b, Texture2D texture, Microsoft.Xna.Framework.Rectangle sourceRect, int x, int y, int width, int height, Color color) { drawTextureBox(b, texture, sourceRect, x, y, width, height, color, 1, true, false); } + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] public static new void drawTextureBox(SpriteBatch b, Texture2D texture, Microsoft.Xna.Framework.Rectangle sourceRect, int x, int y, int width, int height, Color color, float scale) { drawTextureBox(b, texture, sourceRect, x, y, width, height, color, scale, true, false); } + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] public static new void drawTextureBox(SpriteBatch b, Texture2D texture, Microsoft.Xna.Framework.Rectangle sourceRect, int x, int y, int width, int height, Color color, float scale, bool drawShadow) { drawTextureBox(b, texture, sourceRect, x, y, width, height, color, scale, drawShadow, false); } + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] public new void drawHorizontalPartition(SpriteBatch b, int yPosition, bool small = false, int red = -1, int green = -1, int blue = -1) { this.drawMobileHorizontalPartition(b, 0, yPosition, 64, small); } + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] public new void drawVerticalUpperIntersectingPartition(SpriteBatch b, int xPosition, int partitionHeight, int red = -1, int green = -1, int blue = -1) { this.drawVerticalUpperIntersectingPartition(b, xPosition, partitionHeight); } + + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public new void drawVerticalIntersectingPartition(SpriteBatch b, int xPosition, int yPosition, int red = -1, int green = -1, int blue = -1) + { + this.drawVerticalIntersectingPartition(b, xPosition, yPosition); + } } } From be167734ea0f7dfc524ae68800e9f6d68e27afd6 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:05:28 -0500 Subject: [PATCH 4/8] Add Utility Rewrites --- src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs b/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs index 4409b932..b4f225ae 100644 --- a/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs +++ b/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs @@ -16,5 +16,11 @@ namespace StardewModdingAPI.Framework.RewriteFacades { return getTrashReclamationPrice(item, player, -1); } + + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public static new int getRandomItemFromSeason(string season, int randomSeedAddition, bool forQuest, bool changeDaily = true) + { + return getRandomItemFromSeason(season, randomSeedAddition, forQuest); + } } } From 430a2e5713844936790cdf1aa4e2cb1e567637fe Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:07:07 -0500 Subject: [PATCH 5/8] Comment out part of LooseSprites/Cursors since it's a List instead of IList --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index db9514be..85c60c6f 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -353,11 +353,12 @@ namespace StardewModdingAPI.Metadata case "loosesprites\\cursors": // Game1.LoadContent Game1.mouseCursors = content.Load(key); - foreach (DayTimeMoneyBox menu in Game1.onScreenMenus.OfType()) - { - foreach (ClickableTextureComponent button in new[] { menu.questButton, menu.zoomInButton, menu.zoomOutButton }) - button.texture = Game1.mouseCursors; - } + //Game1.onScreenMenus is a List instead of an IList + //foreach (DayTimeMoneyBox menu in Game1.onScreenMenus) + //{ + // foreach (ClickableTextureComponent button in new[] { menu.questButton, menu.zoomInButton, menu.zoomOutButton }) + // button.texture = Game1.mouseCursors; + //} return true; case "loosesprites\\cursors2": // Game1.LoadContent @@ -920,7 +921,8 @@ namespace StardewModdingAPI.Metadata int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault(); if (lastScheduleTime != 0) { - villager.scheduleTimeToTry = NPC.NO_TRY; // use time that's passed in to checkSchedule + //villager.scheduleTimeToTry = NPC.NO_TRY; // use time that's passed in to checkSchedule + this.Reflection.GetField(villager, "scheduleTimeToTry").SetValue(9999999); villager.checkSchedule(lastScheduleTime); } } From 58ad294515150464957dfb49f684b40b9543edfb Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:08:04 -0500 Subject: [PATCH 6/8] Readded things to SCore affected by mscorlib issue, removed terminal disabled message. --- src/SMAPI/Framework/SCore.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3882e3c3..d0c545d2 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -183,8 +183,7 @@ namespace StardewModdingAPI.Framework this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message); // init logging - //this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {Constants.Platform} ({EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)})", LogLevel.Info); - this.Monitor.Log($"MartyrPher's Android SMAPI Loader: {Constants.AndroidApiVersion} on Android: {Android.OS.Build.VERSION.Sdk}", LogLevel.Info); + this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {Constants.Platform}", LogLevel.Info); //({EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)})", LogLevel.Info); this.Monitor.Log($"Mods go here: {modsPath}"); if (modsPath != Constants.DefaultModsPath) this.Monitor.Log("(Using custom --mods-path argument.)", LogLevel.Trace); @@ -267,11 +266,11 @@ namespace StardewModdingAPI.Framework // apply game patches new GamePatcher(this.Monitor).Apply( new EventErrorPatch(this.MonitorForGame), - //new DialogueErrorPatch(this.MonitorForGame, this.Reflection), + new DialogueErrorPatch(this.MonitorForGame, this.Reflection), new ObjectErrorPatch(), new LoadContextPatch(this.Reflection, this.GameInstance.OnLoadStageChanged), new LoadErrorPatch(this.Monitor, this.GameInstance.OnSaveContentRemoved), - new ScheduleErrorPatch(this.MonitorForGame) + new ScheduleErrorPatch(this.MonitorForGame), new SaveBackupPatch(this.EventManager) ); @@ -340,8 +339,8 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"You have SMAPI for developers, so the console will be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info); if (!this.Settings.CheckForUpdates) this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn); - if (!this.Monitor.WriteToConsole) - this.Monitor.Log("Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn); + //if (!this.Monitor.WriteToConsole) + //this.Monitor.Log("Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn); this.Monitor.VerboseLog("Verbose logging enabled."); // update window titles @@ -469,7 +468,7 @@ namespace StardewModdingAPI.Framework // load mods resolver.ValidateManifests(mods, Constants.ApiVersion, toolkit.GetUpdateUrl); - //mods = resolver.ProcessDependencies(mods, modDatabase).ToArray(); + mods = resolver.ProcessDependencies(mods, modDatabase).ToArray(); this.LoadMods(mods, this.Toolkit.JsonHelper, this.ContentCore, modDatabase); // check for updates From cc56b3920922254d92e95580299b4069be413d64 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:08:28 -0500 Subject: [PATCH 7/8] Add files to .csproj --- src/SMAPI/SMAPI.csproj | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 65575854..7e932ed2 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -26,6 +26,7 @@ DEBUG;TRACE prompt 4 + 8.0 pdbonly @@ -34,6 +35,7 @@ TRACE prompt 4 + 8.0 @@ -62,6 +64,9 @@ ..\..\..\..\..\..\..\SteamLibrary\steamapps\common\Stardew Valley\smapi-internal\Newtonsoft.Json.dll + + ..\SMAPI.Toolkit\bin\Debug\net4.5\SMAPI.Toolkit.dll + ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.118\assemblies\StardewValley.dll @@ -72,6 +77,9 @@ + + ..\..\..\..\..\..\..\SteamLibrary\steamapps\common\Stardew Valley\smapi-internal\TMXTile.dll + ..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\xTile.dll @@ -157,6 +165,7 @@ + @@ -190,6 +199,7 @@ + @@ -228,6 +238,13 @@ + + + + + + + @@ -331,6 +348,7 @@ + @@ -372,10 +390,6 @@ {ed8e41fa-ddfa-4a77-932e-9853d279a129} SMAPI.Toolkit.CoreInterfaces - - {08184f74-60ad-4eee-a78c-f4a35ade6246} - SMAPI.Toolkit - From 5b146632cf4dd86b6699d14df6224c396c682793 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2020 11:37:18 -0500 Subject: [PATCH 8/8] PR#2 Update SGameConsole --- src/SMAPI/SGameConsole.cs | 141 ++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 52 deletions(-) diff --git a/src/SMAPI/SGameConsole.cs b/src/SMAPI/SGameConsole.cs index 448f8bad..252d49cd 100644 --- a/src/SMAPI/SGameConsole.cs +++ b/src/SMAPI/SGameConsole.cs @@ -1,9 +1,6 @@ using System.Collections.Generic; -using System.Reflection; -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; @@ -11,68 +8,53 @@ using StardewValley.Menus; namespace StardewModdingAPI { - class SGameConsole : IClickableMenu + public class SGameConsole : IClickableMenu { public static SGameConsole Instance; public bool isVisible; private readonly LinkedList> consoleMessageQueue = new LinkedList>(); - private readonly TextBox textBox; - private readonly MobileScrollbox scrollbox; - private Rectangle textBoxBounds; + private MobileScrollbox scrollbox; + + private ClickableTextureComponent commandButton; private SpriteFont smallFont; - private TextBoxEvent textBoxEvent; - - private Vector2 size; - private bool scrolling = false; + private int scrollLastFakeY = 0; + + private int scrollLastY = 0; + + private int MaxScrollBoxHeight => (int)(Game1.graphics.PreferredBackBufferHeight * 20 / Game1.NativeZoomLevel); + + private int MaxTextAreaWidth => (int)((Game1.graphics.PreferredBackBufferWidth - 32) / Game1.NativeZoomLevel); + internal SGameConsole() { Instance = this; this.isVisible = true; - this.textBox = new TextBox(null, null, Game1.dialogueFont, Game1.textColor) - { - X = 0, - Y = 100, - Width = IClickableMenu.viewport.Width, - Height = IClickableMenu.viewport.Height - }; - this.scrollbox = new MobileScrollbox(0, 0, 1280, 320, this.consoleMessageQueue.Count, new Rectangle(0, 0, 1280, 320)); - this.textBoxBounds = new Rectangle(this.textBox.X, this.textBox.Y, this.textBox.Width, this.textBox.Height); - this.scrollbox.Bounds = this.textBoxBounds; - this.textBoxEvent = new TextBoxEvent(this.textBoxEnter); } internal void InitializeContent(LocalizedContentManager content) { + this.scrollbox = new MobileScrollbox(0, 0, this.MaxTextAreaWidth, (int)(Game1.graphics.PreferredBackBufferHeight / Game1.NativeZoomLevel), this.MaxScrollBoxHeight, + new Rectangle(0, 0, (int)(Game1.graphics.PreferredBackBufferWidth / Game1.NativeZoomLevel), (int)(Game1.graphics.PreferredBackBufferHeight / Game1.NativeZoomLevel))); this.smallFont = content.Load(@"Fonts\SmallFont"); - this.size = this.smallFont.MeasureString("aA"); } public void Show() { if (this.upperRightCloseButton == null) this.initializeUpperRightCloseButton(); + if (this.commandButton == null) + this.commandButton = new ClickableTextureComponent(new Rectangle(16, 0, 64, 64), Game1.mobileSpriteSheet, new Rectangle(0, 44, 16, 16), 4f, false); Game1.activeClickableMenu = this; this.isVisible = true; } public override void receiveLeftClick(int x, int y, bool playSound = true) { - if (this.textBoxBounds.Contains(x, y)) - { - this.scrollbox.receiveLeftClick(x, y); - this.scrolling = this.scrollbox.panelScrolling; - this.textBox.Selected = true; - this.textBox.OnEnterPressed += this.textBoxEvent; - - this.textBox.Update(); - Game1.keyboardDispatcher.Subscriber = this.textBox; - this.textBoxEnter(this.textBox); - } if (this.upperRightCloseButton.bounds.Contains(x, y)) { @@ -80,31 +62,61 @@ namespace StardewModdingAPI Game1.activeClickableMenu = null; Game1.playSound("bigDeSelect"); } + 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"); + } + else + { + this.scrollLastFakeY = y; + this.scrollLastY = y; + this.scrolling = true; + this.scrollbox.receiveLeftClick(x, y); + } } - public void textBoxEnter(TextBox text) + public void textBoxEnter(string text) { - this.textBox.OnEnterPressed -= this.textBoxEvent; - string command = text.Text.Trim(); - - SGame.instance.CommandQueue.Enqueue(command); + string command = text.Trim(); + if (command.Length > 0) + { + if (command.EndsWith(";")) + { + command = command.TrimEnd(';'); + 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) { if (this.scrolling) { + int tmp = y; + y = this.scrollLastFakeY + this.scrollLastY - y; + this.scrollLastY = tmp; + this.scrollLastFakeY = y; this.scrollbox.leftClickHeld(x, y); - this.scrollbox.setYOffsetForScroll(9999); } } public override void releaseLeftClick(int x, int y) { + this.scrolling = false; this.scrollbox.releaseLeftClick(x, y); } - public void WriteLine(string consoleMessage, ConsoleLogLevel level) + internal void WriteLine(string consoleMessage, ConsoleLogLevel level) { lock (this.consoleMessageQueue) { @@ -121,18 +133,42 @@ namespace StardewModdingAPI this.scrollbox.update(time); } + private string _parseText(string text) + { + string line = string.Empty; + string returnString = string.Empty; + string[] strings = text.Split("\n"); + foreach (string t in strings) + { + string[] wordArray = t.Split(' '); + foreach (string word in wordArray) + { + if (this.smallFont.MeasureString(line + word).X > this.MaxTextAreaWidth) + { + returnString = returnString + line + '\n'; + line = string.Empty; + } + line = line + word + ' '; + } + returnString = returnString + line + '\n'; + line = string.Empty; + } + returnString.TrimEnd('\n'); + return returnString; + } + public override void draw(SpriteBatch b) { - float y = Game1.game1.screen.Height - this.size.Y; + this.scrollbox.setUpForScrollBoxDrawing(b); lock (this.consoleMessageQueue) { + float offset = 0; foreach (var log in this.consoleMessageQueue) { - string text = log.Value; - if (text.Contains("\n")) - { - text = text.Replace("\n", ""); - } + string text = this._parseText(log.Value); + Vector2 size = this.smallFont.MeasureString(text); + float y = Game1.game1.screen.Height - size.Y - offset - this.scrollbox.getYOffsetForScroll(); + offset += size.Y; switch (log.Key) { case ConsoleLogLevel.Critical: @@ -155,18 +191,19 @@ namespace StardewModdingAPI b.DrawString(this.smallFont, text, new Vector2(16, y), Color.LightGray); break; } - - this.size = this.smallFont.MeasureString(text); - if (y < 0) + + if (offset > this.MaxScrollBoxHeight) { break; } - y -= this.size.Y; } } - + this.scrollbox.finishScrollBoxDrawing(b); if (Context.IsWorldReady) + { this.upperRightCloseButton.draw(b); + this.commandButton.draw(b); + } } } }