Skip to content

Commit

Permalink
Update ConfigurationManagerAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Mar 7, 2023
1 parent 7a8eeaa commit b187d5f
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions src/Shared.Core/Utilities/ConfigurationManagerAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace KKAPI.Utilities
/// Class that specifies how a setting should be displayed inside the ConfigurationManager settings window.
///
/// Usage:
/// You can use this copy of the class instead of including it in your own plugin.
/// Make a new instance, assign any fields that you want to override, and pass it as a tag for your setting.
/// This class template has to be copied inside the plugin's project and referenced by its code directly.
/// make a new instance, assign any fields that you want to override, and pass it as a tag for your setting.
///
/// If a field is null (default), it will be ignored and won't change how the setting is displayed.
/// If a field is non-null (you assigned a value to it), it will override default behavior.
Expand All @@ -20,10 +20,10 @@ namespace KKAPI.Utilities
/// Here's an example of overriding order of settings and marking one of the settings as advanced:
/// <code>
/// // Override IsAdvanced and Order
/// Config.AddSetting("X", "1", 1, new ConfigDescription("", null, new ConfigurationManagerAttributes { IsAdvanced = true, Order = 3 }));
/// Config.Bind("X", "1", 1, new ConfigDescription("", null, new ConfigurationManagerAttributes { IsAdvanced = true, Order = 3 }));
/// // Override only Order, IsAdvanced stays as the default value assigned by ConfigManager
/// Config.AddSetting("X", "2", 2, new ConfigDescription("", null, new ConfigurationManagerAttributes { Order = 1 }));
/// Config.AddSetting("X", "3", 3, new ConfigDescription("", null, new ConfigurationManagerAttributes { Order = 2 }));
/// Config.Bind("X", "2", 2, new ConfigDescription("", null, new ConfigurationManagerAttributes { Order = 1 }));
/// Config.Bind("X", "3", 3, new ConfigDescription("", null, new ConfigurationManagerAttributes { Order = 2 }));
/// </code>
/// </example>
///
Expand All @@ -42,7 +42,53 @@ public sealed class ConfigurationManagerAttributes
/// Custom setting editor (OnGUI code that replaces the default editor provided by ConfigurationManager).
/// See below for a deeper explanation. Using a custom drawer will cause many of the other fields to do nothing.
/// </summary>
public Action<ConfigEntryBase> CustomDrawer;
public System.Action<BepInEx.Configuration.ConfigEntryBase> CustomDrawer;

/// <summary>
/// Custom setting editor that allows polling keyboard input with the Input (or UnityInput) class.
/// Use either CustomDrawer or CustomHotkeyDrawer, using both at the same time leads to undefined behaviour.
/// </summary>
public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

/// <summary>
/// Custom setting draw action that allows polling keyboard input with the Input class.
/// Note: Make sure to focus on your UI control when you are accepting input so user doesn't type in the search box or in another setting (best to do this on every frame).
/// If you don't draw any selectable UI controls You can use `GUIUtility.keyboardControl = -1;` on every frame to make sure that nothing is selected.
/// </summary>
/// <example>
/// CustomHotkeyDrawer = (ConfigEntryBase setting, ref bool isEditing) =>
/// {
/// if (isEditing)
/// {
/// // Make sure nothing else is selected since we aren't focusing on a text box with GUI.FocusControl.
/// GUIUtility.keyboardControl = -1;
///
/// // Use Input.GetKeyDown and others here, remember to set isEditing to false after you're done!
/// // It's best to check Input.anyKeyDown and set isEditing to false immediately if it's true,
/// // so that the input doesn't have a chance to propagate to the game itself.
///
/// if (GUILayout.Button("Stop"))
/// isEditing = false;
/// }
/// else
/// {
/// if (GUILayout.Button("Start"))
/// isEditing = true;
/// }
///
/// // This will only be true when isEditing is true and you hold any key
/// GUILayout.Label("Any key pressed: " + Input.anyKey);
/// }
/// </example>
/// <param name="setting">
/// Setting currently being set (if available).
/// </param>
/// <param name="isCurrentlyAcceptingInput">
/// Set this ref parameter to true when you want the current setting drawer to receive Input events.
/// The value will persist after being set, use it to see if the current instance is being edited.
/// Remember to set it to false after you are done!
/// </param>
public delegate void CustomHotkeyDrawerFunc(BepInEx.Configuration.ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

/// <summary>
/// Show this setting in the settings screen at all? If false, don't show.
Expand Down Expand Up @@ -100,11 +146,11 @@ public sealed class ConfigurationManagerAttributes
/// <summary>
/// Custom converter from setting type to string for the built-in editor textboxes.
/// </summary>
public Func<object, string> ObjToStr;
public System.Func<object, string> ObjToStr;

/// <summary>
/// Custom converter from string to setting type for the built-in editor textboxes.
/// </summary>
public Func<string, object> StrToObj;
public System.Func<string, object> StrToObj;
}
}

0 comments on commit b187d5f

Please sign in to comment.