Ejemplo n.º 1
0
        public virtual void RenderControls(ISurface surface, bool force = false)
        {
            if ((surface.IsDirty || force) && surface.Tint.A != 255)
            {
                int                  cellCount;
                Rectangle            rect;
                Point                point;
                Controls.ControlBase control;
                Cell                 cell;
                Font                 font;
                // For each control
                for (int i = 0; i < Controls.Count; i++)
                {
                    if (Controls[i].IsVisible)
                    {
                        control   = Controls[i];
                        cellCount = control.TextSurface.Cells.Length;

                        font = control.AlternateFont == null ? surface.Font : control.AlternateFont;

                        // Draw background of each cell for the control
                        for (int cellIndex = 0; cellIndex < cellCount; cellIndex++)
                        {
                            cell = control[cellIndex];

                            if (cell.IsVisible)
                            {
                                point = BasicSurface.GetPointFromIndex(cellIndex, control.TextSurface.Width);
                                point = new Point(point.X + control.Position.X, point.Y + control.Position.Y);

                                if (surface.RenderArea.Contains(point.X, point.Y))
                                {
                                    point = new Point(point.X - surface.RenderArea.Left, point.Y - surface.RenderArea.Top);
                                    rect  = surface.RenderRects[surface.GetIndexFromPoint(point)];

                                    if (cell.Background != Color.Transparent)
                                    {
                                        Global.SpriteBatch.Draw(font.FontImage, rect, font.GlyphRects[font.SolidGlyphIndex], cell.Background, 0f, Vector2.Zero, SpriteEffects.None, 0.23f);
                                    }

                                    if (cell.Foreground != Color.Transparent)
                                    {
                                        Global.SpriteBatch.Draw(font.FontImage, rect, font.GlyphRects[cell.Glyph], cell.Foreground, 0f, Vector2.Zero, cell.Mirror, 0.26f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connects all lines in a surface based on the <paramref name="lineStyle"/> style provided.
        /// </summary>
        /// <param name="surface">The surface to process.</param>
        /// <param name="lineStyle">The array of line styles indexed by <see cref="LineRoadIndex"/>.</param>
        public static void ConnectLines(ISurface surface, int[] lineStyle)
        {
            Rectangle area = new Rectangle(0, 0, surface.Width, surface.Height);

            for (int x = 0; x < surface.Width; x++)
            {
                for (int y = 0; y < surface.Height; y++)
                {
                    Point pos   = new Point(x, y);
                    int   index = surface.GetIndexFromPoint(pos);

                    // Check if this pos is a road
                    if (!lineStyle.Contains(surface[index].Glyph))
                    {
                        continue;
                    }

                    // Get all valid positions and indexes around this point
                    var valids     = GameHelpers.Directions.GetValidDirections(pos, area);
                    var posIndexes = GameHelpers.Directions.GetDirectionIndexes(pos, area);
                    var roads      = new bool[] { false, false, false, false, false, false, false, false, false };

                    for (int i = 0; i < 8; i++)
                    {
                        if (valids[i])
                        {
                            if (lineStyle.Contains(surface[posIndexes[i]].Glyph))
                            {
                                roads[i] = true;
                            }
                        }
                    }

                    if (roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                        roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                        roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                        roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.Middle];
                        surface.IsDirty      = true;
                    }
                    else if (!roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.TopMiddleToDown];
                        surface.IsDirty      = true;
                    }
                    else if (roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.BottomMiddleToTop];
                        surface.IsDirty      = true;
                    }
                    else if (roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.RightMiddleToLeft];
                        surface.IsDirty      = true;
                    }
                    else if (roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.LeftMiddleToRight];
                        surface.IsDirty      = true;
                    }
                    else if (!roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             (roads[(int)GameHelpers.Directions.DirectionEnum.East] ||
                              roads[(int)GameHelpers.Directions.DirectionEnum.West]))
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.Top];
                        surface.IsDirty      = true;
                    }
                    else if ((roads[(int)GameHelpers.Directions.DirectionEnum.North] ||
                              roads[(int)GameHelpers.Directions.DirectionEnum.South]) &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.Left];
                        surface.IsDirty      = true;
                    }
                    else if (roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.BottomRight];
                        surface.IsDirty      = true;
                    }
                    else if (roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.BottomLeft];
                        surface.IsDirty      = true;
                    }
                    else if (!roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.TopRight];
                        surface.IsDirty      = true;
                    }
                    else if (!roads[(int)GameHelpers.Directions.DirectionEnum.North] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.South] &&
                             roads[(int)GameHelpers.Directions.DirectionEnum.East] &&
                             !roads[(int)GameHelpers.Directions.DirectionEnum.West])
                    {
                        surface[index].Glyph = lineStyle[(int)LineRoadIndex.TopLeft];
                        surface.IsDirty      = true;
                    }
                }
            }
        }