Skip to content

Commit

Permalink
Merge pull request #635 from drewhoener/djh/legacy-master
Browse files Browse the repository at this point in the history
Version update v2.3.7 for Stardew 1.6.14
  • Loading branch information
drewhoener authored Nov 12, 2024
2 parents f4bfe9b + 2801e6d commit 9f53601
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
8 changes: 8 additions & 0 deletions UIInfoSuite2/Infrastructure/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using StardewValley.GameData.FruitTrees;
using StardewValley.Menus;
using StardewValley.TerrainFeatures;
using StardewValley.WorldMaps;
using SObject = StardewValley.Object;

namespace UIInfoSuite2.Infrastructure;
Expand Down Expand Up @@ -303,4 +304,11 @@ public static IEnumerable<int> GetDaysFromCondition(GameStateQuery.ParsedGameSta

return days.Count == 0 ? null : days.Max();
}

public static MapAreaPosition? GetMapPositionDataSafe(GameLocation location, Point position)
{
MapAreaPosition? mapAreaPosition = WorldMapManager.GetPositionData(location, position)?.Data;

return mapAreaPosition ?? WorldMapManager.GetPositionData(Game1.getFarm(), Point.Zero)?.Data;
}
}
30 changes: 16 additions & 14 deletions UIInfoSuite2/UIElements/LocationOfTownsfolk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void OnUpdateTicked(object? sender, UpdateTickedEventArgs e)
{
foreach (NPC? character in loc.characters)
{
if (character.isVillager())
if (character.IsVillager)
{
_townsfolk.Add(character);
}
Expand Down Expand Up @@ -311,13 +311,18 @@ private static void DrawNPC(NPC character, List<string> namesToShow)
}

Rectangle headShot = character.GetHeadShot();
MapAreaPosition? mapPosition =
WorldMapManager.GetPositionData(
Game1.player.currentLocation,
new Point((int)location.Value.X, (int)location.Value.Y)
) ??
WorldMapManager.GetPositionData(Game1.getFarm(), Point.Zero);
MapRegion? mapRegion = mapPosition.Region;
MapAreaPosition? mapPosition = Tools.GetMapPositionDataSafe(
Game1.player.currentLocation,
new Point((int)location.Value.X, (int)location.Value.Y)
);

if (mapPosition is null)
{
ModEntry.MonitorObject.LogOnce($"Unable to draw headshot for {character.Name}");
return;
}

MapRegion mapRegion = mapPosition.Region;
Rectangle mapBounds = mapRegion.GetMapPixelBounds();
var offsetLocation = new Vector2(
location.Value.X + mapBounds.X - headShot.Width,
Expand Down Expand Up @@ -356,21 +361,18 @@ private static void DrawNPC(NPC character, List<string> namesToShow)
private static Vector2? GetMapCoordinatesForNPC(NPC character)
{
var playerNormalizedTile = new Point(Math.Max(0, Game1.player.TilePoint.X), Math.Max(0, Game1.player.TilePoint.Y));
MapAreaPosition playerMapAreaPosition =
WorldMapManager.GetPositionData(Game1.player.currentLocation, playerNormalizedTile) ??
WorldMapManager.GetPositionData(Game1.getFarm(), Point.Zero);
MapAreaPosition? playerMapAreaPosition = Tools.GetMapPositionDataSafe(Game1.player.currentLocation, playerNormalizedTile);
// ^^ Regarding that ?? clause... If the player is in the farmhouse or barn or any building on the farm, GetPositionData is
// going to return null. Thus the fallback to pretending the player is on the farm. However, it seems to me that
// Game1.player.currentLocation.GetParentLocation() would be the safer long-term bet. But rule number 1 of modding is this:
// the game code is always right, even when it's wrong.

var characterNormalizedTile = new Point(Math.Max(0, character.TilePoint.X), Math.Max(0, character.TilePoint.Y));
MapAreaPosition characterMapAreaPosition =
WorldMapManager.GetPositionData(character.currentLocation, characterNormalizedTile);
MapAreaPosition? characterMapAreaPosition = Tools.GetMapPositionDataSafe(character.currentLocation, characterNormalizedTile);

if (playerMapAreaPosition != null &&
characterMapAreaPosition != null &&
!(characterMapAreaPosition.Region.Id != playerMapAreaPosition.Region.Id))
characterMapAreaPosition.Region.Id == playerMapAreaPosition.Region.Id)
{
return characterMapAreaPosition.GetMapPixelPosition(character.currentLocation, characterNormalizedTile);
}
Expand Down
6 changes: 3 additions & 3 deletions UIInfoSuite2/UIInfoSuite2.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>2.3.6</Version>
<Version>2.3.7</Version>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ModZipPath>$(SolutionDir)\Releases</ModZipPath>
Expand All @@ -18,8 +18,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1"/>
<PackageReference Include="Pathoschild.Stardew.ModTranslationClassBuilder" Version="2.0.1"/>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.3.2" />
<PackageReference Include="Pathoschild.Stardew.ModTranslationClassBuilder" Version="2.2.0" />
</ItemGroup>

<Import Project="UIInfoSuite2.csproj.local" Condition="Exists('UIInfoSuite2.csproj.local')"/>
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "UI Info Suite 2",
"Author": "Annosz",
"Version": "2.3.6",
"Version": "2.3.7",
"Description": "Adds a useful information to the user interface. Based on Cdaragorn's excellent UI Info Suite.",
"UniqueID": "Annosz.UiInfoSuite2",
"EntryDll": "UIInfoSuite2.dll",
Expand Down

0 comments on commit 9f53601

Please sign in to comment.