From ccefa806421d64471b8a1e22f990b973d6bf96b5 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sat, 21 Nov 2020 14:48:32 +1300 Subject: [PATCH] Added overlay to inform user UI is locked This informs the user that the user UI is locked until they close the game/application that is started. --- HeliosPlus/HeliosPlus.csproj | 9 ++ HeliosPlus/ShortcutRepository.cs | 9 +- HeliosPlus/UIForms/MaskedDialog.cs | 116 +++++++++++++++++++++ HeliosPlus/UIForms/MaskedForm.cs | 115 +++++++++++++++++++++ HeliosPlus/UIForms/MaskedForm.resx | 120 ++++++++++++++++++++++ HeliosPlus/UIForms/ShortcutLibraryForm.cs | 19 +++- 6 files changed, 383 insertions(+), 5 deletions(-) create mode 100644 HeliosPlus/UIForms/MaskedDialog.cs create mode 100644 HeliosPlus/UIForms/MaskedForm.cs create mode 100644 HeliosPlus/UIForms/MaskedForm.resx diff --git a/HeliosPlus/HeliosPlus.csproj b/HeliosPlus/HeliosPlus.csproj index e1e4399..098cf0d 100644 --- a/HeliosPlus/HeliosPlus.csproj +++ b/HeliosPlus/HeliosPlus.csproj @@ -100,6 +100,12 @@ ApplyingProfileForm.cs + + Form + + + Form + Form @@ -160,6 +166,9 @@ ApplyingProfileForm.cs + + MaskedForm.cs + WaitingForm.cs diff --git a/HeliosPlus/ShortcutRepository.cs b/HeliosPlus/ShortcutRepository.cs index f2c9dcd..e014e9f 100644 --- a/HeliosPlus/ShortcutRepository.cs +++ b/HeliosPlus/ShortcutRepository.cs @@ -618,7 +618,10 @@ namespace HeliosPlus IPCService.GetInstance().HoldProcessId = processesToMonitor.FirstOrDefault()?.Id ?? 0; IPCService.GetInstance().Status = InstanceStatus.OnHold; - notifyIcon.Text = $"HeliosPlus: Waiting for the Application {processesToMonitor[0].ProcessName} to exit..."; + int substringStart = shortcutToUse.ExecutableNameAndPath.Length - 42; + if (substringStart < 0) + substringStart = 0; + notifyIcon.Text = $"HeliosPlus: Running {shortcutToUse.ExecutableNameAndPath.Substring(substringStart)}..."; Application.DoEvents(); // Wait for the monitored process to exit @@ -682,7 +685,7 @@ namespace HeliosPlus IPCService.GetInstance().Status = InstanceStatus.OnHold; // Add a status notification icon in the status area - notifyIcon.Text = $"HeliosPlus: Waiting for the Game {steamGameToRun.Name} to exit..."; + notifyIcon.Text = $"HeliosPlus: Running {steamGameToRun.Name.Substring(0, 41)}..."; Application.DoEvents(); // Wait 300ms for the game process to spawn @@ -754,7 +757,7 @@ namespace HeliosPlus IPCService.GetInstance().Status = InstanceStatus.OnHold; // Add a status notification icon in the status area - notifyIcon.Text = $"HeliosPlus: Waiting for the Game {uplayGameToRun.Name} to exit..."; + notifyIcon.Text = $"HeliosPlus: Running {uplayGameToRun.Name.Substring(0,41)}..."; Application.DoEvents(); // Wait 300ms for the game process to spawn diff --git a/HeliosPlus/UIForms/MaskedDialog.cs b/HeliosPlus/UIForms/MaskedDialog.cs new file mode 100644 index 0000000..fbc6f70 --- /dev/null +++ b/HeliosPlus/UIForms/MaskedDialog.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HeliosPlus.UIForms +{ + public partial class MaskedDialog : Form + { + // from https://stackoverflow.com/questions/21530699/how-to-draw-overlay-window-winform-apps-c-sharp + + static MaskedDialog mask; + static Form frmContainer; + + private Form dialog; + private UserControl ucDialog; + + private MaskedDialog(Form parent, Form dialog) + { + this.dialog = dialog; + this.FormBorderStyle = FormBorderStyle.None; + this.BackColor = System.Drawing.Color.Black; + this.Opacity = 0.50; + this.ShowInTaskbar = false; + this.StartPosition = FormStartPosition.Manual; + this.Size = parent.ClientSize; + this.Location = parent.PointToScreen(System.Drawing.Point.Empty); + parent.Move += AdjustPosition; + parent.SizeChanged += AdjustPosition; + } + + private MaskedDialog(Form parent, UserControl ucDialog) + { + this.ucDialog = ucDialog; + this.FormBorderStyle = FormBorderStyle.None; + this.BackColor = System.Drawing.Color.Black; + this.Opacity = 0.50; + this.ShowInTaskbar = false; + this.StartPosition = FormStartPosition.Manual; + this.Size = parent.ClientSize; + this.Location = parent.PointToScreen(System.Drawing.Point.Empty); + parent.Move += AdjustPosition; + parent.SizeChanged += AdjustPosition; + } + + private void AdjustPosition(object sender, EventArgs e) + { + Form parent = sender as Form; + this.Location = parent.PointToScreen(System.Drawing.Point.Empty); + this.ClientSize = parent.ClientSize; + } + + // + public static DialogResult ShowDialog(Form parent, Form dialog) + { + mask = new MaskedDialog(parent, dialog); + dialog.StartPosition = FormStartPosition.CenterParent; + mask.MdiParent = parent.MdiParent; + //mask.Show(); + DialogResult result = dialog.ShowDialog(mask); + //mask.Close(); + return result; + } + + public static DialogResult ShowDialog(Form parent, UserControl dialog) + { + mask = new MaskedDialog(parent, dialog); + frmContainer = new Form(); + frmContainer.ShowInTaskbar = false; + frmContainer.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + frmContainer.StartPosition = FormStartPosition.CenterParent; + frmContainer.Height = dialog.Height; + frmContainer.Width = dialog.Width; + + frmContainer.Controls.Add(dialog); + mask.MdiParent = parent.MdiParent; + //mask.ShowDialog(); + DialogResult result = frmContainer.ShowDialog(mask); + frmContainer.Close(); + //mask.Close(); + return result; + } + + public static void CloseDialog() + { + if (frmContainer != null) + { + frmContainer.Close(); + } + } + + private void InitializeComponent() + { + this.SuspendLayout(); + // + // MaskedDialog + // + this.ClientSize = new System.Drawing.Size(284, 262); + this.Name = "MaskedDialog"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MaskedDialog_FormClosing); + this.Load += new System.EventHandler(this.MaskedDialog_Load); + this.ResumeLayout(false); + + } + + private void MaskedDialog_Load(object sender, EventArgs e) + { + } + + private void MaskedDialog_FormClosing(object sender, FormClosingEventArgs e) + { + } + } +} diff --git a/HeliosPlus/UIForms/MaskedForm.cs b/HeliosPlus/UIForms/MaskedForm.cs new file mode 100644 index 0000000..d857c21 --- /dev/null +++ b/HeliosPlus/UIForms/MaskedForm.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HeliosPlus.UIForms +{ + public partial class MaskedForm : Form + { + private Label lbl_message; + + // from https://stackoverflow.com/questions/21530699/how-to-draw-overlay-window-winform-apps-c-sharp + + public static MaskedForm mask; + + + + private MaskedForm(Form parent, string message) + { + this.SuspendLayout(); + InitializeComponent(); + this.FormBorderStyle = FormBorderStyle.None; + //this.BackColor = System.Drawing.Color.Black; + this.Opacity = 0.50; + this.ShowInTaskbar = false; + this.StartPosition = FormStartPosition.Manual; + this.Size = parent.ClientSize; + this.Location = parent.PointToScreen(System.Drawing.Point.Empty); + //this.lbl_message.BackColor = System.Drawing.Color.Black; + this.lbl_message.Text = message; + this.MdiParent = parent.MdiParent; + this.TopLevel = true; + parent.Move += AdjustPosition; + parent.SizeChanged += AdjustPosition; + this.ResumeLayout(); + } + + private void AdjustPosition(object sender, EventArgs e) + { + Form parent = sender as Form; + this.Location = parent.PointToScreen(System.Drawing.Point.Empty); + this.ClientSize = parent.ClientSize; + } + + // + public static MaskedForm Show(Form parent, string message) + { + mask = new MaskedForm(parent, message); + mask.Show(); + mask.Activate(); + Application.DoEvents(); + return mask; + } + + public static MaskedForm ShowDialog(Form parent, string message) + { + mask = new MaskedForm(parent, message); + mask.ShowDialog(); + mask.Activate(); + Application.DoEvents(); + return mask; + } + + /*public static void Close() + { + MaskedForm.mask.Close(); + }*/ + + private void InitializeComponent() + { + this.lbl_message = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lbl_message + // + this.lbl_message.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbl_message.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbl_message.Location = new System.Drawing.Point(161, 93); + this.lbl_message.Name = "lbl_message"; + this.lbl_message.Size = new System.Drawing.Size(415, 104); + this.lbl_message.TabIndex = 0; + this.lbl_message.Text = "label1"; + this.lbl_message.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // MaskedForm + // + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(714, 310); + this.Controls.Add(this.lbl_message); + this.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.ForeColor = System.Drawing.Color.White; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "MaskedForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MaskedForm_FormClosing); + this.Load += new System.EventHandler(this.MaskedForm_Load); + this.ResumeLayout(false); + + } + + private void MaskedForm_Load(object sender, EventArgs e) + { + } + + private void MaskedForm_FormClosing(object sender, FormClosingEventArgs e) + { + } + } +} diff --git a/HeliosPlus/UIForms/MaskedForm.resx b/HeliosPlus/UIForms/MaskedForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/HeliosPlus/UIForms/MaskedForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HeliosPlus/UIForms/ShortcutLibraryForm.cs b/HeliosPlus/UIForms/ShortcutLibraryForm.cs index 5905fa7..dc3bd47 100644 --- a/HeliosPlus/UIForms/ShortcutLibraryForm.cs +++ b/HeliosPlus/UIForms/ShortcutLibraryForm.cs @@ -234,10 +234,25 @@ namespace HeliosPlus.UIForms if (_selectedShortcut == null) return; - MainForm mf = (MainForm)this.Owner; + // Figure out the string we're going to use as the MaskedForm message + string message = ""; + if (_selectedShortcut.Category.Equals(ShortcutCategory.Application)) + message = $"Starting the {_selectedShortcut.ExecutableNameAndPath} application and waiting until you close it."; + else if (_selectedShortcut.Category.Equals(ShortcutCategory.Game)) + message = $"Starting the {_selectedShortcut.GameName} game and waiting until you close it."; + + // Create a MaskForm that will cover the ShortcutLibrary Window to lock + // the controls and inform the user that the game is running.... + MaskedForm maskedForm = MaskedForm.Show(this, message); + + // Get the MainForm so we can access the NotifyIcon on it. + MainForm mainForm = (MainForm)this.Owner; + // Run the shortcut - ShortcutRepository.RunShortcut(_selectedShortcut, mf.notifyIcon); + ShortcutRepository.RunShortcut(_selectedShortcut, mainForm.notifyIcon); + + maskedForm.Close(); } } }