diff options
Diffstat (limited to 'src/StardewModdingAPI/Inheritance/SGame.cs')
| -rw-r--r-- | src/StardewModdingAPI/Inheritance/SGame.cs | 1726 |
1 files changed, 1726 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Inheritance/SGame.cs b/src/StardewModdingAPI/Inheritance/SGame.cs new file mode 100644 index 00000000..9b69434a --- /dev/null +++ b/src/StardewModdingAPI/Inheritance/SGame.cs @@ -0,0 +1,1726 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using StardewModdingAPI.Events;
+using StardewValley;
+using StardewValley.BellsAndWhistles;
+using StardewValley.Locations;
+using StardewValley.Menus;
+using StardewValley.Tools;
+using xTile.Dimensions;
+using Rectangle = Microsoft.Xna.Framework.Rectangle;
+
+namespace StardewModdingAPI.Inheritance
+{
+ /// <summary>
+ /// The 'SGame' class.
+ /// This summary, and many others, only exists because XML doc tags.
+ /// </summary>
+ public class SGame : Game1
+ {
+ /// <summary>
+ /// Useless right now.
+ /// </summary>
+ public const int LowestModItemID = 1000;
+
+ private bool FireLoadedGameEvent;
+
+ /// <summary>
+ /// Gets a jagged array of all buttons pressed on the gamepad the prior frame.
+ /// </summary>
+ public Buttons[][] PreviouslyPressedButtons;
+
+ internal SGame()
+ {
+ Instance = this;
+ FirstUpdate = true;
+ }
+
+ /// <summary>
+ /// Useless at this time.
+ /// </summary>
+ [Obsolete]
+ // ReSharper disable once UnusedAutoPropertyAccessor.Local
+ 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();
+
+ /// <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>
+ /// Indicates if the MenuClosed event was fired to prevent it from re-firing.
+ /// </summary>
+ internal bool WasMenuClosedInvoked = false;
+
+ /// <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 result of Game1.newDay
+ /// </summary>
+ public bool PreviousIsNewDay { 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>
+ /// The current Colour in Game1 (Private field, uses reflection)
+ /// </summary>
+ public Color BgColour
+ {
+ get { return (Color) typeof(Game1).GetBaseFieldValue<object>(Program.gamePtr, "bgColor"); }
+ set { typeof(Game1).SetBaseFieldValue<object>(this, "bgColor", 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; }
+
+ internal static Queue<String> DebugMessageQueue { 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);
+ }
+
+ /// <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);
+ }
+
+ /// <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);
+ }
+
+ /// <summary>
+ /// Gets an array of all Buttons pressed on a joystick
+ /// </summary>
+ /// <param name="index"></param>
+ /// <returns></returns>
+ public Buttons[] GetButtonsDown(PlayerIndex index)
+ {
+ var state = GamePad.GetState(index);
+ var buttons = new List<Buttons>();
+ if (state.IsConnected)
+ {
+ if (state.Buttons.A == ButtonState.Pressed) buttons.Add(Buttons.A);
+ if (state.Buttons.B == ButtonState.Pressed) buttons.Add(Buttons.B);
+ if (state.Buttons.Back == ButtonState.Pressed) buttons.Add(Buttons.Back);
+ if (state.Buttons.BigButton == ButtonState.Pressed) buttons.Add(Buttons.BigButton);
+ if (state.Buttons.LeftShoulder == ButtonState.Pressed) buttons.Add(Buttons.LeftShoulder);
+ if (state.Buttons.LeftStick == ButtonState.Pressed) buttons.Add(Buttons.LeftStick);
+ if (state.Buttons.RightShoulder == ButtonState.Pressed) buttons.Add(Buttons.RightShoulder);
+ if (state.Buttons.RightStick == ButtonState.Pressed) buttons.Add(Buttons.RightStick);
+ if (state.Buttons.Start == ButtonState.Pressed) buttons.Add(Buttons.Start);
+ if (state.Buttons.X == ButtonState.Pressed) buttons.Add(Buttons.X);
+ if (state.Buttons.Y == ButtonState.Pressed) buttons.Add(Buttons.Y);
+ if (state.DPad.Up == ButtonState.Pressed) buttons.Add(Buttons.DPadUp);
+ if (state.DPad.Down == ButtonState.Pressed) buttons.Add(Buttons.DPadDown);
+ if (state.DPad.Left == ButtonState.Pressed) buttons.Add(Buttons.DPadLeft);
+ if (state.DPad.Right == ButtonState.Pressed) buttons.Add(Buttons.DPadRight);
+ if (state.Triggers.Left > 0.2f) buttons.Add(Buttons.LeftTrigger);
+ if (state.Triggers.Right > 0.2f) buttons.Add(Buttons.RightTrigger);
+ }
+ 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)
+ {
+ 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.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);
+ if (WasButtonJustPressed(Buttons.RightShoulder, state.Buttons.RightShoulder, index)) buttons.Add(Buttons.RightShoulder);
+ if (WasButtonJustPressed(Buttons.RightStick, state.Buttons.RightStick, index)) buttons.Add(Buttons.RightStick);
+ if (WasButtonJustPressed(Buttons.Start, state.Buttons.Start, index)) buttons.Add(Buttons.Start);
+ if (WasButtonJustPressed(Buttons.X, state.Buttons.X, index)) buttons.Add(Buttons.X);
+ if (WasButtonJustPressed(Buttons.Y, state.Buttons.Y, index)) buttons.Add(Buttons.Y);
+ if (WasButtonJustPressed(Buttons.DPadUp, state.DPad.Up, index)) buttons.Add(Buttons.DPadUp);
+ if (WasButtonJustPressed(Buttons.DPadDown, state.DPad.Down, index)) buttons.Add(Buttons.DPadDown);
+ if (WasButtonJustPressed(Buttons.DPadLeft, state.DPad.Left, index)) buttons.Add(Buttons.DPadLeft);
+ if (WasButtonJustPressed(Buttons.DPadRight, state.DPad.Right, index)) buttons.Add(Buttons.DPadRight);
+ 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();
+ }
+
+ /// <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)
+ {
+ 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);
+ if (WasButtonJustReleased(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B);
+ if (WasButtonJustReleased(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back);
+ if (WasButtonJustReleased(Buttons.BigButton, state.Buttons.BigButton, index)) buttons.Add(Buttons.BigButton);
+ if (WasButtonJustReleased(Buttons.LeftShoulder, state.Buttons.LeftShoulder, index)) buttons.Add(Buttons.LeftShoulder);
+ if (WasButtonJustReleased(Buttons.LeftStick, state.Buttons.LeftStick, index)) buttons.Add(Buttons.LeftStick);
+ if (WasButtonJustReleased(Buttons.RightShoulder, state.Buttons.RightShoulder, index)) buttons.Add(Buttons.RightShoulder);
+ if (WasButtonJustReleased(Buttons.RightStick, state.Buttons.RightStick, index)) buttons.Add(Buttons.RightStick);
+ if (WasButtonJustReleased(Buttons.Start, state.Buttons.Start, index)) buttons.Add(Buttons.Start);
+ if (WasButtonJustReleased(Buttons.X, state.Buttons.X, index)) buttons.Add(Buttons.X);
+ if (WasButtonJustReleased(Buttons.Y, state.Buttons.Y, index)) buttons.Add(Buttons.Y);
+ if (WasButtonJustReleased(Buttons.DPadUp, state.DPad.Up, index)) buttons.Add(Buttons.DPadUp);
+ if (WasButtonJustReleased(Buttons.DPadDown, state.DPad.Down, index)) buttons.Add(Buttons.DPadDown);
+ if (WasButtonJustReleased(Buttons.DPadLeft, state.DPad.Left, index)) buttons.Add(Buttons.DPadLeft);
+ if (WasButtonJustReleased(Buttons.DPadRight, state.DPad.Right, index)) buttons.Add(Buttons.DPadRight);
+ if (WasButtonJustReleased(Buttons.LeftTrigger, state.Triggers.Left, index)) buttons.Add(Buttons.LeftTrigger);
+ if (WasButtonJustReleased(Buttons.RightTrigger, state.Triggers.Right, index)) buttons.Add(Buttons.RightTrigger);
+ }
+ return buttons.ToArray();
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public static MethodInfo DrawFarmBuildings = typeof(Game1).GetMethod("drawFarmBuildings", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ /// <summary>
+ ///
+ /// </summary>
+ public static MethodInfo DrawHUD = typeof(Game1).GetMethod("drawHUD", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ /// <summary>
+ ///
+ /// </summary>
+ public static MethodInfo DrawDialogueBox = typeof(Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static MethodInfo CheckForEscapeKeys = typeof(Game1).GetMethod("checkForEscapeKeys", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static MethodInfo UpdateControlInput = typeof(Game1).GetMethod("UpdateControlInput", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static MethodInfo UpdateCharacters = typeof(Game1).GetMethod("UpdateCharacters", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static MethodInfo UpdateLocations = typeof(Game1).GetMethod("UpdateLocations", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static MethodInfo getViewportCenter = typeof(Game1).GetMethod("getViewportCenter", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static MethodInfo UpdateTitleScreen = typeof(Game1).GetMethod("UpdateTitleScreen", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public delegate void BaseBaseDraw();
+
+ /// <summary>
+ /// Whether or not the game's zoom level is 1.0f
+ /// </summary>
+ public bool ZoomLevelIsOne => options.zoomLevel.Equals(1.0f);
+
+ /// <summary>
+ /// XNA Init Method
+ /// </summary>
+ protected override void Initialize()
+ {
+ Log.AsyncY("XNA Initialize");
+ //ModItems = new Dictionary<int, SObject>();
+ DebugMessageQueue = new Queue<string>();
+ PreviouslyPressedButtons = new Buttons[4][];
+ 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.AsyncY("XNA LoadContent");
+ base.LoadContent();
+ GameEvents.InvokeLoadContent();
+ }
+
+ /// <summary>
+ /// XNA Update Method
+ /// </summary>
+ /// <param name="gameTime"></param>
+ protected override void Update(GameTime gameTime)
+ {
+ QueueDebugMessage("FPS: " + FramesPerSecond);
+ UpdateEventCalls();
+
+ /*
+ if (ZoomLevelIsOne)
+ {
+ options.zoomLevel = 0.99f;
+ InvokeBasePrivateInstancedMethod("Window_ClientSizeChanged", null, null);
+ }
+ */
+
+ if (FramePressedKeys.Contains(Keys.F3))
+ {
+ Debug = !Debug;
+ }
+
+ if (FramePressedKeys.Contains(Keys.F2))
+ {
+ //Built-in debug mode
+ debugMode = !debugMode;
+ }
+
+ if (Constants.EnableCompletelyOverridingBaseCalls)
+ {
+ #region Overridden Update Call
+
+ try
+ {
+ if (Program.BuildType == 0)
+ SteamHelper.update();
+ if ((paused /*|| !this.IsActive*/) && (options == null || options.pauseWhenOutOfFocus || paused))
+ return;
+ if (quit)
+ Exit();
+ currentGameTime = gameTime;
+ if (gameMode != 11)
+ {
+ if (IsMultiplayer && gameMode == 3)
+ {
+ if (multiplayerMode == 2)
+ server.receiveMessages();
+ else
+ client.receiveMessages();
+ }
+ if (IsActive)
+ InvokeMethodInfo(CheckForEscapeKeys);
+ //InvokeBasePrivateInstancedMethod("checkForEscapeKeys");
+
+ //this.checkForEscapeKeys();
+ updateMusic();
+ updateRaindropPosition();
+ bloom?.tick(gameTime);
+ if (globalFade)
+ {
+ if (!dialogueUp)
+ {
+ if (fadeIn)
+ {
+ fadeToBlackAlpha = Math.Max(0.0f, fadeToBlackAlpha - globalFadeSpeed);
+ if (fadeToBlackAlpha <= 0.0)
+ {
+ globalFade = false;
+ if (afterFade != null)
+ {
+ afterFadeFunction afterFadeFunction = afterFade;
+ afterFade();
+ if (afterFade != null && afterFade.Equals(afterFadeFunction))
+ afterFade = null;
+ if (nonWarpFade)
+ fadeToBlack = false;
+ }
+ }
+ }
+ else
+ {
+ fadeToBlackAlpha = Math.Min(1f, fadeToBlackAlpha + globalFadeSpeed);
+ if (fadeToBlackAlpha >= 1.0)
+ {
+ globalFade = false;
+ if (afterFade != null)
+ {
+ afterFadeFunction afterFadeFunction = afterFade;
+ afterFade();
+ if (afterFade != null && afterFade.Equals(afterFadeFunction))
+ afterFade = null;
+ if (nonWarpFade)
+ fadeToBlack = false;
+ }
+ }
+ }
+ }
+ else
+ InvokeMethodInfo(UpdateControlInput, gameTime);
+ //InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime);
+ //this.UpdateControlInput(gameTime);
+ }
+ else if (pauseThenDoFunctionTimer > 0)
+ {
+ freezeControls = true;
+ pauseThenDoFunctionTimer -= gameTime.ElapsedGameTime.Milliseconds;
+ if (pauseThenDoFunctionTimer <= 0)
+ {
+ freezeControls = false;
+ afterPause?.Invoke();
+ }
+ }
+ if (gameMode == 3 || gameMode == 2)
+ {
+ player.millisecondsPlayed += (uint) gameTime.ElapsedGameTime.Milliseconds;
+ bool flag = true;
+ if (currentMinigame != null)
+ {
+ if (pauseTime > 0.0)
+ updatePause(gameTime);
+ if (fadeToBlack)
+ {
+ updateScreenFade(gameTime);
+ if (fadeToBlackAlpha >= 1.0)
+ fadeToBlack = false;
+ }
+ else
+ {
+ if (thumbstickMotionMargin > 0)
+ thumbstickMotionMargin -= gameTime.ElapsedGameTime.Milliseconds;
+ if (IsActive)
+ {
+ KeyboardState state1 = Keyboard.GetState();
+ MouseState state2 = Mouse.GetState();
+ GamePadState state3 = GamePad.GetState(PlayerIndex.One);
+ foreach (Keys keys in state1.GetPressedKeys())
+ {
+ if (!oldKBState.IsKeyDown(keys))
+ currentMinigame.receiveKeyPress(keys);
+ }
+ if (options.gamepadControls)
+ {
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ foreach (Buttons b in Utility.getPressedButtons(state3, oldPadState))
+ currentMinigame.receiveKeyPress(Utility.mapGamePadButtonToKey(b));
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ if (state3.ThumbSticks.Right.Y < -0.200000002980232 && oldPadState.ThumbSticks.Right.Y >= -0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Down);
+ if (state3.ThumbSticks.Right.Y > 0.200000002980232 && oldPadState.ThumbSticks.Right.Y <= 0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Up);
+ if (state3.ThumbSticks.Right.X < -0.200000002980232 && oldPadState.ThumbSticks.Right.X >= -0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Left);
+ if (state3.ThumbSticks.Right.X > 0.200000002980232 && oldPadState.ThumbSticks.Right.X <= 0.200000002980232)
+ currentMinigame.receiveKeyPress(Keys.Right);
+ if (oldPadState.ThumbSticks.Right.Y < -0.200000002980232 && state3.ThumbSticks.Right.Y >= -0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Down);
+ if (oldPadState.ThumbSticks.Right.Y > 0.200000002980232 && state3.ThumbSticks.Right.Y <= 0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Up);
+ if (oldPadState.ThumbSticks.Right.X < -0.200000002980232 && state3.ThumbSticks.Right.X >= -0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Left);
+ if (oldPadState.ThumbSticks.Right.X > 0.200000002980232 && state3.ThumbSticks.Right.X <= 0.200000002980232)
+ currentMinigame.receiveKeyRelease(Keys.Right);
+ if (isGamePadThumbstickInMotion())
+ {
+ setMousePosition(getMouseX() + (int) (state3.ThumbSticks.Left.X * 16.0), getMouseY() - (int) (state3.ThumbSticks.Left.Y * 16.0));
+ lastCursorMotionWasMouse = false;
+ }
+ else if (getMousePosition().X != getOldMouseX() || getMousePosition().Y != getOldMouseY())
+ lastCursorMotionWasMouse = true;
+ }
+ foreach (Keys keys in oldKBState.GetPressedKeys())
+ {
+ if (!state1.IsKeyDown(keys))
+ currentMinigame.receiveKeyRelease(keys);
+ }
+ if (options.gamepadControls)
+ {
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ if (state3.IsConnected && state3.IsButtonDown(Buttons.X) && !oldPadState.IsButtonDown(Buttons.X))
+ currentMinigame.receiveRightClick(getMouseX(), getMouseY(), true);
+ else if (state3.IsConnected && state3.IsButtonDown(Buttons.A) && !oldPadState.IsButtonDown(Buttons.A))
+ currentMinigame.receiveLeftClick(getMouseX(), getMouseY(), true);
+ else if (state3.IsConnected && !state3.IsButtonDown(Buttons.X) && oldPadState.IsButtonDown(Buttons.X))
+ currentMinigame.releaseRightClick(getMouseX(), getMouseY());
+ else if (state3.IsConnected && !state3.IsButtonDown(Buttons.A) && oldPadState.IsButtonDown(Buttons.A))
+ currentMinigame.releaseLeftClick(getMouseX(), getMouseY());
+ foreach (Buttons b in Utility.getPressedButtons(oldPadState, state3))
+ currentMinigame.receiveKeyRelease(Utility.mapGamePadButtonToKey(b));
+ if (state3.IsConnected && state3.IsButtonDown(Buttons.A))
+ currentMinigame?.leftClickHeld(0, 0);
+ }
+ if (currentMinigame == null)
+ {
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ return;
+ }
+ if (state2.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed)
+ currentMinigame.receiveLeftClick(getMouseX(), getMouseY(), true);
+ if (state2.RightButton == ButtonState.Pressed && oldMouseState.RightButton != ButtonState.Pressed)
+ currentMinigame.receiveRightClick(getMouseX(), getMouseY(), true);
+ if (state2.LeftButton == ButtonState.Released && oldMouseState.LeftButton == ButtonState.Pressed)
+ currentMinigame.releaseLeftClick(getMouseX(), getMouseY());
+ if (state2.RightButton == ButtonState.Released && oldMouseState.RightButton == ButtonState.Pressed)
+ currentMinigame.releaseLeftClick(getMouseX(), getMouseY());
+ if (state2.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Pressed)
+ currentMinigame.leftClickHeld(getMouseX(), getMouseY());
+ oldMouseState = state2;
+ oldKBState = state1;
+ oldPadState = state3;
+ }
+ if (currentMinigame != null && currentMinigame.tick(gameTime))
+ {
+ currentMinigame.unload();
+ currentMinigame = null;
+ fadeIn = true;
+ fadeToBlackAlpha = 1f;
+ return;
+ }
+ }
+ flag = IsMultiplayer;
+ }
+ else if (farmEvent != null && farmEvent.tickUpdate(gameTime))
+ {
+ farmEvent.makeChangesToLocation();
+ timeOfDay = 600;
+ UpdateOther(gameTime);
+ displayHUD = true;
+ farmEvent = null;
+ currentLocation = getLocationFromName("FarmHouse");
+ player.position = Utility.PointToVector2(Utility.getHomeOfFarmer(player).getBedSpot()) * tileSize;
+ player.position.X -= tileSize;
+ changeMusicTrack("none");
+ currentLocation.resetForPlayerEntry();
+ player.forceCanMove();
+ freezeControls = false;
+ displayFarmer = true;
+ outdoorLight = Color.White;
+ viewportFreeze = false;
+ fadeToBlackAlpha = 0.0f;
+ fadeToBlack = false;
+ globalFadeToClear(null, 0.02f);
+ player.mailForTomorrow.Clear();
+ showEndOfNightStuff();
+ }
+ if (flag)
+ {
+ if (endOfNightMenus.Count() > 0 && activeClickableMenu == null)
+ activeClickableMenu = endOfNightMenus.Pop();
+ if (activeClickableMenu != null)
+ {
+ updateActiveMenu(gameTime);
+ }
+ else
+ {
+ if (pauseTime > 0.0)
+ updatePause(gameTime);
+ if (!globalFade && !freezeControls && (activeClickableMenu == null && IsActive))
+ InvokeMethodInfo(UpdateControlInput, gameTime);
+ //InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime);
+ //this.UpdateControlInput(gameTime);
+ }
+ if (showingEndOfNightStuff && endOfNightMenus.Count() == 0 && activeClickableMenu == null)
+ {
+ showingEndOfNightStuff = false;
+ globalFadeToClear(playMorningSong, 0.02f);
+ }
+ if (!showingEndOfNightStuff)
+ {
+ if (IsMultiplayer || activeClickableMenu == null && currentMinigame == null)
+ UpdateGameClock(gameTime);
+ //this.UpdateCharacters(gameTime);
+ //this.UpdateLocations(gameTime);
+ //InvokeBasePrivateInstancedMethod("UpdateCharacters", gameTime);
+ //InvokeBasePrivateInstancedMethod("UpdateLocations", gameTime);
+ //UpdateViewPort(false, (Point)InvokeBasePrivateInstancedMethod("getViewportCenter"));
+
+ InvokeMethodInfo(UpdateCharacters, gameTime);
+ InvokeMethodInfo(UpdateLocations, gameTime);
+ UpdateViewPort(false, (Point) InvokeMethodInfo(getViewportCenter));
+ }
+ UpdateOther(gameTime);
+ if (messagePause)
+ {
+ KeyboardState state1 = Keyboard.GetState();
+ MouseState state2 = Mouse.GetState();
+ GamePadState state3 = GamePad.GetState(PlayerInd |
