Пример #1
0
 // Sample an event tile at the given point.
 public EventTileDataInstance SampleEventTile(Point2I point)
 {
     Room room = SampleRoom(point);
     if (room == null)
         return null;
     Point2I roomOffset = GetRoomDrawPosition(room);
     for (int i = 0; i < room.EventData.Count; i++) {
         EventTileDataInstance eventTile = room.EventData[i];
         Rectangle2I tileRect = new Rectangle2I(eventTile.Position + roomOffset, eventTile.Size * GameSettings.TILE_SIZE);
         if (tileRect.Contains(point))
             return eventTile;
     }
     return null;
 }
Пример #2
0
        //-----------------------------------------------------------------------------
        // Internal Iteration
        //-----------------------------------------------------------------------------
        private IEnumerable<BaseTileDataInstance> GetTilesInArea(Rectangle2I area)
        {
            // Make sure the area is within the level bounds.
            area = Rectangle2I.Intersect(area,
                new Rectangle2I(Point2I.Zero, roomSize * dimensions));

            // Iterate the tile grid.
            for (int x = 0; x < area.Width; x++) {
                for (int y = 0; y < area.Height; y++) {
                    LevelTileCoord coord = (LevelTileCoord) (area.Point + new Point2I(x, y));
                    Room room = GetRoom(coord);
                    if (room != null) {
                        Point2I tileLocation = GetTileLocation(coord);
                        for (int i = 0; i < roomLayerCount; i++) {
                            TileDataInstance tile = room.GetTile(tileLocation, i);
                            if (tile != null && tile.Location == tileLocation)
                                yield return tile;
                        }
                    }
                }
            }

            // Determine the collection of rooms that will contain the event tiles.
            Point2I roomAreaMin = GetRoomLocation((LevelTileCoord) area.Min);
            Point2I roomAreaMax = GetRoomLocation((LevelTileCoord) area.Max);
            Rectangle2I roomArea = new Rectangle2I(roomAreaMin, roomAreaMax - roomAreaMin + Point2I.One);
            roomArea = Rectangle2I.Intersect(roomArea, new Rectangle2I(Point2I.Zero, dimensions));
            Rectangle2I pixelArea = new Rectangle2I(
                area.Point * GameSettings.TILE_SIZE,
                area.Size  * GameSettings.TILE_SIZE);

            // Iterate event tiles.
            for (int x = roomArea.Left; x < roomArea.Right; x++) {
                for (int y = roomArea.Top; y < roomArea.Bottom; y++) {
                    Room room = rooms[x, y];
                    for (int i = 0; i < room.EventData.Count; i++) {
                        EventTileDataInstance eventTile = room.EventData[i];
                        Rectangle2I tileBounds = eventTile.GetBounds();
                        tileBounds.Point += room.Location * roomSize * GameSettings.TILE_SIZE;
                        if (pixelArea.Contains(tileBounds.Point))
                            yield return eventTile;
                    }
                }
            }
        }
Пример #3
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;
            }
        }