2023-07-12 22:41:31 +00:00
|
|
|
|
using MaterialDesignThemes.Wpf;
|
|
|
|
|
using MSFSPopoutPanelManager.DomainModel.Profile;
|
|
|
|
|
using MSFSPopoutPanelManager.Orchestration;
|
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
2023-07-23 05:13:23 +00:00
|
|
|
|
using MSFSPopoutPanelManager.WindowsAgent;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
using Prism.Commands;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Input;
|
2024-02-28 02:44:21 +00:00
|
|
|
|
using MSFSPopoutPanelManager.MainApp.AppUserControl.Dialog;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.MainApp.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class ProfileCardViewModel : BaseViewModel
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
private readonly ProfileOrchestrator _profileOrchestrator;
|
|
|
|
|
private readonly PanelSourceOrchestrator _panelSourceOrchestrator;
|
|
|
|
|
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
|
|
|
|
|
private readonly PanelPopOutOrchestrator _panelPopOutOrchestrator;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public ICommand DeleteProfileCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand ToggleAircraftBindingCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand ToggleLockProfileCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand ToggleEditPanelSourceCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand AddPanelCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand StartPopOutCommand { get; }
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public ICommand ClosePopOutCommand { get; }
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public ICommand IncludeInGamePanelUpdatedCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand AddHudBarUpdatedCommand { get; }
|
|
|
|
|
|
2023-07-23 05:13:23 +00:00
|
|
|
|
public ICommand RefocusDisplayUpdatedCommand { get; }
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public ICommand AddNumPadUpdatedCommand { get; }
|
|
|
|
|
|
2023-07-23 05:13:23 +00:00
|
|
|
|
public ICommand RefocusDisplayRefreshedCommand { get; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<string> RefocusDisplaySelectionUpdatedCommand { get; }
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public List<string> HudBarTypes => Enum.GetNames(typeof(HudBarType)).Where(x => x != "None").Select(x => x.Replace("_", " ")).ToList();
|
|
|
|
|
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public ProfileCardViewModel(SharedStorage sharedStorage, ProfileOrchestrator profileOrchestrator, PanelSourceOrchestrator panelSourceOrchestrator, PanelConfigurationOrchestrator panelConfigurationOrchestrator, PanelPopOutOrchestrator panelPopOutOrchestrator) : base(sharedStorage)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_profileOrchestrator = profileOrchestrator;
|
|
|
|
|
_panelSourceOrchestrator = panelSourceOrchestrator;
|
|
|
|
|
_panelConfigurationOrchestrator = panelConfigurationOrchestrator;
|
|
|
|
|
_panelPopOutOrchestrator = panelPopOutOrchestrator;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
DeleteProfileCommand = new DelegateCommand(OnDeleteProfile);
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ToggleAircraftBindingCommand = new DelegateCommand(OnEditAircraftBinding, () => ProfileData != null && ActiveProfile != null && FlightSimData != null && FlightSimData.HasAircraftName && ProfileData.IsAllowedAddAircraftBinding && FlightSimData.IsSimulatorStarted)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
.ObservesProperty(() => FlightSimData.AircraftName)
|
|
|
|
|
.ObservesProperty(() => FlightSimData.HasAircraftName)
|
|
|
|
|
.ObservesProperty(() => ProfileData.IsAllowedAddAircraftBinding)
|
|
|
|
|
.ObservesProperty(() => FlightSimData.IsSimulatorStarted);
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ToggleLockProfileCommand = new DelegateCommand(OnToggleLockProfile, () => ProfileData != null && ActiveProfile != null && ActiveProfile.PanelConfigs.Count > 0)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.PanelConfigs.Count);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ToggleEditPanelSourceCommand = new DelegateCommand(OnToggleEditPanelSource, () => ProfileData != null && ActiveProfile != null && ActiveProfile.PanelConfigs.Count > 0 && !ActiveProfile.IsLocked && FlightSimData.IsInCockpit)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.PanelConfigs.Count)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.IsLocked)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
.ObservesProperty(() => FlightSimData.IsInCockpit);
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
AddPanelCommand = new DelegateCommand(OnAddPanel, () => ProfileData != null && ActiveProfile != null && !ActiveProfile.IsLocked && FlightSimData.IsInCockpit)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.IsLocked)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
.ObservesProperty(() => FlightSimData.IsInCockpit);
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
StartPopOutCommand = new DelegateCommand(OnStartPopOut, () => ProfileData != null && ActiveProfile != null && (ActiveProfile.PanelConfigs.Count > 0 || ActiveProfile.ProfileSetting.IncludeInGamePanels || ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled) && !ActiveProfile.HasUnidentifiedPanelSource && !ActiveProfile.IsEditingPanelSource && !ActiveProfile.IsDisabledStartPopOut && FlightSimData.IsInCockpit)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.PanelConfigs.Count)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.ProfileSetting.IncludeInGamePanels)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.HasUnidentifiedPanelSource)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.IsEditingPanelSource)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.IsDisabledStartPopOut)
|
|
|
|
|
.ObservesProperty(() => FlightSimData.IsInCockpit);
|
|
|
|
|
|
|
|
|
|
ClosePopOutCommand = new DelegateCommand(OnClosePopOut, () => ProfileData != null && ActiveProfile != null && ActiveProfile.PanelConfigs.Count > 0 && ActiveProfile.IsPoppedOut && FlightSimData.IsInCockpit)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.PanelConfigs.Count)
|
|
|
|
|
.ObservesProperty(() => FlightSimData.IsInCockpit)
|
|
|
|
|
.ObservesProperty(() => ActiveProfile.IsPoppedOut);
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
IncludeInGamePanelUpdatedCommand = new DelegateCommand(OnIncludeInGamePanelUpdated);
|
|
|
|
|
|
|
|
|
|
AddHudBarUpdatedCommand = new DelegateCommand(OnAddHudBarUpdated);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
AddNumPadUpdatedCommand = new DelegateCommand(OnAddNumPadUpdated);
|
|
|
|
|
|
2023-07-23 05:13:23 +00:00
|
|
|
|
RefocusDisplayUpdatedCommand = new DelegateCommand(OnRefocusDisplayUpdated);
|
|
|
|
|
|
|
|
|
|
RefocusDisplayRefreshedCommand = new DelegateCommand(OnRefocusDisplayRefreshed);
|
|
|
|
|
|
|
|
|
|
RefocusDisplaySelectionUpdatedCommand = new DelegateCommand<string>(RefocusDisplaySelectionUpdated);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void OnDeleteProfile()
|
|
|
|
|
{
|
|
|
|
|
var result = await DialogHost.Show(new ConfirmationDialog("WARNING! Are you sure you want to delete the profile?", "Delete"), "RootDialog");
|
|
|
|
|
|
|
|
|
|
if (result != null && result.Equals("CONFIRM"))
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelSourceOrchestrator.CloseAllPanelSource();
|
|
|
|
|
_panelConfigurationOrchestrator.EndConfiguration();
|
|
|
|
|
_profileOrchestrator.DeleteActiveProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEditAircraftBinding()
|
|
|
|
|
{
|
|
|
|
|
if (!ProfileData.IsAircraftBoundToProfile)
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_profileOrchestrator.AddProfileBinding(FlightSimData.AircraftName);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
else
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_profileOrchestrator.DeleteProfileBinding(FlightSimData.AircraftName);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnToggleLockProfile()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile.IsLocked)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelSourceOrchestrator.CloseAllPanelSource();
|
|
|
|
|
|
|
|
|
|
foreach (var panelConfig in ActiveProfile.PanelConfigs)
|
|
|
|
|
{
|
|
|
|
|
panelConfig.IsSelectedPanelSource = false;
|
|
|
|
|
panelConfig.IsEditingPanel = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActiveProfile.IsSelectingPanelSource = false;
|
|
|
|
|
ActiveProfile.IsEditingPanelSource = false;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelConfigurationOrchestrator.StartConfiguration();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void OnToggleEditPanelSource()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile.IsEditingPanelSource)
|
|
|
|
|
await _panelSourceOrchestrator.StartEditPanelSources();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
else
|
2024-02-28 02:44:21 +00:00
|
|
|
|
await _panelSourceOrchestrator.EndEditPanelSources();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
private async void OnAddPanel()
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_profileOrchestrator.AddPanel();
|
|
|
|
|
|
|
|
|
|
ActiveProfile.IsEditingPanelSource = true;
|
|
|
|
|
await _panelSourceOrchestrator.StartEditPanelSources();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
private async void OnStartPopOut()
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile.IsDisabledStartPopOut || !FlightSimData.IsInCockpit)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
await _panelPopOutOrchestrator.ManualPopOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnClosePopOut()
|
|
|
|
|
{
|
|
|
|
|
if (ActiveProfile.IsDisabledStartPopOut || !FlightSimData.IsInCockpit)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_panelPopOutOrchestrator.ClosePopOut();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnIncludeInGamePanelUpdated()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile != null && !ActiveProfile.ProfileSetting.IncludeInGamePanels)
|
|
|
|
|
ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelType == PanelType.BuiltInPopout);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAddHudBarUpdated()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile == null)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.HudBarWindow))
|
2023-07-23 05:13:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.PanelConfigs.Add(new PanelConfig
|
2023-07-23 05:13:23 +00:00
|
|
|
|
{
|
|
|
|
|
PanelName = "HUD Bar",
|
|
|
|
|
PanelType = PanelType.HudBarWindow,
|
|
|
|
|
Left = 0,
|
|
|
|
|
Top = 0,
|
|
|
|
|
Width = 1920,
|
|
|
|
|
Height = 40,
|
|
|
|
|
AutoGameRefocus = false
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-08-14 19:51:28 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelType == PanelType.HudBarWindow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAddNumPadUpdated()
|
|
|
|
|
{
|
|
|
|
|
if (ActiveProfile == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (ActiveProfile.ProfileSetting.NumPadConfig.IsEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.NumPadWindow))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ActiveProfile.PanelConfigs.Add(new PanelConfig
|
|
|
|
|
{
|
|
|
|
|
PanelName = "Virtual NumPad",
|
|
|
|
|
PanelType = PanelType.NumPadWindow,
|
|
|
|
|
Left = 0,
|
|
|
|
|
Top = 0,
|
|
|
|
|
Width = 1920,
|
|
|
|
|
Height = 40,
|
|
|
|
|
AutoGameRefocus = false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelType == PanelType.NumPadWindow);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRefocusDisplayUpdated()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile == null)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile.ProfileSetting.RefocusOnDisplay.Monitors.Count == 0)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
{
|
|
|
|
|
var monitors = WindowActionManager.GetMonitorsInfo().OrderBy(m => m.Name);
|
|
|
|
|
|
|
|
|
|
foreach (var monitor in monitors)
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.ProfileSetting.RefocusOnDisplay.Monitors.Add(monitor);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (!ActiveProfile.ProfileSetting.RefocusOnDisplay.IsEnabled)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelType == PanelType.RefocusDisplay);
|
|
|
|
|
ActiveProfile.ProfileSetting.RefocusOnDisplay.Monitors.ToList().ForEach(p => p.IsSelected = false);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRefocusDisplayRefreshed()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile == null)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.ProfileSetting.RefocusOnDisplay.Monitors.Clear();
|
|
|
|
|
ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelType == PanelType.RefocusDisplay);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
|
|
|
|
|
var monitors = WindowActionManager.GetMonitorsInfo().OrderBy(m => m.Name);
|
|
|
|
|
|
|
|
|
|
foreach (var monitor in monitors)
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.ProfileSetting.RefocusOnDisplay.Monitors.Add(monitor);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefocusDisplaySelectionUpdated(string arg)
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (ActiveProfile == null)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
var monitor = ActiveProfile.ProfileSetting.RefocusOnDisplay.Monitors.FirstOrDefault(m => m.Name == arg);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
|
|
|
|
|
if (monitor == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-14 19:51:28 +00:00
|
|
|
|
if (!monitor.IsSelected)
|
2023-07-23 05:13:23 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelName == arg && p.PanelType == PanelType.RefocusDisplay);
|
2023-07-23 05:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
ActiveProfile.PanelConfigs.Add(new PanelConfig
|
2023-07-23 05:13:23 +00:00
|
|
|
|
{
|
|
|
|
|
PanelName = arg,
|
|
|
|
|
PanelType = PanelType.RefocusDisplay,
|
|
|
|
|
Left = monitor.X,
|
|
|
|
|
Top = monitor.Y,
|
|
|
|
|
Width = monitor.Width,
|
|
|
|
|
Height = monitor.Height,
|
2023-08-14 19:51:28 +00:00
|
|
|
|
TouchEnabled = true
|
2023-07-23 05:13:23 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|