using Microsoft.Xna.Framework; using MrGameEng.Core; namespace MrGameEng.Host; /// /// A scene transition that draws a full-screen overlay through a /// . The timing state machine lives in /// ; renders the overlay each draw while a /// transition is active. Transitions are stateless and reusable. /// public abstract class OverlayTransition : Transition { /// Creates a transition with explicit phase durations. protected OverlayTransition(float outDuration, float inDuration) : base(outDuration, inDuration) { } /// /// Draws the overlay. is 0 (scene fully visible) to /// 1 (scene fully covered); tells which side of the switch this is. /// public abstract void Draw(TransitionRenderer renderer, float coverage, TransitionPhase phase); } /// Factories for the built-in visual scene transitions. public static class Transitions { /// Fade through a solid color (black by default). Total duration is split between out and in. public static Transition Fade(float duration = 0.6f, Color? color = null) => new FadeTransition(duration / 2f, duration / 2f, color ?? Color.Black); /// A curtain wiping across the screen (black by default). Total duration is split between out and in. public static Transition Wipe(float duration = 0.6f, Color? color = null) => new WipeTransition(duration / 2f, duration / 2f, color ?? Color.Black); private sealed class FadeTransition(float outDuration, float inDuration, Color color) : OverlayTransition(outDuration, inDuration) { public override void Draw( TransitionRenderer renderer, float coverage, TransitionPhase phase ) => renderer.Fill(0f, 0f, 1f, 1f, color, coverage); } private sealed class WipeTransition(float outDuration, float inDuration, Color color) : OverlayTransition(outDuration, inDuration) { public override void Draw( TransitionRenderer renderer, float coverage, TransitionPhase phase ) { // Out: шторка растёт слева направо; In: уезжает дальше вправо. if (phase == TransitionPhase.Out) { renderer.Fill(0f, 0f, coverage, 1f, color); } else { renderer.Fill(1f - coverage, 0f, coverage, 1f, color); } } } }