diff --git a/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs b/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs index af6d4499..3d316a96 100644 --- a/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs +++ b/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs @@ -30,6 +30,15 @@ namespace Revitalize.Framework.Graphics this.modID = ""; } + public Texture2DExtended(Texture2D Texture) + { + this.Name = ""; + this.texture = Texture; + this.path = ""; + this.helper = null; + this.modID = ""; + } + /// /// Constructor. /// diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index 9e208fe1..e9c7d6ce 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -24,6 +24,8 @@ namespace Revitalize.Framework.Objects public string id; public BasicItemInformation info; + public GameLocation location; + /// /// The animation manager. /// @@ -174,6 +176,8 @@ namespace Revitalize.Framework.Objects { Revitalize.ModCore.log("Clicky click!"); + Revitalize.ModCore.log(System.Environment.StackTrace); + return removeAndAddToPlayersInventory(); //return base.clicked(who); } @@ -190,6 +194,7 @@ namespace Revitalize.Framework.Objects if(t.GetType()== typeof(StardewValley.Tools.Axe) || t.GetType()== typeof(StardewValley.Tools.Pickaxe)) { Game1.createItemDebris(this, Game1.player.getStandingPosition(), Game1.player.getDirection()); + this.location = null; Game1.player.currentLocation.removeObject(this.TileLocation, false); return false; } @@ -209,6 +214,7 @@ namespace Revitalize.Framework.Objects Game1.showRedMessage("Inventory full."); return false; } + this.location = null; Game1.player.currentLocation.removeObject(this.TileLocation, false); Game1.player.addItemToInventory(this); return true; @@ -256,6 +262,7 @@ namespace Revitalize.Framework.Objects public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { this.updateDrawPosition(); + this.location = location; return base.placementAction(location, x, y, who); } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs new file mode 100644 index 00000000..b0c366d4 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -0,0 +1,110 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using PyTK.CustomElementHandler; +using StardewValley; +using StardewValley.Objects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Revitalize.Framework.Objects +{ + public class MultiTiledComponent:CustomObject + { + + public MultiTiledObject containerObject; + + public MultiTiledComponent():base() + { + + } + + public MultiTiledComponent(BasicItemInformation info):base(info) + { + + } + + public MultiTiledComponent(BasicItemInformation info, Vector2 TileLocation): base(info, TileLocation) + { + + } + + public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) + { + //Revitalize.ModCore.log("Checking for a clicky click???"); + return base.checkForAction(who, justCheckingForActivity); + } + + public override bool clicked(Farmer who) + { + + Revitalize.ModCore.log("Clicked a multiTiledComponent!"); + this.containerObject.pickUp(); + return true; + //return base.clicked(who); + } + + + + public override void performRemoveAction(Vector2 tileLocation, GameLocation environment) + { + base.performRemoveAction(this.TileLocation, environment); + } + + public virtual void removeFromLocation(GameLocation location,Vector2 offset) + { + location.removeObject(this.TileLocation,false); + //this.performRemoveAction(this.TileLocation,location); + } + + /// + /// Places an object down. + /// + /// + /// + /// + /// + /// + public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) + { + Revitalize.ModCore.ModMonitor.Log("SCREAMING!!!!"); + this.updateDrawPosition(); + this.location = location; + + this.TileLocation = new Vector2((int)(x / Game1.tileSize), (int)(y / Game1.tileSize)); + + return base.placementAction(location, x, y, who); + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) + { + if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1) + Utility.drawTinyDigits(this.Stack, spriteBatch, location + new Vector2((float)(Game1.tileSize - Utility.getWidthOfTinyDigitString(this.Stack, 3f * scaleSize)) + 3f * scaleSize, (float)((double)Game1.tileSize - 18.0 * (double)scaleSize + 2.0)), 3f * scaleSize, 1f, Color.White); + if (drawStackNumber && this.Quality > 0) + { + float num = this.Quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); + spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.Quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.Quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth); + } + spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * .75)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), scaleSize, SpriteEffects.None, layerDepth); + } + + public override Item getOne() + { + MultiTiledComponent component=new MultiTiledComponent(this.info, this.TileLocation); + component.containerObject = this.containerObject; + return component; + + } + + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; + MultiTiledComponent component= new MultiTiledComponent((BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation); + component.containerObject = this.containerObject; + return containerObject; + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs new file mode 100644 index 00000000..bc30ba63 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -0,0 +1,216 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using PyTK.CustomElementHandler; +using StardewValley; +using StardewValley.Objects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Revitalize.Framework.Objects +{ + public class MultiTiledObject:CustomObject + { + public Dictionary objects; + + public MultiTiledObject() : base() + { + + this.objects = new Dictionary(); + } + + public MultiTiledObject(BasicItemInformation info) : base(info) + { + this.objects = new Dictionary(); + } + + public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation) : base(info, TileLocation) + { + this.objects = new Dictionary(); + } + + public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary ObjectsList) : base(info, TileLocation) + { + this.objects = new Dictionary(); + foreach(var v in ObjectsList) + { + MultiTiledComponent component =(MultiTiledComponent)v.Value.getOne(); + this.addComponent(v.Key, component); + } + } + + public bool addComponent(Vector2 key, MultiTiledComponent obj) + { + if (this.objects.ContainsKey(key)) + { + return false; + } + else + { + this.objects.Add(key, obj); + obj.containerObject = this; + return true; + } + } + + public bool removeComponent(Vector2 key) + { + if (!this.objects.ContainsKey(key)) + { + return false; + } + else + { + this.objects.Remove(key); + return true; + } + } + + public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) + { + foreach (KeyValuePair pair in this.objects) + { + pair.Value.draw(spriteBatch, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, alpha); + } + } + + public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) + { + foreach (KeyValuePair pair in this.objects) + { + pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile+ (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha); + } + + //base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha); + } + + public override void drawAsProp(SpriteBatch b) + { + base.drawAsProp(b); + } + + public override void drawAttachments(SpriteBatch b, int x, int y) + { + base.drawAttachments(b, x, y); + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) + { + foreach (KeyValuePair pair in this.objects) + { + pair.Value.drawInMenu(spriteBatch, location + (pair.Key*16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow); + } + //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow); + } + + public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) + { + base.drawPlacementBounds(spriteBatch, location); + } + + public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f) + { + + foreach(KeyValuePair pair in this.objects) + { + pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f); + } + //base.drawWhenHeld(spriteBatch, objectPosition, f); + } + + + + //IMPLEMENT THESE! + + + public virtual void pickUp() + { + bool canPickUp= this.removeAndAddToPlayersInventory(); + if (canPickUp) + { + foreach (KeyValuePair pair in this.objects) + { + pair.Value.removeFromLocation(pair.Value.location,pair.Key); + } + this.location = null; + } + else + { + Game1.showRedMessage("NOOOOOOOO"); + } + } + + public override bool removeAndAddToPlayersInventory() + { + if (Game1.player.isInventoryFull()) + { + Game1.showRedMessage("Inventory full."); + return false; + } + Game1.player.addItemToInventory(this); + return true; + } + + public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) + { + + foreach(KeyValuePair pair in this.objects) + { + pair.Value.placementAction(location, x + (int)pair.Key.X*Game1.tileSize, y + (int)pair.Key.Y*Game1.tileSize, who); + Revitalize.ModCore.log(pair.Value.TileLocation); + } + this.location = location; + return true; + //return base.placementAction(location, x, y, who); + } + + public override bool canBePlacedHere(GameLocation l, Vector2 tile) + { + foreach(KeyValuePair pair in this.objects) + { + if (pair.Value.canBePlacedHere(l, tile + pair.Key) == false) return false; + } + return true; + + } + public override bool clicked(Farmer who) + { + Revitalize.ModCore.log("WTF IS HAPPENING???"); + bool cleanUp=clicked(who); + if (cleanUp) + { + pickUp(); + } + return cleanUp; + } + + public override bool rightClicked(Farmer who) + { + return base.rightClicked(who); + } + + public override bool shiftRightClicked(Farmer who) + { + return base.shiftRightClicked(who); + } + + public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) + { + + return base.checkForAction(who, justCheckingForActivity); + } + + public override Item getOne() + { + return new MultiTiledObject(this.info, this.TileLocation,this.objects); + } + + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; + return new MultiTiledObject((BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation,this.objects); + } + } +} diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 924875d8..427e08e9 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -9,6 +9,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Revitalize.Framework.Graphics; +using Revitalize.Framework.Graphics.Animations; namespace Revitalize { @@ -30,11 +32,18 @@ namespace Revitalize private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) { - CustomObject obj = new CustomObject(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.CoreObject",Color.Violet,-300,0,false,100,Vector2.Zero,true,true,"Omegasis.bleh", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(CustomObject),null,new Framework.Graphics.Animations.AnimationManager(),Color.Red)); + MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.MultiTiledComponent",Color.White,-300,0,false,100,Vector2.Zero,true,true,"Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(MultiTiledComponent),null,new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet),new Animation(new Rectangle(0,0,16,16))),Color.Red)); + MultiTiledComponent obj2 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest2", "SomeFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red)); + MultiTiledComponent obj3 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest3", "NoFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red)); + + MultiTiledObject bigObject= new MultiTiledObject(new BasicItemInformation("MultiTest", "A really big object", "Omegasis.Revitalize.MultiTiledObject", Color.Blue, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.BigTiledTest", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White)); + bigObject.addComponent(new Vector2(0, 0), obj); + bigObject.addComponent(new Vector2(1, 0), obj2); + bigObject.addComponent(new Vector2(2, 0), obj3); - new InventoryItem(obj, 100,1).addToNPCShop("Gus"); - Game1.player.addItemToInventory(obj); + new InventoryItem(bigObject, 100,1).addToNPCShop("Gus"); + Game1.player.addItemToInventory(bigObject); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index b74de180..dd1f7f2a 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -50,6 +50,8 @@ + +