Crafting menus fixed!

This commit is contained in:
Joshua Navarro 2018-07-18 17:41:38 -07:00 committed by GitHub
parent 2141c151ca
commit c4f6f981c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 149 additions and 80 deletions

View File

@ -167,6 +167,7 @@ namespace ShaderExample
var pageField = GetInstanceField(typeof(StardewValley.Menus.GameMenu), Game1.activeClickableMenu, "pages");
var pages = (List<IClickableMenu>)pageField;
var socialPage = pages.ElementAt(2);
var v = (StardewValley.Menus.SocialPage)socialPage;
if (v == null)
@ -251,7 +252,16 @@ namespace ShaderExample
IClickableMenu.drawHoverText(Game1.spriteBatch, hoverText, Game1.smallFont, 0, 0, -1, (string)null, -1, (string[])null, (Item)null, 0, -1, -1, -1, -1, 1f, (CraftingRecipe)null);
}
if((Game1.activeClickableMenu as StardewValley.Menus.GameMenu).currentTab == 4)
{
var pageField = GetInstanceField(typeof(StardewValley.Menus.GameMenu), Game1.activeClickableMenu, "pages");
var pages = (List<IClickableMenu>)pageField;
var craftingPage = pages.ElementAt(4);
Monitor.Log(craftingPage.GetType().ToString());
var v = (StardewValley.Menus.CraftingPage)craftingPage;
Framework.Drawers.Menus.craftingPageDraw((craftingPage as StardewValley.Menus.CraftingPage), Game1.spriteBatch);
}
Game1.activeClickableMenu.upperRightCloseButton.draw(Game1.spriteBatch);
Game1.activeClickableMenu.drawMouse(Game1.spriteBatch);
@ -265,7 +275,7 @@ namespace ShaderExample
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
Class1.effect.CurrentTechnique.Passes[0].Apply();
Monitor.Log(Game1.getMousePosition().ToString());
if(Game1.activeClickableMenu==null&& Game1.eventUp==false)getInvokeMethod(Program.gamePtr, "drawHUD", new object[] { });
drawMouse();
Game1.spriteBatch.End();
@ -276,7 +286,6 @@ namespace ShaderExample
drawMouse();
}
private int rowPosition(IClickableMenu menu,int i)
{
@ -285,7 +294,7 @@ namespace ShaderExample
int num2 = 112;
return menu.yPositionOnScreen + IClickableMenu.borderWidth + 160 + 4 + num1 * num2;
}
public void drawMapPart1()
@ -304,10 +313,10 @@ namespace ShaderExample
//Game1.spriteBatch.End();
}
public void getInvokeMethod(object target, string name ,object[] param)
public static object getInvokeMethod(object target, string name ,object[] param)
{
var hello=target.GetType().GetMethod(name, BindingFlags.Public | BindingFlags.NonPublic| BindingFlags.Instance| BindingFlags.Static);
hello.Invoke(target, param);
return hello.Invoke(target, param);
}
public void drawMapPart2()
@ -335,9 +344,19 @@ namespace ShaderExample
/// <returns></returns>
public static object GetInstanceField(Type type, object instance, string fieldName)
{
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
| BindingFlags.Static;
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic| BindingFlags.Static;
FieldInfo field = type.GetField(fieldName, bindFlags);
/*
FieldInfo[] meh = type.GetFields(bindFlags);
foreach(var v in meh)
{
if (v.Name == null)
{
continue;
}
Monitor.Log(v.Name);
}
*/
return field.GetValue(instance);
}
@ -350,73 +369,9 @@ namespace ShaderExample
return;
}
public void mouse(SpriteBatch b)
{
if (Game1.options.hardwareCursor)
return;
b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, !Game1.options.snappyMenus || !Game1.options.gamepadControls ? 0 : 44, 16, 16)), Color.White * Game1.mouseCursorTransparency, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
}
public void drawMouseCursor()
{
InputState input =(InputState) GetInstanceField(typeof(Game1), Program.gamePtr, "input");
if (Game1.timerUntilMouseFade > 0)
{
Game1.timerUntilMouseFade -= Game1.currentGameTime.ElapsedGameTime.Milliseconds;
if (Game1.timerUntilMouseFade <= 0)
Game1.lastMousePositionBeforeFade = Game1.getMousePosition();
}
if (Game1.options.gamepadControls && Game1.timerUntilMouseFade <= 0 && Game1.activeClickableMenu == null)
{
Game1.mouseCursorTransparency = 0.0f;
if (Program.gamePtr.IsActive)
{
IClickableMenu activeClickableMenu = Game1.activeClickableMenu;
}
}
if (Game1.activeClickableMenu == null && Game1.mouseCursor > -1)
{
MouseState mouseState =input.GetMouseState();
if (mouseState.X == 0)
{
mouseState = input.GetMouseState();
if (mouseState.Y == 0)
goto label_20;
}
if ((Game1.getOldMouseX() != 0 || Game1.getOldMouseY() != 0) && Game1.currentLocation != null)
{
if ((double)Game1.mouseCursorTransparency <= 0.0 || !Utility.canGrabSomethingFromHere(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y, Game1.player) || Game1.mouseCursor == 3)
{
if (Game1.player.ActiveObject != null && Game1.mouseCursor != 3 && !Game1.eventUp)
{
if ((double)Game1.mouseCursorTransparency > 0.0 || Game1.options.showPlacementTileForGamepad)
{
Game1.player.ActiveObject.drawPlacementBounds(Game1.spriteBatch, Game1.currentLocation);
if ((double)Game1.mouseCursorTransparency > 0.0)
{
bool flag = Utility.playerCanPlaceItemHere(Game1.currentLocation, Game1.player.CurrentItem, Game1.getMouseX() + Game1.viewport.X, Game1.getMouseY() + Game1.viewport.Y, Game1.player) || Utility.isThereAnObjectHereWhichAcceptsThisItem(Game1.currentLocation, Game1.player.CurrentItem, Game1.getMouseX() + Game1.viewport.X, Game1.getMouseY() + Game1.viewport.Y) && Utility.withinRadiusOfPlayer(Game1.getMouseX() + Game1.viewport.X, Game1.getMouseY() + Game1.viewport.Y, 1, Game1.player);
Game1.player.CurrentItem.drawInMenu(Game1.spriteBatch, new Vector2((float)(Game1.getMouseX() + 16), (float)(Game1.getMouseY() + 16)), flag ? (float)((double)Game1.dialogueButtonScale / 75.0 + 1.0) : 1f, flag ? 1f : 0.5f, 0.999f);
}
}
}
else if (Game1.mouseCursor == 0 && Game1.isActionAtCurrentCursorTile)
Game1.mouseCursor = Game1.isInspectionAtCurrentCursorTile ? 5 : 2;
}
if (!Game1.options.hardwareCursor)
Game1.spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, Game1.mouseCursor, 16, 16)), Color.White * Game1.mouseCursorTransparency, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
Game1.wasMouseVisibleThisFrame = (double)Game1.mouseCursorTransparency > 0.0;
}
}
label_20:
Game1.mouseCursor = 0;
if (Game1.isActionAtCurrentCursorTile || Game1.activeClickableMenu != null)
return;
Game1.mouseCursorTransparency = 1f;
}
public void drawMouse()
{
if ((Game1.getOldMouseX() != 0 || Game1.getOldMouseY() != 0) && Game1.currentLocation != null)
{
if ((double)Game1.mouseCursorTransparency <= 0.0 || !Utility.canGrabSomethingFromHere(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y, Game1.player) || Game1.mouseCursor == 3)
@ -435,18 +390,18 @@ namespace ShaderExample
}
else if (Game1.mouseCursor == 0 && Game1.isActionAtCurrentCursorTile)
{
Game1.mouseCursor = Game1.isInspectionAtCurrentCursorTile ? 5 : 2;
}
}
if (!Game1.options.hardwareCursor)
{
Game1.mouseCursorTransparency = 0.0001f;
Game1.spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, Game1.mouseCursor, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
}
Game1.wasMouseVisibleThisFrame = (double)Game1.mouseCursorTransparency > 0.0;
Game1.wasMouseVisibleThisFrame = (double)Game1.mouseCursorTransparency > 0.0;
}
/*
@ -457,11 +412,10 @@ namespace ShaderExample
Game1.spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMousePosition().X, (float)Game1.getMousePosition().Y), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, Game1.mouseCursor, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
}
*/
}
}
protected void drawOverlays()
{
SpriteBatch spriteBatch = Game1.spriteBatch;

View File

@ -0,0 +1,115 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShaderExample.Framework.Drawers
{
class Menus
{
public static void craftingPageDraw(StardewValley.Menus.CraftingPage menu, SpriteBatch b)
{
int craftingPage = (int)Class1.GetInstanceField(typeof(StardewValley.Menus.CraftingPage), menu, "currentCraftingPage");
bool cooking = (bool)Class1.GetInstanceField(typeof(StardewValley.Menus.CraftingPage), menu, "cooking");
if (cooking)
Game1.drawDialogueBox(menu.xPositionOnScreen, menu.yPositionOnScreen, menu.width, menu.height, false, true, (string)null, false);
Class1.getInvokeMethod(menu, "drawHorizontalPartition", new object[] {
b, menu.yPositionOnScreen + IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + 256, false
});
menu.inventory.draw(b);
if (menu.trashCan != null)
{
menu.trashCan.draw(b);
b.Draw(Game1.mouseCursors, new Vector2((float)(menu.trashCan.bounds.X + 60), (float)(menu.trashCan.bounds.Y + 40)), new Rectangle?(new Rectangle(686, 256, 18, 10)), Color.White, menu.trashCanLidRotation, new Vector2(16f, 10f), 4f, SpriteEffects.None, 0.86f);
}
//b.End();
//b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
IList<Item> fridge = (IList<Item>)Class1.getInvokeMethod(menu, "fridge", new object[] { });
foreach (ClickableTextureComponent key in menu.pagesOfCraftingRecipes[craftingPage].Keys)
{
if (key.hoverText.Equals("ghosted"))
key.draw(b, Color.Black * 0.35f, 0.89f);
else if (!menu.pagesOfCraftingRecipes[craftingPage][key].doesFarmerHaveIngredientsInInventory(cooking ? fridge : (IList<Item>)null))
{
key.draw(b, Color.LightGray * 0.4f, 0.89f);
}
else
{
key.draw(b);
if (menu.pagesOfCraftingRecipes[craftingPage][key].numberProducedPerCraft > 1)
NumberSprite.draw(menu.pagesOfCraftingRecipes[craftingPage][key].numberProducedPerCraft, b, new Vector2((float)(key.bounds.X + 64 - 2), (float)(key.bounds.Y + 64 - 2)), Color.Red, (float)(0.5 * ((double)key.scale / 4.0)), 0.97f, 1f, 0, 0);
}
}
//b.End();
//b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
Item hoverItem = (Item)Class1.GetInstanceField(menu.GetType(), menu, "hoverItem");
Item heldItem = (Item)Class1.GetInstanceField(menu.GetType(), menu, "heldItem");
Item lastCookingHover = (Item)Class1.GetInstanceField(menu.GetType(), menu, "lastCookingHover");
string hoverText = (string)Class1.GetInstanceField(menu.GetType(), menu, "hoverText");
string hoverTitle = (string)Class1.GetInstanceField(menu.GetType(), menu, "hoverTitle");
CraftingRecipe hoverRecipe = (CraftingRecipe)Class1.GetInstanceField(menu.GetType(), menu, "hoverRecipe");
if (hoverItem != null)
IClickableMenu.drawToolTip(b, hoverText, hoverTitle, hoverItem, heldItem != null, -1, 0, -1, -1, (CraftingRecipe)null, -1);
else if (!string.IsNullOrEmpty(hoverText))
IClickableMenu.drawHoverText(b, hoverText, Game1.smallFont, heldItem != null ? 64 : 0, heldItem != null ? 64 : 0, -1, (string)null, -1, (string[])null, (Item)null, 0, -1, -1, -1, -1, 1f, (CraftingRecipe)null);
if (heldItem != null)
heldItem.drawInMenu(b, new Vector2((float)(Game1.getOldMouseX() + 16), (float)(Game1.getOldMouseY() + 16)), 1f);
//(menu as IClickableMenu).draw(b);
if (menu.downButton != null && craftingPage < menu.pagesOfCraftingRecipes.Count - 1)
menu.downButton.draw(b);
if (menu.upButton != null && craftingPage > 0)
menu.upButton.draw(b);
//if (cooking)
//drawMouse(b);
if (hoverRecipe == null)
return;
SpriteBatch b1 = b;
string text = " ";
SpriteFont smallFont = Game1.smallFont;
int xOffset = heldItem != null ? 48 : 0;
int yOffset = heldItem != null ? 48 : 0;
int moneyAmountToDisplayAtBottom = -1;
string displayName = hoverRecipe.DisplayName;
int healAmountToDisplay = -1;
string[] buffIconsToDisplay;
if (cooking && lastCookingHover != null)
{
if (Game1.objectInformation[(int)((lastCookingHover as StardewValley.Object).parentSheetIndex)].Split('/').Length > 7)
{
buffIconsToDisplay = Game1.objectInformation[(int)((lastCookingHover as StardewValley.Object).parentSheetIndex)].Split('/')[7].Split(' ');
goto label_32;
}
}
buffIconsToDisplay = (string[])null;
label_32:
Item lastCookingHover2 = lastCookingHover;
int currencySymbol = 0;
int extraItemToShowIndex = -1;
int extraItemToShowAmount = -1;
int overrideX = -1;
int overrideY = -1;
double num = 1.0;
CraftingRecipe hoverRecipe2 = hoverRecipe;
IClickableMenu.drawHoverText(b1, text, smallFont, xOffset, yOffset, moneyAmountToDisplayAtBottom, displayName, healAmountToDisplay, buffIconsToDisplay, lastCookingHover2, currencySymbol, extraItemToShowIndex, extraItemToShowAmount, overrideX, overrideY, (float)num, hoverRecipe2);
}
}
}

View File

@ -1 +1 @@
d435c4e4ec5503281ab00282b8e1921cd31d8660
acb7ac65c1444ef93858a2b1dce3b3956fc32fd6