namespace Sandbox.UI; /// /// A panel that gets deleted automatically when clicked away from /// public abstract class BasePopup : Panel { static List AllPopups = new(); /// /// Stay open, even when CloseAll popups is called /// 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().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 ); } }