Editor tool UI for the Supershot feature. It creates an overlay window with buttons to open the Supershot studio, perform quick captures at various resolutions, and post captures to configured Discord webhooks.
using System;
using Sandbox;
namespace Editor.SuperShot;
[EditorTool]
[Title( "Supershot" )]
[Icon( "photo_camera" )]
[Group( "Supershot" )]
public sealed class FramingTool : EditorTool
{
Overlay _overlay;
public override void OnEnabled()
{
base.OnEnabled();
_overlay = new Overlay( this );
AddOverlay( _overlay, TextFlag.RightBottom, new Vector2( 16, 16 ) );
}
public override void OnDisabled()
{
base.OnDisabled();
_overlay = null;
}
public override void OnUpdate()
{
base.OnUpdate();
var view = Gizmo.Camera;
if ( view is null )
return;
SuperShotContext.UpdateFreecam( Gizmo.CameraTransform, view.FieldOfView, view.ZNear, view.ZFar );
}
static void OpenStudio()
{
SuperShotWindow.Open();
}
sealed class Overlay : WidgetWindow
{
public Overlay( FramingTool tool ) : base( tool.SceneOverlay, "Supershot" )
{
Layout = Layout.Column();
Layout.Margin = 8;
Layout.Spacing = 4;
FixedWidth = 190f;
Layout.Add( new Button.Primary( "Open Studio", "photo_camera" ) { Clicked = OpenStudio } );
Layout.Add( new Label( "Quick capture" ) );
AddCapture( "1080p", ShotResolution.HD1080 );
AddCapture( "4K", ShotResolution.UHD4K );
Layout.Add( new Label( "s&box package" ) );
AddCapture( "Square 512", ShotResolution.PackageSquare );
AddCapture( "Wide 910", ShotResolution.PackageWide );
AddCapture( "Tall 512", ShotResolution.PackageTall );
BuildDiscordSection();
}
void AddCapture( string label, ShotResolution res )
{
Layout.Add( new Button( label ) { Clicked = () => SuperShotService.QuickCapture( res ) } );
}
void BuildDiscordSection()
{
var share = SuperShotSettings.Current.Share;
var configured = share.Webhooks.FindAll( w => w is not null && w.IsConfigured );
if ( configured.Count == 0 )
return;
Layout.Add( new Label( "Capture + post to" ) );
configured.Sort( ( a, b ) => b.Favorite.CompareTo( a.Favorite ) );
foreach ( var wh in configured )
{
var target = wh;
Layout.Add( new Button( wh.Name, wh.Favorite ? "star" : "send" ) { Clicked = () => _ = SuperShotService.CaptureAndPostTo( target ) } );
}
if ( SuperShotService.EnabledWebhooks( share ).Count > 0 )
Layout.Add( new Button.Primary( "Post to all Discord Channels", "share" ) { Clicked = () => _ = SuperShotService.CaptureAndPostAll() } );
}
}
}