mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-16 10:19:18 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
58 lines
1.0 KiB
C#
58 lines
1.0 KiB
C#
namespace Sandbox.UI;
|
|
|
|
/// <summary>
|
|
/// A panel that gets deleted automatically when clicked away from
|
|
/// </summary>
|
|
public abstract class BasePopup : Panel
|
|
{
|
|
static List<BasePopup> AllPopups = new();
|
|
|
|
/// <summary>
|
|
/// Stay open, even when CloseAll popups is called
|
|
/// </summary>
|
|
public bool StayOpen { get; set; }
|
|
|
|
public static void CloseAll( Panel exceptThisOne = null )
|
|
{
|
|
if ( AllPopups.Count == 0 )
|
|
return;
|
|
|
|
AllPopups.RemoveAll( x => !x.IsValid() );
|
|
|
|
BasePopup floater = null;
|
|
|
|
if ( exceptThisOne is Panel flt )
|
|
{
|
|
floater = flt.AncestorsAndSelf.OfType<BasePopup>().FirstOrDefault();
|
|
}
|
|
|
|
foreach ( var panel in AllPopups.ToArray() )
|
|
{
|
|
if ( panel == floater ) continue;
|
|
if ( panel.StayOpen && panel.Parent.IsValid() ) continue;
|
|
|
|
try
|
|
{
|
|
AllPopups.Remove( panel );
|
|
panel.Delete();
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
}
|
|
|
|
public BasePopup()
|
|
{
|
|
AllPopups.Add( this );
|
|
}
|
|
|
|
public override void OnDeleted()
|
|
{
|
|
base.OnDeleted();
|
|
|
|
AllPopups.Remove( this );
|
|
}
|
|
}
|