예제 #1
0
        public void Render(IStateOwner pOwner, Graphics pRenderTarget, MenuStateMultiOption Source, MenuStateMenuItemGDIPlusDrawData Element)
        {
            Font   useFont       = MenuStateTextMenuItemGDIRenderer.GetScaledFont(pOwner, Source.FontFace, Source.FontSize);
            var    OptionManager = Source.OptionManagerBase;
            var    Bounds        = Element.Bounds;
            String sLeftCover    = "< ";
            String sRightCover   = ">";

            var PrevItem = OptionManager.GetTextBase(OptionManager.PeekPreviousBase());
            var NextItem = OptionManager.GetTextBase(OptionManager.PeekNextBase());

            sLeftCover  = PrevItem + sLeftCover;
            sRightCover = sRightCover + NextItem;
            var MeasureLeft  = pRenderTarget.MeasureString(sLeftCover, useFont);
            var MeasureRight = pRenderTarget.MeasureString(sRightCover, useFont);

            PointF LeftPos  = new PointF(Bounds.Left - MeasureLeft.Width, Bounds.Top + (Bounds.Height / 2) - MeasureLeft.Height / 2);
            PointF RightPos = new PointF(Bounds.Right, Bounds.Top + (Bounds.Height / 2) - MeasureRight.Height / 2);

            if (Source.Activated)
            {
                TetrisGame.DrawText(pRenderTarget, useFont, sLeftCover, new SolidBrush(Source.ForeColor), new SolidBrush(Source.ShadowColor), LeftPos.X, LeftPos.Y);
                TetrisGame.DrawText(pRenderTarget, useFont, sRightCover, new SolidBrush(Source.ForeColor), new SolidBrush(Source.ShadowColor), RightPos.X, RightPos.Y);
            }
            base.Render(pOwner, pRenderTarget, Source, Element);
        }
        public void Render(IStateOwner pOwner, Graphics pRenderTarget, PauseGameState Source, BaseDrawParameters Element)
        {
            if (!Source.DrawDataInitialized)
            {
                InitDrawData(pOwner, Source, Element);
                Source.DrawDataInitialized = true;
            }
            Graphics g          = pRenderTarget;
            var      Bounds     = Element.Bounds;
            var      FallImages = Source.FallImages;
            //Render the paused state.
            Font   usePauseFont = TetrisGame.GetRetroFont(24, pOwner.ScaleFactor);
            String sPauseText   = "Pause";
            SizeF  Measured     = g.MeasureString(sPauseText, usePauseFont);

            g.FillRectangle(Brushes.Gray, Bounds);
            foreach (var iterate in FallImages)
            {
                iterate.Draw(g);
            }

            g.ResetTransform();
            PointF DrawPos = new PointF(Bounds.Width / 2 - Measured.Width / 2, Bounds.Height / 2 - Measured.Height / 2);

            TetrisGame.DrawText(g, usePauseFont, sPauseText, Brushes.White, Brushes.Black, DrawPos.X, DrawPos.Y);
            //retrieve the renderer for the MenuState object.
            base.Render(pOwner, pRenderTarget, Source, Element);
        }
예제 #3
0
        public virtual float DrawHeader(IStateOwner pOwner, MenuState Source, Graphics Target, RectangleF Bounds)
        {
            Font  useHeaderFont = GetScaledHeaderFont(pOwner, Source);
            var   HeaderSize    = Target.MeasureString(Source.StateHeader, useHeaderFont);
            float UseX          = (Bounds.Width / 2) - (HeaderSize.Width / 2) + Source.MainXOffset;
            float UseY          = HeaderSize.Height / 3;

            TetrisGame.DrawText(Target, useHeaderFont, Source.StateHeader, Brushes.Black, Brushes.White, UseX, UseY);

            return(UseY + HeaderSize.Height);
        }
예제 #4
0
        public override void RenderStats(IStateOwner pOwner, Graphics pRenderTarget, GameplayGameState Source, BaseDrawParameters Element)
        {
            var Bounds = Element.Bounds;
            var g      = pRenderTarget;

            bool RedrawsNeeded = !LastDrawStat.Equals(Bounds);

            LastDrawStat = Bounds;
            if (StatisticsBackground == null || RedrawsNeeded || GeneratedImageTheme != Source.PlayField.Theme)
            {
                GenerateStatisticsBackground(Source);
            }

            g.DrawImage(StatisticsBackground, Bounds);
            //g.Clear(Color.Black);
            if (!Source.HasTetrominoImages() || RedrawsNeeded)
            {
                RedrawStatusbarTetrominoBitmaps(pOwner, Source, Bounds);
            }

            lock (Source.LockTetImageRedraw)
            {
                var    useStats = Source.GameStats;
                double Factor   = Bounds.Height / 644d;
                int    DesiredFontPixelHeight = (int)(Bounds.Height * (23d / 644d));
                using (Font standardFont = new Font(TetrisGame.RetroFont, DesiredFontPixelHeight, FontStyle.Bold, GraphicsUnit.Pixel))
                {
                    var LocalScores    = Source.GetLocalScores();
                    var TopScore       = LocalScores == null ? 0 : LocalScores.GetScores().First().Score;
                    int MaxScoreLength = Math.Max(TopScore.ToString().Length, useStats.Score.ToString().Length);

                    String CurrentScoreStr = useStats.Score.ToString().PadLeft(MaxScoreLength + 2);
                    String TopScoreStr     = TopScore.ToString().PadLeft(MaxScoreLength + 2);
                    //TODO: redo this segment separately, so we can have the labels left-aligned and the values right-aligned.
                    // String BuildStatString = "Time:  " + FormatGameTime(pOwner).ToString().PadLeft(MaxScoreLength + 2) + "\n" +
                    //                          "Score: " + CurrentScoreStr + "\n" +
                    //                          "Top:   " + TopScoreStr + " \n" +
                    //                          "Lines: " + GameStats.LineCount.ToString().PadLeft(MaxScoreLength+2);

                    g.FillRectangle(LightenBrush, 0, 5, Bounds.Width, (int)(450 * Factor));
                    String[] StatLabels   = new string[] { "Time:", "Score:", "Top:", "Lines:" };
                    int      LineCount    = Source.GameStats is TetrisStatistics ? (Source.GameStats as TetrisStatistics).LineCount : 0;
                    String[] StatValues   = new string[] { FormatGameTime(pOwner), useStats.Score.ToString(), TopScore.ToString(), LineCount.ToString() };
                    Point    StatPosition = new Point((int)(7 * Factor), (int)(7 * Factor));

                    int CurrentYPosition = StatPosition.Y;
                    for (int statindex = 0; statindex < StatLabels.Length; statindex++)
                    {
                        var   MeasureLabel = g.MeasureString(StatLabels[statindex], standardFont);
                        var   MeasureValue = g.MeasureString(StatValues[statindex], standardFont);
                        float LargerHeight = Math.Max(MeasureLabel.Height, MeasureValue.Height);

                        //we want to draw the current stat label at position StatPosition.X,CurrentYPosition...

                        TetrisGame.DrawText(g, standardFont, StatLabels[statindex], Brushes.Black, Brushes.White, StatPosition.X, CurrentYPosition);

                        //we want to draw the current stat value at Bounds.Width-ValueWidth.
                        TetrisGame.DrawText(g, standardFont, StatValues[statindex], Brushes.Black, Brushes.White, (float)(Bounds.Width - MeasureValue.Width - (5 * Factor)), CurrentYPosition);

                        //add the larger of the two heights to the current Y Position.
                        CurrentYPosition += (int)LargerHeight;
                        CurrentYPosition += 2;
                    }



                    Type[] useTypes = new Type[] { typeof(Tetromino_I), typeof(Tetromino_O), typeof(Tetromino_J), typeof(Tetromino_T), typeof(Tetromino_L), typeof(Tetromino_S), typeof(Tetromino_Z) };

                    int[] PieceCounts = null;

                    if (useStats is TetrisStatistics ts)
                    {
                        PieceCounts = new int[] { ts.I_Piece_Count, ts.O_Piece_Count, ts.J_Piece_Count, ts.T_Piece_Count, ts.L_Piece_Count, ts.S_Piece_Count, ts.Z_Piece_Count };
                    }
                    else
                    {
                        PieceCounts = new int[] { 0, 0, 0, 0, 0, 0, 0 };
                    }


                    int             StartYPos = (int)(140 * Factor);
                    int             useXPos   = (int)(30 * Factor);
                    ImageAttributes ShadowTet = TetrisGame.GetShadowAttributes();
                    if (Source.GameHandler is StandardTetrisHandler)
                    {
                        for (int i = 0; i < useTypes.Length; i++)
                        {
                            PointF BaseCoordinate = new PointF(useXPos, StartYPos + (int)((float)i * (40d * Factor)));
                            PointF TextPos        = new PointF(useXPos + (int)(100d * Factor), BaseCoordinate.Y);
                            String StatText       = "" + PieceCounts[i];
                            SizeF  StatTextSize   = g.MeasureString(StatText, standardFont);
                            String sNomTypeKey    = Source.PlayField.Theme.GetNominoTypeKey(useTypes[i], Source.GameHandler, Source.PlayField);
                            Image  TetrominoImage = TetrisGame.Choose(Source.NominoImages[sNomTypeKey]);
                            PointF ImagePos       = new PointF(BaseCoordinate.X, BaseCoordinate.Y + (StatTextSize.Height / 2 - TetrominoImage.Height / 2));

                            g.DrawImage(TetrominoImage, ImagePos);
                            g.DrawString(StatText, standardFont, Brushes.White, new PointF(TextPos.X + 4, TextPos.Y + 4));
                            g.DrawString(StatText, standardFont, Brushes.Black, TextPos);
                        }
                    }

                    Point NextDrawPosition = new Point((int)(40f * Factor), (int)(420 * Factor));
                    Size  NextSize         = new Size((int)(200f * Factor), (int)(200f * Factor));
                    Point CenterPoint      = new Point(NextDrawPosition.X + NextSize.Width / 2, NextDrawPosition.Y + NextSize.Height / 2);
                    //now draw the "Next" Queue. For now we'll just show one "next" item.
                    if (Source.NextBlocks.Count > 0)
                    {
                        var QueueList = Source.NextBlocks.ToArray();
                        //(from t in QueueList select Source.GetTetrominoSKBitmap(pOwner,t)).ToArray()
                        Image[] NextTetrominoes = (from t in QueueList select Source.GetTetrominoImage(pOwner, t)).ToArray(); //  TetrisGame.Choose(Source.NominoImages[Source.PlayField.Theme.GetNominoKey(t,Source.GameHandler,Source.PlayField)])).ToArray();
                        Image   DisplayBox      = TetrisGame.Imageman["display_box"];
                        //draw it at 40,420. (Scaled).
                        float ScaleDiff = 0;
                        iActiveSoundObject PlayingMusic;
                        if ((PlayingMusic = TetrisGame.Soundman.GetPlayingMusic_Active()) != null)
                        {
                            Source.StoredLevels.Enqueue(PlayingMusic.Level);
                        }

                        if (Source.StoredLevels.Count >= 4)
                        {
                            ScaleDiff = Math.Min(30, 10 * Source.StoredLevels.Dequeue());
                        }

                        if (!TetrisGame.DJMode)
                        {
                            ScaleDiff = 0;
                        }

                        g.DrawImage
                            (DisplayBox,
                            new Rectangle(new Point((int)(NextDrawPosition.X - ScaleDiff), (int)(NextDrawPosition.Y - ScaleDiff)), new Size((int)(NextSize.Width + (ScaleDiff * 2)), (int)(NextSize.Height + (ScaleDiff * 2)))), 0, 0, DisplayBox.Width, DisplayBox.Height, GraphicsUnit.Pixel);

                        g.FillEllipse(Brushes.Black, CenterPoint.X - 5, CenterPoint.Y - 5, 10, 10);

                        for (int i = NextTetrominoes.Length - 1; i > -1; i--)
                        {
                            double StartAngle         = Math.PI;
                            double AngleIncrementSize = (Math.PI * 1.8) / (double)NextTetrominoes.Length;
                            //we draw starting at StartAngle, in increments of AngleIncrementSize.
                            //i is the index- we want to increase the angle by that amount (well, obviously, I suppose...

                            double UseAngleCurrent = StartAngle + AngleIncrementSize * (float)i + Source.NextAngleOffset;

                            double UseXPosition = CenterPoint.X + ((float)((NextSize.Width) / 2.2) * Math.Cos(UseAngleCurrent));
                            double UseYPosition = CenterPoint.Y + ((float)((NextSize.Height) / 2.2) * Math.Sin(UseAngleCurrent));


                            var NextTetromino = NextTetrominoes[i];

                            float Deviation = (i - NextTetrominoes.Length / 2);
                            Point Deviate   = new Point((int)(Deviation * 20 * Factor), (int)(Deviation * 20 * Factor));

                            Point DrawTetLocation = new Point((int)UseXPosition - (NextTetromino.Width / 2), (int)UseYPosition - NextTetromino.Height / 2);
                            //Point DrawTetLocation = new Point(Deviate.X + (int)(NextDrawPosition.X + ((float)NextSize.Width / 2) - ((float)NextTetromino.Width / 2)),
                            //    Deviate.Y + (int)(NextDrawPosition.Y + ((float)NextSize.Height / 2) - ((float)NextTetromino.Height / 2)));
                            double AngleMovePercent = Source.NextAngleOffset / AngleIncrementSize;
                            double NumAffect        = Source.NextAngleOffset == 0 ? 0 : AngleIncrementSize / Source.NextAngleOffset;
                            Size   DrawTetSize      = new Size
                                                      (
                                (int)((float)NextTetromino.Width * (0.3 + (1 - ((float)(i) * 0.15f) - .15f * AngleMovePercent))),
                                (int)((float)NextTetromino.Height * (0.3 + (1 - ((float)(i) * 0.15f) - .15f * AngleMovePercent))));


                            //g.TranslateTransform(CenterPoint.X,CenterPoint.Y);

                            g.TranslateTransform(DrawTetLocation.X + DrawTetSize.Width / 2, DrawTetLocation.Y + DrawTetSize.Width / 2);


                            double DrawTetAngle = UseAngleCurrent;
                            DrawTetAngle += (Math.PI * AngleMovePercent);
                            float useDegrees = 180 + (float)(DrawTetAngle * (180 / Math.PI));

                            g.RotateTransform((float)useDegrees);

                            g.TranslateTransform(-(DrawTetLocation.X + DrawTetSize.Width / 2), -(DrawTetLocation.Y + DrawTetSize.Height / 2));
                            //g.TranslateTransform(-CenterPoint.X,-CenterPoint.Y);


                            if (DrawTetSize.Width > 0 && DrawTetSize.Height > 0)
                            {
                                //ImageAttributes Shade = GetShadowAttributes(1.0f - ((float)i * 0.3f));
                                ImageAttributes Shade = new ImageAttributes();
                                Shade.SetColorMatrix(ColorMatrices.GetFader(1.0f - ((float)i * 0.1f)));


                                g.DrawImage
                                    (NextTetromino, new Rectangle((int)DrawTetLocation.X, (int)DrawTetLocation.Y, DrawTetSize.Width, DrawTetSize.Height), 0f, 0f,
                                    (float)NextTetromino.Width, (float)NextTetromino.Height, GraphicsUnit.Pixel, Shade);
                            }

                            g.ResetTransform();
                        }
                    }

                    if (Source.HoldBlock != null)
                    {
                        var   GetKey        = Source.PlayField.Theme.GetNominoKey(Source.HoldBlock, Source.GameHandler, Source.PlayField);
                        Image HoldTetromino = Source.GetTetrominoImage(pOwner, Source.HoldBlock);
                        g.DrawImage(HoldTetromino, CenterPoint.X - HoldTetromino.Width / 2, CenterPoint.Y - HoldTetromino.Height / 2);
                    }
                }
            }
        }
        public override void Render(IStateOwner pOwner, Graphics pRenderTarget, GameOverGameState Source, BaseDrawParameters Element)
        {
            var Bounds = Element.Bounds;
            var g      = pRenderTarget;

            if (Source.GameOveredState is GameplayGameState)
            {
                GameplayGameState standardgame = Source.GameOveredState as GameplayGameState;
                SizeF             BlockSize    = new SizeF(Bounds.Width / (float)standardgame.PlayField.ColCount, Bounds.Height / (float)standardgame.PlayField.RowCount);
                useCoverBrush = new LinearGradientBrush(new Rectangle(0, 0, (int)Bounds.Width, (int)BlockSize.Height), Color.DarkSlateGray, Color.MintCream, LinearGradientMode.Vertical);
                RenderingProvider.Static.DrawElement(pOwner, g, Source.GameOveredState, Element);
                g.FillRectangle(useCoverBrush, 0f, 0f, (float)Bounds.Width, (float)BlockSize.Height * Source.CoverBlocks);
            }

            if (Source.CompleteScroll)
            {
                Font EntryFont    = TetrisGame.GetRetroFont(14, pOwner.ScaleFactor);
                Font GameOverFont = TetrisGame.GetRetroFont(24, pOwner.ScaleFactor);

                var    measured    = g.MeasureString(Source.GameOverText, GameOverFont);
                var    measuremini = g.MeasureString(Source.GameOverText, EntryFont);
                PointF GameOverPos = new PointF(Bounds.Width / 2 - measured.Width / 2, measured.Height / 4);
                g.DrawString(Source.GameOverText, GameOverFont, Brushes.White, 5 + GameOverPos.X, 5 + GameOverPos.Y);
                g.DrawString(Source.GameOverText, GameOverFont, Brushes.Black, GameOverPos.X, GameOverPos.Y);

                //draw each "line" of summary statistical information based on ShowExtraLines.

                for (int i = 0; i < Source.CurrentLinesDisplay; i++)
                {
                    float XPosition = Bounds.Width * 0.25f;
                    float YPosition = GameOverPos.Y + ((1 + i) * measuremini.Height) + measuremini.Height;

                    if (i == 0)
                    {
                        var measuredmini = g.MeasureString("---Line Clears---", EntryFont);
                        TetrisGame.DrawText(g, EntryFont, "---Line Clears---", Brushes.Black, Brushes.White, Bounds.Width / 2 - measuredmini.Width / 2, GameOverPos.Y + measured.Height);
                    }

                    if (i == 1)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_I), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                    if (i == 2)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_O), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                    if (i == 3)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_T), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                    if (i == 4)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_J), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                    if (i == 5)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_L), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                    if (i == 6)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_S), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                    if (i == 7)
                    {
                        DrawTetrominoStat(Source, typeof(Tetrominoes.Tetromino_Z), new PointF(XPosition, YPosition), g, Bounds, EntryFont);
                    }
                }

                if (Source.NewScorePosition > -1)
                {
                    Font HighScoreEntryFont = new Font(GameOverFont.FontFamily, (float)(8 * pOwner.ScaleFactor), FontStyle.Regular);
                    //draw the awarded score position as well.
                    float  XPosition         = Bounds.Width * .25f;
                    float  YPosition         = Bounds.Height - measured.Height - 10;
                    String ScoreText         = "New High Score!";
                    var    MeasuredScoreText = g.MeasureString(ScoreText, HighScoreEntryFont);
                    using (Brush RainbowBrush = new SolidBrush(TetrisGame.GetRainbowColor(Color.Lime, 0.1d)))
                    {
                        TetrisGame.DrawText(g, GameOverFont, ScoreText, Brushes.Black, RainbowBrush, Bounds.Width / 2 - MeasuredScoreText.Width / 2, YPosition + measuremini.Height);
                    }
                }
            }
        }