mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-09 10:38:59 +08:00
1.6.8
* Added a ModConfig, allowing you to define the main menu toggle keybind and the default window size (so far). * Made the parsing of arguments more intelligent, should now behave as expected for null or empty arguments.
This commit is contained in:
parent
a927b5ed21
commit
1d739a1936
@ -244,30 +244,41 @@ namespace Explorer
|
||||
var input = m_argumentInput[i];
|
||||
var type = m_arguments[i].ParameterType;
|
||||
|
||||
if (type == typeof(string))
|
||||
// First, try parse the input and use that.
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
parsedArgs.Add(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
// strings can obviously just be used directly
|
||||
if (type == typeof(string))
|
||||
{
|
||||
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) })
|
||||
.Invoke(null, new object[] { input }));
|
||||
parsedArgs.Add(input);
|
||||
continue;
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
if (m_arguments[i].HasDefaultValue)
|
||||
// try to invoke the parse method and use that.
|
||||
try
|
||||
{
|
||||
parsedArgs.Add(m_arguments[i].DefaultValue);
|
||||
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) })
|
||||
.Invoke(null, new object[] { input }));
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
catch
|
||||
{
|
||||
// Try add a null arg I guess
|
||||
parsedArgs.Add(null);
|
||||
MelonLogger.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't use input, see if there is a default value.
|
||||
if (m_arguments[i].HasDefaultValue)
|
||||
{
|
||||
parsedArgs.Add(m_arguments[i].DefaultValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try add a null arg I guess
|
||||
parsedArgs.Add(null);
|
||||
}
|
||||
|
||||
return parsedArgs.ToArray();
|
||||
|
62
src/Config/ModConfig.cs
Normal file
62
src/Config/ModConfig.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public class ModConfig
|
||||
{
|
||||
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
|
||||
|
||||
[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\CppExplorer";
|
||||
[XmlIgnore] private const string SETTINGS_PATH = EXPLORER_FOLDER + @"\config.xml";
|
||||
|
||||
[XmlIgnore] public static ModConfig Instance;
|
||||
|
||||
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
public Vector2 Default_Window_Size = new Vector2(550, 700);
|
||||
|
||||
public static void OnLoad()
|
||||
{
|
||||
if (!Directory.Exists(EXPLORER_FOLDER))
|
||||
{
|
||||
Directory.CreateDirectory(EXPLORER_FOLDER);
|
||||
}
|
||||
|
||||
if (File.Exists(SETTINGS_PATH))
|
||||
{
|
||||
LoadSettings(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = new ModConfig();
|
||||
SaveSettings(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadSettings(bool checkExist = true)
|
||||
{
|
||||
if (checkExist && !File.Exists(SETTINGS_PATH))
|
||||
return;
|
||||
|
||||
var file = File.OpenRead(SETTINGS_PATH);
|
||||
Instance = (ModConfig)Serializer.Deserialize(file);
|
||||
file.Close();
|
||||
}
|
||||
|
||||
public static void SaveSettings(bool checkExist = true)
|
||||
{
|
||||
if (checkExist && File.Exists(SETTINGS_PATH))
|
||||
File.Delete(SETTINGS_PATH);
|
||||
|
||||
FileStream file = File.Create(SETTINGS_PATH);
|
||||
Serializer.Serialize(file, Instance);
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace Explorer
|
||||
public class CppExplorer : MelonMod
|
||||
{
|
||||
public const string NAME = "CppExplorer";
|
||||
public const string VERSION = "1.6.7";
|
||||
public const string VERSION = "1.6.8";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.cppexplorer";
|
||||
|
||||
@ -54,6 +54,8 @@ namespace Explorer
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
ModConfig.OnLoad();
|
||||
|
||||
InputHelper.Init();
|
||||
|
||||
new MainMenu();
|
||||
@ -80,7 +82,7 @@ namespace Explorer
|
||||
public override void OnUpdate()
|
||||
{
|
||||
// Check main toggle key input
|
||||
if (InputHelper.GetKeyDown(KeyCode.F7))
|
||||
if (InputHelper.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
||||
{
|
||||
ShowMenu = !ShowMenu;
|
||||
}
|
||||
|
@ -85,6 +85,7 @@
|
||||
<Compile Include="CachedObjects\Struct\CacheQuaternion.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheVector.cs" />
|
||||
<Compile Include="CachedObjects\Struct\CacheRect.cs" />
|
||||
<Compile Include="Config\ModConfig.cs" />
|
||||
<Compile Include="CppExplorer.cs" />
|
||||
<Compile Include="Extensions\ReflectionExtensions.cs" />
|
||||
<Compile Include="Helpers\InputHelper.cs" />
|
||||
|
@ -27,8 +27,9 @@ namespace Explorer
|
||||
}
|
||||
}
|
||||
|
||||
public const int MainWindowID = 10;
|
||||
public static Rect MainRect = new Rect(5, 5, 550, 700);
|
||||
public const int MainWindowID = 5000;
|
||||
public static Rect MainRect = new Rect(new Vector2(5,5), ModConfig.Instance.Default_Window_Size);
|
||||
|
||||
private static readonly List<WindowPage> Pages = new List<WindowPage>();
|
||||
private static int m_currentPage = 0;
|
||||
|
||||
@ -63,7 +64,7 @@ namespace Explorer
|
||||
{
|
||||
GUI.DragWindow(new Rect(0, 0, MainRect.width - 90, 20));
|
||||
|
||||
if (GUI.Button(new Rect(MainRect.width - 90, 2, 80, 20), "Hide (F7)"))
|
||||
if (GUI.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})"))
|
||||
{
|
||||
CppExplorer.ShowMenu = false;
|
||||
return;
|
||||
|
@ -17,7 +17,7 @@ namespace Explorer
|
||||
public object Target;
|
||||
|
||||
public int windowID;
|
||||
public Rect m_rect = new Rect(0, 0, 550, 700);
|
||||
public Rect m_rect = new Rect(Vector2.zero, ModConfig.Instance.Default_Window_Size);
|
||||
|
||||
public Vector2 scroll = Vector2.zero;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user