コード例 #1
0
        }   // end of GameListManager Update()


        public void Render()
        {
#if NETFX_CORE
            if (BokuGame.ScreenSize.X > BokuGame.ScreenSize.Y)
            {
#endif
            for (int i = 0; i < renderList.Count; ++i)
            {
                RenderObject obj = renderList[i] as RenderObject;
                obj.Render(null);
            }
#if NETFX_CORE
        }

        else
        {
            // Game paused since in strange snapped mode
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
            InGame.Clear(Color.Black);

            // Center Kodu.
            Vector2     size  = new Vector2(deadKoduTexture.Width, deadKoduTexture.Height);
            Vector2     pos   = (BokuGame.ScreenSize - size) * 0.5f;
            SpriteBatch batch = UI2D.Shared.SpriteBatch;
            batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
            batch.Draw(deadKoduTexture, pos, Color.White);
            batch.End();

            pos.X  = BokuGame.ScreenSize.X / 2.0f - 150.0f;
            pos.Y += size.Y + 30.0f;

            blob.RenderWithButtons(pos, new Color(0.8f, 0.8f, 0.8f));
        }
#endif
        } // end of GameListManager Render()
コード例 #2
0
        }   // end of ThoughtBalloon Activate()

        public void RefreshTexture()
        {
            RenderTarget2D rt = UI2D.Shared.RenderTarget256_256;

            //
            // Render the frame and text to the rendertarget.
            //
            InGame.SetRenderTarget(rt);

            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

            InGame.Clear(Color.Transparent);

            // Frame
            ssquad.Render(ThoughtBalloonManager.FrameTexture, Vector2.Zero, new Vector2(rt.Width, rt.Height), "TexturedRegularAlpha");

            int      width = 238;
            TextBlob blob  = new TextBlob(UI2D.Shared.GetGameFont30Bold, text, width);

            blob.Justification = Boku.UI2D.UIGridElement.Justification.Center;

            if (blob.NumLines > 3)
            {
                blob.Font = UI2D.Shared.GetGameFont24Bold;
                if (blob.NumLines > 3)
                {
                    blob.Font = UI2D.Shared.GetGameFont24Bold;
                }
            }

            duration = defaultDuration * blob.NumLines;

            int     margin      = 8;
            int     middle      = 76; // Vertical midpoint of space for text.
            int     lineSpacing = blob.Font().LineSpacing;
            int     numLines    = Math.Min(4, blob.NumLines);
            Vector2 pos         = new Vector2(margin, middle - (numLines * 0.5f) * lineSpacing);

            blob.RenderWithButtons(pos, Color.Black, maxLines: numLines);

            InGame.RestoreRenderTarget();

            //
            // Copy result to local texture.
            //
            rt.GetData <int>(_scratchData);
            contentTexture.SetData <int>(_scratchData);
        }   // end of ThoughtBalloon RefreshTexture()
コード例 #3
0
            public override void Render(Camera camera)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                // Clear the screen & z-buffer.
                InGame.Clear(backgroundColor);

                // Set up params for rendering UI with this camera.
                BokuGame.bokuGame.shaderGlobals.Effect.Parameters["EyeLocation"].SetValue(new Vector4(shared.camera.From, 1.0f));
                BokuGame.bokuGame.shaderGlobals.Effect.Parameters["CameraUp"].SetValue(new Vector4(shared.camera.Up, 1.0f));

                // Render the active grid using the local camera.
                UIGrid curGrid = shared.GetGridFromCurTab();

                if (curGrid != null)
                {
                    curGrid.Render(shared.camera);
                }

                // Render the backdrop/frame on top of the grid.
                ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

                ssquad.Render(shared.backgroundTexture, new Vector2(0.0f), new Vector2(BokuGame.bokuGame.GraphicsDevice.Viewport.Width - 1.0f, BokuGame.bokuGame.GraphicsDevice.Viewport.Height - 1.0f), @"TexturedRegularAlpha");

                // Render the tabs.
#if !HIDE_MISSIONS
                shared.missionsTab.Render(shared.camera);
#endif
                shared.myWorldsTab.Render(shared.camera);
                shared.starterWorldsTab.Render(shared.camera);
                shared.downloadsTab.Render(shared.camera);


                // Render the bottom bar.  Well, actually, instead of rendering the bar
                // we'll just steal the texture from it and render than.
                shared.bottomBar.Render(shared.camera);
                CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();

                //csquad.Render(shared.camera, shared.bottomBar.Diffuse.GetTexture(), new Vector2(0.0f, -3.35f), new Vector2(9.5f, 0.5f), @"TexturedRegularAlpha");

                // Render the buttons for the bottom bar.
                if (shared.parent.curTab == Tab.MyWorlds || shared.parent.curTab == Tab.Downloads)
                {
                    csquad.Render(shared.camera, ButtonTextures.XButton, shared.xButtonPosition, shared.buttonSize, @"TexturedRegularAlpha");
                }
                csquad.Render(shared.camera, ButtonTextures.YButton, shared.yButtonPosition, shared.buttonSize, @"TexturedRegularAlpha");
            }   // end of LoadLevelMenu RenderObj Render()
コード例 #4
0
        }   // end of HandleMouseInput()

        /// <summary>
        /// Renders the text to be displayed into the 1024x768 rendertarget.
        /// </summary>
        private void PreRender()
        {
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            RenderTarget2D rt1k = UI2D.Shared.RenderTarget1024_768;

            CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();
            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

            Color darkTextColor  = new Color(20, 20, 20);
            Color greyTextColor  = new Color(127, 127, 127);
            Color greenTextColor = new Color(8, 123, 110);
            Color whiteTextColor = new Color(255, 255, 255);

            // Render the text into the 1k rendertarget.
            InGame.SetRenderTarget(rt1k);
            InGame.Clear(Color.Transparent);

            // Set up params for rendering UI with this camera.
            Fx.ShaderGlobals.SetCamera(camera);

            //
            // Text.
            //

            // If we don't have enough text to go into scrolling, center vertically.
            int centering = 0;

            if (blob.NumLines < textVisibleLines)
            {
                centering += (int)(blob.TotalSpacing * (textVisibleLines - blob.NumLines) / 2.0f);
            }

            Vector2 pos;

            pos = new Vector2(textMargin, textTop + textOffset + centering);
            blob.RenderWithButtons(pos, darkTextColor);

            InGame.RestoreRenderTarget();
        }   // end of PreRender()
コード例 #5
0
        private static void RefreshTexture()
        {
            RenderTarget2D  rt   = UI2D.Shared.RenderTargetDepthStencil1280_720;
            ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

            InGame.SetRenderTarget(rt);
            InGame.Clear(Color.Transparent);

            bool showTeam   = (ActiveTeam != Classification.Colors.NotApplicable);
            bool showPlayer = ActivePlayer != GamePadSensor.PlayerId.Dynamic;

            if (showTeam || showPlayer)
            {
                // Main graphic.
                Vector2 size = new Vector2(textureWinner.Width, textureWinner.Height);
                Vector2 pos  = new Vector2((rt.Width - size.X) / 2.0f, 0.0f);
                quad.Render(textureWinner, pos, size, "TexturedPreMultAlpha");

                // Team or Player.
                size = new Vector2(textureTeam.Width, textureTeam.Height);
                pos  = new Vector2((rt.Width - size.X) / 2.0f, 354);
                quad.Render(textureTeam, pos, size, "TexturedPreMultAlpha");

                string label = String.Empty;
                if (showTeam)
                {
                    label = Strings.Localize("gameOver.team") + " ";
                }
                if (showPlayer)
                {
                    // Nothing to add here.
                }

                // Get correct color for team.
                Texture2D glyph = null;

                switch (ActivePlayer)
                {
                case GamePadSensor.PlayerId.One:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.player1");
                    label += CardSpace.Cards.GetLabel("filter.player1");
                    break;

                case GamePadSensor.PlayerId.Two:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.player2");
                    label += CardSpace.Cards.GetLabel("filter.player2");
                    break;

                case GamePadSensor.PlayerId.Three:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.player3");
                    label += CardSpace.Cards.GetLabel("filter.player3");
                    break;

                case GamePadSensor.PlayerId.Four:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.player4");
                    label += CardSpace.Cards.GetLabel("filter.player4");
                    break;

                default:
                    // Do nothing...
                    break;
                }

                switch (ActiveTeam)
                {
                case Classification.Colors.White:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.white");
                    label += Strings.Localize("colorNames.white");
                    break;

                case Classification.Colors.Black:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.Black");
                    label += Strings.Localize("colorNames.black");
                    break;

                case Classification.Colors.Grey:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.Grey");
                    label += Strings.Localize("colorNames.grey");
                    break;

                case Classification.Colors.Red:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.red");
                    label += Strings.Localize("colorNames.red");
                    break;

                case Classification.Colors.Green:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.green");
                    label += Strings.Localize("colorNames.green");
                    break;

                case Classification.Colors.Blue:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.blue");
                    label += Strings.Localize("colorNames.blue");
                    break;

                case Classification.Colors.Orange:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.orange");
                    label += Strings.Localize("colorNames.orange");
                    break;

                case Classification.Colors.Yellow:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.yellow");
                    label += Strings.Localize("colorNames.yellow");
                    break;

                case Classification.Colors.Purple:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.purple");
                    label += Strings.Localize("colorNames.purple");
                    break;

                case Classification.Colors.Pink:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.pink");
                    label += Strings.Localize("colorNames.pink");
                    break;

                case Classification.Colors.Brown:
                    glyph  = CardSpace.Cards.CardFaceTexture("filter.brown");
                    label += Strings.Localize("colorNames.brown");
                    break;

                default:
                    break;
                }

                // Grabbing the glyph from CardSpace may have changed rendertargets
                // since we now create them somewhat on demand.
                InGame.SetRenderTarget(rt);

                if (glyph != null)
                {
                    size = new Vector2(90, 90);
                    pos += new Vector2(7, 10);
                    quad.Render(glyph, pos, size, "TexturedPreMultAlpha");
                }

                // Options.
                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad)
                {
                    size = new Vector2(textureOptions.Width, textureOptions.Height);
                    pos  = new Vector2((rt.Width - size.X) / 2.0f, 470);
                    quad.Render(textureOptions, pos, size, "TexturedPreMultAlpha");
                }
                else
                {
                    size = new Vector2(textureOptionsKey.Width, textureOptionsKey.Height);
                    pos  = new Vector2((rt.Width - size.X) / 2.0f, 470);
                    quad.Render(textureOptionsKey, pos, size, "TexturedPreMultAlpha");

                    // Add key face icons.
                    Color    color = new Color(20, 20, 20);
                    TextBlob blob  = new TextBlob(UI2D.Shared.GetGameFont20, "[home]", 100);
                    blob.Justification = Boku.UI2D.UIGridElement.Justification.Center;

                    pos.Y += 16;
                    blob.RenderWithButtons(pos, color);
                    homeHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));

                    blob.RawText = "[esc]";
                    pos.Y       += 50;
                    blob.RenderWithButtons(pos, color);
                    editHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));

                    blob.RawText = "[enter]";
                    pos.Y       += 50;
                    blob.RenderWithButtons(pos, color);
                    restartHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));
                }

                // Add button labels.
                SpriteBatch         batch = UI2D.Shared.SpriteBatch;
                UI2D.Shared.GetFont Font  = UI2D.Shared.GetGameFont24Bold;
                //Color fontColor = new Color(10, 75, 108);
                Color   fontColor    = new Color(127, 127, 127);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                if (label != null)
                {
                    // Center the team name.
                    int len = (int)Font().MeasureString(label).X;
                    pos    = new Vector2(565, 386);
                    pos.X += (textureTeam.Width - textureTeam.Height - len) / 2;
                    TextHelper.DrawStringNoBatch(Font, label, pos + shadowOffset, shadowColor);
                    TextHelper.DrawStringNoBatch(Font, label, pos, fontColor);
                }

                pos = new Vector2(572, 482);
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.browse"), pos + shadowOffset, shadowColor);
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.browse"), pos, fontColor);

                pos.Y += 51;
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.edit"), pos + shadowOffset, shadowColor);
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.edit"), pos, fontColor);

                pos.Y += 51;
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.restart"), pos + shadowOffset, shadowColor);
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.restart"), pos, fontColor);

                // Restore default blend state.
                device.BlendState = BlendState.AlphaBlend;
            }

            if (ActiveWinner)
            {
                // Main graphic.
                Vector2 size = new Vector2(textureWinner.Width, textureWinner.Height);
                Vector2 pos  = new Vector2((rt.Width - size.X) / 2.0f, 0.0f);
                quad.Render(textureWinner, pos, size, "TexturedPreMultAlpha");

                // Options.
                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad)
                {
                    size = new Vector2(textureOptions.Width, textureOptions.Height);
                    pos  = new Vector2((rt.Width - size.X) / 2.0f, 470);
                    quad.Render(textureOptions, pos, size, "TexturedPreMultAlpha");
                }
                else
                {
                    size = new Vector2(textureOptionsKey.Width, textureOptionsKey.Height);
                    pos  = new Vector2((rt.Width - size.X) / 2.0f, 470);
                    quad.Render(textureOptionsKey, pos, size, "TexturedPreMultAlpha");

                    // Add key face icons.
                    Color    color = new Color(20, 20, 20);
                    TextBlob blob  = new TextBlob(UI2D.Shared.GetGameFont20, "[home]", 100);
                    blob.Justification = Boku.UI2D.UIGridElement.Justification.Center;

                    pos.Y += 16;
                    blob.RenderWithButtons(pos, color);
                    homeHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));

                    blob.RawText = "[esc]";
                    pos.Y       += 50;
                    blob.RenderWithButtons(pos, color);
                    editHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));

                    blob.RawText = "[enter]";
                    pos.Y       += 50;
                    blob.RenderWithButtons(pos, color);
                    restartHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));
                }

                // Add button labels.
                SpriteBatch         batch = UI2D.Shared.SpriteBatch;
                UI2D.Shared.GetFont Font  = UI2D.Shared.GetGameFont24Bold;
                Color fontColor           = new Color(10, 75, 108);

                pos = new Vector2(572, 482);
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.browse"), pos, fontColor);
                pos.Y += 51;
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.edit"), pos, fontColor);
                pos.Y += 51;
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.restart"), pos, fontColor);
            }

            if (ActiveGameOver)
            {
                // Main graphic.
                Vector2 size = new Vector2(textureGameOver.Width, textureGameOver.Height);
                Vector2 pos  = new Vector2((rt.Width - size.X) / 2.0f, 0.0f);
                quad.Render(textureGameOver, pos, size, "TexturedPreMultAlpha");

                // Options.
                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad)
                {
                    size = new Vector2(textureOptions.Width, textureOptions.Height);
                    pos  = new Vector2((rt.Width - size.X) / 2.0f, 470);
                    quad.Render(textureOptions, pos, size, "TexturedPreMultAlpha");
                }
                else
                {
                    size = new Vector2(textureOptionsKey.Width, textureOptionsKey.Height);
                    pos  = new Vector2((rt.Width - size.X) / 2.0f, 470);
                    quad.Render(textureOptionsKey, pos, size, "TexturedPreMultAlpha");

                    // Add key face icons.
                    Color    color = new Color(20, 20, 20);
                    TextBlob blob  = new TextBlob(UI2D.Shared.GetGameFont20, "[home]", 100);
                    blob.Justification = Boku.UI2D.UIGridElement.Justification.Center;

                    pos.Y += 16;
                    blob.RenderWithButtons(pos, color);
                    homeHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));

                    blob.RawText = "[esc]";
                    pos.Y       += 50;
                    blob.RenderWithButtons(pos, color);
                    editHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));

                    blob.RawText = "[enter]";
                    pos.Y       += 50;
                    blob.RenderWithButtons(pos, color);
                    restartHitBox.Set(pos, pos + new Vector2(100, blob.TotalSpacing));
                }

                // Add button labels.
                SpriteBatch         batch = UI2D.Shared.SpriteBatch;
                UI2D.Shared.GetFont Font  = UI2D.Shared.GetGameFont24Bold;
                Color fontColor           = new Color(10, 75, 108);

                pos = new Vector2(572, 482);
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.browse"), pos, fontColor);
                pos.Y += 51;
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.edit"), pos, fontColor);
                pos.Y += 51;
                TextHelper.DrawStringNoBatch(Font, Strings.Localize("gameOver.restart"), pos, fontColor);
            }

            InGame.RestoreRenderTarget();

            dirty = false;
        }   // end of RefreshTexture()
コード例 #6
0
            }   // end of RenderObj c'tor

            public override void Render(Camera camera)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                // Animate the dots...
                double tic = Time.WallClockTotalSeconds;

                tic *= 2.0;     // Speed up time?
                for (int i = 0; i < 4; i++)
                {
                    float t = (float)tic + 5.0f - 0.5f * i;
                    t %= 6.0f;
                    if (t > 4.0f)
                    {
                        dots[i].radius = 0.0f;
                        dots[i].alpha  = 0.0f;
                    }
                    else
                    {
                        t *= 0.5f;
                        if (t > 1.0f)
                        {
                            t = 2.0f - t;
                        }
                        t = TwitchCurve.Apply(t, TwitchCurve.Shape.EaseOut);

                        dots[i].radius = t * kMaxRadius;
                        dots[i].alpha  = t;
                    }
                }

                Vector2 screenSize = BokuGame.ScreenSize;

#if NETFX_CORE
                // For some reason, right at the start, this shows up as 0, 0.
                if (screenSize == Vector2.Zero)
                {
                    screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height);
                }
#endif

                Vector2 backgroundSize = new Vector2(backgroundTexture.Width, backgroundTexture.Height);
                Vector2 position       = (screenSize - backgroundSize) / 2.0f;
                // Clamp to pixels.
                position.X = (int)position.X;
                position.Y = (int)position.Y;

                // Clear the screen & z-buffer.
                InGame.Clear(Color.Black);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;

                batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
                {
                    // Apply the background.
                    batch.Draw(backgroundTexture, position, Color.White);

                    // Render dots.
                    for (int i = 0; i < 4; i++)
                    {
                        Vector2 size = new Vector2(dots[i].radius);
                        Vector2 pos  = position + dots[i].position - size;
                        size *= 2;
                        Color color = new Color(1, 1, 1, dots[i].alpha);
                        batch.Draw(dotTexture, new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y), color);
                        // Reflection
                        color = new Color(1, 1, 1, dots[i].alpha * 0.15f);
                        batch.Draw(dotTexture, new Rectangle((int)pos.X, (int)pos.Y + 150, (int)size.X, (int)size.Y), color);
                    }

                    // If in wait mode, show texture.
                    if (shared.waitMode)
                    {
                        Vector2 size = new Vector2(waitTexture.Width, waitTexture.Height);
                        Vector2 pos  = screenSize * 0.5f - size * 0.5f;
                        pos.Y -= 50;
                        batch.Draw(waitTexture, new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y), Color.White);
                    }
                }
                batch.End();
            }   // end of Render()
コード例 #7
0
        }   // end of HandleMouseInput()

        /// <summary>
        /// Renders the dialog into a rendertarget.  This happens during Update() phase so
        /// that we don't need to swap rendertargets during the Render call.  This allows
        /// the dialog to be safely rendered into the scene when the scene itself is being
        /// rendered into a rendertarget.
        /// </summary>
        private void PreRender()
        {
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            //
            // First, render the text into a rendertarget.
            //

            RenderTarget2D rt1k = UI2D.Shared.RenderTarget1024_768;

            CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();
            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

            Color darkTextColor  = new Color(20, 20, 20);
            Color greyTextColor  = new Color(127, 127, 127);
            Color greenTextColor = new Color(8, 123, 110);
            Color whiteTextColor = new Color(255, 255, 255);

            // Render the text into the 1k rendertarget.
            InGame.SetRenderTarget(rt1k);
            InGame.Clear(Color.Transparent);

            // Set up params for rendering UI with this camera.
            Fx.ShaderGlobals.SetCamera(camera);

            //
            // Text.
            //

            // If we don't have enough text to go into scrolling, center vertically.
            int centering = 0;

            if (blob.NumLines < textVisibleLines)
            {
                centering += (int)(blob.TotalSpacing * (textVisibleLines - blob.NumLines) / 2.0f);
            }

            Vector2 pos;

            pos = new Vector2(textMargin, textTop + textOffset + centering);

            int startLine = 0;

            if (textOffset < 0)
            {
                startLine = -(int)(textOffset / blob.TotalSpacing);
                pos.Y    += startLine * blob.TotalSpacing;
            }

            // Clamp to pixel coords.
            pos.X = (int)pos.X;
            pos.Y = (int)pos.Y;
            blob.RenderWithButtons(pos, greyTextColor, startLine: startLine, maxLines: textVisibleLines + 2);

            InGame.RestoreRenderTarget();

            //
            // Second, render all the chrome with the text into the final rendertarget.

            RenderTarget2D rtFull = UI2D.Shared.RenderTargetDepthStencil1024_768;   // Rendertarget we render whole display into.

            // Render the scene to our rendertarget.
            InGame.SetRenderTarget(rtFull);

            // Clear to transparent.
            InGame.Clear(Color.Transparent);

            // Set up params for rendering UI with this camera.
            Fx.ShaderGlobals.SetCamera(camera);

            Vector2 rtSize = new Vector2(rtFull.Width, rtFull.Height);

            // Now render the background tiles.
            Vector2 backgroundSize = new Vector2(backgroundTexture.Width, backgroundTexture.Height);

            pos = (rtSize - backgroundSize) / 2.0f;
            // Clamp to pixel coords.
            pos.X = (int)pos.X;
            pos.Y = (int)pos.Y;
            ssquad.Render(backgroundTexture, pos, backgroundSize, @"TexturedRegularAlpha");

            displayPosition = pos;

            // Now render the contents of the rt1k texture but with the edges blended using the mask.
            Vector2 rt1kSize = new Vector2(rt1k.Width, rt1k.Height);

            pos -= new Vector2(40, 70);

            // Clamp to nearest pixel;
            pos.X = (int)pos.X;
            pos.Y = (int)pos.Y;

            try//minimize bug fix.
            {
                Vector4 limits = new Vector4(0.095f, 0.112f, 0.57f, 0.64f);
                ssquad.RenderWithYLimits(rt1k, limits, pos, rt1kSize, @"TexturedRegularAlpha");
            }
            catch
            {
                InGame.RestoreRenderTarget();
                return;
            }

            //
            // Add button icon with label.
            //

            SpriteBatch batch = UI2D.Shared.SpriteBatch;
            Vector2     min; // Used to capture info for mouse hit boxes.
            Vector2     max;

            batch.Begin();
            {
                pos = new Vector2(rtSize.X / 2.0f, rtSize.Y / 2.0f + backgroundSize.Y * 0.28f);
                int buttonWidth = 48;
                pos.X -= (Font().MeasureString(Strings.Localize("textDialog.continue")).X + buttonWidth) / 2.0f;
                // Also account for B button if we have one.
                int margin = 24;
                if (!string.IsNullOrEmpty(textB))
                {
                    pos.X -= (Font().MeasureString(textB).X + buttonWidth + margin) / 2.0f;
                }
                min = pos;

                // Render the A button and it's label.
                ssquad.Render(ButtonTextures.AButton, pos, new Vector2(56, 56), @"TexturedRegularAlpha");
                pos.X += buttonWidth;
                max    = new Vector2(pos.X + Font().MeasureString(Strings.Localize("textDialog.continue")).X, min.Y + buttonWidth);
                hitBoxA.Set(min, max);

                TextHelper.DrawString(Font, Strings.Localize("textDialog.continue"), pos, labelAColor);

                pos.X += Font().MeasureString(Strings.Localize("textDialog.continue")).X + margin;
                min    = pos;

                // Render the B button and it's label.
                if (!string.IsNullOrEmpty(textB))
                {
                    ssquad.Render(ButtonTextures.BButton, pos, new Vector2(56, 56), @"TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    max    = new Vector2(pos.X + Font().MeasureString(textB).X, min.Y + buttonWidth);
                    hitBoxB.Set(min, max);

                    TextHelper.DrawString(Font, textB, pos, labelBColor);
                }
            }
            batch.End();

            // Add left stick if needed.
            if (blob.NumLines >= textVisibleLines)
            {
                pos = displayPosition + new Vector2(-31, 300);
                ssquad.Render(leftStick, pos, new Vector2(leftStick.Width, leftStick.Height), "TexturedRegularAlpha");
                min = pos;
                max = min + new Vector2(leftStick.Width, leftStick.Height / 2.0f);
                upBox.Set(min, max);
                min.Y  = max.Y;
                max.Y += leftStick.Height / 2.0f;
                downBox.Set(min, max);
            }

            InGame.RestoreRenderTarget();
        }   // end of PreRender()
コード例 #8
0
            public override void Render(Camera camera)
            {
                if (!parent.Active)
                {
                    return;
                }

                ScreenSpaceQuad quad   = ScreenSpaceQuad.GetInstance();
                GraphicsDevice  device = BokuGame.bokuGame.GraphicsDevice;

                HelpOverlay.RefreshTexture();

                RenderTarget2D rt = UI2D.Shared.RenderTarget1024_768;

                Vector2 screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height);
                Vector2 rtSize     = new Vector2(rt.Width, rt.Height);

                if (shared.dataChanged)
                {
                    shared.dataChanged = false;

#if RenderColorBlocks
                    InGame.SetRenderTarget(rt);

                    // Clear the screen.
                    InGame.Clear(Color.Black);

                    // Render data block to screen.
                    Vector4 colorLo = new Vector4(0, 0, 0, 1);
                    Vector4 colorHi = new Vector4(0, 0, 0, 1);
                    for (int j = 0; j < blockH; j++)
                    {
                        for (int i = 0; i < blockW; i++)
                        {
                            byte b = shared.data[i + j * blockW];

                            byte lo = (byte)(b & 0x0f);
                            byte hi = (byte)((b & 0xf0) >> 4);

                            // Least significant bits go into red.
                            colorLo.X = (lo & 0x03) * 0.25f + 0.125f;
                            colorLo.Y = ((lo >> 2) & 0x03) * 0.25f + 0.125f;

                            colorHi.X = (hi & 0x03) * 0.25f + 0.125f;
                            colorHi.Y = ((hi >> 2) & 0x03) * 0.25f + 0.125f;

                            Block(colorLo, colorHi, i, j);
                        }
                    }

                    InGame.RestoreRenderTarget();
#else
                    try
                    {
                        // Render data block into memory.
                        Color colorLo = Color.Black;
                        Color colorHi = Color.Black;
                        for (int j = 0; j < blockH; j++)
                        {
                            for (int i = 0; i < blockW; i++)
                            {
                                byte b = shared.data[i + j * blockW];

                                byte lo = (byte)(b & 0x0f);
                                byte hi = (byte)((b & 0xf0) >> 4);

                                // Least significant bits go into red.
                                colorLo.R = (byte)((lo & 0x03) * 64 + 32);
                                colorLo.G = (byte)(((lo >> 2) & 0x03) * 64 + 32);

                                colorHi.R = (byte)((hi & 0x03) * 64 + 32);
                                colorHi.G = (byte)(((hi >> 2) & 0x03) * 64 + 32);

                                MemBlock(colorLo, colorHi, i, j);
                            }
                        }

                        shared.texture.SetData <Color>(shared.colors);

                        // Copy to rendertarget.
                        InGame.SetRenderTarget(rt);
                        quad.Render(shared.texture, Vector2.Zero, new Vector2(shared.texture.Width, shared.texture.Height), "TexturedNoAlpha");
                        InGame.RestoreRenderTarget();
                    }
                    catch (Exception e)
                    {
                        if (e != null)
                        {
                        }

                        // Something faileded, try again next frame.
                        shared.dataChanged = true;
                    }
#endif
                }

                InGame.Clear(Color.Black);

                quad.Render(rt, Vector2.Zero, rtSize, @"TexturedNoAlpha");
            }   // end of Render()
コード例 #9
0
            }   // end of Render()

            /// <summary>
            /// If the text being displayed has changed, we need to refresh the texture.
            /// Note this requires changing the rendertarget so this should no be called
            /// during the normal rendering loop.
            /// </summary>
            public void RefreshTexture()
            {
                if (shared.dirty)
                {
                    GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                    SpriteBatch         batch  = UI2D.Shared.SpriteBatch;
                    UI2D.Shared.GetFont Font20 = UI2D.Shared.GetGameFont20;
                    UI2D.Shared.GetFont Font24 = UI2D.Shared.GetGameFont24;

                    InGame.SetRenderTarget(diffuse);
                    InGame.Clear(Color.Transparent);

                    TextBlob blob = new TextBlob(UI2D.Shared.GetGameFont20, shared.Prompt, (int)(diffuse.Width - 2.0f * margin));

                    // Render the backdrop.
                    ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
                    ssquad.Render(background, Vector2.Zero, new Vector2(512, 256), @"TexturedPreMultAlpha");

                    // Render the prompt.
                    if (shared.Prompt != null && shared.Prompt.Length > 0)
                    {
                        // Render the prompt text into the texture.
                        Vector2 promptPos = new Vector2(margin, margin);
                        int     textWidth = (int)Font20().MeasureString(shared.Prompt).X;

                        blob.RenderWithButtons(promptPos, shared.textColor, shared.shadowColor, new Vector2(1, 1), maxLines: 3);

                        //TextHelper.DrawStringWithShadow(Font20, batch, x, y, shared.Prompt, shared.textColor, shared.shadowColor, false);
                    }


                    batch.Begin();

                    Vector2 glyphSize = new Vector2(64f, 64f);

                    // Pre-measure the button strip so we can align it.

                    int stripWidth = 0;
                    if (0 != (shared.parent.Buttons & TextDialogButtons.Accept))
                    {
                        string text = shared.parent.ButtonText(TextDialogButtons.Accept);
                        stripWidth += ((int)glyphSize.X * 7 / 6) + (int)Font20().MeasureString(text).X;
                    }
                    if (0 != (shared.parent.Buttons & TextDialogButtons.Discard))
                    {
                        string text = shared.parent.ButtonText(TextDialogButtons.Discard);
                        stripWidth += ((int)glyphSize.X * 7 / 6) + (int)Font20().MeasureString(text).X;
                    }
                    if (0 != (shared.parent.Buttons & TextDialogButtons.Cancel))
                    {
                        string text = shared.parent.ButtonText(TextDialogButtons.Cancel);
                        stripWidth += ((int)glyphSize.X * 7 / 6) + (int)Font20().MeasureString(text).X;
                    }

                    // Render the buttons and the text that goes with them.

                    Point position = new Point();
                    position.X = (backgroundWidth - stripWidth) / 2;
                    position.Y = backgroundHeight - margin - 40;
                    ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                    if (0 != (shared.parent.Buttons & TextDialogButtons.Accept))
                    {
                        string text = shared.parent.ButtonText(TextDialogButtons.Accept);
                        quad.Render(ButtonTextures.AButton, new Vector2(position.X, position.Y - 2), glyphSize, @"TexturedRegularAlpha");
                        position.X += (int)glyphSize.X * 2 / 3;
                        TextHelper.DrawStringWithShadow(Font20, batch, position.X, position.Y, text, Color.White, Color.Black, false);
                        position.X += (int)glyphSize.X / 2 + (int)Font20().MeasureString(text).X;
                    }

                    if (0 != (shared.parent.Buttons & TextDialogButtons.Discard))
                    {
                        string text = shared.parent.ButtonText(TextDialogButtons.Discard);
                        quad.Render(ButtonTextures.XButton, new Vector2(position.X, position.Y - 2), glyphSize, @"TexturedRegularAlpha");
                        position.X += (int)glyphSize.X * 2 / 3;
                        TextHelper.DrawStringWithShadow(Font20, batch, position.X, position.Y, text, Color.White, Color.Black, false);
                        position.X += (int)glyphSize.X / 2 + (int)Font20().MeasureString(text).X;
                    }

                    if (0 != (shared.parent.Buttons & TextDialogButtons.Cancel))
                    {
                        string text = shared.parent.ButtonText(TextDialogButtons.Cancel);
                        quad.Render(ButtonTextures.BButton, new Vector2(position.X, position.Y - 2), glyphSize, @"TexturedRegularAlpha");
                        position.X += (int)glyphSize.X * 2 / 3;
                        TextHelper.DrawStringWithShadow(Font20, batch, position.X, position.Y, text, Color.White, Color.Black, false);
                        position.X += (int)glyphSize.X / 2 + (int)Font20().MeasureString(text).X;
                    }

                    // Render the user text.
                    // Position user text in the vertical center of the tile.
                    position.X  = margin;
                    position.Y  = margin + blob.NumLines * blob.TotalSpacing;
                    position.Y += (backgroundHeight - position.Y) / 2 - Font24().LineSpacing - Font24().LineSpacing / 2;

                    // Calc the cursor position.
                    string tmpText = shared.curString.Substring(0, shared.cursorPosition);
                    int    width   = (int)Font24().MeasureString(tmpText).X;

                    float   cursorHeight = Font24().LineSpacing + 4.0f;
                    Vector2 cursorTop    = new Vector2(position.X + width, position.Y);
                    Vector2 cursorBottom = cursorTop;
                    cursorBottom.Y += cursorHeight;

                    // Render the user text with cursor.
                    Vector2 pos = new Vector2(position.X, position.Y);
                    TextHelper.DrawString(Font24, shared.curString, pos, Color.Black);
                    Utils.Draw2DLine(cursorTop, cursorBottom, Color.Black.ToVector4());
                    pos += new Vector2(1, -1);
                    TextHelper.DrawString(Font24, shared.curString, pos, Color.White);
                    cursorTop    += new Vector2(1.0f, -1.0f);
                    cursorBottom += new Vector2(1.0f, -1.0f);
                    Utils.Draw2DLine(cursorTop, cursorBottom, Color.White.ToVector4());

                    batch.End();

                    // Restore backbuffer.
                    InGame.RestoreRenderTarget();

                    //shared.dirty = false;
                }
            }   // end of TextDialog RenderObj RefreshTexture()
コード例 #10
0
        }   // end of PreRender()

        public void Render()
        {
            if (Active)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                RenderTarget2D rtFull = UI2D.Shared.RenderTargetDepthStencil1024_768;   // Rendertarget we render whole display into.
                RenderTarget2D rt1k   = UI2D.Shared.RenderTarget1024_768;

                Vector2 rtSize = new Vector2(rtFull.Width, rtFull.Height);

                CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();
                ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

                Color darkTextColor  = new Color(20, 20, 20);
                Color greyTextColor  = new Color(127, 127, 127);
                Color greenTextColor = new Color(8, 123, 110);
                Color whiteTextColor = new Color(255, 255, 255);

                // Render the scene to our rendertarget.
                InGame.SetRenderTarget(rtFull);

                // Clear to transparent.
                InGame.Clear(Color.Transparent);


                // Set up params for rendering UI with this camera.
                Fx.ShaderGlobals.SetCamera(camera);

                Vector2 pos;

                // Now render the background tiles.
                Vector2 backgroundSize = new Vector2(backgroundTexture.Width, backgroundTexture.Height);
                pos = (rtSize - backgroundSize) / 2.0f;
                ssquad.Render(backgroundTexture, pos, backgroundSize, @"TexturedRegularAlpha");

                displayPosition = pos;

                // Now render the contents of the rt1k texture but with the edges blended using the mask.
                Vector2 rt1kSize = new Vector2(rt1k.Width, rt1k.Height);
                pos -= new Vector2(40, 70);
                try//minimize bug fix.
                {
                    Vector4 limits = new Vector4(0.095f, 0.112f, 0.57f, 0.64f);
                    ssquad.RenderWithYLimits(rt1k, limits, pos, rt1kSize, @"TexturedPreMultAlpha");
                }
                catch
                {
                    return;
                }

                //
                // Add button icons with labels.
                //

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                Vector2     min; // Used to capture info for mouse hit boxes.
                Vector2     max;

                batch.Begin();
                {
                    // Calc center position.
                    pos = new Vector2(rtSize.X / 2.0f, rtSize.Y / 2.0f + backgroundSize.Y * 0.28f);

                    // Calc overall width buttons and text.  Leave a button width's space between each section.
                    float aWidth      = Font().MeasureString(Strings.Localize("toast.continue")).X;
                    float xWidth      = Font().MeasureString(Strings.Localize("toast.dismiss")).X;
                    int   buttonWidth = 48;
                    float totalWidth  = aWidth + xWidth + 3.0f * buttonWidth;

                    pos.X -= totalWidth / 2.0f;

                    // A button
                    min = pos;
                    ssquad.Render(ButtonTextures.AButton, pos, new Vector2(56, 56), @"TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    TextHelper.DrawString(Font, Strings.Localize("toast.continue"), pos, labelAColor);
                    max = new Vector2(pos.X + aWidth, min.Y + buttonWidth);
                    hitBoxA.Set(min, max);

                    pos.X += aWidth;

                    // Space
                    pos.X += buttonWidth;

                    // X button
                    min = pos;
                    ssquad.Render(ButtonTextures.XButton, pos, new Vector2(56, 56), @"TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    TextHelper.DrawString(Font, Strings.Localize("toast.dismiss"), pos, labelBColor);
                    max = new Vector2(pos.X + xWidth, min.Y + buttonWidth);
                    hitBoxB.Set(min, max);
                }
                batch.End();

                // Add left stick if needed.
                if (blob.NumLines >= textVisibleLines)
                {
                    pos = displayPosition + new Vector2(-31, 300);
                    ssquad.Render(leftStick, pos, new Vector2(leftStick.Width, leftStick.Height), "TexturedRegularAlpha");
                    min = pos;
                    max = min + new Vector2(leftStick.Width, leftStick.Height / 2.0f);
                    upBox.Set(min, max);
                    min.Y  = max.Y;
                    max.Y += leftStick.Height / 2.0f;
                    downBox.Set(min, max);
                }

                InGame.RestoreRenderTarget();
                InGame.SetViewportToScreen();

                // No put it all together.
                // Start with the background.
                if (useBackgroundThumbnail)
                {
                    if (!thumbnail.GraphicsDevice.IsDisposed && !thumbnail.IsDisposed)
                    {
                        // Render the blurred thumbnail (if valid) full screen.
                        if (!thumbnail.GraphicsDevice.IsDisposed)
                        {
                            InGame.RestoreViewportToFull();
                            Vector2 screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height);
                            ssquad.Render(thumbnail, Vector2.Zero, screenSize, @"TexturedNoAlpha");
                            InGame.SetViewportToScreen();
                        }
                    }
                    else
                    {
                        // No valid thumbnail, clear to dark.
                        device.Clear(darkTextColor);
                    }
                }

                // Calc scaling and position for rt.
                renderPosition = Vector2.Zero;
                renderScale    = 1.0f;

                // The part of the dialog we care about is 1024x600 so we want to use
                // that as the size to fit to the screen.
                Vector2 dialogSize = new Vector2(1024, 600);
                Vector2 scale      = BokuGame.ScreenSize / dialogSize;
                renderScale = Math.Min(Math.Min(scale.X, scale.Y), 1.0f);
                Vector2 renderSize = rt1kSize * renderScale;

                // Center on screen.
                renderPosition = (BokuGame.ScreenSize - renderSize) / 2.0f;

                ssquad.Render(rtFull, renderPosition, renderSize, @"TexturedRegularAlpha");
            }
        }   // end of ScrollableModalHint Render()
コード例 #11
0
        }   // end of Render()

        #endregion

        #region Internal

        /// <summary>
        /// If the text being displayed has changed, we need to refresh the texture.
        /// Note this requires changing the rendertarget so this should no be called
        /// during the normal rendering loop.
        /// </summary>
        private void RefreshTexture()
        {
            if (dirty)
            {
                GraphicsDevice device = BokuGame.Graphics.GraphicsDevice;

                LoadContent(true);

                diffuse = UI2D.Shared.RenderTarget512_302;
                if (diffuse == null)
                {
                    /// Not ready yet, remain dirty.
                    return;
                }
                SpriteBatch batch  = UI2D.Shared.SpriteBatch;
                SpriteFont  font20 = UI2D.Shared.GameFont20;
                SpriteFont  font24 = UI2D.Shared.GameFont24;

                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                // Render the backdrop.
                ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
                ssquad.Render(background, Vector2.Zero, new Vector2(512, 512), @"TexturedPreMultAlpha");

                //
                // Render the text message.
                //

                List <string> lineList = new List <string>();
                TextHelper.SplitMessage(Text, (int)(width - margin * 2), font24, false, lineList);

                // Calc center of display.
                int y  = (int)((height - 1.5f * font24.LineSpacing) / 2.0f);
                int dy = font24.LineSpacing;
                // Offset based on number of lines.
                y -= (int)(dy * (lineList.Count - 1) / 2.0f);

                batch.Begin();

                for (int i = 0; i < lineList.Count; i++)
                {
                    string line = lineList[i];

                    // Render the label text into the texture.
                    int     x        = 0;
                    Vector2 textSize = font24.MeasureString(line);

                    x = TextHelper.CalcJustificationOffset(margin, (int)width, (int)textSize.X, Justification);

                    if (UseDropShadow)
                    {
                        TextHelper.DrawStringWithShadow(font24, batch, x, y, line, TextColor, DropShadowColor, InvertDropShadow);
                    }
                    else
                    {
                        batch.DrawString(font24, line, new Vector2(x, y), TextColor);
                    }

                    y += dy;
                }   // end of i loop over lines in list.

                //
                // Render any active buttons and the text that goes with them.
                //

                // We need to cal the width of each active button and it's label
                // so we can center the whole set at the bottom of the dialog.
                // TODO Set this up so we can also right/left justify?

                Vector2 position = Vector2.Zero;
                position.X = width / 2.0f;
                position.Y = height - margin - 40.0f;

                Vector2 buttonSize  = new Vector2(64, 64);  // Size for rendering.
                int     buttonWidth = 40;                   // Size for spacing.
                int     gap         = 8;                    // Space between sets.

                float totalWidth = 0;

                if (handlerA != null)
                {
                    totalWidth += buttonWidth;
                    totalWidth += font20.MeasureString(labelA).X;
                }
                if (handlerB != null)
                {
                    if (totalWidth != 0)
                    {
                        totalWidth += gap;
                    }
                    totalWidth += buttonWidth;
                    totalWidth += font20.MeasureString(labelB).X;
                }
                if (handlerX != null)
                {
                    if (totalWidth != 0)
                    {
                        totalWidth += gap;
                    }
                    totalWidth += buttonWidth;
                    totalWidth += font20.MeasureString(labelX).X;
                }
                if (handlerY != null)
                {
                    if (totalWidth != 0)
                    {
                        totalWidth += gap;
                    }
                    totalWidth += buttonWidth;
                    totalWidth += font20.MeasureString(labelY).X;
                }

                position.X -= (int)totalWidth / 2;

                //
                // Render each button/label pair if needed.
                //
                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                if (handlerA != null)
                {
                    quad.Render(ButtonTextures.AButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha");
                    position.X += buttonWidth;
                    //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelA, TextColor, DropShadowColor, InvertDropShadow);
                    batch.DrawString(font20, labelA, position, TextColor);
                    position.X += (int)font20.MeasureString(labelA).X + gap;
                }
                if (handlerB != null)
                {
                    quad.Render(ButtonTextures.BButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha");
                    position.X += buttonWidth;
                    //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelB, TextColor, DropShadowColor, InvertDropShadow);
                    batch.DrawString(font20, labelB, position, TextColor);
                    position.X += (int)font20.MeasureString(labelB).X + gap;
                }
                if (handlerX != null)
                {
                    quad.Render(ButtonTextures.XButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha");
                    position.X += buttonWidth;
                    //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelX, TextColor, DropShadowColor, InvertDropShadow);
                    batch.DrawString(font20, labelX, position, TextColor);
                    position.X += (int)font20.MeasureString(labelX).X + gap;
                }
                if (handlerY != null)
                {
                    quad.Render(ButtonTextures.YButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha");
                    position.X += buttonWidth;
                    //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelY, TextColor, DropShadowColor, InvertDropShadow);
                    batch.DrawString(font20, labelY, position, TextColor);
                    position.X += (int)font20.MeasureString(labelY).X + gap;
                }

                batch.End();

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of MessageDialog RefreshTexture()
コード例 #12
0
            }   // end of GetGridFromCurTab()

            #endregion

            #region Internal

            /// <summary>
            /// Updates the texture to be rendered to the bottom bar based on the number of worlds and the current sort order.
            /// </summary>
            public void UpdateBottomBarTexture()
            {
                UIGrid grid       = GetGridFromCurTab();
                int    worldCount = grid != null ? grid.ActualDimensions.Y : 0;

                if (numWorlds != worldCount || bottomBarDirty)
                {
                    numWorlds      = worldCount;
                    bottomBarDirty = false;

                    GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                    // Render into the diffuse texture.
                    RenderTarget2D diffuse = bottomBar.Diffuse;

                    InGame.SetRenderTarget(diffuse);
                    InGame.Clear(Color.TransparentBlack);

                    BitmapFont font = BokuGame.fontBerlinSansFBDemiBold20;

                    // Render the label text into the texture.
                    const int   dpi           = 128;
                    const float buttonSpacing = 0.1f;   // Magic number gotten through trial and error.  No other reason.
                    int         x             = diffuse.Width / 2 + (int)((xButtonPosition.X - bottomBar.Position.X + buttonSpacing) * dpi);

                    int h = (int)(dpi * bottomBar.Height);
                    int y = (int)((h - font.LineHeight) / 2.0f) - 2;

                    // Only show delete option for MyWorlds and Downloads.
                    if (parent.curTab == Tab.MyWorlds || parent.curTab == Tab.Downloads)
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.deleteWorld, x, y, bottomBar.TextColor);
                    }

                    // Sort options.
                    x  = diffuse.Width / 2 + (int)((yButtonPosition.X - bottomBar.Position.X + buttonSpacing) * dpi);
                    x += DrawText(Strings.Instance.loadLevelMenu.oldSortBy, x, y, bottomBar.TextColor);

                    if (curSortOrder == LevelSort.SortBy.WorldName)
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.world, x, y, Color.Yellow);
                    }
                    else
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.world, x, y, bottomBar.TextColor);
                    }
                    x += DrawText(Strings.Instance.loadLevelMenu.separator, x, y, bottomBar.TextColor);
                    if (curSortOrder == LevelSort.SortBy.Creator)
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.oldCreator, x, y, Color.Yellow);
                    }
                    else
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.oldCreator, x, y, bottomBar.TextColor);
                    }
                    x += DrawText(Strings.Instance.loadLevelMenu.separator, x, y, bottomBar.TextColor);
                    if (curSortOrder == LevelSort.SortBy.Rating)
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.rating, x, y, Color.Yellow);
                    }
                    else
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.rating, x, y, bottomBar.TextColor);
                    }
                    x += DrawText(Strings.Instance.loadLevelMenu.separator, x, y, bottomBar.TextColor);
                    if (curSortOrder == LevelSort.SortBy.Date)
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.date, x, y, Color.Yellow);
                    }
                    else
                    {
                        x += DrawText(Strings.Instance.loadLevelMenu.date, x, y, bottomBar.TextColor);
                    }

                    string str = numWorlds.ToString() + (numWorlds == 1 ? Strings.Instance.loadLevelMenu.worldCount : Strings.Instance.loadLevelMenu.worldsCount);
                    x  = diffuse.Width - font.MeasureString(str) - 50;
                    x += DrawText(str, x, y, bottomBar.TextColor);

                    // Note:
                    // The button graphics are rendered on the fly in the Render()
                    // call rather than being rendered into the texture so they
                    // don't get washed out by the specular highlights.



                    // Restore backbuffer.
                    InGame.RestoreRenderTarget();
                }
            }   // end of UpdateBottomBarTexture()
コード例 #13
0
ファイル: MainMenu.cs プロジェクト: eanders-MS/KoduGameLab-1
            public override void Render(Camera camera)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                HelpOverlay.RefreshTexture();

                RenderTarget2D rt         = UI2D.Shared.RenderTargetDepthStencil1280_720;
                Vector2        screenSize = BokuGame.ScreenSize;
                Vector2        rtSize     = new Vector2(rt.Width, rt.Height);

                if (skipFrames > 0 || shared.waitingForStorage)
                {
                    InGame.Clear(Color.Black);
                    --skipFrames;
                    return;
                }

                shared.liveFeed.FeedSize = shared.liveFeed.ResetScrollBoxSize;
                InGame.SetRenderTarget(rt);

                // Clear the screen & z-buffer.
                InGame.Clear(Color.Black);

                // Apply the background.
                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                Vector2 position = Vector2.Zero;

                quad.Render(shared.backgroundTexture, position, rtSize, @"TexturedNoAlpha");

                Color textColor = new Color(21, 125, 178);

                if (parent.newWorldDialog.Active)
                {
                    // Hide the dialog if auth UI is active.  Just keeps things cleaner.
                    if (!AuthUI.IsModalActive)
                    {
                        // If options menu is active, render instead of main menu.
                        parent.newWorldDialog.Render(new Vector2(rt.Width, rt.Height));
                    }
                }
                else if (shared.optionsMenu.Active)
                {
                    // Hide the menu if auth UI is active.  Just keeps things cleaner.
                    if (!AuthUI.IsModalActive)
                    {
                        // If options menu is active, render instead of main menu.
                        shared.optionsMenu.Render();
                    }
                }
                else
                {
                    // Render url
                    SpriteBatch         batch = UI2D.Shared.SpriteBatch;
                    UI2D.Shared.GetFont Font  = UI2D.Shared.GetGameFont24;
                    Vector2             size  = Font().MeasureString(shared.screenUrl);
                    Vector2             pos   = new Vector2(rt.Width / 2 - size.X / 2, 586);
                    batch.Begin();
                    TextHelper.DrawString(Font, shared.screenUrl, pos, textColor);
                    batch.End();
                    shared.urlBox.Set(pos, pos + size);

                    // Hide the menu if auth UI is active.  Just keeps things cleaner.
                    if (!AuthUI.IsModalActive)
                    {
                        // Render menu using local cameras.
                        ShaderGlobals.SetCamera(shared.camera);
                        shared.menu.WorldMatrix = Matrix.CreateTranslation(0.0f, -0.3f, 0.0f);
                        shared.menu.Render(shared.camera);
                    }

                    // Render Boku.
                    ShaderGlobals.SetCamera(shared.bokuCamera);
                    string oldRig = BokuGame.bokuGame.shaderGlobals.PushLightRig(ShaderGlobals.GreeterRigName);

                    // TODO (****) How to temporarily disable point lights???
                    // Do we really need to?
                    //Luz.SetToEffect(true); // disable scene point lights

                    if (BokuGame.bMarsMode)
                    {
                        shared.boku.Movement.Position = new Vector3(-0.0f, 0.25f, -0.5f);
                        shared.boku.ReScale           = 0.50f;

                        //quad = ScreenSpaceQuad.GetInstance();
                        //float wid=shared.jplTexture.Width/2;
                        //position = new Vector2(1250-(wid), 20);
                        //quad.Render(shared.jplTexture, position, new Vector2(wid, shared.jplTexture.Height/2), @"TexturedRegularAlpha");
                    }
                    else
                    {
                        shared.boku.Movement.Position = new Vector3(0.0f, 0.0f, 0.0f);
                    }
                    fVal += 0.01f;

                    // Be sure to set the right camera so the env map looks correct.
                    ShaderGlobals.SetCamera(shared.bokuCamera);

                    shared.boku.RenderObject.Render(shared.bokuCamera);

                    // TODO (****) How to temporarily disable point lights???
                    //Luz.SetToEffect(false); // re-enable scene point lights
                    BokuGame.bokuGame.shaderGlobals.PopLightRig(oldRig);
                }

                InGame.RestoreRenderTarget();

                InGame.Clear(new Color(20, 20, 20));
                InGame.SetViewportToScreen();

                // Copy the rendered scene to the backbuffer.
                {
                    ScreenWarp.FitRtToScreen(rtSize);

                    quad.Render(rt, ScreenWarp.RenderPosition, ScreenWarp.RenderSize, @"TexturedNoAlpha");
                }

                // Render news feed.
                if (!shared.optionsMenu.Active)
                {
                    shared.liveFeed.Render();
                }

                // Hide overlay if auth UI is active.
                if (!AuthUI.IsModalActive)
                {
                    HelpOverlay.Render();
                }

                // Render text dialogs if being shown by OptionsMenu.
                // TODO (****) Need to get rid of rendering to RTs where possible.
                // TODO (****) Need to split OptionsMenu from MainMenu.
                if (shared.optionsMenu.Active)
                {
                    InGame.inGame.shared.smallTextDisplay.Render();
                    InGame.inGame.shared.scrollableTextDisplay.Render();
                }

                MainMenu.Instance.prevSessionCrashedMessage.Render();
                MainMenu.Instance.noCommunityMessage.Render();
                MainMenu.Instance.noSharingMessage.Render();
            }   // end of Render()
コード例 #14
0
            public override void Render(Camera camera)
            {
                // Clear the screen.
                InGame.Clear(Color.Black);

                InGame.SetViewportToScreen();

                // Display current help screen.
                // Basically we're goin to shrink or stretch it to ensure that it is fully displayed without
                // having its aspect ratio changed.
                Vector2 imgSize = new Vector2(shared.curTexture.Width, shared.curTexture.Height);
                Vector2 ratios  = imgSize / BokuGame.ScreenSize;
                float   scale   = 1.0f / Math.Max(ratios.X, ratios.Y);
                Vector2 size    = imgSize * scale;
                Vector2 pos     = (BokuGame.ScreenSize - imgSize * scale) / 2.0f;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                pos.X += shared.pushOffset;
                quad.Render(shared.curTexture, pos, imgSize * scale, "TexturedNoAlpha");

                // If pushing, also render the previous help screen.
                if (shared.prevTexture != null && shared.pushOffset != 0)
                {
                    float offset = -Math.Sign(shared.pushOffset) * BokuGame.ScreenSize.X;
                    pos.X += offset;
                    quad.Render(shared.prevTexture, pos, imgSize, "TexturedNoAlpha");
                }

                // Label with page number in lower right hand corner.
                if (shared.curScreen >= 0 && shared.curScreen < shared.screenList.Count)
                {
                    // Start with far right corner and subtract off what we don't need.
                    pos = BokuGame.ScreenSize;

                    string str = (shared.curScreen + 1).ToString() + @"/" + shared.screenList.Count.ToString();

                    // Add in arrow buttons for mouse navigation.
                    size  = new Vector2(shared.rightArrowTexture.Width, shared.rightArrowTexture.Height);
                    size *= 0.5f;

                    // And add a bit of a margin.
                    pos -= new Vector2(30, 10 + UI2D.Shared.GameFont18Bold.LineSpacing);

                    // Right arrow.
                    pos.X -= size.X;
                    quad.Render(shared.rightArrowTexture, pos, size, "TexturedRegularAlpha");
                    shared.rightArrowBox.Set(pos, pos + size);

                    // Adjust for length of string.
                    pos.X -= UI2D.Shared.GameFont18Bold.MeasureString(str).X;

                    SpriteBatch batch = UI2D.Shared.SpriteBatch;
//                    Color blueText = new Color(12, 150, 209);
                    Color blueText = new Color(241, 221, 83);
                    Color shadow   = new Color(4, 50, 70);
//                    Color highlight = new Color(200, 230, 240);
                    Color highlight = new Color(255, 255, 240);
                    batch.Begin();
                    // shadow
                    TextHelper.DrawString(UI2D.Shared.GetGameFont18Bold, str, pos + new Vector2(1, 1), shadow);
                    // other dirs.
                    TextHelper.DrawString(UI2D.Shared.GetGameFont18Bold, str, pos + new Vector2(1, -1), shadow);
                    TextHelper.DrawString(UI2D.Shared.GetGameFont18Bold, str, pos + new Vector2(-1, 1), shadow);
                    // highlight
                    TextHelper.DrawString(UI2D.Shared.GetGameFont18Bold, str, pos + new Vector2(-1, -1), highlight);
                    // Front face
                    TextHelper.DrawString(UI2D.Shared.GetGameFont18Bold, str, pos, blueText);
                    batch.End();

                    // Left arrow.
                    pos.X -= size.X;
                    quad.Render(shared.leftArrowTexture, pos, size, "TexturedRegularAlpha");
                    shared.leftArrowBox.Set(pos, pos + size);

                    //Back button
                    //some padding on left of screen
                    pos.X = 30;
                    quad.Render(shared.backTexture, pos, size, "TexturedRegularAlpha");
                    shared.backBox.Set(pos, pos + size);
                }
            }
コード例 #15
0
        public void PreRender()
        {
            RenderTarget2D rt = Shared.RenderTargetDepthStencil1280_720;

            Vector2 rtSize = new Vector2(rt.Width, rt.Height);

            ScreenWarp.FitRtToScreen(rtSize);

            // Render the scene to our rendertarget.
            InGame.SetRenderTarget(rt);
            InGame.Clear(Color.Transparent);

            // Set up params for rendering UI with this camera.
            ShaderGlobals.SetCamera(camera);

            ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

            SpriteBatch batch = Shared.SpriteBatch;

            var center    = new Vector2(640, 360);
            var dialogMin = center - new Vector2(dialogWidth / 2, dialogHeight / 2);
            var dialogMax = center + new Vector2(dialogWidth / 2, dialogHeight / 2);


            // Top and bottom of dialog.
            var     size = new Vector2(dialogWidth, whiteTop.Height);
            Vector2 pos  = dialogMin;

            quad.Render(whiteTop, new Vector4(0, 0, 0, 1), pos, size, "TexturedRegularAlpha");
            pos += new Vector2(0, dialogHeight - 16);
            quad.Render(whiteBottom, new Vector4(0, 0, 0, 1), pos, size, "TexturedRegularAlpha");

            //dialog center
            size    = new Vector2(dialogWidth, dialogHeight);
            pos     = dialogMin;
            pos.Y  += 16;
            size.Y  = dialogHeight - 32;
            pos.X  += 1; //to match size of top and bottom pieces
            size.X -= 2; //
            quad.Render(new Vector4(0, 0, 0, 1), pos, size);

            //top and bottom highlights
            int highlightMargin = 3;

            pos    = dialogMin + new Vector2(highlightMargin, 2);
            size.X = dialogWidth - 2 * highlightMargin;
            size.Y = 30;
            quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), pos, size, "AdditiveBlendWithAlpha");

            pos    = dialogMin + new Vector2(highlightMargin, dialogHeight - 60);
            size.X = dialogWidth - 2 * highlightMargin;
            size.Y = 30;
            quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), pos, size, "AdditiveBlendWithAlpha");

            batch.Begin();

            //Dialog title.
            TextHelper.DrawString(Shared.GetGameFont20, title, dialogMin + new Vector2(10, 10 + 5), Color.White);

            //Ok and Cancel buttons
            var buttonSize = cancelButton.GetSize();

            pos = dialogMax - buttonSize - new Vector2(10, 10);
            cancelButton.Render(pos);

            buttonSize = okButton.GetSize();
            pos       -= new Vector2(buttonSize.X + 20, 0);
            okButton.Render(pos);

            batch.End();

            // Render text box
            textLineEditor.Render(camera);

            InGame.RestoreRenderTarget();

            InGame.SetViewportToScreen();
        }   // end of Render()
コード例 #16
0
        }   // end of Render()

        #endregion

        #region Internal

        /// <summary>
        /// If the text being displayed has changed, we need to refresh the texture.
        /// Note this requires changing the rendertarget so this should no be called
        /// during the normal rendering loop.
        /// </summary>
        private void RefreshTexture()
        {
            // This needs to be refactored.  The problem is that when the buttons change color
            // (for hover for instance) the changing state of thier color needs to set the dirty
            // flag.  For now, just always set it so we always have the right behavior.
            dirty = true;
            if (dirty)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                LoadContent(true);

                diffuse = UI2D.Shared.RenderTarget512_302;
                if (diffuse == null)
                {
                    // Not ready yet, remain dirty.
                    return;
                }
                SpriteBatch         batch  = UI2D.Shared.SpriteBatch;
                UI2D.Shared.GetFont Font20 = UI2D.Shared.GetGameFont20;
                UI2D.Shared.GetFont Font24 = UI2D.Shared.GetGameFont24;

                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                // Render the backdrop.
                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();
                quad.Render(background, Vector2.Zero, new Vector2(512, 302), @"TexturedPreMultAlpha");

                //
                // Render the text message.
                //

                Vector2 pos = new Vector2(margin, 0.0f);
                // Calc vertical center of display.
                pos.Y = (int)((height - blackHeight - 1.5f * textBlob.TotalSpacing) / 2.0f);
                // Offset based on number of lines.
                pos.Y -= (int)(textBlob.TotalSpacing * (textBlob.NumLines - 1) / 2.0f);

                textBlob.RenderWithButtons(pos + shadowOffset, shadowColor);
                textBlob.RenderWithButtons(pos, textColor);

                //
                // Render any active buttons and the text that goes with them.
                //

                batch.Begin();

                // We need to calc the width of each active button and it's label
                // so we can center the whole set at the bottom of the dialog.
                // TODO Set this up so we can also right/left justify?

                Vector2 position = Vector2.Zero;
                position.X = width / 2.0f;
                position.Y = height - margin - 40.0f;
                int gap = Button.Margin;

                int totalWidth = 0;
                if (aButton != null)
                {
                    totalWidth += (int)aButton.GetSize().X;
                    totalWidth += gap;
                }
                if (bButton != null)
                {
                    totalWidth += (int)bButton.GetSize().X;
                    totalWidth += gap;
                }
                if (xButton != null)
                {
                    totalWidth += (int)xButton.GetSize().X;
                    totalWidth += gap;
                }
                if (yButton != null)
                {
                    totalWidth += (int)yButton.GetSize().X;
                    totalWidth += gap;
                }

                totalWidth -= gap;   // Remove the extra one...
                position.X -= (int)(totalWidth / 2);

                if (aButton != null)
                {
                    aButton.Render(position);
                    position.X += aButton.GetSize().X + gap;
                }
                if (bButton != null)
                {
                    bButton.Render(position);
                    position.X += bButton.GetSize().X + gap;
                }
                if (xButton != null)
                {
                    xButton.Render(position);
                    position.X += xButton.GetSize().X + gap;
                }
                if (yButton != null)
                {
                    yButton.Render(position);
                    position.X += yButton.GetSize().X + gap;
                }

                batch.End();

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of ModularMessageDialog RefreshTexture()
コード例 #17
0
            public override void Render(Camera camera)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                RenderTarget2D rt = UI2D.Shared.RenderTargetDepthStencil1280_720;

                Vector2 screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height);
                Vector2 rtSize     = new Vector2(rt.Width, rt.Height);

                // Render the scene to our rendertarget.
                InGame.SetRenderTarget(rt);

                // Set up params for rendering UI with this camera.
                Fx.ShaderGlobals.SetCamera(shared.camera);

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Copy the background to the rt.
                quad.Render(backgroundTexture, Vector2.Zero, rtSize, "TexturedNoAlpha");

                // Set up local camera for rendering.
                Fx.ShaderGlobals.SetCamera(shared.camera);

                // Render the grid of friends.
                shared.grid.Render(shared.camera);

                Color darkText  = new Color(40, 40, 40);
                Color greenText = new Color(12, 255, 0);

                // Tile1
                Vector2 size     = new Vector2(tile1.Width, tile1.Height);
                Vector2 position = new Vector2(285, 0);

                quad.Render(tile1, position, size, "TexturedRegularAlpha");

                // TODO Add code to adjust for a change in the number of lines of text to make localization easier.
                position += new Vector2(120, 42);
                tile1Blob.RenderWithButtons(position, darkText);

                int numFriends = CalcNumInvitedFriends();

                SpriteBatch batch = UI2D.Shared.SpriteBatch;

                batch.Begin();

                int w = 70 - (int)UI2D.Shared.GetGameFont30Bold().MeasureString(numFriends.ToString()).X;

                position = new Vector2(790 + w / 2, 52);
                TextHelper.DrawString(UI2D.Shared.GetGameFont30Bold, numFriends.ToString(), position, greenText);

                position = new Vector2(865 - w / 3, 52);
                TextHelper.DrawString(UI2D.Shared.GetGameFont20, numFriends == 1 ? Strings.Localize("shareHub.friend") : Strings.Localize("shareHub.friends"), position, greenText);

                position = new Vector2(865 - w / 3, 77);
                TextHelper.DrawString(UI2D.Shared.GetGameFont20, Strings.Localize("shareHub.invited"), position, greenText);

                batch.End();

                // Tile2
                size     = new Vector2(tile2.Width, tile2.Height);
                position = new Vector2(285, 550);
                quad.Render(tile2, position, size, "TexturedRegularAlpha");

                // Set up hit box for bottom tile.
                shared.openBox.Set(position, position + size);

                // TODO Add code to adjust for a change in the number of lines of text to make localization easier.
                position += new Vector2(120, 48);
                tile2Blob.RenderWithButtons(position, darkText);


                InGame.RestoreRenderTarget();

                InGame.Clear(new Color(20, 20, 20));

                // Copy the rendered scene to the rendertarget.
                float rtAspect = rtSize.X / rtSize.Y;

                position = Vector2.Zero;
                Vector2 newSize = screenSize;

                newSize.X  = rtAspect * newSize.Y;
                position.X = (screenSize.X - newSize.X) / 2.0f;

                quad.Render(rt, position, newSize, @"TexturedNoAlpha");

                RenderMessages();
            }
コード例 #18
0
            public override void Render(Camera camera)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                RenderTarget2D rtFull = UI2D.Shared.RenderTargetDepthStencil1280_720;   // Rendertarget we render whole display into.
                RenderTarget2D rt1k   = UI2D.Shared.RenderTargetDepthStencil1024_768;

                Vector2 screenSize = BokuGame.ScreenSize;
                Vector2 rtSize     = new Vector2(rtFull.Width, rtFull.Height);

                CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();
                ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

                Color   greyTextColor   = new Color(127, 127, 127);
                Color   shadowTextColor = new Color(0, 0, 0, 20);
                Color   greenTextColor  = new Color(0, 255, 12);
                Color   whiteTextColor  = new Color(255, 255, 255);
                Vector2 shadowOffset    = new Vector2(0, 6);

                // Render the description text and examples into the 1k rendertarget.
                InGame.SetRenderTarget(rt1k);
                InGame.Clear(Color.Transparent);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;

                UI2D.Shared.GetFont FontHuge = UI2D.Shared.GetGameFont20;

                // Set up params for rendering UI with this camera.
                Fx.ShaderGlobals.SetCamera(shared.camera1k);

                //
                // Render the samples grid.
                //
                bool noExamples = shared.examplesGrid == null || shared.examplesGrid.ActualDimensions == Point.Zero;

                if (!noExamples)
                {
                    // Clear the stencil buffer.
                    device.Clear(ClearOptions.Stencil, Color.Transparent, 1.0f, 0);

                    // Render the new stencil mask.  Magic numbers from Photoshop.
                    ssquad.RenderStencil(Vector4.One, new Vector2(100, 300), new Vector2(820, 400));

                    // Turn off stencil writing while rendering the grid.
                    device.DepthStencilState = depthStencilStateNoWrite;

                    shared.examplesGrid.Render(shared.camera1k);

                    // Restore default.
                    device.DepthStencilState = DepthStencilState.Default;
                }

                // Render the scene to our rendertarget.
                InGame.SetRenderTarget(rtFull);

                // Set up params for rendering UI with this camera.
                Fx.ShaderGlobals.SetCamera(shared.camera);

                InGame.Clear(Color.Transparent);

                // Set up effect for rendering tiles.
                effect.CurrentTechnique = effect.Techniques["NormalMappedNoTexture"];

                effect.Parameters["Alpha"].SetValue(1.0f);
                effect.Parameters["SpecularColor"].SetValue(Vector4.Zero);
                effect.Parameters["SpecularPower"].SetValue(16.0f);
                effect.Parameters["NormalMap"].SetValue(normalMap);

                // Render tiles.
                Matrix world = Matrix.Identity;

                world.Translation = new Vector3(-3.4f, 2.5f, 0.0f);
                effect.Parameters["WorldMatrix"].SetValue(world);
                effect.Parameters["WorldViewProjMatrix"].SetValue(world * shared.camera.ViewProjectionMatrix);
                effect.Parameters["DiffuseColor"].SetValue(new Vector4(1.0f, 1.0f, 1.0f, 0.2f));
                glassTile.Render(effect);

                world.Translation = new Vector3(1.15f, 2.5f, 0.0f);
                effect.Parameters["WorldMatrix"].SetValue(world);
                effect.Parameters["WorldViewProjMatrix"].SetValue(world * shared.camera.ViewProjectionMatrix);
                effect.Parameters["DiffuseColor"].SetValue(new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
                descTile.Render(effect);

                world.Translation = new Vector3(0.0f, -1.1f, 0.0f);
                effect.Parameters["WorldMatrix"].SetValue(world);
                effect.Parameters["WorldViewProjMatrix"].SetValue(world * shared.camera.ViewProjectionMatrix);
                effect.Parameters["DiffuseColor"].SetValue(new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
                examplesTile.Render(effect);

                // Render highlights on tiles.
                CameraSpaceQuad quad = CameraSpaceQuad.GetInstance();

                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Glass tile.
                quad.Render(shared.camera, glassTileHighlight, Vector4.One, 1.0f, new Vector2(-3.4f, 2.9f), new Vector2(2.02f, 1.25f), "TexturedRegularAlpha");

                // Desc tile.
                quad.Render(shared.camera, whiteHighlight, new Vector4(0.6f, 1.0f, 0.8f, 0.2f), 1.0f, new Vector2(1.15f, 1.85f), new Vector2(6.52f, 0.7f), "TexturedRegularAlpha");

                // Examples tile.
                quad.Render(shared.camera, blackHighlight, Vector4.One, 1.0f, new Vector2(0.0f, 0.3f), new Vector2(8.82f, 2.0f), "TexturedRegularAlpha");

                device.BlendState = BlendState.AlphaBlend;

                // Actor Icon.
                if (shared.actorHelp.upid != null)
                {
                    Texture2D actorImage = CardSpace.Cards.CardFaceTexture(shared.actorHelp.upid);
                    if (actorImage != null)
                    {
                        quad.Render(shared.camera, actorImage, new Vector2(-3.4f, 2.5f), new Vector2(1.8f, 1.8f), @"TexturedRegularAlpha");
                    }
                }

                // Stick Icons.
                ssquad.Render(leftStickTexture, new Vector2(181, 560), new Vector2(leftStickTexture.Width, leftStickTexture.Height), @"TexturedRegularAlpha");
                Vector2 min = new Vector2(181, 560);
                Vector2 max = min + new Vector2(leftStickTexture.Width, leftStickTexture.Height);

                shared.leftStickBox.Set(min, max);
                if (shared.descBlob.NumLines > 3)
                {
                    ssquad.Render(rightStickTexture, new Vector2(1036, 70), new Vector2(rightStickTexture.Width, rightStickTexture.Height), @"TexturedRegularAlpha");
                    min = new Vector2(1036, 70);
                    max = min + new Vector2(rightStickTexture.Width, rightStickTexture.Height);
                    shared.rightStickBox.Set(min, max);
                }

                // A button
                ssquad.Render(ButtonTextures.AButton, new Vector2(1000, 245), new Vector2(80, 80), "TexturedRegularAlpha");
                shared.chooseBox.Set(new Vector2(990 - UI2D.Shared.GetGameFont24().MeasureString(Strings.Localize("helpCard.choose")).X, 245), new Vector2(1060, 245 + 55));

                // Text labels.

                // Actor description
                // Render the new stencil mask.  Magic numbers from Photoshop.
                ssquad.RenderStencil(Vector4.One, new Vector2(310, 75), new Vector2(590, 140));

                device.DepthStencilState = depthStencilState;

                // Description.
                if (shared.descBlob != null)
                {
                    Vector2 pos = new Vector2(shared.descMargin, shared.descTop + shared.descOffset);
                    pos.X = 450;
                    shared.descBlob.RenderWithButtons(pos, greyTextColor, maxLines: 3);
                }

                // Restore DepthStencilState to default.
                device.DepthStencilState = DepthStencilState.Default;

                batch.Begin();

                // Actor name
                TextHelper.DrawString(UI2D.Shared.GetGameFont30Bold, shared.curActorName, new Vector2(450, 30) + shadowOffset, shadowTextColor);
                TextHelper.DrawString(UI2D.Shared.GetGameFont30Bold, shared.curActorName, new Vector2(450, 30), greyTextColor);

                // Create
                TextHelper.DrawString(UI2D.Shared.GetGameFont24Bold, Strings.Localize("helpCard.create"), new Vector2(268, 250), whiteTextColor);

                // Choose
                TextHelper.DrawString(UI2D.Shared.GetGameFont24, Strings.Localize("helpCard.choose"), new Vector2(990 - UI2D.Shared.GetGameFont24().MeasureString(Strings.Localize("helpCard.choose")).X, 250), greyTextColor);

                batch.End();


                // Now render the contents of the rt1k texture but with the edges blended using the mask.
                Vector4 limits = new Vector4(0.4f, 0.41f, 0.857f, 0.93f);

                ssquad.RenderWithYLimits(rt1k, limits, new Vector2((rtFull.Width - rt1k.Width) / 2, 0), new Vector2(rt1k.Width, rtFull.Height), @"TexturedPreMultAlpha");

                // Restore rt for final rendering.
                InGame.RestoreRenderTarget();

                device.Clear(ClearOptions.DepthBuffer, Color.Pink, 1.0f, 0);

                // Start by using the blurred version of the scene as a backdrop.
                if (!shared.thumbnail.GraphicsDevice.IsDisposed)
                {
                    //InGame.Clear(Color.Transparent);
                    ssquad.Render(shared.thumbnail, Vector2.Zero, new Vector2(device.Viewport.Width, device.Viewport.Height), @"TexturedNoAlpha");
                }
                else
                {
                    Color backgroundColor = new Color(16, 66, 52);  // 1/4 strength turquoise.
                    InGame.Clear(backgroundColor);
                }

                // Copy the rendered scene to the rendertarget.
                float   rtAspect = rtSize.X / rtSize.Y;
                Vector2 position = Vector2.Zero;
                Vector2 newSize  = screenSize;

                newSize.X  = rtAspect * newSize.Y;
                position.X = (screenSize.X - newSize.X) / 2.0f;

                ssquad.Render(rtFull, position + BokuGame.ScreenPosition, newSize, @"TexturedRegularAlpha");
            }   // end of AddItemHelpCard RenderObj Render()
コード例 #19
0
            public override void Render(Camera camera)
            {
                if (parent.saveLevelDialog.Active)
                {
                    parent.saveLevelDialog.Render(null);
                }
                else
                {
                    ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

                    // This clear is not needed in desktop build but is required to clear z-buffer in WinRT version.
                    // TODO (****) Maybe issue is that z-test should be off for this?
                    InGame.Clear(new Color(20, 20, 20));

                    // Fill the background with the thumbnail if valid.
                    RenderTarget2D smallThumb = InGame.inGame.SmallThumbNail as RenderTarget2D;
                    if (smallThumb != null && !smallThumb.IsDisposed)
                    {
                        SpriteBatch batch = UI2D.Shared.SpriteBatch;
                        batch.Begin(SpriteSortMode.Deferred, BlendState.Opaque);
                        {
                            // Stretch thumbnail across whole screen.  Don't worry about distorting it
                            // since it's blurred anyway.
                            Microsoft.Xna.Framework.Rectangle dstRect = new Microsoft.Xna.Framework.Rectangle((int)BokuGame.ScreenPosition.X, (int)BokuGame.ScreenPosition.Y, (int)BokuGame.ScreenSize.X, (int)BokuGame.ScreenSize.Y);

                            Microsoft.Xna.Framework.Rectangle srcRect;
                            if (BokuGame.ScreenPosition.Y > 0)
                            {
                                // Set srcRect to ignore part of image at top of screen.
                                int y = (int)(BokuGame.ScreenPosition.Y * smallThumb.Height / (float)BokuGame.ScreenSize.Y);
                                srcRect = new Microsoft.Xna.Framework.Rectangle(0, y, smallThumb.Width, smallThumb.Height - y);
                            }
                            else
                            {
                                // Set srcRect to cover full thumbnail.
                                srcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, smallThumb.Width, smallThumb.Height);
                            }
                            batch.Draw(smallThumb, dstRect, srcRect, Color.White);
                        }
                        batch.End();
                    }
                    else
                    {
                        // No thumbnail so just clear to black.
                        InGame.Clear(new Color(20, 20, 20));
                    }

                    InGame.SetViewportToScreen();

                    if (parent.newWorldDialog.Active)
                    {
                        // Hide the dialog if auth UI is active.  Just keeps things cleaner.
                        if (!AuthUI.IsModalActive)
                        {
                            // If options menu is active, render instead of main menu.
                            parent.newWorldDialog.Render(BokuGame.ScreenSize);
                        }
                    }
                    else
                    {
                        // Render menu using local camera.
                        shared.camera.Resolution = new Point((int)BokuGame.ScreenSize.X, (int)BokuGame.ScreenSize.Y);
                        shared.camera.Update();
                        Fx.ShaderGlobals.SetCamera(shared.camera);
                        shared.menu.Render(shared.camera);

                        {
                            CameraSpaceQuad quad = CameraSpaceQuad.GetInstance();
                            // Position Home icon on same baseline as menu title text.
                            // Assume uniform scaling.
                            float height = shared.menu.Height * shared.menu.WorldMatrix.M22;
                            float y      = height / 2.0f - 0.18f;
                            quad.Render(shared.camera, parent.homeTexture, new Vector2(-2.4f, y), new Vector2(1.2f, 1.2f), "TexturedRegularAlpha");
                        }

                        // Render sign out button if user is logged in.
                        Vector2 screenSize = BokuGame.ScreenSize;

                        // Messages will only render if active.
                        parent.saveChangesMessage.Render();
                        parent.saveChangesWithDiscardMessage.Render();
                        parent.shareSuccessMessage.Render();
                        parent.noCommunityMessage.Render();

                        shared.communityShareMenu.Render();

                        HelpOverlay.Render();
                    }
                }
            }   // end of Render()
コード例 #20
0
        public void Activate(GameActor thinker, string text, UIGridElement.Justification justification, bool useBackgroundThumbnail, bool useRtCoords)
        {
            if (text == null)
            {
                return;
            }

            if (state != States.Active)
            {
                this.useBackgroundThumbnail = useBackgroundThumbnail;
                this.useRtCoords            = useRtCoords;

                // Do stack handling here.  If we do it in the update object we have no
                // clue which order things get pushed and popped and madness ensues.
                CommandStack.Push(commandMap);

                state = States.Active;

                // Get the current scene thumbnail.  If we're using this from the main menu (options)
                // then use the title screen image instead.
                if (InGame.inGame.State == InGame.States.Inactive)
                {
                    thumbnail = BokuGame.bokuGame.mainMenu.BackgroundTexture;
                }
                else
                {
                    thumbnail = InGame.inGame.SmallThumbNail;
                }

                // Tell InGame we're using the thumbnail so no need to do full render.
                prevRenderWorldAsThumbnail = InGame.inGame.RenderWorldAsThumbnail;
                if (!prevRenderWorldAsThumbnail)
                {
                    InGame.inGame.RenderWorldAsThumbnail = true;
                }

                Time.Paused = true;

                HelpOverlay.Push(@"TextDisplay");

                // Get text string.
                if (thinker != null)
                {
                    text = TextHelper.ApplyStringSubstitutions(text, thinker as GameActor);
                }
                rawText            = text;
                text               = TextHelper.RemoveTags(text);
                blob               = new TextBlob(Font, text, textWidth);
                blob.Justification = justification;

                this.thinker = thinker;

                // Render text into RT.
                RenderTarget2D rt = UI2D.Shared.RenderTarget512_512;
                InGame.SetRenderTarget(rt);
                InGame.Clear(Color.Transparent);
                Color greyTextColor = new Color(127, 127, 127);
                blob.RenderWithButtons(textPosition, greyTextColor);
                InGame.RestoreRenderTarget();

                activationTime = Time.WallClockTotalSeconds;
            }
        }   // end of Activate