Got multi-tiled objects and components working at a surprising speed actually.

This commit is contained in:
Joshua Navarro 2018-12-23 00:53:43 -08:00
parent 591a6f4a96
commit f46379f9e6
6 changed files with 356 additions and 3 deletions

View File

@ -30,6 +30,15 @@ namespace Revitalize.Framework.Graphics
this.modID = ""; this.modID = "";
} }
public Texture2DExtended(Texture2D Texture)
{
this.Name = "";
this.texture = Texture;
this.path = "";
this.helper = null;
this.modID = "";
}
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>

View File

@ -24,6 +24,8 @@ namespace Revitalize.Framework.Objects
public string id; public string id;
public BasicItemInformation info; public BasicItemInformation info;
public GameLocation location;
/// <summary> /// <summary>
/// The animation manager. /// The animation manager.
/// </summary> /// </summary>
@ -174,6 +176,8 @@ namespace Revitalize.Framework.Objects
{ {
Revitalize.ModCore.log("Clicky click!"); Revitalize.ModCore.log("Clicky click!");
Revitalize.ModCore.log(System.Environment.StackTrace);
return removeAndAddToPlayersInventory(); return removeAndAddToPlayersInventory();
//return base.clicked(who); //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)) if(t.GetType()== typeof(StardewValley.Tools.Axe) || t.GetType()== typeof(StardewValley.Tools.Pickaxe))
{ {
Game1.createItemDebris(this, Game1.player.getStandingPosition(), Game1.player.getDirection()); Game1.createItemDebris(this, Game1.player.getStandingPosition(), Game1.player.getDirection());
this.location = null;
Game1.player.currentLocation.removeObject(this.TileLocation, false); Game1.player.currentLocation.removeObject(this.TileLocation, false);
return false; return false;
} }
@ -209,6 +214,7 @@ namespace Revitalize.Framework.Objects
Game1.showRedMessage("Inventory full."); Game1.showRedMessage("Inventory full.");
return false; return false;
} }
this.location = null;
Game1.player.currentLocation.removeObject(this.TileLocation, false); Game1.player.currentLocation.removeObject(this.TileLocation, false);
Game1.player.addItemToInventory(this); Game1.player.addItemToInventory(this);
return true; return true;
@ -256,6 +262,7 @@ namespace Revitalize.Framework.Objects
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{ {
this.updateDrawPosition(); this.updateDrawPosition();
this.location = location;
return base.placementAction(location, x, y, who); return base.placementAction(location, x, y, who);
} }

View File

@ -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);
}
/// <summary>
/// Places an object down.
/// </summary>
/// <param name="location"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="who"></param>
/// <returns></returns>
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<string, string> 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;
}
}
}

View File

@ -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<Vector2, MultiTiledComponent> objects;
public MultiTiledObject() : base()
{
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
}
public MultiTiledObject(BasicItemInformation info) : base(info)
{
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
}
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation) : base(info, TileLocation)
{
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
}
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2,MultiTiledComponent> ObjectsList) : base(info, TileLocation)
{
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
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<Vector2, MultiTiledComponent> 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<Vector2, MultiTiledComponent> 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<Vector2, MultiTiledComponent> 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<Vector2,MultiTiledComponent> 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<Vector2, MultiTiledComponent> 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<Vector2,MultiTiledComponent> 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<Vector2,MultiTiledComponent> 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<string, string> additionalSaveData, object replacement)
{
BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]];
return new MultiTiledObject((BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation,this.objects);
}
}
}

View File

@ -9,6 +9,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Revitalize.Framework.Graphics;
using Revitalize.Framework.Graphics.Animations;
namespace Revitalize namespace Revitalize
{ {
@ -30,11 +32,18 @@ namespace Revitalize
private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) 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"); new InventoryItem(bigObject, 100,1).addToNPCShop("Gus");
Game1.player.addItemToInventory(obj); Game1.player.addItemToInventory(bigObject);
} }

View File

@ -50,6 +50,8 @@
<Compile Include="Framework\Graphics\Texture2DExtended.cs" /> <Compile Include="Framework\Graphics\Texture2DExtended.cs" />
<Compile Include="Framework\Objects\BasicItemInformation.cs" /> <Compile Include="Framework\Objects\BasicItemInformation.cs" />
<Compile Include="Framework\Objects\CustomObject.cs" /> <Compile Include="Framework\Objects\CustomObject.cs" />
<Compile Include="Framework\Objects\MultiTiledComponent.cs" />
<Compile Include="Framework\Objects\MultiTiledObject.cs" />
<Compile Include="ModCore.cs" /> <Compile Include="ModCore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>