2022-07-23 19:23:32 +00:00
|
|
|
|
using MSFSPopoutPanelManager.Orchestration;
|
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
|
|
|
|
using Prism.Commands;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
using System;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.WpfApp.ViewModel
|
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public class PanelConfigurationViewModel : 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 PanelConfigurationViewModel(MainOrchestrator orchestrator)
|
|
|
|
|
{
|
|
|
|
|
_orchestrator = orchestrator;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
LockPanelsCommand = new DelegateCommand(OnLockPanelsUpdated);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
PanelConfigUpdatedCommand = new DelegateCommand<object>(OnPanelConfigUpdated);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
MinusTenPixelCommand = new DelegateCommand<object>(OnDataItemIncDec, (obj) => NumericDataPointTextBox != null && ProfileData.HasActiveProfile && !ProfileData.ActiveProfile.IsLocked).ObservesProperty(() => SelectedPanelConfigItem).ObservesProperty(() => ProfileData.ActiveProfile.IsLocked);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
MinusOnePixelCommand = new DelegateCommand<object>(OnDataItemIncDec, (obj) => NumericDataPointTextBox != null && ProfileData.HasActiveProfile && !ProfileData.ActiveProfile.IsLocked).ObservesProperty(() => SelectedPanelConfigItem).ObservesProperty(() => ProfileData.ActiveProfile.IsLocked);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
PlusOnePixelCommand = new DelegateCommand<object>(OnDataItemIncDec, (obj) => NumericDataPointTextBox != null && ProfileData.HasActiveProfile && !ProfileData.ActiveProfile.IsLocked).ObservesProperty(() => SelectedPanelConfigItem).ObservesProperty(() => ProfileData.ActiveProfile.IsLocked);
|
|
|
|
|
|
|
|
|
|
PlusTenPixelCommand = new DelegateCommand<object>(OnDataItemIncDec, (obj) => NumericDataPointTextBox != null && ProfileData.HasActiveProfile && !ProfileData.ActiveProfile.IsLocked).ObservesProperty(() => SelectedPanelConfigItem).ObservesProperty(() => ProfileData.ActiveProfile.IsLocked);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public DelegateCommand LockPanelsCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> PanelConfigUpdatedCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> MinusTenPixelCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> MinusOnePixelCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> PlusOnePixelCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> PlusTenPixelCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public ProfileData ProfileData { get { return _orchestrator.ProfileData; } }
|
|
|
|
|
|
|
|
|
|
public PanelConfigItem SelectedPanelConfigItem { get; set; }
|
|
|
|
|
|
|
|
|
|
public TextBox NumericDataPointTextBox { get; set; }
|
|
|
|
|
|
|
|
|
|
private void OnLockPanelsUpdated()
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (ProfileData.ActiveProfile == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!ProfileData.ActiveProfile.IsLocked)
|
|
|
|
|
{
|
|
|
|
|
_orchestrator.PanelConfiguration.LockStatusUpdated();
|
|
|
|
|
}
|
|
|
|
|
else if (DialogHelper.ConfirmDialog("Confirm Unlock Panels", "Are you sure you want to unlock all panels to make changes?"))
|
|
|
|
|
{
|
|
|
|
|
_orchestrator.PanelConfiguration.LockStatusUpdated();
|
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
private void OnPanelConfigUpdated(object commandParameter)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
var panelConfigItem = commandParameter as PanelConfigItem;
|
|
|
|
|
if (panelConfigItem != null)
|
|
|
|
|
_orchestrator.PanelConfiguration.PanelConfigPropertyUpdated(panelConfigItem.PanelIndex, panelConfigItem.PanelConfigProperty);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDataItemIncDec(object commandParameter)
|
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, SelectedPanelConfigItem.PanelConfigProperty, Convert.ToInt32(commandParameter));
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
if (NumericDataPointTextBox != null)
|
|
|
|
|
NumericDataPointTextBox.Focus();
|
|
|
|
|
});
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2022-06-30 23:53:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|