コード例 #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 HandleTouchInput()

        public override void Render(Camera camera)
        {
            CameraSpaceQuad quad = CameraSpaceQuad.GetInstance();

            Vector2 pos = new Vector2(worldMatrix.Translation.X, worldMatrix.Translation.Y);

            pos.X -= 3.4f;
            quad.Render(camera, tile, alpha, pos, new Vector2(1.2f, 1.2f), "TexturedRegularAlpha");

            pos.X += 0.8f;
            pos.Y += 0.7f;
            Point loc = camera.WorldToScreenCoords(new Vector3(pos.X, pos.Y, 0.0f));

            pos = new Vector2(loc.X, loc.Y);

            if (textBlob.NumLines == 1)
            {
                pos.Y += textBlob.Font().LineSpacing;
            }
            if (textBlob.NumLines == 2)
            {
                pos.Y += 0.5f * textBlob.Font().LineSpacing;
            }

            textBlob.RenderWithButtons(pos, textColor, maxLines: 3);
        }   // end of UIGrid2DProgrammedBotElement Render()
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pos">Appears to be position on RT to render this news item.  Different for each item.</param>
        override public void Render(Vector2 pos)
        {
            base.Render(pos);
            drawPos = pos;
            // drawOffset seems just to be an offset accumulated as each section of
            // the news item is rendered.
            Vector2 drawOffset = Vector2.Zero;

            dateBlob.RenderWithButtons(
                drawPos,
                Color.Black,
                maxLines: 1);
            drawOffset.Y += GetDateHeightOffset();

            titleBlob.RenderWithButtons(
                drawPos + drawOffset,
                Color.Black,
                maxLines: 1);
            drawOffset.Y += GetTitleHeightOffset();

            // Draw the body of the news item.
            textBlob.RenderWithButtons(drawPos + drawOffset, bodyTextColor);
            drawOffset.Y += textBlob.NumLines * textBlob.TotalSpacing;

            // Draw any attatched hyperlinks.
            foreach (Hyperlink link in hyperlinkList)
            {
                link.Draw(drawPos + drawOffset);
            }
        }
コード例 #4
0
        }   // end of OnCancel()

        /// <summary>
        ///
        /// </summary>
        /// <param name="screenSize">If rendering to an RT allows us to know how to center.</param>
        public void Render(Vector2 screenSize)
        {
            if (active)
            {
                titleRect      = new Rectangle(0, 0, 512, 72);
                dialogBodyRect = new Rectangle(0, 64, 512, 268);

                // Now that we have the final dialog size, center it on the screen.
                Vector2 pos = screenSize / 2.0f;
                pos.X           -= titleRect.Width / 2;
                pos.Y           -= (titleRect.Height + dialogBodyRect.Height) / 2;
                titleRect.X      = (int)pos.X;
                titleRect.Y      = (int)pos.Y;
                dialogBodyRect.X = titleRect.X;
                dialogBodyRect.Y = titleRect.Y + titleRect.Height;

                AuthUI.RenderTile(titleBarTexture, titleRect);
                AuthUI.RenderTile(dialogBodyTexture, dialogBodyRect);

                // Title bar text.
                string str = Strings.Localize("miniHub.emptyLevel");
                blob.RawText       = str;
                blob.Font          = UI2D.Shared.GetGameFont30Bold;
                blob.Justification = UIGridElement.Justification.Left;
                blob.RenderWithButtons(new Vector2(titleRect.X + 16, titleRect.Y + 6), Color.White, Color.Black, new Vector2(0, 2), maxLines: 1);

                // World tiles.
                // Update rects.
                Rectangle rect = new Rectangle(dialogBodyRect.X + margin, dialogBodyRect.Y + margin, 128, 128);
                foreach (NewWorldLevel level in levels)
                {
                    level.Box.Set(rect);
                    rect.X += 128 + margin;
                }

                foreach (NewWorldLevel level in levels)
                {
                    SpriteBatch batch = UI2D.Shared.SpriteBatch;
                    batch.Begin();
                    {
                        if (level.FrameColor != Color.Transparent)
                        {
                            int       frameWidth = 4;
                            Rectangle frameRect  = new Rectangle((int)level.Box.Min.X - frameWidth, (int)level.Box.Min.Y - frameWidth, (int)(level.Box.Width + 2 * frameWidth), (int)(level.Box.Height + 2 * frameWidth));
                            batch.Draw(Utils.white, frameRect, level.FrameColor);
                        }

                        batch.Draw(level.ThumbnailTexture, level.Box.Rectangle, Color.White);
                    }
                    batch.End();
                }

                // Buttons.  Fit at bottom of dialog.
                pos    = new Vector2(dialogBodyRect.Right, dialogBodyRect.Bottom);
                pos.X -= margin + 6;
                pos.Y -= margin + 8;
                pos   -= cancelButton.GetSize();
                cancelButton.Render(pos, useBatch: false);
            }
        }   // end of Render()
コード例 #5
0
            }   // end of Update()

            public void Render()
            {
                if (blob == null)
                {
                    blob = new TextBlob(UI2D.Shared.GetGameFont30Bold, "foo", 1000);
                }

                // NOTE: Assumes Begin has already been called on batch
                // and End will be called elsewhere.
                SpriteBatch batch = UI2D.Shared.SpriteBatch;

                bool invertColors = false;

                if (pressed && OnKey == null)
                {
                    invertColors = true;
                }

                // KeyCap
                batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
                Rectangle rect = new Rectangle((int)hitBox.Min.X, (int)hitBox.Min.Y, (int)hitBox.Size.X, (int)hitBox.Size.Y);

                batch.Draw(VirtualKeyboard.whiteTexture, rect, invertColors ? labelColor : keyCapColor);
                batch.End();

                // Texture
                // Note we render textures before labels just in case key has both.
                if (texture != null)
                {
                    // Center texture on keycap.
                    Vector2 size = new Vector2(texture.Width, texture.Height);
                    Vector2 pos  = this.position;
                    pos += (hitBox.Size - size) / 2.0f;
                    batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
                    batch.Draw(texture, pos, labelColor);
                    batch.End();
                }

                // Label
                if (!string.IsNullOrEmpty(label))
                {
                    blob.Font    = Font;
                    blob.RawText = label;

                    float width = blob.GetLineWidth(0);

                    // Center side to side based on actual width but top to bottom based on line spacing.
                    Vector2 pos = this.position;
                    pos.X += (hitBox.Size.X - width) / 2.0f;
                    pos.Y += (hitBox.Size.Y - Font().LineSpacing) / 2.0f;
                    // Clamp to int to get better looking glyphs.
                    pos.X = (int)pos.X;
                    pos.Y = (int)pos.Y;
                    blob.RenderWithButtons(pos, invertColors ? keyCapColor : labelColor);
                }
            }   // end of Render()
コード例 #6
0
        }   // end of HandleTouchInput()

        public override void Render(Camera camera)
        {
            CameraSpaceQuad quad = CameraSpaceQuad.GetInstance();

            Vector2 size = new Vector2(1.0f, 1.0f);
            Vector2 pos  = new Vector2(worldMatrix.Translation.X, worldMatrix.Translation.Y);
            //pos.Y += height / 2.0f;
            float gap = 0.1f;

            if (camera.Frustum.CullTest(worldMatrix.Translation, 1.2f) == Frustum.CullResult.TotallyOutside)
            {
                return;
            }

            // Render the reflex.

            if (tiles != null)
            {
                for (int i = 0; i < tiles.Count; i++)
                {
                    // Not fully selected?
                    if (alpha < 1.0f)
                    {
                        quad.Render(camera, unselectedBackground, pos + new Vector2(i * (size.X + gap), 0), size, @"TexturedRegularAlpha");
                    }

                    // Not fully unselected?
                    if (alpha > 0.0f)
                    {
                        quad.Render(camera, selectedBackground, alpha, pos + new Vector2(i * (size.X + gap), 0), size, @"TexturedRegularAlpha");
                    }

                    quad.Render(camera, tiles[i], pos + new Vector2(i * (size.X + gap), 0), size, @"TexturedRegularAlpha");
                }
            }

            // And the description.
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            //device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

            pos.Y -= size.Y / 2.0f;
            Point pixelCoord = camera.WorldToScreenCoords(new Vector3(pos.X, pos.Y, 0.0f));

            pos = new Vector2(pixelCoord.X, pixelCoord.Y);
            descBlob.RenderWithButtons(pos, textColor);

            //device.BlendState = BlendState.AlphaBlend;
        }   // end of UIGrid2DExampleElement Render()
コード例 #7
0
        public void Render()
        {
            if (active)
            {
                // Render the underlying button texture.
                AuthUI.RenderTile(tileTexture, tileRect);

                Vector2 offset = new Vector2(16, 6);
                if (pressed)
                {
                    offset.Y += 1;
                }
                blob.RenderWithButtons(hitBox.Min + offset, Color.White);
            } // end of active
        }     // end of Render()
コード例 #8
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()
コード例 #9
0
        }   // end of LiveFeedDisplay Render()

        #endregion

        #region Internal

        private void RenderFeedBasePlate()
        {
            GraphicsDevice device = BokuGame.Graphics.GraphicsDevice;

            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);
            Vector2         screenSize     = new Vector2(
                BokuGame.Graphics.GraphicsDevice.Viewport.Width,
                BokuGame.Graphics.GraphicsDevice.Viewport.Height);
            Vector2 pos       = new Vector2(0.0f, 40.0f);
            Vector2 baseSize  = GetScrollBoxSize;
            Vector2 iconSize  = new Vector2(42.0f, 42.0f);
            Vector4 baseColor = new Vector4(0.0f, 0.0f, 0.0f, 0.7f);
            // baseSize.X /= 5;
            // baseSize.Y *= 0.80f;
            Vector2 headerSize = baseSize;

            headerSize.X *= 0.8f;
            headerSize.Y *= 0.055f;
            Vector2 headerPos = pos;

            headerPos.Y -= headerSize.Y;

            Vector2 cornerSize = new Vector2(headerSize.Y * 0.25f, headerSize.Y * 0.25f);

            Vector2 titlePos = headerPos + textPosition;

            titlePos.X += iconSize.X;

            Vector2 iconPos = iconPosition;

            iconPos.Y += headerPos.Y;

            ssquad.Render(baseColor, headerPos, headerSize);
            ssquad.Render(baseColor, pos, baseSize);
            ssquad.Render(baseColor, headerPos + new Vector2(headerSize.X, cornerSize.Y), new Vector2(cornerSize.X, headerSize.Y - cornerSize.Y));

            ssquad.Render(cornerTR, baseColor, headerPos + new Vector2(headerSize.X, 0.0f), cornerSize, "TexturedRegularAlpha");
            ssquad.Render(cornerTR, baseColor, pos + new Vector2(baseSize.X, 0.0f), cornerSize, "TexturedRegularAlpha");
            ssquad.Render(cornerBR, baseColor, pos + baseSize - new Vector2(0.0f, cornerSize.Y), cornerSize, "TexturedRegularAlpha");
            ssquad.Render(baseColor, pos + new Vector2(baseSize.X, cornerSize.Y), new Vector2(cornerSize.X, baseSize.Y - (cornerSize.Y * 2)));

            blob.RenderWithButtons(titlePos, greyTextColor, false, UIGridElement.Justification.Center);
            ssquad.Render(Header_bg, iconPos, iconSize, "TexturedRegularAlpha");
        }
コード例 #10
0
        public void Draw(Vector2 position)
        {
            blob.RenderWithButtons(position, TextColor);

            // Set hitbox.  Note that the coordinates for the hitbox are relative
            // to the upper left hand corner of the rendertarget we're currently
            // drawing to, not the screen.  Need to adjust when hit testing.
            Vector2 size = new Vector2(blob.Font().MeasureString(blob.ScrubbedText).X, blob.TotalSpacing);

            hitBox.Set(position, position + size);

            /*
             * // Debug highlight of hyperlink hitbox.
             * ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
             * ssquad.Render(new Vector4(1, 0, 0, 0.5f), position, size);
             */
        }
コード例 #11
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()
コード例 #12
0
        override public void Render(Vector2 pos)
        {
            base.Render(pos);
            drawPos = pos;

            tweetBlob.RenderWithButtons(
                drawPos,
                Color.White,
                false,
                UIGridElement.Justification.Left);

            SpriteBatch batch = UI2D.Shared.SpriteBatch;

            batch.Begin();

            foreach (Hyperlink link in hyperlinkList)
            {
                if (useFocus)
                {
                    if (link == hyperlinkList[focusIndex])
                    {
                        link.drawColor = hoverColor;
                    }
                }
                foreach (TextSegment segment in link.segmentList)
                {
                    batch.DrawString(
                        tweetBlob.Font(),
                        segment.Text,
                        drawPos + segment.HitBox.Min,
                        link.drawColor);
                }
                // Always reset the draw color after rendering. This ensures that
                // only items which were changed this frame have a different color.
                link.drawColor = defaultColor;
            }

            batch.End();
        }
コード例 #13
0
            }   // end of PreGameRacingWithDesc Update()

            public override void Render(Camera camera)
            {
                if (showingDescription)
                {
                    Vector2 pos = Vector2.Zero;
                    pos.X = BokuGame.bokuGame.GraphicsDevice.Viewport.Width / 4.0f;
                    pos.Y = BokuGame.bokuGame.GraphicsDevice.Viewport.Height / 2.0f - blob.NumLines / 2.0f * blob.Font().LineSpacing;
                    blob.RenderWithButtons(pos, Color.White, outlineColor: Color.Black, outlineWidth: 1.5f, maxLines: 20);
                }
                else
                {
                    ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                    Vector2 center = 0.5f * new Vector2(BokuGame.bokuGame.GraphicsDevice.Viewport.Width, BokuGame.bokuGame.GraphicsDevice.Viewport.Height);
                    Vector2 size   = new Vector2(256.0f);

                    // Pick the right number texture to show.
                    double    dt      = Time.WallClockTotalSeconds - startTime;
                    Texture2D texture = texture3;
                    if (dt > 2.0)
                    {
                        texture = texture1;
                        dt     -= 2.0f;
                    }
                    else if (dt > 1.0)
                    {
                        texture = texture2;
                        dt     -= 1.0f;
                    }

                    size   *= 1.0f + 2.0f * (float)dt;
                    center -= 0.5f * size;

                    Vector4 color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f - (float)dt);

                    quad.Render(texture, color, center, size, "TexturedRegularAlpha");
                }
            }   // end of PreGameRacingWithDesc Render()
コード例 #14
0
            }   // end of PreGameDesc Update()

            public override void Render(Camera camera)
            {
                Texture2D logoTexture = null;

                if (!string.IsNullOrEmpty(logo))
                {
                    switch (logo)
                    {
                    case "n23":
                        logoTexture = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\NASA_JPL");
                        break;

                    default:
                        logoTexture = null;
                        break;
                    }
                }

                Vector2 pos = Vector2.Zero;

                pos.X = BokuGame.bokuGame.GraphicsDevice.Viewport.Width / 4.0f;
                pos.Y = BokuGame.bokuGame.GraphicsDevice.Viewport.Height / 2.0f - blob.NumLines / 2.0f * blob.Font().LineSpacing;

                if (logoTexture != null)
                {
                    Vector2 logoSize = new Vector2(logoTexture.Width, logoTexture.Height);

                    ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
                    // Position logo in upper right corner.
                    Vector2 logoPos = new Vector2(BokuGame.bokuGame.GraphicsDevice.Viewport.Width * 0.98f - logoSize.X, BokuGame.bokuGame.GraphicsDevice.Viewport.Width * 0.02f);
                    // Force to be pixel aligned.
                    logoPos.X = (int)logoPos.X;
                    logoPos.Y = (int)logoPos.Y;
                    ssquad.Render(logoTexture, logoPos, logoSize, "TexturedRegularAlpha");
                }

                blob.RenderWithButtons(pos, Color.White, outlineColor: Color.Black, outlineWidth: 1.5f, maxLines: 20);
            }   // end of PreGameDesc Render()
コード例 #15
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()
コード例 #16
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()
コード例 #17
0
        }   // end of Clear()

        private static void RefreshTexture()
        {
            bool lores = BokuGame.ScreenSize.Y <= 480;

            UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24Bold;
            if (lores)
            {
                Font = UI2D.Shared.GetGameFont30Bold;
            }
            blob.Font = Font;

            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
            RenderTarget2D  rt     = UI2D.Shared.RenderTarget512_302;

            InGame.SetRenderTarget(rt);

            InGame.Clear(Color.Transparent);

            ssquad.Render(background, Vector2.Zero, new Vector2(512, 302), "TexturedRegularAlpha");

            // Tile name.
            SpriteBatch batch = UI2D.Shared.SpriteBatch;
            Vector2     pos   = new Vector2(margin, margin);

            /*
             * batch.Begin();
             * TextHelper.DrawString(Font, curTip, pos, Color.Yellow);
             * batch.End();
             */
            string desc = blob.RawText; // Save string we're displaying.

            blob.RawText = curTip;
            if (blob.HasRtoL)
            {
                blob.Justification = Boku.UI2D.UIGridElement.Justification.Right;
            }
            blob.RenderWithButtons(pos, Color.Yellow);
            blob.RawText = desc;        // Restore

            // We need to special case groups since they don't have any data.  For groups
            // we just display a string that says "press <a> for more..."
            if (curTip == Strings.Localize("toolTips.group"))
            {
                blob = new TextBlob(Font, Strings.Localize("toolTips.groupDesc"), 512 - margin * 2);
                blob.Justification = Boku.UI2D.UIGridElement.Justification.Center;
                pos = new Vector2(0, (302 - Font().LineSpacing) / 2);
                blob.RenderWithButtons(pos, Color.White);
            }
            else
            {
                // Normal ToolTip.

                // Text description.
                if (blob != null)
                {
                    int maxLines = showButtons ? (lores ? 3 : 4) : (lores ? 4 : 6);

                    // Modify final line to end with ellipsis.
                    blob.AddEllipsisToLine(maxLines - 1);

                    // Move down to account for title.
                    pos.Y += Font().LineSpacing;

                    // If less than maxLines of text, center on texture.
                    int spareLines = maxLines - blob.NumLines - 1;
                    if (spareLines > 0)
                    {
                        pos.Y += spareLines * 0.5f * Font().LineSpacing;
                    }

                    // Right justify if RtoL
                    if (blob.HasRtoL)
                    {
                        blob.Justification = Boku.UI2D.UIGridElement.Justification.Right;
                    }

                    blob.RenderWithButtons(pos, Color.White, maxLines: maxLines);
                }

                // Buttons @ bottom
                if (showButtons)
                {
                    string aText = useAdd ? Strings.Localize("toolTips.add") : Strings.Localize("toolTips.change");

                    int     buttonWidth = 40;                   // For spacing.
                    Vector2 buttonSize  = new Vector2(64, 64);  // For rendering.
                    pos.Y = 302 - margin - Font().LineSpacing;
                    int aTextWidth = (int)Font().MeasureString(aText).X;
                    int yTextWidth = (int)Font().MeasureString(Strings.Localize("toolTips.examples")).X;
                    int width      = 3 * buttonWidth + aTextWidth + yTextWidth;
                    pos.X = (512 - width) / 2;

                    batch.Begin();

                    ssquad.Render(ButtonTextures.AButton, pos, buttonSize, "TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    TextHelper.DrawString(Font, aText, pos, Color.White);

                    pos.X += buttonWidth + aTextWidth;
                    ssquad.Render(ButtonTextures.YButton, pos, buttonSize, "TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    TextHelper.DrawString(Font, Strings.Localize("toolTips.examples"), pos, Color.White);

                    batch.End();
                }
            }

            InGame.RestoreRenderTarget();

            //
            // Copy result to local texture.
            //
            int[] data = new int[512 * 302];
            rt.GetData <int>(data);
            texture.SetData <int>(data);

            // Scale size to 1/4 screen height.
            int   w     = (int)BokuGame.ScreenSize.X;
            int   h     = (int)BokuGame.ScreenSize.Y;
            float scale = h / 4.0f / 302.0f;

            size  = new Vector2(512, 302);
            size *= scale;

            // Check position to keep on screen within 10% safe area.
            // Horizontal
            int safe = (int)(w * 0.05f);

            if (pendingPosition.X < safe)
            {
                pendingPosition.X = safe;
            }
            else if (pendingPosition.X > w - safe - size.X)
            {
                pendingPosition.X = w - safe - size.X;
            }
            // Vertical
            safe = (int)(h * 0.05f);
            if (pendingPosition.Y < safe)
            {
                pendingPosition.Y = safe;
            }
            else if (pendingPosition.Y > h - safe - size.Y)
            {
                pendingPosition.Y = h - safe - size.Y;
            }

            dirty = false;
        }   // end of RefreshTexture()
コード例 #18
0
        }   // end of UIGridModularButtonElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            // dirty = true;  // Debug only.

            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the white region with highlight.
                Vector2 position = new Vector2(h - 2, 0);
                Vector2 size     = new Vector2(w, h) - position;
                quad.Render(checkboxWhite, position, size, "TexturedNoAlpha");

                // Render the black box.
                position = Vector2.Zero;
                size.X   = size.Y;
                quad.Render(blackSquare, position, size, "TexturedRegularAlpha");

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

                // Render the label text into the texture.
                int margin = 16;
                position.X = (int)size.X + margin;

                string text = label + "\n";
                if (aButtonText != null)
                {
                    text += "    <A> " + aButtonText + "\n";
                }
                if (xButtonText != null)
                {
                    text += "    <X> " + xButtonText;
                }

                TextBlob blob = new TextBlob(Font, text, w - (int)position.X - margin);

                position.Y = (int)((h - blob.TotalSpacing) / 2.0f) - 2;
                if (blob.NumLines == 2)
                {
                    position.Y -= blob.TotalSpacing / 2.0f;
                }
                else if (blob.NumLines == 3)
                {
                    position.Y -= blob.TotalSpacing;
                }

                Color   fontColor    = new Color(127, 127, 127);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                blob.RenderWithButtons(position, fontColor, shadowColor, shadowOffset, maxLines: 3);

                // Restore default blending.
                device.BlendState = BlendState.AlphaBlend;

                int line = blob.NumLines - 1;   // Which line in the text has the button.

                // Calc bounding boxes in UV space for A and X buttons/labels.
                if (onXButton != null)
                {
                    Vector2 min = new Vector2(position.X / w, (position.Y + line * blob.TotalSpacing) / h);
                    Vector2 max = min + new Vector2((float)blob.GetLineWidth(line) / w, (float)blob.TotalSpacing / h);
                    xButtonBox.Set(min, max);
                    --line;
                }

                if (onAButton != null)
                {
                    Vector2 min = new Vector2(position.X / w, (position.Y + line * blob.TotalSpacing) / h);
                    Vector2 max = min + new Vector2((float)blob.GetLineWidth(line) / w, (float)blob.TotalSpacing / h);
                    aButtonBox.Set(min, max);
                }

                // DEBUG Show hit box for a button as overlay.

                /*
                 * if (onAButton != null)
                 * {
                 *  position = new Vector2(diffuse.Width * aButtonBox.Min.X, diffuse.Height * aButtonBox.Min.Y);
                 *  size = new Vector2(diffuse.Width * (aButtonBox.Size.X), diffuse.Height * aButtonBox.Size.Y);
                 *  quad.Render(new Vector4(1, 0, 0, 0.5f), position, size);
                 * }
                 * if (onXButton != null)
                 * {
                 *  position = new Vector2(diffuse.Width * xButtonBox.Min.X, diffuse.Height * xButtonBox.Min.Y);
                 *  size = new Vector2(diffuse.Width * (xButtonBox.Size.X), diffuse.Height * xButtonBox.Size.Y);
                 *  quad.Render(new Vector4(0, 1, 0, 0.5f), position, size);
                 * }
                 */

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularButtonElement Render()
コード例 #19
0
        }   // end of UIGridModularCheckboxElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the white region with highlight.
                Vector2 position = new Vector2(h - 2, 0);
                Vector2 size     = new Vector2(w, h) - position;
                quad.Render(checkboxWhite, position, size, "TexturedNoAlpha");

                // Render the checkbox.
                position = Vector2.Zero;
                size.X   = size.Y;
                if (check)
                {
                    quad.Render(checkOn, position, size, "TexturedRegularAlpha");
                }
                else
                {
                    quad.Render(checkOff, position, size, "TexturedRegularAlpha");
                }

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

                // Render the label text into the texture.
                int margin = 16;
                position.X = (int)size.X + margin;

                TextBlob blob = new TextBlob(Font, label, w - (int)position.X - margin);

                position.Y = (int)((h - blob.TotalSpacing) / 2.0f) - 2;

                if (blob.NumLines == 2)
                {
                    position.Y -= blob.TotalSpacing / 2.0f;
                }
                else if (blob.NumLines == 3)
                {
                    position.Y -= blob.TotalSpacing;
                }

                Color   fontColor    = new Color(127, 127, 127);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                blob.RenderWithButtons(position, fontColor, shadowColor, shadowOffset, maxLines: 3);

                // Render help button.

                /*
                 * if (ShowHelpButton)
                 * {
                 *  position.X = w - 54;
                 *  position.Y = h - 54;
                 *  size = new Vector2(64, 64);
                 *  quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha");
                 *  position.X -= 10 + (int)font.MeasureString(Strings.Localize("editObjectParams.help")).X;
                 *  batch.Begin();
                 *  TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position + shadowOffset, shadowColor);
                 *  TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position, fontColor);
                 *  batch.End();
                 *
                 *  if (xButtonText != null)
                 *  {
                 *      position.X = w - 54;
                 *      position.Y = h - 54 - Font().LineSpacing - 6;
                 *      size = new Vector2(64, 64);
                 *      quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");
                 *      position.X -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                 *      batch.Begin();
                 *      TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position + shadowOffset, shadowColor);
                 *      TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position, fontColor);
                 *      batch.End();
                 *  }
                 * }
                 */

                if (xButtonText != null)
                {
                    position.X = w - 54;
                    position.Y = h - 54;
                    size       = new Vector2(64, 64);
                    quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");

                    Vector2 min = Vector2.Zero;
                    Vector2 max = Vector2.Zero;

                    max.X = (position.X + 54) / w;
                    min.Y = position.Y / h;

                    position.X -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                    SpriteBatch batch = UI2D.Shared.SpriteBatch;
                    batch.Begin();
                    TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position + shadowOffset, shadowColor);
                    TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position, fontColor);
                    batch.End();

                    min.X = position.X / w;
                    max.Y = min.Y + (float)Font().LineSpacing / h;

                    xButtonBox.Set(min, max);
                }

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

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularCheckboxElement Render()
コード例 #20
0
        }   // end of OnExitTutorial()

        public static void PreRender()
        {
            // Decide which font to use based on screen width.
            UI2D.Shared.GetFont prevFont = font;
            font = BokuGame.ScreenSize.X > 1280 ? UI2D.Shared.GetGameFont24Bold : UI2D.Shared.GetGameFont18Bold;

            // Did the font or window size change?  If so, reallocate the rendertarget.
            if (font != prevFont || rt == null || BokuGame.ScreenSize.X > rt.Width)
            {
                InGame.RelRT("TutorialRT", rt);
                BokuGame.Release(ref rt);
                CreateRenderTarget();
            }

            if (backdrop == null || rt == null)
            {
                return;
            }

            ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

            InGame.SetRenderTarget(rt);

            // Clear and add highlight.
            quad.Render(backdrop, Vector2.Zero, new Vector2(rt.Width, rt.Height), "TexturedRegularAlpha");

            if (Active)
            {
                int indent = 10;

                // Lazy allocation.
                if (titleBlob == null)
                {
                    titleBlob = new TextBlob(font, "test", (int)(rt.Width - 2.0f * indent));
                    //titleBlob.ProgrammingTileBackdrop = true;
                }
                if (instructionBlob == null)
                {
                    instructionBlob = new TextBlob(font, "test", (int)(rt.Width - 2.0f * indent));
                    //instructionBlob.ProgrammingTileBackdrop = true;
                }

                // Font may have changed, keep the blobs up to date.
                titleBlob.Font       = font;
                instructionBlob.Font = font;

                // Raw strings to put into blobs.
                string titleStr       = null;
                string instructionStr = null;

                // We only care about the non-modal text if there's no modal display.
                // TODO We could think about displaying this under the modal display but we'd have to
                // add a drop shadow first to avoid cluttering things up.
                if (!modalDisplay.Active)
                {
                    // We should only display text when the tutorial mode is fully open.
                    bool display = targetPositionY > 1 && BokuGame.ScreenPosition.Y > targetPositionY - 2.0f;
                    if (display)
                    {
                        if (curCrumb != null || targetModeReached)
                        {
                            // First line should be the goal of this section of the tutorial.  High level.
                            titleStr = curStep.GoalText;

                            // Second line is either from the crumb telling us where to go OR from the step telling us what to do now that we're here.
                            if (curCrumb == null)
                            {
                                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                                {
                                    instructionStr = curStep.MouseText;
                                }
                                else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                                {
                                    instructionStr = curStep.TouchText;
                                }
                                else    // gamepad
                                {
                                    instructionStr = curStep.GamepadText;
                                }
                            }
                            else
                            {
                                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                                {
                                    instructionStr = curCrumb.MouseText;
                                }
                                else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                                {
                                    instructionStr = curCrumb.TouchText;
                                }
                                else    // gamepad
                                {
                                    instructionStr = curCrumb.GamepadText;
                                }
                            }
#if DEBUG
                            // Add in some debug info.
                            //instructionStr += "\nCurMode = " + curGameMode.ToString() + "   curTargetMode = " + curStep.TargetMode.ToString();
#endif
                        }
                        else
                        {
                            if (DebugMode)
                            {
                                // We've got no crumb.  Need to add one!
                                instructionStr = "Missing Crumb!";
                                // Add in some debug info.
                                instructionStr += "\nCurMode = " + curGameMode.ToString() + "   HelpOverlay = " + HelpOverlay.Peek() + "\nUpdateMode = " + InGame.inGame.CurrentUpdateMode.ToString();
                                if (curStep != null)
                                {
                                    instructionStr += "\nTargetMode = " + curStep.TargetMode;
                                }
                            }
                        }

                        // Render text blob.

                        // TODO Center text vertically and if fewer lines, increase the spacing a bit.

                        titleBlob.RawText       = titleStr;
                        instructionBlob.RawText = instructionStr;

                        //Color titleColor = new Color(50, 255, 50);  // Same green as the hover text color we user elsewhere.
                        Color titleColor = new Color(20, 20, 20);   // Not quite black.
                        //Color titleColor = new Color(250, 190, 50); // Amber.
                        Color shadowColor = new Color(0, 0, 0, 40);
                        Color lightGrey   = new Color(200, 200, 200);
                        Color darkGrey    = new Color(100, 100, 100);

                        Color textColor = darkGrey;
                        if (DebugMode && curGameMode == GameMode.Unknown)
                        {
                            textColor = Color.Red;
                        }
                        titleBlob.RenderWithButtons(new Vector2(indent, 0), titleColor, shadowColor, new Vector2(0, 2), maxLines: 4);
                        // Vertically center the instruction text.
                        int yOffset = 0;
                        if (instructionBlob.NumLines == 1)
                        {
                            yOffset = instructionBlob.TotalSpacing;
                        }
                        else if (instructionBlob.NumLines == 2)
                        {
                            yOffset = (int)(instructionBlob.TotalSpacing / 2.0f);
                        }
                        instructionBlob.RenderWithButtons(new Vector2(indent, titleBlob.TotalSpacing + yOffset - 2), textColor, shadowColor, new Vector2(0, 2), maxLines: 4);
                    } // end if display true
                }     // end if not modal active
            }         // end if tutorial mode active

            InGame.RestoreRenderTarget();
        }   // end of PreRender()
コード例 #21
0
        }   // end of PreRender()

        public static void Render()
        {
            if (!active || backdrop == null || rt == null)
            {
                return;
            }

            ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

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

            backdropBox.Set(Vector2.Zero, size);

            // Tutorial info needs to go at top of "real" screen.
            InGame.RestoreViewportToFull();
            quad.Render(rt, Vector2.Zero, size, "TexturedNoAlpha");

            if (modalDisplay.Active)
            {
                quad.Render(dropShadow, Vector2.Zero, BokuGame.ScreenSize, "TexturedRegularAlpha");
            }
            modalDisplay.Render();

            // Display debug spew if active.
            if (DebugMode && active)
            {
                Vector2     pos   = new Vector2(20, 400);
                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                Color       color = Color.Yellow;

                TextBlob blob = new TextBlob(UI2D.Shared.GetGameFont20, "", 1000);

                string text = "Tutorial Manager\n";

                try
                {
                    text += "  current game mode : " + curGameMode.ToString() + "\n";
                    text += "  current help overlay : " + HelpOverlay.Peek() + "\n";
                    text += "  current step\n";
                    text += "    display mode : " + curStep.DisplayMode.ToString() + "\n";
                    text += "    target mode : " + curStep.TargetMode.ToString() + "\n";
                    if (curStep.CompletionTest != null)
                    {
                        text += "    completion test : " + curStep.CompletionTest.Name.ToString() + "\n";
                        text += "      args : " + curStep.CompletionTest.Args.ToString() + "\n";
                    }
                    text += "  current input mode : " + GamePadInput.ActiveMode.ToString() + "\n";
                    if (curCrumb != null)
                    {
                        text += "current crumb id " + curCrumb.id + "\n";
                    }
                }
                catch
                {
                }

                blob.RawText = text;

                blob.RenderWithButtons(pos, Color.Black, outlineColor: Color.White, outlineWidth: 1.2f);
            }
        }   // end of Render()
コード例 #22
0
        }   // end of ApplyExclusiveFiltering()

        public void Render(Camera camera)
        {
            if (Active && geometry != null)
            {
                // Black background.
                effect.CurrentTechnique = effect.Techniques["NormalMappedNoTexture"];

                effect.Parameters["WorldMatrix"].SetValue(worldMatrix);
                effect.Parameters["WorldViewProjMatrix"].SetValue(worldMatrix * camera.ViewProjectionMatrix);

                effect.Parameters["Alpha"].SetValue(1.0f);
                effect.Parameters["DiffuseColor"].SetValue(new Vector4(0, 0, 0, 1));
                effect.Parameters["SpecularColor"].SetValue(new Vector4(0.2f, 0.2f, 0.2f, 1.0f));
                effect.Parameters["SpecularPower"].SetValue(32.0f);

                effect.Parameters["NormalMap"].SetValue(normalMap);

                geometry.Render(effect);


                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                Vector3 upperLeftCorner = worldMatrix.Translation;
                upperLeftCorner.X -= geometry.Width / 2.0f;
                upperLeftCorner.Y += geometry.Height / 2.0f;

                upperLeftCorner.X += tileBorder;
                upperLeftCorner.Y -= tileBorder / 2.0f;

                Point   loc = camera.WorldToScreenCoords(upperLeftCorner);
                Vector2 pos = new Vector2(loc.X, loc.Y);

                loc = camera.WorldToScreenCoords(2.0f * worldMatrix.Translation - upperLeftCorner);
                Vector2 size = new Vector2(loc.X, loc.Y) - pos;

                int lineSpacing = Font().LineSpacing;

                // Render highlight.
                quad.Render(whiteHighlight, new Vector4(1.0f, 1.0f, 1.0f, 0.3f), pos + new Vector2(-4, 0), new Vector2(w + 6, w / 2.0f), "TexturedRegularAlpha");

                // Render the green bar().
                for (int i = 0; i < itemList.Count; i++)
                {
                    if (itemList[i].BarAlpha > 0.0)
                    {
                        quad.Render(greenBar, new Vector4(1.0f, 1.0f, 1.0f, itemList[i].BarAlpha), pos + new Vector2(0, 2 + i * lineSpacing), new Vector2(w, lineSpacing), "TexturedRegularAlpha");
                    }
                }

                // Render the text.
                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                for (int i = 0; i < itemList.Count; i++)
                {
                    Vector2 position = pos + new Vector2(margin + checkboxSize + gap, i * lineSpacing);
                    TextHelper.DrawString(Font, itemList[i].Text, position, itemList[i].TextColor);
                    // Calc bounds in UV space.
                    Vector2 min = new Vector2(0, i * lineSpacing);
                    Vector2 max = min + new Vector2(w, lineSpacing);
                    min /= size;
                    max /= size;
                    itemList[i].UVBoundingBox.Set(min, max);
                }
                batch.End();

                // Render the checkboxes.
                for (int i = 0; i < itemList.Count; i++)
                {
                    float a = itemList[i].LitValue;

                    // If not fully lit.
                    if (a < 1.0f)
                    {
                        quad.Render(AllExclusive ? radioButtonUnlit : checkboxUnlit, pos + new Vector2(margin, 6 + i * lineSpacing), new Vector2(checkboxSize), "TexturedRegularAlpha");
                    }

                    // If lit at all.
                    if (a > 0.0f)
                    {
                        quad.Render(AllExclusive ? radioButtonLit : checkboxLit, new Vector4(1, 1, 1, a), pos + new Vector2(margin, 6 + i * lineSpacing), new Vector2(checkboxSize), "TexturedRegularAlpha");
                    }
                }

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad)
                {
                    // Render help.
                    string   str  = "<a> " + Strings.Localize("saveLevelDialog.change") + "\n<b> " + Strings.Localize("saveLevelDialog.back");
                    TextBlob blob = new TextBlob(UI2D.Shared.GetGameFont24, str, 400);
                    pos   += size;
                    pos.X += 16;
                    pos.Y -= 2.0f * blob.TotalSpacing;
                    blob.RenderWithButtons(pos, Color.White);

                    // Mouse hit boxes for help.
                    changeBox.Set(pos, pos + new Vector2(blob.GetLineWidth(0), blob.TotalSpacing));
                    backBox.Set(pos + new Vector2(0, blob.TotalSpacing), pos + new Vector2(0, blob.TotalSpacing) + new Vector2(blob.GetLineWidth(1), blob.TotalSpacing));
                }
            } // end if active
        }     // end of ModularCheckboxList Render()
コード例 #23
0
        }   // end of LoadLevelPopup Update()

        public void Render(Camera camera)
        {
            if (Active)
            {
                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Frame.
                quad.Render(frame, position, _size, "TexturedRegularAlpha");

                // Calc alpha value to use for elements based on expanded size of frame.
                float alpha = _size.X / size.X;
                alpha *= alpha;

                // Items.

                float   additionalSpacing = (_size.Y - itemList.Count * ItemFont().LineSpacing) / (itemList.Count + 1);
                Vector2 barSize           = new Vector2(_size.X, ItemFont().LineSpacing);
                float   margin            = 6;
                Vector2 pos = Vector2.Zero;
                pos.X  = position.X + _size.X - margin;
                pos.Y  = position.Y + _size.Y / 2.0f;   // Center.
                pos.Y -= itemList.Count / 2.0f * ItemFont().LineSpacing + (itemList.Count - 1) / 2.0f * additionalSpacing;
                for (int i = 0; i < itemList.Count; i++)
                {
                    // Render bar if needed.
                    if (itemList[i].BarAlpha > 0.0f)
                    {
                        quad.Render(greenBar, new Vector4(1.0f, 1.0f, 1.0f, itemList[i].BarAlpha * alpha), pos - new Vector2(_size.X, -2), barSize, "TexturedRegularAlpha");
                    }

                    // Set up mouse hit box.
                    itemList[i].hitBox.Set(pos - new Vector2(_size.X, -2), pos - new Vector2(_size.X, -2) + barSize);

                    // Render text
                    Color textColor = itemList[i].TextColor;
                    if (alpha < 1.0f)
                    {
                        textColor.A = (byte)(textColor.A * alpha);
                    }
                    blob.RawText = itemList[i].Text;
                    Vector2 textPos   = pos - new Vector2(505, 0);
                    int     lineWidth = blob.GetLineWidth(0);
                    int     spacing   = blob.TotalSpacing;
                    if (lineWidth > 180)
                    {
                        blob.Font = UI2D.Shared.GetGameFont20;
                        lineWidth = blob.GetLineWidth(0);
                        if (lineWidth > 180)
                        {
                            blob.Font = UI2D.Shared.GetGameFont18Bold;
                            lineWidth = blob.GetLineWidth(0);
                            if (lineWidth > 180)
                            {
                                blob.Font = UI2D.Shared.GetGameFont15_75;
                            }
                        }
                    }
                    int down = (int)((spacing - blob.TotalSpacing) / 2.0f);
                    blob.RenderWithButtons(textPos + new Vector2(0, down), textColor);

                    // Restore larger font.
                    blob.Font = UI2D.Shared.GetGameFont24;

                    pos.Y += ItemFont().LineSpacing + additionalSpacing;
                }
            }
        }   // end of LoadLevelPopup Render()
コード例 #24
0
        }   // end of LiveFeedDisplay Render()

        #endregion

        #region Internal

        private void RenderFeedBasePlate()
        {
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
            // default width = 300 px
            // default height = 190 px
            // Adjustment Scale X
            // Adjustment Scale Y
            Vector2 defaultScreenSize = new Vector2(1280, 1024);
            Vector2 extraSize         = Vector2.Zero;
            Vector2 cOffset           = Vector2.Zero; //center Offset of cloud background;
            float   xCrushScale       = 1.0f;
            float   xCrushPixel       = 0.0f;

            extraSize.X = 80;//moves over the word "News"

            ScreenSpaceQuad ssquad         = ScreenSpaceQuad.GetInstance();
            Color           darkTextColor  = new Color(20, 20, 20);
            Color           greyTextColor  = new Color(127, 127, 127);
            Color           greenTextColor = new Color(0, 255, 45);
            Vector2         screenSize     = BokuGame.ScreenSize;

            Vector2 scaledBy = new Vector2(screenSize.X / defaultScreenSize.X, screenSize.Y / defaultScreenSize.Y);

            if (expanded)
            {
                extraSize.Y += 600.0f * scaledBy.Y;
            }
            if (scaledBy.X < 0.9f)
            {
                xCrushScale = scaledBy.X;
                xCrushPixel = cloudTL.Width - (cloudTL.Width * scaledBy.X);
            }
            Vector2 pos = new Vector2(2.0f, 80.0f);

            cOffset    = pos;
            cOffset.X += cloudTL.Width;
            cOffset.Y += cloudTL.Height - 25.0f;

            Vector2 baseSize   = FeedSize;
            Vector2 iconSize   = new Vector2(42.0f, 42.0f);
            Vector4 baseColor  = new Vector4(0.0f, 0.0f, 0.0f, 0.7f);
            Vector2 headerSize = baseSize;

            headerSize.X *= 0.8f;
            headerSize.Y *= 0.055f;
            Vector2 headerPos = pos;
            Vector2 baseOffset;

            baseOffset.Y = (float)cloudTL.Height + cloudLC.Height * scaledBy.Y;

            headerPos.Y -= headerSize.Y;

            iconSize = new Vector2(headerSize.Y * 0.95f, headerSize.Y * 0.95f);

            Vector2 cornerSize = new Vector2(headerSize.Y * 0.25f, headerSize.Y * 0.25f);

            Vector2 titlePos = headerPos + textPosition;

            titlePos.X += iconSize.X;

            Vector2 iconPos = iconPosition;

            iconPos.Y += headerPos.Y;
            if (screenSize.X > 1200)
            {
                iconPos.Y += 5.0f;
            }

            //  ssquad.Render(baseColor, headerPos, headerSize);
            //  ssquad.Render(baseColor, pos, baseSize);
            //  ssquad.Render(baseColor, headerPos + new Vector2(headerSize.X, cornerSize.Y), new Vector2(cornerSize.X, headerSize.Y - cornerSize.Y));

            //Top left cloud
            ssquad.Render(
                cloudTL, cOffset - new Vector2(cloudTL.Width, cloudTL.Height / 1.25f),
                new Vector2(cloudTL.Width * xCrushScale, cloudTL.Height / 1.25f), "TexturedRegularAlpha");
            //Bottom left cloud
            ssquad.Render(
                cloudBL, cOffset - new Vector2(cloudBL.Width, -((cloudLC.Height + extraSize.Y) * scaledBy.Y)), //baseOffset.Y + ((cloudLC.Height + extraSize.Y) * scaledBy.Y)),
                new Vector2(cloudBL.Width * xCrushScale, cloudBL.Height), "TexturedRegularAlpha");
            // left center Fill
            ssquad.Render(
                cloudLC, cOffset - new Vector2(cloudLC.Width, 0.0f),
                new Vector2(cloudLC.Width * xCrushScale, (cloudLC.Height + extraSize.Y) * scaledBy.Y), "TexturedRegularAlpha");

            //Top right cloud
            ssquad.Render(
                cloudTR, cOffset + new Vector2(((cloudTC.Width + extraSize.X) * scaledBy.X) - xCrushPixel, -(cloudTR.Height / 1.25f)),
                new Vector2(cloudTR.Width * xCrushScale, cloudTR.Height / 1.25f), "TexturedRegularAlpha");
            //Bottom right cloud
            ssquad.Render(
                cloudBR, cOffset + new Vector2(((cloudTC.Width + extraSize.X) * scaledBy.X) - xCrushPixel, (cloudLC.Height + extraSize.Y) * scaledBy.Y),
                new Vector2(cloudBR.Width * xCrushScale, cloudBR.Height), "TexturedRegularAlpha");
            // right center Fill
            ssquad.Render(
                cloudRC, cOffset + new Vector2(((cloudTC.Width + extraSize.X) * scaledBy.X) - xCrushPixel, 0.0f),
                new Vector2(cloudRC.Width * xCrushScale, (cloudRC.Height + extraSize.Y) * scaledBy.Y), "TexturedRegularAlpha");
            // Top center Fill
            ssquad.Render(
                cloudTC, cOffset - new Vector2(xCrushPixel, cloudTC.Height / 1.25f),
                new Vector2((cloudTC.Width + extraSize.X) * scaledBy.X, cloudTC.Height / 1.25f), "TexturedRegularAlpha");
            // Top bottom Fill
            ssquad.Render(
                cloudBC, cOffset + new Vector2(-xCrushPixel, (cloudLC.Height + extraSize.Y) * scaledBy.Y),
                new Vector2((cloudBC.Width + extraSize.X) * scaledBy.X, cloudBC.Height), "TexturedRegularAlpha");

            // Center Fill
            ssquad.Render(
                cloudCenter, cOffset + new Vector2(-xCrushPixel, 0.0f),
                new Vector2((cloudTC.Width + extraSize.X) * scaledBy.X,
                            (cloudCenter.Height + extraSize.Y) * scaledBy.Y), "TexturedRegularAlpha");

            Vector2 moreLessBoxLT =
                new Vector2(
                    (cOffset.X - ((cloudBL.Width * 0.70f) * xCrushScale) - xCrushPixel),
                    (cOffset.Y + ((cloudLC.Height + extraSize.Y) * scaledBy.Y) + cloudBL.Height * 0.40f));
            Vector2 moreLessBoxBR = moreLessBoxLT;

            float moreLessPos = (cloudBL.Width * xCrushScale * 0.52f);

            if (newsScroller.Count > 1)
            {
                if (!expanded)
                {
                    moreLessPos -= (float)(flagMoreBlob.GetLineWidth(0) / 3);
                    flagMoreBlob.Justification = UIGridElement.Justification.Center;
                    pos = new Vector2(moreLessPos, moreLessBoxLT.Y + 8);
                    // Clamp to pixel coords so text doesn't look like #$%.
                    pos.X = (int)pos.X;
                    pos.Y = (int)pos.Y;
                    flagMoreBlob.RenderWithButtons(pos, flagMoreLessColor, maxLines: 1);
                    moreLessBoxBR.X += flagMoreBlob.Width * 2.5f;         //2.5 makes click area larger.
                    moreLessBoxBR.Y += flagMoreBlob.TotalSpacing * 1.85f; //1.85 makes click area larger.
                }
                else
                {
                    moreLessPos -= (float)(flagLessBlob.GetLineWidth(0) / 3);
                    flagLessBlob.Justification = UIGridElement.Justification.Center;
                    pos = new Vector2(moreLessPos, moreLessBoxLT.Y + 8);
                    // Clamp to pixel coords so text doesn't look like #$%.
                    pos.X = (int)pos.X;
                    pos.Y = (int)pos.Y;
                    flagLessBlob.RenderWithButtons(pos, flagMoreLessColor, maxLines: 1);
                    moreLessBoxBR.X += (int)flagMoreBlob.Width * 2.5f;         //2.5 makes click area larger.
                    moreLessBoxBR.Y += (int)flagMoreBlob.TotalSpacing * 1.85f; //1.85 makes click area larger.
                }

                moreLessHitBox.Set(moreLessBoxLT, moreLessBoxBR);
            }
            else
            {
                moreLessHitBox.Set(new Vector2(0, 0), new Vector2(0, 0));
            }


            pos = new Vector2(cOffset.X - ((cloudTL.Width / 1.8f) * xCrushScale) - xCrushPixel, cOffset.Y - cloudTL.Height * 0.65f);
            // Clamp to pixel coords so text doesn't look like #$%.
            pos.X = (int)pos.X + 3;
            pos.Y = (int)pos.Y;

            smallblob.RenderWithButtons(pos, Active ? greenTextColor : darkTextColor, maxLines: 1);
        }
コード例 #25
0
        }   // end of OnHelp()

        public void Render()
        {
            if (active)
            {
                titleRect      = new Rectangle(0, 0, dialogWidth, 72);
                dialogBodyRect = new Rectangle(0, 64, dialogWidth, 320);

                // Now that we have the final dialog size, center it on the screen.
                Vector2 pos = BokuGame.ScreenSize / 2.0f;
                pos.X           -= titleRect.Width / 2;
                pos.Y           -= (titleRect.Height + dialogBodyRect.Height) / 2;
                titleRect.X      = (int)pos.X;
                titleRect.Y      = (int)pos.Y;
                dialogBodyRect.X = titleRect.X;
                dialogBodyRect.Y = titleRect.Y + titleRect.Height;

                int padding = 4;
                helpRect = new Rectangle(titleRect.X + titleRect.Width - titleRect.Height - margin, titleRect.Y + padding, titleRect.Height - 2 * padding, titleRect.Height - 2 * padding);

                AuthUI.RenderTile(titleBarTexture, titleRect);
                AuthUI.RenderTile(dialogBodyTexture, dialogBodyRect);

                // Title bar help icon.
                AuthUI.RenderTile(helpIcon, helpRect);
                helpBox.Set(helpRect);

                // Title bar text.
                string str = newUserMode ? Strings.Localize("auth.newUserTitle") : Strings.Localize("auth.signInTitle");
                blob.RawText       = str;
                blob.Font          = UI2D.Shared.GetGameFont30Bold;
                blob.Justification = UIGridElement.Justification.Left;
                blob.RenderWithButtons(new Vector2(titleRect.X + margin, titleRect.Y + 6), Color.White, Color.Black, new Vector2(0, 2), maxLines: 1);

                // Text box labels.
                int verticalBoxSpacing = blob.TotalSpacing + 4;
                blob.Font          = UI2D.Shared.GetGameFont24;
                blob.Justification = UIGridElement.Justification.Right;
                string creatorString = Strings.Localize("auth.creator");
                string pinString     = Strings.Localize("auth.pin");

                int posX = (int)Math.Max(blob.Font().MeasureString(creatorString).X, blob.Font().MeasureString(pinString).X);
                posX        += margin;
                blob.Width   = dialogBodyRect.Width - posX - 2 * margin;
                pos          = new Vector2(dialogBodyRect.X + posX - blob.Width, dialogBodyRect.Y + margin);
                blob.RawText = creatorString;
                blob.RenderWithButtons(pos, Color.White);
                pos.Y       += verticalBoxSpacing;
                blob.RawText = pinString;
                blob.RenderWithButtons(pos, Color.White);

                // Text boxes.
                // Creator.
                creatorBlob.Justification = UIGridElement.Justification.Left;
                pos.Y -= verticalBoxSpacing;
                pos.X  = dialogBodyRect.X + posX + margin;
                int       creatorBoxWidth    = dialogBodyRect.Width - posX - 2 * margin;
                Rectangle creatorTextBoxRect = new Rectangle((int)pos.X, (int)pos.Y, creatorBoxWidth, 40);
                creatorBox.Set(creatorTextBoxRect);
                // If editing, put a focus highlight around it.
                if (EditingCreator)
                {
                    AuthUI.RenderTile(textBoxTexture, creatorTextBoxRect, AuthUI.FocusColor);
                    creatorTextBoxRect = creatorTextBoxRect.Shrink(2);

                    // Also display warning about picking a good creator name.
                    Vector2 warningPos = new Vector2(dialogBodyRect.Left + 8, pinBox.Rectangle.Bottom);
                    int     prevWidth  = blob.Width;
                    blob.Width         = dialogBodyRect.Width - 16;
                    blob.Justification = UIGridElement.Justification.Left;
                    str          = Strings.Localize("auth.helpTextShort");
                    blob.RawText = str;
                    blob.Font    = UI2D.Shared.GetGameFont15_75;
                    blob.RenderWithButtons(warningPos, AuthUI.ErrorColor);
                    blob.Font          = UI2D.Shared.GetGameFont24;
                    blob.Width         = prevWidth;
                    blob.Justification = UIGridElement.Justification.Right;
                }
                AuthUI.RenderTile(textBoxTexture, creatorTextBoxRect);
                creatorBlob.RenderWithButtons(pos, creatorBlob.ScrubbedText == "Guest" ? Color.Gray : Color.Black, renderCursor: EditingCreator);

                // Pin
                pos.Y += verticalBoxSpacing;
                // Use regular blob for measurement.
                blob.Justification = UIGridElement.Justification.Left;
                int       pinBoxWidth    = (int)pinBlob.Font().MeasureString("0000").X; // Assumes 0s are max width characters.
                Rectangle pinTextBoxRect = new Rectangle((int)pos.X, (int)pos.Y, pinBoxWidth, 40);
                pinBox.Set(pinTextBoxRect);
                if (EditingPin)
                {
                    AuthUI.RenderTile(textBoxTexture, pinTextBoxRect, AuthUI.FocusColor);
                    pinTextBoxRect = pinTextBoxRect.Shrink(2);
                }
                AuthUI.RenderTile(textBoxTexture, pinTextBoxRect);

                // Hack to hide pin numbers.  Only show last number unless Guest pin.
                string rawText = pinBlob.ScrubbedText;  // Save existing string.
                if (pinBlob.ScrubbedText != Auth.DefaultCreatorPin)
                {
                    str = "";
                    if (pinBlob.ScrubbedText.Length > 0)
                    {
                        for (int i = 0; i < pinBlob.ScrubbedText.Length - 1; i++)
                        {
                            str += '•';
                        }
                        str            += pinBlob.ScrubbedText[pinBlob.ScrubbedText.Length - 1];
                        pinBlob.RawText = str;
                    }
                }
                pinBlob.RenderWithButtons(pos, pinBlob.ScrubbedText == Auth.DefaultCreatorPin ? Color.Gray : Color.Black, renderCursor: EditingPin);
                // Restore
                pinBlob.RawText = rawText;

                // Pin warnings.
                if (pinBlob.ScrubbedText != Auth.DefaultCreatorPin && !Auth.IsPinValid(pinBlob.ScrubbedText))
                {
                    pos.X += pinTextBoxRect.Width + 8;
                    str    = Strings.Localize("auth.pinError");
                    if (pinBlob.ScrubbedText.Length != 4)
                    {
                        str += "\n" + Strings.Localize("auth.pinTooShort");
                    }
                    else
                    {
                        str += "\n" + Strings.Localize("auth.pinTooSimple");
                    }
                    blob.RawText = str;
                    blob.RenderWithButtons(pos, AuthUI.ErrorColor);
                }

                // Buttons.  Fit at bottom of dialog.
                pos    = new Vector2(dialogBodyRect.Right, dialogBodyRect.Bottom);
                pos.X -= margin;
                pos.Y -= margin;
                pos   -= cancelButton.GetSize();
                cancelButton.Render(pos, useBatch: false);
                pos.X -= margin;
                pos.X -= okButton.GetSize().X;
                okButton.Render(pos, useBatch: false);

                // Keep signed in checkbox.
                // Position vertically just above buttons.
                pos.X        = dialogBodyRect.X + margin;
                pos.Y        = okButton.Box.Min.Y + 32;
                pos.X       += 32; // Adjust for checkbox.
                blob.RawText = Strings.Localize("auth.keepSignedIn");
                blob.Width   = dialogBodyRect.Width - 2 * margin - 32;
                pos.Y       -= blob.NumLines * blob.TotalSpacing;
                Rectangle checkboxRect = new Rectangle((int)pos.X - 32, (int)pos.Y + 4, 32, 32);
                checkBoxBox.Set(checkboxRect);
                AuthUI.RenderTile(keepSignedInChecked ? checkboxLit : checkboxUnlit, checkboxRect);
                blob.RenderWithButtons(pos, Color.White);

                // Adjust dialog size to CreatorName box is the desired size.
                // This keeps the entry box the same size regardless of the length
                // of "Creator" in whatever language is being used.
                dialogWidth += desiredCreatorNameSpace - (int)creatorBox.Width;

                scrollableTextDisplay.Render();
            }

            VirtualKeyboard.Render();
        }   // end of Render()
コード例 #26
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()
コード例 #27
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()
コード例 #28
0
        }   // end of OnCancel()

        public void Render()
        {
            if (active)
            {
                titleRect      = new Rectangle(0, 0, 512, 72);
                dialogBodyRect = new Rectangle(0, 64, 512, 320);

                // Now that we have the final dialog size, center it on the screen.
                Vector2 pos = BokuGame.ScreenSize / 2.0f;
                pos.X           -= titleRect.Width / 2;
                pos.Y           -= (titleRect.Height + dialogBodyRect.Height) / 2;
                titleRect.X      = (int)pos.X;
                titleRect.Y      = (int)pos.Y;
                dialogBodyRect.X = titleRect.X;
                dialogBodyRect.Y = titleRect.Y + titleRect.Height;

                AuthUI.RenderTile(titleBarTexture, titleRect);
                AuthUI.RenderTile(dialogBodyTexture, dialogBodyRect);

                // Title bar text.
                string str = Strings.Localize("auth.signOutTitle");
                blob.RawText       = str;
                blob.Font          = UI2D.Shared.GetGameFont30Bold;
                blob.Justification = UIGridElement.Justification.Left;
                blob.RenderWithButtons(new Vector2(titleRect.X + margin, titleRect.Y + 6), Color.White, Color.Black, new Vector2(0, 2), maxLines: 1);

                // Text box labels.
                int verticalBoxSpacing = blob.TotalSpacing + 4;
                blob.Font          = UI2D.Shared.GetGameFont24;
                blob.Justification = UIGridElement.Justification.Left;
                str = Strings.Localize("auth.currentlySignedInAs") + Auth.CreatorName;

                blob.Width   = dialogBodyRect.Width - 2 * margin;
                pos          = new Vector2(dialogBodyRect.X + margin, dialogBodyRect.Y + margin);
                blob.RawText = str;
                blob.RenderWithButtons(pos, Color.White);

                // Buttons.  Fit at bottom of dialog.
                pos    = new Vector2(dialogBodyRect.Right, dialogBodyRect.Bottom);
                pos.X -= margin;
                pos.Y -= margin;
                pos   -= cancelButton.GetSize();
                cancelButton.Render(pos, useBatch: false);
                pos.X -= margin;
                pos.X -= signOutButton.GetSize().X;
                signOutButton.Render(pos, useBatch: false);

                // Keep signed in checkbox.
                // Position vertically just above buttons.
                pos.X        = dialogBodyRect.X + margin;
                pos.Y        = signOutButton.Box.Min.Y;
                pos.X       += 32; // Adjust for checkbox.
                blob.RawText = Strings.Localize("auth.keepSignedIn");
                blob.Width   = dialogBodyRect.Width - 2 * margin - 32;
                pos.Y       -= blob.NumLines * blob.TotalSpacing;
                Rectangle checkboxRect = new Rectangle((int)pos.X - 32, (int)pos.Y + 4, 32, 32);
                checkBoxBox.Set(checkboxRect);
                AuthUI.RenderTile(keepSignedInChecked ? checkboxLit : checkboxUnlit, checkboxRect);
                blob.RenderWithButtons(pos, Color.White);
            }
        }   // end of Render()
コード例 #29
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();
            }
コード例 #30
0
        }   // end of Clear()

        private static void RefreshTexture()
        {
            // TODO (****) *** Does this make sense any more since we require a min height of 600?
            bool lores = BokuGame.ScreenSize.Y <= 480;

            UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24Bold;
            if (lores)
            {
                Font = UI2D.Shared.GetGameFont30Bold;
            }
            blob.Font = Font;

            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
            RenderTarget2D  rt     = UI2D.Shared.RenderTarget512_302;

            InGame.SetRenderTarget(rt);

            InGame.Clear(Color.Transparent);

            ssquad.Render(background, Vector2.Zero, new Vector2(512, 302), "TexturedRegularAlpha");

            // Text description.
            if (blob != null)
            {
                Vector2 pos      = new Vector2(margin, margin);
                int     maxLines = showYButton ? (lores ? 3 : 4) : (lores ? 4 : 6);

                // Modify final line to end with ellipsis.
                blob.AddEllipsisToLine(maxLines - 1);

                // If less than maxLines of text, center on texture.
                int spareLines = maxLines - blob.NumLines - 1;
                if (spareLines > 0)
                {
                    pos.Y += spareLines * 0.5f * Font().LineSpacing;
                }

                blob.RenderWithButtons(pos, Color.Yellow, maxLines: maxLines);
            }


            InGame.RestoreRenderTarget();

            //
            // Copy result to local texture.
            //
            int[] data = new int[512 * 302];
            rt.GetData <int>(data);
            texture.SetData <int>(data);

            // Scale size to 1/4 screen height.
            int   w     = (int)BokuGame.ScreenSize.X;
            int   h     = (int)BokuGame.ScreenSize.Y;
            float scale = h / 4.0f / 302.0f;

            size  = new Vector2(512, 302);
            size *= scale;

            // Position in lower right hand corner.
            targetPosition  = new Vector2(w, h);
            targetPosition -= size;

            dirty = false;
        }   // end of RefreshTexture()