Skip to content

Commit

Permalink
Merge pull request #516 from ow-mods/dev
Browse files Browse the repository at this point in the history
Some menu fixes/improvements, and deprecate ModHelper.Events
  • Loading branch information
misternebula authored Dec 1, 2022
2 parents 3ef0fb7 + 1c63c42 commit 000e3b3
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/content/pages/guides/mod_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ public class MyMod : ModBehaviour {
}
}
```

## Config Updates

Something important to note is that when the manager pulls and update for your mod, the `config.json` file is preserved. The issue with this is menus are generated from the `config.json` file. When changing options like slider minimums and maximums or choices, you may want to create a new property rather than edit an existing one to make sure the UI is correct.
5 changes: 5 additions & 0 deletions src/OWML.Common/Interfaces/IModEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@

namespace OWML.Common
{
[Obsolete("Use HarmonyHelper instead.")]
public interface IModEvents
{
[Obsolete("Use HarmonyHelper instead.")]
IModPlayerEvents Player { get; }

[Obsolete("Use HarmonyHelper instead.")]
IModSceneEvents Scenes { get; }

[Obsolete("Use HarmonyHelper instead.")]
IModUnityEvents Unity { get; }

[Obsolete("Use HarmonyHelper instead.")]
event Action<MonoBehaviour, Events> Event;

[Obsolete("Use Event instead.")]
Expand Down
1 change: 1 addition & 0 deletions src/OWML.Common/Interfaces/IModPlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace OWML.Common
{
public interface IModPlayerEvents
{
[Obsolete("Use HarmonyHelper instead.")]
event Action<PlayerBody> OnPlayerAwake;

void Init(IModEvents events);
Expand Down
2 changes: 2 additions & 0 deletions src/OWML.Common/Interfaces/IModSceneEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ namespace OWML.Common
{
public interface IModSceneEvents
{
[Obsolete("Use HarmonyHelper instead.")]
event Action<OWScene, OWScene> OnStartSceneChange;

[Obsolete("Use HarmonyHelper instead.")]
event Action<OWScene, OWScene> OnCompleteSceneChange;
}
}
3 changes: 3 additions & 0 deletions src/OWML.Common/Interfaces/IModUnityEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ namespace OWML.Common
{
public interface IModUnityEvents
{
[Obsolete("Use HarmonyHelper instead.")]
event Action OnUpdate;

[Obsolete("Use HarmonyHelper instead.")]
event Action OnFixedUpdate;

[Obsolete("Use HarmonyHelper instead.")]
event Action OnLateUpdate;

void FireOnNextUpdate(Action action);
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Alek",
"name": "OWML",
"uniqueName": "Alek.OWML",
"version": "2.7.5",
"version": "2.8.0",
"minGameVersion": "1.1.13.393",
"maxGameVersion": "1.1.13.456"
}
6 changes: 6 additions & 0 deletions src/OWML.ModHelper.Events/ModEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

namespace OWML.ModHelper.Events
{
[Obsolete("Use HarmonyHelper instead.")]
public class ModEvents : IModEvents
{
[Obsolete("Use HarmonyHelper instead.")]
public IModPlayerEvents Player { get; }

[Obsolete("Use HarmonyHelper instead.")]
public IModSceneEvents Scenes { get; }

[Obsolete("Use HarmonyHelper instead.")]
public IModUnityEvents Unity { get; }

[Obsolete("Use HarmonyHelper instead.")]
public event Action<MonoBehaviour, Common.Events> Event;

[Obsolete("Use Event instead.")]
Expand Down Expand Up @@ -57,6 +62,7 @@ private void OnPatchEvent(MonoBehaviour behaviour, Common.Events ev)
}
}

[Obsolete("Use HarmonyHelper instead.")]
public void Subscribe<T>(Common.Events ev) where T : MonoBehaviour
{
SubscribeToEvent<T>(ev);
Expand Down
1 change: 1 addition & 0 deletions src/OWML.ModHelper.Events/ModPlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace OWML.ModHelper.Events
{
public class ModPlayerEvents : IModPlayerEvents
{
[Obsolete("Use HarmonyHelper instead.")]
public event Action<PlayerBody> OnPlayerAwake;

public void Init(IModEvents events)
Expand Down
2 changes: 2 additions & 0 deletions src/OWML.ModHelper.Events/ModSceneEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace OWML.ModHelper.Events
{
public class ModSceneEvents : IModSceneEvents
{
[Obsolete("Use HarmonyHelper instead.")]
public event Action<OWScene, OWScene> OnStartSceneChange;
[Obsolete("Use HarmonyHelper instead.")]
public event Action<OWScene, OWScene> OnCompleteSceneChange;

public ModSceneEvents()
Expand Down
3 changes: 3 additions & 0 deletions src/OWML.ModHelper.Events/ModUnityEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ namespace OWML.ModHelper.Events
{
public class ModUnityEvents : MonoBehaviour, IModUnityEvents
{
[Obsolete("Use HarmonyHelper instead.")]
public event Action OnUpdate;

[Obsolete("Use HarmonyHelper instead.")]
public event Action OnFixedUpdate;

[Obsolete("Use HarmonyHelper instead.")]
public event Action OnLateUpdate;

public void FireOnNextUpdate(Action action) =>
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.ModHelper.Menus/ModConfigMenuBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void AddSeparator(string key, int index, JObject obj)
separator.Show();
}

private void SetupInputTooltip<T>(IModInput<T> input, string tooltip)
internal void SetupInputTooltip<T>(IModInput<T> input, string tooltip)
{
var menuOption = input.Element.GetComponent<MenuOption>();
menuOption.SetValue("_tooltipTextType", UITextType.None);
Expand Down
20 changes: 18 additions & 2 deletions src/OWML.ModHelper.Menus/OwmlConfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ namespace OWML.ModHelper.Menus
public class OwmlConfigMenu : ModConfigMenuBase
{
private const string DebugModeTitle = "Debug mode";
private const string DebugModeTooltip = "Enable verbose logging. Some effects only enable/disable when game is reloaded.";
private const string ForceExeTitle = "Force run through .exe";
private const string ForceExeTooltip = "Force OWML to run the game's exe, rather than going through Steam/Epic.";
private const string IncrementalGCTitle = "Enable incremental GC";
private const string IncrementalGCTooltip = "Incremental GC (garbage collection) can help reduce lag spikes with some mods. Only has effect after game is reloaded.";

private readonly IOwmlConfig _config;
private readonly IOwmlConfig _defaultConfig;
Expand All @@ -27,20 +31,31 @@ protected override void AddInputs()
{
AddConfigInput(DebugModeTitle, _config.DebugMode, 2);
AddConfigInput(ForceExeTitle, _config.ForceExe, 3);
AddConfigInput(IncrementalGCTitle, _config.IncrementalGC, 4);
UpdateNavigation();
SelectFirst();
}

public override void UpdateUIValues()
{
GetToggleInput(DebugModeTitle).Value = _config.DebugMode;
GetToggleInput(ForceExeTitle).Value = _config.ForceExe;
var debug = GetToggleInput(DebugModeTitle);
debug.Value = _config.DebugMode;
SetupInputTooltip(debug, DebugModeTooltip);

var exe = GetToggleInput(ForceExeTitle);
exe.Value = _config.ForceExe;
SetupInputTooltip(exe, ForceExeTooltip);

var gc = GetToggleInput(IncrementalGCTitle);
gc.Value = _config.IncrementalGC;
SetupInputTooltip(gc, IncrementalGCTooltip);
}

protected override void OnSave()
{
_config.DebugMode = GetInputValue<bool>(DebugModeTitle);
_config.ForceExe = GetInputValue<bool>(ForceExeTitle);
_config.IncrementalGC = GetInputValue<bool>(IncrementalGCTitle);
JsonHelper.SaveJsonObject($"{_config.OWMLPath}{Constants.OwmlConfigFileName}", _config);
Close();
}
Expand All @@ -50,6 +65,7 @@ protected override void OnReset()
_config.GamePath = _defaultConfig.GamePath;
_config.DebugMode = _defaultConfig.DebugMode;
_config.ForceExe = _defaultConfig.ForceExe;
_config.IncrementalGC = _defaultConfig.IncrementalGC;
UpdateUIValues();
}
}
Expand Down

0 comments on commit 000e3b3

Please sign in to comment.