ShowYesNo() 개인적인 메소드

private ShowYesNo ( [ prompt ) : bool
prompt [
리턴 bool
예제 #1
0
        static MenuState ShowKeyList()
        {
            Refresh("Section {0}", currentSection);

            TextMenu   menu           = new TextMenu();
            TextOption optionBack     = menu.AddOption("B", "Back to sections");
            TextOption optionDefaults = menu.AddOption("D", "Use defaults");

            menu.AddSpacer();

            ConfigKey[] keys   = currentSection.GetKeys();
            int         maxLen = keys.Select(key => key.ToString().Length).Max();

            for (int i = 0; i < keys.Length; i++)
            {
                string str = String.Format("{0} = {1}",
                                           keys[i].ToString().PadLeft(maxLen, '.'),
                                           keys[i].GetPresentationString());
                TextOption option = new TextOption((i + 1).ToString(CultureInfo.InvariantCulture),
                                                   str,
                                                   Column.Left);
                if (!keys[i].IsDefault())
                {
                    option.ForeColor = ConsoleColor.White;
                }
                option.Tag = keys[i];
                menu.AddOption(option);
            }

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.SectionList);
            }
            else if (choice == optionDefaults)
            {
                if (TextMenu.ShowYesNo("Reset everything in section {0} to defaults?",
                                       currentSection))
                {
                    Config.LoadDefaults(currentSection);
                }
            }
            else
            {
                currentKey = (ConfigKey)choice.Tag;
                return(MenuState.Key);
            }

            return(MenuState.KeyList);
        }
예제 #2
0
        static void EraseRank()
        {
            int rankIndexToErase = TextMenu.ShowNumber("Which rank to delete?",
                                                       1, RankManager.Ranks.Count);

            if (rankIndexToErase == -1)
            {
                return;
            }

            Rank rankToErase = RankManager.Ranks[rankIndexToErase - 1];
            Rank subRank;

            if (RankManager.Ranks.Count > 2)
            {
                Console.WriteLine();
                WriteWarning(RankEraseWarning, rankToErase.Name);

                while (true)
                {
                    int substitute = TextMenu.ShowNumber("Substitute rank",
                                                         1, RankManager.Ranks.Count);
                    if (substitute == rankIndexToErase)
                    {
                        Console.WriteLine("Cannot substitute rank with itself; pick a different rank.");
                    }
                    else
                    {
                        subRank = RankManager.Ranks[substitute - 1];
                        break;
                    }
                }
            }
            else
            {
                subRank = rankToErase.NextRankDown ?? rankToErase.NextRankUp;
            }

            if (TextMenu.ShowYesNo("Delete rank {0}, and substitute with {1}?",
                                   rankToErase.Name, subRank.Name))
            {
                RankManager.DeleteRank(rankToErase, subRank);
            }
        }
예제 #3
0
        static MenuState ShowPermissionLimits()
        {
            Refresh("Rank List > Rank {0} ({1} of {2}) > Permission Limits",
                    currentRank.Name, currentRank.Index + 1, RankManager.Ranks.Count);

            TextMenu menu = new TextMenu();
            int      i    = 1;

            Permission[] limits = LimitedPermissions.Where(perm => currentRank.Can(perm)).ToArray();

            int maxPermLength = limits.Max(perm => perm.ToString().Length);

            foreach (Permission perm in limits)
            {
                string text;
                string permName = perm.ToString().PadLeft(maxPermLength, '.');
                if (currentRank.HasLimitSet(perm))
                {
                    Rank limit = currentRank.GetLimit(perm);
                    text = String.Format("{0} - {1}", permName, limit.Name);
                }
                else
                {
                    text = String.Format("{0} - (own rank)", permName);
                }
                menu.AddOption(i, text, perm);
                i++;
            }
            menu.Column = Column.Right;
            TextOption optionBack  = menu.AddOption("B", "Back to rank " + currentRank.Name);
            TextOption optionReset = menu.AddOption("R", "Reset limits.");

            menu.AddSpacer();
            TextOption optionNextUp = null, optionNextDown = null;

            if (currentRank.NextRankUp != null)
            {
                optionNextUp = menu.AddOption("U", "Go to next rank up", currentRank.NextRankUp);
            }
            if (currentRank.NextRankDown != null)
            {
                optionNextDown = menu.AddOption("D", "Go to next rank down", currentRank.NextRankDown);
            }

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.RankDetails);
            }
            else if (choice == optionReset)
            {
                if (TextMenu.ShowYesNo("Reset all permission limits for rank {0} to \"own rank\"?",
                                       currentRank.Name))
                {
                    foreach (Permission perm in LimitedPermissions)
                    {
                        currentRank.ResetLimit(perm);
                    }
                }
            }
            else if (choice == optionNextDown || choice == optionNextUp)
            {
                currentRank = (Rank)choice.Tag;
            }
            else
            {
                currentPermission = (Permission)choice.Tag;
                return(MenuState.PermissionLimitDetails);
            }
            return(MenuState.PermissionLimits);
        }
예제 #4
0
        static MenuState ShowPermissions()
        {
            Refresh("Rank List > Rank {0} > Permissions",
                    currentRank.Name);

            TextMenu menu = new TextMenu();

            Permission[] permissions = (Permission[])Enum.GetValues(typeof(Permission));

            TextOption optionBack   = menu.AddOption("B", "Back to rank " + currentRank.Name);
            TextOption optionInvert = menu.AddOption("I", "Invert");

            menu.AddSpacer();

            menu.Column = Column.Right;
            TextOption optionAll  = menu.AddOption("A", "All");
            TextOption optionNone = menu.AddOption("N", "None");

            menu.AddSpacer();

            for (int i = 0; i < permissions.Length; i++)
            {
                menu.Column = (i > permissions.Length / 2 ? Column.Right : Column.Left);
                if (currentRank.Permissions[i])
                {
                    TextOption option = menu.AddOption(i + 1,
                                                       "[X] " + permissions[i],
                                                       permissions[i]);
                    option.ForeColor = ConsoleColor.White;
                }
                else
                {
                    menu.AddOption(i + 1,
                                   "[ ] " + permissions[i],
                                   permissions[i]);
                }
            }

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.RankDetails);
            }
            else if (choice == optionAll)
            {
                if (TextMenu.ShowYesNo("Grant all permissions to rank {0}?",
                                       currentRank.Name))
                {
                    for (int i = 0; i < permissions.Length; i++)
                    {
                        currentRank.Permissions[i] = true;
                    }
                }
            }
            else if (choice == optionNone)
            {
                if (TextMenu.ShowYesNo("Revoke all permissions from rank {0}?",
                                       currentRank.Name))
                {
                    for (int i = 0; i < permissions.Length; i++)
                    {
                        currentRank.Permissions[i] = false;
                    }
                }
            }
            else if (choice == optionInvert)
            {
                for (int i = 0; i < permissions.Length; i++)
                {
                    currentRank.Permissions[i] = !currentRank.Permissions[i];
                }
            }
            else
            {
                int permissionIndex = (int)choice.Tag;
                currentRank.Permissions[permissionIndex] = !currentRank.Permissions[permissionIndex];
            }

            return(MenuState.Permissions);
        }
예제 #5
0
        static MenuState ShowRanks()
        {
            Refresh("Rank list");

            TextMenu menu = new TextMenu();

            for (int i = 0; i < RankManager.Ranks.Count; i++)
            {
                Rank       rank = RankManager.Ranks[i];
                TextOption derp = menu.AddOption(i + 1,
                                                 rank.Name,
                                                 rank);
                derp.ForeColor = Color.ToConsoleColor(rank.Color);
                if (derp.ForeColor == ConsoleColor.Black)
                {
                    derp.BackColor = ConsoleColor.Gray;
                }
            }

            TextOption optionErase = null, optionRaise = null, optionLower = null;

            menu.Column = Column.Right;
            TextOption optionBack = menu.AddOption("B", "Back to sections");

            menu.AddSpacer();
            TextOption optionAdd  = menu.AddOption("A", "Add rank (blank)");
            TextOption optionCopy = menu.AddOption("C", "Copy existing rank");

            if (RankManager.Ranks.Count > 1)
            {
                optionErase = menu.AddOption("E", "Erase rank");
            }

            if (RankManager.Ranks.Count > 1)
            {
                menu.AddSpacer();
                optionRaise = menu.AddOption("R", "Raise rank in hierarchy");
                optionLower = menu.AddOption("L", "Lower rank in hierarchy");
            }

            menu.AddSpacer();
            TextOption optionDefaults = menu.AddOption("D", "Use defaults");

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.SectionList);
            }
            else if (choice == optionAdd)
            {
                Console.Write("Enter new rank name: ");
                while (true)
                {
                    string rankName = Console.ReadLine();
                    if (Rank.IsValidRankName(rankName))
                    {
                        if (RankManager.FindRank(rankName) != null)
                        {
                            WriteWarning("A rank with this name already exists.");
                        }
                        else
                        {
                            Rank newRank = new Rank(rankName, RankManager.GenerateID());
                            AddRank(newRank);
                            break;
                        }
                    }
                    else
                    {
                        WriteWarning("Rank names must be between 1 and 16 characters long, " +
                                     "and must contain only letters, digits, and underscores.");
                    }
                }
            }
            else if (choice == optionCopy)
            {
                int rankToCopyIndex = TextMenu.ShowNumber("Which rank to copy?",
                                                          1, RankManager.Ranks.Count);
                if (rankToCopyIndex != -1)
                {
                    Console.WriteLine();
                    Rank rankToCopy = RankManager.Ranks[rankToCopyIndex - 1];
                    Console.Write("Enter new rank name: ");
                    while (true)
                    {
                        string rankName = Console.ReadLine();
                        if (Rank.IsValidRankName(rankName))
                        {
                            if (RankManager.FindRank(rankName) != null)
                            {
                                WriteWarning("A rank with this name already exists.");
                            }
                            else
                            {
                                Rank newRank = new Rank(rankName, RankManager.GenerateID(), rankToCopy);
                                AddRank(newRank);
                                break;
                            }
                        }
                        else
                        {
                            WriteWarning("Rank names must be between 1 and 16 characters long, " +
                                         "and must contain only letters, digits, and underscores.");
                        }
                    }
                }
            }
            else if (choice == optionErase)
            {
                EraseRank();
            }
            else if (choice == optionRaise)
            {
                int rankToRaise = TextMenu.ShowNumber("Which rank to raise?",
                                                      2, RankManager.Ranks.Count);
                if (rankToRaise != -1)
                {
                    RankManager.RaiseRank(RankManager.Ranks[rankToRaise - 1]);
                }
            }
            else if (choice == optionLower)
            {
                int rankToLower = TextMenu.ShowNumber("Which rank to lower?",
                                                      1, RankManager.Ranks.Count - 1);
                if (rankToLower != -1)
                {
                    RankManager.LowerRank(RankManager.Ranks[rankToLower - 1]);
                }
            }
            else if (choice == optionDefaults)
            {
                if (TextMenu.ShowYesNo("Reset all ranks to defaults?"))
                {
                    RankManager.ResetToDefaults();
                }
            }
            else
            {
                currentRank = (Rank)choice.Tag;
                return(MenuState.RankDetails);
            }

            return(MenuState.Ranks);
        }
예제 #6
0
        static MenuState ShowSectionList()
        {
            Refresh("Editing {0}", Paths.ConfigFileName);

            TextMenu menu = new TextMenu();

            ConfigSection[] sections = (ConfigSection[])Enum.GetValues(typeof(ConfigSection));
            for (int i = 0; i < sections.Length; i++)
            {
                menu.AddOption(i + 1,
                               sections[i].ToString(),
                               sections[i]);
            }
            TextOption optionRanks = menu.AddOption(sections.Length + 1, "Ranks");

            menu.Column = Column.Right;
            TextOption optionSaveAndExit     = menu.AddOption("S", "Save and exit");
            TextOption optionQuit            = menu.AddOption("Q", "Quit without saving");
            TextOption optionResetEverything = menu.AddOption("D", "Use defaults");
            TextOption optionReloadConfig    = menu.AddOption("R", "Reload config");

            var choice = menu.Show();

            if (choice == optionSaveAndExit)
            {
                if (TextMenu.ShowYesNo("Save and exit?") && Config.Save())
                {
                    return(MenuState.Done);
                }
            }
            else if (choice == optionQuit)
            {
                if (TextMenu.ShowYesNo("Exit without saving?"))
                {
                    return(MenuState.Done);
                }
            }
            else if (choice == optionResetEverything)
            {
                if (TextMenu.ShowYesNo("Reset everything to defaults?"))
                {
                    Config.LoadDefaults();
                    RankManager.ResetToDefaults();
                    Config.ResetLogOptions();
                }
            }
            else if (choice == optionReloadConfig)
            {
                if (File.Exists(Paths.ConfigFileName))
                {
                    if (TextMenu.ShowYesNo("Reload configuration from \"{0}\"?",
                                           Paths.ConfigFileName))
                    {
                        Config.Reload(true);
                        Console.WriteLine("Configuration file \"{0}\" reloaded.", Paths.ConfigFileName);
                    }
                }
                else
                {
                    Console.WriteLine("Configuration file \"{0}\" does not exist.", Paths.ConfigFileName);
                }
            }
            else if (choice == optionRanks)
            {
                return(MenuState.Ranks);
            }
            else
            {
                currentSection = (ConfigSection)choice.Tag;
                return(MenuState.KeyList);
            }

            return(MenuState.SectionList);
        }