static void PromptLoad(IDictionary <Option, IInputTool> options, IEnumSelector <Confirm> doLoad = null) { OpenFileDialog dialog; Character loaded = null; if (doLoad == null) { doLoad = new EnumSelector <Confirm> { Title = "Load character", Header = "Do you want to load a character? (from file)" } } ; if ((Confirm)doLoad.Activate().ObjValue == Confirm.Yes) { dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { var json = File.ReadAllText(dialog.FileName); loaded = JsonConvert.DeserializeObject <Character>(json); } if (loaded != null) { Option opt = 0; try { opt = Option.Name; options[Option.Name].Cast <string>().Value = loaded.Name; opt = Option.Age; options[Option.Age].Cast <int>().Value = loaded.Age; opt = Option.Gender; (options[Option.Gender] as ISelector).Index = loaded.Gender; opt = Option.Style; (options[Option.Style] as ISelector).Index = loaded.Style; opt = Option.Weapon; options[Option.Weapon].Cast <Weapon>().Value = loaded.Weapon; opt = Option.Armour; options[Option.Armour].Cast <Armour>().Value = loaded.Armour; opt = Option.Badges; options[Option.Badges].Cast <Badges>().Value = loaded.Badges; } catch (ArgumentException) { doLoad.ErrorMessage = $"Data '{opt}' was corrupted in {dialog.FileName}."; doLoad.HasError = true; PromptLoad(options, doLoad); } } } }
public static Selector <object> CreateMenu(string path, EnumSelector <Confirm> exit, IEnumerable <string> extensions) { var dir = new Directory() { Path = path }; var menu = CreateMenuByDirectory(dir, extensions); if (menu != null) { menu.CancelTrigger = x => menu.Cancel = exit.Activate().Cast <Confirm>().Value == Confirm.Yes; menu.KeyPressActions[ConsoleKey.O] = (m) => { menu.Cancel = true; menu.CancelTrigger = (_) => { }; }; } return(menu); }
static IInputToolSelector <IInputTool> GenerateMenu() { var options = GenerateOptions(); var menu = new InputToolSelector <IInputTool>(options.Values) { Title = "Main menu", Header = "Main menu" }; var colorSelector = GenerateColorSelector(menu); SetupBadgesFooter((IFlagSelector <Badges>)options[Option.Badges]); PromptLoad(options); menu.PreActivateTrigger = (x) => menu.Footer = GetInfoString(options); var exit = new EnumSelector <Exit> { Header = "Exiting character creation" }; Func <string> saveHeader = () => $"Do you want to save '{options[Option.Name].Cast<string>().Value}'?"; var save = new EnumSelector <Confirm>() { Header = saveHeader() }; save.PostActivateTrigger = (x) => { if (x == Confirm.Yes) { Save(options); } }; menu.ActUponInputToolTree(x => x.IfType <ISelector>(y => y.KeyPressActions[ConsoleKey.S] = (m) => save.Activate())); menu.ActUponInputToolTree(x => x.IfType <ISelector>(y => y.KeyPressActions[ConsoleKey.C] = (m) => colorSelector.Activate())); menu.CancelTrigger = (x) => { exit.Activate(); menu.Cancel = exit.Value != Exit.Cancel; if (exit.Value == Exit.SaveAndQuit) { Save(options); } }; return(menu); }
static void Main(string[] args) { Range.DefaultSlideWidth = 64; var red = Range.New(0, 255, 1, Default: 0xFF, Title: "Primary color Red"); var green = Range.New(0, 255, 1, Default: 0xFF, Title: "Primary color Green"); var blue = Range.New(0, 255, 1, Default: 0xFF, Title: "Primary color Blue"); var red2 = Range.New(0, 255, 1, Default: 0, Title: "Secondary color Red"); var green2 = Range.New(0, 255, 1, Default: 0, Title: "Secondary color Green"); var blue2 = Range.New(0, 255, 1, Default: 0, Title: "Secondary color Blue"); red.SlideSplash = red2.SlideSplash = new Splash() { ForegroundColor = ConsoleColor.Red, BackgroundColor = ConsoleColor.DarkRed }; green.SlideSplash = green2.SlideSplash = new Splash() { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGreen }; blue.SlideSplash = blue2.SlideSplash = new Splash() { ForegroundColor = ConsoleColor.Blue, BackgroundColor = ConsoleColor.DarkBlue }; TextInput name = null; name = new TextInput(x => { var chars = x.Intersect(Path.GetInvalidFileNameChars()); if (x.Length == 0) { name.ErrorMessage = $"Value cannot be empty"; } else if (chars.Any()) { name.ErrorMessage = $"Remove: {Environment.NewLine}{string.Join(Environment.NewLine, chars)}"; } else { return(true); } return(false); }) { Title = "Finish", Header = "Choose filename:", Footer = "extension will be added (for example '.bmp')" }; var options = new IInputTool[] { red, green, blue, red2, green2, blue2, name }; var imageSettings = new InputToolSelector <IInputTool>(options); var cancel = new Selector <bool>(new bool[] { false, true }) { Header = "Do you want to exit without saving?", DisplayFormat = x => x ? "Yes" : "No" }; imageSettings.CancelTrigger = x => imageSettings.Cancel = cancel.Activate().IfType <Selector <bool> >(y => { }).Value; var bgsplash = new Splash() { ForegroundColor = ConsoleColor.DarkGray, BackgroundColor = ConsoleColor.Gray }; imageSettings.ActUponInputToolTree(tool => tool.IfType <IRange <int> >(x => { x.IncrementByModifiers[ConsoleModifiers.Control] = 5; x.IncrementByModifiers[ConsoleModifiers.Shift | ConsoleModifiers.Control] = 20; x.SlideBackgroundSplash = bgsplash; x.Header = x.Title; })); imageSettings.InputSplash.ForegroundColor = ConsoleColor.Cyan; name.PostActivateTrigger = x => imageSettings.Cancel = true; name.FooterSplash.ForegroundColor = ConsoleColor.DarkGray; var format = new EnumSelector <ImageFormat> { Header = "Choose image format", InputSplash = imageSettings.InputSplash }; while (true) { imageSettings.Activate(); if (imageSettings.Cancel) { return; } format.Activate(); if (format.Cancel) { continue; } var size = 16; var drawer = new BitmapDrawer(name.Value, 32 * 8 * size, 32 * 5 * size) { Iterations = 64, Zoom = 4, XScroll = 0.45, YScroll = 0.05, PrimaryColor = Color.FromArgb(red.Value, green.Value, blue.Value), SecondaryColor = Color.FromArgb(red2.Value, green2.Value, blue2.Value), LimitAlpha = 1, ImageFormat = format.Value }; drawer.CreateImage(); drawer.SaveImage(); Process.Start($"{Directory.GetCurrentDirectory()}\\{drawer.FullFileName}"); break; } }