summaryrefslogtreecommitdiff
path: root/StardewModdingAPI/Inheritance
diff options
context:
space:
mode:
authorZoryn Aaron <zoryn4163@gmail.com>2016-03-01 01:35:52 -0500
committerZoryn Aaron <zoryn4163@gmail.com>2016-03-01 01:35:52 -0500
commit9a32b3afdda54e513cd370a0edfa87febc5cd1f0 (patch)
tree3ff47d467b8803c847d33f14bbf0717ab47cd2f0 /StardewModdingAPI/Inheritance
parent54faadf7b567eb2b71492471c4a2162487059ce6 (diff)
downloadSMAPI-9a32b3afdda54e513cd370a0edfa87febc5cd1f0.tar.gz
SMAPI-9a32b3afdda54e513cd370a0edfa87febc5cd1f0.tar.bz2
SMAPI-9a32b3afdda54e513cd370a0edfa87febc5cd1f0.zip
trying to get custom content working - do NOT try to implement cc yet
Diffstat (limited to 'StardewModdingAPI/Inheritance')
-rw-r--r--StardewModdingAPI/Inheritance/Menus/SGameMenu.cs60
-rw-r--r--StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs26
-rw-r--r--StardewModdingAPI/Inheritance/SGame.cs99
-rw-r--r--StardewModdingAPI/Inheritance/SGameLocation.cs90
-rw-r--r--StardewModdingAPI/Inheritance/SObject.cs188
5 files changed, 460 insertions, 3 deletions
diff --git a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs
new file mode 100644
index 00000000..8b883fb6
--- /dev/null
+++ b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Eventing.Reader;
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework.Graphics;
+using StardewValley;
+using StardewValley.Menus;
+
+namespace StardewModdingAPI.Inheritance.Menus
+{
+ public class SGameMenu : StardewValley.Menus.GameMenu
+ {
+ public GameMenu BaseGameMenu { get; private set; }
+
+ public List<ClickableComponent> tabs
+ {
+ get { return (List<ClickableComponent>)GetBaseFieldInfo("tabs").GetValue(BaseGameMenu); }
+ set { GetBaseFieldInfo("tabs").SetValue(BaseGameMenu, value); }
+ }
+
+ public List<IClickableMenu> pages
+ {
+ get { return (List<IClickableMenu>)GetBaseFieldInfo("pages").GetValue(BaseGameMenu); }
+ set { GetBaseFieldInfo("pages").SetValue(BaseGameMenu, value); }
+ }
+
+ public static SGameMenu ConstructFromBaseClass(GameMenu baseClass)
+ {
+ SGameMenu s = new SGameMenu();
+ s.BaseGameMenu = baseClass;
+ return s;
+ }
+
+ public override void receiveRightClick(int x, int y, bool playSound = true)
+ {
+ if (pages[currentTab] is InventoryPage)
+ {
+ Program.LogInfo("INV SCREEN");
+ }
+ else
+ {
+ }
+ base.receiveRightClick(x, y, playSound);
+ }
+
+ public static FieldInfo[] GetPrivateFields()
+ {
+ return typeof(GameMenu).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
+ }
+
+ public static FieldInfo GetBaseFieldInfo(string name)
+ {
+ return typeof(GameMenu).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
+ }
+ }
+}
diff --git a/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs b/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs
new file mode 100644
index 00000000..6bcb7662
--- /dev/null
+++ b/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using StardewValley;
+using StardewValley.Menus;
+
+namespace StardewModdingAPI.Inheritance.Menus
+{
+ public class SInventoryPage : InventoryPage
+ {
+ public InventoryPage BaseInventoryPage { get; private set; }
+
+ public static SInventoryPage ConstructFromBaseClass(InventoryPage baseClass)
+ {
+ SInventoryPage s = new SInventoryPage(0,0,0,0);
+ s.BaseInventoryPage = baseClass;
+ return s;
+ }
+
+ public SInventoryPage(int x, int y, int width, int height) : base(x, y, width, height)
+ {
+ }
+ }
+}
diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs
index 895c4d95..6ac78410 100644
--- a/StardewModdingAPI/Inheritance/SGame.cs
+++ b/StardewModdingAPI/Inheritance/SGame.cs
@@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewValley;
using StardewValley.Menus;
@@ -15,9 +19,14 @@ namespace StardewModdingAPI.Inheritance
{
public class SGame : Game1
{
- public static FieldInfo[] StaticFields { get { return Thing(); } }
+ public static List<SGameLocation> ModLocations = new List<SGameLocation>();
+ public static SGameLocation CurrentLocation { get; internal set; }
+ public static Dictionary<Int32, SObject> ModItems { get; private set; }
+ public const Int32 LowestModItemID = 1000;
- public static FieldInfo[] Thing()
+ public static FieldInfo[] StaticFields { get { return GetStaticFields(); } }
+
+ public static FieldInfo[] GetStaticFields()
{
return typeof(Game1).GetFields();
}
@@ -33,9 +42,15 @@ namespace StardewModdingAPI.Inheritance
get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
}
+ public int PreviousGameLocations { get; private set; }
+ public GameLocation PreviousGameLocation { get; private set; }
+ public IClickableMenu PreviousActiveMenu { get; private set; }
+
protected override void Initialize()
{
Program.Log("XNA Initialize");
+ ModItems = new Dictionary<Int32, SObject>();
+ PreviouslyPressedKeys = new Keys[0];
Events.InvokeInitialize();
base.Initialize();
}
@@ -58,12 +73,33 @@ namespace StardewModdingAPI.Inheritance
if (KStateNow != KStatePrior)
{
Events.InvokeKeyboardChanged(KStateNow);
+ KStatePrior = KStateNow;
+ }
+
+ if (Game1.activeClickableMenu != null && Game1.activeClickableMenu != PreviousActiveMenu)
+ {
+ Events.InvokeMenuChanged(Game1.activeClickableMenu);
+ PreviousActiveMenu = Game1.activeClickableMenu;
+ }
+
+ if (Game1.locations.GetHash() != PreviousGameLocations)
+ {
+ Events.InvokeLocationsChanged(Game1.locations);
+ PreviousGameLocations = Game1.locations.GetHash();
}
+ if (Game1.currentLocation != PreviousGameLocation)
+ {
+ Events.InvokeCurrentLocationChanged(Game1.currentLocation);
+ PreviousGameLocation = Game1.currentLocation;
+ }
+
+ if (CurrentLocation != null)
+ CurrentLocation.update(gameTime);
+
Events.InvokeUpdateTick();
base.Update(gameTime);
- KStatePrior = KStateNow;
PreviouslyPressedKeys = CurrentlyPressedKeys;
}
@@ -71,6 +107,63 @@ namespace StardewModdingAPI.Inheritance
{
Events.InvokeDrawTick();
base.Draw(gameTime);
+ spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ if (CurrentLocation != null)
+ CurrentLocation.draw(Game1.spriteBatch);
+ spriteBatch.End();
+ }
+
+ public static Int32 RegisterModItem(SObject modItem)
+ {
+ if (modItem.HasBeenRegistered)
+ {
+ Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
+ return modItem.RegisteredId;
+ }
+ Int32 newId = LowestModItemID;
+ if (ModItems.Count > 0)
+ newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
+ ModItems.Add(newId, modItem);
+ modItem.HasBeenRegistered = true;
+ modItem.RegisteredId = newId;
+ return newId;
+ }
+
+ public static SObject PullModItemFromDict(Int32 id, bool isIndex)
+ {
+ if (isIndex)
+ {
+ if (ModItems.ElementAtOrDefault(id).Value != null)
+ {
+ return ModItems.ElementAt(id).Value.Clone();
+ }
+ else
+ {
+ Program.LogError("ModItem Dictionary does not contain index: " + id);
+ return null;
+ }
+ }
+ else
+ {
+ if (ModItems.ContainsKey(id))
+ {
+ return ModItems[id].Clone();
+ }
+ else
+ {
+ Program.LogError("ModItem Dictionary does not contain ID: " + id);
+ return null;
+ }
+ }
+ }
+
+ public static SGameLocation GetLocationFromName(String name)
+ {
+ if (ModLocations.Any(x => x.name == name))
+ {
+ return ModLocations[ModLocations.IndexOf(ModLocations.First(x => x.name == name))];
+ }
+ return null;
}
}
} \ No newline at end of file
diff --git a/StardewModdingAPI/Inheritance/SGameLocation.cs b/StardewModdingAPI/Inheritance/SGameLocation.cs
new file mode 100644
index 00000000..f4523c21
--- /dev/null
+++ b/StardewModdingAPI/Inheritance/SGameLocation.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Eventing.Reader;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using StardewValley;
+using StardewValley.BellsAndWhistles;
+
+namespace StardewModdingAPI.Inheritance
+{
+ public class SGameLocation : GameLocation
+ {
+ public GameLocation BaseGameLocation { get; private set; }
+
+ public SerializableDictionary<Vector2, SObject> ModObjects { get; set; }
+
+ public static SGameLocation ConstructFromBaseClass(GameLocation baseClass)
+ {
+ SGameLocation s = new SGameLocation();
+ s.BaseGameLocation = baseClass;
+ s.ModObjects = new SerializableDictionary<Vector2, SObject>();
+ //s.IsFarm = baseClass.IsFarm;
+ //s.IsOutdoors = baseClass.IsOutdoors;
+ //s.LightLevel = baseClass.LightLevel;
+ //s.Map = baseClass.Map;
+ //s.objects = baseClass.objects;
+ //s.temporarySprites = baseClass.temporarySprites;
+ s.actionObjectForQuestionDialogue = baseClass.actionObjectForQuestionDialogue;
+ s.characters = baseClass.characters;
+ s.critters = (List<Critter>)typeof(GameLocation).GetField("critters", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(baseClass);
+ s.currentEvent = baseClass.currentEvent;
+ s.debris = baseClass.debris;
+ s.doorSprites = baseClass.doorSprites;
+ s.doors = baseClass.doors;
+ s.farmers = baseClass.farmers;
+ s.fishSplashAnimation = baseClass.fishSplashAnimation;
+ s.fishSplashPoint = baseClass.fishSplashPoint;
+ s.forceViewportPlayerFollow = baseClass.forceViewportPlayerFollow;
+ s.ignoreDebrisWeather = baseClass.ignoreDebrisWeather;
+ s.ignoreLights = baseClass.ignoreLights;
+ s.ignoreOutdoorLighting = baseClass.ignoreOutdoorLighting;
+ s.isFarm = baseClass.isFarm;
+ s.isOutdoors = baseClass.isOutdoors;
+ s.isStructure = baseClass.isStructure;
+ s.largeTerrainFeatures = baseClass.largeTerrainFeatures;
+ s.lastQuestionKey = baseClass.lastQuestionKey;
+ s.lastTouchActionLocation = baseClass.lastTouchActionLocation;
+ s.lightGlows = baseClass.lightGlows;
+ s.map = baseClass.map;
+ s.name = baseClass.name;
+ s.numberOfSpawnedObjectsOnMap = baseClass.numberOfSpawnedObjectsOnMap;
+ s.objects = baseClass.objects;
+ s.orePanAnimation = baseClass.orePanAnimation;
+ s.orePanPoint = baseClass.orePanPoint;
+ s.projectiles = baseClass.projectiles;
+ s.temporarySprites = baseClass.temporarySprites;
+ s.terrainFeatures = baseClass.terrainFeatures;
+ s.uniqueName = baseClass.uniqueName;
+ s.warps = baseClass.warps;
+ s.wasUpdated = (bool)typeof(GameLocation).GetField("wasUpdated", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(baseClass);
+ s.waterAnimationIndex = baseClass.waterAnimationIndex;
+ s.waterAnimationTimer = baseClass.waterAnimationTimer;
+ s.waterColor = baseClass.waterColor;
+ s.waterTileFlip = baseClass.waterTileFlip;
+ s.waterTiles = baseClass.waterTiles;
+ return s;
+ }
+
+ public static List<SGameLocation> ConvertGameLocations(List<GameLocation> baseGameLocations)
+ {
+ return baseGameLocations.Select(ConstructFromBaseClass).ToList();
+ }
+
+ public virtual void update(GameTime gameTime)
+ {
+ }
+
+ public override void draw(SpriteBatch b)
+ {
+ foreach (var v in ModObjects)
+ {
+ v.Value.draw(b, (int)v.Key.X, (int)v.Key.Y, -999999, 1);
+ }
+ }
+ }
+}
diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs
new file mode 100644
index 00000000..e05b4f20
--- /dev/null
+++ b/StardewModdingAPI/Inheritance/SObject.cs
@@ -0,0 +1,188 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using StardewValley;
+using StardewValley.Locations;
+
+namespace StardewModdingAPI.Inheritance
+{
+ public class SObject : StardewValley.Object
+ {
+ public override String Name { get; set; }
+ public String Description { get; set; }
+ public Texture2D Texture { get; set; }
+ public String CategoryName { get; set; }
+ public Color CategoryColour { get; set; }
+ public Boolean IsPassable { get; set; }
+ public Boolean IsPlaceable { get; set; }
+ public Boolean HasBeenRegistered { get; set; }
+ public Int32 RegisteredId { get; set; }
+
+ public Int32 MaxStackSize { get; set; }
+
+ public Boolean WallMounted { get; set; }
+ public Vector2 DrawPosition { get; set; }
+
+ public Boolean FlaggedForPickup { get; set; }
+
+ public SObject()
+ {
+ Name = "Modded Item Name";
+ Description = "Modded Item Description";
+ CategoryName = "Modded Item Category";
+ Category = 4163;
+ CategoryColour = Color.White;
+ IsPassable = false;
+ IsPlaceable = false;
+ boundingBox = new Rectangle(0, 0, 64, 64);
+ }
+
+ public override string getDescription()
+ {
+ return Description;
+ }
+
+ 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));
+ }
+
+ public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
+ {
+ if (Texture != null)
+ {
+ spriteBatch.Draw(Texture, new Vector2(xNonTile, yNonTile), null, new Color(255, 255, 255, 255f * alpha), 0, Vector2.Zero, 1, SpriteEffects.None, layerDepth);
+ spriteBatch.DrawString(Game1.dialogueFont, "TARG: " + new Vector2(xNonTile, yNonTile), new Vector2(128, 0), Color.Red);
+ }
+ }
+
+ public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber)
+ {
+ if (this.isRecipe)
+ {
+ transparency = 0.5f;
+ scaleSize *= 0.75f;
+ }
+
+ if (Texture != null)
+ {
+ int targSize = (int) (64 * scaleSize * 0.9f);
+ int midX = (int) ((location.X) + 32);
+ int midY = (int) ((location.Y) + 32);
+
+ int targX = midX - targSize / 2;
+ int targY = midY - targSize / 2;
+
+ spriteBatch.Draw(Texture, new Rectangle(targX, targY, targSize, targSize), null, new Color(255, 255, 255, transparency), 0, Vector2.Zero, SpriteEffects.None, layerDepth);
+ }
+ if (drawStackNumber)
+ {
+ float scale = 0.5f + scaleSize;
+ Game1.drawWithBorder(string.Concat(this.stack), Color.Black, Color.White, location + new Vector2((float) Game1.tileSize - Game1.tinyFont.MeasureString(string.Concat(this.stack)).X * scale, (float) Game1.tileSize - (float) ((double) Game1.tinyFont.MeasureString(string.Concat(this.stack)).Y * 3.0f / 4.0f) * scale), 0.0f, scale, 1f, true);
+ }
+ }
+
+ public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f)
+ {
+ if (Texture != null)
+ {
+ int targSize = 64;
+ int midX = (int) ((objectPosition.X) + 32);
+ int midY = (int) ((objectPosition.Y) + 32);
+
+ int targX = midX - targSize / 2;
+ int targY = midY - targSize / 2;
+
+ spriteBatch.Draw(Texture, new Rectangle(targX, targY, targSize, targSize), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (f.getStandingY() + 2) / 10000f);
+ }
+ }
+
+ public override Color getCategoryColor()
+ {
+ return CategoryColour;
+ }
+
+ public override string getCategoryName()
+ {
+ if (string.IsNullOrEmpty(CategoryName))
+ return "Modded Item";
+ return CategoryName;
+ }
+
+ public override bool isPassable()
+ {
+ return IsPassable;
+ }
+
+ public override bool isPlaceable()
+ {
+ return IsPlaceable;
+ }
+
+ public override int maximumStackSize()
+ {
+ return MaxStackSize;
+ }
+
+ public SObject Clone()
+ {
+ SObject toRet = new SObject();
+
+ toRet.Name = this.Name;
+ toRet.CategoryName = this.CategoryName;
+ toRet.Description = this.Description;
+ toRet.Texture = this.Texture;
+ toRet.IsPassable = this.IsPassable;
+ toRet.IsPlaceable = this.IsPlaceable;
+ toRet.quality = this.quality;
+ toRet.scale = this.scale;
+ toRet.isSpawnedObject = this.isSpawnedObject;
+ toRet.isRecipe = this.isRecipe;
+ toRet.questItem = this.questItem;
+ toRet.stack = 1;
+ toRet.HasBeenRegistered = this.HasBeenRegistered;
+ toRet.RegisteredId = this.RegisteredId;
+
+ return toRet;
+ }
+
+ public override Item getOne()
+ {
+ return this.Clone();
+ }
+
+ public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
+ {
+ SGameLocation s = SGame.GetLocationFromName(location.name);
+
+ 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();
+ }
+
+ Console.Title = (this.GetHashCode() + " PLACEMENT");
+
+ if (s != null)
+ {
+ Vector2 index1 = new Vector2((float)(x / Game1.tileSize), (float)(y / Game1.tileSize));
+ if (!s.ModObjects.ContainsKey(index1))
+ {
+ s.ModObjects.Add(index1, this);
+ return true;
+ }
+ }
+ else
+ {
+ Program.LogError("No SGameLocation could be found for the supplied GameLocation!");
+ return false;
+ }
+ return false;
+ }
+ }
+} \ No newline at end of file