1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-29 01:00:13 +00:00
msfs-popout-panel-manager/WpfApp/ViewModel/PanelConfigurationViewModel.cs
2022-08-03 19:04:33 -04:00

129 lines
No EOL
5.4 KiB
C#

using MSFSPopoutPanelManager.Orchestration;
using MSFSPopoutPanelManager.Shared;
using Prism.Commands;
using System;
using System.Windows;
using System.Windows.Controls;
namespace MSFSPopoutPanelManager.WpfApp.ViewModel
{
public class PanelConfigurationViewModel : ObservableObject
{
private MainOrchestrator _orchestrator;
public PanelConfigurationViewModel(MainOrchestrator orchestrator)
{
_orchestrator = orchestrator;
LockPanelsCommand = new DelegateCommand(OnLockPanelsUpdated);
PanelConfigUpdatedCommand = new DelegateCommand<object>(OnPanelConfigUpdated);
ConfigurePanelPixelCommand = new DelegateCommand<object>(OnDataItemIncDec, (obj) => NumericDataPointTextBox != null && ProfileData.HasActiveProfile && !ProfileData.ActiveProfile.IsLocked).ObservesProperty(() => SelectedPanelConfigItem).ObservesProperty(() => ProfileData.ActiveProfile.IsLocked);
ConfigurePanelCommand = new DelegateCommand<object>(OnConfigurePanel, (obj) => true);
}
public DelegateCommand LockPanelsCommand { get; private set; }
public DelegateCommand<object> PanelConfigUpdatedCommand { get; private set; }
public DelegateCommand<object> ConfigurePanelPixelCommand { get; private set; }
public DelegateCommand<object> ConfigurePanelCommand { get; private set; }
public ProfileData ProfileData { get { return _orchestrator.ProfileData; } }
public PanelConfigItem SelectedPanelConfigItem { get; set; }
public TextBox NumericDataPointTextBox { get; set; }
private void OnLockPanelsUpdated()
{
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();
}
}
private void OnPanelConfigUpdated(object commandParameter)
{
var panelConfigItem = commandParameter as PanelConfigItem;
if (panelConfigItem != null)
_orchestrator.PanelConfiguration.PanelConfigPropertyUpdated(panelConfigItem.PanelIndex, panelConfigItem.PanelConfigProperty);
}
private void OnDataItemIncDec(object commandParameter)
{
_orchestrator.PanelConfiguration.PanelConfigIncreaseDecrease(SelectedPanelConfigItem.PanelIndex, SelectedPanelConfigItem.PanelConfigProperty, Convert.ToInt32(commandParameter));
Application.Current.Dispatcher.Invoke(() =>
{
if (NumericDataPointTextBox != null)
NumericDataPointTextBox.Focus();
});
}
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; }
}
}