mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 13:59:22 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
124 lines
2.5 KiB
C#
124 lines
2.5 KiB
C#
using Sandbox.Audio;
|
|
using System;
|
|
|
|
namespace Editor.Audio;
|
|
|
|
public class MixerWidget : Widget
|
|
{
|
|
private Mixer mixer;
|
|
SerializedObject serialized;
|
|
|
|
AudioMeterWidget meterWidget;
|
|
|
|
public MixerWidget( Mixer main )
|
|
{
|
|
mixer = main;
|
|
HorizontalSizeMode = SizeMode.CanShrink;
|
|
serialized = mixer.GetSerialized();
|
|
|
|
Layout = Layout.Column();
|
|
BuildUI();
|
|
}
|
|
|
|
[EditorEvent.Hotload]
|
|
public void BuildUI()
|
|
{
|
|
Layout.Clear( true );
|
|
|
|
Layout.Margin = 0;
|
|
|
|
{
|
|
Layout.AddSpacingCell( 24 );
|
|
}
|
|
|
|
Layout.AddSpacingCell( 16 );
|
|
|
|
{
|
|
var row = Layout.AddRow();
|
|
row.Spacing = 8;
|
|
row.Margin = 8;
|
|
row.Add( new Button( "SOLO" ) );
|
|
row.Add( new Button( "MUTE" ) );
|
|
}
|
|
|
|
Layout.AddSpacingCell( 16 );
|
|
|
|
// Big volumey wasted space
|
|
{
|
|
var center = Layout.AddRow();
|
|
center.AddStretchCell();
|
|
center.Add( new VolumeTicksWidget() );
|
|
meterWidget = center.Add( new AudioMeterWidget() );
|
|
center.Add( new VolumeSliderWidget( serialized.GetProperty( "Volume" ) ) );
|
|
center.AddStretchCell();
|
|
}
|
|
|
|
// Processor List
|
|
{
|
|
Layout.AddSpacingCell( 8 );
|
|
Layout.Add( new ProcessorListWidget( mixer ) );
|
|
}
|
|
|
|
Layout.AddStretchCell();
|
|
}
|
|
|
|
protected override Vector2 SizeHint() => new Vector2( 120, 200 );
|
|
|
|
protected override void OnPaint()
|
|
{
|
|
base.OnPaint();
|
|
|
|
bool selected = EditorUtility.InspectorObject == mixer;
|
|
|
|
Paint.SetBrushAndPen( Theme.SurfaceBackground );
|
|
Paint.DrawRect( LocalRect );
|
|
|
|
// Header
|
|
{
|
|
var headerRect = LocalRect;
|
|
headerRect.Height = 22;
|
|
|
|
Paint.SetBrushAndPen( Theme.ControlBackground.WithAlpha( 0.5f ) );
|
|
|
|
if ( selected )
|
|
Paint.SetBrushAndPen( Theme.Blue.WithAlpha( 0.5f ) );
|
|
|
|
Paint.DrawRect( headerRect );
|
|
|
|
Paint.Pen = Theme.TextControl;
|
|
|
|
Paint.DrawText( headerRect.Shrink( 8, 0 ), "Mixer Name", TextFlag.LeftCenter );
|
|
|
|
var voices = mixer.Meter.Current.VoiceCount;
|
|
Paint.Pen = Theme.TextControl.WithAlpha( voices == 0 ? 0.2f : 0.5f );
|
|
Paint.DrawText( headerRect.Shrink( 8, 0 ), $"{voices:n0}", TextFlag.RightCenter );
|
|
}
|
|
|
|
if ( EditorUtility.InspectorObject == mixer )
|
|
{
|
|
Paint.SetBrushAndPen( Color.Transparent, Theme.Blue.WithAlpha( 0.1f ), 2 );
|
|
Paint.DrawRect( LocalRect );
|
|
}
|
|
}
|
|
|
|
protected override void OnMouseClick( MouseEvent e )
|
|
{
|
|
base.OnMouseClick( e );
|
|
|
|
EditorUtility.InspectorObject = mixer;
|
|
}
|
|
|
|
[EditorEvent.Frame]
|
|
public void Frame()
|
|
{
|
|
meterWidget.UpdateValues( mixer.Meter );
|
|
|
|
SetContentHash( ContentHash, 0.1f );
|
|
}
|
|
|
|
int ContentHash()
|
|
{
|
|
return HashCode.Combine( EditorUtility.InspectorObject == mixer, mixer.Meter.Current.VoiceCount );
|
|
}
|
|
}
|