Example #1
0
        private void AddGenericModConfigMenu()
        {
            IGenericModConfigMenuAPI modconfigAPI = this.Helper.ModRegistry.GetApi <IGenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu");

            if (modconfigAPI != null)
            {
                modconfigAPI.RegisterModConfig(
                    mod: this.ModManifest,
                    revertToDefault: () => ModEntry.Config = new Config(),
                    saveToFile: () => this.Helper.WriteConfig(ModEntry.Config));
                modconfigAPI.SetDefaultIngameOptinValue(
                    mod: this.ModManifest,
                    optedIn: true);
                System.Reflection.PropertyInfo[] properties = ModEntry.Config
                                                              .GetType()
                                                              .GetProperties()
                                                              .Where(p => p.PropertyType == typeof(bool))
                                                              .ToArray();
                foreach (System.Reflection.PropertyInfo property in properties)
                {
                    string key         = property.Name.ToLower();
                    string description = Translations.GetTranslation($"config.{key}.description", defaultToNull: true);
                    modconfigAPI.RegisterSimpleOption(
                        mod: this.ModManifest,
                        optionName: Translations.GetTranslation($"config.{key}.name"),
                        optionDesc: string.IsNullOrWhiteSpace(description) ? null : description,
                        optionGet: () => (bool)property.GetValue(ModEntry.Config),
                        optionSet: (bool value) => property.SetValue(ModEntry.Config, value: value));
                }
            }
        }