Let SMAPI rewrite broken code instead

This commit is contained in:
yangzhi 2020-02-09 00:58:23 +08:00
parent f3dfcc64ae
commit 134eb34c0a
2 changed files with 4 additions and 6 deletions

View File

@ -42,8 +42,7 @@ namespace UIInfoSuite.UIElements
// draw shop harvest prices // draw shop harvest prices
if (Game1.activeClickableMenu is ShopMenu menu) if (Game1.activeClickableMenu is ShopMenu menu)
{ {
object item = _helper.Reflection.GetField<object>(menu, "hoveredItem").GetValue(); if (menu.hoveredItem is Item hoverItem)
if (item is Item hoverItem)
{ {
String text = string.Empty; String text = string.Empty;
bool itemHasPriceInfo = Tools.GetTruePrice(hoverItem) > 0; bool itemHasPriceInfo = Tools.GetTruePrice(hoverItem) > 0;
@ -68,8 +67,7 @@ namespace UIInfoSuite.UIElements
text = " " + temp.Price; text = " " + temp.Price;
} }
item = _helper.Reflection.GetField<object>(menu, "heldItem").GetValue(); var heldItem = menu.heldItem as Item;
var heldItem = item as Item;
if (heldItem == null) if (heldItem == null)
{ {
int value = 0; int value = 0;
@ -164,7 +162,7 @@ namespace UIInfoSuite.UIElements
getHoveredItemExtraItemIndex.Invoke<int>(new object[0]), getHoveredItemExtraItemIndex.Invoke<int>(new object[0]),
getHoveredItemExtraItemAmount.Invoke<int>(new object[0]), getHoveredItemExtraItemAmount.Invoke<int>(new object[0]),
null, null,
_helper.Reflection.GetField<Int32>(menu, "hoverPrice").GetValue()); menu.hoverPrice);
} }
} }
} }

View File

@ -103,7 +103,7 @@ namespace UIInfoSuite.UIElements
} }
} }
String hoverText = (string)gameMenu.GetType().GetField("hoverText", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)?.GetValue(gameMenu); String hoverText = gameMenu.hoverText;
IClickableMenu.drawHoverText( IClickableMenu.drawHoverText(
Game1.spriteBatch, Game1.spriteBatch,
hoverText, hoverText,