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