2017-07-20 11:51:05 +08:00
|
|
|
|
using UIInfoSuite.Options;
|
|
|
|
|
using UIInfoSuite.UIElements;
|
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewModdingAPI.Events;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace UIInfoSuite
|
|
|
|
|
{
|
|
|
|
|
public class ModEntry : Mod
|
|
|
|
|
{
|
2018-12-25 12:36:39 +08:00
|
|
|
|
private SkipIntro _skipIntro;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
private String _modDataFileName;
|
|
|
|
|
private readonly Dictionary<String, String> _options = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
public static IMonitor MonitorObject { get; private set; }
|
|
|
|
|
|
|
|
|
|
private ModOptionsPageHandler _modOptionsPageHandler;
|
|
|
|
|
|
2018-12-25 12:36:39 +08:00
|
|
|
|
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
|
|
|
|
|
/// <param name="helper">Provides simplified APIs for writing mods.</param>
|
2017-07-20 11:51:05 +08:00
|
|
|
|
public override void Entry(IModHelper helper)
|
|
|
|
|
{
|
|
|
|
|
//Helper = helper;
|
|
|
|
|
MonitorObject = Monitor;
|
2018-12-25 12:36:39 +08:00
|
|
|
|
_skipIntro = new SkipIntro(helper.Events);
|
|
|
|
|
|
2018-05-21 07:38:50 +08:00
|
|
|
|
Monitor.Log("starting.", LogLevel.Debug);
|
2018-12-25 12:36:39 +08:00
|
|
|
|
helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;
|
|
|
|
|
helper.Events.GameLoop.Saved += OnSaved;
|
|
|
|
|
helper.Events.GameLoop.ReturnedToTitle += OnReturnedToTitle;
|
|
|
|
|
helper.Events.Display.Rendering += IconHandler.Handler.Reset;
|
2019-11-27 14:12:29 +08:00
|
|
|
|
helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
//Resources = new ResourceManager("UIInfoSuite.Resource.strings", Assembly.GetAssembly(typeof(ModEntry)));
|
|
|
|
|
//try
|
|
|
|
|
//{
|
|
|
|
|
// //Test to make sure the culture specific files are there
|
|
|
|
|
// Resources.GetString(LanguageKeys.Days, ModEntry.SpecificCulture);
|
|
|
|
|
//}
|
|
|
|
|
//catch
|
|
|
|
|
//{
|
|
|
|
|
// Resources = Properties.Resources.ResourceManager;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 14:12:29 +08:00
|
|
|
|
private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 12:36:39 +08:00
|
|
|
|
/// <summary>Raised after the game returns to the title screen.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
private void OnReturnedToTitle(object sender, ReturnedToTitleEventArgs e)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-08-20 05:57:45 +08:00
|
|
|
|
_modOptionsPageHandler?.Dispose();
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_modOptionsPageHandler = null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 12:36:39 +08:00
|
|
|
|
/// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event arguments.</param>
|
|
|
|
|
private void OnSaved(object sender, EventArgs e)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2017-11-28 13:27:52 +08:00
|
|
|
|
if (!String.IsNullOrWhiteSpace(_modDataFileName))
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2017-11-28 13:27:52 +08:00
|
|
|
|
if (File.Exists(_modDataFileName))
|
|
|
|
|
File.Delete(_modDataFileName);
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
settings.IndentChars = " ";
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(File.Open(_modDataFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite), settings))
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2017-11-28 13:27:52 +08:00
|
|
|
|
writer.WriteStartElement("options");
|
|
|
|
|
|
|
|
|
|
foreach (var option in _options)
|
|
|
|
|
{
|
|
|
|
|
writer.WriteStartElement("option");
|
|
|
|
|
writer.WriteAttributeString("name", option.Key);
|
|
|
|
|
writer.WriteValue(option.Value);
|
|
|
|
|
writer.WriteEndElement();
|
|
|
|
|
}
|
2017-07-20 11:51:05 +08:00
|
|
|
|
writer.WriteEndElement();
|
2019-01-07 13:25:05 +08:00
|
|
|
|
writer.Close();
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 12:36:39 +08:00
|
|
|
|
/// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event arguments.</param>
|
|
|
|
|
private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2017-11-28 13:27:52 +08:00
|
|
|
|
try
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
_modDataFileName = Path.Combine(Helper.DirectoryPath, Game1.player.Name + "_modData.xml");
|
2017-11-28 13:27:52 +08:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Monitor.Log("Error: Player name contains character that cannot be used in file name. Using generic file name." + Environment.NewLine +
|
|
|
|
|
"Options may not be able to be different between characters.", LogLevel.Warn);
|
|
|
|
|
_modDataFileName = Path.Combine(Helper.DirectoryPath, "default_modData.xml");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (File.Exists(_modDataFileName))
|
|
|
|
|
{
|
|
|
|
|
XmlDocument document = new XmlDocument();
|
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
document.Load(_modDataFileName);
|
|
|
|
|
XmlNodeList nodes = document.GetElementsByTagName("option");
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode node in nodes)
|
|
|
|
|
{
|
|
|
|
|
String key = node.Attributes["name"]?.Value;
|
|
|
|
|
String value = node.InnerText;
|
|
|
|
|
|
|
|
|
|
if (key != null)
|
|
|
|
|
_options[key] = value;
|
|
|
|
|
}
|
2017-11-28 13:27:52 +08:00
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
2017-11-28 13:27:52 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Monitor.Log("Error loading mod config. " + ex.Message + Environment.NewLine + ex.StackTrace, LogLevel.Error);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_modOptionsPageHandler = new ModOptionsPageHandler(Helper, _options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|