Inheritance: ICloneable
Ejemplo n.º 1
0
        public TextOption AddOption(int label, [NotNull] string text, [CanBeNull] object tag)
        {
            TextOption newOption = new TextOption(label.ToString(CultureInfo.InvariantCulture), text, Column)
            {
                Tag = tag
            };

            return(AddOption(newOption));
        }
Ejemplo n.º 2
0
        public TextOption AddOption([CanBeNull] string label, [NotNull] string text, [CanBeNull] object tag)
        {
            TextOption newOption = new TextOption(label, text, Column)
            {
                Tag = tag
            };

            return(AddOption(newOption));
        }
Ejemplo n.º 3
0
        static void AddRank(Rank newRank)
        {
            Console.WriteLine();
            Console.WriteLine("Where to position the new rank?");
            TextMenu   menu = new TextMenu();
            TextOption optionTop = menu.AddOption("T", "Top of the hierarchy");
            TextOption optionBottom = menu.AddOption("B", "Bottom of the hierarchy");
            TextOption optionCancel = menu.AddOption("C", "Cancel");
            TextOption optionAbove = null, optionUnder = null;

            if (RankManager.Ranks.Count > 1)
            {
                menu.Column = Column.Right;
                optionAbove = menu.AddOption("O", "Over a specific rank");
                optionUnder = menu.AddOption("U", "Under a specific rank");
            }

            TextOption choice = menu.Show();

            if (choice == optionCancel)
            {
                return;
            }

            if (choice == optionTop)
            {
                RankManager.AddRank(newRank, 0);
            }
            else if (choice == optionBottom)
            {
                RankManager.AddRank(newRank);
            }
            else if (choice == optionAbove)
            {
                int otherRankIndex = TextMenu.ShowNumber("Above which rank?",
                                                         1, RankManager.Ranks.Count);
                if (otherRankIndex == -1)
                {
                    return;
                }
                RankManager.AddRank(newRank, otherRankIndex - 1);
            }
            else if (choice == optionUnder)
            {
                int otherRankIndex = TextMenu.ShowNumber("Under which rank?",
                                                         1, RankManager.Ranks.Count);
                if (otherRankIndex == -1)
                {
                    return;
                }
                RankManager.AddRank(newRank, otherRankIndex);
            }
        }
Ejemplo n.º 4
0
 public TextOption AddOption([NotNull] TextOption newOption)
 {
     if (newOption == null)
     {
         throw new ArgumentNullException("newOption");
     }
     if (newOption.Label != null)
     {
         options.Add(newOption.Label.ToLower(), newOption);
     }
     lines.Add(newOption);
     return(newOption);
 }
Ejemplo n.º 5
0
 static void SetColor([NotNull] TextOption option)
 {
     if (option == null)
     {
         throw new ArgumentNullException("option");
     }
     if (!ConfigCLI.UseColor)
     {
         return;
     }
     Console.BackgroundColor = option.BackColor;
     Console.ForegroundColor = option.ForeColor;
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        static MenuState ShowPermissionLimitDetails()
        {
            Refresh("Rank List > Rank {0} > {1} Permission Limit",
                    currentRank.Name, currentPermission);
            TextMenu menu = new TextMenu();

            TextOption optionOwnRank = menu.AddOption("0", "(own rank)");

            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;
                }
            }

            menu.AddSpacer();
            TextOption optionCancel = menu.AddOption("C", "Cancel");

            TextOption choice = menu.Show();

            if (choice == optionOwnRank)
            {
                currentRank.ResetLimit(currentPermission);
            }
            else if (choice != optionCancel)
            {
                currentRank.SetLimit(currentPermission, (Rank)choice.Tag);
            }

            return(MenuState.PermissionLimits);
        }
Ejemplo n.º 8
0
 public TextOption AddOption( [CanBeNull] string label, [NotNull] string text, [CanBeNull] object tag ) {
     TextOption newOption = new TextOption( label, text, Column ) {
         Tag = tag
     };
     return AddOption( newOption );
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        static MenuState ShowRankDetails()
        {
            Refresh("Rank List > Rank {0} ({1} of {2})",
                    currentRank.Name, currentRank.Index + 1, RankManager.Ranks.Count);

            TextMenu menu = new TextMenu();

            TextOption optionName = menu.AddOption(1, "Name: \"" + currentRank.Name + "\"");

            TextOption optionColor = menu.AddOption(2, "Color: " + Color.GetName(currentRank.Color));

            optionColor.ForeColor = Color.ToConsoleColor(currentRank.Color);

            TextOption optionPrefix = menu.AddOption(3, "Prefix: \"" + currentRank.Prefix + "\"");

            TextOption optionHasReservedSlot = menu.AddOption(4, "HasReservedSlot: " + currentRank.HasReservedSlot);

            TextOption optionAllowSecurityCircumvention = menu.AddOption(5,
                                                                         "AllowSecurityCircumvention: " +
                                                                         currentRank.AllowSecurityCircumvention);

            TextOption optionIdleKickTimer = menu.AddOption(6, "IdleKickTimer: " + currentRank.IdleKickTimer);

            TextOption optionDrawLimit        = menu.AddOption(7, "DrawLimit: " + currentRank.DrawLimit);
            TextOption optionFillLimit        = menu.AddOption(8, "FillLimit: " + currentRank.FillLimit);
            TextOption optionCopySlots        = menu.AddOption(9, "CopySlots: " + currentRank.CopySlots);
            TextOption optionAntiGriefBlocks  = menu.AddOption(10, "AntiGriefBlocks: " + currentRank.AntiGriefBlocks);
            TextOption optionAntiGriefSeconds = menu.AddOption(11, "AntiGriefSeconds: " + currentRank.AntiGriefSeconds);

            menu.Column = Column.Right;

            TextOption optionBack = menu.AddOption("B", "Back to rank list");

            menu.AddSpacer();
            TextOption optionPermissions      = menu.AddOption("P", "Permissions");
            TextOption optionPermissionLimits = null;

            if (LimitedPermissions.Any(perm => currentRank.Can(perm)))
            {
                optionPermissionLimits = menu.AddOption("L", "Permission 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.Ranks);
            }
            else if (choice == optionPermissions)
            {
                return(MenuState.Permissions);
            }
            else if (choice == optionPermissionLimits)
            {
                return(MenuState.PermissionLimits);
            }
            else if (choice == optionNextDown || choice == optionNextUp)
            {
                currentRank = (Rank)choice.Tag;
            }

            return(MenuState.RankDetails);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        static MenuState ShowKey()
        {
            Refresh("Section {0} > Key {1}", currentSection, currentKey);
            Type valueType = currentKey.GetValueType();

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.Write("    Value Type: ");
            if (UseColor)
            {
                Console.ResetColor();
            }
            if (valueType.IsEnum)
            {
                Console.WriteLine("{0} (enumeration)", valueType.Name);
            }
            else if (valueType == typeof(int))
            {
                Console.WriteLine("Integer");
            }
            else if (valueType == typeof(bool))
            {
                Console.WriteLine("{0} (true/false)", valueType.Name);
            }
            else
            {
                Console.WriteLine(valueType.Name);
            }

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.WriteLine("   Description:");
            if (UseColor)
            {
                Console.ResetColor();
            }
            string[] newlineSeparator = new[] { "\r\n" };
            string[] descriptionLines = currentKey.GetDescription().Split(newlineSeparator,
                                                                          StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in descriptionLines)
            {
                Console.WriteLine("    " + line);
            }

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.Write(" Default value: ");
            PrintKeyValue(currentKey.GetDefault().ToString());

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.Write(" Current value: ");
            PrintKeyValue(currentKey.GetRawString());

            if (valueType.IsEnum)
            {
                if (UseColor)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                }
                Console.Write("       Choices: ");
                if (UseColor)
                {
                    Console.ResetColor();
                }
                Console.WriteLine(Enum.GetNames(valueType).JoinToString());
            }
            else if (currentKey.IsColor())
            {
                PrintColorList();
            }

            Console.WriteLine();
            TextMenu   menu           = new TextMenu();
            TextOption optionBack     = menu.AddOption("B", "Back to " + currentSection);
            TextOption optionChange   = menu.AddOption("C", "Change value");
            TextOption optionDefaults = menu.AddOption("D", "Use default");

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.KeyList);
            }
            else if (choice == optionChange)
            {
                while (true)
                {
                    try {
                        Console.Write("Enter new value for {0}: ", currentKey);
                        currentKey.SetValue(Console.ReadLine());
                        break;
                    } catch (FormatException ex) {
                        WriteWarning(ex.Message);
                    }
                }
            }
            else if (choice == optionDefaults)
            {
                currentKey.SetValue(currentKey.GetDefault());
            }
            return(MenuState.Key);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        void PrintOptions()
        {
            bool hasRightSide = lines.Any(line => line.Column == Column.Right);

            if (hasRightSide)
            {
                var listLeft            = lines.Where(line => line.Column == Column.Left).ToArray();
                var listRight           = lines.Where(line => line.Column == Column.Right).ToArray();
                int maxLeftOptionLength = listLeft.Where(line => line.Label != null)
                                          .Max(line => line.Label.Length);
                int maxRightOptionLength = listRight.Where(line => line.Label != null)
                                           .Max(line => line.Label.Length);
                int maxSize = Math.Max(listLeft.Length, listRight.Length);

                for (int i = 0; i < maxSize; i++)
                {
                    if (i >= listLeft.Length)
                    {
                        TextOption option    = listRight[i];
                        int        labelSize = maxRightOptionLength + 2;
                        if (option.Label == null)
                        {
                            SetColor(option);
                            Console.WriteLine(option.Text
                                              .PadLeftSub(ColumnSize + labelSize, ColumnSize * 2 - 1));
                        }
                        else
                        {
                            Console.Write("{0}. ", option.Label
                                          .PadLeft(ColumnSize + maxRightOptionLength));
                            SetColor(option);
                            Console.WriteLine(option.Text
                                              .PadRightSub(ColumnSize - labelSize - 1));
                        }
                        ResetColor();
                    }
                    else if (i >= listRight.Length)
                    {
                        TextOption option    = listLeft[i];
                        int        labelSize = maxLeftOptionLength + 2;
                        if (option.Label == null)
                        {
                            SetColor(option);
                            Console.WriteLine(option.Text
                                              .PadLeftSub(labelSize, ColumnSize * 2 - 1));
                        }
                        else
                        {
                            Console.Write("{0}. ", option.Label
                                          .PadLeft(maxLeftOptionLength));
                            SetColor(option);
                            Console.WriteLine(option.Text
                                              .PadRightSub(ColumnSize * 2 - labelSize - 1));
                        }
                        ResetColor();
                    }
                    else
                    {
                        TextOption option1 = listLeft[i];
                        TextOption option2 = listRight[i];

                        int leftLabelSize = maxLeftOptionLength + 2;
                        if (option1.Label == null)
                        {
                            SetColor(option1);
                            Console.Write(option1.Text
                                          .PadLeftSub(leftLabelSize, ColumnSize));
                        }
                        else
                        {
                            Console.Write("{0}. ", option1.Label.PadLeft(maxLeftOptionLength));
                            SetColor(option1);
                            Console.Write(option1.Text
                                          .PadRightSub(ColumnSize - leftLabelSize));
                        }
                        ResetColor();

                        int rightLabelSize = maxLeftOptionLength + 2;
                        if (option2.Label == null)
                        {
                            SetColor(option2);
                            Console.WriteLine(option2.Text
                                              .PadLeftSub(rightLabelSize, ColumnSize - 1));
                        }
                        else
                        {
                            Console.Write("{0}. ", option2.Label
                                          .PadLeft(maxRightOptionLength));
                            SetColor(option2);
                            Console.WriteLine(option2.Text
                                              .PadRightSub(ColumnSize - rightLabelSize - 1));
                        }
                        ResetColor();
                    }
                }
            }
            else
            {
                int maxOptionLength = lines.Where(line => line.Label != null).Max(line => line.Label.Length);
                int labelSize       = maxOptionLength + 2;
                foreach (TextOption option in lines)
                {
                    if (option.Label == null)
                    {
                        SetColor(option);
                        Console.WriteLine(option.Text
                                          .PadLeftSub(labelSize, ColumnSize * 2 - 1));
                    }
                    else
                    {
                        Console.Write("{0}. ", option.Label
                                      .PadLeft(maxOptionLength));
                        SetColor(option);
                        Console.WriteLine(option.Text.PadRightSub(ColumnSize * 2 - labelSize - 1));
                    }
                    ResetColor();
                }
            }

            if (ConfigCLI.UseColor)
            {
                Console.ResetColor();
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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;
        }
Ejemplo n.º 17
0
 public TextOption AddOption( int label, [NotNull] string text, [CanBeNull] object tag ) {
     TextOption newOption = new TextOption( label.ToString( CultureInfo.InvariantCulture ), text, Column ) {
         Tag = tag
     };
     return AddOption( newOption );
 }