示例#1
0
        public override void Render()
        {
            base.Render();

            float popupAlpha = 1f;
            float popupScale = 1f;

            if (Tracking?.Scene != Scene)
            {
                PopOut = true;
            }

            // Update can halt in the pause menu.
            if (PopIn || FadeOut || PopOut)
            {
                AnimationTime += Engine.RawDeltaTime;
                if (AnimationTime < 0.1f && PopIn)
                {
                    float t = AnimationTime / 0.1f;
                    // Pop in.
                    popupAlpha = Ease.CubeOut(t);
                    popupScale = Ease.ElasticOut(t);
                }
                else if (AnimationTime < 1f)
                {
                    // Stay.
                    popupAlpha = 1f;
                    popupScale = 1f;
                }
                else if (FadeOut)
                {
                    // Fade out.
                    if (AnimationTime < 2f)
                    {
                        float t = AnimationTime - 1f;
                        popupAlpha = 1f - Ease.CubeIn(t);
                        popupScale = 1f - 0.4f * Ease.CubeIn(t);
                    }
                    else
                    {
                        // Destroy.
                        RemoveSelf();
                        return;
                    }
                }
                else if (PopOut)
                {
                    // Pop out.
                    if (AnimationTime < 1.1f)
                    {
                        float t = (AnimationTime - 1f) / 0.1f;
                        popupAlpha  = 1f - Ease.CubeIn(t);
                        popupAlpha *= popupAlpha;
                        popupScale  = 1f - 0.4f * Ease.BounceIn(t);
                    }
                    else
                    {
                        // Destroy.
                        RemoveSelf();
                        return;
                    }
                }
                else
                {
                    AnimationTime = 1f;
                }
            }

            time += Engine.RawDeltaTime;

            MTexture icon = null;
            string   text = null;

            if (IsIcon(Value))
            {
                icon = GetIcon(Value, time);
            }
            else
            {
                text = Value;
            }

            float alpha = Alpha * popupAlpha;

            if (alpha <= 0f || (icon == null && string.IsNullOrWhiteSpace(text)))
            {
                return;
            }

            if (Tracking == null)
            {
                return;
            }

            Level level = SceneAs <Level>();

            if (level == null)
            {
                return;
            }

            if (Camera == null)
            {
                Camera = level.Camera;
            }
            if (Camera == null)
            {
                return;
            }

            Vector2 pos = Tracking.Position;

            // - name offset - popup offset
            pos.Y -= 16f + 4f;

            pos -= level.Camera.Position;
            pos *= 6f; // 1920 / 320

            if (Float)
            {
                pos.Y -= (float)Math.Sin(time * 2f) * 4f;
            }

            if (icon != null)
            {
                Vector2 size  = new Vector2(icon.Width, icon.Height);
                float   scale = (Size / Math.Max(size.X, size.Y)) * 0.5f * popupScale;
                size *= scale;

                pos = pos.Clamp(
                    0f + size.X * 0.5f, 0f + size.Y * 1f,
                    1920f - size.X * 0.5f, 1080f
                    );

                icon.DrawJustified(
                    pos,
                    new Vector2(0.5f, 1f),
                    Color.White * alpha,
                    Vector2.One * scale
                    );
            }
            else
            {
                Vector2 size  = ActiveFont.Measure(text);
                float   scale = (Size / Math.Max(size.X, size.Y)) * 0.5f * popupScale;
                size *= scale;

                pos = pos.Clamp(
                    0f + size.X * 0.5f, 0f + size.Y * 1f,
                    1920f - size.X * 0.5f, 1080f
                    );

                ActiveFont.DrawOutline(
                    text,
                    pos,
                    new Vector2(0.5f, 1f),
                    Vector2.One * scale,
                    Color.White * alpha,
                    2f,
                    Color.Black * alpha * alpha * alpha
                    );
            }
        }