Esempio n. 1
0
        private static void LoadModConfigMenuElements()
        {
            IGenericModConfigMenuAPI gmcm = Helper.ModRegistry.GetApi <IGenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu");

            if (gmcm == null)
            {
                return;
            }

            gmcm.RegisterModConfig(ModEntry.Instance.ModManifest, () => ModEntry.Config = new Config(), () => Helper.WriteConfig(ModEntry.Config));
            gmcm.SubscribeToChange(ModManifest,
                                   changeHandler: (string key, bool value) =>
            {
                Log.D($"Config check: {key} => {value}",
                      ModEntry.Config.DebugMode);

                if (key == i18n.Get($"config.option.{"AddNewCropsAndStuff".ToLower()}_name") &&
                    Helper.ModRegistry.IsLoaded("blueberry.CommunityKitchen"))
                {
                    // Show warning when using
                    Log.W("Changes to Community Kitchen bundles won't be applied until you reopen the game.");
                }
            });

            string[] entries = new[]
            {
                "features",

                "AddCookingMenu",
                "AddCookingSkillAndRecipes",
                "AddCookingToolProgression",
                //"AddCookingQuestline",
                "AddNewCropsAndStuff",

                "changes",

                "PlayCookingAnimation",
                "AddRecipeRebalancing",
                "AddBuffReassigning",
                "HideFoodBuffsUntilEaten",
                "FoodHealingTakesTime",
                "FoodCanBurn",

                "others",

                "ShowFoodRegenBar",
                "RememberLastSearchFilter",
                "DefaultSearchFilter",
                "ResizeKoreanFonts",
            };
            foreach (string entry in entries)
            {
                BindingFlags flags    = BindingFlags.Public | BindingFlags.Instance;
                PropertyInfo property = typeof(Config).GetProperty(entry, flags);
                if (property != null)
                {
                    string i18nKey = $"config.option.{entry.ToLower()}_";
                    if (property.PropertyType == typeof(bool))
                    {
                        gmcm.RegisterSimpleOption(
                            ModManifest,
                            optionName: i18n.Get(i18nKey + "name"),
                            optionDesc: i18n.Get(i18nKey + "description"),
                            optionGet: () => (bool)property.GetValue(ModEntry.Config),
                            optionSet: (bool value) =>
                        {
                            Log.D($"Config edit: {property.Name} - {property.GetValue(ModEntry.Config)} => {value}",
                                  ModEntry.Config.DebugMode);
                            property.SetValue(ModEntry.Config, value);
                        });
                    }
                    else if (property.Name == "DefaultSearchFilter")
                    {
                        gmcm.RegisterChoiceOption(
                            ModManifest,
                            optionName: i18n.Get(i18nKey + "name"),
                            optionDesc: i18n.Get(i18nKey + "description"),
                            optionGet: () => (string)property.GetValue(ModEntry.Config),
                            optionSet: (string value) => property.SetValue(ModEntry.Config, value),
                            choices: Enum.GetNames(typeof(Objects.CookingMenu.Filter)));
                    }
                }
                else
                {
                    string i18nKey = $"config.{entry}_";
                    gmcm.RegisterLabel(
                        ModManifest,
                        labelName: i18n.Get(i18nKey + "label"),
                        labelDesc: null);
                }
            }
        }