Пример #1
0
    private static void AddCategories()
    {
        var prefs = MelonPreferences.Categories;

        int buttonIndex = 0;

        Il2CppGeneric.List <GameObject> row = new Il2CppGeneric.List <GameObject>();
        foreach (var category in prefs)
        {
            var categoryButton = modMenuOM.AddButton(buttonIndex % 2,
                                                     AddWhitespace(category.DisplayName),
                                                     new Action(() => { CreateCategoryPage(category); }),
                                                     null,
                                                     "");
            buttonIndex++;
            row.Add(categoryButton.gameObject);
            if (row.Count == 2)
            {
                //This is the dumbest code I've ever wrote.
                Il2CppGeneric.List <GameObject> tempRow = new Il2CppGeneric.List <GameObject>();
                tempRow.Add(row[0]);
                tempRow.Add(row[1]);
                modMenuOM.scrollable.AddRow(tempRow);
                row.Clear();
            }
        }
        if (row.Count == 1) //If the last row is missing a pair, add a row with a single object.
        {
            modMenuOM.scrollable.AddRow(row[0]);
            row.Clear();
        }
    }
Пример #2
0
    private static void CreateCategoryPage(MelonPreferences_Category category)
    {
        WipeScroller();
        displayState = DisplayState.Prefs;
        var categoryHeader = modMenuOM.AddHeader(0, category.DisplayName);

        modMenuOM.scrollable.AddRow(categoryHeader);

        int buttonIndex = 0;

        Il2CppGeneric.List <GameObject> row = new Il2CppGeneric.List <GameObject>();
        foreach (var pref in category.Entries)
        {
            switch (pref.BoxedValue)
            {
            case int value:
                MinMaxStepDefaultInt rangesInt = ParseMinMaxStepInt(pref.DisplayName);
                if (rangesInt.Equals(default(MinMaxStepDefaultInt)))
                {
                    break;
                }
                var intSlider = modMenuOM.AddSlider(buttonIndex % 2,
                                                    AddWhitespace(pref.Identifier),
                                                    null,
                                                    new Action <float>((amount) =>
                {
                    int currentVal = MelonPreferences.GetEntryValue <int>(pref.Category.Identifier, pref.Identifier);
                    int increment  = (int)amount * rangesInt.step;
                    int newVal     = currentVal + increment;
                    if (newVal > rangesInt.max)
                    {
                        MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, rangesInt.max);
                    }
                    else if (newVal < rangesInt.min)
                    {
                        MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, rangesInt.min);
                    }
                    else
                    {
                        MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, newVal);
                    }
                }),
                                                    new Func <float>(() => { return(MelonPreferences.GetEntryValue <int>(pref.Category.Identifier, pref.Identifier)); }),
                                                    new Action(() => { MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, rangesInt.prefDefault); }),
                                                    RemoveTags(pref.DisplayName),
                                                    new Func <float, string>((amount) => { return(amount.ToString()); }));
                buttonIndex++;
                row.Add(intSlider.gameObject);
                break;

            case bool value:
                var checkbox = modMenuOM.AddButton(buttonIndex % 2,
                                                   AddWhitespace(pref.Identifier),
                                                   new Action(() =>
                {
                    bool currentVal = MelonPreferences.GetEntryValue <bool>(pref.Category.Identifier, pref.Identifier);
                    MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, !currentVal);
                }),
                                                   new Func <bool>(() => { return(MelonPreferences.GetEntryValue <bool>(pref.Category.Identifier, pref.Identifier)); }),
                                                   pref.DisplayName);

                row.Add(checkbox.gameObject);
                buttonIndex++;
                break;

            case float value:
                MinMaxStepDefault rangesFloat = ParseMinMaxStep(pref.DisplayName);
                if (rangesFloat.Equals(default(MinMaxStepDefault)))
                {
                    break;
                }
                var customSpecifier = GetFormatSpecifier(pref.DisplayName);
                if (customSpecifier == "")
                {
                    customSpecifier = "N2";                            //Default to N2 if specifier is missing
                }
                var floatSlider = modMenuOM.AddSlider(buttonIndex % 2,
                                                      AddWhitespace(pref.Identifier),
                                                      "N2",
                                                      new Action <float>((amount) =>
                {
                    float currentVal = MelonPreferences.GetEntryValue <float>(pref.Category.Identifier, pref.Identifier);
                    float increment  = rangesFloat.step * amount;        //(amount * Mathf.Floor(currentVal * 10f));
                    float newVal     = currentVal + increment;
                    if (newVal > rangesFloat.max)
                    {
                        MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, rangesFloat.max);
                    }
                    else if (newVal < rangesFloat.min)
                    {
                        MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, rangesFloat.min);
                    }
                    else
                    {
                        MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, currentVal + increment);
                    }
                }),
                                                      new Func <float>(() => { return(MelonPreferences.GetEntryValue <float>(pref.Category.Identifier, pref.Identifier)); }),
                                                      new Action(() => { MelonPreferences.SetEntryValue(pref.Category.Identifier, pref.Identifier, rangesFloat.prefDefault); }),
                                                      RemoveTags(pref.DisplayName),
                                                      new Func <float, string>((amount) => { return(amount.ToString(customSpecifier)); }));
                row.Add(floatSlider.gameObject);
                buttonIndex++;
                break;

            case string value:
                if (pref.DisplayName.ToLower().Contains("[header]"))
                {
                    if (row.Count == 1)
                    {
                        modMenuOM.scrollable.AddRow(row[0]);
                        row.Clear();
                    }
                    var header = modMenuOM.AddHeader(0, RemoveTags(pref.DisplayName));
                    modMenuOM.scrollable.AddRow(header);
                    buttonIndex = 0;
                }
                break;

            default:
                break;
            }
            if (row.Count == 2)
            {
                //This is the dumbest code I've ever wrote.
                Il2CppGeneric.List <GameObject> tempRow = new Il2CppGeneric.List <GameObject>();
                tempRow.Add(row[0]);
                tempRow.Add(row[1]);
                modMenuOM.scrollable.AddRow(tempRow);
                row.Clear();
            }
            else if (buttonIndex == category.Entries.Count && buttonIndex % 2 == 1) // This might be obsolete
            {
                modMenuOM.scrollable.AddRow(row[0]);
                row.Clear();
            }
        }
    }