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]
79 lines
1.3 KiB
C#
79 lines
1.3 KiB
C#
using System;
|
|
using System.Threading;
|
|
namespace Editor;
|
|
|
|
|
|
|
|
public static class Progress
|
|
{
|
|
static ProgressWindow currentWindow;
|
|
static int Popups;
|
|
|
|
class ProgressSection : IDisposable
|
|
{
|
|
bool disposed;
|
|
string oldTitle;
|
|
|
|
public ProgressSection( string name )
|
|
{
|
|
currentWindow ??= new ProgressWindow();
|
|
Popups++;
|
|
|
|
// save state
|
|
oldTitle = currentWindow.Window.WindowTitle;
|
|
|
|
// new state
|
|
currentWindow.Window.WindowTitle = name;
|
|
|
|
currentWindow.Show();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if ( disposed ) return;
|
|
disposed = true;
|
|
|
|
Popups--;
|
|
|
|
if ( Popups <= 0 )
|
|
{
|
|
Popups = 0;
|
|
currentWindow.Window.Destroy();
|
|
currentWindow = null;
|
|
}
|
|
else
|
|
{
|
|
// restore state
|
|
currentWindow.Window.WindowTitle = oldTitle;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public static IDisposable Start( string name )
|
|
{
|
|
return new ProgressSection( name );
|
|
}
|
|
|
|
public static void Update( string title, float current = 0, float total = 0 )
|
|
{
|
|
if ( currentWindow == null )
|
|
return;
|
|
|
|
currentWindow.TaskTitle = title;
|
|
currentWindow.ProgressCurrent = current;
|
|
currentWindow.ProgressTotal = total;
|
|
currentWindow.Update();
|
|
|
|
Application.Spin();
|
|
}
|
|
|
|
public static CancellationToken GetCancel()
|
|
{
|
|
if ( currentWindow == null )
|
|
return CancellationToken.None;
|
|
|
|
return currentWindow.GetCancel();
|
|
}
|
|
}
|