Skip to content

Commit

Permalink
Fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
thespbgamer committed Aug 31, 2023
1 parent 2ac0f84 commit 9ea6354
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Full Changelog

## [1.4.0] - 2023-08-31

### Improvements

- Code optimization

### Fixed

- Mod not showing correct image if there was not text showing

## [1.3.0] - 2023-07-30

### Improvements
Expand Down Expand Up @@ -41,7 +51,8 @@

- Initial release

[Unreleased]: https://github.com/thespbgamer/LovedLabelsRedux/compare/v1.2.0...HEAD
[Unreleased]: https://github.com/thespbgamer/LovedLabelsRedux/compare/v1.4.0...HEAD
[1.4.0]: https://github.com/thespbgamer/LovedLabelsRedux/releases/tag/1.4.0
[1.3.0]: https://github.com/thespbgamer/LovedLabelsRedux/releases/tag/1.3.0
[1.2.0]: https://github.com/thespbgamer/LovedLabelsRedux/releases/tag/1.2.0
[1.1.0]: https://github.com/thespbgamer/LovedLabelsRedux/releases/tag/1.1.0
Expand Down
26 changes: 15 additions & 11 deletions LovedLabelsRedux/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ModEntry : Mod
private ModConfig configsForTheMod;
private Texture2D _hearts;
private string _hoverText;
private bool? _hoverStatus;

public override void Entry(IModHelper helper)
{
Expand Down Expand Up @@ -68,8 +69,9 @@ private void OnButtonPressed(object sender, ButtonPressedEventArgs e)

private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (!Context.IsPlayerFree || !Game1.currentLocation.IsFarm) { return; }
if (!configsForTheMod.IsUIEnabled || (!Context.IsPlayerFree || !Game1.currentLocation.IsFarm)) { return; }
_hoverText = null;
_hoverStatus = null;

if (configsForTheMod.IsPettingEnabled)
{
Expand All @@ -85,11 +87,6 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
}
}

if (!configsForTheMod.IsUIEnabled)
{
return;
}

GameLocation location = Game1.currentLocation;
Vector2 mousePos = new Vector2(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y) / Game1.tileSize;

Expand All @@ -110,7 +107,10 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
RectangleF animalBoundaries = new(animal.position.X, animal.position.Y - animal.Sprite.getHeight(), animal.Sprite.getWidth() * 3 + animal.Sprite.getWidth() / 1.5f, animal.Sprite.getHeight() * 4);

if (animalBoundaries.Contains(mousePos.X * Game1.tileSize, mousePos.Y * Game1.tileSize))
{
_hoverText = animal.wasPet.Value ? configsForTheMod.AlreadyPettedMessage : configsForTheMod.NeedsPettingMessage;
_hoverStatus = animal.wasPet.Value;
}
}

foreach (Pet pet in location.characters.OfType<Pet>())
Expand All @@ -121,18 +121,22 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
NetLongDictionary<int, NetInt> lastPettedDays = Helper.Reflection.GetField<NetLongDictionary<int, NetInt>>(pet, "lastPetDay").GetValue();
bool wasPet = lastPettedDays.Values.Any(day => day == Game1.Date.TotalDays);
_hoverText = wasPet ? configsForTheMod.AlreadyPettedMessage : configsForTheMod.NeedsPettingMessage;
_hoverStatus = wasPet;
}
}
}

private void OnRendered(object sender, RenderedEventArgs e)
{
if (Context.IsPlayerFree && _hoverText != null)
DrawSimpleTooltip(Game1.spriteBatch, _hoverText, Game1.smallFont);
if (Context.IsPlayerFree && _hoverText != null && _hoverStatus != null)
DrawSimpleTooltip(Game1.spriteBatch, _hoverText, Game1.smallFont, _hoverStatus);
}

private void DrawSimpleTooltip(SpriteBatch b, string hoverText, SpriteFont font)
private void DrawSimpleTooltip(SpriteBatch b, string hoverText, SpriteFont font, bool? hoverStatus)
{
//log
this.Monitor.Log("[" + hoverStatus + "]", LogLevel.Debug);

var textSize = font.MeasureString(hoverText);
var width = (int)textSize.X + _hearts.Width + Game1.tileSize / 2;
var height = Math.Max(60, (int)textSize.Y + Game1.tileSize / 2);
Expand All @@ -149,7 +153,7 @@ private void DrawSimpleTooltip(SpriteBatch b, string hoverText, SpriteFont font)
y = Game1.viewport.Height - height;
}
IClickableMenu.drawTextureBox(b, Game1.menuTexture, new Rectangle(0, 256, 60, 60), x, y, width, height, Color.White);
if (hoverText.Length > 1)
if (hoverText.Length >= 1)
{
var tPosVector = new Vector2(x + (Game1.tileSize / 4), y + (Game1.tileSize / 4 + 4));
b.DrawString(font, hoverText, tPosVector + new Vector2(2f, 2f), Game1.textShadowColor, 0, Vector2.Zero, 1f, SpriteEffects.None, 0);
Expand All @@ -158,7 +162,7 @@ private void DrawSimpleTooltip(SpriteBatch b, string hoverText, SpriteFont font)
b.DrawString(font, hoverText, tPosVector, Game1.textColor * 0.9f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0);
}
var halfHeartSize = _hearts.Width * 0.5f;
var sourceY = (hoverText == configsForTheMod.AlreadyPettedMessage) ? 0 : 32;
var sourceY = (hoverStatus == true) ? 0 : 32;
var heartpos = new Vector2(x + textSize.X + halfHeartSize, y + halfHeartSize);
b.Draw(_hearts, heartpos, new Rectangle(0, sourceY, 32, 32), Color.White);
}
Expand Down
2 changes: 1 addition & 1 deletion LovedLabelsRedux/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Loved Labels Redux",
"Author": "thespbgamer",
"Version": "1.3.0",
"Version": "1.4.0",
"Description": "Shows the labels of the animals.",
"UniqueID": "thespbgamer.LovedLabelsRedux",
"EntryDll": "LovedLabelsRedux.dll",
Expand Down

0 comments on commit 9ea6354

Please sign in to comment.