using Microsoft.Xna.Framework;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace UIInfoSuite.UIElements
{
class ShowAccurateHearts : IDisposable
{
private String[] _friendNames;
private SocialPage _socialPage;
private IModEvents _events;
private readonly int[][] _numArray = new int[][]
{
new int[] { 1, 1, 0, 1, 1 },
new int[] { 1, 1, 1, 1, 1 },
new int[] { 0, 1, 1, 1, 0 },
new int[] { 0, 0, 1, 0, 0 }
};
public ShowAccurateHearts(IModEvents events)
{
_events = events;
}
public void ToggleOption(bool showAccurateHearts)
{
_events.Display.MenuChanged -= OnMenuChanged;
_events.Display.RenderedActiveMenu -= OnRenderedActiveMenu;
if (showAccurateHearts)
{
_events.Display.MenuChanged += OnMenuChanged;
_events.Display.RenderedActiveMenu += OnRenderedActiveMenu;
}
}
public void Dispose()
{
ToggleOption(false);
}
/// When a menu is open ( isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.
/// The event sender.
/// The event arguments.
private void OnRenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e)
{
// draw heart fills
if (Game1.activeClickableMenu is GameMenu gameMenu)
{
if (gameMenu.currentTab == 2)
{
if (_socialPage != null)
{
int slotPosition = (int)typeof(SocialPage)
.GetField(
"slotPosition",
BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(_socialPage);
int yOffset = 0;
for (int i = slotPosition; i < slotPosition + 5 && i < _friendNames.Length; ++i)
{
int yPosition = Game1.activeClickableMenu.yPositionOnScreen + 130 + yOffset;
yOffset += 112;
Friendship friendshipValues;
String nextName = _friendNames[i];
if (Game1.player.friendshipData.TryGetValue(nextName, out friendshipValues))
{
int friendshipRawValue = friendshipValues.Points;
if (friendshipRawValue > 0)
{
int pointsToNextHeart = friendshipRawValue % 250;
int numHearts = friendshipRawValue / 250;
if (friendshipRawValue < 3000 &&
_friendNames[i] == Game1.player.spouse ||
friendshipRawValue < 2500)
{
DrawEachIndividualSquare(numHearts, pointsToNextHeart, yPosition);
//if (!Game1.options.hardwareCursor)
// Game1.spriteBatch.Draw(
// Game1.mouseCursors,
// new Vector2(Game1.getMouseX(), Game1.getMouseY()),
// Game1.getSourceRectForStandardTileSheet(
// Game1.mouseCursors, Game1.mouseCursor,
// 16,
// 16),
// Color.White,
// 0.0f,
// Vector2.Zero,
// Game1.pixelZoom + (float)(Game1.dialogueButtonScale / 150.0),
// SpriteEffects.None,
// 1f);
}
}
}
}
String hoverText = typeof(GameMenu).GetField("hoverText", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gameMenu) as String;
IClickableMenu.drawHoverText(
Game1.spriteBatch,
hoverText,
Game1.smallFont);
}
else
{
ExtendMenuIfNeeded();
}
}
}
}
/// Raised after a game menu is opened, closed, or replaced.
/// The event sender.
/// The event arguments.
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
ExtendMenuIfNeeded();
}
private void ExtendMenuIfNeeded()
{
if (Game1.activeClickableMenu is GameMenu)
{
List menuList = typeof(GameMenu).GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Game1.activeClickableMenu) as List;
foreach (var menu in menuList)
{
if (menu is SocialPage page)
{
_socialPage = page;
_friendNames = (typeof(SocialPage).GetField("names", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_socialPage) as List