Skip to content
Closed
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
13 changes: 13 additions & 0 deletions UIInfoSuite2/Infrastructure/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public static Item GetHoveredItem()
return hoverItem;
}

public static CraftingRecipe GetHoveredCraftingRecipe()
{
CraftingRecipe hoverRecipe = null;

if(Game1.activeClickableMenu is CraftingPage craftingPage)
{
FieldInfo hoveredCraftingRecipeField = typeof(CraftingPage).GetField("hoverRecipe", BindingFlags.Instance | BindingFlags.NonPublic);
hoverRecipe = hoveredCraftingRecipeField.GetValue(craftingPage) as CraftingRecipe;
}

return hoverRecipe;
}

public static void GetSubTexture(Color[] output, Color[] originalColors, Rectangle sourceBounds, Rectangle clipArea)
{
if (output.Length < clipArea.Width * clipArea.Height)
Expand Down
11 changes: 10 additions & 1 deletion UIInfoSuite2/Options/ModOptionsPageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ModOptionsPageHandler(IModHelper helper, ModOptions options, bool showPer
var showScarecrowAndSprinklerRange = new ShowItemEffectRanges(helper);
var experienceBar = new ExperienceBar(helper);
var showItemHoverInformation = new ShowItemHoverInformation(helper);
var showHoverCraftableInCollection = new ShowHoverCraftableInCollection(helper);
var shopHarvestPrices = new ShopHarvestPrices(helper);
var showQueenOfSauceIcon = new ShowQueenOfSauceIcon(helper);
var showTravelingMerchant = new ShowTravelingMerchant(helper);
Expand Down Expand Up @@ -91,7 +92,7 @@ public ModOptionsPageHandler(IModHelper helper, ModOptions options, bool showPer
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.DisplayCalendarAndBillboard)), whichOption++, showCalendarAndBillboardOnGameMenuButton.ToggleOption, () => options.DisplayCalendarAndBillboard, v => options.DisplayCalendarAndBillboard = v));
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowCropAndBarrelTooltip)), whichOption++, showCropAndBarrelTime.ToggleOption, () => options.ShowCropAndBarrelTooltip, v => options.ShowCropAndBarrelTooltip = v));
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowItemEffectRanges)), whichOption++, showScarecrowAndSprinklerRange.ToggleOption, () => options.ShowItemEffectRanges, v => options.ShowItemEffectRanges = v));
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowExtraItemInformation)), whichOption++, showItemHoverInformation.ToggleOption, () => options.ShowExtraItemInformation, v => options.ShowExtraItemInformation = v));
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowExtraItemInformation)), whichOption++, toggleHoverInformation, () => options.ShowExtraItemInformation, v => options.ShowExtraItemInformation = v));
var travellingMerchantIcon = new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowTravelingMerchant)), whichOption++, showTravelingMerchant.ToggleOption, () => options.ShowTravelingMerchant, v => options.ShowTravelingMerchant = v);
_optionsElements.Add(travellingMerchantIcon);
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.HideMerchantWhenVisited)), whichOption++, showTravelingMerchant.ToggleHideWhenVisitedOption, () => options.HideMerchantWhenVisited, v => options.HideMerchantWhenVisited = v, travellingMerchantIcon));
Expand All @@ -104,6 +105,14 @@ public ModOptionsPageHandler(IModHelper helper, ModOptions options, bool showPer
_optionsElements.Add(seasonalBerryIcon);
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowSeasonalBerryHazelnut)), whichOption++, showSeasonalBerry.ToggleHazelnutOption, () => options.ShowSeasonalBerryHazelnut, v => options.ShowSeasonalBerryHazelnut = v, seasonalBerryIcon));
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(nameof(options.ShowTodaysGifts)), whichOption++, showTodaysGift.ToggleOption, () => options.ShowTodaysGifts, v => options.ShowTodaysGifts = v));


void toggleHoverInformation(bool isChecked)
{
showHoverCraftableInCollection.ToggleOption(isChecked);
showItemHoverInformation.ToggleOption(isChecked);
}

}


Expand Down
104 changes: 104 additions & 0 deletions UIInfoSuite2/UIElements/ShowHoverCraftableInCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
using StardewValley;
using StardewValley.Menus;
using System;
using UIInfoSuite2.Infrastructure;

namespace UIInfoSuite2.UIElements
{
internal class ShowHoverCraftableInCollection : IDisposable
{

private readonly IModHelper _helper;
private readonly PerScreen<CraftingRecipe> _hoverRecipe = new();

public ShowHoverCraftableInCollection(IModHelper helper)
{
_helper = helper;
}

public void ToggleOption(bool showItemHoverInformation)
{
_helper.Events.Display.Rendering -= OnRendering;
_helper.Events.Display.Rendered -= OnRendered;


if (showItemHoverInformation)
{
_helper.Events.Display.Rendering += OnRendering;
_helper.Events.Display.Rendered += OnRendered;
}
}

public void Dispose()
{
throw new NotImplementedException();
}
Comment on lines +35 to +38
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the exception thrown on purpose or can it be safely removed ?


private void OnRendering(object sender, EventArgs e)
{
_hoverRecipe.Value = Tools.GetHoveredCraftingRecipe();
}

private void OnRendered(object sender, EventArgs e)
{
DrawToolTip();
}

private void DrawToolTip()
{
if (Game1.activeClickableMenu != null)
{
if (_hoverRecipe.Value is StardewValley.CraftingRecipe recipe)
Comment thread
tqdv marked this conversation as resolved.
{
if (recipe.isCookingRecipe && !Game1.player.recipesCooked.ContainsKey(recipe.getIndexOfMenuView()))
{
int windowHeight = 80;

int windowY = Game1.getMouseY() + 20;
windowY = Game1.viewport.Height - windowHeight - windowY < 0 ? Game1.viewport.Height - windowHeight : windowY;

int windowWidth = 80;

int windowX = Game1.getMouseX() - windowWidth - 25;

if (Game1.getMouseX() > Game1.viewport.Width - 300)
{
windowX = Game1.viewport.Width - windowWidth - 350;
}
else if (windowX < 0)
{
windowX = Game1.getMouseX() + 350;
}

Vector2 windowPos = new Vector2(windowX, windowY);

// +22 centers the image in the box
int num1 = (int)windowPos.X + 22;
int num2 = (int)windowPos.Y + 22;

IClickableMenu.drawTextureBox(
Game1.spriteBatch,
Game1.menuTexture,
new Rectangle(0, 256, 60, 60),
(int)windowPos.X,
(int)windowPos.Y,
windowWidth,
windowHeight,
Color.White);

var _icon = new ClickableTextureComponent(
new Rectangle(num1, num2, 40, 40),
Game1.mouseCursors,
new Rectangle(609, 361, 28, 28),
1.3f);

_icon.draw(Game1.spriteBatch);
}
}
}
}
}
}