2016-10-20 15:15:14 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewModdingAPI;
|
2017-07-30 01:54:26 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewValley;
|
2017-07-30 01:54:26 +08:00
|
|
|
|
using StardewValley.Menus;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
|
|
|
|
|
namespace Omegasis.BillboardAnywhere
|
2016-10-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
|
|
|
|
public class BillboardAnywhere : Mod
|
2016-10-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Properties
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The key which shows the billboard menu.</summary>
|
|
|
|
|
private string KeyBinding = "B";
|
2016-10-20 15:15:14 +08:00
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
/// <summary>Whether the player loaded a save.</summary>
|
|
|
|
|
private bool IsGameLoaded;
|
2016-10-20 15:15:14 +08:00
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** 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-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
|
|
|
|
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
|
2016-10-20 15:15:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** Private methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <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)
|
2017-02-22 15:29:00 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
this.IsGameLoaded = true;
|
|
|
|
|
this.LoadConfig();
|
2017-02-22 15:29:00 +08:00
|
|
|
|
}
|
2016-10-20 15:15:14 +08:00
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
/// <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>
|
|
|
|
|
public void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
|
2016-10-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
if (Game1.player == null || Game1.player.currentLocation == null || this.IsGameLoaded == false || Game1.activeClickableMenu != null)
|
|
|
|
|
return;
|
2016-10-20 15:15:14 +08:00
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
// load menu if key pressed
|
|
|
|
|
if (e.KeyPressed.ToString() == this.KeyBinding)
|
|
|
|
|
Game1.activeClickableMenu = new Billboard();
|
2016-10-20 15:15:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
/// <summary>Load the configuration settings.</summary>
|
|
|
|
|
void LoadConfig()
|
2016-10-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
string path = Path.Combine(this.Helper.DirectoryPath, "Billboard_Anywhere_Config.txt");
|
2017-07-31 13:15:45 +08:00
|
|
|
|
if (!File.Exists(path))
|
2016-10-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
this.KeyBinding = "B";
|
|
|
|
|
this.WriteConfig();
|
2016-10-20 15:15:14 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
string[] text = File.ReadAllLines(path);
|
|
|
|
|
this.KeyBinding = Convert.ToString(text[3]);
|
2016-10-20 15:15:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:54:26 +08:00
|
|
|
|
/// <summary>Save the configuration settings.</summary>
|
|
|
|
|
void WriteConfig()
|
2016-10-20 15:15:14 +08:00
|
|
|
|
{
|
2017-07-30 01:54:26 +08:00
|
|
|
|
string path = Path.Combine(Helper.DirectoryPath, "Billboard_Anywhere_Config.txt");
|
|
|
|
|
string[] text = new string[20];
|
2017-07-31 13:15:45 +08:00
|
|
|
|
text[0] = "Config: Billboard_Anywhere. Feel free to mess with these settings.";
|
|
|
|
|
text[1] = "====================================================================================";
|
|
|
|
|
text[2] = "Key binding for opening the billboard anywhere. Press this key to do so";
|
|
|
|
|
text[3] = this.KeyBinding;
|
|
|
|
|
File.WriteAllLines(path, text);
|
2016-10-20 15:15:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|