1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-12-01 10:10:11 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/PopOutPanelSourceCardViewModel.cs

81 lines
3.6 KiB
C#
Raw Normal View History

2024-02-28 02:44:21 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using MSFSPopoutPanelManager.Shared;
using Prism.Commands;
using System;
2024-03-12 15:10:19 +00:00
using System.Threading;
2024-02-28 02:44:21 +00:00
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class PopOutPanelSourceCardViewModel : BaseViewModel
{
private readonly PanelSourceOrchestrator _panelSourceOrchestrator;
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
public PanelConfig DataItem { get; set; }
public ICommand AddPanelSourceLocationCommand { get; set; }
public DelegateCommand<string> PanelAttributeUpdatedCommand { get; set; }
public DelegateCommand EditPanelSourceCommand { get; set; }
public ObservableRangeCollection<FixedCameraConfig> FixedCameraConfigs { get; set; } = new();
public PopOutPanelSourceCardViewModel(SharedStorage sharedStorage, PanelSourceOrchestrator panelSourceOrchestrator, PanelConfigurationOrchestrator panelConfigurationOrchestrator) : base(sharedStorage)
{
_panelSourceOrchestrator = panelSourceOrchestrator;
_panelConfigurationOrchestrator = panelConfigurationOrchestrator;
AddPanelSourceLocationCommand = new DelegateCommand(OnAddPanelSourceLocation, () => ActiveProfile != null && !ActiveProfile.IsSelectingPanelSource && FlightSimData.IsInCockpit)
.ObservesProperty(() => ActiveProfile)
.ObservesProperty(() => ActiveProfile.IsSelectingPanelSource)
.ObservesProperty(() => FlightSimData.IsInCockpit);
EditPanelSourceCommand = new DelegateCommand(OnEditPanelSource, () => ActiveProfile != null && FlightSimData.IsInCockpit)
.ObservesProperty(() => ActiveProfile)
.ObservesProperty(() => FlightSimData.IsInCockpit);
PanelAttributeUpdatedCommand = new DelegateCommand<string>(OnPanelAttributeUpdated);
}
private void OnPanelAttributeUpdated(string commandParameter)
{
if (DataItem != null && commandParameter != null)
_panelConfigurationOrchestrator.PanelConfigPropertyUpdated(DataItem.PanelHandle, (PanelConfigPropertyName)Enum.Parse(typeof(PanelConfigPropertyName), commandParameter));
}
private void OnAddPanelSourceLocation()
{
2024-03-12 15:10:19 +00:00
_panelSourceOrchestrator.ShowPanelSourceForEdit(DataItem); // This is to reset active panel source
2024-02-28 02:44:21 +00:00
FixedCameraConfigs.Clear();
FixedCameraConfigs.AddRange(_panelSourceOrchestrator.GetFixedCameraConfigs());
2024-03-12 15:10:19 +00:00
DataItem.IsEditingPanel = true;
2024-02-28 02:44:21 +00:00
_panelSourceOrchestrator.StartPanelSelectionEvent();
_panelSourceOrchestrator.StartPanelSelection(DataItem);
}
public void SetCamera()
{
_panelSourceOrchestrator.SetCamera(DataItem);
}
private void OnEditPanelSource()
{
2024-03-12 15:10:19 +00:00
if (!DataItem.HasPanelSource)
return;
2024-02-28 02:44:21 +00:00
FixedCameraConfigs.Clear();
FixedCameraConfigs.AddRange(_panelSourceOrchestrator.GetFixedCameraConfigs());
2024-03-12 15:10:19 +00:00
DataItem.IsSelectedPanelSource = true;
2024-02-28 02:44:21 +00:00
_panelSourceOrchestrator.ShowPanelSourceForEdit(DataItem);
}
}
}