Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanyeti committed Apr 30, 2024
1 parent bf76f01 commit cb75c98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
32 changes: 21 additions & 11 deletions BetterRanching/BetterRanchingApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using StardewModdingAPI;
using StardewValley;
using StardewValley.Characters;
using StardewValley.GameData.Pets;
using StardewValley.ItemTypeDefinitions;

namespace BetterRanching
{
Expand Down Expand Up @@ -53,10 +55,8 @@ public void DrawHeartBubble(SpriteBatch spriteBatch, float xPosition, float yPos

public void DrawItemBubble(SpriteBatch spriteBatch, FarmAnimal animal, bool ranchingInProgress)
{
if (!int.TryParse(animal.currentProduce.Value, out var produceId))
{
produceId = 0;
}
ParsedItemData dataOrErrorItem = ItemRegistry.GetDataOrErrorItem(animal.currentProduce.Value);
int produceId = dataOrErrorItem.SpriteIndex;

DrawItemBubble(
spriteBatch,
Expand All @@ -70,13 +70,14 @@ public void DrawItemBubble(SpriteBatch spriteBatch, FarmAnimal animal, bool ranc
() => !animal.wasPet.Value,
true,
false,
animal.friendshipTowardFarmer.Value
animal.friendshipTowardFarmer.Value,
dataOrErrorItem
);
}

public void DrawItemBubble(SpriteBatch spriteBatch, float xPosition, float yPosition, int spriteWidth,
bool isShortTarget, int produceIcon, Func<bool> displayItem, Func<bool> displayHeart,
bool isFarmAnimal, bool isPet, int friendship)
bool isFarmAnimal, bool isPet, int friendship, ParsedItemData? itemData = null)
{
var showItem = displayItem() && _config.DisplayProduce;
var showHeart = displayHeart() &&
Expand All @@ -102,38 +103,47 @@ public void DrawItemBubble(SpriteBatch spriteBatch, float xPosition, float yPosi
if (showHeart)
{
if (showItem)
{
spriteBatch.Draw(Game1.mouseCursors,
Game1.GlobalToLocal(Game1.viewport,
new Vector2(xPosition + spriteWidth / 2f + 40,
yPosition - 25 + num)), sourceRectangle, Color.White * 0.75f, 0.0f, new Vector2(8f, 8f),
Game1.pixelZoom, SpriteEffects.None, 1);
}
else
{
spriteBatch.Draw(Game1.mouseCursors,
Game1.GlobalToLocal(Game1.viewport,
new Vector2((float)(xPosition + spriteWidth / 2f + Game1.tileSize * 1.1),
yPosition - 7 + num)), sourceRectangle, Color.White * 0.75f, 0.0f, new Vector2(8f, 8f),
(float)Game1.pixelZoom * 5 / 3, SpriteEffects.None, 1);
}
}

if (!showItem) return;

if (showHeart)
{
// Small item icon
spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport,
spriteBatch.Draw(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport,
new Vector2(xPosition + spriteWidth / 2f + 56,
yPosition - 45 + num)),
Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, produceIcon, 16, 16),
Game1.getSourceRectForStandardTileSheet(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, produceIcon, 16, 16),
Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), (float)(Game1.pixelZoom * .60),
SpriteEffects.None,
1);
}
else
{
// Big item icon
spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport,
spriteBatch.Draw(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport,
new Vector2((float)(xPosition + spriteWidth / 2f + Game1.tileSize * .625),
yPosition - 45 + num)),
Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, produceIcon, 16, 16),
yPosition - 45 + num)),
Game1.getSourceRectForStandardTileSheet(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, produceIcon, 16, 16),
Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), Game1.pixelZoom, SpriteEffects.None,
1);
}

}


Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Stardew Valley mod that prevents failing milking/shearing attempts and adds an i

Compatible with Stardew Valley 1.6+ on Linux, Mac, and Windows. Requires SMAPI 4.0.0 or later.

**Update 2.0.4 (2024/04/30)**: Fixed a bug causing the "Hide Hearts w/ Max Friendship" setting to be ignored for pets.
**Update 2.0.4 (2024/04/30)**: Fixed a bug that was causing the wrong icon to show for custom items. Thank you to kitsutsune and their awesome [Chocobo Valley](https://www.nexusmods.com/stardewvalley/mods/22226/) mod for bringing this to my attention! Also Fixed a bug causing the "Hide Hearts w/ Max Friendship" setting to be ignored for pets.
![Preview image](/better_ranching_preview.gif)

<h2>How to Install:</h2>
Expand Down Expand Up @@ -78,6 +78,7 @@ Compatible with Stardew Valley 1.6+ on Linux, Mac, and Windows. Requires SMAPI 4
* 2.0.3:
* Fixed bug causing animal hearts to display over building they are in.
* 2.0.4:
* Added support for custom harvest items to display above animals!
* Fixed bug causing "Hide Hearts w/ Max Friendship" setting to be ignored for pets

<h2>Other Contributors</h2>
Expand Down

0 comments on commit cb75c98

Please sign in to comment.