Пример #1
0
        protected override void DrawView(CellSurface surface)
        {
            base.DrawView(surface);

            const int dX = 5;

            surface.Print(dX, 2, $"You has reached level {Level}!");
            surface.Print(dX, 3, "Please select stat you want to increase:");

            DoForAllStats((y, stat) =>
            {
                var name = TextHelper.GetStatName(stat);
                name     = $"{name}:";
                while (name.Length < maxStatNameLength)
                {
                    name += " ";
                }

                surface.Print(dX, y, name);
                surface.Print(dX + maxStatNameLength + 2, y, StatsValue[stat].ToString());
            });

            const int dY = 6;

            for (var index = 0; index < stats.Length; index++)
            {
                var stat = stats[index];
                var y    = dY + index * 4;
                PrintStatStatus(5, y, stat, surface);
            }
        }
Пример #2
0
 public static void SetBackground(this CellSurface cellSurface, int x, int y, int width, Color color)
 {
     for (int i = x; i < x + width; i++)
     {
         cellSurface.SetBackground(i, y, color);
     }
 }
Пример #3
0
        private void DrawCellManaLevel(CellSurface surface)
        {
            const int yPos = 15;

            var cell = game.Map.GetCell(game.PlayerPosition);

            surface.Print(2, yPos, "Area Mana");

            var manaBarLength           = Width - 3;
            var manaLevelPercent        = (float)cell.MagicEnergyLevel() / cell.MaxMagicEnergyLevel();
            var disturbanceLevelPercent = (float)cell.MagicDisturbanceLevel() / cell.MaxMagicEnergyLevel();

            var manaLevelLength        = (int)Math.Floor(manaBarLength * manaLevelPercent);
            var disturbanceLevelLength = (int)Math.Ceiling(manaBarLength * disturbanceLevelPercent);
            var leftLength             = manaBarLength - (manaLevelLength + disturbanceLevelLength);

            var shiftX = 2;

            for (int i = 0; i < disturbanceLevelLength; i++)
            {
                surface.Print(shiftX + i, yPos + 1, new ColoredGlyph(Glyphs.GetGlyph('.'), Color.Black, Color.BlueViolet));
            }

            shiftX += disturbanceLevelLength;
            for (int i = 0; i < leftLength; i++)
            {
                surface.Print(shiftX + i, yPos + 1, new ColoredGlyph(Glyphs.GetGlyph('.'), Color.Black, Color.DarkBlue));
            }

            shiftX += leftLength;
            for (int i = 0; i < manaLevelLength; i++)
            {
                surface.Print(shiftX + i, yPos + 1, new ColoredGlyph(Glyphs.GetGlyph('.'), Color.Black, Color.DeepSkyBlue));
            }
        }
Пример #4
0
        public static void DrawImageToSurface(this Texture2D texture, CellSurface surface, Point position, Action <int, Cell, Color> cellProcessor)
        {
            Color[] pixels = new Color[texture.Width * texture.Height];
            texture.GetData <Color>(pixels);

            int startX       = position.X;
            int widthCounter = 0;

            for (int i = 0; i < pixels.Length; i++)
            {
                if (widthCounter >= texture.Width)
                {
                    widthCounter = 0;
                    position.X   = startX;
                    position.Y++;
                }

                if (surface.IsValidCell(position.X, position.Y))
                {
                    int destinationIndex = position.ToIndex(surface.Width);

                    cellProcessor(destinationIndex, surface[destinationIndex], pixels[i]);
                }

                position.X++;
                widthCounter++;
            }
        }
Пример #5
0
        /// <summary>
        /// Renders the current entity's animation frame to a surface at the specified location.
        /// </summary>
        /// <param name="surface">The surface to print the frame on.</param>
        /// <param name="location">Specifies the cell at which the frame will be printed at.</param>
        public void RenderToSurface(CellSurface surface, Point location)
        {
            // copy the current frame of the animation to the console at the specified location
            Frame frame = _currentAnimation.CurrentFrame;

            frame.Copy(0, 0, frame.Width, frame.Height, surface, location.X, location.Y);
        }
Пример #6
0
        private void PlotCell(CellSurface surface, int x, int y, int character, bool fillMe = false)
        {
            if (surface.IsValidCell(x, y))
            {
                var cell = surface[x, y];

                if (fillMe)
                {
                    cell.Background     = FillColor;
                    cell.Foreground     = Foreground;
                    cell.CharacterIndex = character;
                    return;
                }

                if (Foreground != Color.Transparent || DrawTransparency)
                {
                    cell.Foreground = Foreground;
                }

                if (BorderBackground != Color.Transparent || DrawTransparency)
                {
                    cell.Background = BorderBackground;
                }

                cell.CharacterIndex = character;
            }
        }
Пример #7
0
            public void SetTargetSurface(Console surface)
            {
                SurfaceReference = null;
                SurfaceView      = null;

                SurfaceReference = surface;
                SurfaceView      = new ScrollingConsole(surface.Width, surface.Height, surface.Font, new Rectangle(0, 0, Width - 2 > surface.Width ? surface.Width : Width - 2,
                                                                                                                   Height - 2 > surface.Height ? surface.Height : Height - 2), surface.Cells);
                SurfaceView.DefaultBackground = surface.DefaultBackground;

                if (SurfaceView.ViewPort.Width != SurfaceView.Width)
                {
                    HorizontalBar.IsEnabled = true;
                    HorizontalBar.Maximum   = SurfaceView.Width - SurfaceView.ViewPort.Width;
                }
                else
                {
                    HorizontalBar.IsEnabled = false;
                }

                if (SurfaceView.ViewPort.Height != SurfaceView.Height)
                {
                    VerticalBar.IsEnabled = true;
                    VerticalBar.Maximum   = SurfaceView.Height - SurfaceView.ViewPort.Height;
                }
                else
                {
                    VerticalBar.IsEnabled = false;
                }

                VerticalBar.Value   = 0;
                HorizontalBar.Value = 0;

                IsDirty = true;
            }
Пример #8
0
        public static void DrawImage(this CellSurface surface, int x, int y, SymbolsImage image, Color defaultForeColor, Color defaultBackColor)
        {
            for (int posY = 0; posY < image.Height; posY++)
            {
                for (int posX = 0; posX < image.Width; posX++)
                {
                    var pixel     = image[posX, posY];
                    var backColor = pixel.BackgroundColor?.ToXna() ?? defaultBackColor;

                    var printX = x + posX;
                    var printY = y + posY;

                    if (pixel.Symbol.HasValue)
                    {
                        var foreColor = pixel.Color?.ToXna() ?? defaultForeColor;
                        surface.Print(printX, printY,
                                      new ColoredGlyph(pixel.Symbol.Value, foreColor, backColor));
                    }
                    else
                    {
                        surface.Print(printX, printY, new ColoredGlyph(' ', defaultForeColor, backColor));
                    }
                }
            }
        }
Пример #9
0
        public static void PrintStyledText(this CellSurface surface, int x, int y, params ColoredString[] text)
        {
            var glyphs        = text.SelectMany(part => part.ToArray()).ToArray();
            var coloredString = new ColoredString(glyphs);

            surface.Print(x, y, coloredString);
        }
Пример #10
0
        public static void DrawImageToSurface(this Texture2D texture, CellSurface surface, Point position, Action<int, Cell, Color> cellProcessor)
        {
            Color[] pixels = new Color[texture.Width * texture.Height];
            texture.GetData<Color>(pixels);

            int startX = position.X;
            int widthCounter = 0;

            for (int i = 0; i < pixels.Length; i++)
            {
                if (widthCounter >= texture.Width)
                {
                    widthCounter = 0;
                    position.X = startX;
                    position.Y++;
                }

                if (surface.IsValidCell(position.X, position.Y))
                {
                    int destinationIndex = position.ToIndex(surface.Width);

                    cellProcessor(destinationIndex, surface[destinationIndex], pixels[i]);
                }

                position.X++;
                widthCounter++;
            }
        }
Пример #11
0
        public void Draw(CellSurface surface)
        {
            if (BorderAppearance == null)
                BorderAppearance = new CellAppearance(Color.Blue, Color.Black, 4);

            Algorithms.Circle(Center.X, Center.Y, Radius, (x, y) => { if (surface.IsValidCell(x, y)) surface.SetCellAppearance(x, y, BorderAppearance); });
        }
Пример #12
0
            public static EffectsManager Load(string file, CellSurface surface)
            {
                EffectsManagerSerialized data    = Serializer.Load <EffectsManagerSerialized>(file, Settings.SerializationIsCompressed);
                EffectsManager           manager = new EffectsManager(surface);

                foreach (var effect in data.Effects.Keys)
                {
                    int[] effectCellIndexes = data.Effects[effect];

                    List <Cell> cells = new List <Cell>(effectCellIndexes.Length);

                    foreach (var index in effectCellIndexes)
                    {
                        cells.Add(surface.Cells[index]);
                    }

                    var effectData = new CellEffectData(effect)
                    {
                        Cells = cells
                    };

                    manager._effects.Add(effect, effectData);

                    foreach (var cell in cells)
                    {
                        manager._effectCells.Add(cell, effectData);
                    }
                }

                return(manager);
            }
Пример #13
0
        /// <summary>
        /// Converts a <see cref="TileLayer"/> to a <see cref="CellSurface"/>.
        /// </summary>
        /// <returns>The convereted surface.</returns>
        public CellSurface ToCellSurface()
        {
            var cells            = new CellSurface(Tiles.GetUpperBound(1), Tiles.GetUpperBound(0));
            var transparentColor = new Microsoft.Xna.Framework.Color(255, 0, 255);

            cells.Fill(Microsoft.Xna.Framework.Color.Black, Microsoft.Xna.Framework.Color.Transparent, 0, null);

            for (int y = 0; y < cells.Height; y++)
            {
                for (int x = 0; x < cells.Width; x++)
                {
                    var tile            = Tiles[y, x];
                    var backgroundColor = new Microsoft.Xna.Framework.Color(tile.BackgroundRed, tile.BackgroundGreen, tile.BackgroundBlue);
                    if (backgroundColor != transparentColor)
                    {
                        var cell = cells[x, y];
                        cell.CharacterIndex = tile.CharacterCode;
                        cell.Foreground     = new Microsoft.Xna.Framework.Color(tile.ForegroundRed, tile.ForegroundGreen, tile.ForegroundBlue);
                        cell.Background     = backgroundColor;
                    }
                }
            }

            return(cells);
        }
Пример #14
0
        /// <summary>
        /// Converts this REXPaint image to a collection of <see cref="CellSurface"/>.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <CellSurface> ToLayersComponent()
        {
            var layers = new CellSurface[LayerCount];

            for (int i = 0; i < LayerCount; i++)
            {
                layers[i] = new CellSurface(Width, Height);

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        Cell rexCell = _layers[i][x, y];
                        if (rexCell.IsTransparent())
                        {
                            continue;
                        }

                        SadConsole.ColoredGlyph newCell = layers[i][x, y];
                        newCell.Foreground = new SadRogueColor(rexCell.Foreground.R, rexCell.Foreground.G, rexCell.Foreground.B, (byte)255);
                        newCell.Background = new SadRogueColor(rexCell.Background.R, rexCell.Background.G, rexCell.Background.B, (byte)255);
                        newCell.Glyph      = rexCell.Character;
                    }
                }

                layers[i].IsDirty = true;
            }


            return(layers);
        }
Пример #15
0
        public void Draw(CellSurface surface)
        {
            for (int x = Location.X; x < Location.X + Width; x++)
            {
                for (int y = Location.Y; y < Location.Y + Height; y++)
                {
                    // Top row
                    if (y == Location.Y)
                    {
                        if (x == Location.X)
                        {
                            PlotCell(surface, x, y, TopLeftCharacter);
                        }
                        else if (x == Location.X + Width - 1)
                        {
                            PlotCell(surface, x, y, TopRightCharacter);
                        }
                        else
                        {
                            PlotCell(surface, x, y, TopSideCharacter);
                        }
                    }

                    // Bottom row
                    else if (y == Location.Y + Height - 1)
                    {
                        if (x == Location.X)
                        {
                            PlotCell(surface, x, y, BottomLeftCharacter);
                        }
                        else if (x == Location.X + Width - 1)
                        {
                            PlotCell(surface, x, y, BottomRightCharacter);
                        }
                        else
                        {
                            PlotCell(surface, x, y, BottomSideCharacter);
                        }
                    }

                    // Other rows
                    else
                    {
                        if (x == Location.X)
                        {
                            PlotCell(surface, x, y, LeftSideCharacter);
                        }
                        else if (x == Location.X + Width - 1)
                        {
                            PlotCell(surface, x, y, RightSideCharacter);
                        }
                        else if (Fill)
                        {
                            PlotCell(surface, x, y, 0, Fill);
                        }
                    }
                }
            }
        }
Пример #16
0
        //public ICellAppearance FillAppearance;
        //public bool Fill;

        public void Draw(CellSurface surface)
        {
            Algorithms.Ellipse(StartingPoint.X, StartingPoint.Y, EndingPoint.X, EndingPoint.Y, (x, y) => { if (surface.IsValidCell(x, y))
                                                                                                           {
                                                                                                               surface.SetCellAppearance(x, y, BorderAppearance);
                                                                                                           }
                               });
        }
Пример #17
0
        protected override void DrawView(CellSurface surface)
        {
            base.DrawView(surface);

            var labelX = Width / 2 - 7;

            surface.Print(labelX, 12, new ColoredString("You have died!", Color.Red, DefaultBackground));
        }
Пример #18
0
 public static void DrawVerticalLine(this CellSurface surface, int x, int y, int length,
                                     ColoredGlyph coloredGlyph)
 {
     for (var dY = 0; dY < length; dY++)
     {
         surface.Print(x, y + dY, coloredGlyph);
     }
 }
Пример #19
0
        /// <summary>
        /// Determines the cells that would be drawn on and returns them instead of drawing the line.
        /// </summary>
        /// <param name="surface">The surface to get the cells from.</param>
        /// <returns>The cells the line would have drawn on.</returns>
        public IEnumerable <Cell> GetCells(CellSurface surface)
        {
            List <Cell> cells = new List <Cell>();

            Algorithms.Line(StartingLocation.X, StartingLocation.Y, EndingLocation.X, EndingLocation.Y, (x, y) => { cells.Add(surface[x, y]); return(true); });

            return(cells);
        }
Пример #20
0
        protected override void DrawView(CellSurface surface)
        {
            base.DrawView(surface);

            surface.Print(1, 1, "Open Image");
            surface.Clear(new Rectangle(1, 2, Width - 2, 2));
            surface.Print(1, 2, Path);
        }
Пример #21
0
        /// <inheritdoc />
        public override void Draw(ControlsConsole console, CellSurface hostSurface)
        {
            hostSurface.DefaultForeground = FillStyle.Foreground;
            hostSurface.DefaultBackground = FillStyle.Background;
            hostSurface.Fill(hostSurface.DefaultForeground, hostSurface.DefaultBackground, FillStyle.Glyph, null);

            if (!(console is Window window))
            {
                return;
            }

            if (BorderLineStyle != null)
            {
                hostSurface.DrawBox(new Rectangle(0, 0, hostSurface.Width, hostSurface.Height), new Cell(BorderStyle.Foreground,
                                                                                                         BorderStyle.Background, 0), null, BorderLineStyle);
            }

            // Draw title
            var adjustedText  = "";
            var adjustedWidth = hostSurface.Width - 2;

            TitleAreaLength = 0;
            TitleAreaX      = 0;

            if (!string.IsNullOrEmpty(window.Title))
            {
                if (window.Title.Length > adjustedWidth)
                {
                    adjustedText = window.Title.Substring(0, window.Title.Length - (window.Title.Length - adjustedWidth));
                }
                else
                {
                    adjustedText = window.Title;
                }
            }

            if (!string.IsNullOrEmpty(adjustedText))
            {
                TitleAreaLength = adjustedText.Length;

                if (window.TitleAlignment == HorizontalAlignment.Left)
                {
                    TitleAreaX = 1;
                }

                else if (window.TitleAlignment == HorizontalAlignment.Center)
                {
                    TitleAreaX = ((adjustedWidth - adjustedText.Length) / 2) + 1;
                }

                else
                {
                    TitleAreaX = hostSurface.Width - 1 - adjustedText.Length;
                }

                hostSurface.Print(TitleAreaX, TitleAreaY, adjustedText, TitleStyle);
            }
        }
Пример #22
0
        /// <summary>
        /// Draws the theme to the console.
        /// </summary>
        /// <param name="console">Console associated with the theme.</param>
        /// <param name="hostSurface">Surface used for drawing.</param>
        public virtual void Draw(ControlsConsole console, CellSurface hostSurface)
        {
            Colors colors = console.ThemeColors ?? Library.Default.Colors;

            FillStyle = colors.Appearance_ControlNormal;

            hostSurface.DefaultForeground = FillStyle.Foreground;
            hostSurface.DefaultBackground = FillStyle.Background;
            hostSurface.Fill(hostSurface.DefaultForeground, hostSurface.DefaultBackground, FillStyle.Glyph, null);
        }
Пример #23
0
        public BorderComponent(int[] connectedLineStyle, Color foreground, Color background)
        {
            if (!CellSurface.ValidateLineStyle(connectedLineStyle))
            {
                throw new ArgumentException("The connected line array is invalid.", nameof(connectedLineStyle));
            }

            _borderGlyphs    = connectedLineStyle;
            _borderCellStyle = new Cell(foreground, background);
        }
Пример #24
0
        private void PrintStatStatus(int x, int y, PlayerStats stat, CellSurface surface)
        {
            int symbol = ' ';

            if (SelectedStat.HasValue && SelectedStat.Value == stat)
            {
                symbol = Glyphs.GetGlyph('▲');
            }
            surface.Print(x + maxStatNameLength + 5, y, new ColoredGlyph(symbol, TextHelper.PositiveValueColor.ToXna(), DefaultBackground));
        }
Пример #25
0
        private void PrintPlayerStats(int dX, int dY, CellSurface surface)
        {
            surface.Print(dX, dY, "Stats:");

            var stats     = Enum.GetValues(typeof(PlayerStats)).Cast <PlayerStats>().ToArray();
            var maxLength = stats.Select(TextHelper.GetStatName).Select(name => name.Length).Max();

            for (var index = 0; index < stats.Length; index++)
            {
                var stat = stats[index];

                var pureValue  = Player.GetPureStat(stat);
                var bonusValue = Player.Equipment.GetStatsBonus(stat);

                var name = TextHelper.GetStatName(stat);

                var y = dY + 2 + index;
                surface.Print(dX, y, name);
                var bonusText = new StyledLine
                {
                    pureValue.ToString()
                };
                if (bonusValue != 0)
                {
                    var bonusSymbol = bonusValue > 0 ? "+" : "-";
                    var bonusColor  = bonusValue > 0 ? TextHelper.PositiveValueColor : TextHelper.NegativeValueColor;
                    bonusText.Add(" (");
                    bonusText.Add($"{bonusSymbol}{bonusValue}", bonusColor);
                    bonusText.Add(")");
                }
                surface.PrintStyledText(dX + maxLength + 1, y, bonusText.ToColoredString(DefaultBackground));
            }

            var xPos = dX + maxLength + 10;

            surface.PrintStyledText(xPos, dY + 2, new StyledLine {
                "Max Health           ", new StyledString(Player.MaxHealth.ToString(), TextHelper.HealthColor)
            }.ToColoredString(DefaultBackground));
            surface.PrintStyledText(xPos, dY + 3, new StyledLine {
                "Max Mana             ", new StyledString(Player.MaxMana.ToString(), TextHelper.ManaColor)
            }.ToColoredString(DefaultBackground));
            surface.PrintStyledText(xPos, dY + 4, new StyledLine {
                "Mana Regeneration    ", new StyledString(Player.ManaRegeneration.ToString(), TextHelper.ManaRegenerationColor)
            }.ToColoredString(DefaultBackground));
            surface.PrintStyledText(xPos, dY + 5, new StyledLine {
                "Dodge Chance         ", $"{Player.DodgeChance}%"
            }.ToColoredString(DefaultBackground));

            surface.PrintStyledText(dX, dY + 4 + stats.Length, new StyledLine {
                $"Level: {Player.Level}"
            }.ToColoredString(DefaultBackground));
            surface.PrintStyledText(dX, dY + 5 + stats.Length, new StyledLine {
                "XP:    ", new StyledString($"{Player.Experience} / {Player.GetXpToLevelUp()}", TextHelper.XpColor)
            }.ToColoredString(DefaultBackground));
        }
        private CellSurface PrintingCells()
        {
            CellSurface surface = new CellSurface(3, 3);

            surface.DefaultBackground = Color.Transparent;
            surface.DefaultForeground = Color.DarkGoldenrod;
            surface.SetGlyph(0, 0, ' '); surface.SetGlyph(1, 0, ' '); surface.SetGlyph(2, 0, ' ');
            surface.SetGlyph(0, 1, '('); surface.SetGlyph(1, 1, ' '); surface.SetGlyph(2, 1, ')');
            surface.SetGlyph(0, 2, ' '); surface.SetGlyph(1, 2, ' '); surface.SetGlyph(2, 2, '\\');
            return(surface);
        }
Пример #27
0
 /// <summary>
 /// Creates a new instance of the CellsRenderer class with an existing cell data and a SpriteBatch to render with.
 /// </summary>
 /// <param name="cellData">The cell data.</param>
 /// <param name="spriteBatch">The SpriteBatch used for rendering.</param>
 public CellsRenderer(CellSurface cellData, SpriteBatch spriteBatch)
 {
     Batch = spriteBatch;
     DoUpdate = true;
     _isVisible = true;
     Position = new Point(0, 0);
     Tint = Color.Transparent;
     CellData = cellData;
     ResetViewArea();
     Font = Engine.DefaultFont;
     UpdateOnlyViewCells = true;
 }
Пример #28
0
        protected override void DrawView(CellSurface surface)
        {
            base.DrawView(surface);

            surface.Print(3, 2, "Edit spell file, fill all data and click OK to continue.");
            surface.Print(3, 4, "Spell Name:");
            surface.Print(3, 7, "Mana Cost:");

            surface.Print(3, Height - 5,
                          new ColoredString("Don't forget to save spell file changes before pressing OK.",
                                            new Cell(Color.Red, DefaultBackground)));
        }
Пример #29
0
        private ParseCommandBase CustomParseCommand(string command, string parameters, ColoredGlyph[] glyphString,
                                                    CellSurface surface, ParseCommandStacks commandStacks)
        {
            switch (command)
            {
            case "t":
                return(new ParseCommandRetext(parameters));

            default:
                return(null);;
            }
        }
Пример #30
0
        public void Draw(CellSurface surface)
        {
            if (BorderAppearance == null)
            {
                BorderAppearance = new CellAppearance(Color.Blue, Color.Black, 4);
            }

            Algorithms.Circle(Center.X, Center.Y, Radius, (x, y) => { if (surface.IsValidCell(x, y))
                                                                      {
                                                                          surface.SetCellAppearance(x, y, BorderAppearance);
                                                                      }
                              });
        }
Пример #31
0
        protected override void DrawView(CellSurface surface)
        {
            base.DrawView(surface);

            // Journal box frame
            surface.Print(0, Height - 11, new ColoredGlyph(Glyphs.GetGlyph('╟'), FrameColor, DefaultBackground));
            surface.Print(1, Height - 11, new ColoredGlyph(Glyphs.GetGlyph('─'), FrameColor, DefaultBackground));
            surface.Print(Width - 1, Height - 11, new ColoredGlyph(Glyphs.GetGlyph('╢'), FrameColor, DefaultBackground));

            // Player stats frame
            surface.Print(Width - 40, 0, new ColoredGlyph(Glyphs.GetGlyph('╤'), FrameColor, DefaultBackground));
            surface.Print(Width - 1, 3, new ColoredGlyph(Glyphs.GetGlyph('╢'), FrameColor, DefaultBackground));
        }
Пример #32
0
        /// <summary>
        /// Creates a new instance of the CellsRenderer class with an existing cell data and a SpriteBatch to render with.
        /// </summary>
        /// <param name="cellData">The cell data.</param>
        /// <param name="spriteBatch">The SpriteBatch used for rendering.</param>
        public CellsRenderer(CellSurface cellData, SpriteBatch spriteBatch)
        {
            Batch               = spriteBatch;
            DoUpdate            = true;
            _isVisible          = true;
            Position            = new Point(0, 0);
            Tint                = Color.Transparent;
            Font                = Engine.DefaultFont;
            UpdateOnlyViewCells = true;

            CellData = cellData;
            ResetViewArea();
        }
Пример #33
0
        protected override void DrawView(CellSurface surface)
        {
            base.DrawView(surface);

            surface.Print(2, 1, "Game Settings");

            surface.Print(2, 4, "Spell Editor Application:");
            surface.Print(2, 5, new ColoredString(SpellEditorPath, new Cell(Color.Gray, DefaultBackground)));

            surface.Print(2, 10, "Font Size:");
            surface.Clear(15, 10, 10);
            surface.Print(15, 10, new ColoredString(FontSizeName, Color.Gray, DefaultBackground));
        }
Пример #34
0
        public void Draw(CellSurface surface)
        {
            for (int x = Location.X; x < Location.X + Width; x++)
            {
                for (int y = Location.Y; y < Location.Y + Height; y++)
                {
                    // Top row
                    if (y == Location.Y)
                    {
                        if (x == Location.X)
                            PlotCell(surface, x, y, TopLeftCharacter);
                        else if (x == Location.X + Width - 1)
                            PlotCell(surface, x, y, TopRightCharacter);
                        else
                            PlotCell(surface, x, y, TopSideCharacter);
                    }

                    // Bottom row
                    else if (y == Location.Y + Height - 1)
                    {
                        if (x == Location.X)
                            PlotCell(surface, x, y, BottomLeftCharacter);
                        else if (x == Location.X + Width - 1)
                            PlotCell(surface, x, y, BottomRightCharacter);
                        else
                            PlotCell(surface, x, y, BottomSideCharacter);
                    }

                    // Other rows
                    else
                    {
                        if (x == Location.X)
                            PlotCell(surface, x, y, LeftSideCharacter);
                        else if (x == Location.X + Width - 1)
                            PlotCell(surface, x, y, RightSideCharacter);
                        else if (Fill)
                            PlotCell(surface, x, y, 0, Fill);
                    }
                    
                }
            }

        }
Пример #35
0
        /// <summary>
        /// Draws the line shape.
        /// </summary>
        /// <param name="surface">The cell surface to draw on.</param>
        public void Draw(CellSurface surface)
        {
            List<Cell> cells = new List<Cell>();

            Algorithms.Line(StartingLocation.X, StartingLocation.Y, EndingLocation.X, EndingLocation.Y, (x, y) => { cells.Add(surface[x, y]); return true; });

            if (cells.Count > 1)
            {
                if (UseStartingCell)
                {
                    StartingCellAppearance.Copy(cells[0]);
                    surface.SetEffect(cells[0], StartingCellAppearance.Effect);
                }
                else
                {
                    CellAppearance.Copy(cells[0]);
                    surface.SetEffect(cells[0], CellAppearance.Effect);
                }

                if (UseEndingCell)
                {
                    EndingCellAppearance.Copy(cells[cells.Count - 1]);
                    surface.SetEffect(cells[cells.Count - 1], EndingCellAppearance.Effect);
                }
                else
                {
                    CellAppearance.Copy(cells[cells.Count - 1]);
                    surface.SetEffect(cells[cells.Count - 1], CellAppearance.Effect);
                }

                for (int i = 1; i < cells.Count - 1; i++)
                {
                    CellAppearance.Copy(cells[i]);
                    surface.SetEffect(cells[i], CellAppearance.Effect);
                }
            }
            else if (cells.Count == 1)
            {
                CellAppearance.Copy(cells[0]);
                surface.SetEffect(cells[0], CellAppearance.Effect);
            }
        }
Пример #36
0
        public static void DrawImageToSurface(this Texture2D texture, CellSurface surface, Point position, bool useBackground, Func<Color, Color, Color> blendOperation = null)
        {
            Color[] pixels = new Color[texture.Width * texture.Height];
            texture.GetData<Color>(pixels);

            int startX = position.X;
            int widthCounter = 0;

            for (int i = 0; i < pixels.Length; i++)
            {
                if (widthCounter >= texture.Width)
                {
                    widthCounter = 0;
                    position.X = startX;
                    position.Y++;
                }

                if (surface.IsValidCell(position.X, position.Y))
                {
                    int destinationIndex = position.ToIndex(surface.Width);

                    if (useBackground)
                    {
                        if (blendOperation == null)
                            surface[destinationIndex].Background = pixels[i];
                        else
                            surface[destinationIndex].Background = blendOperation(surface[destinationIndex].Background, pixels[i]);
                    }
                    else
                    {
                        if (blendOperation == null)
                            surface[destinationIndex].Foreground = pixels[i];
                        else
                            surface[destinationIndex].Foreground = blendOperation(surface[destinationIndex].Foreground, pixels[i]);
                    }
                }

                position.X++;
                widthCounter++;
            }
        }
Пример #37
0
        public override void Render()
        {
            // These 3 render calls are a hack to get the console data generated and display a message to the user
            // Should add in async calls that let us generate these in the background... That would be cool.

            if (!initialized)
                base.Render();

            else if(!initializedStep2)
            {
                initializedStep2 = true;
                base.Render();
            }
            else if (!initializedStep3)
            {
                base.Render();

                // Generate the content
                mainData = new CellSurface(2000, 2000);

                // Clear message data and make it transparent so that it acts as a layer
                messageData.CellData.Fill(Color.White, Color.Transparent, 0, null);

                // We need to set celldata to the big console data so we can use the FillWithRandom method.
                CellData = mainData;
                ViewArea = new Rectangle(0, 0, 80, 25);
                FillWithRandomGarbage();
                initializedStep3 = true;
            }

            else
            {
                // Set message data information about where the viewport is located
                messageData.CellData.Print(0, 0, $"{ViewArea.X} , {ViewArea.Y}            ", Color.White, Color.Black);

                // Create a faux layering system.
                base.Render();
                messageData.Render();
            }
        }
Пример #38
0
        private void PlotCell(CellSurface surface, int x, int y, int character, bool fillMe = false)
        {
            if (surface.IsValidCell(x,y))
            {
                var cell = surface[x, y];

                if (fillMe)
                {
                    cell.Background = FillColor;
                    cell.Foreground = Foreground;
                    cell.CharacterIndex = character;
                    return;
                }

                if (Foreground != Color.Transparent || DrawTransparency)
                    cell.Foreground = Foreground;

                if (BorderBackground != Color.Transparent || DrawTransparency)
                    cell.Background = BorderBackground;

                cell.CharacterIndex = character;
            }
        }
Пример #39
0
        /// <summary>
        /// Converts a <see cref="TileLayer"/> to a <see cref="CellSurface"/>.
        /// </summary>
        /// <returns>The convereted surface.</returns>
        public CellSurface ToCellSurface()
        {
            var cells = new CellSurface(Tiles.GetUpperBound(1), Tiles.GetUpperBound(0));
            var transparentColor = new Microsoft.Xna.Framework.Color(255, 0, 255);
            cells.Fill(Microsoft.Xna.Framework.Color.Black, Microsoft.Xna.Framework.Color.Transparent, 0, null);

            for (int y = 0; y < cells.Height; y++)
            {
                for (int x = 0; x < cells.Width; x++)
                {
                    var tile = Tiles[y, x];
                    var backgroundColor = new Microsoft.Xna.Framework.Color(tile.BackgroundRed, tile.BackgroundGreen, tile.BackgroundBlue);
                    if (backgroundColor != transparentColor)
                    {
                        var cell = cells[x, y];
                        cell.CharacterIndex = tile.CharacterCode;
                        cell.Foreground = new Microsoft.Xna.Framework.Color(tile.ForegroundRed, tile.ForegroundGreen, tile.ForegroundBlue);
                        cell.Background = backgroundColor; 
                    }
                }
            }

            return cells;
        }
Пример #40
0
        ///// <summary>
        ///// Renders the entity using the specified sprite batch. This method will not call Batch.Begin and Batch.End.
        ///// </summary>
        ///// <param name="batch">The sprite batch to render the entity.</param>
        //public void Render(SpriteBatch batch)
        //{
        //    var oldBatch = base.Batch;
        //    base.Batch = batch;
        //    base._skipBatchBeginEnd = true;
        //    base.Render();
        //    base.Batch = oldBatch;
        //    base._skipBatchBeginEnd = false;
        //}

        /// <summary>
        /// Renders the current entity's animation frame to a surface using the <see cref="Position"/> property for the location.
        /// </summary>
        /// <param name="surface">The surface to print the frame on.</param>
        public void RenderToSurface(CellSurface surface)
        {
            this.RenderToSurface(surface, this.Position);
        }
Пример #41
0
        public void Draw(CellSurface surface)
        {
            // box is on the console area
            if (Location.X < surface.Width && Location.Y < surface.Height)
            {
                // box is on the console area
                if (Location.X + Width > 0 && Location.Y + Height > 0)
                {
                    int workingWidth;
                    int workingHeight;
                    int workingX;
                    int workingY;

                    // Flags for drawing sides of the box
                    bool drawLeft = Location.X >= 0 && Location.X < surface.Width;
                    bool drawRight = Location.X + Width >= 0 && Location.X + Width <= surface.Width;
                    bool drawTop = Location.Y >= 0 && Location.Y < surface.Height;
                    bool drawBottom = Location.Y + Height >= 0 && Location.Y + Height <= surface.Height;

                    // Predict X and Y start.
                    if (drawLeft)
                        workingX = Location.X;
                    else
                        workingX = 0;

                    if (drawTop)
                        workingY = Location.Y;
                    else
                        workingY = 0;

                    // Predict the width and height.
                    if (workingX + Width <= surface.Width)
                        workingWidth = Width;
                    else
                        workingWidth = surface.Width - workingX;

                    if (workingY + Height <= surface.Height)
                        workingHeight = Height;
                    else
                        workingHeight = surface.Height - workingY;

                    // Fill
                    if (Fill)
                        surface.FillArea(new Rectangle(workingX, workingY, workingWidth, workingHeight), Foreground, FillColor, 0, null);

                    // Drawing top\bottom
                    if (drawTop && drawBottom)
                    {
                        int topStartingIndex = surface.GetIndexFromPoint(workingX, workingY);
                        int bottomStartingIndex = topStartingIndex + (surface.Width * (workingHeight - 1));

                        for (int x = 0; x < workingWidth; x++)
                        {
                            if (Foreground != Color.Transparent || DrawTransparency)
                            {
                                surface[topStartingIndex + x].Foreground = Foreground;
                                surface[bottomStartingIndex + x].Foreground = Foreground;
                            }
                            if (BorderBackground != Color.Transparent || DrawTransparency)
                            {
                                surface[topStartingIndex + x].Background = BorderBackground;
                                surface[bottomStartingIndex + x].Background = BorderBackground;
                            }

                            surface[topStartingIndex + x].CharacterIndex = TopSideCharacter;
                            surface[bottomStartingIndex + x].CharacterIndex = BottomSideCharacter;
                        }
                    }
                    else if (drawTop)
                    {
                        int topStartingIndex = surface.GetIndexFromPoint(workingX, workingY);

                        for (int x = 0; x < workingWidth; x++)
                        {
                            if (Foreground != Color.Transparent || DrawTransparency)
                                surface[topStartingIndex + x].Foreground = Foreground;

                            if (BorderBackground != Color.Transparent || DrawTransparency)
                                surface[topStartingIndex + x].Background = BorderBackground;

                            surface[topStartingIndex + x].CharacterIndex = TopSideCharacter;
                        }
                    }
                    else
                    {
                        int bottomStartingIndex = surface.GetIndexFromPoint(workingX, workingY + workingHeight - 1);

                        for (int x = 0; x < workingWidth; x++)
                        {
                            if (Foreground != Color.Transparent || DrawTransparency)
                                surface[bottomStartingIndex + x].Foreground = Foreground;

                            if (BorderBackground != Color.Transparent || DrawTransparency)
                                surface[bottomStartingIndex + x].Background = BorderBackground;

                            surface[bottomStartingIndex + x].CharacterIndex = BottomSideCharacter;
                        }
                    }

                    // Draw left\right
                    if (drawLeft && drawRight)
                    {
                        int leftStartingIndex = surface.GetIndexFromPoint(workingX, workingY);
                        int rightStartingIndex = leftStartingIndex + workingWidth - 1;

                        for (int y = 0; y < workingHeight; y++)
                        {
                            if (Foreground != Color.Transparent || DrawTransparency)
                            {
                                surface[leftStartingIndex + (y * surface.Width)].Foreground = Foreground;
                                surface[rightStartingIndex + (y * surface.Width)].Foreground = Foreground;
                            }
                            if (BorderBackground != Color.Transparent || DrawTransparency)
                            {
                                surface[leftStartingIndex + (y * surface.Width)].Background = BorderBackground;
                                surface[rightStartingIndex + (y * surface.Width)].Background = BorderBackground;
                            }

                            surface[leftStartingIndex + (y * surface.Width)].CharacterIndex = LeftSideCharacter;
                            surface[rightStartingIndex + (y * surface.Width)].CharacterIndex = RightSideCharacter;
                        }
                    }
                    else if (drawLeft)
                    {
                        int leftStartingIndex = surface.GetIndexFromPoint(workingX, workingY);

                        for (int y = 0; y < workingHeight; y++)
                        {
                            if (Foreground != Color.Transparent || DrawTransparency)
                                surface[leftStartingIndex + (y * surface.Width)].Foreground = Foreground;

                            if (BorderBackground != Color.Transparent || DrawTransparency)
                                surface[leftStartingIndex + (y * surface.Width)].Background = BorderBackground;

                            surface[leftStartingIndex + (y * surface.Width)].CharacterIndex = LeftSideCharacter;
                        }
                    }
                    else
                    {
                        int rightStartingIndex = surface.GetIndexFromPoint(workingX + workingWidth - 1, workingY);

                        for (int y = 0; y < workingHeight; y++)
                        {
                            if (Foreground != Color.Transparent || DrawTransparency)
                                surface[rightStartingIndex + (y * surface.Width)].Foreground = Foreground;

                            if (BorderBackground != Color.Transparent || DrawTransparency)
                                surface[rightStartingIndex + (y * surface.Width)].Background = BorderBackground;

                            surface[rightStartingIndex + (y * surface.Width)].CharacterIndex = RightSideCharacter;
                        }
                    }

                    // Corners
                    if (drawTop && drawLeft)
                    {
                        int index = surface.GetIndexFromPoint(workingX, workingY);

                        if (Foreground != Color.Transparent || DrawTransparency)
                            surface[index].Foreground = Foreground;

                        if (BorderBackground != Color.Transparent || DrawTransparency)
                            surface[index].Background = BorderBackground;

                        surface[index].CharacterIndex = TopLeftCharacter;
                    }

                    if (drawTop && drawRight)
                    {
                        int index = surface.GetIndexFromPoint(workingX + workingWidth - 1, workingY);

                        if (Foreground != Color.Transparent || DrawTransparency)
                            surface[index].Foreground = Foreground;

                        if (BorderBackground != Color.Transparent || DrawTransparency)
                            surface[index].Background = BorderBackground;

                        surface[index].CharacterIndex = TopRightCharacter;
                    }

                    if (drawBottom && drawLeft)
                    {
                        int index = surface.GetIndexFromPoint(workingX, workingY + workingHeight - 1);

                        if (Foreground != Color.Transparent || DrawTransparency)
                            surface[index].Foreground = Foreground;

                        if (BorderBackground != Color.Transparent || DrawTransparency)
                            surface[index].Background = BorderBackground;

                        surface[index].CharacterIndex = BottomLeftCharacter;
                    }

                    if (drawBottom && drawRight)
                    {
                        int index = surface.GetIndexFromPoint(workingX + workingWidth - 1, workingY + workingHeight - 1);

                        if (Foreground != Color.Transparent || DrawTransparency)
                            surface[index].Foreground = Foreground;

                        if (BorderBackground != Color.Transparent || DrawTransparency)
                            surface[index].Background = BorderBackground;

                        surface[index].CharacterIndex = BottomRightCharacter;
                    }
                }
            }
        }
Пример #42
0
 protected virtual void OnCellDataChanged(CellSurface oldCells, CellSurface newCells)
 {
 }
Пример #43
0
        /// <summary>
        /// Determines the cells that would be drawn on and returns them instead of drawing the line.
        /// </summary>
        /// <param name="surface">The surface to get the cells from.</param>
        /// <returns>The cells the line would have drawn on.</returns>
        public IEnumerable<Cell> GetCells(CellSurface surface)
        {
            List<Cell> cells = new List<Cell>();

            Algorithms.Line(StartingLocation.X, StartingLocation.Y, EndingLocation.X, EndingLocation.Y, (x, y) => { cells.Add(surface[x, y]); return true; });

            return cells;
        }
Пример #44
0
 public Console(CellSurface cellData)
     : base(cellData, new SpriteBatch(Engine.Device))
 {
     _virtualCursor = new Cursor(this);
 }
Пример #45
0
 /// <summary>
 /// Renders the current entity's animation frame to a surface at the specified location.
 /// </summary>
 /// <param name="surface">The surface to print the frame on.</param>
 /// <param name="location">Specifies the cell at which the frame will be printed at.</param>
 public void RenderToSurface(CellSurface surface, Point location)
 {
     // copy the current frame of the animation to the console at the specified location
     Frame frame = _currentAnimation.CurrentFrame;
     frame.Copy(0, 0, frame.Width, frame.Height, surface, location.X, location.Y);
 }
Пример #46
0
        //public ICellAppearance FillAppearance;
        //public bool Fill;

        public void Draw(CellSurface surface)
        {
            Algorithms.Ellipse(StartingPoint.X, StartingPoint.Y, EndingPoint.X, EndingPoint.Y, (x, y) => { if (surface.IsValidCell(x, y)) surface.SetCellAppearance(x, y, BorderAppearance); });
        }