1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2025-02-16 16:34:28 +01:00
msfs-popout-panel-manager/UI/UserControlPanelSelection.cs

165 lines
7 KiB
C#
Raw Normal View History

2021-12-14 06:40:07 +01:00
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.UIController;
using System;
2021-09-30 04:17:20 +02:00
using System.Windows.Forms;
2021-12-14 06:40:07 +01:00
namespace MSFSPopoutPanelManager.UI
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
public partial class UserControlPanelSelection : UserControl
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
private PanelSelectionController _controller;
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
public UserControlPanelSelection()
2021-09-30 04:17:20 +02:00
{
InitializeComponent();
2021-12-14 06:40:07 +01:00
_controller = new PanelSelectionController();
// Listen to controller event
_controller.OnUIStateChanged += HandleOnUIStateChanged;
_controller.Initialize();
// Set bindings
comboBoxProfile.DisplayMember = "ProfileName";
comboBoxProfile.ValueMember = "ProfileId";
comboBoxProfile.DataSource = _controller.PlaneProfileList;
comboBoxProfile.DataBindings.Add("SelectedValue", _controller, "SelectedProfileId");
comboBoxProfile.SelectedValue = -1; // forced a default
comboBoxProfile.SelectedIndexChanged += HandleProfileChanged;
buttonAddProfile.Click += HandleAddProfile;
buttonDeleteProfile.Click += HandleDeleteProfile;
buttonSetDefault.Click += (source, e) => _controller.SetDefaultProfile();
buttonPanelSelection.Click += HandlePanelSelectionStarted;
buttonStartPopOut.Click += (source, e) => _controller.StartPopOut(ParentForm);
dataGridViewPanelCoor.AutoGenerateColumns = false;
dataGridViewPanelCoor.AutoSize = false;
dataGridViewPanelCoor.DataSource = _controller.PanelCoordinates;
checkBoxShowPanelLocation.DataBindings.Add("Checked", _controller, "ShowPanelLocationOverlay");
checkBoxShowPanelLocation.CheckedChanged += (source, e) => _controller.ShowPanelLocationOverlayChanged(checkBoxShowPanelLocation.Checked);
2021-09-30 04:17:20 +02:00
}
2021-12-14 06:40:07 +01:00
private void HandleAddProfile(object sender, EventArgs e)
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
using(var form = new AddProfileForm { StartPosition = FormStartPosition.CenterParent })
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
var dialogResult = form.ShowDialog();
if(dialogResult == DialogResult.OK)
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
_controller.AddUserProfile(form.ProfileName);
2021-09-30 04:17:20 +02:00
}
}
}
2021-12-14 06:40:07 +01:00
private void HandleDeleteProfile(object sender, EventArgs e)
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
var title = "Confirm Delete";
var message = "Are you sure you want to delete the selected profile?";
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
using (var form = new ConfirmDialogForm(title, message) { StartPosition = FormStartPosition.CenterParent })
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
var dialogResult = form.ShowDialog();
2021-09-30 04:17:20 +02:00
2021-12-14 06:40:07 +01:00
if (dialogResult == DialogResult.Yes)
{
_controller.DeleteProfile();
}
2021-09-30 04:17:20 +02:00
}
}
2021-12-14 06:40:07 +01:00
private void HandleProfileChanged(object sender, EventArgs e)
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
if(Convert.ToInt32(comboBoxProfile.SelectedValue) > 0)
_controller.ProfileChanged(Convert.ToInt32(comboBoxProfile.SelectedValue));
2021-09-30 04:17:20 +02:00
}
2021-12-14 06:40:07 +01:00
private void HandlePanelSelectionStarted(object sender, EventArgs e)
2021-09-30 04:17:20 +02:00
{
2021-12-14 06:40:07 +01:00
if (_controller.ActiveProfile != null)
{
if (_controller.ActiveProfile.PanelConfigs.Count > 0)
{
var title = "Confirm Overwrite";
var message = "Are you sure you want to overwrite existing saved panel locations and settings for this profile??";
using (var form = new ConfirmDialogForm(title, message) { StartPosition = FormStartPosition.CenterParent })
{
var dialogResult = form.ShowDialog();
if (dialogResult == DialogResult.No)
{
return;
}
}
}
2021-10-17 18:18:45 +02:00
2021-12-14 06:40:07 +01:00
_controller.StartPanelSelection(ParentForm);
}
2021-10-17 18:18:45 +02:00
}
2021-12-14 06:40:07 +01:00
private void HandleOnUIStateChanged(object sender, EventArgs<PanelSelectionUIState> e)
2021-10-17 18:18:45 +02:00
{
2021-12-14 06:40:07 +01:00
switch (e.Value)
2021-10-17 18:18:45 +02:00
{
2021-12-14 06:40:07 +01:00
case PanelSelectionUIState.NoProfileSelected:
comboBoxProfile.Enabled = true;
buttonAddProfile.Enabled = true;
buttonDeleteProfile.Enabled = false;
buttonSetDefault.Enabled = false;
buttonPanelSelection.Enabled = false;
checkBoxShowPanelLocation.Enabled = false;
buttonStartPopOut.Enabled = false;
break;
case PanelSelectionUIState.ProfileSelected:
comboBoxProfile.Enabled = true;
buttonAddProfile.Enabled = true;
buttonDeleteProfile.Enabled = true;
buttonSetDefault.Enabled = true;
buttonPanelSelection.Enabled = true;
checkBoxShowPanelLocation.Enabled = true;
buttonStartPopOut.Enabled = false;
break;
case PanelSelectionUIState.PanelSelectionStarted:
comboBoxProfile.Enabled = true;
buttonAddProfile.Enabled = false;
buttonDeleteProfile.Enabled = false;
buttonSetDefault.Enabled = false;
buttonPanelSelection.Enabled = false;
checkBoxShowPanelLocation.Enabled = false;
buttonStartPopOut.Enabled = false;
break;
case PanelSelectionUIState.PanelSelectionCompletedValid:
comboBoxProfile.Enabled = true;
buttonAddProfile.Enabled = true;
buttonDeleteProfile.Enabled = true;
buttonSetDefault.Enabled = true;
buttonPanelSelection.Enabled = true;
checkBoxShowPanelLocation.Enabled = true;
buttonStartPopOut.Enabled = true;
buttonStartPopOut.Focus();
break;
case PanelSelectionUIState.PanelSelectionCompletedInvalid:
comboBoxProfile.Enabled = true;
buttonAddProfile.Enabled = true;
buttonDeleteProfile.Enabled = true;
buttonSetDefault.Enabled = true;
buttonPanelSelection.Enabled = true;
checkBoxShowPanelLocation.Enabled = true;
buttonStartPopOut.Enabled = false;
break;
case PanelSelectionUIState.PopoutStarted:
comboBoxProfile.Enabled = false;
buttonAddProfile.Enabled = false;
buttonDeleteProfile.Enabled = false;
buttonSetDefault.Enabled = false;
buttonPanelSelection.Enabled = false;
checkBoxShowPanelLocation.Enabled = false;
buttonStartPopOut.Enabled = false;
break;
2021-10-17 18:18:45 +02:00
}
2021-09-30 04:17:20 +02:00
}
}
}