2023-07-12 22:41:31 +00:00
|
|
|
|
using MSFSPopoutPanelManager.DomainModel.Profile;
|
|
|
|
|
using MSFSPopoutPanelManager.DomainModel.Setting;
|
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
using MSFSPopoutPanelManager.WindowsAgent;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
using System.Windows;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.Orchestration
|
|
|
|
|
{
|
|
|
|
|
public class PanelPopOutOrchestrator : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
// This will be replaced by a signal from Ready to Fly Skipper into webserver in version 4.0
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private const int READY_TO_FLY_BUTTON_APPEARANCE_DELAY = 2000;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private ProfileData _profileData;
|
|
|
|
|
private AppSettingData _appSettingData;
|
|
|
|
|
private FlightSimData _flightSimData;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public PanelPopOutOrchestrator(ProfileData profileData, AppSettingData appSettingData, FlightSimData flightSimData)
|
|
|
|
|
{
|
|
|
|
|
_profileData = profileData;
|
|
|
|
|
_appSettingData = appSettingData;
|
|
|
|
|
_flightSimData = flightSimData;
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
internal FlightSimOrchestrator FlightSimOrchestrator { private get; set; }
|
|
|
|
|
|
|
|
|
|
internal PanelSourceOrchestrator PanelSourceOrchestrator { private get; set; }
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
internal PanelConfigurationOrchestrator PanelConfigurationOrchestrator { private get; set; }
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private UserProfile ActiveProfile { get { return _profileData == null ? null : _profileData.ActiveProfile; } }
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private ApplicationSetting AppSetting { get { return _appSettingData == null ? null : _appSettingData.ApplicationSetting; } }
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
public event EventHandler OnPopOutStarted;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public event EventHandler OnPopOutCompleted;
|
|
|
|
|
public event EventHandler<PanelConfig> OnHudBarOpened;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public async void ManualPopOut()
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await CoreSteps(false);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public async void AutoPopOut()
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await Application.Current.Dispatcher.Invoke(async () =>
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
_profileData.AutoSwitchProfile();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-26 20:22:44 +00:00
|
|
|
|
if (ActiveProfile == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Do not do auto pop out if no profile matches the current aircraft
|
|
|
|
|
if (!ActiveProfile.AircraftBindings.Any(p => p == _flightSimData.AircraftName))
|
|
|
|
|
return;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Do not do auto pop out if no panel configs defined
|
|
|
|
|
if (ActiveProfile.PanelConfigs.Count == 0)
|
|
|
|
|
return;
|
2022-10-16 13:11:01 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Do not do auto pop out if not all custom panels have panel source defined
|
|
|
|
|
if (ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.CustomPopout) > 0 &&
|
|
|
|
|
ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.CustomPopout && p.HasPanelSource) != ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.CustomPopout))
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await CoreSteps(true);
|
|
|
|
|
});
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task CoreSteps(bool isAutoPopOut)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (ActiveProfile == null || ActiveProfile.IsEditingPanelSource || ActiveProfile.HasUnidentifiedPanelSource)
|
|
|
|
|
return;
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
OnPopOutStarted?.Invoke(this, null);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.IsEnabled = true;
|
|
|
|
|
StatusMessageWriter.ClearMessage();
|
|
|
|
|
StatusMessageWriter.WriteMessageNewLine("Pop out in progress. Please refrain from moving your mouse.", StatusMessageType.Info);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StepPopoutPrep();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await StepReadyToFlyDelay(isAutoPopOut);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// *** THIS MUST BE DONE FIRST. Get the built-in panel list to be configured later
|
|
|
|
|
List<IntPtr> builtInPanelHandles = WindowActionManager.GetWindowsByPanelType(new List<PanelType>() { PanelType.BuiltInPopout });
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await StepAddCutomPanels(builtInPanelHandles);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StepAddBuiltInPanels(builtInPanelHandles);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StepAddHudBar();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-23 05:13:23 +00:00
|
|
|
|
SetupRefocusDisplay();
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StepApplyPanelConfig();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await StepPostPopout();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.IsEnabled = false;
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private void StepPopoutPrep()
|
|
|
|
|
{
|
|
|
|
|
PanelConfigurationOrchestrator.EndConfiguration();
|
|
|
|
|
|
|
|
|
|
// Set profile pop out status
|
|
|
|
|
_profileData.ResetActiveProfile();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
// Close all existing custom pop out panels
|
|
|
|
|
WindowActionManager.CloseAllPopOuts();
|
|
|
|
|
|
|
|
|
|
// Close all panel source overlays
|
|
|
|
|
PanelSourceOrchestrator.CloseAllPanelSource();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task StepReadyToFlyDelay(bool isAutoPopOut)
|
|
|
|
|
{
|
|
|
|
|
if (!isAutoPopOut)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await Task.Run(() =>
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.WriteMessage("Waiting on ready to fly button delay", StatusMessageType.Info);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Match the delay for Ready to Fly button to disappear
|
|
|
|
|
Thread.Sleep(READY_TO_FLY_BUTTON_APPEARANCE_DELAY);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Extra wait for cockpit view to appear and align
|
|
|
|
|
Thread.Sleep(AppSetting.AutoPopOutSetting.ReadyToFlyDelay * 1000);
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task StepAddCutomPanels(List<IntPtr> builtInPanelHandles)
|
|
|
|
|
{
|
|
|
|
|
if (!ActiveProfile.HasCustomPanels)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await StepPreCustomPanelPopOut();
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await StepCustomPanelPopOut(builtInPanelHandles);
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await StepPostCustomPanelPopOut();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task StepPreCustomPanelPopOut()
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await Task.Run(() =>
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Set Windowed Display Mode window's configuration if needed
|
|
|
|
|
if (_appSettingData.ApplicationSetting.WindowedModeSetting.AutoResizeMsfsGameWindow && WindowActionManager.IsMsfsGameInWindowedMode())
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.WriteMessage("Moving and resizing MSFS game window", StatusMessageType.Info);
|
|
|
|
|
WindowActionManager.SetMsfsGameWindowLocation(ActiveProfile.MsfsGameWindowConfig);
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
|
|
|
|
// Turn on power and avionics if required to pop out panels at least one (fix Cessna 208b grand caravan mod bug where battery is reported as on)
|
|
|
|
|
if (ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
FlightSimOrchestrator.TurnOnPower();
|
|
|
|
|
FlightSimOrchestrator.TurnOnAvionics();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Turn off TrackIR if TrackIR is started
|
|
|
|
|
FlightSimOrchestrator.TurnOffTrackIR();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Turn on Active Pause
|
|
|
|
|
FlightSimOrchestrator.TurnOnActivePause();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Setting custom camera angle for auto panning
|
|
|
|
|
if (AppSetting.PopOutSetting.AutoPanning.IsEnabled)
|
|
|
|
|
{
|
|
|
|
|
StatusMessageWriter.WriteMessage("Setting auto panning camera angle", StatusMessageType.Info);
|
|
|
|
|
InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
|
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task StepCustomPanelPopOut(List<IntPtr> builtInPanelHandles)
|
2022-09-06 04:07:03 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await Task.Run(() =>
|
2022-09-06 04:07:03 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Save current application location to restore it after pop out
|
|
|
|
|
var appLocation = WindowActionManager.GetWindowRectangle(WindowProcessManager.GetApplicationProcess().Handle);
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
int index = 0;
|
|
|
|
|
foreach (var panelConfig in ActiveProfile.PanelConfigs)
|
2022-09-06 04:07:03 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (panelConfig.PanelType == PanelType.CustomPopout)
|
|
|
|
|
{
|
|
|
|
|
StatusMessageWriter.WriteMessage($"Popping out panel '{panelConfig.PanelName}'", StatusMessageType.Info);
|
|
|
|
|
|
|
|
|
|
panelConfig.IsSelectedPanelSource = true;
|
|
|
|
|
//PanelSourceOrchestrator.ShowPanelSourceNonEdit(panelConfig);
|
|
|
|
|
//Thread.Sleep(500);
|
|
|
|
|
//PanelSourceOrchestrator.ClosePanelSourceNonEdit(panelConfig);
|
|
|
|
|
ExecuteCustomPopout(panelConfig, builtInPanelHandles, index++);
|
|
|
|
|
ApplyPanelLocation(panelConfig);
|
|
|
|
|
panelConfig.IsSelectedPanelSource = false;
|
|
|
|
|
|
|
|
|
|
if (panelConfig.IsPopOutSuccess != null && !(bool)panelConfig.IsPopOutSuccess)
|
|
|
|
|
StatusMessageWriter.WriteFailureStatusMessage();
|
|
|
|
|
else
|
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Restore current application location
|
|
|
|
|
WindowActionManager.MoveWindow(WindowProcessManager.GetApplicationProcess().Handle, appLocation);
|
|
|
|
|
});
|
2022-09-06 04:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task StepPostCustomPanelPopOut()
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
await Task.Run(() =>
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart)
|
|
|
|
|
{
|
|
|
|
|
FlightSimOrchestrator.TurnOffAvionics();
|
|
|
|
|
FlightSimOrchestrator.TurnOffPower();
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Turn TrackIR back on
|
|
|
|
|
FlightSimOrchestrator.TurnOnTrackIR();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Turn on Active Pause
|
|
|
|
|
FlightSimOrchestrator.TurnOffActivePause();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Return to custom camera view if set
|
|
|
|
|
var task = Task.Run(() => ReturnToAfterPopOutCameraView());
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private void StepAddBuiltInPanels(List<IntPtr> builtInPanelHandles)
|
|
|
|
|
{
|
|
|
|
|
if (ActiveProfile.ProfileSetting.IncludeInGamePanels)
|
|
|
|
|
{
|
|
|
|
|
var builtInPanels = new List<PanelConfig>();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.WriteMessage("Configuring built-in panel", StatusMessageType.Info);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
foreach (var panelHandle in builtInPanelHandles)
|
|
|
|
|
{
|
|
|
|
|
var panelCaption = WindowActionManager.GetWindowCaption(panelHandle);
|
|
|
|
|
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelName == panelCaption);
|
|
|
|
|
|
|
|
|
|
if (panelConfig == null)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (!ActiveProfile.IsLocked)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
var rectangle = WindowActionManager.GetWindowRectangle(panelHandle);
|
|
|
|
|
panelConfig = new PanelConfig()
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
PanelHandle = panelHandle,
|
|
|
|
|
PanelType = PanelType.BuiltInPopout,
|
|
|
|
|
PanelName = panelCaption,
|
|
|
|
|
Top = rectangle.Top,
|
|
|
|
|
Left = rectangle.Left,
|
|
|
|
|
Width = rectangle.Width,
|
|
|
|
|
Height = rectangle.Height,
|
|
|
|
|
AutoGameRefocus = false
|
2022-07-23 19:23:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
ActiveProfile.PanelConfigs.Add(panelConfig);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
panelConfig.PanelHandle = panelHandle;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Need to do it twice for MSFS to take this setting (MSFS bug)
|
|
|
|
|
ApplyPanelLocation(panelConfig);
|
|
|
|
|
ApplyPanelLocation(panelConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Set handles for missing built-in panels
|
|
|
|
|
foreach (var panelConfig in ActiveProfile.PanelConfigs)
|
|
|
|
|
{
|
|
|
|
|
if (panelConfig.PanelType == PanelType.BuiltInPopout && panelConfig.PanelHandle == IntPtr.MaxValue)
|
|
|
|
|
panelConfig.PanelHandle = IntPtr.Zero;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.BuiltInPopout && p.IsPopOutSuccess != null && !(bool)p.IsPopOutSuccess) ||
|
|
|
|
|
ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.BuiltInPopout) == 0)
|
|
|
|
|
StatusMessageWriter.WriteFailureStatusMessage();
|
|
|
|
|
else
|
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private void StepAddHudBar()
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (!ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StatusMessageWriter.WriteMessage("Opening HUD Bar", StatusMessageType.Info);
|
|
|
|
|
|
|
|
|
|
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.HudBarWindow);
|
2022-09-11 13:50:04 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
OnHudBarOpened?.Invoke(this, panelConfig);
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-23 05:13:23 +00:00
|
|
|
|
public void SetupRefocusDisplay()
|
|
|
|
|
{
|
|
|
|
|
if (!ActiveProfile.ProfileSetting.RefocusOnDisplay.IsEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.RefocusDisplay);
|
|
|
|
|
if (panelConfig != null)
|
|
|
|
|
{
|
|
|
|
|
StatusMessageWriter.WriteMessage($"Configurating {panelConfig.PanelName} for auto refocus on touch", StatusMessageType.Info);
|
|
|
|
|
panelConfig.PanelHandle = new IntPtr(1);
|
|
|
|
|
StatusMessageWriter.WriteOkStatusMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private void StepApplyPanelConfig()
|
|
|
|
|
{
|
|
|
|
|
// Must apply other panel config after pop out since MSFS popping out action will overwrite panel config such as Always on Top
|
|
|
|
|
foreach (var panelConfig in ActiveProfile.PanelConfigs)
|
|
|
|
|
{
|
|
|
|
|
ApplyPanelConfig(panelConfig);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Set title bar color
|
|
|
|
|
if (_appSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.IsEnabled && !panelConfig.FullScreen)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
WindowActionManager.SetWindowTitleBarColor(panelConfig.PanelHandle, _appSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.HexColor);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private async Task StepPostPopout()
|
|
|
|
|
{
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
// Set profile pop out status
|
|
|
|
|
ActiveProfile.IsPoppedOut = true;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Must use application dispatcher to dispatch UI events (winEventHook)
|
|
|
|
|
PanelConfigurationOrchestrator.StartConfiguration();
|
2022-09-06 04:07:03 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Start touch hook
|
|
|
|
|
PanelConfigurationOrchestrator.StartTouchHook();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (CheckForPopOutError())
|
|
|
|
|
StatusMessageWriter.WriteMessageNewLine("Pop out has been completed with error.", StatusMessageType.Info, 10);
|
|
|
|
|
else
|
|
|
|
|
StatusMessageWriter.WriteMessageNewLine("Pop out has been completed successfully.", StatusMessageType.Info, 10);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
OnPopOutCompleted?.Invoke(this, null);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
});
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
private void ExecuteCustomPopout(PanelConfig panel, List<IntPtr> builtInPanelHandles, int index)
|
|
|
|
|
{
|
|
|
|
|
if (panel.PanelType == PanelType.CustomPopout)
|
2022-09-11 13:50:04 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// There should only be one handle that is not in both builtInPanelHandles vs latestAceAppWindowsWithCaptionHandles
|
|
|
|
|
var handle = TryPopOutCustomPanel(panel.PanelSource, builtInPanelHandles);
|
2022-10-16 13:11:01 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (handle == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
panel.PanelHandle = IntPtr.Zero;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-11 13:50:04 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Unable to pop out panel, the handle was previously popped out's handle
|
|
|
|
|
if (_profileData.ActiveProfile.PanelConfigs.Any(p => p.PanelHandle.Equals(handle)) || handle.Equals(WindowProcessManager.SimulatorProcess.Handle) || handle == IntPtr.Zero)
|
2022-09-11 13:50:04 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
panel.PanelHandle = IntPtr.Zero;
|
|
|
|
|
return;
|
2022-10-16 13:11:01 +00:00
|
|
|
|
}
|
2022-09-11 13:50:04 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
panel.PanelHandle = handle;
|
|
|
|
|
WindowActionManager.SetWindowCaption(panel.PanelHandle, $"{panel.PanelName} (Custom)");
|
|
|
|
|
|
|
|
|
|
// First time popping out
|
|
|
|
|
if (panel.Width == 0 && panel.Height == 0)
|
2022-10-16 13:11:01 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
var rect = WindowActionManager.GetWindowRectangle(panel.PanelHandle);
|
|
|
|
|
panel.Top = 0 + index * 30;
|
|
|
|
|
panel.Left = 0 + index * 30;
|
|
|
|
|
panel.Width = rect.Width;
|
|
|
|
|
panel.Height = rect.Height;
|
2022-10-16 13:11:01 +00:00
|
|
|
|
}
|
2022-09-11 13:50:04 +00:00
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IntPtr TryPopOutCustomPanel(PanelSource panelSource, List<IntPtr> builtInPanelHandles)
|
|
|
|
|
{
|
|
|
|
|
// Try to pop out 5 times before failure with 1/4 second wait in between
|
|
|
|
|
int count = 0;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
InputEmulationManager.PopOutPanel((int)panelSource.X, (int)panelSource.Y, AppSetting.PopOutSetting.UseLeftRightControlToPopOut);
|
|
|
|
|
|
|
|
|
|
var latestAceAppWindowsWithCaptionHandles = WindowActionManager.GetWindowsByPanelType(new List<PanelType>() { PanelType.BuiltInPopout });
|
|
|
|
|
|
|
|
|
|
// There should only be one handle that is not in both builtInPanelHandles vs latestAceAppWindowsWithCaptionHandles
|
|
|
|
|
var handle = latestAceAppWindowsWithCaptionHandles.Except(builtInPanelHandles).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (handle != IntPtr.Zero)
|
|
|
|
|
return handle;
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(250);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
while (count < 5);
|
|
|
|
|
|
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ApplyPanelLocation(PanelConfig panel)
|
|
|
|
|
{
|
|
|
|
|
if (panel.IsPopOutSuccess == null || !((bool)panel.IsPopOutSuccess) || panel.PanelHandle == IntPtr.Zero)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Apply top/left/width/height
|
|
|
|
|
WindowActionManager.MoveWindow(panel.PanelHandle, panel.Left, panel.Top, panel.Width, panel.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ApplyPanelConfig(PanelConfig panel)
|
|
|
|
|
{
|
|
|
|
|
if (panel.IsPopOutSuccess == null || !((bool)panel.IsPopOutSuccess) || panel.PanelHandle == IntPtr.Zero)
|
|
|
|
|
return;
|
2022-09-11 13:50:04 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (!panel.FullScreen)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Apply always on top
|
|
|
|
|
if (panel.AlwaysOnTop)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
WindowActionManager.ApplyAlwaysOnTop(panel.PanelHandle, panel.PanelType, panel.AlwaysOnTop);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
Thread.Sleep(250);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
2022-09-11 13:50:04 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
// Apply hide title bar
|
|
|
|
|
if (panel.HideTitlebar)
|
|
|
|
|
{
|
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panel.PanelHandle, true);
|
|
|
|
|
Thread.Sleep(250);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (panel.FullScreen && !panel.AlwaysOnTop && !panel.HideTitlebar)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
InputEmulationManager.ToggleFullScreenPanel(panel.PanelHandle);
|
|
|
|
|
Thread.Sleep(250);
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReturnToAfterPopOutCameraView()
|
|
|
|
|
{
|
2023-07-12 22:41:31 +00:00
|
|
|
|
if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
{
|
|
|
|
|
case AfterPopOutCameraViewType.CockpitCenterView:
|
|
|
|
|
InputEmulationManager.CenterView();
|
|
|
|
|
break;
|
|
|
|
|
case AfterPopOutCameraViewType.CustomCameraView:
|
2023-07-12 22:41:31 +00:00
|
|
|
|
InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
|
|
|
|
private bool CheckForPopOutError()
|
|
|
|
|
{
|
|
|
|
|
return ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null && (bool)p.IsPopOutSuccess) != ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null);
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|