diff options
Diffstat (limited to 'StardewModdingAPI/Inheritance')
-rw-r--r-- | StardewModdingAPI/Inheritance/ItemStackChange.cs | 2 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/Menus/SBobberBar.cs | 29 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/Menus/SGameMenu.cs | 14 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs | 12 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/Minigames/SMinigameBase.cs | 4 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/SBareObject.cs | 11 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/SGame.cs | 397 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/SObject.cs | 538 |
8 files changed, 594 insertions, 413 deletions
diff --git a/StardewModdingAPI/Inheritance/ItemStackChange.cs b/StardewModdingAPI/Inheritance/ItemStackChange.cs index cfadea04..88fc002e 100644 --- a/StardewModdingAPI/Inheritance/ItemStackChange.cs +++ b/StardewModdingAPI/Inheritance/ItemStackChange.cs @@ -15,4 +15,4 @@ namespace StardewModdingAPI.Inheritance public int StackChange { get; set; }
public ChangeType ChangeType { get; set; }
}
-}
+}
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs b/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs index ecfc0c38..ddac33c6 100644 --- a/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs +++ b/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs @@ -7,20 +7,28 @@ namespace StardewModdingAPI.Inheritance.Menus { public class SBobberBar : BobberBar { + /// <summary> + /// DO NOT CONSTRUCT THIS CLASS + /// To retrieve an instance of SBobberBar, use SBobberBar.ConstructFromBaseClass() + /// </summary> + public SBobberBar(int whichFish, float fishSize, bool treasure, int bobber) : base(whichFish, fishSize, treasure, bobber) + { + } + public BobberBar BaseBobberBar { get; private set; } /// <summary> - /// The green rectangle bar that moves up and down + /// The green rectangle bar that moves up and down /// </summary> public float bobberPosition { get { return (float) GetBaseFieldInfo("bobberPosition").GetValue(BaseBobberBar); } set { GetBaseFieldInfo("bobberPosition").SetValue(BaseBobberBar, value); } } - + /// <summary> - /// The green bar on the right. How close to catching the fish you are - /// Range: 0 - 1 | 1 = catch, 0 = fail + /// The green bar on the right. How close to catching the fish you are + /// Range: 0 - 1 | 1 = catch, 0 = fail /// </summary> public float distanceFromCatching { @@ -137,7 +145,7 @@ namespace StardewModdingAPI.Inheritance.Menus } /// <summary> - /// Whether or not a treasure chest appears + /// Whether or not a treasure chest appears /// </summary> public bool treasure { @@ -266,20 +274,11 @@ namespace StardewModdingAPI.Inheritance.Menus public static SBobberBar ConstructFromBaseClass(BobberBar baseClass) { - SBobberBar b = new SBobberBar(0, 0, false, 0); + var b = new SBobberBar(0, 0, false, 0); b.BaseBobberBar = baseClass; return b; } - /// <summary> - /// DO NOT CONSTRUCT THIS CLASS - /// To retrieve an instance of SBobberBar, use SBobberBar.ConstructFromBaseClass() - /// </summary> - public SBobberBar(int whichFish, float fishSize, bool treasure, int bobber) : base(whichFish, fishSize, treasure, bobber) - { - - } - public static FieldInfo[] GetPrivateFields() { return typeof (BobberBar).GetFields(BindingFlags.Instance | BindingFlags.NonPublic); diff --git a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs index 43ea30d7..f45758f7 100644 --- a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs +++ b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs @@ -10,19 +10,19 @@ namespace StardewModdingAPI.Inheritance.Menus public List<ClickableComponent> tabs { - get { return (List<ClickableComponent>)GetBaseFieldInfo("tabs").GetValue(BaseGameMenu); } + 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); } + get { return (List<IClickableMenu>) GetBaseFieldInfo("pages").GetValue(BaseGameMenu); } set { GetBaseFieldInfo("pages").SetValue(BaseGameMenu, value); } } public static SGameMenu ConstructFromBaseClass(GameMenu baseClass) { - SGameMenu s = new SGameMenu(); + var s = new SGameMenu(); s.BaseGameMenu = baseClass; return s; } @@ -31,19 +31,19 @@ namespace StardewModdingAPI.Inheritance.Menus { if (pages[currentTab] is InventoryPage) { - Log.Verbose("INV SCREEN"); + Log.AsyncY("INV SCREEN"); } base.receiveRightClick(x, y, playSound); } public static FieldInfo[] GetPrivateFields() { - return typeof(GameMenu).GetFields(BindingFlags.Instance | BindingFlags.NonPublic); + return typeof (GameMenu).GetFields(BindingFlags.Instance | BindingFlags.NonPublic); } public static FieldInfo GetBaseFieldInfo(string name) { - return typeof(GameMenu).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic); + return typeof (GameMenu).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic); } } -} +}
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs b/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs index d798fc95..a51b2d71 100644 --- a/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs +++ b/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs @@ -4,17 +4,17 @@ namespace StardewModdingAPI.Inheritance.Menus { public class SInventoryPage : InventoryPage { + public SInventoryPage(int x, int y, int width, int height) : base(x, y, width, height) + { + } + public InventoryPage BaseInventoryPage { get; private set; } public static SInventoryPage ConstructFromBaseClass(InventoryPage baseClass) { - SInventoryPage s = new SInventoryPage(0,0,0,0); + var 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) - { - } } -} +}
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/Minigames/SMinigameBase.cs b/StardewModdingAPI/Inheritance/Minigames/SMinigameBase.cs index 08a5e861..f30021de 100644 --- a/StardewModdingAPI/Inheritance/Minigames/SMinigameBase.cs +++ b/StardewModdingAPI/Inheritance/Minigames/SMinigameBase.cs @@ -5,7 +5,7 @@ using StardewValley.Minigames; namespace StardewModdingAPI.Inheritance.Minigames { - abstract class SMinigameBase : IMinigame + internal abstract class SMinigameBase : IMinigame { public abstract bool tick(GameTime time); @@ -31,4 +31,4 @@ namespace StardewModdingAPI.Inheritance.Minigames public abstract void receiveEventPoke(int data); } -} +}
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SBareObject.cs b/StardewModdingAPI/Inheritance/SBareObject.cs index 905dac0d..5bef7b3e 100644 --- a/StardewModdingAPI/Inheritance/SBareObject.cs +++ b/StardewModdingAPI/Inheritance/SBareObject.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.AccessControl; -using System.Text; -using System.Threading.Tasks; - -namespace StardewModdingAPI.Inheritance +namespace StardewModdingAPI.Inheritance { public struct SBareObject { @@ -24,4 +17,4 @@ namespace StardewModdingAPI.Inheritance quality = qua; } } -} +}
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index ce2488d5..f1887253 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -11,60 +11,264 @@ using StardewValley.Menus; namespace StardewModdingAPI.Inheritance
{
+ /// <summary>
+ /// The 'SGame' class.
+ /// This summary, and many others, only exists because XML doc tags.
+ /// </summary>
public class SGame : Game1
{
- public static Dictionary<Int32, SObject> ModItems { get; private set; }
- public const Int32 LowestModItemID = 1000;
+ /// <summary>
+ /// Useless right now.
+ /// </summary>
+ public const int LowestModItemID = 1000;
- public static FieldInfo[] StaticFields { get { return GetStaticFields(); } }
+ private bool FireLoadedGameEvent;
+
+ /// <summary>
+ /// Gets a jagged array of all buttons pressed on the gamepad the prior frame.
+ /// </summary>
+ public Buttons[][] PreviouslyPressedButtons;
- public static FieldInfo[] GetStaticFields()
+ internal SGame()
{
- return typeof(Game1).GetFields();
+ Instance = this;
+ FirstUpdate = true;
}
+ /// <summary>
+ /// Useless at this time.
+ /// </summary>
+ [Obsolete]
+ public static Dictionary<int, SObject> ModItems { get; private set; }
+
+ /// <summary>
+ /// The current KeyboardState
+ /// </summary>
public KeyboardState KStateNow { get; private set; }
+ /// <summary>
+ /// The prior KeyboardState
+ /// </summary>
public KeyboardState KStatePrior { get; private set; }
+ /// <summary>
+ /// The current MouseState
+ /// </summary>
public MouseState MStateNow { get; private set; }
+
+ /// <summary>
+ /// The prior MouseState
+ /// </summary>
public MouseState MStatePrior { get; private set; }
+ /// <summary>
+ /// All keys pressed on the current frame
+ /// </summary>
public Keys[] CurrentlyPressedKeys => KStateNow.GetPressedKeys();
+
+ /// <summary>
+ /// All keys pressed on the prior frame
+ /// </summary>
public Keys[] PreviouslyPressedKeys => KStatePrior.GetPressedKeys();
+ /// <summary>
+ /// All keys pressed on this frame except for the ones pressed on the prior frame
+ /// </summary>
public Keys[] FramePressedKeys => CurrentlyPressedKeys.Except(PreviouslyPressedKeys).ToArray();
+ /// <summary>
+ /// All keys pressed on the prior frame except for the ones pressed on the current frame
+ /// </summary>
public Keys[] FrameReleasedKeys => PreviouslyPressedKeys.Except(CurrentlyPressedKeys).ToArray();
- public Buttons[][] PreviouslyPressedButtons;
+ /// <summary>
+ /// Whether or not a save was tagged as 'Loaded' the prior frame.
+ /// </summary>
+ public bool PreviouslyLoadedGame { get; private set; }
+
+ /// <summary>
+ /// The list of GameLocations on the prior frame
+ /// </summary>
+ public int PreviousGameLocations { get; private set; }
+
+ /// <summary>
+ /// The list of GameObjects on the prior frame
+ /// </summary>
+ public int PreviousLocationObjects { get; private set; }
+ /// <summary>
+ /// The list of Items in the player's inventory on the prior frame
+ /// </summary>
+ public Dictionary<Item, int> PreviousItems { get; private set; }
+
+ /// <summary>
+ /// The player's Combat level on the prior frame
+ /// </summary>
+ public int PreviousCombatLevel { get; private set; }
+ /// <summary>
+ /// The player's Farming level on the prior frame
+ /// </summary>
+ public int PreviousFarmingLevel { get; private set; }
+ /// <summary>
+ /// The player's Fishing level on the prior frame
+ /// </summary>
+ public int PreviousFishingLevel { get; private set; }
+ /// <summary>
+ /// The player's Foraging level on the prior frame
+ /// </summary>
+ public int PreviousForagingLevel { get; private set; }
+ /// <summary>
+ /// The player's Mining level on the prior frame
+ /// </summary>
+ public int PreviousMiningLevel { get; private set; }
+ /// <summary>
+ /// The player's Luck level on the prior frame
+ /// </summary>
+ public int PreviousLuckLevel { get; private set; }
+
+ //Kill me now comments are so boring
+
+ /// <summary>
+ /// The player's previous game location
+ /// </summary>
+ public GameLocation PreviousGameLocation { get; private set; }
+
+ /// <summary>
+ /// The previous ActiveGameMenu in Game1
+ /// </summary>
+ public IClickableMenu PreviousActiveMenu { get; private set; }
+
+ /// <summary>
+ /// The previous mine level
+ /// </summary>
+ public int PreviousMineLevel { get; private set; }
+
+ /// <summary>
+ /// The previous TimeOfDay (Int32 between 600 and 2400?)
+ /// </summary>
+ public int PreviousTimeOfDay { get; private set; }
+
+ /// <summary>
+ /// The previous DayOfMonth (Int32 between 1 and 28?)
+ /// </summary>
+ public int PreviousDayOfMonth { get; private set; }
+
+ /// <summary>
+ /// The previous Season (String as follows: "winter", "spring", "summer", "fall")
+ /// </summary>
+ public string PreviousSeasonOfYear { get; private set; }
+
+ /// <summary>
+ /// The previous Year
+ /// </summary>
+ public int PreviousYearOfGame { get; private set; }
+
+ /// <summary>
+ /// The previous 'Farmer' (Player)
+ /// </summary>
+ public Farmer PreviousFarmer { get; private set; }
+
+ /// <summary>
+ /// The current index of the update tick. Recycles every 60th tick to 0. (Int32 between 0 and 59)
+ /// </summary>
+ public int CurrentUpdateTick { get; private set; }
+
+ /// <summary>
+ /// Whether or not this update frame is the very first of the entire game
+ /// </summary>
+ public bool FirstUpdate { get; private set; }
+
+ /// <summary>
+ /// The current RenderTarget in Game1 (Private field, uses reflection)
+ /// </summary>
+ public RenderTarget2D Screen
+ {
+ get { return typeof (Game1).GetBaseFieldValue<RenderTarget2D>(Program.gamePtr, "screen"); }
+ set { typeof (Game1).SetBaseFieldValue<RenderTarget2D>(this, "screen", value); }
+ }
+
+ /// <summary>
+ /// Static accessor for an Instance of the class SGame
+ /// </summary>
+ public static SGame Instance { get; private set; }
+
+ /// <summary>
+ /// The game's FPS. Re-determined every Draw update.
+ /// </summary>
+ public static float FramesPerSecond { get; private set; }
+
+ /// <summary>
+ /// Whether or not we're in a pseudo 'debug' mode. Mostly for displaying information like FPS.
+ /// </summary>
+ public static bool Debug { get; private set; }
+
+ /// <summary>
+ /// The current player (equal to Farmer.Player)
+ /// </summary>
+ [Obsolete("Use Farmer.Player instead")]
+ public Farmer CurrentFarmer => player;
+
+ /// <summary>
+ /// Gets ALL static fields that belong to 'Game1'
+ /// </summary>
+ public static FieldInfo[] GetStaticFields => typeof (Game1).GetFields();
+
+ /// <summary>
+ /// Whether or not a button was just pressed on the controller
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="buttonState"></param>
+ /// <param name="stateIndex"></param>
+ /// <returns></returns>
private bool WasButtonJustPressed(Buttons button, ButtonState buttonState, PlayerIndex stateIndex)
{
- return buttonState == ButtonState.Pressed && !PreviouslyPressedButtons[(int)stateIndex].Contains(button);
+ return buttonState == ButtonState.Pressed && !PreviouslyPressedButtons[(int) stateIndex].Contains(button);
}
+ /// <summary>
+ /// Whether or not a button was just released on the controller
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="buttonState"></param>
+ /// <param name="stateIndex"></param>
+ /// <returns></returns>
private bool WasButtonJustReleased(Buttons button, ButtonState buttonState, PlayerIndex stateIndex)
{
- return buttonState == ButtonState.Released && PreviouslyPressedButtons[(int)stateIndex].Contains(button);
+ return buttonState == ButtonState.Released && PreviouslyPressedButtons[(int) stateIndex].Contains(button);
}
+ /// <summary>
+ /// Whether or not an analog button was just pressed on the controller
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="value"></param>
+ /// <param name="stateIndex"></param>
+ /// <returns></returns>
private bool WasButtonJustPressed(Buttons button, float value, PlayerIndex stateIndex)
{
return WasButtonJustPressed(button, value > 0.2f ? ButtonState.Pressed : ButtonState.Released, stateIndex);
}
-
+
+ /// <summary>
+ /// Whether or not an analog button was just released on the controller
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="value"></param>
+ /// <param name="stateIndex"></param>
+ /// <returns></returns>
private bool WasButtonJustReleased(Buttons button, float value, PlayerIndex stateIndex)
{
return WasButtonJustReleased(button, value > 0.2f ? ButtonState.Pressed : ButtonState.Released, stateIndex);
}
- public bool PreviouslyLoadedGame { get; private set; }
- private bool FireLoadedGameEvent;
-
+ /// <summary>
+ /// Gets an array of all Buttons pressed on a joystick
+ /// </summary>
+ /// <param name="index"></param>
+ /// <returns></returns>
public Buttons[] GetButtonsDown(PlayerIndex index)
{
- GamePadState state = GamePad.GetState(index);
- List<Buttons> buttons = new List<Buttons>();
+ var state = GamePad.GetState(index);
+ var buttons = new List<Buttons>();
if (state.IsConnected)
{
if (state.Buttons.A == ButtonState.Pressed) buttons.Add(Buttons.A);
@@ -88,15 +292,20 @@ namespace StardewModdingAPI.Inheritance return buttons.ToArray();
}
+ /// <summary>
+ /// Gets all buttons that were pressed on the current frame of a joystick
+ /// </summary>
+ /// <param name="index"></param>
+ /// <returns></returns>
public Buttons[] GetFramePressedButtons(PlayerIndex index)
- {
- GamePadState state = GamePad.GetState(index);
- List<Buttons> buttons = new List<Buttons>();
+ {
+ var state = GamePad.GetState(index);
+ var buttons = new List<Buttons>();
if (state.IsConnected)
{
- if (WasButtonJustPressed(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A);
- if (WasButtonJustPressed(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B);
- if (WasButtonJustPressed(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back);
+ if (WasButtonJustPressed(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A);
+ if (WasButtonJustPressed(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B);
+ if (WasButtonJustPressed(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back);
if (WasButtonJustPressed(Buttons.BigButton, state.Buttons.BigButton, index)) buttons.Add(Buttons.BigButton);
if (WasButtonJustPressed(Buttons.LeftShoulder, state.Buttons.LeftShoulder, index)) buttons.Add(Buttons.LeftShoulder);
if (WasButtonJustPressed(Buttons.LeftStick, state.Buttons.LeftStick, index)) buttons.Add(Buttons.LeftStick);
@@ -112,13 +321,18 @@ namespace StardewModdingAPI.Inheritance if (WasButtonJustPressed(Buttons.LeftTrigger, state.Triggers.Left, index)) buttons.Add(Buttons.LeftTrigger);
if (WasButtonJustPressed(Buttons.RightTrigger, state.Triggers.Right, index)) buttons.Add(Buttons.RightTrigger);
}
- return buttons.ToArray();
+ return buttons.ToArray();
}
+ /// <summary>
+ /// Gets all buttons that were released on the current frame of a joystick
+ /// </summary>
+ /// <param name="index"></param>
+ /// <returns></returns>
public Buttons[] GetFrameReleasedButtons(PlayerIndex index)
{
- GamePadState state = GamePad.GetState(index);
- List<Buttons> buttons = new List<Buttons>();
+ var state = GamePad.GetState(index);
+ var buttons = new List<Buttons>();
if (state.IsConnected)
{
if (WasButtonJustReleased(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A);
@@ -142,70 +356,34 @@ namespace StardewModdingAPI.Inheritance return buttons.ToArray();
}
- public int PreviousGameLocations { get; private set; }
- public int PreviousLocationObjects { get; private set; }
- public Dictionary<Item, int> PreviousItems { get; private set; }
-
- public int PreviousCombatLevel { get; private set; }
- public int PreviousFarmingLevel { get; private set; }
- public int PreviousFishingLevel { get; private set; }
- public int PreviousForagingLevel { get; private set; }
- public int PreviousMiningLevel { get; private set; }
- public int PreviousLuckLevel { get; private set; }
-
- public GameLocation PreviousGameLocation { get; private set; }
- public IClickableMenu PreviousActiveMenu { get; private set; }
-
- public int PreviousMineLevel { get; private set; }
-
- public Int32 PreviousTimeOfDay { get; private set; }
- public Int32 PreviousDayOfMonth { get; private set; }
- public String PreviousSeasonOfYear { get; private set; }
- public Int32 PreviousYearOfGame { get; private set; }
-
- public Farmer PreviousFarmer { get; private set; }
-
- public Int32 CurrentUpdateTick { get; private set; }
- public bool FirstUpdate { get; private set; }
-
- public RenderTarget2D Screen
- {
- get { return typeof (Game1).GetBaseFieldValue<RenderTarget2D>(Program.gamePtr, "screen"); }
- set { typeof (Game1).SetBaseFieldValue<RenderTarget2D>(this, "screen", value); }
- }
-
- private static SGame instance;
- public static SGame Instance => instance;
-
- public static float FramesPerSecond { get; private set; }
- public static bool Debug { get; private set; }
-
- public Farmer CurrentFarmer => player;
-
- public SGame()
- {
- instance = this;
- FirstUpdate = true;
- }
-
+ /// <summary>
+ /// XNA Init Method
+ /// </summary>
protected override void Initialize()
{
- Log.Verbose("XNA Initialize");
- ModItems = new Dictionary<Int32, SObject>();
+ Log.AsyncY("XNA Initialize");
+ //ModItems = new Dictionary<int, SObject>();
PreviouslyPressedButtons = new Buttons[4][];
- for (int i = 0; i < 4; ++i) PreviouslyPressedButtons[i] = new Buttons[0];
+ for (var i = 0; i < 4; ++i) PreviouslyPressedButtons[i] = new Buttons[0];
base.Initialize();
GameEvents.InvokeInitialize();
}
+ /// <summary>
+ /// XNA LC Method
+ /// </summary>
protected override void LoadContent()
{
- Log.Verbose("XNA LoadContent");
+ Log.AsyncY("XNA LoadContent");
base.LoadContent();
GameEvents.InvokeLoadContent();
}
+ /// <summary>
+ /// XNA Update Method
+ /// </summary>
+ /// <param name="gameTime"></param>
protected override void Update(GameTime gameTime)
{
UpdateEventCalls();
@@ -221,7 +399,7 @@ namespace StardewModdingAPI.Inheritance }
catch (Exception ex)
{
- Log.Error("An error occured in the base update loop: " + ex);
+ Log.AsyncR("An error occured in the base update loop: " + ex);
Console.ReadKey();
}
@@ -257,15 +435,19 @@ namespace StardewModdingAPI.Inheritance if (KStatePrior != KStateNow)
KStatePrior = KStateNow;
- for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ for (var i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
{
- PreviouslyPressedButtons[(int)i] = GetButtonsDown(i);
+ PreviouslyPressedButtons[(int) i] = GetButtonsDown(i);
}
}
+ /// <summary>
+ /// XNA Draw Method
+ /// </summary>
+ /// <param name="gameTime"></param>
protected override void Draw(GameTime gameTime)
{
- FramesPerSecond = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
+ FramesPerSecond = 1 / (float) gameTime.ElapsedGameTime.TotalSeconds;
try
{
@@ -273,7 +455,7 @@ namespace StardewModdingAPI.Inheritance }
catch (Exception ex)
{
- Log.Error("An error occured in the base draw loop: " + ex);
+ Log.AsyncR("An error occured in the base draw loop: " + ex);
Console.ReadKey();
}
@@ -299,6 +481,12 @@ namespace StardewModdingAPI.Inheritance //spriteBatch.End();
+ //Re-draw the HUD
+ spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
+ if ((displayHUD || eventUp) && currentBillboard == 0 && gameMode == 3 && !freezeControls && !panMode)
+ typeof (Game1).GetMethod("drawHUD", BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(Program.gamePtr, null);
+ spriteBatch.End();
+
if (!options.zoomLevel.Equals(1.0f))
{
GraphicsDevice.SetRenderTarget(null);
@@ -306,11 +494,6 @@ namespace StardewModdingAPI.Inheritance spriteBatch.Draw(Screen, Vector2.Zero, Screen.Bounds, Color.White, 0.0f, Vector2.Zero, options.zoomLevel, SpriteEffects.None, 1f);
spriteBatch.End();
}
-
- //Re-draw the mouse
- spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
- spriteBatch.Draw(mouseCursors, new Vector2(getMouseX(), getMouseY()), getSourceRectForStandardTileSheet(mouseCursors, mouseCursor, 16, 16), Color.White * mouseCursorTransparency, 0.0f, Vector2.Zero, pixelZoom + dialogueButtonScale / 150f, SpriteEffects.None, 1f);
- spriteBatch.End();
}
if (Debug)
@@ -321,14 +504,15 @@ namespace StardewModdingAPI.Inheritance }
}
- public static Int32 RegisterModItem(SObject modItem)
+ [Obsolete("Do not use at this time.")]
+ private static int RegisterModItem(SObject modItem)
{
if (modItem.HasBeenRegistered)
{
- Log.Error("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
+ Log.AsyncR($"The item {modItem.Name} has already been registered with ID {modItem.RegisteredId}");
return modItem.RegisteredId;
}
- Int32 newId = LowestModItemID;
+ var newId = LowestModItemID;
if (ModItems.Count > 0)
newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
ModItems.Add(newId, modItem);
@@ -337,7 +521,8 @@ namespace StardewModdingAPI.Inheritance return newId;
}
- public static SObject PullModItemFromDict(Int32 id, bool isIndex)
+ [Obsolete("Do not use at this time.")]
+ private static SObject PullModItemFromDict(int id, bool isIndex)
{
if (isIndex)
{
@@ -345,35 +530,35 @@ namespace StardewModdingAPI.Inheritance {
return ModItems.ElementAt(id).Value.Clone();
}
- Log.Error("ModItem Dictionary does not contain index: " + id);
+ Log.AsyncR("ModItem Dictionary does not contain index: " + id);
return null;
}
if (ModItems.ContainsKey(id))
{
return ModItems[id].Clone();
}
- Log.Error("ModItem Dictionary does not contain ID: " + id);
+ Log.AsyncR("ModItem Dictionary does not contain ID: " + id);
return null;
}
-
- public void UpdateEventCalls()
+
+ private void UpdateEventCalls()
{
KStateNow = Keyboard.GetState();
MStateNow = Mouse.GetState();
- foreach (Keys k in FramePressedKeys)
+ foreach (var k in FramePressedKeys)
ControlEvents.InvokeKeyPressed(k);
- foreach (Keys k in FrameReleasedKeys)
+ foreach (var k in FrameReleasedKeys)
ControlEvents.InvokeKeyReleased(k);
- for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ for (var i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
{
- Buttons[] buttons = GetFramePressedButtons(i);
- foreach (Buttons b in buttons)
+ var buttons = GetFramePressedButtons(i);
+ foreach (var b in buttons)
{
- if(b == Buttons.LeftTrigger || b == Buttons.RightTrigger)
+ if (b == Buttons.LeftTrigger || b == Buttons.RightTrigger)
{
ControlEvents.InvokeTriggerPressed(i, b, b == Buttons.LeftTrigger ? GamePad.GetState(i).Triggers.Left : GamePad.GetState(i).Triggers.Right);
}
@@ -384,9 +569,9 @@ namespace StardewModdingAPI.Inheritance }
}
- for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ for (var i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
{
- foreach (Buttons b in GetFrameReleasedButtons(i))
+ foreach (var b in GetFrameReleasedButtons(i))
{
if (b == Buttons.LeftTrigger || b == Buttons.RightTrigger)
{
@@ -471,7 +656,7 @@ namespace StardewModdingAPI.Inheritance PreviousLuckLevel = player.luckLevel;
}
- List<ItemStackChange> changedItems;
+ List<ItemStackChange> changedItems;
if (player != null && HasInventoryChanged(player.items, out changedItems))
{
PlayerEvents.InvokeInventoryChanged(player.items, changedItems);
@@ -479,7 +664,7 @@ namespace StardewModdingAPI.Inheritance }
var objectHash = currentLocation?.objects?.GetHash();
- if(objectHash != null && PreviousLocationObjects != objectHash)
+ if (objectHash != null && PreviousLocationObjects != objectHash)
{
LocationEvents.InvokeOnNewLocationObject(currentLocation.objects);
PreviousLocationObjects = objectHash ?? -1;
@@ -537,24 +722,24 @@ namespace StardewModdingAPI.Inheritance {
if (PreviousItems != null && PreviousItems.ContainsKey(item))
{
- if(PreviousItems[item] != item.Stack)
+ if (PreviousItems[item] != item.Stack)
{
- changedItems.Add(new ItemStackChange { Item = item, StackChange = item.Stack - PreviousItems[item], ChangeType = ChangeType.StackChange });
+ changedItems.Add(new ItemStackChange {Item = item, StackChange = item.Stack - PreviousItems[item], ChangeType = ChangeType.StackChange});
}
}
else
{
- changedItems.Add(new ItemStackChange { Item = item, StackChange = item.Stack, ChangeType = ChangeType.Added });
+ changedItems.Add(new ItemStackChange {Item = item, StackChange = item.Stack, ChangeType = ChangeType.Added});
}
}
if (PreviousItems != null)
{
changedItems.AddRange(PreviousItems.Where(n => actualItems.All(i => i != n.Key)).Select(n =>
- new ItemStackChange { Item = n.Key, StackChange = -n.Key.Stack, ChangeType = ChangeType.Removed }));
+ new ItemStackChange {Item = n.Key, StackChange = -n.Key.Stack, ChangeType = ChangeType.Removed}));
}
- return (changedItems.Any());
+ return changedItems.Any();
}
}
}
\ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index ea32d2fc..9ffe2a85 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -1,271 +1,275 @@ -using System; -using System.Xml.Serialization; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using StardewValley; -using Object = StardewValley.Object; - -namespace StardewModdingAPI.Inheritance -{ - public class SObject : Object - { - 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; } - 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; } - - [XmlIgnore] - public Vector2 CurrentMouse { get; protected set; } - [XmlIgnore] - public Vector2 PlacedAt { get; protected set; } - - public override int Stack - { - get { return stack; } - set { stack = value; } - } - - 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); - MaxStackSize = 999; - - type = "interactive"; - } - - public override string getDescription() - { - return Description; - } - - public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) +using System;
+using System.Xml.Serialization;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using StardewValley;
+using Object = StardewValley.Object;
+
+#pragma warning disable 1591
+
+namespace StardewModdingAPI.Inheritance
+{
+ [Obsolete("Do not use at this time.")]
+ public class SObject : Object
+ {
+ 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);
+ MaxStackSize = 999;
+
+ type = "interactive";
+ }
+
+ 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; }
+ public Color CategoryColour { get; set; }
+ public bool IsPassable { get; set; }
+ public bool IsPlaceable { get; set; }
+ public bool HasBeenRegistered { get; set; }
+ public int RegisteredId { get; set; }
+
+ public int MaxStackSize { get; set; }
+
+ public bool WallMounted { get; set; }
+ public Vector2 DrawPosition { get; set; }
+
+ public bool FlaggedForPickup { get; set; }
+
+ [XmlIgnore]
+ public Vector2 CurrentMouse { get; protected set; }
+
+ [XmlIgnore]
+ public Vector2 PlacedAt { get; protected set; }
+
+ public override int Stack
+ {
+ get { return stack; }
+ set { stack = value; }
+ }
+
+ 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, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * Game1.tileSize + Game1.tileSize / 2 + (shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), y * Game1.tileSize + Game1.tileSize / 2 + (shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0))), Game1.currentLocation.getSourceRectForObject(ParentSheetIndex), Color.White * alpha, 0f, new Vector2(8f, 8f), scale.Y > 1f ? getScale().Y : Game1.pixelZoom, flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (isPassable() ? getBoundingBox(new Vector2(x, y)).Top : getBoundingBox(new Vector2(x, y)).Bottom) / 10000f);
+ }
+ }
+
+ public new void drawAsProp(SpriteBatch b)
+ {
+ }
+
+ public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
+ {
+ Log.Debug("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED");
+ //try
+ //{
+ // if (Texture != null)
+ // {
+ // int targSize = Game1.tileSize;
+ // int midX = (xNonTile) + 32;
+ // int midY = (yNonTile) + 32;
+
+ // int targX = midX - targSize / 2;
+ // int targY = midY - targSize / 2;
+
+ // Rectangle targ = new Rectangle(targX, targY, targSize, targSize);
+ // spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha), 0, Vector2.Zero, SpriteEffects.None, layerDepth);
+ // //spriteBatch.Draw(Program.DebugPixel, targ, null, Color.Red, 0, Vector2.Zero, SpriteEffects.None, layerDepth);
+ // /*
+ // spriteBatch.DrawString(Game1.dialogueFont, "TARG: " + targ, new Vector2(128, 0), Color.Red);
+ // spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX * 0.5f, targY), Color.Orange);
+ // spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX, targY), Color.Red);
+ // spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX * 1.5f, targY), Color.Yellow);
+ // spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX * 2f, targY), Color.Green);
+ // */
+ // }
+ //}
+ //catch (Exception ex)
+ //{
+ // Log.AsyncR(ex.ToString());
+ // Console.ReadKey();
+ //}
+ }
+
+ public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber)
+ {
+ if (isRecipe)
+ {
+ transparency = 0.5f;
+ scaleSize *= 0.75f;
+ }
+
+ if (Texture != null)
+ {
+ var targSize = (int) (64 * scaleSize * 0.9f);
+ var midX = (int) (location.X + 32);
+ var midY = (int) (location.Y + 32);
+
+ var targX = midX - targSize / 2;
+ var 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)
+ {
+ var _scale = 0.5f + scaleSize;
+ Game1.drawWithBorder(stack.ToString(), Color.Black, Color.White, location + new Vector2(Game1.tileSize - Game1.tinyFont.MeasureString(string.Concat(stack.ToString())).X * _scale, Game1.tileSize - (float) ((double) Game1.tinyFont.MeasureString(string.Concat(stack.ToString())).Y * 3.0f / 4.0f) * _scale), 0.0f, _scale, 1f, true);
+ }
+ }
+
+ public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f)
+ {
+ if (Texture != null)
+ {
+ var targSize = 64;
+ var midX = (int) (objectPosition.X + 32);
+ var midY = (int) (objectPosition.Y + 32);
+
+ var targX = midX - targSize / 2;
+ var 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()
{
- if (Texture != null) - { - spriteBatch.Draw(Texture, Game1.GlobalToLocal(Game1.viewport, new Vector2(((x * Game1.tileSize) + (Game1.tileSize / 2)) + ((shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), ((y * Game1.tileSize) + (Game1.tileSize / 2)) + ((shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0))), Game1.currentLocation.getSourceRectForObject(ParentSheetIndex), Color.White * alpha, 0f, new Vector2(8f, 8f), (scale.Y > 1f) ? getScale().Y : Game1.pixelZoom, flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (isPassable() ? getBoundingBox(new Vector2(x, y)).Top : getBoundingBox(new Vector2(x, y)).Bottom) / 10000f);
- } - } - - public void drawAsProp(SpriteBatch b)
+ 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()
+ {
+ var toRet = new SObject();
+
+ toRet.Name = Name;
+ toRet.CategoryName = CategoryName;
+ toRet.Description = Description;
+ toRet.Texture = Texture;
+ toRet.IsPassable = IsPassable;
+ toRet.IsPlaceable = IsPlaceable;
+ toRet.quality = quality;
+ toRet.scale = scale;
+ toRet.isSpawnedObject = isSpawnedObject;
+ toRet.isRecipe = isRecipe;
+ toRet.questItem = questItem;
+ toRet.stack = 1;
+ toRet.HasBeenRegistered = HasBeenRegistered;
+ toRet.RegisteredId = RegisteredId;
+
+ return toRet;
+ }
+
+ public override Item getOne()
+ {
+ return Clone();
+ }
+
+ public override void actionWhenBeingHeld(Farmer who)
+ {
+ var x = Game1.oldMouseState.X + Game1.viewport.X;
+ var y = Game1.oldMouseState.Y + Game1.viewport.Y;
+
+ x = x / Game1.tileSize;
+ y = y / Game1.tileSize;
+
+ CurrentMouse = new Vector2(x, y);
+ //Program.LogDebug(canBePlacedHere(Game1.currentLocation, CurrentMouse));
+ base.actionWhenBeingHeld(who);
+ }
+
+ public override bool canBePlacedHere(GameLocation l, Vector2 tile)
+ {
+ //Program.LogDebug(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)
+ {
+ if (Game1.didPlayerJustRightClick())
+ return false;
+
+ x = x / Game1.tileSize;
+ y = y / Game1.tileSize;
+
+ //Program.LogDebug(x + " - " + y);
+ //Console.ReadKey();
+
+ var key = new Vector2(x, y);
+
+ if (!canBePlacedHere(location, key))
+ return false;
+
+ var s = Clone();
+
+ s.PlacedAt = key;
+ s.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, boundingBox.Width, boundingBox.Height);
+
+ location.objects.Add(key, s);
+ Log.Async($"{GetHashCode()} - {s.GetHashCode()}");
+
+ return true;
+ }
+
+ public override void actionOnPlayerEntry()
+ {
+ //base.actionOnPlayerEntry();
+ }
+
+ public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
{
+ if (canBePlacedHere(location, CurrentMouse))
+ {
+ var targSize = Game1.tileSize;
- } - - public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) - { - Log.Debug("THIS DRAW FUNCTION IS NOT IMPLEMENTED I WANT TO KNOW WHERE IT IS CALLED"); - return; - try - { - if (Texture != null) - { - int targSize = Game1.tileSize; - int midX = (xNonTile) + 32; - int midY = (yNonTile) + 32; - - int targX = midX - targSize / 2; - int targY = midY - targSize / 2; - - Rectangle targ = new Rectangle(targX, targY, targSize, targSize); - spriteBatch.Draw(Texture, targ, null, new Color(255, 255, 255, 255f * alpha), 0, Vector2.Zero, SpriteEffects.None, layerDepth); - //spriteBatch.Draw(Program.DebugPixel, targ, null, Color.Red, 0, Vector2.Zero, SpriteEffects.None, layerDepth); - /* - spriteBatch.DrawString(Game1.dialogueFont, "TARG: " + targ, new Vector2(128, 0), Color.Red); - spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX * 0.5f, targY), Color.Orange); - spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX, targY), Color.Red); - spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX * 1.5f, targY), Color.Yellow); - spriteBatch.DrawString(Game1.dialogueFont, ".", new Vector2(targX * 2f, targY), Color.Green); - */ - } - } - catch (Exception ex) - { - Log.Error(ex.ToString()); - Console.ReadKey(); - } - } - - public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber) - { - if (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(stack.ToString()), Color.Black, Color.White, location + new Vector2(Game1.tileSize - Game1.tinyFont.MeasureString(string.Concat(stack.ToString())).X * scale, Game1.tileSize - (float) ((double) Game1.tinyFont.MeasureString(string.Concat(stack.ToString())).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 = Name; - toRet.CategoryName = CategoryName; - toRet.Description = Description; - toRet.Texture = Texture; - toRet.IsPassable = IsPassable; - toRet.IsPlaceable = IsPlaceable; - toRet.quality = quality; - toRet.scale = scale; - toRet.isSpawnedObject = isSpawnedObject; - toRet.isRecipe = isRecipe; - toRet.questItem = questItem; - toRet.stack = 1; - toRet.HasBeenRegistered = HasBeenRegistered; - toRet.RegisteredId = RegisteredId; - - return toRet; - } - - public override Item getOne() - { - return Clone(); - } - - public override void actionWhenBeingHeld(Farmer who) - { - int x = Game1.oldMouseState.X + Game1.viewport.X; - int y = Game1.oldMouseState.Y + Game1.viewport.Y; - - x = x / Game1.tileSize; - y = y / Game1.tileSize; - - CurrentMouse = new Vector2(x, y); - //Program.LogDebug(canBePlacedHere(Game1.currentLocation, CurrentMouse)); - base.actionWhenBeingHeld(who); - } - - public override bool canBePlacedHere(GameLocation l, Vector2 tile) - { - //Program.LogDebug(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) - { - if (Game1.didPlayerJustRightClick()) - return false; - - x = (x / Game1.tileSize); - y = (y / Game1.tileSize); - - //Program.LogDebug(x + " - " + y); - //Console.ReadKey(); - - Vector2 key = new Vector2(x, y); - - 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, boundingBox.Width, boundingBox.Height); - - location.objects.Add(key, s); - Log.Verbose("{0} - {1}", 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(x / Game1.tileSize * Game1.tileSize - Game1.viewport.X, y / Game1.tileSize * Game1.tileSize - Game1.viewport.Y), new Rectangle(Utility.playerCanPlaceItemHere(location, this, x, y, Game1.player) ? 194 : 210, 388, 16, 16), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 0.01f); - } - } - } + var x = Game1.oldMouseState.X + Game1.viewport.X;
+ var y = Game1.oldMouseState.Y + Game1.viewport.Y;
+ spriteBatch.Draw(Game1.mouseCursors, new Vector2(x / Game1.tileSize * Game1.tileSize - Game1.viewport.X, y / Game1.tileSize * Game1.tileSize - Game1.viewport.Y), new Rectangle(Utility.playerCanPlaceItemHere(location, this, x, y, Game1.player) ? 194 : 210, 388, 16, 16), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 0.01f);
+ }
+ }
+ }
}
\ No newline at end of file |