Skip to content

Commit

Permalink
fix: Add function to handle more complex "should show icon" behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewhoener committed Mar 20, 2024
1 parent 90b23c8 commit 72c25b2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/LuckOfDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void OnRenderedHud(object sender, RenderedHudEventArgs e)
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// draw dice icon
if (!Game1.eventUp)
if (UIElementUtils.IsRenderingNormally())
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
ClickableTextureComponent icon = _icon.Value;
Expand Down
4 changes: 2 additions & 2 deletions UIInfoSuite2/UIElements/ShowBirthdayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void OnDayStarted(object? sender, DayStartedEventArgs e)

private void OnRenderingHud(object? sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp)
if (UIElementUtils.IsRenderingNormally())
{
DrawBirthdayIcon();
}
Expand All @@ -89,7 +89,7 @@ private void OnRenderingHud(object? sender, RenderingHudEventArgs e)

private void OnRenderedHud(object? sender, RenderedHudEventArgs e)
{
if (!Game1.eventUp)
if (UIElementUtils.IsRenderingNormally())
{
DrawHoverText();
}
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/ShowItemEffectRanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void OnUpdateTicked(object? sender, UpdateTickedEventArgs e)
}
}

if (Game1.activeClickableMenu == null && !Game1.eventUp)
if (Game1.activeClickableMenu == null && UIElementUtils.IsRenderingNormally())
{
UpdateEffectiveArea();
}
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/ShowQueenOfSauceIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)

private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp)
if (UIElementUtils.IsRenderingNormally())
{
if (_drawQueenOfSauceIcon.Value)
{
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/ShowRobinBuildingStatusIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void OnDayStarted(object sender, DayStartedEventArgs e)
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// Draw icon
if (!Game1.eventUp && _IsBuildingInProgress && _buildingIconSpriteLocation.HasValue)
if (UIElementUtils.IsRenderingNormally() && _IsBuildingInProgress && _buildingIconSpriteLocation.HasValue)
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_buildingIcon.Value = new ClickableTextureComponent(
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/ShowToolUpgradeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void OnDayStarted(object sender, DayStartedEventArgs e)
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// Draw a 40x40 icon
if (!Game1.eventUp && _toolBeingUpgraded.Value != null)
if (UIElementUtils.IsRenderingNormally() && _toolBeingUpgraded.Value != null)
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_toolUpgradeIcon.Value = new ClickableTextureComponent(
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/ShowTravelingMerchant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void OnMenuChanged(object sender, MenuChangedEventArgs e)
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// Draw icon
if (!Game1.eventUp && ShouldDrawIcon())
if (UIElementUtils.IsRenderingNormally() && ShouldDrawIcon())
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_travelingMerchantIcon = new ClickableTextureComponent(
Expand Down
4 changes: 2 additions & 2 deletions UIInfoSuite2/UIElements/ShowWhenAnimalNeedsPet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void OnWarped(object sender, WarpedEventArgs e) { }

private void OnRenderingHud_DrawNeedsPetTooltip(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp &&
if (UIElementUtils.IsRenderingNormally() &&
Game1.activeClickableMenu == null &&
(Game1.currentLocation is AnimalHouse || Game1.currentLocation is Farm || Game1.currentLocation is FarmHouse))
{
Expand All @@ -82,7 +82,7 @@ private void OnRenderingHud_DrawNeedsPetTooltip(object sender, RenderingHudEvent

private void OnRenderingHud_DrawAnimalHasProduct(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp &&
if (UIElementUtils.IsRenderingNormally() &&
Game1.activeClickableMenu == null &&
(Game1.currentLocation is AnimalHouse || Game1.currentLocation is Farm))
{
Expand Down
20 changes: 20 additions & 0 deletions UIInfoSuite2/UIElements/UIElementUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Linq;
using StardewValley;

namespace UIInfoSuite2.UIElements;

public static class UIElementUtils
{
public static bool IsRenderingNormally()
{
bool[] conditions =
{
!Game1.game1.takingMapScreenshot,
!Game1.eventUp,
!Game1.viewportFreeze,
Game1.displayHUD
};

return conditions.All(condition => condition);
}
}

0 comments on commit 72c25b2

Please sign in to comment.