2018-12-30 18:00:05 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Microsoft.Xna.Framework;
|
2018-12-23 16:53:43 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using PyTK.CustomElementHandler;
|
|
|
|
using StardewValley;
|
|
|
|
using StardewValley.Objects;
|
|
|
|
|
|
|
|
namespace Revitalize.Framework.Objects
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
public class MultiTiledComponent : CustomObject
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
|
|
|
public MultiTiledObject containerObject;
|
|
|
|
|
2019-01-09 14:15:58 +08:00
|
|
|
public Vector2 offsetKey;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledComponent() { }
|
2018-12-23 16:53:43 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledComponent(BasicItemInformation info) : base(info) { }
|
2018-12-23 16:53:43 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledComponent(BasicItemInformation info, Vector2 TileLocation) : base(info, TileLocation) { }
|
2018-12-23 16:53:43 +08:00
|
|
|
|
2019-01-09 14:15:58 +08:00
|
|
|
|
|
|
|
public override bool isPassable()
|
|
|
|
{
|
|
|
|
return this.info.ignoreBoundingBox || Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this.containerObject;
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
//ModCore.log("Checking for a clicky click???");
|
2018-12-23 16:53:43 +08:00
|
|
|
return base.checkForAction(who, justCheckingForActivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool clicked(Farmer who)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
ModCore.log("Clicked a multiTiledComponent!");
|
2018-12-23 16:53:43 +08:00
|
|
|
this.containerObject.pickUp();
|
|
|
|
return true;
|
|
|
|
//return base.clicked(who);
|
|
|
|
}
|
|
|
|
|
2018-12-26 11:48:45 +08:00
|
|
|
public override bool rightClicked(Farmer who)
|
|
|
|
{
|
|
|
|
if (this.location == null)
|
|
|
|
this.location = Game1.player.currentLocation;
|
2019-01-09 14:15:58 +08:00
|
|
|
//this.info.lightManager.toggleLights(this.location, this);
|
2018-12-29 15:28:21 +08:00
|
|
|
|
2019-01-09 14:15:58 +08:00
|
|
|
//ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero);
|
2018-12-29 15:28:21 +08:00
|
|
|
|
2018-12-26 11:48:45 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
|
|
|
|
public override void performRemoveAction(Vector2 tileLocation, GameLocation environment)
|
|
|
|
{
|
2018-12-26 11:48:45 +08:00
|
|
|
this.location = null;
|
2018-12-23 16:53:43 +08:00
|
|
|
base.performRemoveAction(this.TileLocation, environment);
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public virtual void removeFromLocation(GameLocation location, Vector2 offset)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
location.removeObject(this.TileLocation, false);
|
2018-12-26 11:48:45 +08:00
|
|
|
this.location = null;
|
2018-12-23 16:53:43 +08:00
|
|
|
//this.performRemoveAction(this.TileLocation,location);
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Places an object down.</summary>
|
2018-12-23 16:53:43 +08:00
|
|
|
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
ModCore.ModMonitor.Log("SCREAMING!!!!");
|
|
|
|
this.updateDrawPosition(x, y);
|
2018-12-23 16:53:43 +08:00
|
|
|
this.location = location;
|
|
|
|
|
2018-12-26 11:48:45 +08:00
|
|
|
if (this.location == null) this.location = Game1.player.currentLocation;
|
2018-12-23 16:53:43 +08:00
|
|
|
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);
|
|
|
|
}
|
2018-12-30 18:00:05 +08:00
|
|
|
spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize / 4), (float)(Game1.tileSize * .75)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), scaleSize, SpriteEffects.None, layerDepth);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Item getOne()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
MultiTiledComponent component = new MultiTiledComponent(this.info, this.TileLocation);
|
2018-12-23 16:53:43 +08:00
|
|
|
component.containerObject = this.containerObject;
|
2019-01-09 14:15:58 +08:00
|
|
|
component.offsetKey = this.offsetKey;
|
2018-12-23 16:53:43 +08:00
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
|
|
|
|
{
|
|
|
|
BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]];
|
2018-12-30 18:00:05 +08:00
|
|
|
return new MultiTiledComponent(data, (replacement as Chest).TileLocation)
|
|
|
|
{
|
2019-01-09 14:15:58 +08:00
|
|
|
containerObject = this.containerObject,
|
|
|
|
offsetKey = this.offsetKey
|
2018-12-30 18:00:05 +08:00
|
|
|
};
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
2019-01-09 14:15:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// <summary>What happens when the object is drawn at a tile location.</summary>
|
|
|
|
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), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//The actual planter box being drawn.
|
|
|
|
if (this.animationManager == null)
|
|
|
|
{
|
|
|
|
if (this.animationManager.getExtendedTexture() == null)
|
|
|
|
ModCore.ModMonitor.Log("Tex Extended is null???");
|
|
|
|
|
|
|
|
spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f));
|
|
|
|
// Log.AsyncG("ANIMATION IS NULL?!?!?!?!");
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Log.AsyncC("Animation Manager is working!");
|
|
|
|
float addedDepth = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this.containerObject && this.info.facingDirection == Enums.Direction.Up)
|
|
|
|
{
|
|
|
|
addedDepth += (this.containerObject.Height - 1) - ((int)(this.offsetKey.Y));
|
|
|
|
if (this.info.ignoreBoundingBox) addedDepth+=1.5f;
|
|
|
|
}
|
|
|
|
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), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)((this.TileLocation.Y + addedDepth) * Game1.tileSize) / 10000f));
|
|
|
|
try
|
|
|
|
{
|
|
|
|
this.animationManager.tickAnimation();
|
|
|
|
// Log.AsyncC("Tick animation");
|
|
|
|
}
|
|
|
|
catch (Exception err)
|
|
|
|
{
|
|
|
|
ModCore.ModMonitor.Log(err.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
}
|