1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 14:10:45 +00:00
msfs-popout-panel-manager/WpfApp/ViewModel/PanelSelectionViewModel.cs

206 lines
14 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using MSFSPopoutPanelManager.Orchestration;
2022-01-27 13:40:04 +00:00
using MSFSPopoutPanelManager.Shared;
2022-07-23 19:23:32 +00:00
using Prism.Commands;
2022-01-27 13:40:04 +00:00
using System;
using System.Linq;
namespace MSFSPopoutPanelManager.WpfApp.ViewModel
{
2022-06-30 23:53:08 +00:00
public class PanelSelectionViewModel : ObservableObject
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
private MainOrchestrator _orchestrator;
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public PanelSelectionViewModel(MainOrchestrator orchestrator)
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
_orchestrator = orchestrator;
2022-01-27 13:40:04 +00:00
2022-08-08 06:07:24 +00:00
AddProfileCommand = new DelegateCommand(OnAddProfile, () => FlightSimData.HasCurrentMsfsAircraft && FlightSimData.IsSimulatorStarted)
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-07-23 20:04:06 +00:00
2022-08-08 06:07:24 +00:00
DeleteProfileCommand = new DelegateCommand(OnDeleteProfile, () => ProfileData.HasActiveProfile && FlightSimData.HasCurrentMsfsAircraft && FlightSimData.IsSimulatorStarted)
.ObservesProperty(() => ProfileData.HasActiveProfile)
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-07-23 20:04:06 +00:00
2022-08-08 06:07:24 +00:00
ChangeProfileCommand = new DelegateCommand<object>(OnChangeProfile, (obj) => FlightSimData.HasCurrentMsfsAircraft && FlightSimData.IsSimulatorStarted)
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-07-23 20:04:06 +00:00
2022-08-01 23:21:42 +00:00
AddProfileBindingCommand = new DelegateCommand(OnAddProfileBinding, () => ProfileData.HasActiveProfile && FlightSimData.HasCurrentMsfsAircraft && ProfileData.IsAllowedAddAircraftBinding && FlightSimData.IsSimulatorStarted)
2022-07-30 02:29:20 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile)
2022-08-01 23:21:42 +00:00
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.HasActiveProfile)
.ObservesProperty(() => ProfileData.IsAllowedAddAircraftBinding)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-01-27 13:40:04 +00:00
2022-08-01 23:21:42 +00:00
DeleteProfileBindingCommand = new DelegateCommand(OnDeleteProfileBinding, () => ProfileData.HasActiveProfile && ProfileData.IsAllowedDeleteAircraftBinding && ProfileData.ActiveProfile.BindingAircrafts.Count > 0 && FlightSimData.IsSimulatorStarted)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.HasActiveProfile)
.ObservesProperty(() => ProfileData.IsAllowedDeleteAircraftBinding)
2022-08-01 23:21:42 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile.BindingAircrafts.Count)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-01-27 13:40:04 +00:00
2022-08-13 06:14:49 +00:00
SetPowerOnRequiredCommand = new DelegateCommand(() => ProfileData.WriteProfiles(), () => FlightSimData.HasCurrentMsfsAircraft && ProfileData.HasActiveProfile && FlightSimData.IsSimulatorStarted)
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-04-18 16:24:00 +00:00
2022-09-11 13:50:04 +00:00
SetIncludeInGamePanelsCommand = new DelegateCommand(OnSetIncludeInGamePanels, () => FlightSimData.HasCurrentMsfsAircraft && ProfileData.HasActiveProfile && FlightSimData.IsSimulatorStarted)
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
.ObservesProperty(() => ProfileData.ActiveProfile)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-08-19 16:03:12 +00:00
StartPanelSelectionCommand = new DelegateCommand(OnStartPanelSelection, () => FlightSimData.HasCurrentMsfsAircraft && ProfileData.HasActiveProfile && ProfileData.ActiveProfile != null && FlightSimData.IsSimulatorStarted && FlightSimData.IsInCockpit)
2022-08-13 06:14:49 +00:00
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile)
2022-08-18 14:20:12 +00:00
.ObservesProperty(() => FlightSimData.IsSimulatorStarted)
2022-08-19 16:03:12 +00:00
.ObservesProperty(() => FlightSimData.IsInCockpit);
2022-01-27 13:40:04 +00:00
StartPopOutCommand = new DelegateCommand(OnStartPopOut, () => FlightSimData.HasCurrentMsfsAircraft && ProfileData.HasActiveProfile && (ProfileData.ActiveProfile.PanelSourceCoordinates.Count > 0 || ProfileData.ActiveProfile.TouchPanelBindings.Count > 0 || ProfileData.ActiveProfile.IncludeInGamePanels) && FlightSimData.IsSimulatorStarted && FlightSimData.IsInCockpit)
2022-08-13 06:14:49 +00:00
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile)
.ObservesProperty(() => ProfileData.ActiveProfile.PanelSourceCoordinates.Count)
.ObservesProperty(() => ProfileData.ActiveProfile.TouchPanelBindings.Count)
.ObservesProperty(() => ProfileData.ActiveProfile.IncludeInGamePanels)
2022-08-18 14:20:12 +00:00
.ObservesProperty(() => FlightSimData.IsSimulatorStarted)
2022-08-19 16:03:12 +00:00
.ObservesProperty(() => FlightSimData.IsInCockpit);
2022-01-27 13:40:04 +00:00
2022-08-19 16:03:12 +00:00
SaveAutoPanningCameraCommand = new DelegateCommand(OnSaveAutoPanningCamera, () => FlightSimData.HasCurrentMsfsAircraft && ProfileData.HasActiveProfile && ProfileData.ActiveProfile.PanelSourceCoordinates.Count > 0 && FlightSimData.IsSimulatorStarted && FlightSimData.IsInCockpit)
2022-08-13 06:14:49 +00:00
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile)
.ObservesProperty(() => ProfileData.ActiveProfile.PanelSourceCoordinates.Count)
2022-08-18 14:20:12 +00:00
.ObservesProperty(() => FlightSimData.IsSimulatorStarted)
2022-08-19 16:03:12 +00:00
.ObservesProperty(() => FlightSimData.IsInCockpit);
2022-01-27 13:40:04 +00:00
2022-08-19 16:03:12 +00:00
EditPanelSourceCommand = new DelegateCommand(EditPanelSource, () => FlightSimData.HasCurrentMsfsAircraft && ProfileData.HasActiveProfile && ProfileData.ActiveProfile.PanelSourceCoordinates.Count > 0 && FlightSimData.IsSimulatorStarted && FlightSimData.IsInCockpit)
2022-08-13 06:14:49 +00:00
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-07-23 19:23:32 +00:00
.ObservesProperty(() => ProfileData.ActiveProfile)
.ObservesProperty(() => ProfileData.ActiveProfile.PanelSourceCoordinates.Count)
2022-08-18 14:20:12 +00:00
.ObservesProperty(() => FlightSimData.IsSimulatorStarted)
2022-08-19 16:03:12 +00:00
.ObservesProperty(() => FlightSimData.IsInCockpit);
2022-04-18 03:38:33 +00:00
2022-08-08 06:07:24 +00:00
OpenTouchPanelBindingCommand = new DelegateCommand(OnOpenTouchPanelBinding, () => FlightSimData.HasCurrentMsfsAircraft && FlightSimData.IsSimulatorStarted && ProfileData.HasActiveProfile && AppSettingData.AppSetting.TouchPanelSettings.EnableTouchPanelIntegration)
2022-08-13 06:14:49 +00:00
.ObservesProperty(() => FlightSimData.HasCurrentMsfsAircraft)
2022-08-08 06:07:24 +00:00
.ObservesProperty(() => ProfileData.HasActiveProfile)
.ObservesProperty(() => AppSettingData.AppSetting.TouchPanelSettings.EnableTouchPanelIntegration)
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
2022-04-18 03:38:33 +00:00
2022-07-23 19:23:32 +00:00
TouchPanelBindingViewModel = new TouchPanelBindingViewModel(_orchestrator);
2022-01-27 13:40:04 +00:00
}
2022-07-23 20:04:06 +00:00
public DelegateCommand AddProfileCommand { get; private set; }
public DelegateCommand DeleteProfileCommand { get; private set; }
public DelegateCommand<object> ChangeProfileCommand { get; private set; }
2022-07-23 19:23:32 +00:00
public DelegateCommand AddProfileBindingCommand { get; private set; }
2022-04-18 03:38:33 +00:00
2022-07-23 19:23:32 +00:00
public DelegateCommand DeleteProfileBindingCommand { get; private set; }
2022-04-18 03:38:33 +00:00
2022-07-23 19:23:32 +00:00
public DelegateCommand SetPowerOnRequiredCommand { get; private set; }
2022-01-27 13:40:04 +00:00
public DelegateCommand SetIncludeInGamePanelsCommand { get; private set; }
2022-07-23 19:23:32 +00:00
public DelegateCommand StartPanelSelectionCommand { get; private set; }
2022-05-04 15:11:04 +00:00
2022-07-23 19:23:32 +00:00
public DelegateCommand StartPopOutCommand { get; private set; }
2022-07-06 18:09:10 +00:00
2022-07-23 19:23:32 +00:00
public DelegateCommand SaveAutoPanningCameraCommand { get; private set; }
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public DelegateCommand EditPanelSourceCommand { get; private set; }
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public DelegateCommand OpenTouchPanelBindingCommand { get; private set; }
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public ProfileData ProfileData { get { return _orchestrator.ProfileData; } }
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public FlightSimData FlightSimData { get { return _orchestrator.FlightSimData; } }
2022-07-06 18:09:10 +00:00
2022-07-23 19:23:32 +00:00
public AppSettingData AppSettingData { get { return _orchestrator.AppSettingData; } }
2022-07-06 18:09:10 +00:00
2022-07-23 19:23:32 +00:00
public PanelSourceOrchestrator PanelSource { get { return _orchestrator.PanelSource; } }
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public TouchPanelBindingViewModel TouchPanelBindingViewModel { get; private set; }
public event EventHandler OpenTouchPanelBindingDialog;
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
private void OnAddProfile()
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
var result = DialogHelper.AddProfileDialog(ProfileData.Profiles.ToList());
2022-07-06 18:09:10 +00:00
2022-07-23 19:23:32 +00:00
if (result != null)
_orchestrator.Profile.AddProfile(result.ProfileName, result.CopyProfileId);
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnDeleteProfile()
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
if (DialogHelper.ConfirmDialog("Confirm Delete", "Are you sure you want to delete the selected profile?"))
_orchestrator.Profile.DeleteActiveProfile();
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnChangeProfile(object commandParameter)
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
if (commandParameter == null)
return;
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
var profileId = Convert.ToInt32(commandParameter);
_orchestrator.Profile.ChangeProfile(profileId);
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnAddProfileBinding()
2022-01-27 13:40:04 +00:00
{
2022-08-01 23:21:42 +00:00
_orchestrator.Profile.AddProfileBinding(FlightSimData.CurrentMsfsAircraft);
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnDeleteProfileBinding()
2022-01-27 13:40:04 +00:00
{
2022-08-01 23:21:42 +00:00
_orchestrator.Profile.DeleteProfileBinding(FlightSimData.CurrentMsfsAircraft);
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnStartPanelSelection()
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
if (!ProfileData.HasActiveProfile)
return;
if (ProfileData.ActiveProfile.PanelSourceCoordinates.Count > 0 && !DialogHelper.ConfirmDialog("Confirm Overwrite", "WARNING! Are you sure you want to overwrite existing saved panel locations and all saved setttings for this profile?"))
return;
_orchestrator.PanelSource.StartPanelSelection();
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnStartPopOut()
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
_orchestrator.PanelPopOut.ManualPopOut();
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void OnSaveAutoPanningCamera()
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
if (!ProfileData.HasActiveProfile)
return;
2022-05-04 15:11:04 +00:00
2022-07-23 19:23:32 +00:00
if (ProfileData.ActiveProfile.PanelSourceCoordinates.Count > 0 && !DialogHelper.ConfirmDialog("Confirm Overwrite Auto Panning Camera", "WARNING! Are you sure you want to overwrite existing Auto Panning camera angle?"))
return;
2022-07-11 00:18:02 +00:00
2022-07-23 19:23:32 +00:00
_orchestrator.PanelSource.SaveAutoPanningCamera();
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private void EditPanelSource()
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
_orchestrator.PanelSource.EditPanelSource();
2022-01-27 13:40:04 +00:00
}
2022-07-06 18:09:10 +00:00
2022-07-23 19:23:32 +00:00
private void OnOpenTouchPanelBinding()
2022-07-06 18:09:10 +00:00
{
2022-07-23 19:23:32 +00:00
OpenTouchPanelBindingDialog?.Invoke(this, null);
2022-07-06 18:09:10 +00:00
}
2022-09-11 13:50:04 +00:00
private void OnSetIncludeInGamePanels()
{
// Reset all in-game panels configuration
if (!ProfileData.ActiveProfile.IncludeInGamePanels)
ProfileData.ActiveProfile.PanelConfigs.RemoveAll(c => c.PanelType == PanelType.BuiltInPopout);
ProfileData.WriteProfiles();
}
2022-01-27 13:40:04 +00:00
}
}