UI/AgentThoughtPanel.razor
@using Sandbox.UI
@using System
@using System.Linq
@namespace HC3.UI
<root>
<div class="thoughts">
@foreach (var thought in Agent.Thoughts.GetAll())
{
<div class="thought gap @GetThoughtClasses(thought)" onclick=@(() => OnThoughtClicked(thought)) tooltip=@GetThoughtTooltip(thought)>
<div class="time">@FormatTime(thought.TimeStamp)</div>
<div class="message">@thought.Message</div>
<div class="grow"/>
@if ( thought.Tags.Any() )
{
<div class="tags">
@foreach ( var tag in thought.Tags.Where( ValidTag ) )
{
<span class="tag">@tag</span>
}
</div>
}
</div>
}
@if ( !Agent.Thoughts.GetAll().Any() )
{
<label>No thoughts to display..</label>
}
</div>
</root>
@code
{
public Agent Agent { get; set; }
protected string GetThoughtClasses(AgentThought thought)
{
var classes = new List<string>();
if ( thought.Tags.Contains( "good" ) ) classes.Add( "good" );
if ( thought.Tags.Contains( "bad" ) ) classes.Add( "bad" );
return string.Join(" ", classes);
}
protected bool ValidTag( string tag )
{
if ( tag.Contains( "good" ) || tag.Contains( "bad" ) )
return false;
return true;
}
protected string FormatTime(DateTimeOffset time)
{
var diff = DateTimeOffset.Now - time;
if (diff.TotalSeconds < 60)
return $"{diff.TotalSeconds:0}s ago";
if (diff.TotalMinutes < 60)
return $"{diff.TotalMinutes:0}m ago";
if (diff.TotalHours < 24)
return $"{diff.TotalHours:0}h ago";
return $"{diff.TotalDays:0}d ago";
}
private void OnThoughtClicked( AgentThought thought )
{
if ( thought.Location.HasValue )
{
CameraPanning.Instance.FrameOn( thought.Location.Value );
}
}
protected string GetThoughtTooltip( AgentThought thought )
{
if ( thought.Location.HasValue )
{
return "Pan to location";
}
return null;
}
protected override int BuildHash()
{
return System.HashCode.Combine( Time.Now );
}
}