Fixed tabled held object logic.

This commit is contained in:
JoshuaNavarro 2019-05-15 22:27:38 -07:00
parent 7eaaa44910
commit e63b48ab6a
8 changed files with 227 additions and 10 deletions

View File

@ -174,12 +174,12 @@ namespace Revitalize.Framework.Factories.Objects
private static void SerializeTableFiles()
{
TableTileComponent upperLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"),new Animation(new Rectangle(0,0,16,16),-1)),Color.White,true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(false));
TableTileComponent upperRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 0, 16, 16), -1)), Color.White, true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(false));
TableTileComponent centerLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(0, 16, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(false));
TableTileComponent centerRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 16, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(false));
TableTileComponent bottomLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(0, 32, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(false));
TableTileComponent bottomRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 32, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(false));
TableTileComponent upperLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"),new Animation(new Rectangle(0,0,16,16),-1)),Color.White,true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent upperRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 0, 16, 16), -1)), Color.White, true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent centerLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(0, 16, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent centerRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 16, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent bottomLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(0, 32, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent bottomRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 32, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableMultiTiledObject obj = new TableMultiTiledObject(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 350, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableMultiTiledObject), null, new AnimationManager(), Color.White, false, new Utilities.InventoryManager(), new LightManager()));

View File

@ -123,6 +123,8 @@ namespace Revitalize.Framework.Objects
/// <summary>Checks for interaction with the object.</summary>
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
{
MouseState mState = Mouse.GetState();
KeyboardState keyboardState = Game1.GetKeyboardState();
@ -135,6 +137,8 @@ namespace Revitalize.Framework.Objects
if (mState.RightButton == ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)))
return this.shiftRightClicked(who);
return base.checkForAction(who, justCheckingForActivity);
if (justCheckingForActivity)
return true;
ModCore.log("Left clicked!");

View File

@ -129,5 +129,22 @@ namespace Revitalize.Framework.Objects.Furniture
}
}
public override void pickUp()
{
bool canPickUp = this.removeAndAddToPlayersInventory();
if (canPickUp)
{
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
{
(pair.Value as TableTileComponent).removeFromLocation((pair.Value as TableTileComponent).location, pair.Key);
(pair.Value as TableTileComponent).pickUpItem(true);
}
this.location = null;
}
else
Game1.showRedMessage("NOOOOOOOO");
}
}
}

View File

@ -7,6 +7,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PyTK.CustomElementHandler;
using Revitalize.Framework.Objects.InformationFiles.Furniture;
using Revitalize.Framework.Utilities.Serialization;
using StardewValley;
namespace Revitalize.Framework.Objects.Furniture
@ -15,6 +16,18 @@ namespace Revitalize.Framework.Objects.Furniture
{
public TableInformation furnitureInfo;
public StardewValley.Object heldItem
{
get
{
return this.heldObject.Value;
}
set
{
this.heldObject.Value = value;
}
}
public bool CanPlaceItemsHere
{
get
@ -23,6 +36,12 @@ namespace Revitalize.Framework.Objects.Furniture
}
}
public enum PickUpState
{
RemoveContainer,
DoNothing,
}
public TableTileComponent() : base()
{
@ -40,18 +59,127 @@ namespace Revitalize.Framework.Objects.Furniture
}
public override bool clicked(Farmer who)
public PickUpState pickUpItem(bool forCleanUp = false)
{
return base.clicked(who);
ModCore.log("Pick up!");
if (this.CanPlaceItemsHere == false) return PickUpState.DoNothing;
if (forCleanUp == true)
{
ModCore.log("Clean up: " + this.TileLocation);
if (this.heldItem != null)
{
if (Game1.player.isInventoryFull() == true)
{
Game1.createItemDebris(this.heldItem.getOne(), Vector2.Zero, 0, this.location);
this.heldItem = null;
return PickUpState.DoNothing;
}
else
{
Game1.player.addItemToInventoryBool(this.heldItem.getOne());
this.heldItem = null;
return PickUpState.DoNothing;
}
}
else
{
ModCore.log("Nothing here...");
return PickUpState.DoNothing;
}
}
if (this.heldItem == null)
{
if (this.CanPlaceItemsHere == true && this.heldItem == null && Game1.player.ActiveObject != null)
{
ModCore.log("Hello1");
this.heldItem = (StardewValley.Object)Game1.player.ActiveObject.getOne();
Game1.player.reduceActiveItemByOne();
ModCore.log(System.Environment.StackTrace);
return PickUpState.DoNothing;
}
else if (this.CanPlaceItemsHere == true && this.heldItem == null && Game1.player.ActiveObject == null)
{
return PickUpState.RemoveContainer;
}
return PickUpState.DoNothing;
}
else if(this.heldItem!=null)
{
if (this.CanPlaceItemsHere == true && this.heldItem != null && Game1.player.ActiveObject == null)
{
ModCore.log("Hello2");
if (Game1.player.isInventoryFull() == false)
{
Game1.player.addItemToInventoryBool(this.heldItem);
this.heldItem = null;
ModCore.log("Get rid of it11111");
return PickUpState.DoNothing;
}
else
{
ModCore.log("I'm not sure....");
//do nothing.
return PickUpState.DoNothing;
}
}
else if (this.CanPlaceItemsHere == true && this.heldItem != null && Game1.player.ActiveObject != null)
{
ModCore.log("Hello3");
if (Game1.player.isInventoryFull() == false)
{
Game1.player.addItemToInventoryBool(this.heldItem);
this.heldItem = null;
ModCore.log("Get rid of it222222");
ModCore.log(System.Environment.StackTrace);
return PickUpState.DoNothing;
}
else
{
ModCore.log("I'm not sure....");
//do nothing.
return PickUpState.DoNothing;
}
}
}
return PickUpState.DoNothing;
}
public override bool performObjectDropInAction(Item dropInItem, bool probe, Farmer who)
{
ModCore.log("DropInAnItem");
return false;
//return base.performObjectDropInAction(dropInItem, probe, who);
}
public override bool rightClicked(Farmer who)
public override bool performDropDownAction(Farmer who)
{
ModCore.log("HELLO WORLD!!!!");
return base.performDropDownAction(who);
}
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
{
return base.checkForAction(who, justCheckingForActivity);
}
public override bool clicked(Farmer who)
{
ModCore.log("Click a table");
if (this.pickUpItem() == PickUpState.DoNothing) return false;
else
{
return base.clicked(who);
}
///Not sure.
return true;
return false;
//return base.rightClicked(who);
}
public override bool shiftRightClicked(Farmer who)
{
return base.shiftRightClicked(who);
@ -159,6 +287,7 @@ namespace Revitalize.Framework.Objects.Furniture
{
ModCore.ModMonitor.Log(err.ToString());
}
if (this.heldItem != null) SpriteBatchUtilities.Draw(spriteBatch, this, this.heldItem, alpha, 99f);
}
// spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0));

View File

@ -323,5 +323,22 @@ namespace Revitalize.Framework.Utilities
this.Serialize(path, obj);
}
/// <summary>
/// https://stackoverflow.com/questions/2742276/how-do-i-check-if-a-type-is-a-subtype-or-the-type-of-an-object
/// </summary>
/// <param name="potentialBase"></param>
/// <param name="potentialDescendant"></param>
/// <returns></returns>
public bool IsSameOrSubclass(Type potentialBase, Type potentialDescendant)
{
return potentialDescendant.IsSubclassOf(potentialBase)
|| potentialDescendant == potentialBase;
}
public bool IsSubclass(Type potentialBase, Type potentialDescendant)
{
return potentialDescendant.IsSubclassOf(potentialBase);
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Revitalize.Framework.Objects;
using StardewValley;
namespace Revitalize.Framework.Utilities.Serialization
{
public class SpriteBatchUtilities
{
public static void Draw(SpriteBatch spriteBatch, CustomObject obj, StardewValley.Item itemToDraw,float alpha,float addedDepth)
{
if (itemToDraw.GetType()==typeof(StardewValley.Object))
{
Rectangle rectangle;
SpriteBatch spriteBatch1 = spriteBatch;
Texture2D shadowTexture = Game1.shadowTexture;
Vector2 position = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(obj.TileLocation.X), (float)(obj.TileLocation.Y)));
Rectangle? sourceRectangle = new Rectangle?(Game1.shadowTexture.Bounds);
Color color = Color.White * alpha;
rectangle = Game1.shadowTexture.Bounds;
double x1 = (double)rectangle.Center.X;
rectangle = Game1.shadowTexture.Bounds;
double y1 = (double)rectangle.Center.Y;
Vector2 origin = new Vector2((float)x1, (float)y1);
double num = (double)obj.boundingBox.Bottom / 10000.0;
spriteBatch1.Draw(shadowTexture, position, sourceRectangle, color, 0.0f, origin, 4f, SpriteEffects.None, (float)num);
spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(obj.boundingBox.Center.X - 32), (float)(obj.boundingBox.Center.Y))), obj.animationManager.currentAnimation.sourceRectangle, Color.White * alpha, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, ((float)(obj.boundingBox.Bottom + 1) / 10000f)+ addedDepth);
}
if (ModCore.Serializer.IsSameOrSubclass(typeof(CustomObject),itemToDraw.GetType()))
{
(itemToDraw as CustomObject).draw(spriteBatch,(int)obj.TileLocation.X, (int)obj.TileLocation.Y);
}
}
}
}

View File

@ -20,9 +20,16 @@ using StardewValley.Objects;
namespace Revitalize
{
//Bugs:
// -Chair tops cut off objects
// -ignoring bounding box cuts off objects
// -Tables don't draw their held objects
// TODO:
//
//
//
// -Multiple Lights On Object
// -Illumination Colors
// Furniture:

View File

@ -92,6 +92,7 @@
<Compile Include="Framework\Utilities\Serialization\Converters\Texture2DConverter.cs" />
<Compile Include="Framework\Utilities\Serialization\Converters\Vector2Converter.cs" />
<Compile Include="Framework\Utilities\Serialization\Serialization.cs" />
<Compile Include="Framework\Utilities\Serialization\SpriteBatchUtilities.cs" />
<Compile Include="ModCore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>