2017-09-13 02:20:18 +08:00
using Microsoft.Xna.Framework.Input ;
using StardewModdingAPI ;
using StardewValley ;
using StardewValley.Menus ;
2017-09-12 14:39:59 +08:00
using StardustCore.ModInfo ;
2017-09-14 04:53:12 +08:00
using StardustCore.Serialization ;
2017-09-05 19:13:42 +08:00
using System ;
2017-07-14 11:27:48 +08:00
using System.Collections.Generic ;
2017-09-14 04:53:12 +08:00
using System.IO ;
2017-07-14 11:27:48 +08:00
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2017-09-05 19:13:42 +08:00
namespace StardustCore
2017-07-14 11:27:48 +08:00
{
2017-09-05 19:13:42 +08:00
public class ModCore : Mod
2017-07-14 11:27:48 +08:00
{
2017-09-12 09:35:31 +08:00
public static IModHelper ModHelper ;
public static IMonitor ModMonitor ;
2017-09-14 04:53:12 +08:00
public static Serialization . SerializationManager SerializationManager ;
2018-02-06 17:27:28 +08:00
public static string ContentDirectory ;
2017-09-12 09:35:31 +08:00
public override void Entry ( IModHelper helper )
{
ModHelper = helper ;
2018-02-06 17:27:28 +08:00
ModMonitor = Monitor ;
2017-09-13 07:30:30 +08:00
//Unused MetaData information. Works in player inventory but not in chests. Besides who really care where an object is from anyways. Also doesn't work 100% like I intended since it only gets base mod object that this runs from, not extensions?
2017-09-14 04:53:12 +08:00
// StardewModdingAPI.Events.GraphicsEvents.OnPostRenderGuiEvent += Metadata.GameEvents_UpdateTick;
2018-02-06 17:27:28 +08:00
//StardewModdingAPI.Events.ControlEvents.MouseChanged += ControlEvents_MouseChanged;
2017-09-14 04:53:12 +08:00
string invPath = Path . Combine ( ModCore . ModHelper . DirectoryPath , "PlayerData" , Game1 . player . name , "PlayerInventory" ) ;
string worldPath = Path . Combine ( ModCore . ModHelper . DirectoryPath , Game1 . player . name , "ObjectsInWorld" ) ; ;
string trashPath = Path . Combine ( ModCore . ModHelper . DirectoryPath , "ModTrashFolder" ) ;
string chestPath = Path . Combine ( ModCore . ModHelper . DirectoryPath , "StorageContainers" ) ;
SerializationManager = new SerializationManager ( invPath , trashPath , worldPath , chestPath ) ;
StardewModdingAPI . Events . SaveEvents . AfterSave + = SaveEvents_AfterSave ;
StardewModdingAPI . Events . SaveEvents . BeforeSave + = SaveEvents_BeforeSave ;
StardewModdingAPI . Events . SaveEvents . AfterLoad + = SaveEvents_AfterLoad ;
2017-11-17 15:07:30 +08:00
IlluminateFramework . Colors . initializeColors ( ) ;
2018-02-06 17:27:28 +08:00
ContentDirectory = Path . Combine ( ModHelper . DirectoryPath , "Content" ) ;
if ( ! Directory . Exists ( ContentDirectory ) ) Directory . CreateDirectory ( ContentDirectory ) ;
UIUtilities . SpriteFonts . SpriteFont . initialize ( ) ;
2017-11-25 05:12:36 +08:00
2017-09-14 04:53:12 +08:00
}
2017-11-25 05:12:36 +08:00
2017-09-14 04:53:12 +08:00
private void SaveEvents_AfterLoad ( object sender , EventArgs e )
{
SerializationManager . restoreAllModObjects ( SerializationManager . trackedObjectList ) ;
2017-11-17 15:07:30 +08:00
2017-09-14 04:53:12 +08:00
}
private void SaveEvents_AfterSave ( object sender , EventArgs e )
{
SerializationManager . restoreAllModObjects ( SerializationManager . trackedObjectList ) ;
}
private void SaveEvents_BeforeSave ( object sender , EventArgs e )
{
SerializationManager . cleanUpInventory ( ) ;
SerializationManager . cleanUpWorld ( ) ;
2017-09-14 08:11:05 +08:00
SerializationManager . cleanUpStorageContainers ( ) ;
2017-09-13 02:20:18 +08:00
}
private void ControlEvents_MouseChanged ( object sender , StardewModdingAPI . Events . EventArgsMouseStateChanged e )
{
if ( Game1 . activeClickableMenu = = null ) return ;
var MouseState = Mouse . GetState ( ) ;
if ( Game1 . activeClickableMenu is StardewValley . Menus . ItemGrabMenu & & MouseState . LeftButton = = ButtonState . Released )
{
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . populateClickableComponentList ( ) ;
for ( int index = 0 ; index < ( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory . Count ; + + index )
{
if ( ( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] ! = null )
{
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] . myID + = 53910 ;
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] . upNeighborID + = 53910 ;
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] . rightNeighborID + = 53910 ;
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] . downNeighborID = - 7777 ;
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] . leftNeighborID + = 53910 ;
( Game1 . activeClickableMenu as StardewValley . Menus . ItemGrabMenu ) . ItemsToGrabMenu . inventory [ index ] . fullyImmutable = true ;
}
}
// (Game1.activeClickableMenu as ItemGrabMenu).inventory.playerInventory = false;
// Game1.activeClickableMenu =Game1.activeClickableMenu;//new ItemGrabMenu((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory,true,true,null,null,null,null,false,false,true,true,true,1,null,-1,null);
}
2017-09-12 09:35:31 +08:00
}
2017-07-14 11:27:48 +08:00
}
}