2016-03-05 03:10:39 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Reflection ;
2016-03-29 11:23:09 +08:00
using System.Runtime.CompilerServices ;
2016-03-05 03:10:39 +08:00
using Microsoft.Xna.Framework ;
using Microsoft.Xna.Framework.Graphics ;
using Microsoft.Xna.Framework.Input ;
2016-03-23 08:36:04 +08:00
using StardewModdingAPI.Events ;
2016-03-05 03:10:39 +08:00
using StardewValley ;
2016-03-27 15:52:43 +08:00
using StardewValley.BellsAndWhistles ;
using StardewValley.Locations ;
2016-03-05 03:10:39 +08:00
using StardewValley.Menus ;
2016-03-27 15:52:43 +08:00
using StardewValley.Tools ;
using xTile.Dimensions ;
using Rectangle = Microsoft . Xna . Framework . Rectangle ;
2016-03-05 03:10:39 +08:00
namespace StardewModdingAPI.Inheritance
{
2016-03-27 13:09:09 +08:00
/// <summary>
/// The 'SGame' class.
/// This summary, and many others, only exists because XML doc tags.
/// </summary>
2016-03-05 03:10:39 +08:00
public class SGame : Game1
{
2016-03-27 13:09:09 +08:00
/// <summary>
/// Useless right now.
/// </summary>
public const int LowestModItemID = 1000 ;
2016-03-05 03:10:39 +08:00
2016-03-27 13:09:09 +08:00
private bool FireLoadedGameEvent ;
/// <summary>
/// Gets a jagged array of all buttons pressed on the gamepad the prior frame.
/// </summary>
public Buttons [ ] [ ] PreviouslyPressedButtons ;
2016-03-05 03:10:39 +08:00
2016-03-27 13:09:09 +08:00
internal SGame ( )
2016-03-05 03:10:39 +08:00
{
2016-03-27 13:09:09 +08:00
Instance = this ;
FirstUpdate = true ;
2016-03-05 03:10:39 +08:00
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// Useless at this time.
/// </summary>
[Obsolete]
2016-03-27 15:52:43 +08:00
// ReSharper disable once UnusedAutoPropertyAccessor.Local
2016-03-27 13:09:09 +08:00
public static Dictionary < int , SObject > ModItems { get ; private set ; }
/// <summary>
/// The current KeyboardState
/// </summary>
2016-03-05 03:10:39 +08:00
public KeyboardState KStateNow { get ; private set ; }
2016-03-27 13:09:09 +08:00
/// <summary>
/// The prior KeyboardState
/// </summary>
2016-03-05 03:10:39 +08:00
public KeyboardState KStatePrior { get ; private set ; }
2016-03-27 13:09:09 +08:00
/// <summary>
/// The current MouseState
/// </summary>
2016-03-05 03:10:39 +08:00
public MouseState MStateNow { get ; private set ; }
2016-03-27 13:09:09 +08:00
/// <summary>
/// The prior MouseState
/// </summary>
2016-03-05 03:10:39 +08:00
public MouseState MStatePrior { get ; private set ; }
2016-03-27 13:09:09 +08:00
/// <summary>
/// All keys pressed on the current frame
/// </summary>
2016-03-23 13:11:13 +08:00
public Keys [ ] CurrentlyPressedKeys = > KStateNow . GetPressedKeys ( ) ;
2016-03-27 13:09:09 +08:00
/// <summary>
/// All keys pressed on the prior frame
/// </summary>
2016-03-23 13:11:13 +08:00
public Keys [ ] PreviouslyPressedKeys = > KStatePrior . GetPressedKeys ( ) ;
2016-03-05 03:10:39 +08:00
2016-03-27 13:09:09 +08:00
/// <summary>
/// All keys pressed on this frame except for the ones pressed on the prior frame
/// </summary>
2016-03-27 09:50:47 +08:00
public Keys [ ] FramePressedKeys = > CurrentlyPressedKeys . Except ( PreviouslyPressedKeys ) . ToArray ( ) ;
2016-03-27 13:09:09 +08:00
/// <summary>
/// All keys pressed on the prior frame except for the ones pressed on the current frame
/// </summary>
2016-03-27 09:50:47 +08:00
public Keys [ ] FrameReleasedKeys = > PreviouslyPressedKeys . Except ( CurrentlyPressedKeys ) . ToArray ( ) ;
2016-03-27 13:09:09 +08:00
/// <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 ; }
2016-03-07 21:49:45 +08:00
2016-03-27 13:09:09 +08:00
/// <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 ; }
2016-03-28 16:13:40 +08:00
/// <summary>
/// Indicates if the MenuClosed event was fired to prevent it from re-firing.
/// </summary>
internal bool WasMenuClosedInvoked = false ;
2016-03-27 13:09:09 +08:00
/// <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 ; }
2016-03-27 15:52:43 +08:00
/// <summary>
/// The previous result of Game1.newDay
/// </summary>
public bool PreviousIsNewDay { get ; private set ; }
2016-03-27 13:09:09 +08:00
/// <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 ) ; }
}
2016-03-27 18:40:09 +08:00
/// <summary>
///
/// </summary>
public int ThumbstickMotionMargin
{
get { return ( int ) typeof ( Game1 ) . GetBaseFieldValue < object > ( Program . gamePtr , "thumbstickMotionMargin" ) ; }
set { typeof ( Game1 ) . SetBaseFieldValue < object > ( this , "thumbstickMotionMargin" , value ) ; }
}
2016-03-27 15:52:43 +08:00
/// <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 ) ; }
}
2016-03-27 13:09:09 +08:00
/// <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 ; }
2016-03-27 15:52:43 +08:00
internal static Queue < String > DebugMessageQueue { get ; private set ; }
2016-03-27 13:32:15 +08:00
2016-03-27 13:09:09 +08:00
/// <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>
2016-03-07 21:49:45 +08:00
private bool WasButtonJustPressed ( Buttons button , ButtonState buttonState , PlayerIndex stateIndex )
{
2016-03-27 13:09:09 +08:00
return buttonState = = ButtonState . Pressed & & ! PreviouslyPressedButtons [ ( int ) stateIndex ] . Contains ( button ) ;
2016-03-07 21:49:45 +08:00
}
2016-03-08 01:25:51 +08:00
2016-03-27 13:09:09 +08:00
/// <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>
2016-03-08 01:25:51 +08:00
private bool WasButtonJustReleased ( Buttons button , ButtonState buttonState , PlayerIndex stateIndex )
{
2016-03-27 13:09:09 +08:00
return buttonState = = ButtonState . Released & & PreviouslyPressedButtons [ ( int ) stateIndex ] . Contains ( button ) ;
2016-03-08 01:25:51 +08:00
}
2016-03-27 13:09:09 +08:00
/// <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>
2016-03-08 01:25:51 +08:00
private bool WasButtonJustPressed ( Buttons button , float value , PlayerIndex stateIndex )
{
return WasButtonJustPressed ( button , value > 0.2f ? ButtonState . Pressed : ButtonState . Released , stateIndex ) ;
}
2016-03-27 13:09:09 +08:00
/// <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>
2016-03-08 01:25:51 +08:00
private bool WasButtonJustReleased ( Buttons button , float value , PlayerIndex stateIndex )
{
return WasButtonJustReleased ( button , value > 0.2f ? ButtonState . Pressed : ButtonState . Released , stateIndex ) ;
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// Gets an array of all Buttons pressed on a joystick
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
2016-03-08 01:25:51 +08:00
public Buttons [ ] GetButtonsDown ( PlayerIndex index )
{
2016-03-27 13:09:09 +08:00
var state = GamePad . GetState ( index ) ;
var buttons = new List < Buttons > ( ) ;
2016-03-08 01:25:51 +08:00
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 ( ) ;
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// Gets all buttons that were pressed on the current frame of a joystick
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
2016-03-07 21:49:45 +08:00
public Buttons [ ] GetFramePressedButtons ( PlayerIndex index )
2016-03-27 13:09:09 +08:00
{
var state = GamePad . GetState ( index ) ;
var buttons = new List < Buttons > ( ) ;
2016-03-07 21:49:45 +08:00
if ( state . IsConnected )
{
2016-03-27 13:09:09 +08:00
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 ) ;
2016-03-07 21:49:45 +08:00
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 ) ;
2016-03-08 01:25:51 +08:00
if ( WasButtonJustPressed ( Buttons . LeftTrigger , state . Triggers . Left , index ) ) buttons . Add ( Buttons . LeftTrigger ) ;
if ( WasButtonJustPressed ( Buttons . RightTrigger , state . Triggers . Right , index ) ) buttons . Add ( Buttons . RightTrigger ) ;
2016-03-07 21:49:45 +08:00
}
2016-03-27 13:09:09 +08:00
return buttons . ToArray ( ) ;
2016-03-07 21:49:45 +08:00
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// Gets all buttons that were released on the current frame of a joystick
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
2016-03-08 01:25:51 +08:00
public Buttons [ ] GetFrameReleasedButtons ( PlayerIndex index )
{
2016-03-27 13:09:09 +08:00
var state = GamePad . GetState ( index ) ;
var buttons = new List < Buttons > ( ) ;
2016-03-08 01:25:51 +08:00
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 ( ) ;
}
2016-03-29 10:57:05 +08:00
/// <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 ) ;
2016-03-29 11:23:09 +08:00
public delegate void BaseBaseDraw ( ) ;
2016-03-29 10:57:05 +08:00
2016-03-27 15:52:43 +08:00
/// <summary>
/// Whether or not the game's zoom level is 1.0f
/// </summary>
public bool ZoomLevelIsOne = > options . zoomLevel . Equals ( 1.0f ) ;
2016-03-27 13:09:09 +08:00
/// <summary>
/// XNA Init Method
/// </summary>
2016-03-05 03:10:39 +08:00
protected override void Initialize ( )
{
2016-03-27 13:09:09 +08:00
Log . AsyncY ( "XNA Initialize" ) ;
//ModItems = new Dictionary<int, SObject>();
2016-03-27 13:32:15 +08:00
DebugMessageQueue = new Queue < string > ( ) ;
2016-03-08 01:25:51 +08:00
PreviouslyPressedButtons = new Buttons [ 4 ] [ ] ;
2016-03-27 13:09:09 +08:00
for ( var i = 0 ; i < 4 ; + + i ) PreviouslyPressedButtons [ i ] = new Buttons [ 0 ] ;
2016-03-08 01:25:51 +08:00
2016-03-05 03:10:39 +08:00
base . Initialize ( ) ;
2016-03-23 08:36:04 +08:00
GameEvents . InvokeInitialize ( ) ;
2016-03-05 03:10:39 +08:00
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// XNA LC Method
/// </summary>
2016-03-05 03:10:39 +08:00
protected override void LoadContent ( )
{
2016-03-27 13:09:09 +08:00
Log . AsyncY ( "XNA LoadContent" ) ;
2016-03-05 03:10:39 +08:00
base . LoadContent ( ) ;
2016-03-23 08:36:04 +08:00
GameEvents . InvokeLoadContent ( ) ;
2016-03-05 03:10:39 +08:00
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// XNA Update Method
/// </summary>
/// <param name="gameTime"></param>
2016-03-05 03:10:39 +08:00
protected override void Update ( GameTime gameTime )
{
2016-03-27 18:40:09 +08:00
QueueDebugMessage ( "FPS: " + FramesPerSecond ) ;
2016-03-05 03:10:39 +08:00
UpdateEventCalls ( ) ;
2016-03-29 11:23:09 +08:00
if ( ZoomLevelIsOne )
2016-03-27 18:47:13 +08:00
{
2016-03-27 18:40:09 +08:00
options . zoomLevel = 0.99f ;
2016-03-27 18:47:13 +08:00
InvokeBasePrivateInstancedMethod ( "Window_ClientSizeChanged" , null , null ) ;
2016-03-29 11:23:09 +08:00
}
2016-03-27 18:40:09 +08:00
2016-03-23 13:11:13 +08:00
if ( FramePressedKeys . Contains ( Keys . F3 ) )
{
Debug = ! Debug ;
}
2016-03-27 18:40:09 +08:00
if ( FramePressedKeys . Contains ( Keys . F2 ) )
2016-03-04 02:50:22 +08:00
{
2016-03-27 18:40:09 +08:00
//Built-in debug mode
debugMode = ! debugMode ;
2016-03-05 03:10:39 +08:00
}
2016-03-27 18:40:09 +08:00
if ( Constants . EnableCompletelyOverridingBaseCalls )
2016-03-04 02:50:22 +08:00
{
2016-03-27 18:40:09 +08:00
#region Overridden Update Call
2016-03-29 11:23:09 +08:00
try
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
if ( Program . BuildType = = 0 )
SteamHelper . update ( ) ;
if ( ( paused /*|| !this.IsActive*/ ) & & ( options = = null | | options . pauseWhenOutOfFocus | | paused ) )
return ;
if ( quit )
Exit ( ) ;
currentGameTime = gameTime ;
if ( gameMode ! = 11 )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
if ( IsMultiplayer & & gameMode = = 3 )
{
if ( multiplayerMode = = 2 )
server . receiveMessages ( ) ;
else
client . receiveMessages ( ) ;
}
if ( IsActive )
InvokeMethodInfo ( CheckForEscapeKeys ) ;
2016-03-29 10:57:05 +08:00
//InvokeBasePrivateInstancedMethod("checkForEscapeKeys");
2016-03-29 11:23:09 +08:00
2016-03-27 18:40:09 +08:00
//this.checkForEscapeKeys();
2016-03-29 11:23:09 +08:00
updateMusic ( ) ;
updateRaindropPosition ( ) ;
if ( bloom ! = null )
bloom . tick ( gameTime ) ;
if ( globalFade )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
if ( ! dialogueUp )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
if ( fadeIn )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
fadeToBlackAlpha = Math . Max ( 0.0f , fadeToBlackAlpha - globalFadeSpeed ) ;
if ( fadeToBlackAlpha < = 0.0 )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
globalFade = false ;
if ( afterFade ! = null )
{
afterFadeFunction afterFadeFunction = afterFade ;
afterFade ( ) ;
if ( afterFade ! = null & & afterFade . Equals ( afterFadeFunction ) )
afterFade = null ;
if ( nonWarpFade )
fadeToBlack = false ;
}
2016-03-27 18:40:09 +08:00
}
}
2016-03-29 11:23:09 +08:00
else
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
fadeToBlackAlpha = Math . Min ( 1f , fadeToBlackAlpha + globalFadeSpeed ) ;
if ( fadeToBlackAlpha > = 1.0 )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
globalFade = false ;
if ( afterFade ! = null )
{
afterFadeFunction afterFadeFunction = afterFade ;
afterFade ( ) ;
if ( afterFade ! = null & & afterFade . Equals ( afterFadeFunction ) )
afterFade = null ;
if ( nonWarpFade )
fadeToBlack = false ;
}
2016-03-27 18:40:09 +08:00
}
}
}
2016-03-29 11:23:09 +08:00
else
InvokeMethodInfo ( UpdateControlInput , gameTime ) ;
//InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime);
//this.UpdateControlInput(gameTime);
2016-03-27 18:40:09 +08:00
}
2016-03-29 11:23:09 +08:00
else if ( pauseThenDoFunctionTimer > 0 )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
freezeControls = true ;
pauseThenDoFunctionTimer - = gameTime . ElapsedGameTime . Milliseconds ;
if ( pauseThenDoFunctionTimer < = 0 )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
freezeControls = false ;
if ( afterPause ! = null )
afterPause ( ) ;
2016-03-27 18:40:09 +08:00
}
2016-03-29 11:23:09 +08:00
}
if ( gameMode = = 3 | | gameMode = = 2 )
{
player . millisecondsPlayed + = ( uint ) gameTime . ElapsedGameTime . Milliseconds ;
bool flag = true ;
if ( currentMinigame ! = null )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
if ( pauseTime > 0.0 )
updatePause ( gameTime ) ;
if ( fadeToBlack )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
updateScreenFade ( gameTime ) ;
if ( fadeToBlackAlpha > = 1.0 )
fadeToBlack = false ;
}
else
{
if ( ThumbstickMotionMargin > 0 )
ThumbstickMotionMargin - = gameTime . ElapsedGameTime . Milliseconds ;
if ( IsActive )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
KeyboardState state1 = Keyboard . GetState ( ) ;
MouseState state2 = Mouse . GetState ( ) ;
GamePadState state3 = GamePad . GetState ( PlayerIndex . One ) ;
foreach ( Keys keys in state1 . GetPressedKeys ( ) )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
if ( ! oldKBState . IsKeyDown ( keys ) )
currentMinigame . receiveKeyPress ( keys ) ;
2016-03-27 18:40:09 +08:00
}
2016-03-29 11:23:09 +08:00
if ( options . gamepadControls )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
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 ;
2016-03-27 18:40:09 +08:00
}
2016-03-29 11:23:09 +08:00
foreach ( Keys keys in oldKBState . GetPressedKeys ( ) )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
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 ! = null )
currentMinigame . leftClickHeld ( 0 , 0 ) ;
2016-03-27 18:40:09 +08:00
}
if ( currentMinigame = = null )
{
oldMouseState = state2 ;
oldKBState = state1 ;
oldPadState = state3 ;
return ;
}
2016-03-29 11:23:09 +08:00
if ( state2 . LeftButton = = ButtonState . Pressed & & oldMouseState . LeftButton ! = ButtonState . Pressed )
2016-03-27 18:40:09 +08:00
currentMinigame . receiveLeftClick ( getMouseX ( ) , getMouseY ( ) , true ) ;
2016-03-29 11:23:09 +08:00
if ( state2 . RightButton = = ButtonState . Pressed & & oldMouseState . RightButton ! = ButtonState . Pressed )
currentMinigame . receiveRightClick ( getMouseX ( ) , getMouseY ( ) , true ) ;
if ( state2 . LeftButton = = ButtonState . Released & & oldMouseState . LeftButton = = ButtonState . Pressed )
2016-03-27 18:40:09 +08:00
currentMinigame . releaseLeftClick ( getMouseX ( ) , getMouseY ( ) ) ;
2016-03-29 11:23:09 +08:00
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 ( ) ) ;
2016-03-27 18:40:09 +08:00
oldMouseState = state2 ;
oldKBState = state1 ;
oldPadState = state3 ;
2016-03-29 11:23:09 +08:00
}
if ( currentMinigame ! = null & & currentMinigame . tick ( gameTime ) )
{
currentMinigame . unload ( ) ;
currentMinigame = null ;
fadeIn = true ;
fadeToBlackAlpha = 1f ;
2016-03-27 18:40:09 +08:00
return ;
}
}
2016-03-29 11:23:09 +08:00
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 )
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
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 ( PlayerIndex . One ) ;
if ( isOneOfTheseKeysDown ( state1 , options . actionButton ) & & ! isOneOfTheseKeysDown ( oldKBState , options . actionButton ) )
pressActionButton ( state1 , state2 , state3 ) ;
oldKBState = state1 ;
oldPadState = state3 ;
2016-03-27 18:40:09 +08:00
}
}
}
2016-03-29 11:23:09 +08:00
else
2016-03-27 18:40:09 +08:00
{
2016-03-29 11:23:09 +08:00
//InvokeBasePrivateInstancedMethod("UpdateTitleScreen", gameTime);
InvokeMethodInfo ( UpdateTitleScreen , gameTime ) ;
//this.UpdateTitleScreen(gameTime);
2016-03-27 18:40:09 +08:00
if ( activeClickableMenu ! = null )
updateActiveMenu ( gameTime ) ;
2016-03-29 11:23:09 +08:00
if ( gameMode = = 10 )
UpdateOther ( gameTime ) ;
2016-03-27 18:40:09 +08:00
}
2016-03-29 11:23:09 +08:00
if ( audioEngine ! = null )
audioEngine . Update ( ) ;
if ( multiplayerMode = = 2 & & gameMode = = 3 )
server . sendMessages ( gameTime ) ;
2016-03-27 18:40:09 +08:00
}
2016-03-29 11:23:09 +08:00
}
catch ( Exception ex )
{
Log . Error ( "An error occurred in the overridden update loop: " + ex ) ;
2016-03-27 18:40:09 +08:00
}
//typeof (Game).GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(this, new object[] {gameTime});
//base.Update(gameTime);
#endregion
}
else
{
try
{
base . Update ( gameTime ) ;
}
catch ( Exception ex )
{
Log . AsyncR ( "An error occured in the base update loop: " + ex ) ;
Console . ReadKey ( ) ;
}
2016-03-05 03:10:39 +08:00
}
2016-03-23 08:36:04 +08:00
GameEvents . InvokeUpdateTick ( ) ;
2016-03-21 13:57:42 +08:00
if ( FirstUpdate )
{
GameEvents . InvokeFirstUpdateTick ( ) ;
FirstUpdate = false ;
}
2016-03-05 03:10:39 +08:00
2016-03-21 08:52:26 +08:00
if ( CurrentUpdateTick % 2 = = 0 )
2016-03-23 08:36:04 +08:00
GameEvents . InvokeSecondUpdateTick ( ) ;
2016-03-21 08:52:26 +08:00
if ( CurrentUpdateTick % 4 = = 0 )
2016-03-23 08:36:04 +08:00
GameEvents . InvokeFourthUpdateTick ( ) ;
2016-03-21 08:52:26 +08:00
if ( CurrentUpdateTick % 8 = = 0 )
2016-03-23 08:36:04 +08:00
GameEvents . InvokeEighthUpdateTick ( ) ;
2016-03-21 08:52:26 +08:00
if ( CurrentUpdateTick % 15 = = 0 )
2016-03-23 08:36:04 +08:00
GameEvents . InvokeQuarterSecondTick ( ) ;
2016-03-21 08:52:26 +08:00
if ( CurrentUpdateTick % 30 = = 0 )
2016-03-23 08:36:04 +08:00
GameEvents . InvokeHalfSecondTick ( ) ;
2016-03-21 08:52:26 +08:00
if ( CurrentUpdateTick % 60 = = 0 )
2016-03-23 08:36:04 +08:00
GameEvents . InvokeOneSecondTick ( ) ;
2016-03-21 08:52:26 +08:00
CurrentUpdateTick + = 1 ;
if ( CurrentUpdateTick > = 60 )
CurrentUpdateTick = 0 ;
2016-03-23 13:11:13 +08:00
if ( KStatePrior ! = KStateNow )
KStatePrior = KStateNow ;
2016-03-27 13:09:09 +08:00
for ( var i = PlayerIndex . One ; i < = PlayerIndex . Four ; i + + )
2016-03-08 01:25:51 +08:00
{
2016-03-27 13:09:09 +08:00
PreviouslyPressedButtons [ ( int ) i ] = GetButtonsDown ( i ) ;
2016-03-08 01:25:51 +08:00
}
2016-03-05 03:10:39 +08:00
}
2016-03-27 13:09:09 +08:00
/// <summary>
/// XNA Draw Method
/// </summary>
/// <param name="gameTime"></param>
2016-03-05 03:10:39 +08:00
protected override void Draw ( GameTime gameTime )
{
2016-03-27 13:09:09 +08:00
FramesPerSecond = 1 / ( float ) gameTime . ElapsedGameTime . TotalSeconds ;
2016-03-23 13:11:13 +08:00
2016-03-27 18:40:09 +08:00
if ( Constants . EnableCompletelyOverridingBaseCalls )
2016-03-23 13:11:13 +08:00
{
2016-03-27 16:30:17 +08:00
#region Overridden Draw
2016-03-29 11:23:09 +08:00
try
2016-03-27 09:50:47 +08:00
{
2016-03-27 15:52:43 +08:00
if ( ! ZoomLevelIsOne )
2016-03-27 09:50:47 +08:00
{
2016-03-29 11:23:09 +08:00
GraphicsDevice . SetRenderTarget ( Screen ) ;
2016-03-27 09:50:47 +08:00
}
2016-03-29 11:23:09 +08:00
GraphicsDevice . Clear ( BgColour ) ;
if ( options . showMenuBackground & & activeClickableMenu ! = null & & activeClickableMenu . showWithoutTransparencyIfOptionIsSet ( ) )
2016-03-27 15:52:43 +08:00
{
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
2016-03-29 11:23:09 +08:00
activeClickableMenu . drawBackground ( spriteBatch ) ;
activeClickableMenu . draw ( spriteBatch ) ;
2016-03-27 15:52:43 +08:00
spriteBatch . End ( ) ;
2016-03-29 11:23:09 +08:00
if ( ! ZoomLevelIsOne )
{
GraphicsDevice . SetRenderTarget ( null ) ;
GraphicsDevice . Clear ( BgColour ) ;
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . AlphaBlend , SamplerState . LinearClamp , DepthStencilState . Default , RasterizerState . CullNone ) ;
spriteBatch . Draw ( Screen , Vector2 . Zero , Screen . Bounds , Color . White , 0f , Vector2 . Zero , options . zoomLevel , SpriteEffects . None , 1f ) ;
spriteBatch . End ( ) ;
}
return ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( gameMode = = 11 )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
spriteBatch . DrawString ( smoothFont , "Stardew Valley has crashed..." , new Vector2 ( 16f , 16f ) , Color . HotPink ) ;
spriteBatch . DrawString ( smoothFont , "Please send the error report or a screenshot of this message to @ConcernedApe. (http://stardewvalley.net/contact/)" , new Vector2 ( 16f , 32f ) , new Color ( 0 , 255 , 0 ) ) ;
spriteBatch . DrawString ( smoothFont , parseText ( errorMessage , smoothFont , graphics . GraphicsDevice . Viewport . Width ) , new Vector2 ( 16f , 48f ) , Color . White ) ;
2016-03-27 15:52:43 +08:00
spriteBatch . End ( ) ;
2016-03-29 11:23:09 +08:00
return ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( currentMinigame ! = null )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
currentMinigame . draw ( spriteBatch ) ;
if ( globalFade & & ! menuUp & & ( ! nameSelectUp | | messagePause ) )
{
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
spriteBatch . Draw ( fadeToBlackRect , graphics . GraphicsDevice . Viewport . Bounds , Color . Black * ( ( gameMode = = 0 ) ? ( 1f - fadeToBlackAlpha ) : fadeToBlackAlpha ) ) ;
spriteBatch . End ( ) ;
}
if ( ! ZoomLevelIsOne )
{
GraphicsDevice . SetRenderTarget ( null ) ;
GraphicsDevice . Clear ( BgColour ) ;
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . AlphaBlend , SamplerState . LinearClamp , DepthStencilState . Default , RasterizerState . CullNone ) ;
spriteBatch . Draw ( Screen , Vector2 . Zero , Screen . Bounds , Color . White , 0f , Vector2 . Zero , options . zoomLevel , SpriteEffects . None , 1f ) ;
spriteBatch . End ( ) ;
}
return ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( showingEndOfNightStuff )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
activeClickableMenu ? . draw ( spriteBatch ) ;
2016-03-27 15:52:43 +08:00
spriteBatch . End ( ) ;
2016-03-29 11:23:09 +08:00
if ( ! ZoomLevelIsOne )
{
GraphicsDevice . SetRenderTarget ( null ) ;
GraphicsDevice . Clear ( BgColour ) ;
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . AlphaBlend , SamplerState . LinearClamp , DepthStencilState . Default , RasterizerState . CullNone ) ;
spriteBatch . Draw ( Screen , Vector2 . Zero , Screen . Bounds , Color . White , 0f , Vector2 . Zero , options . zoomLevel , SpriteEffects . None , 1f ) ;
spriteBatch . End ( ) ;
}
return ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( gameMode = = 6 )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
string text = "" ;
int num = 0 ;
while ( num < gameTime . TotalGameTime . TotalMilliseconds % 999.0 / 333.0 )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
text + = "." ;
num + + ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
SpriteText . drawString ( spriteBatch , "Loading" + text , 64 , graphics . GraphicsDevice . Viewport . Height - 64 , 999 , - 1 , 999 , 1f , 1f , false , 0 , "Loading..." ) ;
2016-03-27 15:52:43 +08:00
spriteBatch . End ( ) ;
2016-03-29 11:23:09 +08:00
if ( ! ZoomLevelIsOne )
{
GraphicsDevice . SetRenderTarget ( null ) ;
GraphicsDevice . Clear ( BgColour ) ;
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . AlphaBlend , SamplerState . LinearClamp , DepthStencilState . Default , RasterizerState . CullNone ) ;
spriteBatch . Draw ( Screen , Vector2 . Zero , Screen . Bounds , Color . White , 0f , Vector2 . Zero , options . zoomLevel , SpriteEffects . None , 1f ) ;
spriteBatch . End ( ) ;
}
return ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( gameMode = = 0 )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
else
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
if ( drawLighting )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
GraphicsDevice . SetRenderTarget ( lightmap ) ;
GraphicsDevice . Clear ( Color . White * 0f ) ;
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . NonPremultiplied , SamplerState . PointClamp , null , null ) ;
spriteBatch . Draw ( staminaRect , lightmap . Bounds , currentLocation . name . Equals ( "UndergroundMine" ) ? mine . getLightingColor ( gameTime ) : ( ( ! ambientLight . Equals ( Color . White ) & & ( ! isRaining | | ! currentLocation . isOutdoors ) ) ? ambientLight : outdoorLight ) ) ;
for ( int i = 0 ; i < currentLightSources . Count ; i + + )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
if ( Utility . isOnScreen ( currentLightSources . ElementAt ( i ) . position , ( int ) ( currentLightSources . ElementAt ( i ) . radius * tileSize * 4f ) ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( currentLightSources . ElementAt ( i ) . lightTexture , GlobalToLocal ( viewport , currentLightSources . ElementAt ( i ) . position ) / options . lightingQuality , currentLightSources . ElementAt ( i ) . lightTexture . Bounds , currentLightSources . ElementAt ( i ) . color , 0f , new Vector2 ( currentLightSources . ElementAt ( i ) . lightTexture . Bounds . Center . X , currentLightSources . ElementAt ( i ) . lightTexture . Bounds . Center . Y ) , currentLightSources . ElementAt ( i ) . radius / options . lightingQuality , SpriteEffects . None , 0.9f ) ;
2016-03-27 15:52:43 +08:00
}
}
2016-03-29 11:23:09 +08:00
spriteBatch . End ( ) ;
2016-03-29 18:23:42 +08:00
GraphicsDevice . SetRenderTarget ( ZoomLevelIsOne ? null : Screen ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( bloomDay )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
bloom ? . BeginDraw ( ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
GraphicsDevice . Clear ( BgColour ) ;
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
GraphicsEvents . InvokeOnPreRenderEvent ( null , EventArgs . Empty ) ;
background ? . draw ( spriteBatch ) ;
mapDisplayDevice . BeginScene ( spriteBatch ) ;
currentLocation . Map . GetLayer ( "Back" ) . Draw ( mapDisplayDevice , viewport , Location . Origin , false , pixelZoom ) ;
currentLocation . drawWater ( spriteBatch ) ;
if ( CurrentEvent = = null )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
using ( List < NPC > . Enumerator enumerator = currentLocation . characters . GetEnumerator ( ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
while ( enumerator . MoveNext ( ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
NPC current = enumerator . Current ;
if ( current ! = null & & ! current . swimming & & ! current . hideShadow & & ! current . IsMonster & & ! currentLocation . shouldShadowBeDrawnAboveBuildingsLayer ( current . getTileLocation ( ) ) )
{
spriteBatch . Draw ( shadowTexture , GlobalToLocal ( viewport , current . position + new Vector2 ( current . sprite . spriteWidth * pixelZoom / 2f , current . GetBoundingBox ( ) . Height + ( current . IsMonster ? 0 : ( pixelZoom * 3 ) ) ) ) , shadowTexture . Bounds , Color . White , 0f , new Vector2 ( shadowTexture . Bounds . Center . X , shadowTexture . Bounds . Center . Y ) , ( pixelZoom + current . yJumpOffset / 40f ) * current . scale , SpriteEffects . None , Math . Max ( 0f , current . getStandingY ( ) / 10000f ) - 1E-06f ) ;
}
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
goto IL_B30 ;
2016-03-27 15:52:43 +08:00
}
}
2016-03-29 11:23:09 +08:00
foreach ( NPC current2 in CurrentEvent . actors )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
if ( ! current2 . swimming & & ! current2 . hideShadow & & ! currentLocation . shouldShadowBeDrawnAboveBuildingsLayer ( current2 . getTileLocation ( ) ) )
{
spriteBatch . Draw ( shadowTexture , GlobalToLocal ( viewport , current2 . position + new Vector2 ( current2 . sprite . spriteWidth * pixelZoom / 2f , current2 . GetBoundingBox ( ) . Height + ( current2 . IsMonster ? 0 : ( pixelZoom * 3 ) ) ) ) , shadowTexture . Bounds , Color . White , 0f , new Vector2 ( shadowTexture . Bounds . Center . X , shadowTexture . Bounds . Center . Y ) , ( pixelZoom + current2 . yJumpOffset / 40f ) * current2 . scale , SpriteEffects . None , Math . Max ( 0f , current2 . getStandingY ( ) / 10000f ) - 1E-06f ) ;
}
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
IL_B30 :
if ( ! player . swimming & & ! player . isRidingHorse ( ) & & ! currentLocation . shouldShadowBeDrawnAboveBuildingsLayer ( player . getTileLocation ( ) ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( shadowTexture , GlobalToLocal ( player . position + new Vector2 ( 32f , 24f ) ) , shadowTexture . Bounds , Color . White , 0f , new Vector2 ( shadowTexture . Bounds . Center . X , shadowTexture . Bounds . Center . Y ) , 4f - ( ( ( player . running | | player . usingTool ) & & player . FarmerSprite . indexInCurrentAnimation > 1 ) ? ( Math . Abs ( FarmerRenderer . featureYOffsetPerFrame [ player . FarmerSprite . CurrentFrame ] ) * 0.5f ) : 0f ) , SpriteEffects . None , 0f ) ;
}
currentLocation . Map . GetLayer ( "Buildings" ) . Draw ( mapDisplayDevice , viewport , Location . Origin , false , pixelZoom ) ;
mapDisplayDevice . EndScene ( ) ;
spriteBatch . End ( ) ;
spriteBatch . Begin ( SpriteSortMode . FrontToBack , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
if ( CurrentEvent = = null )
{
using ( List < NPC > . Enumerator enumerator3 = currentLocation . characters . GetEnumerator ( ) )
{
while ( enumerator3 . MoveNext ( ) )
{
NPC current3 = enumerator3 . Current ;
if ( current3 ! = null & & ! current3 . swimming & & ! current3 . hideShadow & & currentLocation . shouldShadowBeDrawnAboveBuildingsLayer ( current3 . getTileLocation ( ) ) )
{
spriteBatch . Draw ( shadowTexture , GlobalToLocal ( viewport , current3 . position + new Vector2 ( current3 . sprite . spriteWidth * pixelZoom / 2f , current3 . GetBoundingBox ( ) . Height + ( current3 . IsMonster ? 0 : ( pixelZoom * 3 ) ) ) ) , shadowTexture . Bounds , Color . White , 0f , new Vector2 ( shadowTexture . Bounds . Center . X , shadowTexture . Bounds . Center . Y ) , ( pixelZoom + current3 . yJumpOffset / 40f ) * current3 . scale , SpriteEffects . None , Math . Max ( 0f , current3 . getStandingY ( ) / 10000f ) - 1E-06f ) ;
}
}
goto IL_F5F ;
}
}
foreach ( NPC current4 in CurrentEvent . actors )
{
if ( ! current4 . swimming & & ! current4 . hideShadow & & currentLocation . shouldShadowBeDrawnAboveBuildingsLayer ( current4 . getTileLocation ( ) ) )
{
spriteBatch . Draw ( shadowTexture , GlobalToLocal ( viewport , current4 . position + new Vector2 ( current4 . sprite . spriteWidth * pixelZoom / 2f , current4 . GetBoundingBox ( ) . Height + ( current4 . IsMonster ? 0 : ( pixelZoom * 3 ) ) ) ) , shadowTexture . Bounds , Color . White , 0f , new Vector2 ( shadowTexture . Bounds . Center . X , shadowTexture . Bounds . Center . Y ) , ( pixelZoom + current4 . yJumpOffset / 40f ) * current4 . scale , SpriteEffects . None , Math . Max ( 0f , current4 . getStandingY ( ) / 10000f ) - 1E-06f ) ;
}
}
IL_F5F :
if ( ! player . swimming & & ! player . isRidingHorse ( ) & & currentLocation . shouldShadowBeDrawnAboveBuildingsLayer ( player . getTileLocation ( ) ) )
{
spriteBatch . Draw ( shadowTexture , GlobalToLocal ( player . position + new Vector2 ( 32f , 24f ) ) , shadowTexture . Bounds , Color . White , 0f , new Vector2 ( shadowTexture . Bounds . Center . X , shadowTexture . Bounds . Center . Y ) , 4f - ( ( ( player . running | | player . usingTool ) & & player . FarmerSprite . indexInCurrentAnimation > 1 ) ? ( Math . Abs ( FarmerRenderer . featureYOffsetPerFrame [ player . FarmerSprite . CurrentFrame ] ) * 0.5f ) : 0f ) , SpriteEffects . None , Math . Max ( 0.0001f , player . getStandingY ( ) / 10000f + 0.00011f ) - 0.0001f ) ;
}
if ( displayFarmer )
{
player . draw ( spriteBatch ) ;
}
if ( ( eventUp | | killScreen ) & & ! killScreen )
{
currentLocation . currentEvent ? . draw ( spriteBatch ) ;
}
if ( player . currentUpgrade ! = null & & player . currentUpgrade . daysLeftTillUpgradeDone < = 3 & & currentLocation . Name . Equals ( "Farm" ) )
{
spriteBatch . Draw ( player . currentUpgrade . workerTexture , GlobalToLocal ( viewport , player . currentUpgrade . positionOfCarpenter ) , player . currentUpgrade . getSourceRectangle ( ) , Color . White , 0f , Vector2 . Zero , 1f , SpriteEffects . None , ( player . currentUpgrade . positionOfCarpenter . Y + tileSize * 3 / 4 ) / 10000f ) ;
}
currentLocation . draw ( spriteBatch ) ;
if ( eventUp & & currentLocation . currentEvent ? . messageToScreen ! = null )
{
drawWithBorder ( currentLocation . currentEvent . messageToScreen , Color . Black , Color . White , new Vector2 ( graphics . GraphicsDevice . Viewport . TitleSafeArea . Width / 2 - borderFont . MeasureString ( currentLocation . currentEvent . messageToScreen ) . X / 2f , graphics . GraphicsDevice . Viewport . TitleSafeArea . Height - tileSize ) , 0f , 1f , 0.999f ) ;
}
if ( player . ActiveObject = = null & & ( player . UsingTool | | pickingTool ) & & player . CurrentTool ! = null & & ( ! player . CurrentTool . Name . Equals ( "Seeds" ) | | pickingTool ) )
{
drawTool ( player ) ;
}
if ( currentLocation . Name . Equals ( "Farm" ) )
{
//typeof (Game1).GetMethod("drawFarmBuildings", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null);
DrawFarmBuildings . Invoke ( Program . gamePtr , null ) ;
//this.drawFarmBuildings();
}
if ( tvStation > = 0 )
{
spriteBatch . Draw ( tvStationTexture , GlobalToLocal ( viewport , new Vector2 ( 6 * tileSize + tileSize / 4 , 2 * tileSize + tileSize / 2 ) ) , new Rectangle ( tvStation * 24 , 0 , 24 , 15 ) , Color . White , 0f , Vector2 . Zero , 4f , SpriteEffects . None , 1E-08f ) ;
}
if ( panMode )
{
spriteBatch . Draw ( fadeToBlackRect , new Rectangle ( ( int ) Math . Floor ( ( getOldMouseX ( ) + viewport . X ) / ( double ) tileSize ) * tileSize - viewport . X , ( int ) Math . Floor ( ( getOldMouseY ( ) + viewport . Y ) / ( double ) tileSize ) * tileSize - viewport . Y , tileSize , tileSize ) , Color . Lime * 0.75f ) ;
foreach ( Warp current5 in currentLocation . warps )
{
spriteBatch . Draw ( fadeToBlackRect , new Rectangle ( current5 . X * tileSize - viewport . X , current5 . Y * tileSize - viewport . Y , tileSize , tileSize ) , Color . Red * 0.75f ) ;
}
2016-03-27 15:52:43 +08:00
}
mapDisplayDevice . BeginScene ( spriteBatch ) ;
2016-03-29 11:23:09 +08:00
currentLocation . Map . GetLayer ( "Front" ) . Draw ( mapDisplayDevice , viewport , Location . Origin , false , pixelZoom ) ;
2016-03-27 15:52:43 +08:00
mapDisplayDevice . EndScene ( ) ;
2016-03-29 11:23:09 +08:00
currentLocation . drawAboveFrontLayer ( spriteBatch ) ;
spriteBatch . End ( ) ;
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
if ( currentLocation . Name . Equals ( "Farm" ) & & stats . SeedsSown > = 200 u )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 3 * tileSize + tileSize / 4 , tileSize + tileSize / 3 ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 4 * tileSize + tileSize , 2 * tileSize + tileSize ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 5 * tileSize , 2 * tileSize ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 3 * tileSize + tileSize / 2 , 3 * tileSize ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 5 * tileSize - tileSize / 4 , tileSize ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 4 * tileSize , 3 * tileSize + tileSize / 6 ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
spriteBatch . Draw ( debrisSpriteSheet , GlobalToLocal ( viewport , new Vector2 ( 4 * tileSize + tileSize / 5 , 2 * tileSize + tileSize / 3 ) ) , getSourceRectForStandardTileSheet ( debrisSpriteSheet , 16 ) , Color . White ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( displayFarmer & & player . ActiveObject ! = null & & player . ActiveObject . bigCraftable & & checkBigCraftableBoundariesForFrontLayer ( ) & & currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( player . getStandingX ( ) , player . getStandingY ( ) ) , viewport . Size ) = = null )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
drawPlayerHeldObject ( player ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
else if ( displayFarmer & & player . ActiveObject ! = null & & ( ( currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( ( int ) player . position . X , ( int ) player . position . Y - tileSize * 3 / 5 ) , viewport . Size ) ! = null & & ! currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( ( int ) player . position . X , ( int ) player . position . Y - tileSize * 3 / 5 ) , viewport . Size ) . TileIndexProperties . ContainsKey ( "FrontAlways" ) ) | | ( currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( player . GetBoundingBox ( ) . Right , ( int ) player . position . Y - tileSize * 3 / 5 ) , viewport . Size ) ! = null & & ! currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( player . GetBoundingBox ( ) . Right , ( int ) player . position . Y - tileSize * 3 / 5 ) , viewport . Size ) . TileIndexProperties . ContainsKey ( "FrontAlways" ) ) ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
drawPlayerHeldObject ( player ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( ( player . UsingTool | | pickingTool ) & & player . CurrentTool ! = null & & ( ! player . CurrentTool . Name . Equals ( "Seeds" ) | | pickingTool ) & & currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( player . getStandingX ( ) , ( int ) player . position . Y - tileSize * 3 / 5 ) , viewport . Size ) ! = null & & currentLocation . Map . GetLayer ( "Front" ) . PickTile ( new Location ( player . getStandingX ( ) , player . getStandingY ( ) ) , viewport . Size ) = = null )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
drawTool ( player ) ;
}
if ( currentLocation . Map . GetLayer ( "AlwaysFront" ) ! = null )
{
mapDisplayDevice . BeginScene ( spriteBatch ) ;
currentLocation . Map . GetLayer ( "AlwaysFront" ) . Draw ( mapDisplayDevice , viewport , Location . Origin , false , pixelZoom ) ;
mapDisplayDevice . EndScene ( ) ;
}
if ( toolHold > 400f & & player . CurrentTool . UpgradeLevel > = 1 & & player . canReleaseTool )
{
Color color = Color . White ;
switch ( ( int ) ( toolHold / 600f ) + 2 )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
case 1 :
color = Tool . copperColor ;
break ;
case 2 :
color = Tool . steelColor ;
break ;
case 3 :
color = Tool . goldColor ;
break ;
case 4 :
color = Tool . iridiumColor ;
break ;
}
spriteBatch . Draw ( littleEffect , new Rectangle ( ( int ) player . getLocalPosition ( viewport ) . X - 2 , ( int ) player . getLocalPosition ( viewport ) . Y - ( player . CurrentTool . Name . Equals ( "Watering Can" ) ? 0 : tileSize ) - 2 , ( int ) ( toolHold % 600f * 0.08f ) + 4 , tileSize / 8 + 4 ) , Color . Black ) ;
spriteBatch . Draw ( littleEffect , new Rectangle ( ( int ) player . getLocalPosition ( viewport ) . X , ( int ) player . getLocalPosition ( viewport ) . Y - ( player . CurrentTool . Name . Equals ( "Watering Can" ) ? 0 : tileSize ) , ( int ) ( toolHold % 600f * 0.08f ) , tileSize / 8 ) , color ) ;
}
if ( isDebrisWeather & & currentLocation . IsOutdoors & & ! currentLocation . ignoreDebrisWeather & & ! currentLocation . Name . Equals ( "Desert" ) & & viewport . X > - 10 )
{
foreach ( WeatherDebris current6 in debrisWeather )
{
current6 . draw ( spriteBatch ) ;
}
}
farmEvent ? . draw ( spriteBatch ) ;
if ( currentLocation . LightLevel > 0f & & timeOfDay < 2000 )
{
spriteBatch . Draw ( fadeToBlackRect , graphics . GraphicsDevice . Viewport . Bounds , Color . Black * currentLocation . LightLevel ) ;
}
if ( screenGlow )
{
spriteBatch . Draw ( fadeToBlackRect , graphics . GraphicsDevice . Viewport . Bounds , screenGlowColor * screenGlowAlpha ) ;
}
currentLocation . drawAboveAlwaysFrontLayer ( spriteBatch ) ;
if ( player . CurrentTool is FishingRod & & ( ( player . CurrentTool as FishingRod ) . isTimingCast | | ( player . CurrentTool as FishingRod ) . castingChosenCountdown > 0f | | ( player . CurrentTool as FishingRod ) . fishCaught | | ( player . CurrentTool as FishingRod ) . showingTreasure ) )
{
player . CurrentTool . draw ( spriteBatch ) ;
}
if ( isRaining & & currentLocation . IsOutdoors & & ! currentLocation . Name . Equals ( "Desert" ) & & ! ( currentLocation is Summit ) & & ( ! eventUp | | currentLocation . isTileOnMap ( new Vector2 ( viewport . X / tileSize , viewport . Y / tileSize ) ) ) )
{
for ( int j = 0 ; j < rainDrops . Length ; j + + )
{
spriteBatch . Draw ( rainTexture , rainDrops [ j ] . position , getSourceRectForStandardTileSheet ( rainTexture , rainDrops [ j ] . frame ) , Color . White ) ;
}
}
spriteBatch . End ( ) ;
2016-03-29 18:23:42 +08:00
//base.Draw(gameTime);
2016-03-29 11:23:09 +08:00
/ * try
{
BaseBaseDraw bbd = ( BaseBaseDraw ) Delegate . CreateDelegate ( typeof ( BaseBaseDraw ) , Program . gamePtr , "Draw" ) ;
bbd . GetType ( ) . BaseType . BaseType . GetField ( "_target" , BindingFlags . Instance | BindingFlags . NonPublic ) . SetValue ( bbd , this ) ;
bbd ( ) ;
}
catch ( Exception ex )
{
Log . Error ( ex ) ;
} * /
spriteBatch . Begin ( SpriteSortMode . FrontToBack , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
if ( eventUp & & currentLocation . currentEvent ! = null )
{
foreach ( NPC current7 in currentLocation . currentEvent . actors )
{
if ( current7 . isEmoting )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
Vector2 localPosition = current7 . getLocalPosition ( viewport ) ;
localPosition . Y - = tileSize * 2 + pixelZoom * 3 ;
if ( current7 . age = = 2 )
{
localPosition . Y + = tileSize / 2 ;
}
else if ( current7 . gender = = 1 )
{
localPosition . Y + = tileSize / 6 ;
}
spriteBatch . Draw ( emoteSpriteSheet , localPosition , new Rectangle ( current7 . CurrentEmoteIndex * ( tileSize / 4 ) % emoteSpriteSheet . Width , current7 . CurrentEmoteIndex * ( tileSize / 4 ) / emoteSpriteSheet . Width * ( tileSize / 4 ) , tileSize / 4 , tileSize / 4 ) , Color . White , 0f , Vector2 . Zero , 4f , SpriteEffects . None , current7 . getStandingY ( ) / 10000f ) ;
2016-03-27 15:52:43 +08:00
}
}
}
2016-03-29 11:23:09 +08:00
spriteBatch . End ( ) ;
if ( drawLighting )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Begin ( SpriteSortMode . Deferred , new BlendState
{
ColorBlendFunction = BlendFunction . ReverseSubtract ,
ColorDestinationBlend = Blend . One ,
ColorSourceBlend = Blend . SourceColor
} , SamplerState . LinearClamp , null , null ) ;
spriteBatch . Draw ( lightmap , Vector2 . Zero , lightmap . Bounds , Color . White , 0f , Vector2 . Zero , options . lightingQuality , SpriteEffects . None , 1f ) ;
if ( isRaining & & currentLocation . isOutdoors & & ! ( currentLocation is Desert ) )
{
spriteBatch . Draw ( staminaRect , graphics . GraphicsDevice . Viewport . Bounds , Color . OrangeRed * 0.45f ) ;
}
spriteBatch . End ( ) ;
}
spriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
if ( drawGrid )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
int num2 = - viewport . X % tileSize ;
float num3 = - ( float ) viewport . Y % tileSize ;
for ( int k = num2 ; k < graphics . GraphicsDevice . Viewport . Width ; k + = tileSize )
{
spriteBatch . Draw ( staminaRect , new Rectangle ( k , ( int ) num3 , 1 , graphics . GraphicsDevice . Viewport . Height ) , Color . Red * 0.5f ) ;
}
for ( float num4 = num3 ; num4 < ( float ) graphics . GraphicsDevice . Viewport . Height ; num4 + = ( float ) tileSize )
{
spriteBatch . Draw ( staminaRect , new Rectangle ( num2 , ( int ) num4 , graphics . GraphicsDevice . Viewport . Width , 1 ) , Color . Red * 0.5f ) ;
}
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( currentBillboard ! = 0 )
{
drawBillboard ( ) ;
}
if ( ( displayHUD | | eventUp ) & & currentBillboard = = 0 & & gameMode = = 3 & & ! freezeControls & & ! panMode )
{
GraphicsEvents . InvokeOnPreRenderHudEvent ( null , EventArgs . Empty ) ;
//typeof (Game1).GetMethod("drawHUD", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null);
DrawHUD . Invoke ( Program . gamePtr , null ) ;
GraphicsEvents . InvokeOnPostRenderHudEvent ( null , EventArgs . Empty ) ;
//this.drawHUD();
}
else if ( activeClickableMenu = = null & & farmEvent = = null )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( mouseCursors , new Vector2 ( getOldMouseX ( ) , getOldMouseY ( ) ) , getSourceRectForStandardTileSheet ( mouseCursors , 0 , 16 , 16 ) , Color . White , 0f , Vector2 . Zero , 4f + dialogueButtonScale / 150f , SpriteEffects . None , 1f ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( hudMessages . Any ( ) & & ( ! eventUp | | isFestival ( ) ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
for ( int l = hudMessages . Count - 1 ; l > = 0 ; l - - )
{
hudMessages [ l ] . draw ( spriteBatch , l ) ;
}
2016-03-27 15:52:43 +08:00
}
}
2016-03-29 11:23:09 +08:00
farmEvent ? . draw ( spriteBatch ) ;
if ( dialogueUp & & ! nameSelectUp & & ! messagePause & & ! ( activeClickableMenu is DialogueBox ) )
{
//typeof (Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null);
DrawDialogueBox . Invoke ( Program . gamePtr , null ) ;
//this.drawDialogueBox();
}
if ( progressBar )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( fadeToBlackRect , new Rectangle ( ( graphics . GraphicsDevice . Viewport . TitleSafeArea . Width - dialogueWidth ) / 2 , graphics . GraphicsDevice . Viewport . TitleSafeArea . Bottom - tileSize * 2 , dialogueWidth , tileSize / 2 ) , Color . LightGray ) ;
spriteBatch . Draw ( staminaRect , new Rectangle ( ( graphics . GraphicsDevice . Viewport . TitleSafeArea . Width - dialogueWidth ) / 2 , graphics . GraphicsDevice . Viewport . TitleSafeArea . Bottom - tileSize * 2 , ( int ) ( pauseAccumulator / pauseTime * dialogueWidth ) , tileSize / 2 ) , Color . DimGray ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( eventUp )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
currentLocation . currentEvent ? . drawAfterMap ( spriteBatch ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( isRaining & & currentLocation . isOutdoors & & ! ( currentLocation is Desert ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( staminaRect , graphics . GraphicsDevice . Viewport . Bounds , Color . Blue * 0.2f ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( ( fadeToBlack | | globalFade ) & & ! menuUp & & ( ! nameSelectUp | | messagePause ) )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( fadeToBlackRect , graphics . GraphicsDevice . Viewport . Bounds , Color . Black * ( ( gameMode = = 0 ) ? ( 1f - fadeToBlackAlpha ) : fadeToBlackAlpha ) ) ;
}
else if ( flashAlpha > 0f )
{
if ( options . screenFlash )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
spriteBatch . Draw ( fadeToBlackRect , graphics . GraphicsDevice . Viewport . Bounds , Color . White * Math . Min ( 1f , flashAlpha ) ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
flashAlpha - = 0.1f ;
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
if ( ( messagePause | | globalFade ) & & dialogueUp )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
//typeof (Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null);
DrawDialogueBox . Invoke ( Program . gamePtr , null ) ;
//this.drawDialogueBox();
2016-03-27 15:52:43 +08:00
}
2016-03-29 11:23:09 +08:00
foreach ( TemporaryAnimatedSprite current8 in screenOverlayTempSprites )
2016-03-27 15:52:43 +08:00
{
2016-03-29 11:23:09 +08:00
current8 . draw ( spriteBatch , true ) ;
}
if ( debugMode )
{
spriteBatch . DrawString ( smallFont , string . Concat ( new object [ ]
{
panMode ? ( ( getOldMouseX ( ) + viewport . X ) / tileSize + "," + ( getOldMouseY ( ) + viewport . Y ) / tileSize ) : string . Concat ( "aplayer: " , player . getStandingX ( ) / tileSize , ", " , player . getStandingY ( ) / tileSize ) ,
Environment . NewLine ,
"debugOutput: " ,
debugOutput
} ) , new Vector2 ( GraphicsDevice . Viewport . TitleSafeArea . X , GraphicsDevice . Viewport . TitleSafeArea . Y ) , Color . Red , 0f , Vector2 . Zero , 1f , SpriteEffects . None , 0.9999999f ) ;
}
if ( inputMode )
{
spriteBatch . DrawString ( smallFont , "Input: " + debugInput , new Vector2 ( tileSize , tileSize * 3 ) , Color . Purple ) ;
}
if ( showKeyHelp )
{
spriteBatch . DrawString ( smallFont , keyHelpString , new Vector2 ( tileSize , viewport . Height - tileSize - ( dialogueUp ? ( tileSize * 3 + ( isQuestion ? ( questionChoices . Count * tileSize ) : 0 ) ) : 0 ) - smallFont . MeasureString ( keyHelpString ) . Y ) , Color . LightGray , 0f , Vector2 . Zero , 1f , SpriteEffects . None , 0.9999999f ) ;
}
if ( activeClickableMenu ! = null )
{
GraphicsEvents . InvokeOnPreRenderGuiEvent ( null , EventArgs . Empty ) ;
activeClickableMenu . draw ( spriteBatch ) ;
GraphicsEvents . InvokeOnPostRenderGuiEvent ( null , EventArgs . Empty ) ;
}
else
{
farmEvent ? . drawAboveEverything ( spriteBatch ) ;
}
2016-03-29 10:13:52 +08:00
2016-03-29 11:23:09 +08:00
GraphicsEvents . InvokeOnPostRenderEvent ( null , EventArgs . Empty ) ;
spriteBatch . End ( ) ;
GraphicsEvents . InvokeDrawTick ( ) ;
GraphicsEvents . InvokeDrawInRenderTargetTick ( ) ;
2016-03-29 10:13:52 +08:00
2016-03-29 11:23:09 +08:00
if ( ! ZoomLevelIsOne )
{
GraphicsDevice . SetRenderTarget ( null ) ;
GraphicsDevice . Clear ( BgColour ) ;
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . Opaque , SamplerState . LinearClamp , DepthStencilState . Default , RasterizerState . CullNone ) ;
spriteBatch . Draw ( Screen , Vector2 . Zero , Screen . Bounds , Color . White , 0f , Vector2 . Zero , options . zoomLevel , SpriteEffects . None , 1f ) ;
spriteBatch . End ( ) ;
}
}
catch ( Exception ex )
2016-03-27 09:50:47 +08:00
{
2016-03-29 11:23:09 +08:00
Log . Error ( "An error occured in the overridden draw loop: " + ex ) ;
2016-03-27 09:50:47 +08:00
}
2016-03-27 16:30:17 +08:00
#endregion
}
else
{
#region Base Draw Call
2016-03-27 13:32:15 +08:00
2016-03-27 16:30:17 +08:00
try
{
base . Draw ( gameTime ) ;
}
catch ( Exception ex )
{
Log . AsyncR ( "An error occured in the base draw loop: " + ex ) ;
Console . ReadKey ( ) ;
}
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
GraphicsEvents . InvokeDrawTick ( ) ;
if ( Constants . EnableDrawingIntoRenderTarget )
{
if ( ! options . zoomLevel . Equals ( 1.0f ) )
2016-03-27 15:52:43 +08:00
{
2016-03-27 16:30:17 +08:00
if ( Screen . RenderTargetUsage = = RenderTargetUsage . DiscardContents )
2016-03-27 15:52:43 +08:00
{
2016-03-27 16:30:17 +08:00
Screen = new RenderTarget2D ( graphics . GraphicsDevice , Math . Min ( 4096 , ( int ) ( Window . ClientBounds . Width * ( 1.0 / options . zoomLevel ) ) ) ,
Math . Min ( 4096 , ( int ) ( Window . ClientBounds . Height * ( 1.0 / options . zoomLevel ) ) ) ,
false , SurfaceFormat . Color , DepthFormat . Depth16 , 1 , RenderTargetUsage . PreserveContents ) ;
2016-03-27 15:52:43 +08:00
}
2016-03-27 16:30:17 +08:00
GraphicsDevice . SetRenderTarget ( Screen ) ;
}
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
// Not beginning the batch due to inconsistancies with the standard draw tick...
//spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
GraphicsEvents . InvokeDrawInRenderTargetTick ( ) ;
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
//spriteBatch.End();
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
//Re-draw the HUD
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . AlphaBlend , SamplerState . PointClamp , null , null ) ;
activeClickableMenu ? . draw ( spriteBatch ) ;
/ *
2016-03-27 15:52:43 +08:00
if ( ( displayHUD | | eventUp ) & & currentBillboard = = 0 & & gameMode = = 3 & & ! freezeControls & & ! panMode )
typeof ( Game1 ) . GetMethod ( "drawHUD" , BindingFlags . NonPublic | BindingFlags . Instance ) ? . Invoke ( Program . gamePtr , null ) ;
* /
2016-03-27 16:30:17 +08:00
spriteBatch . Draw ( mouseCursors , new Vector2 ( getOldMouseX ( ) , getOldMouseY ( ) ) , getSourceRectForStandardTileSheet ( mouseCursors , options . gamepadControls ? 44 : 0 , 16 , 16 ) , Color . White , 0.0f , Vector2 . Zero , pixelZoom + dialogueButtonScale / 150f , SpriteEffects . None , 1f ) ;
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
spriteBatch . End ( ) ;
2016-03-27 15:52:43 +08:00
2016-03-27 16:30:17 +08:00
if ( ! options . zoomLevel . Equals ( 1.0f ) )
2016-03-27 15:52:43 +08:00
{
2016-03-27 16:30:17 +08:00
GraphicsDevice . SetRenderTarget ( null ) ;
spriteBatch . Begin ( SpriteSortMode . Immediate , BlendState . Opaque , SamplerState . LinearClamp , DepthStencilState . Default , RasterizerState . CullNone ) ;
spriteBatch . Draw ( Screen , Vector2 . Zero , Screen . Bounds , Color . White , 0.0f , Vector2 . Zero , options . zoomLevel , SpriteEffects . None , 1f ) ;
2016-03-27 15:52:43 +08:00
spriteBatch . End ( ) ;
}
2016-03-27 16:30:17 +08:00
}
2016-03-27 17:05:36 +08:00
#endregion
}
2016-03-27 16:30:17 +08:00
2016-03-27 17:05:36 +08:00
if ( Debug )
{
spriteBatch . Begin ( ) ;
2016-03-27 18:40:09 +08:00
int i = 0 ;
2016-03-27 17:05:36 +08:00
while ( DebugMessageQueue . Any ( ) )
2016-03-27 16:30:17 +08:00
{
2016-03-27 17:05:36 +08:00
string s = DebugMessageQueue . Dequeue ( ) ;
2016-03-27 18:40:09 +08:00
spriteBatch . DrawString ( smoothFont , s , new Vector2 ( 0 , i * 14 ) , Color . CornflowerBlue ) ;
2016-03-27 17:05:36 +08:00
i + + ;
2016-03-27 16:30:17 +08:00
}
2016-03-27 17:05:36 +08:00
GraphicsEvents . InvokeDrawDebug ( null , EventArgs . Empty ) ;
2016-03-27 18:40:09 +08:00
2016-03-27 17:05:36 +08:00
spriteBatch . End ( ) ;
}
else
{
DebugMessageQueue . Clear ( ) ;
2016-03-27 13:32:15 +08:00
}
2016-03-05 03:10:39 +08:00
}
2016-03-27 13:09:09 +08:00
[Obsolete("Do not use at this time.")]
2016-03-27 15:52:43 +08:00
// ReSharper disable once UnusedMember.Local
2016-03-27 13:09:09 +08:00
private static int RegisterModItem ( SObject modItem )
2016-03-05 03:10:39 +08:00
{
if ( modItem . HasBeenRegistered )
2016-03-04 02:50:22 +08:00
{
2016-03-27 13:09:09 +08:00
Log . AsyncR ( $"The item {modItem.Name} has already been registered with ID {modItem.RegisteredId}" ) ;
2016-03-05 03:10:39 +08:00
return modItem . RegisteredId ;
}
2016-03-27 13:09:09 +08:00
var newId = LowestModItemID ;
2016-03-05 03:10:39 +08:00
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 ;
}
2016-03-27 13:09:09 +08:00
[Obsolete("Do not use at this time.")]
2016-03-27 15:52:43 +08:00
// ReSharper disable once UnusedMember.Local
2016-03-27 13:09:09 +08:00
private static SObject PullModItemFromDict ( int id , bool isIndex )
2016-03-05 03:10:39 +08:00
{
if ( isIndex )
2016-03-04 02:50:22 +08:00
{
2016-03-05 03:10:39 +08:00
if ( ModItems . ElementAtOrDefault ( id ) . Value ! = null )
{
return ModItems . ElementAt ( id ) . Value . Clone ( ) ;
}
2016-03-27 13:09:09 +08:00
Log . AsyncR ( "ModItem Dictionary does not contain index: " + id ) ;
2016-03-05 03:10:39 +08:00
return null ;
}
if ( ModItems . ContainsKey ( id ) )
{
return ModItems [ id ] . Clone ( ) ;
}
2016-03-27 13:09:09 +08:00
Log . AsyncR ( "ModItem Dictionary does not contain ID: " + id ) ;
2016-03-05 03:10:39 +08:00
return null ;
}
2016-03-27 13:09:09 +08:00
private void UpdateEventCalls ( )
2016-03-05 03:10:39 +08:00
{
KStateNow = Keyboard . GetState ( ) ;
2016-03-07 03:46:47 +08:00
2016-03-05 03:10:39 +08:00
MStateNow = Mouse . GetState ( ) ;
2016-03-27 13:09:09 +08:00
foreach ( var k in FramePressedKeys )
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeKeyPressed ( k ) ;
2016-03-07 03:46:47 +08:00
2016-03-27 13:09:09 +08:00
foreach ( var k in FrameReleasedKeys )
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeKeyReleased ( k ) ;
2016-03-07 03:46:47 +08:00
2016-03-27 13:09:09 +08:00
for ( var i = PlayerIndex . One ; i < = PlayerIndex . Four ; i + + )
2016-03-07 21:49:45 +08:00
{
2016-03-27 13:09:09 +08:00
var buttons = GetFramePressedButtons ( i ) ;
foreach ( var b in buttons )
2016-03-07 21:49:45 +08:00
{
2016-03-27 13:09:09 +08:00
if ( b = = Buttons . LeftTrigger | | b = = Buttons . RightTrigger )
2016-03-08 01:25:51 +08:00
{
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeTriggerPressed ( i , b , b = = Buttons . LeftTrigger ? GamePad . GetState ( i ) . Triggers . Left : GamePad . GetState ( i ) . Triggers . Right ) ;
2016-03-08 01:25:51 +08:00
}
else
{
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeButtonPressed ( i , b ) ;
2016-03-08 01:25:51 +08:00
}
2016-03-07 21:49:45 +08:00
}
}
2016-03-27 13:09:09 +08:00
for ( var i = PlayerIndex . One ; i < = PlayerIndex . Four ; i + + )
2016-03-07 21:49:45 +08:00
{
2016-03-27 13:09:09 +08:00
foreach ( var b in GetFrameReleasedButtons ( i ) )
2016-03-07 21:49:45 +08:00
{
2016-03-08 01:25:51 +08:00
if ( b = = Buttons . LeftTrigger | | b = = Buttons . RightTrigger )
{
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeTriggerReleased ( i , b , b = = Buttons . LeftTrigger ? GamePad . GetState ( i ) . Triggers . Left : GamePad . GetState ( i ) . Triggers . Right ) ;
2016-03-08 01:25:51 +08:00
}
else
{
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeButtonReleased ( i , b ) ;
2016-03-08 01:25:51 +08:00
}
2016-03-07 21:49:45 +08:00
}
}
2016-03-05 03:10:39 +08:00
if ( KStateNow ! = KStatePrior )
{
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeKeyboardChanged ( KStatePrior , KStateNow ) ;
2016-03-05 03:10:39 +08:00
}
if ( MStateNow ! = MStatePrior )
{
2016-03-23 08:36:04 +08:00
ControlEvents . InvokeMouseChanged ( MStatePrior , MStateNow ) ;
2016-03-05 03:10:39 +08:00
MStatePrior = MStateNow ;
}
if ( activeClickableMenu ! = null & & activeClickableMenu ! = PreviousActiveMenu )
{
2016-03-23 08:36:04 +08:00
MenuEvents . InvokeMenuChanged ( PreviousActiveMenu , activeClickableMenu ) ;
2016-03-05 03:10:39 +08:00
PreviousActiveMenu = activeClickableMenu ;
2016-03-28 16:13:40 +08:00
WasMenuClosedInvoked = false ;
}
if ( ! WasMenuClosedInvoked & & PreviousActiveMenu ! = null & & activeClickableMenu = = null )
{
MenuEvents . InvokeMenuClosed ( PreviousActiveMenu ) ;
WasMenuClosedInvoked = true ;
2016-03-05 03:10:39 +08:00
}
if ( locations . GetHash ( ) ! = PreviousGameLocations )
{
2016-03-23 08:36:04 +08:00
LocationEvents . InvokeLocationsChanged ( locations ) ;
2016-03-05 03:10:39 +08:00
PreviousGameLocations = locations . GetHash ( ) ;
}
if ( currentLocation ! = PreviousGameLocation )
{
2016-03-23 08:36:04 +08:00
LocationEvents . InvokeCurrentLocationChanged ( PreviousGameLocation , currentLocation ) ;
2016-03-05 03:10:39 +08:00
PreviousGameLocation = currentLocation ;
}
if ( player ! = null & & player ! = PreviousFarmer )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeFarmerChanged ( PreviousFarmer , player ) ;
2016-03-05 03:10:39 +08:00
PreviousFarmer = player ;
}
2016-03-05 04:40:46 +08:00
if ( player ! = null & & player . combatLevel ! = PreviousCombatLevel )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeLeveledUp ( EventArgsLevelUp . LevelType . Combat , player . combatLevel ) ;
2016-03-05 04:40:46 +08:00
PreviousCombatLevel = player . combatLevel ;
}
if ( player ! = null & & player . farmingLevel ! = PreviousFarmingLevel )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeLeveledUp ( EventArgsLevelUp . LevelType . Farming , player . farmingLevel ) ;
2016-03-05 04:40:46 +08:00
PreviousFarmingLevel = player . farmingLevel ;
}
if ( player ! = null & & player . fishingLevel ! = PreviousFishingLevel )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeLeveledUp ( EventArgsLevelUp . LevelType . Fishing , player . fishingLevel ) ;
2016-03-05 04:40:46 +08:00
PreviousFishingLevel = player . fishingLevel ;
}
if ( player ! = null & & player . foragingLevel ! = PreviousForagingLevel )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeLeveledUp ( EventArgsLevelUp . LevelType . Foraging , player . foragingLevel ) ;
2016-03-05 04:40:46 +08:00
PreviousForagingLevel = player . foragingLevel ;
}
if ( player ! = null & & player . miningLevel ! = PreviousMiningLevel )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeLeveledUp ( EventArgsLevelUp . LevelType . Mining , player . miningLevel ) ;
2016-03-05 04:40:46 +08:00
PreviousMiningLevel = player . miningLevel ;
}
if ( player ! = null & & player . luckLevel ! = PreviousLuckLevel )
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeLeveledUp ( EventArgsLevelUp . LevelType . Luck , player . luckLevel ) ;
2016-03-05 04:40:46 +08:00
PreviousLuckLevel = player . luckLevel ;
}
2016-03-27 13:09:09 +08:00
List < ItemStackChange > changedItems ;
2016-03-05 04:20:58 +08:00
if ( player ! = null & & HasInventoryChanged ( player . items , out changedItems ) )
2016-03-05 03:10:39 +08:00
{
2016-03-23 08:36:04 +08:00
PlayerEvents . InvokeInventoryChanged ( player . items , changedItems ) ;
2016-03-05 04:20:58 +08:00
PreviousItems = player . items . Where ( n = > n ! = null ) . ToDictionary ( n = > n , n = > n . Stack ) ;
2016-03-08 13:47:52 +08:00
}
2016-03-05 03:10:39 +08:00
2016-03-08 13:47:52 +08:00
var objectHash = currentLocation ? . objects ? . GetHash ( ) ;
2016-03-27 13:09:09 +08:00
if ( objectHash ! = null & & PreviousLocationObjects ! = objectHash )
2016-03-04 04:36:53 +08:00
{
2016-03-23 08:36:04 +08:00
LocationEvents . InvokeOnNewLocationObject ( currentLocation . objects ) ;
2016-03-08 13:47:52 +08:00
PreviousLocationObjects = objectHash ? ? - 1 ;
2016-03-05 03:10:39 +08:00
}
if ( timeOfDay ! = PreviousTimeOfDay )
2016-03-04 02:50:22 +08:00
{
2016-03-23 08:36:04 +08:00
TimeEvents . InvokeTimeOfDayChanged ( PreviousTimeOfDay , timeOfDay ) ;
2016-03-05 03:10:39 +08:00
PreviousTimeOfDay = timeOfDay ;
}
if ( dayOfMonth ! = PreviousDayOfMonth )
2016-03-04 02:50:22 +08:00
{
2016-03-23 08:36:04 +08:00
TimeEvents . InvokeDayOfMonthChanged ( PreviousDayOfMonth , dayOfMonth ) ;
2016-03-05 03:10:39 +08:00
PreviousDayOfMonth = dayOfMonth ;
}
if ( currentSeason ! = PreviousSeasonOfYear )
2016-03-04 02:50:22 +08:00
{
2016-03-23 08:36:04 +08:00
TimeEvents . InvokeSeasonOfYearChanged ( PreviousSeasonOfYear , currentSeason ) ;
2016-03-05 03:10:39 +08:00
PreviousSeasonOfYear = currentSeason ;
}
if ( year ! = PreviousYearOfGame )
2016-03-04 02:50:22 +08:00
{
2016-03-23 08:36:04 +08:00
TimeEvents . InvokeYearOfGameChanged ( PreviousYearOfGame , year ) ;
2016-03-05 03:10:39 +08:00
PreviousYearOfGame = year ;
}
2016-03-23 08:36:04 +08:00
//NOTE THAT THIS MUST CHECK BEFORE SETTING IT TO TRUE BECAUSE OF SOME SILLY ISSUES
if ( FireLoadedGameEvent )
{
PlayerEvents . InvokeLoadedGame ( new EventArgsLoadedGameChanged ( hasLoadedGame ) ) ;
FireLoadedGameEvent = false ;
}
if ( hasLoadedGame ! = PreviouslyLoadedGame )
{
FireLoadedGameEvent = true ;
PreviouslyLoadedGame = hasLoadedGame ;
}
2016-03-27 09:50:47 +08:00
if ( mine ! = null & & PreviousMineLevel ! = mine . mineLevel )
{
MineEvents . InvokeMineLevelChanged ( PreviousMineLevel , mine . mineLevel ) ;
PreviousMineLevel = mine . mineLevel ;
}
2016-03-27 15:52:43 +08:00
if ( PreviousIsNewDay ! = newDay )
{
2016-03-27 17:05:36 +08:00
TimeEvents . InvokeOnNewDay ( PreviousDayOfMonth , dayOfMonth , newDay ) ;
2016-03-27 15:52:43 +08:00
PreviousIsNewDay = newDay ;
}
2016-03-05 03:10:39 +08:00
}
2016-03-05 04:20:58 +08:00
private bool HasInventoryChanged ( List < Item > items , out List < ItemStackChange > changedItems )
{
changedItems = new List < ItemStackChange > ( ) ;
2016-03-27 15:52:43 +08:00
IEnumerable < Item > actualItems = items . Where ( n = > n ! = null ) . ToArray ( ) ;
2016-03-05 04:20:58 +08:00
foreach ( var item in actualItems )
{
if ( PreviousItems ! = null & & PreviousItems . ContainsKey ( item ) )
{
2016-03-27 13:09:09 +08:00
if ( PreviousItems [ item ] ! = item . Stack )
2016-03-05 04:20:58 +08:00
{
2016-03-27 13:09:09 +08:00
changedItems . Add ( new ItemStackChange { Item = item , StackChange = item . Stack - PreviousItems [ item ] , ChangeType = ChangeType . StackChange } ) ;
2016-03-05 04:20:58 +08:00
}
}
else
{
2016-03-27 13:09:09 +08:00
changedItems . Add ( new ItemStackChange { Item = item , StackChange = item . Stack , ChangeType = ChangeType . Added } ) ;
2016-03-05 04:20:58 +08:00
}
}
if ( PreviousItems ! = null )
{
2016-03-23 08:36:04 +08:00
changedItems . AddRange ( PreviousItems . Where ( n = > actualItems . All ( i = > i ! = n . Key ) ) . Select ( n = >
2016-03-27 13:09:09 +08:00
new ItemStackChange { Item = n . Key , StackChange = - n . Key . Stack , ChangeType = ChangeType . Removed } ) ) ;
2016-03-05 04:20:58 +08:00
}
2016-03-27 13:09:09 +08:00
return changedItems . Any ( ) ;
2016-03-05 04:20:58 +08:00
}
2016-03-27 15:52:43 +08:00
2016-03-27 18:40:09 +08:00
/// <summary>
/// Invokes a private, non-static method in Game1 via Reflection
/// </summary>
/// <param name="name">The name of the method</param>
/// <param name="parameters">Any parameters needed</param>
/// <returns>Whatever the method normally returns. Null if void.</returns>
2016-03-29 10:57:05 +08:00
[Obsolete("This is very slow. Cache the method info and then invoke it with InvokeMethodInfo().")]
2016-03-27 18:40:09 +08:00
public static object InvokeBasePrivateInstancedMethod ( string name , params object [ ] parameters )
{
try
{
return typeof ( Game1 ) . GetMethod ( name , BindingFlags . NonPublic | BindingFlags . Instance ) . Invoke ( Program . gamePtr , parameters ) ;
}
catch
{
Log . AsyncR ( "Failed to call base method: " + name ) ;
return null ;
}
}
2016-03-29 10:57:05 +08:00
/// <summary>
/// Invokes a given method info with the supplied parameters
/// </summary>
/// <param name="mi"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static object InvokeMethodInfo ( MethodInfo mi , params object [ ] parameters )
{
try
{
return mi . Invoke ( Program . gamePtr , parameters ) ;
}
catch
{
Log . AsyncR ( "Failed to call base method: " + mi . Name ) ;
return null ;
}
}
2016-03-27 15:52:43 +08:00
/// <summary>
/// Queue's a message to be drawn in Debug mode (F3)
/// </summary>
/// <returns></returns>
public static bool QueueDebugMessage ( string message )
{
if ( ! Debug )
return false ;
if ( DebugMessageQueue . Count > 32 )
return false ;
DebugMessageQueue . Enqueue ( message ) ;
return true ;
}
2016-03-05 03:10:39 +08:00
}
2016-02-29 09:26:36 +08:00
}