2016-10-13 15:22:50 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-07-31 11:07:07 +08:00
|
|
|
|
using Omegasis.MuseumRearranger.Framework;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewModdingAPI;
|
2017-07-30 01:30:04 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewValley;
|
2017-07-30 01:30:04 +08:00
|
|
|
|
using StardewValley.Locations;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
|
|
|
|
|
namespace Omegasis.MuseumRearranger
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
|
|
|
|
public class MuseumRearranger : Mod
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Properties
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The key which shows the museum rearranging menu.</summary>
|
|
|
|
|
private string ShowMenuKey = "R";
|
2016-10-13 15:22:50 +08:00
|
|
|
|
|
2017-07-30 01:30:04 +08:00
|
|
|
|
/// <summary>The key which toggles the inventory box when the menu is open.</summary>
|
|
|
|
|
private string ToggleInventoryKey = "T";
|
|
|
|
|
|
|
|
|
|
/// <summary>Whether the player loaded a save.</summary>
|
|
|
|
|
private bool IsGameLoaded;
|
|
|
|
|
|
|
|
|
|
/// <summary>The open museum menu (if any).</summary>
|
|
|
|
|
private NewMuseumMenu OpenMenu;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** Public methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
|
|
|
|
|
/// <param name="helper">Provides simplified APIs for writing mods.</param>
|
2016-12-09 08:34:28 +08:00
|
|
|
|
public override void Entry(IModHelper helper)
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
|
|
|
|
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:30:04 +08:00
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** Private methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The method invoked when the presses a keyboard button.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
if (Game1.player == null || Game1.player.currentLocation == null || !this.IsGameLoaded)
|
|
|
|
|
return;
|
2016-10-13 15:22:50 +08:00
|
|
|
|
|
2017-07-30 01:30:04 +08:00
|
|
|
|
// open menu
|
|
|
|
|
if (e.KeyPressed.ToString() == this.ShowMenuKey)
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
if (Game1.activeClickableMenu != null)
|
|
|
|
|
return;
|
|
|
|
|
if (Game1.player.currentLocation is LibraryMuseum)
|
|
|
|
|
Game1.activeClickableMenu = this.OpenMenu = new NewMuseumMenu(this.Helper.Reflection);
|
|
|
|
|
else
|
|
|
|
|
this.Monitor.Log("You can't rearrange the museum here.");
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
2017-07-30 01:30:04 +08:00
|
|
|
|
|
|
|
|
|
// toggle inventory box
|
|
|
|
|
if (e.KeyPressed.ToString() == this.ToggleInventoryKey)
|
|
|
|
|
this.OpenMenu?.ToggleInventory();
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:30:04 +08:00
|
|
|
|
/// <summary>The method invoked after the player loads a save.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
this.IsGameLoaded = true;
|
|
|
|
|
this.LoadConfig();
|
|
|
|
|
this.WriteConfig();
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:30:04 +08:00
|
|
|
|
/// <summary>Load the configuration settings.</summary>
|
|
|
|
|
private void LoadConfig()
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
string path = Path.Combine(Helper.DirectoryPath, "Museum_Rearrange_Config.txt");
|
2017-07-31 13:15:45 +08:00
|
|
|
|
if (!File.Exists(path))
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
this.ShowMenuKey = "R";
|
|
|
|
|
this.ToggleInventoryKey = "T";
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
string[] text = File.ReadAllLines(path);
|
|
|
|
|
this.ShowMenuKey = Convert.ToString(text[3]);
|
|
|
|
|
this.ToggleInventoryKey = Convert.ToString(text[5]);
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:30:04 +08:00
|
|
|
|
/// <summary>Save the configuration settings.</summary>
|
|
|
|
|
private void WriteConfig()
|
2016-10-13 15:22:50 +08:00
|
|
|
|
{
|
2017-07-30 01:30:04 +08:00
|
|
|
|
string path = Path.Combine(Helper.DirectoryPath, "Museum_Rearrange_Config.txt");
|
|
|
|
|
string[] text = new string[20];
|
2017-07-31 13:15:45 +08:00
|
|
|
|
text[0] = "Config: Museum_Rearranger. Feel free to mess with these settings.";
|
|
|
|
|
text[1] = "====================================================================================";
|
|
|
|
|
text[2] = "Key binding for rearranging the museum.";
|
|
|
|
|
text[3] = this.ShowMenuKey;
|
|
|
|
|
text[4] = "Key binding for showing the menu when rearranging the museum.";
|
|
|
|
|
text[5] = this.ToggleInventoryKey;
|
|
|
|
|
File.WriteAllLines(path, text);
|
2016-10-13 15:22:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|