124 lines
3.2 KiB
C#
124 lines
3.2 KiB
C#
using System.Reflection;
|
|
using VRage;
|
|
|
|
namespace PluginLoader.GUI;
|
|
|
|
public sealed class SplashScreen : Form
|
|
{
|
|
private const float barWidth = 0.98f; // 98% of width
|
|
private const float barHeight = 0.06f; // 6% of height
|
|
private readonly RectangleF bar;
|
|
private readonly PictureBox gifBox;
|
|
|
|
private readonly bool invalid;
|
|
private readonly Label lbl;
|
|
|
|
private float barValue = float.NaN;
|
|
|
|
public SplashScreen()
|
|
{
|
|
CheckForIllegalCrossThreadCalls = false;
|
|
if (!TryLoadImage(out var gif))
|
|
{
|
|
invalid = true;
|
|
return;
|
|
}
|
|
|
|
Name = "SplashScreenPluginLoader";
|
|
TopMost = true;
|
|
FormBorderStyle = FormBorderStyle.None;
|
|
Size = new((int)(gif.Width * 1.65), (int)(gif.Height * 1.25));
|
|
BackColor = Color.Black;
|
|
UseWaitCursor = true;
|
|
ShowInTaskbar = false;
|
|
|
|
var barSize = new SizeF(Size.Width * barWidth, Size.Height * barHeight);
|
|
var padding = (1 - barWidth) * Size.Width * 0.5f;
|
|
var barStart = new PointF(padding, Size.Height - barSize.Height - padding);
|
|
bar = new(barStart, barSize);
|
|
|
|
var lblFont = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold);
|
|
lbl = new()
|
|
{
|
|
Name = "PluginLoaderInfo",
|
|
Font = lblFont,
|
|
BackColor = Color.Black,
|
|
ForeColor = Color.White,
|
|
MaximumSize = Size,
|
|
Size = new(Size.Width, lblFont.Height),
|
|
TextAlign = ContentAlignment.MiddleCenter,
|
|
Location = new(0, (int)(barStart.Y - lblFont.Height - 1))
|
|
};
|
|
Controls.Add(lbl);
|
|
|
|
gifBox = new()
|
|
{
|
|
Name = "PluginLoaderAnimation",
|
|
Image = gif,
|
|
Size = Size,
|
|
AutoSize = false,
|
|
SizeMode = PictureBoxSizeMode.CenterImage
|
|
};
|
|
Controls.Add(gifBox);
|
|
|
|
gifBox.Paint += OnPictureBoxDraw;
|
|
|
|
CenterToScreen();
|
|
}
|
|
|
|
public object GameInfo { get; private set; }
|
|
|
|
private bool TryLoadImage(out Image img)
|
|
{
|
|
try
|
|
{
|
|
var myAssembly = Assembly.GetExecutingAssembly();
|
|
var myStream = myAssembly.GetManifestResourceStream("PluginLoader.splash.gif")!;
|
|
img = new Bitmap(myStream);
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
img = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void SetText(string msg)
|
|
{
|
|
if (invalid)
|
|
return;
|
|
|
|
lbl.Text = msg;
|
|
barValue = float.NaN;
|
|
}
|
|
|
|
public void SetBarValue(float percent = float.NaN)
|
|
{
|
|
if (invalid)
|
|
return;
|
|
|
|
barValue = percent;
|
|
}
|
|
|
|
private void OnPictureBoxDraw(object sender, PaintEventArgs e)
|
|
{
|
|
if (!float.IsNaN(barValue))
|
|
{
|
|
var graphics = e.Graphics;
|
|
graphics.FillRectangle(Brushes.DarkSlateGray, bar);
|
|
graphics.FillRectangle(Brushes.White, new RectangleF(bar.Location, new(bar.Width * barValue, bar.Height)));
|
|
}
|
|
}
|
|
|
|
public void Delete()
|
|
{
|
|
if (invalid)
|
|
return;
|
|
|
|
gifBox.Paint -= OnPictureBoxDraw;
|
|
Close();
|
|
Dispose();
|
|
MyVRage.Platform.Windows.Window.ShowAndFocus();
|
|
}
|
|
} |