BepInEx / BepInEx.ConfigurationManager

Plugin configuration manager for BepInEx
https://www.patreon.com/ManlyMarco
GNU Lesser General Public License v3.0
227 stars 54 forks source link

[Question] How to make my setting into a drop-down list, please? #68

Closed JoewAlabel closed 1 year ago

JoewAlabel commented 1 year ago

"Specify AcceptableValueList when creating your setting. If you use an enum you don't need to specify AcceptableValueList, all of the enum values will be shown. If you want to hide some values, you will have to use the attribute.

Note: You can add System.ComponentModel.DescriptionAttribute to your enum's items to override their displayed names. "

How I use with enum, please? I can not find any example of it.

The max I can get is list the enum but it not overrides the displayed names:

ENUM:

public enum ItemList 
    {
        [Description("Green Leaf")]
        GREEN_LEAF,

        [Description("Dry Leaf")]
        DRY_LEAF,

        [Description("-------------------------")]
        SEPARATOR,

        [Description("Pineapple")]
       TREE_PINEAPPLE_FRUIT,

        [Description("Apple")]
       TREE_APPLE_FRUIT,
    }

Bind:

public static ConfigEntry<string> AddItemName { get; set; }
AddItemName = this.Config.Bind("Utils",
                                "Item",
                                "Green Leaf",
                                new ConfigDescription("Add item - Key ALT + Insert", new AcceptableValueList<string>(Enum.GetNames(typeof(ItemList)))));

Thank you!!!

JoewAlabel commented 1 year ago

I found a way, thanks!!!

Solution:

Bind:

public static ConfigEntry<ItemList> AddItemName { get; set; }
AddItemName = this.Config.Bind("Utils",
                                  "Item",
                                  ItemList.GREEN_LEAF,
                                  "Add item - Key ALT + Insert");

And the same enum ;)