Got customizable draw colors working.
This commit is contained in:
parent
65ab0812b7
commit
591a6f4a96
|
@ -27,6 +27,8 @@ namespace Revitalize.Framework.Objects
|
|||
public AnimationManager animationManager;
|
||||
public Vector2 drawPosition;
|
||||
|
||||
public Color drawColor;
|
||||
|
||||
public BasicItemInformation() : base()
|
||||
{
|
||||
name = "";
|
||||
|
@ -41,9 +43,10 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
this.animationManager = null;
|
||||
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.description = description;
|
||||
|
@ -71,6 +74,16 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
this.drawPosition = Vector2.Zero;
|
||||
|
||||
if (DrawColor == null)
|
||||
{
|
||||
this.drawColor = Color.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drawColor = DrawColor;
|
||||
}
|
||||
|
||||
|
||||
recreateDataString();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ using System.Threading.Tasks;
|
|||
namespace Revitalize.Framework.Objects
|
||||
{
|
||||
/// <summary>
|
||||
/// Change draw functions.
|
||||
/// A custom object template.
|
||||
/// </summary>
|
||||
public class CustomObject : PySObject
|
||||
{
|
||||
|
@ -24,7 +24,9 @@ namespace Revitalize.Framework.Objects
|
|||
public string id;
|
||||
public BasicItemInformation info;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The animation manager.
|
||||
/// </summary>
|
||||
public AnimationManager animationManager
|
||||
{
|
||||
get
|
||||
|
@ -33,7 +35,9 @@ namespace Revitalize.Framework.Objects
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The display texture for this object.
|
||||
/// </summary>
|
||||
public Texture2D displayTexture
|
||||
{
|
||||
get
|
||||
|
@ -42,24 +46,38 @@ namespace Revitalize.Framework.Objects
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Empty constructor.
|
||||
/// </summary>
|
||||
public CustomObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
public CustomObject(BasicItemInformation info):base(info,Vector2.Zero)
|
||||
{
|
||||
this.info = info;
|
||||
this.initializeBasics();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <param name="TileLocation"></param>
|
||||
public CustomObject(BasicItemInformation info,Vector2 TileLocation) : base(info, TileLocation)
|
||||
{
|
||||
this.info = info;
|
||||
this.initializeBasics();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets some basic information up.
|
||||
/// </summary>
|
||||
public virtual void initializeBasics()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// What happens when the player right clicks the object.
|
||||
/// </summary>
|
||||
/// <param name="who"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool rightClicked(Farmer who)
|
||||
{
|
||||
// Game1.showRedMessage("YOOO");
|
||||
|
@ -126,12 +154,22 @@ namespace Revitalize.Framework.Objects
|
|||
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)
|
||||
{
|
||||
Revitalize.ModCore.log("Shift right clicked!");
|
||||
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)
|
||||
{
|
||||
Revitalize.ModCore.log("Clicky click!");
|
||||
|
@ -140,6 +178,12 @@ namespace Revitalize.Framework.Objects
|
|||
//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)
|
||||
{
|
||||
|
||||
|
@ -154,6 +198,10 @@ namespace Revitalize.Framework.Objects
|
|||
//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()
|
||||
{
|
||||
if (Game1.player.isInventoryFull())
|
||||
|
@ -166,17 +214,29 @@ namespace Revitalize.Framework.Objects
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category color for the object.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override Color getCategoryColor()
|
||||
{
|
||||
return info.categoryColor;
|
||||
//return data.categoryColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category name for the object.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string getCategoryName()
|
||||
{
|
||||
return info.categoryName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description for the object.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string getDescription()
|
||||
{
|
||||
string text = info.description;
|
||||
|
@ -185,27 +245,49 @@ namespace Revitalize.Framework.Objects
|
|||
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)
|
||||
{
|
||||
this.updateDrawPosition();
|
||||
return base.placementAction(location, x, y, who);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a visual draw position.
|
||||
/// </summary>
|
||||
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)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a clone of the game object.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override Item getOne()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -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?!?!?!?!");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
//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
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
|
@ -263,7 +353,7 @@ namespace Revitalize.Framework.Objects
|
|||
int num3 = (bool)(this.flipped) ? 1 : 0;
|
||||
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);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
|
@ -296,15 +397,22 @@ namespace Revitalize.Framework.Objects
|
|||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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("="))
|
||||
{
|
||||
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));
|
||||
|
|
|
@ -30,7 +30,7 @@ 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()));
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue