Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide icons on event #401

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UIInfoSuite2/Options/ModOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UIInfoSuite2.Options
public class ModOptionsPage : IClickableMenu
{
private const int visibleSlots = 7;
private const int Width = 800;
private const int Width = 880;
private readonly ClickableTextureComponent _downArrow;
private readonly List<ModOptionsElement> _options;
private readonly ClickableTextureComponent _scrollBar;
Expand Down
2 changes: 1 addition & 1 deletion UIInfoSuite2/UIElements/ExperienceBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void OnUpdateTicked_HandleTimers(object sender, UpdateTickedEventArgs e)

private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
if (Game1.eventUp)
if (!UIElementUtils.IsRenderingNormally())
{
return;
}
Expand Down
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/ShowRainyDayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
GetWeatherIconSpriteLocation();

if (Game1.eventUp)
if (!UIElementUtils.IsRenderingNormally())
{
return;
}
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
189 changes: 94 additions & 95 deletions UIInfoSuite2/UIElements/ShowSeasonalBerry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,122 +7,121 @@
using UIInfoSuite2.Infrastructure;
using UIInfoSuite2.Infrastructure.Extensions;

namespace UIInfoSuite2.UIElements
namespace UIInfoSuite2.UIElements;

internal class ShowSeasonalBerry : IDisposable
{
internal class ShowSeasonalBerry : IDisposable
#region Logic
private void UpdateBerryForDay()
{
#region Logic
private void UpdateBerryForDay()
string? season = Game1.currentSeason;
int day = Game1.dayOfMonth;
switch (season)
{
string? season = Game1.currentSeason;
int day = Game1.dayOfMonth;
switch (season)
{
case "spring" when day is >= 15 and <= 18:
_berrySpriteLocation = new Rectangle(128, 193, 15, 15);
_hoverText = _helper.SafeGetString(LanguageKeys.CanFindSalmonberry);
_spriteScale = 8 / 3f;
break;
case "fall" when day is >= 8 and <= 11:
_berrySpriteLocation = new Rectangle(32, 272, 16, 16);
_hoverText = _helper.SafeGetString(LanguageKeys.CanFindBlackberry);
_spriteScale = 5 / 2f;
break;
case "fall" when day >= 15 && ShowHazelnut:
_berrySpriteLocation = new Rectangle(1, 274, 14, 14);
_hoverText = _helper.SafeGetString(LanguageKeys.CanFindHazelnut);
_spriteScale = 20 / 7f;
break;
default:
_berrySpriteLocation = null;
break;
}
case "spring" when day is >= 15 and <= 18:
_berrySpriteLocation = new Rectangle(128, 193, 15, 15);
_hoverText = _helper.SafeGetString(LanguageKeys.CanFindSalmonberry);
_spriteScale = 8 / 3f;
break;
case "fall" when day is >= 8 and <= 11:
_berrySpriteLocation = new Rectangle(32, 272, 16, 16);
_hoverText = _helper.SafeGetString(LanguageKeys.CanFindBlackberry);
_spriteScale = 5 / 2f;
break;
case "fall" when day >= 15 && ShowHazelnut:
_berrySpriteLocation = new Rectangle(1, 274, 14, 14);
_hoverText = _helper.SafeGetString(LanguageKeys.CanFindHazelnut);
_spriteScale = 20 / 7f;
break;
default:
_berrySpriteLocation = null;
break;
}
#endregion
}
#endregion

#region Properties
private Rectangle? _berrySpriteLocation;
private float _spriteScale = 8 / 3f;
private string _hoverText;
private ClickableTextureComponent _berryIcon;
#region Properties
private Rectangle? _berrySpriteLocation;
private float _spriteScale = 8 / 3f;
private string _hoverText;
private ClickableTextureComponent _berryIcon;

private readonly IModHelper _helper;
private readonly IModHelper _helper;

private bool Enabled { get; set; }
private bool ShowHazelnut { get; set; }
#endregion
private bool Enabled { get; set; }
private bool ShowHazelnut { get; set; }
#endregion

#region Lifecycle
public ShowSeasonalBerry(IModHelper helper)
{
_helper = helper;
}
#region Lifecycle
public ShowSeasonalBerry(IModHelper helper)
{
_helper = helper;
}

public void Dispose()
{
ToggleOption(false);
}
public void Dispose()
{
ToggleOption(false);
}

public void ToggleOption(bool showSeasonalBerry)
{
Enabled = showSeasonalBerry;
public void ToggleOption(bool showSeasonalBerry)
{
Enabled = showSeasonalBerry;

_berrySpriteLocation = null;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_berrySpriteLocation = null;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;

if (showSeasonalBerry)
{
UpdateBerryForDay();
if (showSeasonalBerry)
{
UpdateBerryForDay();

_helper.Events.GameLoop.DayStarted += OnDayStarted;
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.Display.RenderedHud += OnRenderedHud;
}
_helper.Events.GameLoop.DayStarted += OnDayStarted;
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.Display.RenderedHud += OnRenderedHud;
}
}

public void ToggleHazelnutOption(bool showHazelnut)
{
ShowHazelnut = showHazelnut;
ToggleOption(Enabled);
}
#endregion
public void ToggleHazelnutOption(bool showHazelnut)
{
ShowHazelnut = showHazelnut;
ToggleOption(Enabled);
}
#endregion

#region Event subscriptions
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
UpdateBerryForDay();
}
#region Event subscriptions
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
UpdateBerryForDay();
}

private void OnRenderingHud(object sender, RenderingHudEventArgs e)
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// Draw icon
if (!UIElementUtils.IsRenderingNormally() || !_berrySpriteLocation.HasValue)
{
// Draw icon
if (Game1.eventUp || !_berrySpriteLocation.HasValue)
{
return;
}

Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_berryIcon = new ClickableTextureComponent(
new Rectangle(iconPosition.X, iconPosition.Y, 40, 40),
Game1.objectSpriteSheet,
_berrySpriteLocation.Value,
_spriteScale
);
_berryIcon.draw(Game1.spriteBatch);
return;
}

private void OnRenderedHud(object sender, RenderedHudEventArgs e)
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_berryIcon = new ClickableTextureComponent(
new Rectangle(iconPosition.X, iconPosition.Y, 40, 40),
Game1.objectSpriteSheet,
_berrySpriteLocation.Value,
_spriteScale
);
_berryIcon.draw(Game1.spriteBatch);
}

private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
// Show text on hover
bool hasMouse = _berryIcon?.containsPoint(Game1.getMouseX(), Game1.getMouseY()) ?? false;
bool hasText = !string.IsNullOrEmpty(_hoverText);
if (_berrySpriteLocation.HasValue && hasMouse && hasText)
{
// Show text on hover
bool hasMouse = _berryIcon?.containsPoint(Game1.getMouseX(), Game1.getMouseY()) ?? false;
bool hasText = !string.IsNullOrEmpty(_hoverText);
if (_berrySpriteLocation.HasValue && hasMouse && hasText)
{
IClickableMenu.drawHoverText(Game1.spriteBatch, _hoverText, Game1.dialogueFont);
}
IClickableMenu.drawHoverText(Game1.spriteBatch, _hoverText, Game1.dialogueFont);
}
#endregion
}
#endregion
}
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
Loading