2022-07-23 21:23:32 +02:00
using MSFSPopoutPanelManager.Orchestration ;
2022-01-27 14:40:04 +01:00
using MSFSPopoutPanelManager.Shared ;
2022-07-23 21:23:32 +02:00
using Prism.Commands ;
2022-01-27 14:40:04 +01:00
using System ;
using System.Linq ;
namespace MSFSPopoutPanelManager.WpfApp.ViewModel
{
2022-07-01 01:53:08 +02:00
public class PanelSelectionViewModel : ObservableObject
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
private MainOrchestrator _orchestrator ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public PanelSelectionViewModel ( MainOrchestrator orchestrator )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
_orchestrator = orchestrator ;
2022-01-27 14:40:04 +01:00
2022-07-23 22:04:06 +02:00
AddProfileCommand = new DelegateCommand ( OnAddProfile ) ;
DeleteProfileCommand = new DelegateCommand ( OnDeleteProfile , ( ) = > ProfileData . HasActiveProfile )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile ) ;
ChangeProfileCommand = new DelegateCommand < object > ( OnChangeProfile ) ;
2022-07-23 21:23:32 +02:00
AddProfileBindingCommand = new DelegateCommand ( OnAddProfileBinding , ( ) = > ProfileData . HasActiveProfile & & FlightSimData . HasCurrentMsfsPlaneTitle & & ProfileData . IsAllowedAddAircraftBinding & & FlightSimData . IsSimulatorStarted )
2022-07-30 04:29:20 +02:00
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile )
2022-07-23 21:23:32 +02:00
. ObservesProperty ( ( ) = > FlightSimData . HasCurrentMsfsPlaneTitle )
. ObservesProperty ( ( ) = > ProfileData . HasActiveProfile )
. ObservesProperty ( ( ) = > ProfileData . IsAllowedAddAircraftBinding )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
DeleteProfileBindingCommand = new DelegateCommand ( OnDeleteProfileBinding , ( ) = > ProfileData . HasActiveProfile & & ProfileData . IsAllowedDeleteAircraftBinding & & ProfileData . ActiveProfile . BindingAircraftLiveries . Count > 0 & & FlightSimData . IsSimulatorStarted )
. ObservesProperty ( ( ) = > ProfileData . HasActiveProfile )
. ObservesProperty ( ( ) = > ProfileData . IsAllowedDeleteAircraftBinding )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile . BindingAircraftLiveries . Count )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
SetPowerOnRequiredCommand = new DelegateCommand ( ( ) = > ProfileData . WriteProfiles ( ) , ( ) = > ProfileData . HasActiveProfile & & FlightSimData . IsSimulatorStarted )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-04-18 18:24:00 +02:00
2022-07-23 21:23:32 +02:00
StartPanelSelectionCommand = new DelegateCommand ( OnStartPanelSelection , ( ) = > ProfileData . HasActiveProfile & & ProfileData . ActiveProfile ! = null & & FlightSimData . IsSimulatorStarted )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
StartPopOutCommand = new DelegateCommand ( OnStartPopOut , ( ) = > ProfileData . HasActiveProfile & & ( ProfileData . ActiveProfile . PanelSourceCoordinates . Count > 0 | | ProfileData . ActiveProfile . TouchPanelBindings . Count > 0 ) & & FlightSimData . IsSimulatorStarted )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile . PanelSourceCoordinates . Count )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile . TouchPanelBindings . Count )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
SaveAutoPanningCameraCommand = new DelegateCommand ( OnSaveAutoPanningCamera , ( ) = > ProfileData . HasActiveProfile & & ProfileData . ActiveProfile . PanelSourceCoordinates . Count > 0 & & FlightSimData . IsSimulatorStarted )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile . PanelSourceCoordinates . Count )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
EditPanelSourceCommand = new DelegateCommand ( EditPanelSource , ( ) = > ProfileData . HasActiveProfile & & ProfileData . ActiveProfile . PanelSourceCoordinates . Count > 0 & & FlightSimData . IsSimulatorStarted )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile )
. ObservesProperty ( ( ) = > ProfileData . ActiveProfile . PanelSourceCoordinates . Count )
. ObservesProperty ( ( ) = > FlightSimData . IsSimulatorStarted ) ;
2022-04-18 05:38:33 +02:00
2022-07-23 21:23:32 +02:00
OpenTouchPanelBindingCommand = new DelegateCommand ( OnOpenTouchPanelBinding , ( ) = > ProfileData . HasActiveProfile & & AppSettingData . AppSetting . TouchPanelSettings . EnableTouchPanelIntegration )
. ObservesProperty ( ( ) = > ProfileData . HasActiveProfile )
. ObservesProperty ( ( ) = > AppSettingData . AppSetting . TouchPanelSettings . EnableTouchPanelIntegration ) ;
2022-04-18 05:38:33 +02:00
2022-07-23 21:23:32 +02:00
TouchPanelBindingViewModel = new TouchPanelBindingViewModel ( _orchestrator ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 22:04:06 +02:00
public DelegateCommand AddProfileCommand { get ; private set ; }
public DelegateCommand DeleteProfileCommand { get ; private set ; }
public DelegateCommand < object > ChangeProfileCommand { get ; private set ; }
2022-07-23 21:23:32 +02:00
public DelegateCommand AddProfileBindingCommand { get ; private set ; }
2022-04-18 05:38:33 +02:00
2022-07-23 21:23:32 +02:00
public DelegateCommand DeleteProfileBindingCommand { get ; private set ; }
2022-04-18 05:38:33 +02:00
2022-07-23 21:23:32 +02:00
public DelegateCommand SetPowerOnRequiredCommand { get ; private set ; }
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public DelegateCommand StartPanelSelectionCommand { get ; private set ; }
2022-05-04 17:11:04 +02:00
2022-07-23 21:23:32 +02:00
public DelegateCommand StartPopOutCommand { get ; private set ; }
2022-07-06 20:09:10 +02:00
2022-07-23 21:23:32 +02:00
public DelegateCommand SaveAutoPanningCameraCommand { get ; private set ; }
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public DelegateCommand EditPanelSourceCommand { get ; private set ; }
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public DelegateCommand OpenTouchPanelBindingCommand { get ; private set ; }
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public ProfileData ProfileData { get { return _orchestrator . ProfileData ; } }
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public FlightSimData FlightSimData { get { return _orchestrator . FlightSimData ; } }
2022-07-06 20:09:10 +02:00
2022-07-23 21:23:32 +02:00
public AppSettingData AppSettingData { get { return _orchestrator . AppSettingData ; } }
2022-07-06 20:09:10 +02:00
2022-07-23 21:23:32 +02:00
public PanelSourceOrchestrator PanelSource { get { return _orchestrator . PanelSource ; } }
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
public TouchPanelBindingViewModel TouchPanelBindingViewModel { get ; private set ; }
public event EventHandler OpenTouchPanelBindingDialog ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
private void OnAddProfile ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
var result = DialogHelper . AddProfileDialog ( ProfileData . Profiles . ToList ( ) ) ;
2022-07-06 20:09:10 +02:00
2022-07-23 21:23:32 +02:00
if ( result ! = null )
_orchestrator . Profile . AddProfile ( result . ProfileName , result . CopyProfileId ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnDeleteProfile ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
if ( DialogHelper . ConfirmDialog ( "Confirm Delete" , "Are you sure you want to delete the selected profile?" ) )
_orchestrator . Profile . DeleteActiveProfile ( ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnChangeProfile ( object commandParameter )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
if ( commandParameter = = null )
return ;
2022-01-27 14:40:04 +01:00
2022-07-23 21:23:32 +02:00
var profileId = Convert . ToInt32 ( commandParameter ) ;
_orchestrator . Profile . ChangeProfile ( profileId ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnAddProfileBinding ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
_orchestrator . Profile . AddProfileBinding ( FlightSimData . CurrentMsfsPlaneTitle ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnDeleteProfileBinding ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
_orchestrator . Profile . DeleteProfileBinding ( FlightSimData . CurrentMsfsPlaneTitle ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnStartPanelSelection ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02: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 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnStartPopOut ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
_orchestrator . PanelPopOut . ManualPopOut ( ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void OnSaveAutoPanningCamera ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
if ( ! ProfileData . HasActiveProfile )
return ;
2022-05-04 17:11:04 +02:00
2022-07-23 21:23:32 +02: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 02:18:02 +02:00
2022-07-23 21:23:32 +02:00
_orchestrator . PanelSource . SaveAutoPanningCamera ( ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-23 21:23:32 +02:00
private void EditPanelSource ( )
2022-01-27 14:40:04 +01:00
{
2022-07-23 21:23:32 +02:00
_orchestrator . PanelSource . EditPanelSource ( ) ;
2022-01-27 14:40:04 +01:00
}
2022-07-06 20:09:10 +02:00
2022-07-23 21:23:32 +02:00
private void OnOpenTouchPanelBinding ( )
2022-07-06 20:09:10 +02:00
{
2022-07-23 21:23:32 +02:00
OpenTouchPanelBindingDialog ? . Invoke ( this , null ) ;
2022-07-06 20:09:10 +02:00
}
2022-01-27 14:40:04 +01:00
}
}