1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 13:50:14 +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)
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigPropertyUpdated(panelConfigItem.PanelHandle, panelConfigItem.PanelConfigProperty);
2022-01-27 13:40:04 +00:00
}
private void OnDataItemIncDec(object commandParameter)
{
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, 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)
{
2022-09-11 13:50:04 +00:00
if (SelectedPanelConfigItem.PanelHandle == IntPtr.Zero)
2022-08-02 20:55:20 +00:00
return;
var keyAction = commandParameter as KeyAction;
switch (keyAction.Action)
{
case "Up":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Top, -1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Down":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Top, 1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Left":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Left, -1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Right":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Left, 1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Control-Up":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Height, -1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Control-Down":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Height, 1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Control-Left":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Width, -1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
break;
case "Control-Right":
2022-09-11 13:50:04 +00:00
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelHandle, PanelConfigPropertyName.Width, 1 * keyAction.Multiplier);
2022-08-02 20:55:20 +00:00
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
}
}