예제 #1
0
        /// <summary>
        /// Primary draw method.
        /// </summary>
        /// <param name="gameTime">Handeled by the framework, the passage of time is updated automagically.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            _skybox.Draw(_camera.View, _camera.Projection, _camera.Position);

            foreach (BasicModel model in _models)
            {
                if (_camera.BoundingVolumeIsInView(model.BoundingSphere))
                {
                    model.Draw(_camera.View, _camera.Projection, _camera.Position);
                }
            }

            _lineDrawer.Begin(_camera.View, _camera.Projection);

            _lineDrawer.DrawHexagonGrid(Vector2.One * -9930, (new Vector2(80, 40)), 200, Color.Red);
            _lineDrawer.DrawLine(_models[0].Position, new Vector3(_models[0].Position.X, 0, _models[0].Position.Z), Color.CornflowerBlue);

            ShipMovement.DrawHeading();
            ShipMovement.DrawMarker();

            _lineDrawer.End();

            _stars.Draw(_camera.View, _camera.Projection, _camera.Up, _camera.Right);

            // if rendered card buffer is null, initialize it here
            if (_renderedCardBuffer == null)
            {
                // Choosing a random card for testing...
                Random r = new Random();
                //Card c = _cards[r.Next(_cards.Count)];
                Card c = null;
                foreach (Card cx in _cards)
                {
                    if (cx.Title == "Patrol Drone")
                    //if (_rulesTextFont.MeasureString(WrapText(_rulesTextFont, cx.RulesText, _cardRulesWidth)).Y > _cardRulesHeight)
                    {
                        c = cx;
                        //Debug.WriteLine("{0}", _rulesTextFont.MeasureString(WrapText(_rulesTextFont, cx.RulesText, _cardRulesWidth)).Y - _cardRulesHeight);
                        break;
                    }
                }

                string someRandomText = c.RulesText;
                someRandomText = WrapText(_rulesTextFont, someRandomText, _cardRulesWidth);
                Vector2 textSize = _rulesTextFont.MeasureString(someRandomText);

                string  titleString = c.Title;
                Vector2 titleSize   = _titleFont.MeasureString(titleString);

                string typeString    = c.Supertype.ToString();
                string subtypeString = c.Subtype.ToString();
                if (subtypeString != "None")
                {
                    typeString = typeString + " - " + c.Subtype.ToString();
                }
                Vector2 typeSize = _typeFont.MeasureString(typeString);

                string  costString = (c.EnergyCostType == AmountType.Variable) ? Description.ToDescription(c.EnergyCostVar).Replace("+", string.Empty) : c.EnergyCost.ToString();
                Vector2 costSize   = _statFont.MeasureString(costString);

                Rectangle cardRect = new Rectangle(
                    0,
                    0,
                    _cardTexture.Width,
                    _cardTexture.Height);

                float titleScale = 1;
                if (titleSize.X > _cardTitleWidth)
                {
                    titleScale = _cardTitleWidth / titleSize.X;
                }

                float typeScale = 1;
                if (typeSize.X > _cardTypeWidth)
                {
                    typeScale = _cardTypeWidth / typeSize.X;
                }

                float costScale = 1;
                if (costSize.X > _cardCostWidth)
                {
                    costScale = _cardCostWidth / costSize.X;
                }

                // render the title text's shadow
                RenderTarget2D titleShadowTarget = new RenderTarget2D(GraphicsDevice, _cardTitleWidth, _cardTitleHeight, false,
                                                                      GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
                GraphicsDevice.SetRenderTarget(titleShadowTarget);
                GraphicsDevice.Clear(Color.Transparent);
                _spriteBatch.Begin();
                _spriteBatch.DrawString(_titleFont, titleString,
                                        new Vector2((int)((_cardTitleWidth - titleSize.X * titleScale) / 2), (int)((_cardTitleHeight - titleSize.Y * titleScale) / 2)),
                                        Color.White, 0, Vector2.Zero, titleScale, SpriteEffects.None, 0);
                _spriteBatch.End();

                // do blur
                GaussianBlur gaussianBlur = new GaussianBlur(this);
                gaussianBlur.ComputeKernel(4, 2);
                int            renderTargetWidth  = titleShadowTarget.Width / 2;
                int            renderTargetHeight = titleShadowTarget.Height / 2;
                RenderTarget2D rt1 = new RenderTarget2D(GraphicsDevice,
                                                        renderTargetWidth, renderTargetHeight, false,
                                                        GraphicsDevice.PresentationParameters.BackBufferFormat,
                                                        DepthFormat.None);
                RenderTarget2D rt2 = new RenderTarget2D(GraphicsDevice,
                                                        renderTargetWidth, renderTargetHeight, false,
                                                        GraphicsDevice.PresentationParameters.BackBufferFormat,
                                                        DepthFormat.None);
                gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight);
                Texture2D titleShadowResult = gaussianBlur.PerformGaussianBlur(titleShadowTarget, rt1, rt2, _spriteBatch);

                // render the type text's shadow
                RenderTarget2D typeShadowTarget = new RenderTarget2D(GraphicsDevice, _cardTypeWidth, _cardTypeHeight, false,
                                                                     GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
                GraphicsDevice.SetRenderTarget(typeShadowTarget);
                GraphicsDevice.Clear(Color.Transparent);
                _spriteBatch.Begin();
                _spriteBatch.DrawString(_typeFont, typeString,
                                        new Vector2((int)((_cardTypeWidth - typeSize.X * typeScale) / 2), (int)((_cardTypeHeight - typeSize.Y * typeScale) / 2)),
                                        Color.White, 0, Vector2.Zero, typeScale, SpriteEffects.None, 0);
                _spriteBatch.End();

                // do blur
                renderTargetWidth  = typeShadowTarget.Width / 2;
                renderTargetHeight = typeShadowTarget.Height / 2;
                rt1 = new RenderTarget2D(GraphicsDevice,
                                         renderTargetWidth, renderTargetHeight, false,
                                         GraphicsDevice.PresentationParameters.BackBufferFormat,
                                         DepthFormat.None);
                rt2 = new RenderTarget2D(GraphicsDevice,
                                         renderTargetWidth, renderTargetHeight, false,
                                         GraphicsDevice.PresentationParameters.BackBufferFormat,
                                         DepthFormat.None);
                gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight);
                Texture2D typeShadowResult = gaussianBlur.PerformGaussianBlur(typeShadowTarget, rt1, rt2, _spriteBatch);

                // render the card
                _renderedCardBuffer = new RenderTarget2D(GraphicsDevice, _cardTexture.Width, _cardTexture.Height, false,
                                                         GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
                GraphicsDevice.SetRenderTarget(_renderedCardBuffer);
                GraphicsDevice.Clear(Color.Transparent);

                _spriteBatch.Begin();
                _spriteBatch.Draw(_cardTexture, cardRect, Color.White);
                _spriteBatch.DrawString(_rulesTextFont, someRandomText,
                                        new Vector2(_cardRulesLeftX, (int)(_cardRulesTopY + (_cardRulesHeight - textSize.Y) / 2)),
                                        Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0);

                _spriteBatch.Draw(titleShadowResult,
                                  new Rectangle((int)(_cardTitleLeftX + (_cardTitleWidth - titleShadowResult.Width * 2) / 2), (int)(_cardTitleTopY + (_cardTitleHeight - titleShadowResult.Height * 2) / 2), titleShadowResult.Width * 2, titleShadowResult.Height * 2),
                                  new Rectangle(0, 0, titleShadowResult.Width, titleShadowResult.Height),
                                  Color.White);
                _spriteBatch.Draw(typeShadowResult,
                                  new Rectangle((int)(_cardTypeLeftX + (_cardTypeWidth - typeShadowResult.Width * 2) / 2), (int)(_cardTypeTopY + (_cardTypeHeight - typeShadowResult.Height * 2) / 2), typeShadowResult.Width * 2, typeShadowResult.Height * 2),
                                  new Rectangle(0, 0, typeShadowResult.Width, typeShadowResult.Height),
                                  Color.White);
                _spriteBatch.DrawString(_titleFont, titleString,
                                        new Vector2((int)(_cardTitleLeftX + (_cardTitleWidth - titleSize.X * titleScale) / 2), (int)(_cardTitleTopY + (_cardTitleHeight - titleSize.Y * titleScale) / 2)),
                                        Color.Black, 0, Vector2.Zero, titleScale, SpriteEffects.None, 0);
                _spriteBatch.DrawString(_typeFont, typeString,
                                        new Vector2((int)(_cardTypeLeftX + (_cardTypeWidth - typeSize.X * typeScale) / 2), (int)(_cardTypeTopY + (_cardTypeHeight - typeSize.Y * typeScale) / 2)),
                                        Color.Black, 0, Vector2.Zero, typeScale, SpriteEffects.None, 0);
                _spriteBatch.DrawString(_statFont, costString,
                                        new Vector2((int)(_cardCostLeftX + (_cardCostWidth - costSize.X * costScale) / 2), (int)(_cardCostTopY + (_cardCostHeight - costSize.Y * costScale) / 2)),
                                        Color.Black, 0, Vector2.Zero, costScale, SpriteEffects.None, 0);

                _spriteBatch.End();

                GraphicsDevice.SetRenderTarget(null);
            }

            // Draw cards *this should always appear at the end so its on top
            _spriteBatch.Begin();
            float scale = .4f;

            // Note: this is arbitrary rules text for testing...
            Rectangle retval = new Rectangle(
                0 + 10,
                GraphicsDevice.Viewport.Height - (int)(_cardTexture.Height * scale) - 10,
                (int)(_cardTexture.Width * scale),
                (int)(_cardTexture.Height * scale));

            _spriteBatch.Draw(_renderedCardBuffer, retval, Color.White);

            _spriteBatch.End();

            base.Draw(gameTime);
        }