Level/TextInteractor.cs
using Opium;
using Sandbox;
using Sandbox.UI.Story;
[GameResource( "Text Note Item", "optext", "A Collection of Texts", Icon = "description", IconBgColor = "#325aa8", IconFgColor = "black" )]
public partial class TextNoteResource : GameResource
{
/// <summary>
/// Some tags we can use to sort items
/// </summary>
[Property] public List<TextNote> TextNotes { get; set; } = new();
public struct TextNote
{
[Property,TextArea]
public string Text { get; set; }
[Property]
public int Page { get; set; }
}
}
public sealed class TextInteractor : BaseInteract
{
[Property] public TextNoteResource Note { get; set; }
[Property] public bool IsModel { get; set; } = false;
public TimeUntil NextInteract { get; set; }
bool used = false;
public override bool ShowInteractionUI
{
get
{
// Dunno what happened, but the box doesn't show for ranged weapons.
if ( used )
{
return true;
}
else if ( !used )
{
return false;
}
return base.ShowInteractionUI;
}
}
public override void OnUse( GameObject player )
{
if ( NextInteract >= 0f )
{
return;
}
if ( player.Components.Get<Opium.PlayerController>() is not null )
{
var ui = player.Components.Get<NotesUI>( FindMode.EnabledInSelfAndDescendants );
if ( !ui.LookingAtObject.IsValid() )
{
ui.StartInteract( this );
}
}
}
}