Пример #1
0
        void DrawMenu(GameTime gameTime, ViewRect viewRect)
        {
            if (IsClosed || !IsInitialized || !Activated || Hidden)
            {
                return;
            }

            viewRect.Add(MasterBoundaries);
            IRender render = GraphicsManager.GetRender();

            int x = RealX;
            int y = RealY;

            int posX  = x + menuItemMarginX;
            int posY  = y + Height / 2 - Font.CharHeight / 2;
            int count = 0;

            foreach (var item in MenuItems)
            {
                int strinW = Font.MeasureString(item.Name).X;

                if (count == SelectedMenuItem && ItemIsOpen)
                {
                    render.Begin();

                    Color color = count == SelectedMenuItem && item.Enabled ? FontHighlightColor : FontColor;

                    render.DrawHorizontalLine(new Point(posX, y + menuItemMarginY), strinW, DropdownBorder);
                    render.DrawVerticalLine(new Point(posX, y + menuItemMarginY), Height - menuItemMarginY + toolbarDropdownMargin, DropdownBorder);
                    render.DrawVerticalLine(new Point(posX + strinW, y + menuItemMarginY), Height - menuItemMarginY + toolbarDropdownMargin, DropdownBorder);

                    render.DrawRect(new Rectangle(posX + 1, y + menuItemMarginY + 1, strinW - 2, Height - menuItemMarginY + toolbarDropdownMargin - 2), DropdownBody);

                    Font.DrawString(item.Name, new Point(posX + 1, posY), color, render);

                    //DropdownMenu

                    int top = y + Height + toolbarDropdownMargin - 1;

                    render.DrawHorizontalLine(new Point(posX + strinW, top), dropdownMenuWidth - strinW, DropdownBorder);
                    render.DrawHorizontalLine(new Point(posX, top + dropdownMenuHeight), dropdownMenuWidth, DropdownBorder);
                    render.DrawVerticalLine(new Point(posX, top), dropdownMenuHeight, DropdownBorder);
                    render.DrawVerticalLine(new Point(posX + dropdownMenuWidth - 1, top), dropdownMenuHeight, DropdownBorder);

                    render.DrawRect(new Rectangle(posX + 1, top + 1, dropdownMenuWidth - 3, dropdownMenuHeight - 2), DropdownBody);

                    int elemX        = posX;
                    int elemY        = top + menuElemMarginY;
                    var selectedItem = MenuItems[SelectedMenuItem];
                    int c            = 0;
                    foreach (var elem in selectedItem.Elements)
                    {
                        int elemH;
                        if (elem.Name != null)
                        {
                            elemH = Font.MeasureString(elem.Name).Y + menuElemMarginY;
                        }
                        else
                        {
                            elemH = separatorHeight;
                        }

                        if (c == SelectedMenuElement && item.Enabled && elem.Enabled)
                        {
                            render.DrawRect(new Rectangle(elemX + 1, elemY - menuElemMarginY + 2, dropdownMenuWidth - 3, elemH - 2), ElementHighlightColor);
                        }

                        if (elem.IsSeparator)
                        {
                            render.DrawLine(new Vector2(elemX + separatorMargin, elemY + separatorHeight / 2),
                                            new Vector2(elemX + dropdownMenuWidth - separatorMargin, elemY + separatorHeight / 2), SeparatorColor);
                        }
                        else
                        {
                            Font.DrawString(elem.Name, new Point(elemX + menuElemMarginX, elemY), FontColor, render);
                        }

                        elemY += elemH;

                        c += 1;
                    }

                    render.End();
                }

                posX  += strinW + menuItemMarginX;
                count += 1;
            }

            render.Reset();
        }
Пример #2
0
        public override void Project(GameTime gameTime, int x, int y, IRender render)
        {
            render.Begin();

            if (World == null)
            {
                Font.DrawString("No World", new Point(x + Width / 2, y + Height / 2), new Vector2(0, 0), Color.White, render);
                render.End();
                return;
            }

            float originX = ViewCamera.LookX;
            float originY = ViewCamera.LookY;

            if (ShowRegions)
            {
                var gridColor = new Color(100, 100, 100, 100);

                int width      = (int)Math.Round(World.Width * ViewCamera.Zoom);
                int height     = (int)Math.Round(World.Height * ViewCamera.Zoom);
                int regionSize = (int)Math.Round(World.RegionSize * ViewCamera.Zoom);

                int stop = width + x;
                for (int gridX = x; gridX < stop; gridX += regionSize)
                {
                    render.DrawLine(new Vector2(gridX - originX, y - originY), new Vector2(gridX - originX, y + height - originY), gridColor);
                }

                stop = height + y;
                for (int gridY = y; gridY < stop; gridY += regionSize)
                {
                    render.DrawLine(new Vector2(x - originX, gridY - originY), new Vector2(x + width - originX, gridY - originY), gridColor);
                }
            }

            foreach (Entity entity in World.EntityList)
            {
                //Color color = entity.EntityColor;

                //switch (entity.EntityName)
                //{
                //    case "Creature":
                //        sprite = Creature;

                //        double energyQ = ((Creature)entity).Energy.Value / ((Creature)entity).Energy.Max;
                //        color.R = (byte)Math.Round(color.R * energyQ, 0);
                //        color.G = (byte)Math.Round(color.G * energyQ, 0);
                //        color.B = (byte)Math.Round(color.B * energyQ, 0);
                //        break;
                //    case "Food":
                //        sprite = Food;
                //        break;
                //}

                Type eType = entity.GetType();

                int       radius   = (int)Math.Round(entity.Radius * ViewCamera.Zoom);
                Rectangle destRect = new Rectangle((int)Math.Round(x - originX + entity.Position.X * ViewCamera.Zoom, 0),
                                                   (int)Math.Round(y - originY + entity.Position.Y * ViewCamera.Zoom, 0),
                                                   radius * 2,
                                                   radius * 2);

                if (EntityPaintersDictionary.ContainsKey(eType))
                {
                    foreach (var painter in EntityPaintersDictionary[eType])
                    {
                        painter.Draw(gameTime, entity, destRect.X, destRect.Y, ViewCamera.Zoom, render);
                    }
                }

                //render.DrawSprite(sprite, destRect, new Vector2(radius, radius), Color.Red, (float)entity.Rotation);

                if (entity == SelectedEntity)
                {
                    destRect.X -= destRect.Width / 2;
                    destRect.Y -= destRect.Height / 2;

                    render.DrawHorizontalLine(new Point(destRect.X, destRect.Y), destRect.Width, Color.White);
                    render.DrawHorizontalLine(new Point(destRect.X, destRect.Bottom), destRect.Width, Color.White);
                    render.DrawVerticalLine(new Point(destRect.X, destRect.Y), destRect.Height, Color.White);
                    render.DrawVerticalLine(new Point(destRect.Right, destRect.Y), destRect.Height, Color.White);
                }

                //if (entity.EntityName == "Creature" && entity == infoDrawCreature)
                //{
                //    var creature = (Creature)entity;
                //    double rotation = (creature.Rotation - creature.EyeSpan / 2);
                //    double rotationStep = creature.EyeSpan / creature.EyeNeuronsAmount;
                //    float length = infoDrawCreature.ViewDistance;

                //    for (int i = 0; i < creature.EyeNeuronsAmount + 1; i++)
                //    {
                //        float posX = (float)destRect.X;
                //        float posY = (float)destRect.Y;
                //        float lineX = (float)Math.Cos(rotation) * length + posX;
                //        float lineY = (float)Math.Sin(rotation) * length + posY;
                //        render.DrawLine(new Vector2(posX, posY), new Vector2(lineX, lineY), Color.Red);
                //        rotation += rotationStep;
                //    }
                //}
            }

            int tX = 10 + x;
            int tY = 30 + y;

            foreach (string s in stringsToDraw)
            {
                Font.DrawString(s, new Point(tX, tY), Color.White, render);
                tY += Font.CharHeight + 2;
            }

            stringsToDraw.Clear();

            render.End();
        }