Fixed draw issues with multi tile obects. Next up menu drawing and functionality.

This commit is contained in:
2018-06-13 11:11:56 -07:00
parent 4469fbd9b3
commit bcf76f9163
6 changed files with 157 additions and 79 deletions

View File

@ -20,7 +20,7 @@ namespace StardustCore.Animations
public string currentAnimationName;
public int currentAnimationListIndex;
public List<Animation> currentAnimationList = new List<Animation>();
public Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet.
private Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet.
public Animation defaultDrawFrame;
public Animation currentAnimation;
bool enabled;
@ -218,5 +218,15 @@ namespace StardustCore.Animations
}
}
public Texture2DExtended getExtendedTexture()
{
return this.objectTexture;
}
public Texture2D getTexture()
{
return this.objectTexture.getTexture();
}
}
}

View File

@ -61,10 +61,9 @@ namespace StardustCore
{
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
List<KeyValuePair<Vector2, MultiTileComponent>> objs = new List<KeyValuePair<Vector2, MultiTileComponent>>();
MultiTileComponent tile1 = new MultiTileComponent(new CoreObject(new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test1.png")), 0, Vector2.Zero, 0));
MultiTileComponent tile2 = new MultiTileComponent(new CoreObject(new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test2.png")), 0, Vector2.Zero, 0));
MultiTileComponent tile3 = new MultiTileComponent(new CoreObject(new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test3.png")), 0, Vector2.Zero, 0));
MultiTileComponent tile1 = new MultiTileComponent(0,"Tileobj1","A basic tile obj",new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test1.png")));
MultiTileComponent tile2 = new MultiTileComponent(0,"Tileobj2", "A basic tile obj", new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test2.png")));
MultiTileComponent tile3 = new MultiTileComponent(0,"Tileobj3", "A basic tile obj", new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test3.png")));
objs.Add(new KeyValuePair<Vector2, MultiTileComponent>(new Vector2(0, 0), tile1));
objs.Add(new KeyValuePair<Vector2, MultiTileComponent>(new Vector2(1, 0), tile2));
objs.Add(new KeyValuePair<Vector2, MultiTileComponent>(new Vector2(2, 0), tile3));

View File

@ -42,7 +42,7 @@ namespace StardustCore
public string description;
[XmlIgnore]
public Texture2DExtended TextureSheet;
protected Texture2DExtended TextureSheet;
public new bool flipped;
@ -143,7 +143,7 @@ namespace StardustCore
{
this.defaultSourceRect.Width = 16;
this.defaultSourceRect.Height = 16;
this.sourceRect = new Rectangle(which * 16 % TextureSheet.getTexture().Width, which * 16 / TextureSheet.getTexture().Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16);
this.sourceRect = new Rectangle((which * 16) % TextureSheet.getTexture().Width, (which * 16) / TextureSheet.getTexture().Width * 16, this.defaultSourceRect.Width, this.defaultSourceRect.Height);
this.defaultSourceRect = this.sourceRect;
}
this.defaultBoundingBox = new Rectangle((int)this.TileLocation.X, (int)this.TileLocation.Y, 1, 1);
@ -1370,27 +1370,27 @@ namespace StardustCore
else return false;
}
public virtual void spillInventoryEverywhere()
public virtual void getInventoryMenu()
{
Game1.activeClickableMenu = new StorageContainer(this.inventory, 3, 3);
this.itemReadyForHarvest = false;
/*
Log.AsyncC("DROPPING INVENTORY!");
*/
}
public virtual void spillInventoryEverywhere()
{
Random random = new Random(inventory.Count);
int i = random.Next();
i = i % 4;
Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize);
Vector2 v2 = new Vector2(this.TileLocation.X * Game1.tileSize, this.TileLocation.Y * Game1.tileSize);
foreach (var I in inventory)
{
Log.AsyncY(I.Name);
Log.AsyncO(I.getStack());
Log.AsyncM(I.Stack);
Log.AsyncC("Dropping an item!");
Game1.createItemDebris(I, v2, i);
}
inventory.Clear();
*/
}
/// <summary>
@ -1487,45 +1487,11 @@ namespace StardustCore
return this.GetType().ToString();
}
/*
public static void Serialize(Item I)
public virtual Texture2DExtended getExtendedTexture()
{
return this.TextureSheet;
}
public static Item ParseIntoInventory()
{
Texture2DExtended texture = new Texture2DExtended();
Item I = new CoreObject(texture,0, Vector2.Zero, 0);
return I;
}
public static void ParseIntoWorld()
{
//Item I = new CoreObject(0, Vector2.Zero, 0);
//return I;
}
public void Serialize(Item I)
{
throw new NotImplementedException();
}
public void deserialize()
{
throw new NotImplementedException();
}
public void ParseIntoWorld()
{
throw new NotImplementedException();
}
void ISerializeable.ParseIntoInventory()
{
throw new NotImplementedException();
}
*/
}
}

View File

@ -6,44 +6,95 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardustCore.UIUtilities;
namespace StardustCore.Objects
{
public class MultiTileComponent : CoreObject
{
//Pass in different function pointers that return bool to check if this default code will run. If not
public MultiTileObject containerObject;
public CoreObject objectPart;
public MultiTileComponent(CoreObject part)
{
this.objectPart = part;
this.name = this.objectPart.name;
this.name = part.name;
this.description = part.description;
this.TextureSheet = part.getExtendedTexture();
this.texturePath = this.TextureSheet.path;
if (part.animationManager != null)
{
this.animationManager = part.animationManager;
}
this.defaultBoundingBox = new Rectangle(0, 0, 16, 16);
this.boundingBox.Value = new Rectangle((int)0 * Game1.tileSize, (int)0* Game1.tileSize, 1 * Game1.tileSize, 1 * Game1.tileSize);
}
public MultiTileComponent(int which,String name, String description, Texture2DExtended texture)
{
this.name = name;
this.displayName = name;
this.description = description;
this.TextureSheet = texture;
this.defaultBoundingBox = new Rectangle(0, 0, 16, 16);
this.boundingBox.Value = new Rectangle((int)0 * Game1.tileSize, (int)0 * Game1.tileSize, 1 * Game1.tileSize, 1 * Game1.tileSize);
this.defaultSourceRect.Width = 16;
this.defaultSourceRect.Height = 16;
this.sourceRect = new Rectangle((which * 16) % TextureSheet.getTexture().Width, (which * 16) / TextureSheet.getTexture().Width * 16, this.defaultSourceRect.Width * 1, this.defaultSourceRect.Height * 1);
this.defaultSourceRect = this.sourceRect;
this.serializationName = this.GetType().ToString();
this.ParentSheetIndex = which;
}
public MultiTileComponent(int which,String name, String description, Animations.AnimationManager animationManager)
{
this.name = name;
this.displayName = name;
this.description = description;
this.animationManager = animationManager;
this.TextureSheet = animationManager.getExtendedTexture();
this.defaultBoundingBox = new Rectangle(0, 0, 16, 16);
this.boundingBox.Value = new Rectangle((int)0 * Game1.tileSize, (int)0 * Game1.tileSize, 1 * Game1.tileSize, 1 * Game1.tileSize);
this.defaultSourceRect.Width = 16;
this.defaultSourceRect.Height = 16;
this.sourceRect = new Rectangle(which * 16 % TextureSheet.getTexture().Width, which * 16 / TextureSheet.getTexture().Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16);
this.defaultSourceRect = this.sourceRect;
this.serializationName = this.GetType().ToString();
this.ParentSheetIndex = which;
}
public override bool clicked(Farmer who)
{
containerObject.RemoveAllObjects();
//Check if shift click to interact with object.
containerObject.RemoveAllObjects();
return true;
}
public override Item getOne()
{
var obj= new MultiTileComponent((CoreObject)objectPart.getOne());
obj.containerObject = this.containerObject;
return obj;
if (this.animationManager != null)
{
var obj = new MultiTileComponent(this.ParentSheetIndex,this.name, this.description, this.animationManager);
obj.containerObject = this.containerObject;
return obj;
}
else
{
var obj = new MultiTileComponent(this.ParentSheetIndex,this.name, this.description, this.TextureSheet);
obj.containerObject = this.containerObject;
return obj;
}
}
public override bool RightClicked(Farmer who)
{
return this.objectPart.RightClicked(who);
return true;
}
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{
Point point = new Point(x / Game1.tileSize, y / Game1.tileSize);
this.position = new Vector2(point.X, point.Y);
this.TileLocation = new Vector2((float)point.X, (float)point.Y);
this.boundingBox.Value = new Rectangle((int)TileLocation.X * Game1.tileSize, (int)TileLocation.Y * Game1.tileSize, 1 * Game1.tileSize, 1 * Game1.tileSize);
using (List<StardewValley.Farmer>.Enumerator enumerator3 = location.getFarmers().GetEnumerator())
@ -90,21 +141,21 @@ namespace StardustCore.Objects
{
if (x == -1)
{
spriteBatch.Draw(this.objectPart.TextureSheet.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.objectPart.drawPosition), new Rectangle?(this.objectPart.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.objectPart.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.objectPart.Decoration_type == 12) ? 0f : ((float)(this.objectPart.boundingBox.Bottom - 8) / 10000f));
spriteBatch.Draw(this.TextureSheet.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f));
}
else
{
//The actual planter box being drawn.
if (animationManager == null)
{
spriteBatch.Draw(this.objectPart.TextureSheet.getTexture(), Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.objectPart.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.objectPart.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
spriteBatch.Draw(this.TextureSheet.getTexture(), Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.sourceRect), Color.White * 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.objectPart.animationManager.objectTexture.getTexture(), Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.objectPart.animationManager.currentAnimation.sourceRectangle), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.objectPart.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
this.animationManager.draw(spriteBatch, this.animationManager.getTexture(), 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);
try
{
this.animationManager.tickAnimation();
@ -123,6 +174,27 @@ namespace StardustCore.Objects
}
}
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f)
{
if (Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64))
return;
if ((int)(this.ParentSheetIndex) != 590 && (int)(this.Fragility) != 2)
spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile + 32), (float)(yNonTile + 51 + 4))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, layerDepth - 1E-06f);
SpriteBatch spriteBatch1 = spriteBatch;
Texture2D objectSpriteSheet = Game1.objectSpriteSheet;
Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile + 32 + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(yNonTile + 32 + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0))));
Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(GameLocation.getSourceRectForObject(this.ParentSheetIndex));
Color color = Color.White * alpha;
double num1 = 0.0;
Vector2 origin = new Vector2(8f, 8f);
Vector2 scale = this.scale;
double num2 = (double)this.scale.Y > 1.0 ? (double)this.getScale().Y : 4.0;
int num3 = (bool)(this.flipped) ? 1 : 0;
double num4 = (double)layerDepth;
spriteBatch1.Draw(TextureSheet.getTexture(), local, sourceRectangle, color, (float)num1, origin, (float)num2, (SpriteEffects)num3, (float)num4);
}

View File

@ -33,18 +33,23 @@ namespace StardustCore.Objects
}
InitializeBasics(0, tile);
this.serializationName = this.GetType().ToString();
this.defaultSourceRect = new Rectangle(0, 0, 16, 16);
this.sourceRect = defaultSourceRect;
}
public MultiTileObject(String Name, String Description, Vector2 tile, Animations.AnimationManager animationManager, List<KeyValuePair<Vector2, MultiTileComponent>> Objects, Color CategoryColor, String CategoryName)
{
this.animationManager = animationManager;
this.objects = Objects;
this.TextureSheet =animationManager.objectTexture;
this.texturePath = animationManager.objectTexture.path;
this.TextureSheet =animationManager.getExtendedTexture();
this.texturePath = animationManager.getExtendedTexture().path;
this.name = Name;
this.displayName = Name;
this.description = Description;
InitializeBasics(0, tile);
this.serializationName = this.GetType().ToString();
}
public void RemoveAllObjects()
@ -52,7 +57,7 @@ namespace StardustCore.Objects
if (Game1.player.isInventoryFull() == false){
foreach (var v in this.objects)
{
v.Value.performRemoveAction(v.Value.TileLocation, v.Value.objectPart.thisLocation);
v.Value.performRemoveAction(v.Value.TileLocation, v.Value.thisLocation);
}
Game1.player.addItemToInventory(this);
}
@ -75,9 +80,24 @@ namespace StardustCore.Objects
}
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{
foreach(var pair in this.objects)
if (canBePlacedHere(location,new Vector2(x/Game1.tileSize,y/Game1.tileSize)))
{
pair.Value.placementAction(location, x+(int)(pair.Key.X*Game1.tileSize), y+ (int)(pair.Key.Y * Game1.tileSize), who);
foreach (var pair in this.objects)
{
pair.Value.placementAction(location, x + (int)(pair.Key.X * Game1.tileSize), y + (int)(pair.Key.Y * Game1.tileSize), who);
}
return true;
}
return false;
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{
bool canBePlaced = true;
foreach (var v in this.objects)
{
canBePlaced=v.Value.canBePlacedHere(l, tile+v.Key);
if (canBePlaced == false) return false;
}
return true;
}
@ -128,10 +148,7 @@ namespace StardustCore.Objects
foreach(var v in this.objects)
{
if (v.Value.objectPart.thisLocation != null)
{
v.Value.draw(spriteBatch, (int)v.Value.position.X, (int)v.Value.position.Y, alpha);
}
v.Value.draw(spriteBatch, (int)x+(int)(v.Key.X), (int)y+(int)(v.Key.Y), alpha);
}
//base.draw(spriteBatch, x, y, alpha);
@ -141,7 +158,7 @@ namespace StardustCore.Objects
{
foreach (var v in this.objects)
{
//v.Value.draw(spriteBatch, (int)v.Value.position.X, (int)v.Value.position.Y, layerDepth, alpha);
v.Value.draw(spriteBatch, (int)xNonTile+(int)(v.Key.X*Game1.tileSize), (int)yNonTile+ (int)(v.Key.Y * Game1.tileSize), layerDepth, alpha);
}
}
@ -149,22 +166,36 @@ namespace StardustCore.Objects
{
if (animationManager == null)
{
spriteBatch.Draw(this.TextureSheet.getTexture(), objectPosition, new Microsoft.Xna.Framework.Rectangle?(GameLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));
foreach (var v in this.objects)
{
spriteBatch.Draw(v.Value.getExtendedTexture().getTexture(), objectPosition + new Vector2(v.Key.X * Game1.tileSize, v.Key.Y * Game1.tileSize), this.sourceRect, Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));
}
}
else
{
spriteBatch.Draw(animationManager.objectTexture.getTexture(), objectPosition, this.animationManager.currentAnimation.sourceRectangle, Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));
foreach (var v in this.objects)
{
spriteBatch.Draw(v.Value.animationManager.getTexture(), objectPosition + new Vector2(v.Key.X * Game1.tileSize, v.Key.Y * Game1.tileSize), this.sourceRect, Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));
}
}
//base.drawWhenHeld(spriteBatch, objectPosition, f);
}
public override void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1)
{
foreach (var v in this.objects)
{
v.Value.drawAtNonTileSpot(spriteBatch, location+new Vector2(v.Key.X * Game1.tileSize, v.Key.Y * Game1.tileSize), layerDepth, alpha);
}
}
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadows)
{
if (animationManager == null) spriteBatch.Draw(this.TextureSheet.getTexture(), location,this.defaultSourceRect, Color.White * transparency, 0f, new Vector2(0,0), scaleSize, SpriteEffects.None, layerDepth);
else
{
spriteBatch.Draw(animationManager.objectTexture.getTexture(), location, animationManager.currentAnimation.sourceRectangle, Color.White * transparency, 0f, new Vector2(0,0), scaleSize, SpriteEffects.None, layerDepth);
spriteBatch.Draw(animationManager.getTexture(), location, animationManager.currentAnimation.sourceRectangle, Color.White * transparency, 0f, new Vector2(0,0), scaleSize, SpriteEffects.None, layerDepth);
//this.modularCrop.drawInMenu(spriteBatch, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), Color.White, 0f,true);
if (Game1.player.CurrentItem != this) animationManager.tickAnimation();
}

View File

@ -204,7 +204,7 @@ namespace StardustCore.UIUtilities.MenuComponents
/// <returns>A Button object that is identical to the one passed in.</returns>
public Button clone()
{
var b= new Button(this.name, this.bounds, this.animationManager.objectTexture, this.label, this.sourceRect, this.scale, this.animationManager.defaultDrawFrame, this.textureColor, this.textColor, this.buttonFunctionality, true);
var b= new Button(this.name, this.bounds, this.animationManager.getExtendedTexture(), this.label, this.sourceRect, this.scale, this.animationManager.defaultDrawFrame, this.textureColor, this.textColor, this.buttonFunctionality, true);
if (b.buttonFunctionality.hover == null)
{
StardustCore.ModCore.ModMonitor.Log("I'm null!");
@ -219,7 +219,7 @@ namespace StardustCore.UIUtilities.MenuComponents
/// <returns></returns>
public Button clone(Vector2 newPosition)
{
var b = new Button(this.name, new Rectangle((int)newPosition.X,(int)newPosition.Y,this.bounds.Width,this.bounds.Height), this.animationManager.objectTexture, this.label, this.sourceRect, this.scale, this.animationManager.defaultDrawFrame, this.textureColor, this.textColor, this.buttonFunctionality, true);
var b = new Button(this.name, new Rectangle((int)newPosition.X,(int)newPosition.Y,this.bounds.Width,this.bounds.Height), this.animationManager.getExtendedTexture(), this.label, this.sourceRect, this.scale, this.animationManager.defaultDrawFrame, this.textureColor, this.textColor, this.buttonFunctionality, true);
if (b.buttonFunctionality.hover == null)
{
//StardustCore.ModCore.ModMonitor.Log("I'm null!");