bloxstrap/Bloxstrap/Dialogs/BootstrapperStyles/VistaDialog.cs
pizzaboxer 92b159d682 Updates and bugfixes for v1.3.0
- Features
    - Added integration with rbxfpsunlocker
    - Added support for user-applicable mods
    - Added ability to disable auto-update checking

 - Misc
    - Removed Bloxstrap branding from Discord Rich Presence
    - Mod presets for old death sound and mouse cursor are now statically stored as base64 strings, eliminating reliance on the website and the old cursors still existing

 - Bugfixes
    - Fixed vista bootstrapper style not hiding properly and improper behavior when closed
    - Fixed forms not being brought to the front when shown

 - Code
    - Reconsolidated Bootstrapper to a single file, using regions instead of partials
2022-08-21 22:41:16 +01:00

170 lines
5.1 KiB
C#

using Bloxstrap.Helpers;
using Bloxstrap.Helpers.RSMM;
namespace Bloxstrap.Dialogs.BootstrapperStyles
{
// https://youtu.be/h0_AL95Sc3o?t=48
// a bit hacky, but this is actually a hidden form
// since taskdialog is part of winforms, it can't really be properly used without a form
// for example, cross-threaded calls to ui controls can't really be done outside of a form
public partial class VistaDialog : BootstrapperStyleForm
{
private TaskDialogPage Dialog;
public override string Message
{
get => Dialog.Heading ?? "";
set => Dialog.Heading = value;
}
public override ProgressBarStyle ProgressStyle
{
set
{
if (Dialog.ProgressBar is null)
return;
switch (value)
{
case ProgressBarStyle.Continuous:
case ProgressBarStyle.Blocks:
Dialog.ProgressBar.State = TaskDialogProgressBarState.Normal;
break;
case ProgressBarStyle.Marquee:
Dialog.ProgressBar.State = TaskDialogProgressBarState.Marquee;
break;
}
}
}
public override int ProgressValue
{
get => Dialog.ProgressBar is null ? 0 : Dialog.ProgressBar.Value;
set
{
if (Dialog.ProgressBar is null)
return;
Dialog.ProgressBar.Value = value;
}
}
public override bool CancelEnabled
{
get => Dialog.Buttons[0].Enabled;
set => Dialog.Buttons[0].Enabled = value;
}
public VistaDialog(Bootstrapper? bootstrapper = null)
{
InitializeComponent();
Bootstrapper = bootstrapper;
Dialog = new TaskDialogPage()
{
Icon = new TaskDialogIcon(IconManager.GetIconResource()),
Caption = Program.ProjectName,
Buttons = { TaskDialogButton.Cancel },
ProgressBar = new TaskDialogProgressBar()
{
State = TaskDialogProgressBarState.Marquee
}
};
Message = "Please wait...";
CancelEnabled = false;
Dialog.Buttons[0].Click += (sender, e) => ButtonCancel_Click(sender, e);
SetupDialog();
}
public override void ShowSuccess(object sender, ChangeEventArgs<string> e)
{
if (this.InvokeRequired)
{
ChangeEventHandler<string> handler = new(ShowSuccess);
this.Invoke(handler, sender, e);
}
else
{
TaskDialogPage successDialog = new()
{
Icon = TaskDialogIcon.ShieldSuccessGreenBar,
Caption = Program.ProjectName,
Heading = e.Value,
Buttons = { TaskDialogButton.OK }
};
successDialog.Buttons[0].Click += (sender, e) => Program.Exit();
Dialog.Navigate(successDialog);
Dialog = successDialog;
}
}
private void InvokeShowError(object sender, ChangeEventArgs<string> e)
{
ShowError(e.Value);
}
public override void ShowError(string message)
{
if (this.InvokeRequired)
{
ChangeEventHandler<string> handler = new(InvokeShowError);
this.Invoke(handler, this, new ChangeEventArgs<string>(message));
}
else
{
TaskDialogPage errorDialog = new()
{
Icon = TaskDialogIcon.Error,
Caption = Program.ProjectName,
Heading = "An error occurred while starting Roblox",
Buttons = { TaskDialogButton.Close },
Expander = new TaskDialogExpander()
{
Text = message,
CollapsedButtonText = "See details",
ExpandedButtonText = "Hide details",
Position = TaskDialogExpanderPosition.AfterText
}
};
errorDialog.Buttons[0].Click += (sender, e) => Program.Exit();
Dialog.Navigate(errorDialog);
Dialog = errorDialog;
}
}
public override void CloseDialog(object? sender, EventArgs e)
{
if (this.InvokeRequired)
{
EventHandler handler = new(CloseDialog);
this.Invoke(handler, sender, e);
}
else
{
if (Dialog.BoundDialog is null)
return;
Dialog.BoundDialog.Close();
}
}
private void TestDialog_Load(object sender, EventArgs e)
{
TaskDialog.ShowDialog(Dialog);
}
}
}