Example #1
0
 public void PrintMessage(ColoredString text)
 {
     if (text.ToString() != lastMessage)
     {
         ShiftDown(1);
         VirtualCursor.Print(text).CarriageReturn();
         lastMessage = text.ToString();
     }
 }
Example #2
0
        /// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button yesButton = new Button(yesPrompt.Length + 2);
            Button noButton  = new Button(noPrompt.Length + 2);

            yesButton.Position = new Point(2, window.textSurface.Height - 2);
            noButton.Position  = new Point(window.textSurface.Width - noButton.Width - 2, window.textSurface.Height - 2);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            window.Add(yesButton);
            window.Add(noButton);

            window.Closed += (o, e) =>
            {
                resultCallback(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
Example #3
0
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action<bool> resultCallback)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window._cellData.Print(2, 2, message);

            Button yesButton = new Button(yesPrompt.Length + 2, 1);
            Button noButton = new Button(noPrompt.Length + 2, 1);

            yesButton.Position = new Microsoft.Xna.Framework.Point(2, window._cellData.Height - 2);
            noButton.Position = new Microsoft.Xna.Framework.Point(window._cellData.Width - noButton.Width - 2, window._cellData.Height - 2);

            yesButton.Text = yesPrompt;
            noButton.Text = noPrompt;

            yesButton.ButtonClicked += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.ButtonClicked += (o, e) => { window.DialogResult = false; window.Hide(); };

            window.Add(yesButton);
            window.Add(noButton);

            window.Closed += (o, e) =>
                {
                    resultCallback(window.DialogResult);
                };

            window.Show(true);
            window.Center();
        }
Example #4
0
        // Executes an attack from an attacking actor
        // on a defending actor, and then describes
        // the outcome of the attack in the Message Log
        public void Attack(Actor attacker, Actor defender)
        {
            // Create two messages that describe the outcome
            // of the attack and defense
            ColoredString attackMessage  = new ColoredString("");
            ColoredString defenseMessage = new ColoredString("");

            // Count up the amount of attacking damage done
            // and the number of successful blocks
            int hits   = ResolveAttack(attacker, defender, attackMessage);
            int blocks = ResolveDefense(defender, hits, attackMessage, defenseMessage);

            // Display the outcome of the attack & defense
            GameLoop.UIManager.MessageLog.Add(attackMessage);
            if (!string.IsNullOrWhiteSpace(defenseMessage.ToString()))
            {
                GameLoop.UIManager.MessageLog.Add(defenseMessage);
            }

            int damage = hits - blocks;

            // The defender now takes damage

            ResolveDamage(defender, damage);
        }
Example #5
0
 public void Write(ColoredString message)
 {
     _lines.Enqueue(message.ToString());
     if (_fireNewMessage != null)
     {
         _fireNewMessage(this, new NewMessageEventArgs(message));
     }
 }
Example #6
0
        private void RedrawPanel()
        {
            Print(2, 2, _characterName);

            // Create a colored string that looks like 52/500
            ColoredString healthStatus = _health.ToString().CreateColored(Color.LightGreen, Color.Black, null) +
                                         "/".CreateColored(Color.White, Color.Black, null) +
                                         _maxHealth.ToString().CreateColored(Color.DarkGreen, Color.Black, null);

            // Align the string to the right side of the console
            Print(Width - 2 - healthStatus.ToString().Length, 2, healthStatus);
        }
        public void Update()
        {
            editor.Clear();
            editor.Print(0, 0, stat.Name);
            //calculation move to method?
            ColoredString statusString = stat.Value.ToString().CreateColored(colorOne, Color.Black, null) +
                                         "/".CreateColored(Color.White, Color.Black, null) +
                                         stat.AltValue.ToString().CreateColored(colorTwo, Color.Black, null);
            ColoredString gradient = new string((char)176, 14).CreateGradient(colorOne, colorTwo, colorOne, colorTwo);
            double        percent  = (double)stat.Value / (double)stat.AltValue;

            //drawing
            editor.Print(width - statusString.ToString().Length, 0, statusString);
            editor.Print(0, 1, gradient.SubString(0, (int)((double)gradient.Count * (double)percent)));
        }
Example #8
0
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button closeButton = new Button(closeButtonText.Length + 2);

            closeButton.Position = new Point(2, window.textSurface.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };

            window.Add(closeButton);

            window.Show(true);
            window.Center();
        }
Example #9
0
        public static void Message(ColoredString message, string closeButtonText)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window._cellData.Print(2, 2, message);

            Button closeButton = new Button(closeButtonText.Length + 2, 1);

            closeButton.Position = new Microsoft.Xna.Framework.Point(2, window._cellData.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.ButtonClicked += (o, e) => { window.DialogResult = true; window.Hide(); };

            window.Add(closeButton);

            window.Show(true);
            window.Center();
        }
Example #10
0
        public static void Message(ColoredString message, string closeButtonText)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window._cellData.Print(2, 2, message);

            Button closeButton = new Button(closeButtonText.Length + 2, 1);

            closeButton.Position = new Microsoft.Xna.Framework.Point(2, window._cellData.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.ButtonClicked += (o, e) => { window.DialogResult = true; window.Hide(); };

            window.Add(closeButton);

            window.Show(true);
            window.Center();
        }
Example #11
0
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button closeButton = new Button(closeButtonText.Length + 2);

            closeButton.Position = new Point(2, window.textSurface.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };

            window.Add(closeButton);

            window.Show(true);
            window.Center();
        }
Example #12
0
        public void TestThatColoredPromptsAreObserved()
        {
            var prompt = new ColoredString("[Prompt!] ", ConsoleColor.Cyan);

            var reader    = Substitute.For <IConsoleReader>();
            var lineInput = Substitute.For <IConsoleLineInput>();

            lineInput.Prompt = prompt;
            reader.LineInput.Returns(lineInput);

            var client = new ConsoleLoopClient(reader);

            client.Prompt.Should().Be(prompt);

            var newPrompt = new ColoredString("NewPrompt", ConsoleColor.Green);

            client.PromptWithColor = newPrompt;
            client.PromptWithColor.Should().Be(newPrompt);
            client.Prompt.Should().Be(newPrompt.ToString());
            lineInput.Prompt.Should().Be(newPrompt);

            client.DisplayPrompt();
            lineInput.Received(1).DisplayPrompt();
        }
        /// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        /// <param name="colors">The colors to apply for the message box and buttons. If <see langword="null"/>, then the colors are from <see cref="Themes.Library"/> will be used.</param>
        /// <param name="buttonTheme">The theme for the buttons on the message box. If <see langword="null"/>, then the theme the from <see cref="Themes.Library"/> will be used.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback, Colors colors = null, Themes.ButtonTheme buttonTheme = null)
        {
            message.IgnoreBackground = true;

            var yesButton = new Button(yesPrompt.Length + 2, 1);
            var noButton  = new Button(noPrompt.Length + 2, 1);

            if (buttonTheme != null)
            {
                yesButton.Theme = buttonTheme;
                noButton.Theme  = buttonTheme;
            }

            var window = new Window(message.ToString().Length + 4, 5 + yesButton.Surface.Height);

            if (colors != null)
            {
                window.Controls.ThemeColors = colors;
            }

            var printArea = new DrawingArea(window.Width, window.Height)
            {
                OnDraw = (ds, time) =>
                {
                    if (!ds.IsDirty)
                    {
                        return;
                    }
                    ColoredGlyph appearance = ((Themes.DrawingAreaTheme)ds.Theme).Appearance;
                    ds.Surface.Fill(appearance.Foreground, appearance.Background, null);
                    ds.Surface.Print(2, 2, message);
                    ds.IsDirty = true;
                }
            };

            yesButton.Position = new Point(2, window.Height - 1 - yesButton.Surface.Height);
            noButton.Position  = new Point(window.Width - noButton.Width - 2, window.Height - 1 - yesButton.Surface.Height);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            yesButton.Theme = null;
            noButton.Theme  = null;

            window.Controls.Add(printArea);
            window.Controls.Add(yesButton);
            window.Controls.Add(noButton);

            noButton.IsFocused = true;

            window.Closed += (o, e) =>
            {
                resultCallback?.Invoke(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        /// <param name="colors">The colors to apply for the message box and buttons. If <see langword="null"/>, then the colors are from <see cref="Themes.Library"/> will be used.</param>
        /// <param name="buttonTheme">The theme for the buttons on the message box. If <see langword="null"/>, then the theme the default from <see cref="Themes.Library"/> will be used.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null, Colors colors = null, Themes.ButtonTheme buttonTheme = null)
        {
            int width       = message.ToString().Length + 4;
            int buttonWidth = closeButtonText.Length + 2;

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            var closeButton = new Button(buttonWidth, 1)
            {
                Text = closeButtonText,
            };

            if (buttonTheme != null)
            {
                closeButton.Theme = buttonTheme;
            }

            var window = new Window(width, 5 + closeButton.Surface.Height);

            if (colors != null)
            {
                window.Controls.ThemeColors = colors;
            }

            message.IgnoreBackground = true;

            var printArea = new DrawingArea(window.Width, window.Height)
            {
                OnDraw = (ds, time) =>
                {
                    if (!ds.IsDirty)
                    {
                        return;
                    }
                    ColoredGlyph appearance = ((Themes.DrawingAreaTheme)ds.Theme).Appearance;
                    ds.Surface.Fill(appearance.Foreground, appearance.Background, null);
                    ds.Surface.Print(2, 2, message);
                    ds.IsDirty = true;
                }
            };

            window.Controls.Add(printArea);

            closeButton.Position = new Point(2, window.Height - 1 - closeButton.Surface.Height);
            closeButton.Click   += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };
            closeButton.Theme    = null;

            window.Controls.Add(closeButton);
            closeButton.IsFocused = true;
            window.CloseOnEscKey  = true;
            window.Show(true);
            window.Center();
        }