1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2025-02-18 01:14:29 +01:00
msfs-popout-panel-manager/UI/StartupForm.cs

137 lines
5.5 KiB
C#
Raw Normal View History

2021-09-30 04:17:20 +02:00
using DarkUI.Forms;
2021-12-14 06:40:07 +01:00
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.UIController;
2021-09-30 04:17:20 +02:00
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
2021-12-14 06:40:07 +01:00
namespace MSFSPopoutPanelManager.UI
2021-09-30 04:17:20 +02:00
{
public partial class StartupForm : DarkForm
{
2021-12-14 06:40:07 +01:00
private Color ERROR_MESSAGE_COLOR = Color.FromArgb(1, 255, 71, 71);
private Color SUCCESS_MESSAGE_COLOR = Color.LightGreen;
private Color INFO_MESSAGE_COLOR = Color.White;
2021-09-30 04:17:20 +02:00
private SynchronizationContext _syncRoot;
private UserControlPanelSelection _ucPanelSelection;
2021-12-14 06:40:07 +01:00
private UserControlPanelConfiguration _ucPanelConfiguration;
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
private StartUpController _controller;
2021-09-30 04:17:20 +02:00
public StartupForm()
{
InitializeComponent();
_syncRoot = SynchronizationContext.Current;
2021-12-14 06:40:07 +01:00
_ucPanelSelection = new UserControlPanelSelection();
_ucPanelConfiguration = new UserControlPanelConfiguration();
panelSteps.Controls.Add(_ucPanelSelection);
panelSteps.Controls.Add(_ucPanelConfiguration);
2021-09-30 04:17:20 +02:00
// Set version number
lblVersion.Text += System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
2021-12-14 06:40:07 +01:00
_controller = new StartUpController(this);
_controller.OnSimConnectionChanged += HandleSimConnectionChanged;
_controller.OnPanelSelectionActivated += (source, e) => { _ucPanelSelection.Visible = true; _ucPanelConfiguration.Visible = false; };
_controller.OnPanelConfigurationActivated += (source, e) => { _ucPanelSelection.Visible = false; _ucPanelConfiguration.Visible = true; };
_controller.Initialize();
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
checkBoxMinimizeToTray.DataBindings.Add("Checked", _controller, "IsMinimizeToTray");
checkBoxMinimizeToTray.CheckedChanged += (source, e) => _controller.SetMinimizeToTray(checkBoxMinimizeToTray.Checked);
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
checkBoxAlwaysOnTop.DataBindings.Add("Checked", _controller, "IsAlwaysOnTop");
checkBoxAlwaysOnTop.CheckedChanged += (source, e) => _controller.SetAlwaysOnTop(checkBoxAlwaysOnTop.Checked);
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
checkBoxAutoStart.DataBindings.Add("Checked", _controller, "IsAutoStart");
checkBoxAutoStart.CheckedChanged += (source, e) => _controller.SetAutoStart(checkBoxAutoStart.Checked);
2021-11-24 16:57:29 +01:00
2021-12-14 06:40:07 +01:00
checkBoxAutoPanning.DataBindings.Add("Checked", _controller, "UseAutoPanning");
checkBoxAutoPanning.CheckedChanged += (source, e) => _controller.SetAutoPanning(checkBoxAutoPanning.Checked);
Logger.OnStatusLogged += Logger_OnStatusLogged;
Logger.OnBackgroundStatusLogged += Logger_OnBackgroundStatusLogged;
2021-09-30 04:17:20 +02:00
}
2021-12-14 06:40:07 +01:00
private void HandleSimConnectionChanged(object sender, EventArgs<bool> e)
2021-09-30 04:17:20 +02:00
{
_syncRoot.Post((arg) =>
{
2021-12-14 06:40:07 +01:00
var connected = Convert.ToBoolean(arg);
if (connected)
{
labelMsfsConnection.ForeColor = SUCCESS_MESSAGE_COLOR;
labelMsfsConnection.Text = "MSFS Connected";
}
else
{
labelMsfsConnection.ForeColor = ERROR_MESSAGE_COLOR;
labelMsfsConnection.Text = "MSFS Disconnected";
}
}, e.Value);
2021-09-30 04:17:20 +02:00
}
2021-12-14 06:40:07 +01:00
private void Logger_OnStatusLogged(object sender, EventArgs<StatusMessage> e)
{
if (e != null)
{
txtBoxStatus.ForeColor = e.Value.MessageType == StatusMessageType.Info ? INFO_MESSAGE_COLOR : ERROR_MESSAGE_COLOR;
txtBoxStatus.Text = e.Value.Message;
}
if (e.Value.MessageType == StatusMessageType.Error)
PInvoke.SetForegroundWindow(Handle);
}
private void Logger_OnBackgroundStatusLogged(object sender, EventArgs<StatusMessage> e)
2021-09-30 04:17:20 +02:00
{
_syncRoot.Post((arg) =>
{
2021-12-14 06:40:07 +01:00
var statusMessage = arg as StatusMessage;
if (statusMessage != null)
{
txtBoxStatus.ForeColor = statusMessage.MessageType == StatusMessageType.Info ? INFO_MESSAGE_COLOR : ERROR_MESSAGE_COLOR;
txtBoxStatus.Text = statusMessage.Message;
}
if (e.Value.MessageType == StatusMessageType.Error)
PInvoke.SetForegroundWindow(Handle);
}, e.Value);
2021-09-30 04:17:20 +02:00
}
private void StartupForm_Load(object sender, EventArgs e)
{
notifyIcon1.BalloonTipText = "Application Minimized";
notifyIcon1.BalloonTipTitle = "MSFS 2020 Pop Out Panel Manager";
}
private void StartupForm_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
if (checkBoxMinimizeToTray.Checked)
{
ShowInTaskbar = false;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(1000);
}
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
ShowInTaskbar = true;
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkVisited = true;
Process.Start(new ProcessStartInfo("https://github.com/hawkeye-stan/msfs-popout-panel-manager") { UseShellExecute = true });
}
}
2021-12-14 06:40:07 +01:00
}