Beispiel #1
0
        static InputToolSelector <IEnumSelector <ConsoleColor> > GenerateColorSelector(IInputToolSelector menu)
        {
            var colors        = GenerateColorMenuItems();
            var colorSelector = new InputToolSelector <IEnumSelector <ConsoleColor> >(colors.Values)
            {
                Title = "Colors", Header = "Colors", Footer = "Footer preview text"
            };

            //assign
            menu.ActUponInputToolTree(x => x.HeaderSplash = menu.HeaderSplash);
            menu.ActUponInputToolTree(x => x.InputSplash  = menu.InputSplash);
            menu.ActUponInputToolTree(x => x.FooterSplash = menu.FooterSplash);

            colorSelector.ActUponInputToolTree(x => x.HeaderSplash = menu.HeaderSplash);
            colorSelector.ActUponInputToolTree(x => x.InputSplash  = menu.InputSplash);
            colorSelector.ActUponInputToolTree(x => x.FooterSplash = menu.FooterSplash);
            colorSelector.ActUponInputToolTree(x => x.Footer       = "Footer preview text!");
            foreach (var c in colorSelector.Options.Skip(2))
            {
                c.Options.Add(Splash.NoColor);
                c.DisplayFormat = (color) =>
                {
                    if (color == Splash.NoColor)
                    {
                        return("Reset");
                    }
                    return(color.ToString());
                };
            }

            colors[Color.HeaderFG].PreviewTrigger   = (x) => menu.HeaderSplash.ForegroundColor = x;
            colors[Color.HeaderBG].PreviewTrigger   = (x) => menu.HeaderSplash.BackgroundColor = x;
            colors[Color.SelectedFG].PreviewTrigger = (x) => menu.InputSplash.ForegroundColor = x;
            colors[Color.SelectedBG].PreviewTrigger = (x) => menu.InputSplash.BackgroundColor = x;
            colors[Color.FooterFG].PreviewTrigger   = (x) => menu.FooterSplash.ForegroundColor = x;
            colors[Color.FooterBG].PreviewTrigger   = (x) => menu.FooterSplash.BackgroundColor = x;

            colors[Color.HeaderFG].CancelTrigger   = (x) => menu.HeaderSplash.ForegroundColor = x;
            colors[Color.HeaderBG].CancelTrigger   = (x) => menu.HeaderSplash.BackgroundColor = x;
            colors[Color.SelectedFG].CancelTrigger = (x) => menu.InputSplash.ForegroundColor = x;
            colors[Color.SelectedBG].CancelTrigger = (x) => menu.InputSplash.BackgroundColor = x;
            colors[Color.FooterFG].CancelTrigger   = (x) => menu.FooterSplash.ForegroundColor = x;
            colors[Color.FooterBG].CancelTrigger   = (x) => menu.FooterSplash.BackgroundColor = x;

            return(colorSelector);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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;
            }
        }