Пример #1
0
        internal static void CreateMenu()
        {
            SubMenu            GeneralMenu       = SettingsUI.CreateSubMenu("Random Sabers");
            int                folderPathLength  = Plugin.SabersFolderPath.Length;
            BoolViewController enabledController = GeneralMenu.AddBool("Enable Random Sabers", "Random sabers on song startup. ");

            enabledController.GetValue += () => { return(PlayerPrefs.GetInt(PrefsModSection + PrefsModEnabled) == 1); };
            enabledController.SetValue += (val) => { PlayerPrefs.SetInt(PrefsModSection + PrefsModEnabled, val ? 1 : 0); if (!val)
                                                     {
                                                         CustomSaber.Plugin.LoadNewSaber(SelectedSaberOnStartup);
                                                     }
            };
            BoolViewController displaySelectedSaberController = GeneralMenu.AddBool("Display Selected Saber", "Displays the selected Saber's name when starting the song.");

            displaySelectedSaberController.GetValue += () => { return(PlayerPrefs.GetInt(PrefsModSection + PrefsDisplaySelectedSaberEnabled) == 1); };
            displaySelectedSaberController.SetValue += (val) => { PlayerPrefs.SetInt(PrefsModSection + PrefsDisplaySelectedSaberEnabled, val ? 1 : 0); };
            BoolViewController listsEnabledController = GeneralMenu.AddBool("Enable Saber Menus", "Enables secondary menus to add or remove sabers from the selection pool. Settings are saved even if the menus are turned off. ");

            listsEnabledController.GetValue += () => { return(PlayerPrefs.GetInt(PrefsModSection + PrefsModListsEnabled) == 1); };
            listsEnabledController.SetValue += (val) => { PlayerPrefs.SetInt(PrefsModSection + PrefsModListsEnabled, val ? 1 : 0); };
            SetAllController SetAllController = GeneralMenu.AddIntSetting <SetAllController>("Set All Sabers To ", "Turn all sabers on, off, or do nothing.");

            SetAllController.SetValues(0, 2, 1);
            SetAllController.GetValue += () => { return(0); };
            SetAllController.SetValue += (val) => {
                setAllValue = val;
                if (1 == val)
                {
                    for (int i = 0; i < Plugin.SaberCount; i++)
                    {
                        PlayerPrefs.SetInt(PrefsEnabledSabersSection + Plugin.GetSaberName(i), 1);
                        isSaberEnabled[Plugin.GetSaberName(i)] = true;
                    }
                }
                else if (2 == val)
                {
                    for (int i = 0; i < Plugin.SaberCount; i++)
                    {
                        PlayerPrefs.SetInt(PrefsEnabledSabersSection + Plugin.GetSaberName(i), 0);
                        isSaberEnabled[Plugin.GetSaberName(i)] = false;
                    }
                }
            };
            //Add option lists in groups of SabersPerMenu.
            if (1 == PlayerPrefs.GetInt(PrefsModSection + PrefsModListsEnabled))
            {
                int sabersCount = Plugin.SaberCount;
                //Console.WriteLine("------------------------------------Random Sabers Menu Setup-----------------------------------");
                int MenuCount = Mathf.CeilToInt((float)sabersCount / SabersPerMenu);
                //Console.WriteLine(sabersCount + " Sabers, " + MenuCount + " Menus. ");
                for (int i = 0; i < MenuCount; i++)
                {
                    int    startingSaberIndex = i * SabersPerMenu;
                    string menuName           = "Random Sabers (";
                    if (0 != i)
                    {
                        string StartSaberName    = Plugin.GetSaberName(startingSaberIndex);
                        string previousSabername = Plugin.GetSaberName(startingSaberIndex - 1);
                        string firstLetter       = StartSaberName.Substring(0, 1).ToUpper();
                        menuName += firstLetter;
                        if (previousSabername.Substring(0, 1).ToUpper() == firstLetter)
                        {
                            menuName += StartSaberName.Substring(1, 1).ToUpper();
                        }
                    }
                    else
                    {
                        menuName += Plugin.GetSaberName(startingSaberIndex).Substring(0, 1).ToUpper();
                    }
                    menuName += " - ";
                    menuName += Plugin.GetSaberName(Mathf.Min(sabersCount - 1, (i + 1) * SabersPerMenu)).Substring(0, 1).ToUpper();
                    menuName += ")";
                    //Console.WriteLine("Added Menu: " + menuName);
                    SubMenu subMenu = SettingsUI.CreateSubMenu(menuName);
                    for (int j = 0; j < SabersPerMenu && startingSaberIndex + j < sabersCount; j++)
                    {
                        string             saberName  = Plugin.GetSaberName(startingSaberIndex + j);
                        BoolViewController controller = subMenu.AddBool(saberName, "Add or remove " + saberName + " from the random sabers options. ");
                        controller.GetValue += () => {
                            if (1 == setAllValue)
                            {
                                return(true);
                            }
                            else if (2 == setAllValue)
                            {
                                return(false);
                            }
                            else
                            {
                                return(isSaberEnabled[saberName]);
                            }
                        };
                        controller.SetValue += (val) =>
                        {
                            isSaberEnabled[saberName] = val;
                            PlayerPrefs.SetInt(PrefsEnabledSabersSection + saberName, val ? 1 : 0);
                            //controller.ApplySettings();
                            Console.WriteLine("Set " + saberName + " to " + PlayerPrefs.GetInt(PrefsEnabledSabersSection + saberName));
                        };
                    }
                }
                //Console.WriteLine("------------------------------------Random Sabers Menu Setup-----------------------------------");
            }
        }