mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-15 01:39:39 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
107 lines
2.3 KiB
C#
107 lines
2.3 KiB
C#
namespace Editor
|
|
{
|
|
internal class EditorSplashScreen : Widget
|
|
{
|
|
internal static EditorSplashScreen Singleton;
|
|
|
|
Pixmap BackgroundImage;
|
|
|
|
public EditorSplashScreen() : base( null, true )
|
|
{
|
|
WindowFlags = WindowFlags.Window | WindowFlags.Customized | WindowFlags.WindowTitle | WindowFlags.MSWindowsFixedSizeDialogHint;
|
|
Singleton = this;
|
|
DeleteOnClose = true;
|
|
|
|
SetWindowIcon( Pixmap.FromFile( "window_icon.png" ) );
|
|
WindowTitle = "Opening s&box Editor";
|
|
BackgroundImage = Pixmap.FromFile( "splash_screen.png" );
|
|
|
|
// load any saved geometry
|
|
string geometryCookie = EditorCookie.GetString( "splash.geometry", null );
|
|
RestoreGeometry( geometryCookie );
|
|
|
|
Size = new( BackgroundImage.Width, BackgroundImage.Height );
|
|
|
|
if ( geometryCookie is null )
|
|
{
|
|
// fallback to screen centre if there's no saved geo
|
|
Position = ScreenGeometry.Contain( Size ).Position;
|
|
}
|
|
|
|
Show();
|
|
|
|
//
|
|
// Resample background image if dpi scale is gonna make us draw it bigger
|
|
//
|
|
if ( DpiScale != 1.0f )
|
|
{
|
|
BackgroundImage = BackgroundImage.Resize( BackgroundImage.Size * DpiScale );
|
|
}
|
|
|
|
ConstrainToScreen();
|
|
|
|
g_pToolFramework2.SetStallMonitorMainThreadWindow( _widget );
|
|
|
|
Logging.OnMessage += OnConsoleMessage;
|
|
}
|
|
|
|
public override void OnDestroyed()
|
|
{
|
|
Logging.OnMessage -= OnConsoleMessage;
|
|
|
|
base.OnDestroyed();
|
|
Singleton = null;
|
|
}
|
|
|
|
void OnConsoleMessage( LogEvent e )
|
|
{
|
|
OnMessage( e.Message );
|
|
|
|
g_pToolFramework2.Spin();
|
|
NativeEngine.EngineGlobal.ToolsStallMonitor_IndicateActivity();
|
|
}
|
|
|
|
public static void StartupFinish()
|
|
{
|
|
if ( Singleton.IsValid() )
|
|
{
|
|
EditorCookie.Set( "splash.geometry", Singleton.SaveGeometry() );
|
|
Singleton.Destroy();
|
|
}
|
|
|
|
Singleton = null;
|
|
}
|
|
|
|
const int MaxMessageCount = 30;
|
|
LinkedList<string> MessageList = new();
|
|
|
|
public void OnMessage( string message )
|
|
{
|
|
MessageList.AddLast( message );
|
|
|
|
if ( MessageList.Count > MaxMessageCount )
|
|
{
|
|
MessageList.RemoveFirst();
|
|
}
|
|
|
|
Update();
|
|
}
|
|
|
|
protected override bool OnClose()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
protected override void OnPaint()
|
|
{
|
|
Paint.Draw( LocalRect, BackgroundImage );
|
|
|
|
Paint.SetPen( Color.White.WithAlpha( 0.4f ) );
|
|
|
|
string visibleMessages = string.Join( "\n", MessageList );
|
|
Paint.DrawText( LocalRect.Shrink( 32 ), visibleMessages, TextFlag.LeftBottom );
|
|
}
|
|
|
|
}
|
|
}
|