diff --git a/GeneralMods/Revitalize/Framework/Factories/Objects/FurnitureFactory.cs b/GeneralMods/Revitalize/Framework/Factories/Objects/FurnitureFactory.cs index c39d753c..217b5792 100644 --- a/GeneralMods/Revitalize/Framework/Factories/Objects/FurnitureFactory.cs +++ b/GeneralMods/Revitalize/Framework/Factories/Objects/FurnitureFactory.cs @@ -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())); diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index 55f5ce90..8b9d1a46 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -123,6 +123,8 @@ namespace Revitalize.Framework.Objects /// Checks for interaction with the object. 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!"); diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs index 5f5a34bb..5f19e21c 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs @@ -129,5 +129,22 @@ namespace Revitalize.Framework.Objects.Furniture } } + public override void pickUp() + { + + bool canPickUp = this.removeAndAddToPlayersInventory(); + if (canPickUp) + { + foreach (KeyValuePair 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"); + + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs index f3f6128e..fb2063c8 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs @@ -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)); diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs index e05e484a..c00bbfb5 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs @@ -323,5 +323,22 @@ namespace Revitalize.Framework.Utilities this.Serialize(path, obj); } + + /// + /// https://stackoverflow.com/questions/2742276/how-do-i-check-if-a-type-is-a-subtype-or-the-type-of-an-object + /// + /// + /// + /// + public bool IsSameOrSubclass(Type potentialBase, Type potentialDescendant) + { + return potentialDescendant.IsSubclassOf(potentialBase) + || potentialDescendant == potentialBase; + } + + public bool IsSubclass(Type potentialBase, Type potentialDescendant) + { + return potentialDescendant.IsSubclassOf(potentialBase); + } } } diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/SpriteBatchUtilities.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/SpriteBatchUtilities.cs new file mode 100644 index 00000000..a21f8019 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/SpriteBatchUtilities.cs @@ -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); + } + } + + } +} diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 8ba8f544..2304a54d 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -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: diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index c54ad75d..cf0f865b 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -92,6 +92,7 @@ +