mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-06 01:23:31 +08:00
Restore UnlockMouse config, adjust config saving
This commit is contained in:
parent
40f698122d
commit
3501a28fd1
24
src/Core/Config/ConfigHandler.cs
Normal file
24
src/Core/Config/ConfigHandler.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Core.Config
|
||||
{
|
||||
public abstract class ConfigHandler
|
||||
{
|
||||
public abstract void RegisterConfigElement<T>(ConfigElement<T> element);
|
||||
|
||||
public abstract void SetConfigValue<T>(ConfigElement<T> element, T value);
|
||||
|
||||
public abstract T GetConfigValue<T>(ConfigElement<T> element);
|
||||
|
||||
public abstract void Init();
|
||||
|
||||
public abstract void LoadConfig();
|
||||
|
||||
public abstract void SaveConfig();
|
||||
|
||||
public virtual void OnAnyConfigChanged() { }
|
||||
}
|
||||
}
|
@ -12,15 +12,17 @@ namespace UnityExplorer.Core.Config
|
||||
{
|
||||
public static class ConfigManager
|
||||
{
|
||||
// Each Loader has its own ConfigHandler.
|
||||
// Each Mod Loader has its own ConfigHandler.
|
||||
// See the UnityExplorer.Loader namespace for the implementations.
|
||||
public static IConfigHandler Handler { get; private set; }
|
||||
public static ConfigHandler Handler { get; private set; }
|
||||
|
||||
public static ConfigElement<KeyCode> Main_Menu_Toggle;
|
||||
public static ConfigElement<bool> Force_Unlock_Mouse;
|
||||
public static ConfigElement<int> Default_Page_Limit;
|
||||
public static ConfigElement<string> Default_Output_Path;
|
||||
public static ConfigElement<bool> Log_Unity_Debug;
|
||||
public static ConfigElement<bool> Hide_On_Startup;
|
||||
|
||||
public static ConfigElement<string> Last_Window_Anchors;
|
||||
public static ConfigElement<int> Last_Active_Tab;
|
||||
public static ConfigElement<bool> Last_DebugConsole_State;
|
||||
@ -28,7 +30,7 @@ namespace UnityExplorer.Core.Config
|
||||
|
||||
internal static readonly Dictionary<string, IConfigElement> ConfigElements = new Dictionary<string, IConfigElement>();
|
||||
|
||||
public static void Init(IConfigHandler configHandler)
|
||||
public static void Init(ConfigHandler configHandler)
|
||||
{
|
||||
Handler = configHandler;
|
||||
Handler.Init();
|
||||
@ -56,6 +58,11 @@ namespace UnityExplorer.Core.Config
|
||||
KeyCode.F7,
|
||||
false);
|
||||
|
||||
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
|
||||
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
|
||||
true,
|
||||
false);
|
||||
|
||||
Default_Page_Limit = new ConfigElement<int>("Default Page Limit",
|
||||
"The default maximum number of elements per 'page' in UnityExplorer.",
|
||||
25,
|
||||
@ -102,25 +109,25 @@ namespace UnityExplorer.Core.Config
|
||||
private static void PanelDragger_OnFinishResize(RectTransform rect)
|
||||
{
|
||||
Last_Window_Anchors.Value = RectAnchorsToString(rect);
|
||||
Handler.SaveConfig();
|
||||
Handler.OnAnyConfigChanged();
|
||||
}
|
||||
|
||||
private static void MainMenu_OnActiveTabChanged(int page)
|
||||
{
|
||||
Last_Active_Tab.Value = page;
|
||||
Handler.SaveConfig();
|
||||
Handler.OnAnyConfigChanged();
|
||||
}
|
||||
|
||||
private static void DebugConsole_OnToggleShow(bool showing)
|
||||
{
|
||||
Last_DebugConsole_State.Value = showing;
|
||||
Handler.SaveConfig();
|
||||
Handler.OnAnyConfigChanged();
|
||||
}
|
||||
|
||||
private static void SceneExplorer_OnToggleShow(bool showing)
|
||||
{
|
||||
Last_SceneExplorer_State.Value = showing;
|
||||
Handler.SaveConfig();
|
||||
Handler.OnAnyConfigChanged();
|
||||
}
|
||||
|
||||
// Window Anchors helpers
|
||||
|
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Core.Config
|
||||
{
|
||||
public interface IConfigHandler
|
||||
{
|
||||
void RegisterConfigElement<T>(ConfigElement<T> element);
|
||||
|
||||
void SetConfigValue<T>(ConfigElement<T> element, T value);
|
||||
|
||||
T GetConfigValue<T>(ConfigElement<T> element);
|
||||
|
||||
void Init();
|
||||
|
||||
void LoadConfig();
|
||||
|
||||
void SaveConfig();
|
||||
}
|
||||
}
|
@ -17,20 +17,18 @@ namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public class CursorUnlocker
|
||||
{
|
||||
//public static bool Unlock
|
||||
//{
|
||||
// get => m_forceUnlock;
|
||||
// set => SetForceUnlock(value);
|
||||
//}
|
||||
//private static bool m_forceUnlock;
|
||||
public static bool Unlock
|
||||
{
|
||||
get => m_forceUnlock;
|
||||
set
|
||||
{
|
||||
m_forceUnlock = value;
|
||||
UpdateCursorControl();
|
||||
}
|
||||
}
|
||||
private static bool m_forceUnlock;
|
||||
|
||||
//private static void SetForceUnlock(bool unlock)
|
||||
//{
|
||||
// m_forceUnlock = unlock;
|
||||
// UpdateCursorControl();
|
||||
//}
|
||||
|
||||
//public static bool ShouldForceMouse => UIManager.ShowMenu && Unlock;
|
||||
public static bool ShouldActuallyUnlock => UIManager.ShowMenu && Unlock;
|
||||
|
||||
private static CursorLockMode m_lastLockMode;
|
||||
private static bool m_lastVisibleState;
|
||||
@ -48,7 +46,8 @@ namespace UnityExplorer.Core.Input
|
||||
|
||||
UpdateCursorControl();
|
||||
|
||||
//Unlock = true;
|
||||
Unlock = true;
|
||||
ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; };
|
||||
}
|
||||
|
||||
private static void SetupPatches()
|
||||
@ -122,7 +121,7 @@ namespace UnityExplorer.Core.Input
|
||||
try
|
||||
{
|
||||
m_currentlySettingCursor = true;
|
||||
if (UIManager.ShowMenu)
|
||||
if (ShouldActuallyUnlock)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
@ -196,10 +195,8 @@ namespace UnityExplorer.Core.Input
|
||||
m_lastEventSystem = value;
|
||||
m_lastInputModule = value?.currentInputModule;
|
||||
|
||||
if (UIManager.ShowMenu)
|
||||
{
|
||||
if (ShouldActuallyUnlock)
|
||||
value = UIManager.EventSys;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,10 +211,8 @@ namespace UnityExplorer.Core.Input
|
||||
{
|
||||
m_lastLockMode = value;
|
||||
|
||||
if (UIManager.ShowMenu)
|
||||
{
|
||||
if (ShouldActuallyUnlock)
|
||||
value = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,10 +223,8 @@ namespace UnityExplorer.Core.Input
|
||||
{
|
||||
m_lastVisibleState = value;
|
||||
|
||||
if (UIManager.ShowMenu)
|
||||
{
|
||||
if (ShouldActuallyUnlock)
|
||||
value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,18 +8,18 @@ using UnityExplorer.Core.Config;
|
||||
|
||||
namespace UnityExplorer.Loader.BIE
|
||||
{
|
||||
public class BepInExConfigHandler : IConfigHandler
|
||||
public class BepInExConfigHandler : ConfigHandler
|
||||
{
|
||||
private ConfigFile Config => ExplorerBepInPlugin.Instance.Config;
|
||||
|
||||
private const string CTG_NAME = "UnityExplorer";
|
||||
|
||||
public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
// Not necessary
|
||||
}
|
||||
|
||||
public void RegisterConfigElement<T>(ConfigElement<T> config)
|
||||
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
||||
{
|
||||
var entry = Config.Bind(CTG_NAME, config.Name, config.Value, config.Description);
|
||||
|
||||
@ -29,7 +29,7 @@ namespace UnityExplorer.Loader.BIE
|
||||
};
|
||||
}
|
||||
|
||||
public T GetConfigValue<T>(ConfigElement<T> element)
|
||||
public override T GetConfigValue<T>(ConfigElement<T> element)
|
||||
{
|
||||
if (Config.TryGetEntry(CTG_NAME, element.Name, out ConfigEntry<T> configEntry))
|
||||
return configEntry.Value;
|
||||
@ -37,7 +37,7 @@ namespace UnityExplorer.Loader.BIE
|
||||
throw new Exception("Could not get config entry '" + element.Name + "'");
|
||||
}
|
||||
|
||||
public void SetConfigValue<T>(ConfigElement<T> element, T value)
|
||||
public override void SetConfigValue<T>(ConfigElement<T> element, T value)
|
||||
{
|
||||
if (Config.TryGetEntry(CTG_NAME, element.Name, out ConfigEntry<T> configEntry))
|
||||
configEntry.Value = value;
|
||||
@ -45,7 +45,7 @@ namespace UnityExplorer.Loader.BIE
|
||||
ExplorerCore.Log("Could not get config entry '" + element.Name + "'");
|
||||
}
|
||||
|
||||
public void LoadConfig()
|
||||
public override void LoadConfig()
|
||||
{
|
||||
foreach (var entry in ConfigManager.ConfigElements)
|
||||
{
|
||||
@ -59,7 +59,7 @@ namespace UnityExplorer.Loader.BIE
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
public override void SaveConfig()
|
||||
{
|
||||
// not required
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace UnityExplorer
|
||||
=> Log;
|
||||
#endif
|
||||
|
||||
public IConfigHandler ConfigHandler => _configHandler;
|
||||
public ConfigHandler ConfigHandler => _configHandler;
|
||||
private BepInExConfigHandler _configHandler;
|
||||
|
||||
public Harmony HarmonyInstance => s_harmony;
|
||||
|
@ -11,7 +11,7 @@ namespace UnityExplorer
|
||||
string ExplorerFolder { get; }
|
||||
|
||||
string ConfigFolder { get; }
|
||||
IConfigHandler ConfigHandler { get; }
|
||||
ConfigHandler ConfigHandler { get; }
|
||||
|
||||
Action<object> OnLogMessage { get; }
|
||||
Action<object> OnLogWarning { get; }
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
using UnityExplorer;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Loader.ML;
|
||||
@ -18,7 +19,7 @@ namespace UnityExplorer
|
||||
public string ExplorerFolder => Path.Combine("Mods", ExplorerCore.NAME);
|
||||
public string ConfigFolder => ExplorerFolder;
|
||||
|
||||
public IConfigHandler ConfigHandler => _configHandler;
|
||||
public ConfigHandler ConfigHandler => _configHandler;
|
||||
public MelonLoaderConfigHandler _configHandler;
|
||||
|
||||
public Action<object> OnLogMessage => MelonLogger.Msg;
|
||||
|
@ -10,20 +10,20 @@ using UnityExplorer.Core.Config;
|
||||
|
||||
namespace UnityExplorer.Loader.ML
|
||||
{
|
||||
public class MelonLoaderConfigHandler : IConfigHandler
|
||||
public class MelonLoaderConfigHandler : ConfigHandler
|
||||
{
|
||||
internal const string CTG_NAME = "UnityExplorer";
|
||||
|
||||
internal MelonPreferences_Category prefCategory;
|
||||
|
||||
public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
|
||||
|
||||
MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter);
|
||||
}
|
||||
|
||||
public void LoadConfig()
|
||||
public override void LoadConfig()
|
||||
{
|
||||
foreach (var entry in ConfigManager.ConfigElements)
|
||||
{
|
||||
@ -36,7 +36,7 @@ namespace UnityExplorer.Loader.ML
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterConfigElement<T>(ConfigElement<T> config)
|
||||
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
||||
{
|
||||
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>;
|
||||
|
||||
@ -49,17 +49,16 @@ namespace UnityExplorer.Loader.ML
|
||||
};
|
||||
}
|
||||
|
||||
public void SetConfigValue<T>(ConfigElement<T> config, T value)
|
||||
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
|
||||
{
|
||||
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
||||
{
|
||||
entry.Value = value;
|
||||
entry.Save();
|
||||
MelonPreferences.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public T GetConfigValue<T>(ConfigElement<T> config)
|
||||
public override T GetConfigValue<T>(ConfigElement<T> config)
|
||||
{
|
||||
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
||||
return entry.Value;
|
||||
@ -67,9 +66,9 @@ namespace UnityExplorer.Loader.ML
|
||||
return default;
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
public override void SaveConfig()
|
||||
{
|
||||
// Not necessary
|
||||
MelonPreferences.Save();
|
||||
}
|
||||
|
||||
public static KeyCode KeycodeReader(TomlObject value)
|
||||
|
@ -48,8 +48,8 @@ namespace UnityExplorer
|
||||
public Harmony HarmonyInstance => s_harmony;
|
||||
public static readonly Harmony s_harmony = new Harmony(ExplorerCore.GUID);
|
||||
|
||||
public IConfigHandler ConfigHandler => _configHandler;
|
||||
private IConfigHandler _configHandler;
|
||||
public ConfigHandler ConfigHandler => _configHandler;
|
||||
private StandaloneConfigHandler _configHandler;
|
||||
|
||||
public string ExplorerFolder
|
||||
{
|
||||
|
@ -10,36 +10,36 @@ using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Loader.STANDALONE
|
||||
{
|
||||
public class StandaloneConfigHandler : IConfigHandler
|
||||
public class StandaloneConfigHandler : ConfigHandler
|
||||
{
|
||||
internal static IniDataParser _parser;
|
||||
internal static string INI_PATH;
|
||||
|
||||
public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
INI_PATH = Path.Combine(ExplorerCore.Loader.ConfigFolder, "config.ini");
|
||||
_parser = new IniDataParser();
|
||||
_parser.Configuration.CommentString = "#";
|
||||
}
|
||||
|
||||
public void LoadConfig()
|
||||
public override void LoadConfig()
|
||||
{
|
||||
if (!TryLoadConfig())
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public void RegisterConfigElement<T>(ConfigElement<T> element)
|
||||
public override void RegisterConfigElement<T>(ConfigElement<T> element)
|
||||
{
|
||||
// Not necessary
|
||||
}
|
||||
|
||||
public void SetConfigValue<T>(ConfigElement<T> element, T value)
|
||||
public override void SetConfigValue<T>(ConfigElement<T> element, T value)
|
||||
{
|
||||
// Not necessary, just save.
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public T GetConfigValue<T>(ConfigElement<T> element)
|
||||
public override T GetConfigValue<T>(ConfigElement<T> element)
|
||||
{
|
||||
// Not necessary, just return the value.
|
||||
return element.Value;
|
||||
@ -82,7 +82,12 @@ namespace UnityExplorer.Loader.STANDALONE
|
||||
return value;
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
public override void OnAnyConfigChanged()
|
||||
{
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public override void SaveConfig()
|
||||
{
|
||||
var data = new IniParser.Model.IniData();
|
||||
|
||||
|
@ -49,7 +49,7 @@ namespace UnityExplorer.UI.CacheObject
|
||||
public override void SetValue()
|
||||
{
|
||||
RefConfig.BoxedValue = IValue.Value;
|
||||
ConfigManager.Handler.SaveConfig();
|
||||
ConfigManager.Handler.OnAnyConfigChanged();
|
||||
}
|
||||
|
||||
internal GameObject m_leftGroup;
|
||||
@ -59,7 +59,9 @@ namespace UnityExplorer.UI.CacheObject
|
||||
{
|
||||
base.ConstructUI();
|
||||
|
||||
var horiGroup = UIFactory.CreateHorizontalGroup(m_mainContent, "ConfigEntryHolder", true, false, true, true, 5, new Vector4(2,2,2,2));
|
||||
var vertGroup = UIFactory.CreateVerticalGroup(m_mainContent, "ConfigHolder", true, false, true, true, 5, new Vector4(2, 2, 2, 2));
|
||||
|
||||
var horiGroup = UIFactory.CreateHorizontalGroup(vertGroup, "ConfigEntryHolder", true, false, true, true);
|
||||
UIFactory.SetLayoutElement(horiGroup, minHeight: 30, flexibleHeight: 0);
|
||||
|
||||
// left group
|
||||
@ -89,6 +91,12 @@ namespace UnityExplorer.UI.CacheObject
|
||||
IValue.m_mainContentParent = m_rightGroup;
|
||||
IValue.m_subContentParent = this.m_subContent;
|
||||
}
|
||||
|
||||
// Config description label
|
||||
|
||||
UIFactory.CreateLabel(vertGroup, "Description", $"<i>{RefConfig.Description}</i>", TextAnchor.MiddleLeft, Color.grey);
|
||||
|
||||
m_subContent.transform.SetAsLastSibling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,6 @@ namespace UnityExplorer.UI.Main.Options
|
||||
{
|
||||
ConstructUI();
|
||||
|
||||
_cachedConfigEntries.AddRange(ConfigManager.ConfigElements.Values
|
||||
.Where(it => !it.IsInternal)
|
||||
.Select(it => new CacheConfigEntry(it, m_contentObj)));
|
||||
|
||||
foreach (var entry in _cachedConfigEntries)
|
||||
entry.Enable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -51,14 +44,26 @@ namespace UnityExplorer.UI.Main.Options
|
||||
var titleLabel = UIFactory.CreateLabel(Content, "Title", "Options", TextAnchor.UpperLeft, default, true, 25);
|
||||
UIFactory.SetLayoutElement(titleLabel.gameObject, minHeight: 30, flexibleHeight: 0);
|
||||
|
||||
// Save button
|
||||
|
||||
var btn = UIFactory.CreateButton(Content,
|
||||
"SaveButton",
|
||||
"Save Config File",
|
||||
() => { ConfigManager.Handler.SaveConfig(); },
|
||||
new Color(0.25f, 0.6f, 0.25f));
|
||||
UIFactory.SetLayoutElement(btn.gameObject, flexibleWidth: 9999, minHeight: 30, flexibleHeight: 0);
|
||||
|
||||
// ~~~~~ Actual options ~~~~~
|
||||
|
||||
UIFactory.CreateScrollView(Content, "ConfigList", out m_contentObj, out _, new Color(0.05f, 0.05f, 0.05f));
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(m_contentObj, forceHeight: true, spacing: 3, padLeft: 3, padRight: 3);
|
||||
|
||||
//m_contentObj = UIFactory.CreateVerticalGroup(Content, "OptionsGroup", true, false, true, false, 5, new Vector4(5,5,5,5),
|
||||
// new Color(0.1f, 0.1f, 0.1f));
|
||||
//UIFactory.SetLayoutElement(m_contentObj, minHeight: 340, flexibleHeight: 9999);
|
||||
_cachedConfigEntries.AddRange(ConfigManager.ConfigElements.Values
|
||||
.Where(it => !it.IsInternal)
|
||||
.Select(it => new CacheConfigEntry(it, m_contentObj)));
|
||||
|
||||
foreach (var entry in _cachedConfigEntries)
|
||||
entry.Enable();
|
||||
}
|
||||
|
||||
|
||||
|
@ -218,7 +218,7 @@
|
||||
<Compile Include="Core\Config\ConfigElement.cs" />
|
||||
<Compile Include="Core\Config\ConfigManager.cs" />
|
||||
<Compile Include="Core\Config\IConfigElement.cs" />
|
||||
<Compile Include="Core\Config\IConfigHandler.cs" />
|
||||
<Compile Include="Core\Config\ConfigHandler.cs" />
|
||||
<Compile Include="Core\CSharp\DummyBehaviour.cs" />
|
||||
<Compile Include="Core\CSharp\ScriptEvaluator.cs" />
|
||||
<Compile Include="Core\CSharp\ScriptInteraction.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user