Got customizable draw colors working.

This commit is contained in:
Joshua Navarro 2018-12-22 22:55:03 -08:00
parent 65ab0812b7
commit 591a6f4a96
3 changed files with 135 additions and 14 deletions

View File

@ -27,6 +27,8 @@ namespace Revitalize.Framework.Objects
public AnimationManager animationManager; public AnimationManager animationManager;
public Vector2 drawPosition; public Vector2 drawPosition;
public Color drawColor;
public BasicItemInformation() : base() public BasicItemInformation() : base()
{ {
name = ""; name = "";
@ -41,9 +43,10 @@ namespace Revitalize.Framework.Objects
this.animationManager = null; this.animationManager = null;
this.drawPosition = Vector2.Zero; this.drawPosition = Vector2.Zero;
this.drawColor = Color.White;
} }
public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData) public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager,Color DrawColor):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData)
{ {
this.name = name; this.name = name;
this.description = description; this.description = description;
@ -71,6 +74,16 @@ namespace Revitalize.Framework.Objects
this.drawPosition = Vector2.Zero; this.drawPosition = Vector2.Zero;
if (DrawColor == null)
{
this.drawColor = Color.White;
}
else
{
this.drawColor = DrawColor;
}
recreateDataString(); recreateDataString();
} }

View File

@ -16,7 +16,7 @@ using System.Threading.Tasks;
namespace Revitalize.Framework.Objects namespace Revitalize.Framework.Objects
{ {
/// <summary> /// <summary>
/// Change draw functions. /// A custom object template.
/// </summary> /// </summary>
public class CustomObject : PySObject public class CustomObject : PySObject
{ {
@ -24,7 +24,9 @@ namespace Revitalize.Framework.Objects
public string id; public string id;
public BasicItemInformation info; public BasicItemInformation info;
/// <summary>
/// The animation manager.
/// </summary>
public AnimationManager animationManager public AnimationManager animationManager
{ {
get get
@ -33,7 +35,9 @@ namespace Revitalize.Framework.Objects
} }
} }
/// <summary>
/// The display texture for this object.
/// </summary>
public Texture2D displayTexture public Texture2D displayTexture
{ {
get get
@ -42,24 +46,38 @@ namespace Revitalize.Framework.Objects
} }
} }
/// <summary>
/// Empty constructor.
/// </summary>
public CustomObject() public CustomObject()
{ {
} }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="info"></param>
public CustomObject(BasicItemInformation info):base(info,Vector2.Zero) public CustomObject(BasicItemInformation info):base(info,Vector2.Zero)
{ {
this.info = info; this.info = info;
this.initializeBasics(); this.initializeBasics();
} }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="info"></param>
/// <param name="TileLocation"></param>
public CustomObject(BasicItemInformation info,Vector2 TileLocation) : base(info, TileLocation) public CustomObject(BasicItemInformation info,Vector2 TileLocation) : base(info, TileLocation)
{ {
this.info = info; this.info = info;
this.initializeBasics(); this.initializeBasics();
} }
/// <summary>
/// Sets some basic information up.
/// </summary>
public virtual void initializeBasics() public virtual void initializeBasics()
{ {
this.name = info.name; this.name = info.name;
@ -78,6 +96,12 @@ namespace Revitalize.Framework.Objects
} }
/// <summary>
/// Checks for interaction with the object.
/// </summary>
/// <param name="who"></param>
/// <param name="justCheckingForActivity"></param>
/// <returns></returns>
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
{ {
var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); var mState = Microsoft.Xna.Framework.Input.Mouse.GetState();
@ -107,7 +131,11 @@ namespace Revitalize.Framework.Objects
return new CustomObject((BasicItemInformation) CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation); return new CustomObject((BasicItemInformation) CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation);
} }
/// <summary>
/// What happens when the player right clicks the object.
/// </summary>
/// <param name="who"></param>
/// <returns></returns>
public virtual bool rightClicked(Farmer who) public virtual bool rightClicked(Farmer who)
{ {
// Game1.showRedMessage("YOOO"); // Game1.showRedMessage("YOOO");
@ -126,12 +154,22 @@ namespace Revitalize.Framework.Objects
return true; return true;
} }
/// <summary>
/// What happens when the player shift-right clicks this object.
/// </summary>
/// <param name="who"></param>
/// <returns></returns>
public virtual bool shiftRightClicked(Farmer who) public virtual bool shiftRightClicked(Farmer who)
{ {
Revitalize.ModCore.log("Shift right clicked!"); Revitalize.ModCore.log("Shift right clicked!");
return true; return true;
} }
/// <summary>
/// What happens when the player left clicks the object.
/// </summary>
/// <param name="who"></param>
/// <returns></returns>
public override bool clicked(Farmer who) public override bool clicked(Farmer who)
{ {
Revitalize.ModCore.log("Clicky click!"); Revitalize.ModCore.log("Clicky click!");
@ -140,6 +178,12 @@ namespace Revitalize.Framework.Objects
//return base.clicked(who); //return base.clicked(who);
} }
/// <summary>
/// What happens when a player uses a tool on this object.
/// </summary>
/// <param name="t"></param>
/// <param name="location"></param>
/// <returns></returns>
public override bool performToolAction(Tool t, GameLocation location) public override bool performToolAction(Tool t, GameLocation location)
{ {
@ -154,6 +198,10 @@ namespace Revitalize.Framework.Objects
//return base.performToolAction(t, location); //return base.performToolAction(t, location);
} }
/// <summary>
/// Remove the object from the world and add it to the player's inventory if possible.
/// </summary>
/// <returns></returns>
public virtual bool removeAndAddToPlayersInventory() public virtual bool removeAndAddToPlayersInventory()
{ {
if (Game1.player.isInventoryFull()) if (Game1.player.isInventoryFull())
@ -166,17 +214,29 @@ namespace Revitalize.Framework.Objects
return true; return true;
} }
/// <summary>
/// Gets the category color for the object.
/// </summary>
/// <returns></returns>
public override Color getCategoryColor() public override Color getCategoryColor()
{ {
return info.categoryColor; return info.categoryColor;
//return data.categoryColor; //return data.categoryColor;
} }
/// <summary>
/// Gets the category name for the object.
/// </summary>
/// <returns></returns>
public override string getCategoryName() public override string getCategoryName()
{ {
return info.categoryName; return info.categoryName;
} }
/// <summary>
/// Gets the description for the object.
/// </summary>
/// <returns></returns>
public override string getDescription() public override string getDescription()
{ {
string text = info.description; string text = info.description;
@ -185,27 +245,49 @@ namespace Revitalize.Framework.Objects
return Game1.parseText(text, smallFont, width); return Game1.parseText(text, smallFont, width);
} }
/// <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) public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{ {
this.updateDrawPosition(); this.updateDrawPosition();
return base.placementAction(location, x, y, who); return base.placementAction(location, x, y, who);
} }
/// <summary>
/// Updates a visual draw position.
/// </summary>
public virtual void updateDrawPosition() public virtual void updateDrawPosition()
{ {
this.info.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.animationManager.currentAnimation.sourceRectangle.Height * Game1.pixelZoom - this.boundingBox.Height))); this.info.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.animationManager.currentAnimation.sourceRectangle.Height * Game1.pixelZoom - this.boundingBox.Height)));
} }
/// <summary>
/// Gets a clone of the game object.
/// </summary>
/// <returns></returns>
public override Item getOne() public override Item getOne()
{ {
return new CustomObject((BasicItemInformation)this.data); return new CustomObject((BasicItemInformation)this.data);
} }
/// <summary>
/// What happens when the object is drawn at a tile location.
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="alpha"></param>
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
{ {
if (x == -1) if (x == -1)
{ {
spriteBatch.Draw(this.info.animationManager.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.info.drawPosition), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); spriteBatch.Draw(this.info.animationManager.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.info.drawPosition), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
} }
else else
{ {
@ -218,14 +300,14 @@ namespace Revitalize.Framework.Objects
} }
spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
// Log.AsyncG("ANIMATION IS NULL?!?!?!?!"); // Log.AsyncG("ANIMATION IS NULL?!?!?!?!");
} }
else else
{ {
//Log.AsyncC("Animation Manager is working!"); //Log.AsyncC("Animation Manager is working!");
this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
try try
{ {
this.animationManager.tickAnimation(); this.animationManager.tickAnimation();
@ -244,6 +326,14 @@ namespace Revitalize.Framework.Objects
} }
} }
/// <summary>
/// Draw the game object at a non-tile spot. Aka like debris.
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="xNonTile"></param>
/// <param name="yNonTile"></param>
/// <param name="layerDepth"></param>
/// <param name="alpha"></param>
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f) public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f)
{ {
@ -263,7 +353,7 @@ namespace Revitalize.Framework.Objects
int num3 = (bool)(this.flipped) ? 1 : 0; int num3 = (bool)(this.flipped) ? 1 : 0;
double num4 = (double)layerDepth; double num4 = (double)layerDepth;
spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, color, (float)num1, origin, (float)4f, (SpriteEffects)num3, (float)num4); spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, info.drawColor*alpha, (float)num1, origin, (float)4f, (SpriteEffects)num3, (float)num4);
} }
@ -279,6 +369,17 @@ namespace Revitalize.Framework.Objects
base.drawAttachments(b, x, y); base.drawAttachments(b, x, y);
} }
/// <summary>
/// What happens when the object is drawn in a menu.
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="location"></param>
/// <param name="scaleSize"></param>
/// <param name="transparency"></param>
/// <param name="layerDepth"></param>
/// <param name="drawStackNumber"></param>
/// <param name="c"></param>
/// <param name="drawShadow"></param>
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) 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) if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1)
@ -288,7 +389,7 @@ namespace Revitalize.Framework.Objects
float num = this.Quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); 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(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), Color.White * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), 3f, 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)), 3f, SpriteEffects.None, layerDepth);
} }
public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
@ -296,15 +397,22 @@ namespace Revitalize.Framework.Objects
base.drawPlacementBounds(spriteBatch, location); base.drawPlacementBounds(spriteBatch, location);
} }
/// <summary>
/// What happens when the object is drawn when held by a player.
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="objectPosition"></param>
/// <param name="f"></param>
public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f)
{ {
if (f.ActiveObject.bigCraftable.Value) if (f.ActiveObject.bigCraftable.Value)
{ {
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));
return; return;
} }
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));
if (f.ActiveObject != null && f.ActiveObject.Name.Contains("=")) if (f.ActiveObject != null && f.ActiveObject.Name.Contains("="))
{ {
spriteBatch.Draw(this.displayTexture, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), this.animationManager.currentAnimation.sourceRectangle, Color.White, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); spriteBatch.Draw(this.displayTexture, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), this.animationManager.currentAnimation.sourceRectangle, Color.White, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));

View File

@ -30,7 +30,7 @@ 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())); 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));
new InventoryItem(obj, 100,1).addToNPCShop("Gus"); new InventoryItem(obj, 100,1).addToNPCShop("Gus");