From d31f1a0827a7b2ca5a4f5842b93b830cd921e057 Mon Sep 17 00:00:00 2001 From: cdaragorn Date: Tue, 26 Nov 2019 23:12:29 -0700 Subject: [PATCH] Some bug fixes. --- SDVModTest/ModEntry.cs | 6 ++ SDVModTest/Properties/AssemblyInfo.cs | 4 +- SDVModTest/UIElements/ShowItemEffectRanges.cs | 86 +++++++++++++------ .../UIElements/ShowToolUpgradeStatus.cs | 3 +- .../UIElements/ShowTravelingMerchant.cs | 2 +- SDVModTest/manifest.json | 2 +- 6 files changed, 73 insertions(+), 30 deletions(-) diff --git a/SDVModTest/ModEntry.cs b/SDVModTest/ModEntry.cs index 78a2a03..4fabe42 100644 --- a/SDVModTest/ModEntry.cs +++ b/SDVModTest/ModEntry.cs @@ -34,6 +34,7 @@ namespace UIInfoSuite helper.Events.GameLoop.Saved += OnSaved; helper.Events.GameLoop.ReturnedToTitle += OnReturnedToTitle; helper.Events.Display.Rendering += IconHandler.Handler.Reset; + helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched; //Resources = new ResourceManager("UIInfoSuite.Resource.strings", Assembly.GetAssembly(typeof(ModEntry))); //try @@ -47,6 +48,11 @@ namespace UIInfoSuite //} } + private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e) + { + + } + /// Raised after the game returns to the title screen. /// The event sender. private void OnReturnedToTitle(object sender, ReturnedToTitleEventArgs e) diff --git a/SDVModTest/Properties/AssemblyInfo.cs b/SDVModTest/Properties/AssemblyInfo.cs index 62877c2..90744d7 100644 --- a/SDVModTest/Properties/AssemblyInfo.cs +++ b/SDVModTest/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.0.0")] +[assembly: AssemblyVersion("1.8.3.0")] +[assembly: AssemblyFileVersion("1.8.3.0")] diff --git a/SDVModTest/UIElements/ShowItemEffectRanges.cs b/SDVModTest/UIElements/ShowItemEffectRanges.cs index 9f96946..2906f27 100644 --- a/SDVModTest/UIElements/ShowItemEffectRanges.cs +++ b/SDVModTest/UIElements/ShowItemEffectRanges.cs @@ -6,6 +6,7 @@ using StardewValley.Buildings; using StardewValley.Locations; using System; using System.Collections.Generic; +using System.Threading; namespace UIInfoSuite.UIElements { @@ -15,6 +16,8 @@ namespace UIInfoSuite.UIElements private readonly ModConfig _modConfig; private readonly IModEvents _events; + private readonly Mutex _mutex = new Mutex(); + private static readonly int[][] _junimoHutArray = new int[17][] { new int[17] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, @@ -67,10 +70,21 @@ namespace UIInfoSuite.UIElements if (!e.IsMultipleOf(4)) return; - // check draw tile outlines - _effectiveArea.Clear(); + if (_mutex.WaitOne()) + { + try + { + // check draw tile outlines + _effectiveArea.Clear(); + } + finally + { + _mutex.ReleaseMutex(); + } + + } if (Game1.activeClickableMenu == null && - !Game1.eventUp) + !Game1.eventUp) { if (Game1.currentLocation is BuildableGameLocation buildableLocation) { @@ -126,7 +140,7 @@ namespace UIInfoSuite.UIElements { arrayToUse = _modConfig.QualitySprinkler; } - else if (name.Contains("prismatic")) + else if (name.Contains("prismatic")) { arrayToUse = _modConfig.PrismaticSprinkler; } @@ -153,10 +167,10 @@ namespace UIInfoSuite.UIElements { arrayToUse = _modConfig.QualitySprinkler; } - else if (name.Contains("prismatic")) - { - arrayToUse = _modConfig.PrismaticSprinkler; - } + else if (name.Contains("prismatic")) + { + arrayToUse = _modConfig.PrismaticSprinkler; + } else { arrayToUse = _modConfig.Sprinkler; @@ -174,6 +188,7 @@ namespace UIInfoSuite.UIElements } } + } /// Raised after the game draws to the sprite patch in a draw tick, just before the final sprite batch is rendered to the screen. @@ -181,30 +196,51 @@ namespace UIInfoSuite.UIElements /// The event arguments. private void OnRendered(object sender, RenderedEventArgs e) { - // draw tile outlines - foreach (Point point in _effectiveArea) - Game1.spriteBatch.Draw( - Game1.mouseCursors, - Game1.GlobalToLocal(new Vector2(point.X * Game1.tileSize, point.Y * Game1.tileSize)), - new Rectangle(194, 388, 16, 16), - Color.White * 0.7f, - 0.0f, - Vector2.Zero, - Game1.pixelZoom, - SpriteEffects.None, - 0.01f); + if (_mutex.WaitOne(0)) + { + try + { + // draw tile outlines + foreach (Point point in _effectiveArea) + Game1.spriteBatch.Draw( + Game1.mouseCursors, + Game1.GlobalToLocal(new Vector2(point.X * Game1.tileSize, point.Y * Game1.tileSize)), + new Rectangle(194, 388, 16, 16), + Color.White * 0.7f, + 0.0f, + Vector2.Zero, + Game1.pixelZoom, + SpriteEffects.None, + 0.01f); + } + finally + { + _mutex.ReleaseMutex(); + } + } } private void ParseConfigToHighlightedArea(int[][] highlightedLocation, int xPos, int yPos) { int xOffset = highlightedLocation.Length / 2; - for (int i = 0; i < highlightedLocation.Length; ++i) + + if (_mutex.WaitOne()) { - int yOffset = highlightedLocation[i].Length / 2; - for (int j = 0; j < highlightedLocation[i].Length; ++j) + try { - if (highlightedLocation[i][j] == 1) - _effectiveArea.Add(new Point(xPos + i - xOffset, yPos + j - yOffset)); + for (int i = 0; i < highlightedLocation.Length; ++i) + { + int yOffset = highlightedLocation[i].Length / 2; + for (int j = 0; j < highlightedLocation[i].Length; ++j) + { + if (highlightedLocation[i][j] == 1) + _effectiveArea.Add(new Point(xPos + i - xOffset, yPos + j - yOffset)); + } + } + } + finally + { + _mutex.ReleaseMutex(); } } } diff --git a/SDVModTest/UIElements/ShowToolUpgradeStatus.cs b/SDVModTest/UIElements/ShowToolUpgradeStatus.cs index 19a12b0..0debc5e 100644 --- a/SDVModTest/UIElements/ShowToolUpgradeStatus.cs +++ b/SDVModTest/UIElements/ShowToolUpgradeStatus.cs @@ -139,7 +139,8 @@ namespace UIInfoSuite.UIElements private void OnRenderedHud(object sender, RenderedHudEventArgs e) { // draw hover text - if (_toolBeingUpgraded != null && _toolUpgradeIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY())) + if (_toolBeingUpgraded != null && + (_toolUpgradeIcon?.containsPoint(Game1.getMouseX(), Game1.getMouseY()) ?? false)) { IClickableMenu.drawHoverText( Game1.spriteBatch, diff --git a/SDVModTest/UIElements/ShowTravelingMerchant.cs b/SDVModTest/UIElements/ShowTravelingMerchant.cs index 13fcdb4..a9f8cb5 100644 --- a/SDVModTest/UIElements/ShowTravelingMerchant.cs +++ b/SDVModTest/UIElements/ShowTravelingMerchant.cs @@ -79,7 +79,7 @@ namespace UIInfoSuite.UIElements private void OnRenderedHud(object sender, RenderedHudEventArgs e) { // draw hover text - if (_travelingMerchantIsHere && _travelingMerchantIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY())) + if (_travelingMerchantIsHere && (_travelingMerchantIcon?.containsPoint(Game1.getMouseX(), Game1.getMouseY()) ?? false)) { string hoverText = _helper.SafeGetString( LanguageKeys.TravelingMerchantIsInTown); diff --git a/SDVModTest/manifest.json b/SDVModTest/manifest.json index ec322ec..f24ec47 100644 --- a/SDVModTest/manifest.json +++ b/SDVModTest/manifest.json @@ -1,7 +1,7 @@ { "Name": "UI Info Suite", "Author": "Cdaragorn", - "Version": "1.8.0", + "Version": "1.8.3", "Description": "Adds a lot of useful information to the user interface. This is based on Demiacle's excellent UIModSuite.", "UniqueID": "Cdaragorn.UiInfoSuite", "EntryDll": "UIInfoSuite.dll",