Exemple #1
0
        /// <summary>
        /// Draws this MenuUI at the specified position.
        /// </summary>
        /// <param name="position">The position of the top-left corner of the menu.</param>
        /// <param name="batch">The sprite batch to draw with.</param>
        /// <param name="screenSize">The size of the screen.</param>
        public void Draw(Vector2 position, SpriteBatch batch, Vector2 screenSize)
        {
            position = new Vector2((int)position.X, (int)position.Y);

            if (DrawBackground)
            {
                batch.Texture(position, Parent.Assets.Get <Texture2D>("ui/menu_corner.png"), Color.White * _alpha, null, null, 0, null, SpriteEffects.None);
                batch.Texture(position + new Vector2((int)Area.Value.X - 7, 0), Parent.Assets.Get <Texture2D>("ui/menu_corner.png"), Color.White * _alpha, null, null, 0, null, SpriteEffects.FlipHorizontally);
                batch.Texture(position + new Vector2(0, (int)Area.Value.Y - 7), Parent.Assets.Get <Texture2D>("ui/menu_corner.png"), Color.White * _alpha, null, null, 0, null, SpriteEffects.FlipVertically);
                batch.Texture(position + new Vector2((int)Area.Value.X - 7, (int)Area.Value.Y - 7), Parent.Assets.Get <Texture2D>("ui/menu_corner.png"), Color.White * _alpha, null, null, 0, null, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically);
            }

            Vector2 fillArea = Area.Value - new Vector2(7 * 2, 7 * 2);

            if (DrawBackground)
            {
                batch.Rectangle(new Rectangle((int)position.X + 7, (int)position.Y + 7, (int)fillArea.X, (int)fillArea.Y), new Color(68, 68, 242) * _alpha);
            }

            batch.SamplerState = SamplerState.PointWrap;

            if (DrawBackground)
            {
                batch.Texture(new Rectangle((int)position.X + 7, (int)position.Y, (int)fillArea.X, 7), Parent.Assets.Get <Texture2D>("ui/menu_top.png"), Color.White * _alpha);
                batch.Texture(new Rectangle((int)position.X + 7, (int)position.Y + (int)Area.Value.Y - 7, (int)fillArea.X, 7), Parent.Assets.Get <Texture2D>("ui/menu_top.png"), Color.White * _alpha, null, 0, null, SpriteEffects.FlipVertically);

                batch.Texture(new Rectangle((int)position.X, (int)position.Y + 7, 7, (int)fillArea.Y), Parent.Assets.Get <Texture2D>("ui/menu_side.png"), Color.White * _alpha);
                batch.Texture(new Rectangle((int)position.X + (int)Area.Value.X - 7, (int)position.Y + 7, 7, (int)fillArea.Y), Parent.Assets.Get <Texture2D>("ui/menu_side.png"), Color.White * _alpha, null, 0, null, SpriteEffects.FlipHorizontally);
            }

            batch.Scissor = new Rectangle((int)position.X + 7, (int)position.Y + 7, (int)fillArea.X, (int)fillArea.Y);
            Vector2 transformLT = Vector2.Transform(batch.Scissor.Value.Location.ToVector2(), batch.Transform);
            Vector2 transformRB = Vector2.Transform(new Vector2(batch.Scissor.Value.Right, batch.Scissor.Value.Bottom), batch.Transform);

            batch.Scissor = new Rectangle(
                (int)transformLT.X,
                (int)transformLT.Y,
                (int)(transformRB.X - transformLT.X),
                (int)(transformRB.Y - transformLT.Y));
            if (Area.Value == Area.TargetValue && _alpha.Value == 1)
            {
                SelectedPage.DrawInsideArea(batch,
                                            new Rectangle((int)position.X + 7, (int)position.Y + 7, (int)fillArea.X, (int)fillArea.Y));
            }

            batch.Scissor = null;
        }
Exemple #2
0
        public static Vector2 ScaleBatch(SpriteBatch batch)
        {
            double scale = Math.Min((double)batch.Device.Viewport.Width / (1920 / 4), (double)batch.Device.Viewport.Height / (1080 / 4));

            if (scale > 1)
            {
                scale = Math.Floor(scale);
            }

            Point     size      = new Point((int)((1920 / 4) * scale), (int)((1080 / 4) * scale));
            Rectangle rectangle = new Rectangle(batch.Device.Viewport.Width / 2 - size.X / 2, batch.Device.Viewport.Height / 2 - size.Y / 2, size.X, size.Y);

            batch.Transform    = Matrix.CreateScale((float)scale) * Matrix.CreateTranslation(rectangle.X, rectangle.Y, 0);
            batch.SamplerState = SamplerState.PointClamp;

            return(new Vector2(1920 / 4, 1080 / 4));
        }
Exemple #3
0
        public static void BlackBorders(SpriteBatch batch)
        {
            double scale = Math.Min((double)batch.Device.Viewport.Width / (1920 / 4), (double)batch.Device.Viewport.Height / (1080 / 4));

            if (scale > 1)
            {
                scale = Math.Floor(scale);
            }

            Point     size      = new Point((int)((1920 / 4) * scale), (int)((1080 / 4) * scale));
            Rectangle rectangle = new Rectangle(batch.Device.Viewport.Width / 2 - size.X / 2, batch.Device.Viewport.Height / 2 - size.Y / 2, size.X, size.Y);

            batch.Scissor   = null;
            batch.Transform = Matrix.Identity;

            batch.Rectangle(new Rectangle(0, 0, batch.Device.Viewport.Width, rectangle.Y), Color.Black);
            batch.Rectangle(new Rectangle(0, rectangle.Y + rectangle.Height, batch.Device.Viewport.Width, batch.Device.Viewport.Height), Color.Black);
            batch.Rectangle(new Rectangle(0, 0, rectangle.X, batch.Device.Viewport.Height), Color.Black);
            batch.Rectangle(new Rectangle(rectangle.X + rectangle.Width, 0, batch.Device.Viewport.Width, batch.Device.Viewport.Height), Color.Black);
        }
Exemple #4
0
        public override void Draw(SpriteBatch batch, Vector2 screenSize)
        {
            _lastState.Draw(batch, screenSize);
            batch.Rectangle(new Rectangle(0, 0, (int)screenSize.X, (int)screenSize.Y), Color.Black * 0.85f);

            Vector2 measure = Game.DefaultFonts.MonoBold.Measure(24, _targetMap + "|");

            batch.Text(SpriteBatch.FontStyle.MonoBold, 24, _targetMap + (Game.TotalFixedUpdates % 40 > 20 ? "|" : " "), new Vector2(screenSize.X / 2 - measure.X / 2, 180), Color.White);

            string match  = FindClosestMatch();
            bool   exists = File.Exists(match);
            string msg    = match.Replace("\\", "/") + (Map.IsPreloaded(match) ? " (preloaded)" : "");

            if (!exists)
            {
                msg = "No map with name \"" + _targetMap + "\" found in any folder";
            }

            measure = Game.DefaultFonts.MonoBold.Measure(14, msg);
            batch.Text(SpriteBatch.FontStyle.MonoBold, 14, msg, new Vector2(screenSize.X / 2 - measure.X / 2, 210), exists ? Color.White * 0.7f : Color.Red * 0.7f);
        }
Exemple #5
0
        public override void Draw(SpriteBatch batch, Vector2 screenSize)
        {
            batch.Transform = Camera.Transform;

            int x, y;

            for (x = 0; x < Field.Width; x++)
            {
                for (y = 0; y < Field.Height; y++)
                {
                    string texture = "empty.png";

                    if (Field.FlagAt(x, y) == FlagType.Flag)
                    {
                        texture = "flag.png";
                    }
                    if (Field.FlagAt(x, y) == FlagType.FlagVisual)
                    {
                        texture = "flagvisual.png";
                    }

                    if (Field.IsRevealed(x, y))
                    {
                        texture = "revealed.png";
                    }

                    // TODO: när man förlorar revealas alla
                    if (Field.IsRevealed(x, y) && Field[x, y])
                    {
                        texture = "nuke.png";
                    }

                    Rectangle rect = new Rectangle(
                        x * (TILE_SIZE + 2), y * (TILE_SIZE + 2),
                        TILE_SIZE, TILE_SIZE);

                    batch.Texture(rect,
                                  Assets.Get <Texture2D>("placeholder/tiles/" + texture),
                                  Color.White);

                    if (Field.IsRevealed(x, y) && !Field[x, y] && Field.SurroundingNukesAt(x, y) > 0)
                    {
                        Vector2 measure = Game.DefaultFonts.Bold.Measure(32, Field.SurroundingNukesAt(x, y).ToString());
                        batch.Text(FontStyle.Bold, 32, Field.SurroundingNukesAt(x, y).ToString(), rect.Center.ToVector2() - measure / 2, Color.Red);
                    }
                }
            }

            if (MenuTile != new Point(-1, -1))
            {
                Rectangle rect = new Rectangle(MenuTile.X * (TILE_SIZE + 2), MenuTile.Y * (TILE_SIZE + 2), (TILE_SIZE + 2) * 2 + TILE_SIZE, TILE_SIZE);

                int oldX = rect.X;

                if (Vector2.Transform(new Vector2(rect.Right, 0), Camera.TransformWithoutScale).X >= screenSize.X)
                {
                    rect.X -= (TILE_SIZE + 2) * 2;
                }

                batch.Rectangle(rect, Color.Black);
                batch.Outline(rect, Color.White, 3, false);
                batch.Outline(new Rectangle(oldX, rect.Y, TILE_SIZE, TILE_SIZE), Color.White, 3, false);

                batch.Texture(new Rectangle(rect.X + 2, rect.Y + 2, TILE_SIZE - 4, TILE_SIZE - 4), Assets.Get <Texture2D>("icons/explode.png"),
                              Color.White * (Field.FlagAt(MenuTile.X, MenuTile.Y) == FlagType.Flag ? 0.6f : 1.0f));
                batch.Texture(new Rectangle(rect.X + 4 + TILE_SIZE, rect.Y + 2, TILE_SIZE - 4, TILE_SIZE - 4), Assets.Get <Texture2D>("icons/flag.png"),
                              Color.White * (Field.FlagsLeft == 0 && Field.FlagAt(MenuTile.X, MenuTile.Y) != FlagType.Flag ? 0.6f : 1.0f));
                batch.Texture(new Rectangle(rect.X + 6 + TILE_SIZE * 2, rect.Y + 2, TILE_SIZE - 4, TILE_SIZE - 4), Assets.Get <Texture2D>("icons/flagvisual.png"),
                              Color.White);
            }

            batch.Transform = Matrix.Identity;

            batch.Rectangle(new Rectangle(0, 0, (int)screenSize.X, 180), Color.DarkGray);
            batch.Outline(new Rectangle(0, 0, (int)screenSize.X, 180), Color.White, 2, false);

            batch.SamplerState = SamplerState.PointClamp;

            string reaction = "idle.png";

            switch (_currentFace)
            {
            case FaceReaction.Hover:
                reaction = "hover.png";
                break;

            case FaceReaction.Win:
                reaction = "win.png";
                break;

            case FaceReaction.Lose:
                reaction = "lose.png";
                break;
            }

            batch.Texture(new Rectangle((int)screenSize.X / 2 - 64 / 2, 40, 64, 64), Assets.Get <Texture2D>("placeholder/reactions/" + reaction), Color.White);
            batch.SamplerState = SamplerState.LinearClamp;
        }
        public override void Draw(SpriteBatch batch, Vector2 screenSize)
        {
            batch.SamplerState = SamplerState.PointWrap;

            if (!BaseState.IsPointObscured(Input.MousePosition))
            {
                batch.Transform = BaseState.Camera.Transform;

                if (_tool == EditTool.PaintRadius)
                {
                    batch.Reset();
                    batch.Circle(Input.MousePosition, _radius * 4f * BaseState.Camera.Zoom, Color.White, 2);
                }
                else
                {
                    float alpha = Input.Mouse(MouseButton.Left) ? 1.0f : 0.6f;

                    if (Input.Mouse(MouseButton.Left))
                    {
                        alpha = MathHelper.Clamp(alpha + (float)Math.Sin(Game.Time * 10f) * 0.4f, 0, 1);
                    }

                    if (Input.Mouse(MouseButton.Left) && _tool == EditTool.PaintRectangle)
                    {
                        batch.Outline(new Rectangle(_rectangleToolRect.X * 16, _rectangleToolRect.Y * 16, _rectangleToolRect.Width * 16 + 16, _rectangleToolRect.Height * 16 + 16),
                                      !_eraseMode && !Game.Input.Key(Keys.E) ? Color.White * alpha : Color.DarkRed * alpha, 1, false);
                    }
                    else
                    {
                        batch.Outline(new Rectangle(SelectedTile.X * 16, SelectedTile.Y * 16, 16, 16),
                                      !_eraseMode && !Game.Input.Key(Keys.E) ? Color.White * alpha : Color.DarkRed * alpha, 1, false);
                    }

                    batch.Reset();

                    if (!(_tool == EditTool.PaintRectangle && _startingTile.X != -1))
                    {
                        string str = "(" + SelectedTile.X + ", " + SelectedTile.Y + ") ";
                        str += "[" + BaseState.Map[Layer, SelectedTile.X, SelectedTile.Y].Name(BaseState.Map.GetMetadata(Layer, SelectedTile.X, SelectedTile.Y), BaseState.Map.Info.Environment) + "]";

                        Vector2 pos = new Vector2(SelectedTile.X * 16, SelectedTile.Y * 16) * BaseState.Camera.Zoom + BaseState.Camera.Translation -
                                      new Vector2(0, 12 * BaseState.Camera.Zoom);

                        if (pos.X < 5 * BaseState.Camera.Zoom)
                        {
                            pos.X = 5 * BaseState.Camera.Zoom;
                        }

                        if (pos.Y < 5 * BaseState.Camera.Zoom)
                        {
                            pos.Y  = 5 * BaseState.Camera.Zoom;
                            pos.X += 3 * BaseState.Camera.Zoom;
                        }

                        batch.Text(
                            SpriteBatch.FontStyle.MonoBold,
                            (uint)(8 * BaseState.Camera.Zoom),
                            str,
                            pos,
                            Color.White * alpha);
                    }
                    else
                    {
                        string str = "(" + _startingTile.X + " -> " + SelectedTile.X + ", " + _startingTile.Y + " -> " + SelectedTile.Y + ")";

                        int tilesX = Math.Abs(SelectedTile.X - _startingTile.X) + 1;
                        int tilesY = Math.Abs(SelectedTile.Y - _startingTile.Y) + 1;
                        str += " [" + (tilesX * tilesY) + " tile(s)]";

                        Vector2 pos = new Vector2(Math.Min(_startingTile.X, SelectedTile.X) * 16, Math.Min(_startingTile.Y, SelectedTile.Y) * 16) * BaseState.Camera.Zoom + BaseState.Camera.Translation -
                                      new Vector2(0, 12 * BaseState.Camera.Zoom);

                        if (pos.X < 5 * BaseState.Camera.Zoom)
                        {
                            pos.X = 5 * BaseState.Camera.Zoom;
                        }

                        if (pos.Y < 5 * BaseState.Camera.Zoom)
                        {
                            pos.Y  = 5 * BaseState.Camera.Zoom;
                            pos.X += 3 * BaseState.Camera.Zoom;
                        }

                        batch.Text(
                            SpriteBatch.FontStyle.MonoBold,
                            (uint)(8 * BaseState.Camera.Zoom),
                            str,
                            pos,
                            Color.White * alpha);

                        Vector2 measure = Game.DefaultFonts.MonoBold.Measure(7, (_rectangleToolRect.Width + 1) + "x" + (_rectangleToolRect.Height + 1));
                        Vector2 sizePos = new Vector2((_rectangleToolRect.Width * 16 + 16) / 2 - measure.X / 2, (_rectangleToolRect.Height * 16 + 16) / 2 - measure.Y / 2);
                        sizePos += _rectangleToolRect.Location.ToVector2() * 16;
                        sizePos -= new Vector2(0, 1);
                        sizePos *= BaseState.Camera.Zoom;
                        sizePos += BaseState.Camera.Translation;

                        batch.Text(
                            SpriteBatch.FontStyle.MonoBold,
                            (uint)(7 * BaseState.Camera.Zoom),
                            (_rectangleToolRect.Width + 1) + "x" + (_rectangleToolRect.Height + 1),
                            sizePos,
                            Color.White * alpha * 0.6f);
                    }
                }
            }

            batch.Reset();
            batch.SamplerState = SamplerState.PointWrap;

            Menu.Draw(Game);
        }
 public override void Draw(SpriteBatch batch, Vector2 screenSize)
 {
     batch.Rectangle(new Rectangle(0, 0, (int)screenSize.X, (int)screenSize.Y), Color.Black * 0.6f);
 }