Skip to content

Commit

Permalink
Use alternate method of early config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrain committed Jan 20, 2024
1 parent d161053 commit 2c7d198
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Changelog

## 1.0.3 (2024-01-19)
- Switched to an alternate method for loading configuration options early since the intro sequence hook ended up breaking things

## 1.0.2 (2024-01-19)
- Added hook to make sure default values for configuration options are loaded earlier in the intro sequence (before quickstarting or entering the Breach)

## 1.0.1 (2023-12-20)
- Simplify logic for "Auto-fire Semi-Automatic Weapons" hook to fix compatibility issues with GungeonCraft and other mods
- Simplified logic for "Auto-fire Semi-Automatic Weapons" hook to fix compatibility issues with GungeonCraft and other mods

## 1.0.0 (2023-12-17)
- Initial Release! :D
8 changes: 4 additions & 4 deletions src/Gunfig/GunfigAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Gunfig Get(string modName)
/// <param name="updateType">Determines when changes to the option are applied. See <see cref="Gunfig.Update"/> documentation for descriptions of each option.</param>
public void AddToggle(string key, bool enabled = false, string label = null, Action<string, string> callback = null, Gunfig.Update updateType = Gunfig.Update.OnConfirm)
{
this._registeredOptions.Add(new Item(){
RegisterOption(new Item(){
_itemType = ItemType.CheckBox,
_updateType = updateType,
_key = key,
Expand All @@ -105,7 +105,7 @@ public void AddToggle(string key, bool enabled = false, string label = null, Act
/// <param name="updateType">Determines when changes to the option are applied. See <see cref="Gunfig.Update"/> documentation for descriptions of each option.</param>
public void AddScrollBox(string key, List<string> options, string label = null, Action<string, string> callback = null, List<string> info = null, Gunfig.Update updateType = Gunfig.Update.OnConfirm)
{
this._registeredOptions.Add(new Item(){
RegisterOption(new Item(){
_itemType = ItemType.ArrowBox,
_updateType = updateType,
_key = key,
Expand All @@ -126,7 +126,7 @@ public void AddScrollBox(string key, List<string> options, string label = null,
/// The callback's second argument will always be "1", and is only set for compatibility with other option callbacks.</param>
public void AddButton(string key, string label = null, Action<string, string> callback = null)
{
this._registeredOptions.Add(new Item(){
RegisterOption(new Item(){
_itemType = ItemType.Button,
_updateType = Gunfig.Update.Immediate,
_key = key,
Expand All @@ -142,7 +142,7 @@ public void AddButton(string key, string label = null, Action<string, string> ca
/// <param name="label">The text displayed for the label on the config page. Can be colorized using <see cref="WithColor()"/>.</param>
public void AddLabel(string label)
{
this._registeredOptions.Add(new Item(){
RegisterOption(new Item(){
_itemType = ItemType.Label,
_updateType = Gunfig.Update.Immediate,
_key = $"{label} label",
Expand Down
14 changes: 0 additions & 14 deletions src/Gunfig/GunfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ internal static void Init()
// typeof(MenuMaster).GetMethod("ReturnToPreOptionsMenu", BindingFlags.Static | BindingFlags.NonPublic)
// );

// Make sure our configurations are loaded before we reach the main menu
new Hook(
typeof(Foyer).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic),
typeof(GunfigMenu).GetMethod("OnFoyerAwake", BindingFlags.Static | BindingFlags.NonPublic)
);

// Make sure our menus are loaded in the main menu
new Hook(
typeof(MainMenuFoyerController).GetMethod("InitializeMainMenu", BindingFlags.Instance | BindingFlags.Public),
Expand Down Expand Up @@ -104,14 +98,6 @@ internal static void Init()
// orig(pm);
// }

private static void OnFoyerAwake(Action<Foyer> orig, Foyer f)
{
if (GameUIRoot.Instance.PauseMenuPanel.GetComponent<PauseMenuController>().OptionsMenu.PreOptionsMenu is PreOptionsMenuController preOptions)
if (!preOptions.m_panel.Find<dfButton>(_MOD_MENU_LABEL))
RebuildOptionsPanels();
orig(f);
}

private static void InitializeMainMenu(Action<MainMenuFoyerController> orig, MainMenuFoyerController mm)
{
if (GameUIRoot.Instance.PauseMenuPanel.GetComponent<PauseMenuController>().OptionsMenu.PreOptionsMenu is PreOptionsMenuController preOptions)
Expand Down
9 changes: 9 additions & 0 deletions src/Gunfig/GunfigPrivateAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ private void SaveToDisk()
}
}

private void RegisterOption(Item item)
{
this._registeredOptions.Add(item);
if (item._itemType != ItemType.CheckBox && item._itemType != ItemType.ArrowBox)
return;
if (this.Value(item._key) == null) // make sure we have a default value for all loaded configuration options
this.Set(item._key, item._values[0]);
}

internal dfScrollPanel RegenConfigPage()
{
dfScrollPanel subOptionsPanel = GunfigMenu.NewOptionsPanel($"{this._modName}");
Expand Down
2 changes: 1 addition & 1 deletion src/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class C // constants

public const string MOD_NAME = "Gunfig";
public const string MOD_INT_NAME = "Gunfiguration";
public const string MOD_VERSION = "1.0.2";
public const string MOD_VERSION = "1.0.3";
public const string MOD_GUID = "pretzel.etg.gunfig";
public const string MOD_PREFIX = "gf";

Expand Down

0 comments on commit 2c7d198

Please sign in to comment.