Ejemplo n.º 1
0
        // Draw an entire room.
        private void DrawRoom(Graphics2D g, Room room)
        {
            Color belowFade = new Color(255, 255, 255, 150);
            Color aboveFade = new Color(255, 255, 255, 100);
            Color hide = Color.Transparent;
            Color normal = Color.White;

            // Draw white background.
            g.FillRectangle(new Rectangle2I(Point2I.Zero, room.Size * GameSettings.TILE_SIZE), Color.White);

            // Draw tile layers.
            for (int i = 0; i < room.LayerCount; i++) {
                // Determine color/transparency for layer based on layer visibility.
                Color color = normal;
                if (!editorControl.ShouldDrawEvents) {
                    if (editorControl.CurrentLayer > i) {
                        if (editorControl.BelowTileDrawMode == TileDrawModes.Hide)
                            color = hide;
                        else if (editorControl.BelowTileDrawMode == TileDrawModes.Fade)
                            color = belowFade;
                    }
                    else if (editorControl.CurrentLayer < i) {
                        if (editorControl.AboveTileDrawMode == TileDrawModes.Hide)
                            color = hide;
                        else if (editorControl.AboveTileDrawMode == TileDrawModes.Fade)
                            color = aboveFade;
                    }
                }

                // Draw the tile grid for this layer.
                for (int x = 0; x < room.Width; x++) {
                    for (int y = 0; y < room.Height; y++) {
                        Point2I position = new Point2I(x, y) * GameSettings.TILE_SIZE;
                        TileDataInstance tile = room.GetTile(x, y, i);

                        // Draw tile.
                        if (tile != null && tile.IsAtLocation(x, y))
                            DrawTile(g, tile, position, color);

                        // Draw grid square.
                        if (i == room.LayerCount - 1) {
                            if (editorControl.ShowGrid)
                                g.DrawRectangle(new Rectangle2I(position, new Point2I(GameSettings.TILE_SIZE + 1)), 1, new Color(0, 0, 0, 150));
                        }
                    }
                }
            }

            // Draw event tiles.
            if (editorControl.ShowEvents || editorControl.ShouldDrawEvents) {
                for (int i = 0; i < room.EventData.Count; i++)
                    DrawEventTile(g, room.EventData[i], room.EventData[i].Position, Color.White);
            }

            // Draw the spacing lines between rooms.
            if (editorControl.RoomSpacing > 0) {
                g.FillRectangle(new Rectangle2I(0, room.Height * GameSettings.TILE_SIZE, room.Width * GameSettings.TILE_SIZE, editorControl.RoomSpacing), Color.Black);
                g.FillRectangle(new Rectangle2I(room.Width * GameSettings.TILE_SIZE, 0, editorControl.RoomSpacing, room.Height * GameSettings.TILE_SIZE + editorControl.RoomSpacing), Color.Black);
            }
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------
        // Overriden methods
        //-----------------------------------------------------------------------------
        protected override void Draw()
        {
            Graphics2D g = new Graphics2D(spriteBatch);

            //g.SetRenderTarget(GameData.RenderTargetGame);

            g.Begin(GameSettings.DRAW_MODE_DEFAULT);
            g.Clear(Color.White);
            g.Translate(new Vector2F(-this.HorizontalScroll.Value, -this.VerticalScroll.Value));
            g.Translate(-Tileset.SpriteSheet.Offset);
            g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero);

            Point2I tilePoint = SelectedTile * (Tileset.SpriteSheet.CellSize + Tileset.SpriteSheet.Spacing);

            g.ResetTranslation();
            g.Translate(new Vector2F(-this.HorizontalScroll.Value, -this.VerticalScroll.Value));
            g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.SpriteSheet.CellSize + 1), 1, Color.White);
            g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.SpriteSheet.CellSize - 1), 1, Color.Black);
            g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.SpriteSheet.CellSize + 3), 1, Color.Black);
            g.ResetTranslation();
            g.End();
        }
Ejemplo n.º 3
0
        // Draw an entire level.
        public void DrawLevel(Graphics2D g)
        {
            g.Clear(new Color(175, 175, 180)); // Gray background.

            // Draw the level if it is open.
            if (editorControl.IsLevelOpen) {
                // Draw the rooms.
                for (int x = 0; x < Level.Width; x++) {
                    for (int y = 0; y < Level.Height; y++) {
                        g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                        g.Translate((Vector2F)(new Point2I(x, y) * ((Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing)));
                        DrawRoom(g, Level.GetRoomAt(x, y));
                        g.ResetTranslation();
                    }
                }

                // Draw the highlight box.
                if (editorControl.HighlightMouseTile && cursorTileLocation >= Point2I.Zero) {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                    Rectangle2I box = new Rectangle2I(GetLevelTileCoordDrawPosition(cursorTileLocation), new Point2I(16, 16));
                    g.DrawRectangle(box.Inflated(1, 1), 1, Color.White);
                    g.ResetTranslation();
                }

                // Draw selection grid.
                if (selectionGridLevel == Level && !selectionGridArea.IsEmpty) {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));

                    if (selectionGrid != null) {
                        for (int i = 0; i < selectionGrid.LayerCount; i++) {
                            for (int y = 0; y < selectionGrid.Height; y++) {
                                for (int x = 0; x < selectionGrid.Width; x++) {
                                    Point2I position = GetLevelTileCoordDrawPosition(selectionGridArea.Point + new Point2I(x, y));
                                    TileDataInstance tile = selectionGrid.GetTileIfAtLocation(x, y, i);

                                    // Draw tile.
                                    if (tile != null)
                                        DrawTile(g, tile, position, Color.White);
                                }
                            }
                        }
                        // Draw event tiles.
                        if (editorControl.ShowEvents || editorControl.ShouldDrawEvents) {
                            for (int i = 0; i < selectionGrid.EventTiles.Count; i++) {
                                Point2I position = GetLevelTileCoordDrawPosition(selectionGridArea.Point) + selectionGrid.EventTiles[i].Position;
                                DrawEventTile(g, selectionGrid.EventTiles[i], position, Color.White);
                            }
                        }
                    }

                    // Draw the selection box.
                    if (!selectionBox.IsEmpty) {
                        Point2I start = GetLevelPixelDrawPosition(selectionBox.TopLeft);
                        Point2I end   = GetLevelPixelDrawPosition(selectionBox.BottomRight);
                        Rectangle2I box = new Rectangle2I(start, end - start);

                        g.DrawRectangle(box, 1, Color.White);
                        g.DrawRectangle(box.Inflated(1, 1), 1, Color.Black);
                        g.DrawRectangle(box.Inflated(-1, -1), 1, Color.Black);
                    }

                    g.ResetTranslation();
                }

                // Draw selected tiles.
                foreach (BaseTileDataInstance tile in selectedTiles) {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                    Rectangle2I bounds = tile.GetBounds();
                    bounds.Point += GetRoomDrawPosition(tile.Room);
                    g.DrawRectangle(bounds, 1, Color.White);
                    g.DrawRectangle(bounds.Inflated(1, 1), 1, Color.Black);
                    g.DrawRectangle(bounds.Inflated(-1, -1), 1, Color.Black);
                    g.ResetTranslation();
                }

                // Draw player sprite for 'Test At Position'
                Point2I roomSize = (Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing;
                Point2I tilePoint = highlightedRoom * roomSize + highlightedTile * GameSettings.TILE_SIZE;
                if (editorControl.PlayerPlaceMode && highlightedTile >= Point2I.Zero) {
                    g.DrawSprite(GameData.SPR_PLAYER_FORWARD, (Vector2F) tilePoint + new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                }
            }
        }
Ejemplo n.º 4
0
        /** <summary> Draws the debug menu. </summary> */
        private void DrawMenu(Graphics2D g, DebugMenuItem item, int pathIndex, Point2I position)
        {
            if (pathIndex >= currentPath.Count)
            return;

            int itemWidth  = 32;
            int itemHeight = 28;
            int offset = 32;
            int textOffset   = 0;
            int hotkeyOffset = 0;
            int hotkeyColumnWidth = 0;
            int textColumnWidth = 0;
            int rightPading = 24;
            //int padding = 20;
            int hotkeyColumnPadding = 20;
            if (pathIndex == 0) {
            offset = 6;
            rightPading = 8;
            hotkeyColumnPadding = 0;
            }

            // Measure the width to draw the menu at.
            for (int i = 0; i < item.Items.Count; ++i) {
            DebugMenuItem subItem = item.Items[i];

            Rectangle2I r1 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.Text, Align.Left);
            Rectangle2I r2 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.HotKey.Name, Align.Left);
            hotkeyOffset = GMath.Max(hotkeyOffset, r1.Width + offset + 10);
            itemWidth = GMath.Max(itemWidth, r1.Width + r2.Width + offset + rightPading);
            textColumnWidth   = GMath.Max(textColumnWidth, r1.Width);
            hotkeyColumnWidth = GMath.Max(hotkeyColumnWidth, r2.Width);
            }
            hotkeyOffset = offset + textColumnWidth + hotkeyColumnPadding;
            textOffset = offset;
            itemWidth = offset + textColumnWidth + hotkeyColumnPadding + hotkeyColumnWidth + rightPading;

            // Draw outline.
            Rectangle2I menuRect = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight * item.Items.Count);
            if (pathIndex == 0) {
            menuRect.Width = itemWidth * item.Items.Count;
            menuRect.Height = itemHeight;
            }
            g.DrawRectangle(menuRect, 1.0f, colorOutline);

            // Draw background.
            menuRect.Inflate(-1, -1);
            g.FillRectangle(menuRect, colorBackground);

            // Draw item list.
            for (int i = 0; i < item.Items.Count; ++i) {
            Rectangle2I r = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight);

            if (pathIndex == 0) {
                r.Inflate(0, -1);
                if (i == 0) {
                    r.X += 1;
                    r.Width -= 1;
                }
                if (i == item.Items.Count - 1)
                    r.Width -= 1;
            }
            else {
                r.Inflate(-1, 0);
                if (i == 0) {
                    r.Y += 1;
                    r.Height -= 1;
                }
                if (i == item.Items.Count - 1)
                    r.Height -= 1;
            }

            DebugMenuItem subItem = item.Items[i];

            // Draw highlight.
            if (currentPath[pathIndex] == i) {
                Rectangle2F sr = (Rectangle2I)r;
                sr.Inflate(-2, -2);
                if (controlMode == MenuControlMode.Keyboard || controlMode == MenuControlMode.GamePad || pathIndex < currentPath.Count - 1)
                    g.FillRectangle(sr, colorBackgroundHighlight);
            }
            Point2I ms = (Point2I)Mouse.GetPosition();
            if (r.Contains(ms)) {
                mouseHover = true;
                mouseHoverItem = subItem;
                Rectangle2F sr = (Rectangle2I)r;
                sr.Inflate(-2, -2);
                if (controlMode == MenuControlMode.Mouse)
                    g.FillRectangle(sr, colorBackgroundHighlight);
            }

            // Draw text label.
            string text   = subItem.Text;
            string hotkey = subItem.HotKey.Name;
            g.DrawRealString(debugMenuFont, text, new Point2I(r.Min.X + textOffset, (int)r.Center.Y), Align.Left | Align.Int, colorText);
            g.DrawRealString(debugMenuFont, hotkey, new Point2I(r.Min.X + hotkeyOffset, (int)r.Center.Y), Align.Left | Align.Int, colorHotkey);

            // Draw toggle check.
            if (subItem is ToggleMenuItem) {
                bool enabled = ((ToggleMenuItem)subItem).IsEnabled;
                SpriteEx spr = debugMenuSprites["checkbox_disabled"];
                if (enabled)
                    spr = debugMenuSprites["checkbox_enabled"];
                if (subItem is RadioButtonMenuItem) {
                    spr = debugMenuSprites["radiobutton_disabled"];
                    if (enabled)
                        spr = debugMenuSprites["radiobutton_enabled"];
                }
                g.DrawSpriteEx(spr, new Vector2F(r.Min.X + 6, r.Min.Y + 6), colorText);
            }

            // Draw submenu arrow.
            if (item != menu && subItem.Items.Count > 0) {
                g.DrawSpriteEx(debugMenuSprites["submenu_arrow"], new Vector2F(r.Max.X - 18, r.Min.Y + 6), colorArrow);
            }

            // Draw nested menu.
            if (currentPath[pathIndex] == i) {
                Point2I p = position;
                if (pathIndex == 0)
                    p.Y += itemHeight - 1;
                else
                    p.X += itemWidth - 1;

                DrawMenu(g, subItem, pathIndex + 1, p);
            }

            // Move current position.
            if (pathIndex == 0)
                position.X += itemWidth;
            else
                position.Y += itemHeight;
            }
        }
Ejemplo n.º 5
0
        // Draw an entire level.
        public void DrawLevel(Graphics2D g)
        {
            g.Clear(new Color(175, 175, 180));

            // Draw the level if it is open.
            if (editorControl.IsLevelOpen) {
                // Draw the rooms.
                for (int x = 0; x < Level.Width; x++) {
                    for (int y = 0; y < Level.Height; y++) {
                        g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                        g.Translate((Vector2F)(new Point2I(x, y) * ((Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing)));
                        DrawRoom(g, Level.GetRoomAt(x, y));
                        g.ResetTranslation();
                    }
                }

                // Draw the highlight box.
                if (editorControl.HighlightMouseTile && cursorTileLocation >= Point2I.Zero) {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                    Rectangle2I box = new Rectangle2I(GetLevelTileCoordDrawPosition(cursorTileLocation), new Point2I(16, 16));
                    g.DrawRectangle(box.Inflated(1, 1), 1, Color.White);
                    g.ResetTranslation();
                }

                // Draw the selection box.
                if (!selectionBox.IsEmpty) {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                    Point2I start = GetLevelTileCoordDrawPosition(selectionBox.TopLeft);
                    Point2I end   = GetLevelTileCoordDrawPosition(selectionBox.BottomRight);
                    Rectangle2I box = new Rectangle2I(start, end - start);
                    g.DrawRectangle(box, 1, Color.White);
                    g.DrawRectangle(box.Inflated(1, 1), 1, Color.Black);
                    g.DrawRectangle(box.Inflated(-1, -1), 1, Color.Black);
                    g.ResetTranslation();
                }

                // Draw player sprite for 'Test At Position'
                Point2I roomSize = (Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing;
                Point2I tilePoint = highlightedRoom * roomSize + highlightedTile * GameSettings.TILE_SIZE;
                if (editorControl.PlayerPlaceMode && highlightedTile >= Point2I.Zero) {
                    g.DrawSprite(GameData.SPR_PLAYER_FORWARD, tilePoint);
                }
            }
        }
Ejemplo n.º 6
0
        private static void DrawTile(Graphics2D g, Tile tile)
        {
            if (TileDebugInfoMode == TileDrawInfo.CollisionBoxes) {
                if (tile.IsSolid && tile.CollisionModel != null) {
                    foreach (Rectangle2F box in tile.CollisionModel.Boxes) {
                        Rectangle2F r = Rectangle2F.Translate(box, tile.Position);
                        g.FillRectangle(r, Color.Red);
                        //g.DrawRectangle(r, 1, Color.Maroon);
                    }
                }
            }
            else if (TileDebugInfoMode == TileDrawInfo.GridArea) {
                Rectangle2F tileBounds = (Rectangle2F) tile.TileGridArea;
                tileBounds.Point *= GameSettings.TILE_SIZE;
                tileBounds.Size *= GameSettings.TILE_SIZE;
                Color c = Color.Yellow;
                if (tile.Layer == 1)
                    c = Color.Blue;
                else if (tile.Layer == 2)
                    c = Color.Red;
                g.FillRectangle(tileBounds, c);

                tileBounds = new Rectangle2F(tile.Position, tile.Size * GameSettings.TILE_SIZE);
                c = Color.Olive;
                if (tile.Layer == 1)
                    c = Color.Cyan;
                else if (tile.Layer == 2)
                    c = Color.Maroon;

                g.DrawLine(new Line2F(tileBounds.TopLeft, tileBounds.BottomRight - new Point2I(1, 1)), 1, c);
                g.DrawLine(new Line2F(tileBounds.TopRight - new Point2I(1, 0), tileBounds.BottomLeft - new Point2I(0, 1)), 1, c);
                g.DrawRectangle(tileBounds, 1, Color.Black);
            }
        }
Ejemplo n.º 7
0
        //-----------------------------------------------------------------------------
        // Overriden methods
        //-----------------------------------------------------------------------------
        protected override void Draw()
        {
            Graphics2D g = new Graphics2D(spriteBatch);
            //g.SetRenderTarget(GameData.RenderTargetGame);
            g.Begin(GameSettings.DRAW_MODE_DEFAULT);

            Point2I selectedTileLocation = GetSelectedTileLocation();

            // Draw the tileset.
            g.Clear(Color.White);
            g.Translate(-this.HorizontalScroll.Value, -this.VerticalScroll.Value);
            if (Tileset.SpriteSheet == null) {
                // Draw each tile's sprite seperately.
                for (int y = 0; y < Tileset.Height; y++) {
                    for (int x = 0; x < Tileset.Width; x++) {
                        BaseTileData tileData = Tileset.GetTileData(x, y);
                        if (tileData != null) {
                            int spacing = 1;
                            Vector2F drawPos = new Vector2F(x, y) * (Tileset.CellSize + spacing);
                            SpriteAnimation spr = tileData.Sprite;

                            int imageVariantID = tileData.Properties.GetInteger("image_variant", Zone.ImageVariantID);
                            if (imageVariantID < 0)
                                imageVariantID = Zone.ImageVariantID;
                            if (spr.IsAnimation) {
                                int substripIndex = tileData.Properties.GetInteger("substrip_index", 0);
                                spr.Animation = spr.Animation.GetSubstrip(substripIndex);
                            }

                            g.DrawAnimation(tileData.Sprite, imageVariantID, 0.0f, drawPos, Color.White);
                        }
                    }
                }
            }
            else {
                // Draw the spritesheet's image.
                g.Translate(-Tileset.SpriteSheet.Offset);
                g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero);
                g.ResetTranslation();
            }

            // Draw the selection box.
            if (selectedTileLocation >= Point2I.Zero) {
                Point2I tilePoint = selectedTileLocation * (Tileset.CellSize + Tileset.Spacing);
                g.Translate(-this.HorizontalScroll.Value, -this.VerticalScroll.Value);
                g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.CellSize + 1), 1, Color.White);
                g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.CellSize - 1), 1, Color.Black);
                g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.CellSize + 3), 1, Color.Black);
                g.ResetTranslation();
            }

            g.End();
        }