2022-01-27 13:40:04 +00:00
|
|
|
|
using MSFSPopoutPanelManager.Model;
|
2021-12-14 05:40:07 +00:00
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
2021-09-30 02:17:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2021-12-14 05:40:07 +00:00
|
|
|
|
namespace MSFSPopoutPanelManager.Provider
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2021-12-14 05:40:07 +00:00
|
|
|
|
public class PanelSelectionManager
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
private UserProfileManager _userProfileManager;
|
2021-09-30 02:17:20 +00:00
|
|
|
|
private int _panelIndex;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
private List<PanelSourceCoordinate> _panelCoordinates;
|
2021-09-30 02:17:20 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public event EventHandler OnPanelSelectionCompleted;
|
|
|
|
|
public event EventHandler<EventArgs<PanelSourceCoordinate>> OnPanelLocationAdded;
|
|
|
|
|
public event EventHandler OnPanelLocationRemoved;
|
|
|
|
|
public event EventHandler OnAllPanelLocationsRemoved;
|
2021-09-30 02:17:20 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public UserProfile UserProfile { get; set; }
|
2021-12-14 05:40:07 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public AppSetting AppSetting { get; set; }
|
|
|
|
|
|
|
|
|
|
public PanelSelectionManager(UserProfileManager userProfileManager)
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
_userProfileManager = userProfileManager;
|
|
|
|
|
|
|
|
|
|
InputHookManager.OnPanelSelectionAdded += HandleOnPanelSelectionAdded;
|
|
|
|
|
InputHookManager.OnPanelSelectionRemoved += HandleOnPanelSelectionRemoved;
|
|
|
|
|
InputHookManager.OnPanelSelectionCompleted += HandleOnPanelSelectionCompleted;
|
2021-09-30 02:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
_panelIndex = 1;
|
|
|
|
|
_panelCoordinates = new List<PanelSourceCoordinate>();
|
2022-07-06 18:09:10 +00:00
|
|
|
|
//ShowPanelLocationOverlay(_panelCoordinates, true);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
InputHookManager.SubscribeToPanelSelectionEvent = true;
|
2022-07-06 18:09:10 +00:00
|
|
|
|
InputHookManager.StartHook();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowPanelLocationOverlay(List<PanelSourceCoordinate> panelCoordinates, bool show)
|
|
|
|
|
{
|
|
|
|
|
// close all overlays
|
|
|
|
|
OnAllPanelLocationsRemoved?.Invoke(this, null);
|
|
|
|
|
|
|
|
|
|
if (show && panelCoordinates.Count > 0)
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
foreach (var coor in panelCoordinates)
|
|
|
|
|
{
|
|
|
|
|
var panelSourceCoordinate = new PanelSourceCoordinate() { PanelIndex = coor.PanelIndex, X = coor.X, Y = coor.Y };
|
|
|
|
|
OnPanelLocationAdded?.Invoke(this, new EventArgs<PanelSourceCoordinate>(panelSourceCoordinate));
|
|
|
|
|
}
|
2021-09-30 02:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
private void HandleOnPanelSelectionAdded(object sender, System.Drawing.Point e)
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
var newPanelCoordinates = new PanelSourceCoordinate() { PanelIndex = _panelIndex, X = e.X, Y = e.Y };
|
|
|
|
|
_panelCoordinates.Add(newPanelCoordinates);
|
|
|
|
|
_panelIndex++;
|
|
|
|
|
|
|
|
|
|
OnPanelLocationAdded?.Invoke(this, new EventArgs<PanelSourceCoordinate>(newPanelCoordinates));
|
2021-09-30 02:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
private void HandleOnPanelSelectionRemoved(object sender, EventArgs e)
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
if (_panelCoordinates.Count > 0)
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
_panelCoordinates.RemoveAt(_panelCoordinates.Count - 1);
|
|
|
|
|
_panelIndex--;
|
|
|
|
|
|
|
|
|
|
OnPanelLocationRemoved?.Invoke(this, null);
|
2021-09-30 02:17:20 +00:00
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2021-09-30 02:17:20 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
private void HandleOnPanelSelectionCompleted(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// If enable, save the current viewport into custom view by Ctrl-Alt-0
|
|
|
|
|
if (AppSetting.UseAutoPanning)
|
2021-09-30 02:17:20 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
var simualatorProcess = DiagnosticManager.GetSimulatorProcess();
|
|
|
|
|
if (simualatorProcess != null)
|
|
|
|
|
{
|
2022-04-18 03:38:33 +00:00
|
|
|
|
InputEmulationManager.SaveCustomView(simualatorProcess.Handle, AppSetting.AutoPanningKeyBinding);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2021-09-30 02:17:20 +00:00
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
|
|
|
|
// Assign and save panel coordinates to active profile
|
|
|
|
|
UserProfile.PanelSourceCoordinates.Clear();
|
|
|
|
|
_panelCoordinates.ForEach(c => UserProfile.PanelSourceCoordinates.Add(c));
|
|
|
|
|
UserProfile.PanelConfigs.Clear();
|
|
|
|
|
UserProfile.IsLocked = false;
|
|
|
|
|
|
|
|
|
|
_userProfileManager.WriteUserProfiles();
|
|
|
|
|
|
|
|
|
|
InputHookManager.SubscribeToPanelSelectionEvent = false;
|
|
|
|
|
OnPanelSelectionCompleted?.Invoke(this, null);
|
|
|
|
|
}
|
2021-09-30 02:17:20 +00:00
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|