예제 #1
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()
예제 #2
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()