1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 07:10:10 +00:00
msfs-popout-panel-manager/WpfApp/ViewModel/PanelConfigurationViewModel.cs

129 lines
5.4 KiB
C#
Raw Normal View History

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-08-02 20:55:20 +00:00
ConfigurePanelPixelCommand = 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-08-02 20:55:20 +00:00
ConfigurePanelCommand = new DelegateCommand<object>(OnConfigurePanel, (obj) => true);
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; }
2022-08-02 20:55:20 +00:00
public DelegateCommand<object> ConfigurePanelPixelCommand { get; private set; }
2022-07-23 19:23:32 +00:00
2022-08-02 20:55:20 +00:00
public DelegateCommand<object> ConfigurePanelCommand { get; private set; }
2022-07-23 19:23:32 +00:00
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-08-02 20:55:20 +00:00
private void OnConfigurePanel(object commandParameter)
{
if (SelectedPanelConfigItem.PanelIndex == -1)
return;
var keyAction = commandParameter as KeyAction;
switch (keyAction.Action)
{
case "Up":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Top, -1 * keyAction.Multiplier);
break;
case "Down":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Top, 1 * keyAction.Multiplier);
break;
case "Left":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Left, -1 * keyAction.Multiplier);
break;
case "Right":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Left, 1 * keyAction.Multiplier);
break;
case "Control-Up":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Height, -1 * keyAction.Multiplier);
break;
case "Control-Down":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Height, 1 * keyAction.Multiplier);
break;
case "Control-Left":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Width, -1 * keyAction.Multiplier);
break;
case "Control-Right":
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, PanelConfigPropertyName.Width, 1 * keyAction.Multiplier);
break;
}
}
}
public class KeyAction
{
public KeyAction(string action, int multiplier)
{
Action = action;
Multiplier = multiplier;
}
public KeyAction(string action)
{
Action = action;
Multiplier = 1;
}
public string Action { get; set; }
public int Multiplier { get; set; }
2022-06-30 23:53:08 +00:00
}
}