Editor/Panels/CapturePanel.cs

Editor UI panel for the SuperShot capture window. It builds the Capture tab: buttons for capturing, preset resolution shortcuts, package thumbnail captures, and a settings sheet bound to serialized capture settings.

NetworkingFile Access
using System;
using Sandbox;

namespace Editor.SuperShot;

public sealed class CapturePanel : Widget
{
	readonly SuperShotWindow _window;

	public CapturePanel( SuperShotWindow window ) : base( null )
	{
		_window = window;
		Name = "Capture";
		WindowTitle = "Capture";
		SetWindowIcon( "photo_camera" );
		Layout = Layout.Column();
		Layout.Margin = 8;
		Layout.Spacing = 8;

		Build();
	}

	void Build()
	{
		var capture = _window.Settings.Capture;

		SuperShotUI.AddBanner( Layout, "Capture", "Frame the editor camera, then shoot.", "photo_camera" );

		var primary = Layout.AddRow();
		primary.Spacing = 6;
		primary.Add( new Button.Primary( "Capture", "photo_camera" )
		{
			FixedHeight = Theme.RowHeight * 2,
			Clicked = () => _window.Capture()
		}, 1 );

		var scroll = new ScrollArea( this );
		scroll.Canvas = new Widget( scroll );
		scroll.Canvas.Layout = Layout.Column();
		scroll.Canvas.Layout.Spacing = 8;
		var body = scroll.Canvas.Layout;

		var quick = SuperShotUI.AddCard( body, "Quick Presets", "bolt" );
		AddPresetRow( quick.Body, clean: false,
			("720p", ShotResolution.HD720),
			("1080p", ShotResolution.HD1080),
			("1440p", ShotResolution.QHD1440) );
		AddPresetRow( quick.Body, clean: false,
			("4K", ShotResolution.UHD4K),
			("8K", ShotResolution.UHD8K),
			("Square", ShotResolution.Square1080) );

		var pkg = SuperShotUI.AddCard( body, "s&box Package Thumbnails", "inventory_2" );
		AddPresetRow( pkg.Body, clean: true,
			("Square 512", ShotResolution.PackageSquare),
			("Wide 910", ShotResolution.PackageWide),
			("Tall 512", ShotResolution.PackageTall) );
		pkg.Body.Add( new Button( "Capture All Three", "burst_mode" ) { Clicked = () => SuperShotService.CaptureAllPackageThumbnails() } );

		var so = capture.GetSerialized();
		so.OnPropertyChanged += _ =>
		{
			_window.Settings.Save();
			_window.NotifyChanged();
		};

		var essentials = SuperShotUI.AddCard( body, "Shot Preferences", "aspect_ratio" );
		essentials.Body.Add( SuperShotUI.SheetWidget( so, IsEssential ) );

		SuperShotUI.AddSection( body, "Advanced Capture", "tune",
			SuperShotUI.SheetWidget( so, p => !IsEssential( p ) ),
			cookie: "supershot.capture.advanced" );

		body.AddStretchCell();
		Layout.Add( scroll, 1 );
	}

	static bool IsEssential( SerializedProperty p )
	{
		return p.Name is nameof( CaptureSettings.Source )
			or nameof( CaptureSettings.Resolution )
			or nameof( CaptureSettings.CustomWidth )
			or nameof( CaptureSettings.CustomHeight );
	}

	void AddPresetRow( Layout parent, bool clean, params (string label, ShotResolution res)[] presets )
	{
		var row = parent.AddRow();
		row.Spacing = 4;
		foreach ( var (label, res) in presets )
		{
			var resolution = res;
			row.Add( new Button( label )
			{
				Clicked = clean
					? () => SuperShotService.QuickCapture( resolution )
					: () => _window.QuickCapture( resolution )
			} );
		}
	}
}