UI/Story/ScrollingTextPanel.razor
@using Sandbox;
@using Sandbox.UI;

@namespace Opium.UI
@inherits Panel

<root>
    @CurrentText
</root>

@code
{
    public float Frequency { get; set; } = 0.05f;

    public string Text { get; set; }

    public float TimeOffset { get; set; } = 0f;

    int CalculateLength()
    {
        return ( ( TimeSinceCreated + TimeOffset ) / Frequency ).FloorToInt().Clamp( 0, Text.Length );
    }

    string CurrentText => string.IsNullOrEmpty( Text ) ? "" : Text.Substring(0, CalculateLength());

    TimeSince TimeSinceCreated;

    public ScrollingTextPanel()
    {
        // TODO: we may not need this now
        using var scope = Game.ActiveScene.Push();

        TimeSinceCreated = 0;
    }

    public override void Tick()
    {
        // TODO: we may not need this now
        using var scope = Game.ActiveScene.Push();
    }
    protected override int BuildHash()
    {
        return HashCode.Combine(Time.Delta);
    }
}