mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
using System;
|
|
namespace Editor;
|
|
|
|
/// <summary>
|
|
/// A simple popup window to quickly display a message, optionally with custom actions.
|
|
/// </summary>
|
|
public class PopupWindow : Dialog
|
|
{
|
|
Label Label;
|
|
|
|
public PopupWindow( string title, string text, string buttonTxt = "OK", IDictionary<string, Action> extraButtons = null )
|
|
{
|
|
Window.MinimumWidth = 500;
|
|
Window.WindowTitle = title;
|
|
Window.SetWindowIcon( "info" );
|
|
Window.SetModal( true, true );
|
|
|
|
Layout = Layout.Column();
|
|
Layout.Margin = 20;
|
|
Layout.Spacing = 20;
|
|
|
|
Label = new Label( this );
|
|
Label.Text = text;
|
|
Layout.Add( Label );
|
|
|
|
var okButton = new Button( this );
|
|
okButton.Text = buttonTxt;
|
|
okButton.MinimumWidth = 64;
|
|
okButton.MouseLeftPress += () => Close();
|
|
okButton.AdjustSize();
|
|
|
|
var buttonLayout = Layout.Row( true );
|
|
buttonLayout.Spacing = 5;
|
|
Layout.Add( buttonLayout );
|
|
buttonLayout.Add( okButton );
|
|
|
|
if ( extraButtons != null )
|
|
{
|
|
foreach ( var KVs in extraButtons )
|
|
{
|
|
var customBtn = new Button( this );
|
|
customBtn.Text = KVs.Key;
|
|
customBtn.MinimumWidth = 64;
|
|
customBtn.MouseLeftPress += KVs.Value;
|
|
customBtn.MouseLeftPress += () => Close();
|
|
customBtn.AdjustSize();
|
|
|
|
buttonLayout.Add( customBtn );
|
|
}
|
|
}
|
|
|
|
buttonLayout.AddStretchCell();
|
|
|
|
Window.AdjustSize();
|
|
Window.Size += 8; // HACK: Adjust for weird padding between Window and this, visible via the debugger
|
|
}
|
|
|
|
protected override void OnPaint()
|
|
{
|
|
base.OnPaint();
|
|
|
|
Paint.ClearPen();
|
|
Paint.SetBrush( Theme.WidgetBackground );
|
|
Paint.DrawRect( LocalRect, 0.0f );
|
|
}
|
|
}
|