summaryrefslogtreecommitdiff
path: root/StardewModdingAPI/Inheritance/SObject.cs
diff options
context:
space:
mode:
authorClxS <slxxls92@gmail.com>2016-03-03 09:20:20 +0000
committerClxS <slxxls92@gmail.com>2016-03-03 09:20:20 +0000
commit2a9c08e1ad85a28b74b27a3e8d7f568c2f77a38f (patch)
treee803066b2054ddfeed43ad75819026e18f246be8 /StardewModdingAPI/Inheritance/SObject.cs
parent38bce3315841c66409e02844c86eb7a5e9295565 (diff)
parent250559d227fa3a8148ad97d75a725ed0a47a0f4f (diff)
downloadSMAPI-2a9c08e1ad85a28b74b27a3e8d7f568c2f77a38f.tar.gz
SMAPI-2a9c08e1ad85a28b74b27a3e8d7f568c2f77a38f.tar.bz2
SMAPI-2a9c08e1ad85a28b74b27a3e8d7f568c2f77a38f.zip
Merge pull request #1 from Zoryn4163/master
Merge pull request #1 from Zoryn4163/master
Diffstat (limited to 'StardewModdingAPI/Inheritance/SObject.cs')
-rw-r--r--StardewModdingAPI/Inheritance/SObject.cs100
1 files changed, 75 insertions, 25 deletions
diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs
index 97d2fa41..5c80cd52 100644
--- a/StardewModdingAPI/Inheritance/SObject.cs
+++ b/StardewModdingAPI/Inheritance/SObject.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
@@ -12,7 +13,10 @@ namespace StardewModdingAPI.Inheritance
{
public class SObject : StardewValley.Object
{
- public override String Name { get; set; }
+ public override String Name {
+ get { return name; }
+ set { name = value; }
+ }
public String Description { get; set; }
public Texture2D Texture { get; set; }
public String CategoryName { get; set; }
@@ -29,9 +33,18 @@ namespace StardewModdingAPI.Inheritance
public Boolean FlaggedForPickup { get; set; }
+ public Vector2 CurrentMouse { get; protected set; }
+ public Vector2 PlacedAt { get; protected set; }
+
+ public override int Stack
+ {
+ get { return stack; }
+ set { stack = value; }
+ }
+
public SObject()
{
- Name = "Modded Item Name";
+ name = "Modded Item Name";
Description = "Modded Item Description";
CategoryName = "Modded Item Category";
Category = 4163;
@@ -39,6 +52,9 @@ namespace StardewModdingAPI.Inheritance
IsPassable = false;
IsPlaceable = false;
boundingBox = new Rectangle(0, 0, 64, 64);
+ MaxStackSize = 999;
+
+ type = "interactive";
}
public override string getDescription()
@@ -48,13 +64,19 @@ namespace StardewModdingAPI.Inheritance
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
{
-
if (Texture != null)
- spriteBatch.Draw(Texture, new Vector2(x, y), new Color(255, 255, 255, 255f * alpha));
+ {
+ int targSize = Game1.tileSize;
+
+ Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2(x,y));
+ Rectangle targ = new Rectangle((int)local.X, (int)local.Y, targSize, targSize);
+ spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha));
+ }
}
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
{
+ Program.LogInfo("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED");
return;
try
{
@@ -181,34 +203,62 @@ namespace StardewModdingAPI.Inheritance
return this.Clone();
}
+ public override void actionWhenBeingHeld(Farmer who)
+ {
+ Point p = Game1.getMousePosition();
+ CurrentMouse = new Vector2((p.X / Game1.tileSize), (p.Y / Game1.tileSize));
+ Program.LogInfo(canBePlacedHere(Game1.currentLocation, CurrentMouse));
+ base.actionWhenBeingHeld(who);
+ }
+
+ public override bool canBePlacedHere(GameLocation l, Vector2 tile)
+ {
+ Program.LogInfo(CurrentMouse.ToString().Replace("{", "").Replace("}", ""));
+ if (!l.objects.ContainsKey(tile))
+ return true;
+
+ return false;
+ }
+
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{
- SGameLocation s = SGame.GetLocationFromName(location.name);
+ if (Game1.didPlayerJustRightClick())
+ return false;
- if (s.GetHashCode() != SGame.CurrentLocation.GetHashCode())
- {
- Program.LogError("HASH DIFFERENCE: " + s.GetHashCode() + " | " + SGame.ModLocations[SGame.ModLocations.IndexOf(SGame.ModLocations.First(z => z.name == location.name))].GetHashCode() + " | " + SGame.CurrentLocation.GetHashCode());
- Console.ReadKey();
- }
+ x = (x / Game1.tileSize) * Game1.tileSize;
+ y = (y / Game1.tileSize) * Game1.tileSize;
- Console.Title = (this.GetHashCode() + " PLACEMENT");
+ Vector2 key = new Vector2(x, y);
- if (s != null)
- {
- Vector2 index1 = new Vector2(x - (Game1.tileSize / 2), y - (Game1.tileSize / 2));
- if (!s.ModObjects.ContainsKey(index1))
- {
- s.ModObjects.Add(index1, this);
- Game1.player.position = index1;
- return true;
- }
- }
- else
- {
- Program.LogError("No SGameLocation could be found for the supplied GameLocation!");
+ if (!canBePlacedHere(location, key))
return false;
+
+ SObject s = Clone();
+
+ s.PlacedAt = key;
+ s.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height);
+
+ location.objects.Add(key, s);
+ Program.LogInfo("{0} - {1}", this.GetHashCode(), s.GetHashCode());
+
+ return true;
+ }
+
+ public override void actionOnPlayerEntry()
+ {
+ //base.actionOnPlayerEntry();
+ }
+
+ public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
+ {
+ if (canBePlacedHere(location, CurrentMouse))
+ {
+ int targSize = Game1.tileSize;
+
+ int x = Game1.oldMouseState.X + Game1.viewport.X;
+ int y = Game1.oldMouseState.Y + Game1.viewport.Y;
+ spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)(x / Game1.tileSize * Game1.tileSize - Game1.viewport.X), (float)(y / Game1.tileSize * Game1.tileSize - Game1.viewport.Y)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(Utility.playerCanPlaceItemHere(location, (Item)this, x, y, Game1.player) ? 194 : 210, 388, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 0.01f);
}
- return false;
}
}
} \ No newline at end of file