Updates Stardust.metadata to work correctly in InventoryMenu, and ItemGrabMenu context. It shows the origin mod source of the item, and what class that item is. Hopefully will be useful for future modders.
This commit is contained in:
parent
3111f8bad0
commit
a67baa4c09
|
@ -1,4 +1,7 @@
|
|||
using StardewModdingAPI;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
using StardustCore.ModInfo;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -16,8 +19,36 @@ namespace StardustCore
|
|||
{
|
||||
ModHelper = helper;
|
||||
ModMonitor = this.Monitor;
|
||||
//Unused MetaData information. Works in player inventory but not in chests. Besides who really care where an object is from anyways?
|
||||
|
||||
StardewModdingAPI.Events.GraphicsEvents.OnPostRenderGuiEvent += Metadata.GameEvents_UpdateTick;
|
||||
StardewModdingAPI.Events.ControlEvents.MouseChanged += ControlEvents_MouseChanged;
|
||||
|
||||
}
|
||||
|
||||
private void ControlEvents_MouseChanged(object sender, StardewModdingAPI.Events.EventArgsMouseStateChanged e)
|
||||
{
|
||||
|
||||
if (Game1.activeClickableMenu == null) return;
|
||||
var MouseState = Mouse.GetState();
|
||||
if (Game1.activeClickableMenu is StardewValley.Menus.ItemGrabMenu && MouseState.LeftButton == ButtonState.Released)
|
||||
{
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.populateClickableComponentList();
|
||||
for (int index = 0; index < (Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory.Count; ++index)
|
||||
{
|
||||
if ((Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index] != null)
|
||||
{
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index].myID += 53910;
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index].upNeighborID += 53910;
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index].rightNeighborID += 53910;
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index].downNeighborID = -7777;
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index].leftNeighborID += 53910;
|
||||
(Game1.activeClickableMenu as StardewValley.Menus.ItemGrabMenu).ItemsToGrabMenu.inventory[index].fullyImmutable = true;
|
||||
}
|
||||
}
|
||||
// (Game1.activeClickableMenu as ItemGrabMenu).inventory.playerInventory = false;
|
||||
// Game1.activeClickableMenu =Game1.activeClickableMenu;//new ItemGrabMenu((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory,true,true,null,null,null,null,false,false,true,true,true,1,null,-1,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using StardewValley;
|
|||
using StardewValley.Menus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
@ -23,7 +24,7 @@ namespace StardustCore.ModInfo
|
|||
/// </summary>
|
||||
/// <param name="modColor"></param>
|
||||
/// <param name="modName"></param>
|
||||
public Metadata(Color ? modColor,string modName="")
|
||||
private Metadata(Color ? modColor,string modName="")
|
||||
{
|
||||
if (modColor == null) ModInfoColor = Color.Black;
|
||||
else ModInfoColor =(Color) modColor;
|
||||
|
@ -43,7 +44,11 @@ namespace StardustCore.ModInfo
|
|||
return array[array.Length-1];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// TODO: Add to check to chest inventory. See if I can grab activeclickable menu and instead hook the inventory component from it.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public static void GameEvents_UpdateTick(object sender, EventArgs e)
|
||||
{
|
||||
if (Game1.activeClickableMenu != null)
|
||||
|
@ -55,17 +60,16 @@ namespace StardustCore.ModInfo
|
|||
{
|
||||
StardewValley.Menus.IClickableMenu s = pages[(Game1.activeClickableMenu as GameMenu).currentTab];
|
||||
|
||||
// Log.AsyncG(s);
|
||||
|
||||
|
||||
foreach (var v in (s as StardewValley.Menus.InventoryPage).allClickableComponents)
|
||||
foreach (var v in s.allClickableComponents)
|
||||
{
|
||||
if (v.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
|
||||
{
|
||||
|
||||
if (v == null) return;
|
||||
if (v == null) continue;
|
||||
string fire = v.name;
|
||||
//Log.AsyncC(v.name);
|
||||
|
||||
|
||||
bool num = true;
|
||||
foreach (var v2 in fire)
|
||||
|
@ -81,27 +85,53 @@ namespace StardustCore.ModInfo
|
|||
{
|
||||
int inv = Convert.ToInt32(v.name);
|
||||
Item I = (s as StardewValley.Menus.InventoryPage).inventory.actualInventory[inv];
|
||||
// Log.AsyncM(I.Name);
|
||||
|
||||
string s1 = parseModNameFromType(I.GetType());
|
||||
string s2 = parseClassNameFromType(I.GetType());
|
||||
Log.AsyncC(s1);
|
||||
Log.AsyncO(s2);
|
||||
string s3 = Assembly.GetAssembly(I.GetType()).Location;
|
||||
s3 = Path.GetFileName(s3);
|
||||
|
||||
|
||||
//DRAW THE INFO BOX!!!
|
||||
try
|
||||
{
|
||||
SpriteBatch b = new SpriteBatch(Game1.graphics.GraphicsDevice);
|
||||
b.Begin();
|
||||
float boxX =Game1.getMouseX()- (Game1.viewport.Width * .20f);
|
||||
float boxX =Game1.getMouseX()- (Game1.viewport.Width * .25f);
|
||||
float boxY =Game1.getMouseY() - (Game1.viewport.Height * .05f);
|
||||
float boxWidth= (Game1.viewport.Width * .20f);
|
||||
float boxWidth= (Game1.viewport.Width * .25f);
|
||||
float boxHeight = (Game1.viewport.Height*.35f);
|
||||
Game1.drawDialogueBox((int)boxX,(int) boxY,(int)boxWidth, (int)boxHeight, false, true, null,false);
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, s1, Game1.smallFont, new Vector2(boxX+(Game1.viewport.Width*.05f), Game1.getMouseY()+(int)(Game1.viewport.Height*.05)), Color.Cyan, 1, -1);
|
||||
|
||||
float xText1XPos = boxX + (Game1.viewport.Width * .08f);
|
||||
float xText2XPos = boxX + (Game1.viewport.Width * .08f);
|
||||
if (s1.Length > 12)
|
||||
{
|
||||
s1 = "\n" + s1;
|
||||
xText1XPos = boxX + (Game1.viewport.Width * .025f);
|
||||
}
|
||||
|
||||
if (s2.Length > 12)
|
||||
{
|
||||
s2 = "\n" + s2;
|
||||
xText2XPos = boxX + (Game1.viewport.Width * .025f);
|
||||
}
|
||||
if (s3.Length > 12)
|
||||
{
|
||||
s3 = "\n" + s3;
|
||||
xText1XPos = boxX + (Game1.viewport.Width * .025f);
|
||||
}
|
||||
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, "Mod: ", Game1.smallFont, new Vector2(boxX + (Game1.viewport.Width * .025f), Game1.getMouseY() + (int)(Game1.viewport.Height * .1f)), Color.Black, 1, -1);
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, s3, Game1.smallFont, new Vector2(xText1XPos, Game1.getMouseY()+(int)(Game1.viewport.Height*.1f)), Color.Black, 1, -1);
|
||||
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, "Class: ", Game1.smallFont, new Vector2(boxX + (Game1.viewport.Width * .025f), Game1.getMouseY() + (int)(Game1.viewport.Height * .2f)), Color.Black, 1, -1);
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, s2, Game1.smallFont, new Vector2(xText2XPos, Game1.getMouseY() + (int)(Game1.viewport.Height * .2f)), I.getCategoryColor(), 1, -1);
|
||||
b.End();
|
||||
}
|
||||
catch(Exception errr)
|
||||
{
|
||||
Log.AsyncC(errr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -111,16 +141,112 @@ namespace StardustCore.ModInfo
|
|||
// Log.AsyncM(v.item.Name);
|
||||
// (s as StardewValley.Menus.InventoryPage).
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception err) //Try to parse a menu that isn't the default GameMenu
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Item> inventory = (List<Item>)Game1.activeClickableMenu.GetType().GetProperty("inventory").GetValue(Game1.activeClickableMenu, null);
|
||||
}
|
||||
catch(Exception errr)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
IClickableMenu s = (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu;
|
||||
if (s == null) return;
|
||||
int i = 0;
|
||||
foreach (var v in s.allClickableComponents)
|
||||
{
|
||||
i++;
|
||||
if (v.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
|
||||
{
|
||||
|
||||
if (v == null || v.name=="") continue;
|
||||
string fire = v.name;
|
||||
|
||||
bool num = true;
|
||||
foreach (var v2 in fire)
|
||||
{
|
||||
if (v2 != '0' && v2 != '1' && v2 != '2' && v2 != '3' && v2 != '4' && v2 != '5' && v2 != '6' && v2 != '7' && v2 != '8' && v2 != '9')
|
||||
{
|
||||
num = false;
|
||||
break;
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
|
||||
///NUM ISN't TRUE!?!?!?!?
|
||||
if (num == true)
|
||||
{
|
||||
int inv = Convert.ToInt32(v.name);
|
||||
Item I = (s as InventoryMenu).actualInventory[inv]; //Inventory Menu is the actual menu under ItemGrabMenu
|
||||
// Item I = (s as StardewValley.Menus.ItemGrabMenu).inventory.actualInventory[inv]; ///I isn't being grabbed???
|
||||
|
||||
string s1 = parseModNameFromType(I.GetType());
|
||||
string s2 = parseClassNameFromType(I.GetType());
|
||||
string s3 = Assembly.GetAssembly(I.GetType()).Location;
|
||||
s3 = Path.GetFileName(s3);
|
||||
|
||||
//Draw the info Box!
|
||||
try
|
||||
{
|
||||
|
||||
float boxX = Game1.getMouseX() - (Game1.viewport.Width * .25f);
|
||||
float boxY = Game1.getMouseY() - (Game1.viewport.Height * .05f);
|
||||
float boxWidth = (Game1.viewport.Width * .25f);
|
||||
float boxHeight = (Game1.viewport.Height * .35f);
|
||||
Game1.drawDialogueBox((int)boxX, (int)boxY, (int)boxWidth, (int)boxHeight, false, true, null, false);
|
||||
|
||||
float xText1XPos = boxX + (Game1.viewport.Width * .08f);
|
||||
float xText2XPos = boxX + (Game1.viewport.Width * .08f);
|
||||
if (s1.Length > 12)
|
||||
{
|
||||
s1 = "\n" + s1;
|
||||
xText1XPos = boxX + (Game1.viewport.Width * .025f);
|
||||
}
|
||||
|
||||
if (s2.Length > 12)
|
||||
{
|
||||
s2 = "\n" + s2;
|
||||
xText2XPos = boxX + (Game1.viewport.Width * .025f);
|
||||
}
|
||||
if (s3.Length > 12)
|
||||
{
|
||||
s3 = "\n" + s3;
|
||||
xText1XPos = boxX + (Game1.viewport.Width * .025f);
|
||||
}
|
||||
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, "Mod: ", Game1.smallFont, new Vector2(boxX + (Game1.viewport.Width * .025f), Game1.getMouseY() + (int)(Game1.viewport.Height * .1f)), Color.Black, 1, -1);
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, s3, Game1.smallFont, new Vector2(xText1XPos, Game1.getMouseY() + (int)(Game1.viewport.Height * .1f)), Color.Black, 1, -1);
|
||||
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, "Class: ", Game1.smallFont, new Vector2(boxX + (Game1.viewport.Width * .025f), Game1.getMouseY() + (int)(Game1.viewport.Height * .2f)), Color.Black, 1, -1);
|
||||
Utility.drawTextWithShadow(Game1.spriteBatch, s2, Game1.smallFont, new Vector2(xText2XPos, Game1.getMouseY() + (int)(Game1.viewport.Height * .2f)), I.getCategoryColor(), 1, -1);
|
||||
|
||||
}
|
||||
catch (Exception errrr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// if (v == null) continue;
|
||||
// Log.AsyncC(v.name);
|
||||
// Log.AsyncM(v.item.Name);
|
||||
// (s as StardewValley.Menus.InventoryPage).
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception err)
|
||||
catch(Exception errrr)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue