1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-21 21:30:12 +00:00

Update camera view logic

This commit is contained in:
hawkeye 2023-08-15 23:41:14 -04:00
parent 079e040ce7
commit 324b7a051b
13 changed files with 327 additions and 207 deletions

View file

@ -46,6 +46,9 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel
case StatusMessageType.Failure: case StatusMessageType.Failure:
run.Foreground = new SolidColorBrush(Colors.IndianRed); run.Foreground = new SolidColorBrush(Colors.IndianRed);
break; break;
case StatusMessageType.Executing:
run.Foreground = new SolidColorBrush(Colors.Yellow);
break;
case StatusMessageType.Info: case StatusMessageType.Info:
break; break;
} }

View file

@ -58,7 +58,7 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel
if (AppSettingData.ApplicationSetting.PopOutSetting.EnablePopOutMessages) if (AppSettingData.ApplicationSetting.PopOutSetting.EnablePopOutMessages)
{ {
WindowActionManager.ApplyAlwaysOnTop(Handle, PanelType.StatusMessageWindow, true); WindowActionManager.ApplyAlwaysOnTop(Handle, PanelType.StatusMessageWindow, true);
OnMessageUpdated?.Invoke(this, FormatStatusMessages(e.Messages)); OnMessageUpdated?.Invoke(this, FormatStatusMessages(e));
CenterDialogToGameWindow(); CenterDialogToGameWindow();
} }

View file

@ -114,7 +114,7 @@ namespace MSFSPopoutPanelManager.Orchestration
_simConnectProvider = null; _simConnectProvider = null;
} }
public void TurnOnTrackIR(bool writeMessage = true) public void TurnOnTrackIR()
{ {
if (_simConnectProvider == null) if (_simConnectProvider == null)
return; return;
@ -122,8 +122,8 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!_appSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR) if (!_appSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR)
return; return;
StatusMessageWriter.WriteMessage("Turning on TrackIR", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning on TrackIR", () =>
{
int count = 0; int count = 0;
do do
{ {
@ -133,13 +133,11 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
while (!_flightSimData.TrackIRStatus && count < 5); while (!_flightSimData.TrackIRStatus && count < 5);
if (_flightSimData.TrackIRStatus) return _flightSimData.TrackIRStatus;
StatusMessageWriter.WriteOkStatusMessage(); });
else
StatusMessageWriter.WriteFailureStatusMessage();
} }
public void TurnOffTrackIR(bool writeMessage = true) public void TurnOffTrackIR()
{ {
if (_simConnectProvider == null) if (_simConnectProvider == null)
return; return;
@ -147,8 +145,8 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!_appSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR) if (!_appSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR)
return; return;
StatusMessageWriter.WriteMessage("Turning off TrackIR", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning off TrackIR", () =>
{
int count = 0; int count = 0;
do do
{ {
@ -158,13 +156,8 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
while (_flightSimData.TrackIRStatus && count < 5); while (_flightSimData.TrackIRStatus && count < 5);
if (!writeMessage) return !_flightSimData.TrackIRStatus;
return; });
if (!_flightSimData.TrackIRStatus)
StatusMessageWriter.WriteOkStatusMessage();
else
StatusMessageWriter.WriteFailureStatusMessage();
} }
public void TurnOnPower() public void TurnOnPower()
@ -176,8 +169,9 @@ namespace MSFSPopoutPanelManager.Orchestration
return; return;
_isTurnedOnPower = true; _isTurnedOnPower = true;
StatusMessageWriter.WriteMessage("Turning on battery", StatusMessageType.Info);
WorkflowStepWithMessage.Execute("Turning on battery", () =>
{
int count = 0; int count = 0;
do do
{ {
@ -187,10 +181,8 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
while (!_flightSimData.ElectricalMasterBatteryStatus && count < 10); while (!_flightSimData.ElectricalMasterBatteryStatus && count < 10);
if (_flightSimData.ElectricalMasterBatteryStatus) return _flightSimData.ElectricalMasterBatteryStatus;
StatusMessageWriter.WriteOkStatusMessage(); });
else
StatusMessageWriter.WriteFailureStatusMessage();
} }
public void TurnOffPower() public void TurnOffPower()
@ -201,8 +193,8 @@ namespace MSFSPopoutPanelManager.Orchestration
if (_profileData.ActiveProfile == null || !_isTurnedOnPower) if (_profileData.ActiveProfile == null || !_isTurnedOnPower)
return; return;
StatusMessageWriter.WriteMessage("Turning off battery", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning off battery", () =>
{
int count = 0; int count = 0;
do do
{ {
@ -212,10 +204,8 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
while (_flightSimData.ElectricalMasterBatteryStatus && count < 10); while (_flightSimData.ElectricalMasterBatteryStatus && count < 10);
if (!_flightSimData.ElectricalMasterBatteryStatus) return !_flightSimData.ElectricalMasterBatteryStatus;
StatusMessageWriter.WriteOkStatusMessage(); });
else
StatusMessageWriter.WriteFailureStatusMessage();
_isTurnedOnPower = false; _isTurnedOnPower = false;
} }
@ -230,8 +220,8 @@ namespace MSFSPopoutPanelManager.Orchestration
_isTurnedOnAvionics = true; _isTurnedOnAvionics = true;
StatusMessageWriter.WriteMessage("Turning on avionics", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning on avionics", () =>
{
int count = 0; int count = 0;
do do
{ {
@ -241,10 +231,8 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
while (!_flightSimData.AvionicsMasterSwitchStatus && count < 10); while (!_flightSimData.AvionicsMasterSwitchStatus && count < 10);
if (_flightSimData.AvionicsMasterSwitchStatus) return _flightSimData.AvionicsMasterSwitchStatus;
StatusMessageWriter.WriteOkStatusMessage(); });
else
StatusMessageWriter.WriteFailureStatusMessage();
} }
public void TurnOffAvionics() public void TurnOffAvionics()
@ -255,8 +243,8 @@ namespace MSFSPopoutPanelManager.Orchestration
if (_profileData.ActiveProfile == null || !_isTurnedOnAvionics) if (_profileData.ActiveProfile == null || !_isTurnedOnAvionics)
return; return;
StatusMessageWriter.WriteMessage("Turning off avionics", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning off avionics", () =>
{
int count = 0; int count = 0;
do do
{ {
@ -266,10 +254,8 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
while (_flightSimData.AvionicsMasterSwitchStatus && count < 10); while (_flightSimData.AvionicsMasterSwitchStatus && count < 10);
if (!_flightSimData.AvionicsMasterSwitchStatus) return !_flightSimData.AvionicsMasterSwitchStatus;
StatusMessageWriter.WriteOkStatusMessage(); });
else
StatusMessageWriter.WriteFailureStatusMessage();
_isTurnedOnAvionics = false; _isTurnedOnAvionics = false;
} }
@ -282,9 +268,10 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!_appSettingData.ApplicationSetting.PopOutSetting.AutoActivePause) if (!_appSettingData.ApplicationSetting.PopOutSetting.AutoActivePause)
return; return;
StatusMessageWriter.WriteMessage("Turning on active pause", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning on active pause", () =>
{
_simConnectProvider.TurnOnActivePause(); _simConnectProvider.TurnOnActivePause();
StatusMessageWriter.WriteOkStatusMessage(); });
} }
public void TurnOffActivePause() public void TurnOffActivePause()
@ -295,10 +282,10 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!_appSettingData.ApplicationSetting.PopOutSetting.AutoActivePause) if (!_appSettingData.ApplicationSetting.PopOutSetting.AutoActivePause)
return; return;
StatusMessageWriter.WriteMessage("Turning off active pause", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Turning off active pause", () =>
{
_simConnectProvider.TurnOffActivePause(); _simConnectProvider.TurnOffActivePause();
StatusMessageWriter.WriteOkStatusMessage(); });
} }
public void IncreaseSimRate() public void IncreaseSimRate()
@ -328,6 +315,11 @@ namespace MSFSPopoutPanelManager.Orchestration
_simConnectProvider.SetCockpitCameraZoomLevel(zoomLevel); _simConnectProvider.SetCockpitCameraZoomLevel(zoomLevel);
} }
public void ResetCameraView()
{
_simConnectProvider.SetCameraRequestAction(1);
}
public void SetHudBarConfig() public void SetHudBarConfig()
{ {
if (_simConnectProvider == null) if (_simConnectProvider == null)

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.Orchestration namespace MSFSPopoutPanelManager.Orchestration
{ {
@ -86,7 +87,7 @@ namespace MSFSPopoutPanelManager.Orchestration
StatusMessageWriter.IsEnabled = true; StatusMessageWriter.IsEnabled = true;
StatusMessageWriter.ClearMessage(); StatusMessageWriter.ClearMessage();
StatusMessageWriter.WriteMessageNewLine("Pop out in progress. Please refrain from moving your mouse.", StatusMessageType.Info); StatusMessageWriter.WriteMessageWithNewLine("Pop out in progress. Please refrain from moving your mouse.", StatusMessageType.Info);
StepPopoutPrep(); StepPopoutPrep();
@ -141,10 +142,11 @@ namespace MSFSPopoutPanelManager.Orchestration
// Set Windowed Display Mode window's configuration if needed // Set Windowed Display Mode window's configuration if needed
if (_appSettingData.ApplicationSetting.WindowedModeSetting.AutoResizeMsfsGameWindow && WindowActionManager.IsMsfsGameInWindowedMode()) if (_appSettingData.ApplicationSetting.WindowedModeSetting.AutoResizeMsfsGameWindow && WindowActionManager.IsMsfsGameInWindowedMode())
{ {
StatusMessageWriter.WriteMessage("Moving and resizing MSFS game window", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Moving and resizing MSFS game window", () =>
{
WindowActionManager.SetMsfsGameWindowLocation(ActiveProfile.MsfsGameWindowConfig); WindowActionManager.SetMsfsGameWindowLocation(ActiveProfile.MsfsGameWindowConfig);
Thread.Sleep(500); Thread.Sleep(1000);
StatusMessageWriter.WriteOkStatusMessage(); });
} }
// 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) // 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)
@ -163,13 +165,28 @@ namespace MSFSPopoutPanelManager.Orchestration
// Setting custom camera angle for auto panning // Setting custom camera angle for auto panning
if (AppSetting.PopOutSetting.AutoPanning.IsEnabled) if (AppSetting.PopOutSetting.AutoPanning.IsEnabled)
{ {
StatusMessageWriter.WriteMessage("Setting auto panning camera angle", StatusMessageType.Info); StatusMessageWriter.WriteMessageWithNewLine("Setting auto panning camera view", StatusMessageType.Info);
// Remember current game's zoom level to be recall after pop out // Remember current game's zoom level to be recall after pop out
_prePopOutCockpitZoomLevel = _flightSimData.CockpitCameraZoom; _prePopOutCockpitZoomLevel = _flightSimData.CockpitCameraZoom;
WorkflowStepWithMessage.Execute("Resetting camera view", () =>
{
ResetCockpitView();
Thread.Sleep(2000);
}, true);
WorkflowStepWithMessage.Execute("Loading custom camera view", () =>
{
LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
Thread.Sleep(2000);
}, true);
WorkflowStepWithMessage.Execute("Setting camera zoom level", () =>
{
SetCockpitZoomLevel(50); SetCockpitZoomLevel(50);
StatusMessageWriter.WriteOkStatusMessage(); }, true);
} }
}); });
} }
@ -181,13 +198,16 @@ namespace MSFSPopoutPanelManager.Orchestration
// Save current application location to restore it after pop out // Save current application location to restore it after pop out
var appLocation = WindowActionManager.GetWindowRectangle(WindowProcessManager.GetApplicationProcess().Handle); var appLocation = WindowActionManager.GetWindowRectangle(WindowProcessManager.GetApplicationProcess().Handle);
if(ActiveProfile.PanelConfigs.Count > 0)
StatusMessageWriter.WriteMessageWithNewLine("Popping out user defined panels", StatusMessageType.Info);
int index = 0; int index = 0;
foreach (var panelConfig in ActiveProfile.PanelConfigs) foreach (var panelConfig in ActiveProfile.PanelConfigs)
{ {
if (panelConfig.PanelType == PanelType.CustomPopout) if (panelConfig.PanelType == PanelType.CustomPopout)
{ {
StatusMessageWriter.WriteMessage($"Popping out panel '{panelConfig.PanelName}'", StatusMessageType.Info); WorkflowStepWithMessage.Execute(panelConfig.PanelName, () =>
{
panelConfig.IsSelectedPanelSource = true; panelConfig.IsSelectedPanelSource = true;
//PanelSourceOrchestrator.ShowPanelSourceNonEdit(panelConfig); //PanelSourceOrchestrator.ShowPanelSourceNonEdit(panelConfig);
//Thread.Sleep(500); //Thread.Sleep(500);
@ -197,9 +217,10 @@ namespace MSFSPopoutPanelManager.Orchestration
panelConfig.IsSelectedPanelSource = false; panelConfig.IsSelectedPanelSource = false;
if (panelConfig.IsPopOutSuccess != null && !(bool)panelConfig.IsPopOutSuccess) if (panelConfig.IsPopOutSuccess != null && !(bool)panelConfig.IsPopOutSuccess)
StatusMessageWriter.WriteFailureStatusMessage(); return false;
else else
StatusMessageWriter.WriteOkStatusMessage(); return true;
}, true);
} }
} }
@ -225,20 +246,23 @@ namespace MSFSPopoutPanelManager.Orchestration
FlightSimOrchestrator.TurnOffActivePause(); FlightSimOrchestrator.TurnOffActivePause();
// Return to custom camera view if set // Return to custom camera view if set
var task = Task.Run(() => {
//SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
ReturnToAfterPopOutCameraView(); ReturnToAfterPopOutCameraView();
}); });
});
} }
private void StepAddBuiltInPanels(List<IntPtr> builtInPanelHandles) private void StepAddBuiltInPanels(List<IntPtr> builtInPanelHandles)
{ {
if (ActiveProfile.ProfileSetting.IncludeInGamePanels) if (ActiveProfile.ProfileSetting.IncludeInGamePanels)
{ {
var builtInPanels = new List<PanelConfig>(); WorkflowStepWithMessage.Execute("Configuring built-in panel", () =>
{
int count = 0;
while (builtInPanelHandles.Count == 0 && count < 5)
{
builtInPanelHandles = WindowActionManager.GetWindowsByPanelType(new List<PanelType>() { PanelType.BuiltInPopout });
}
StatusMessageWriter.WriteMessage("Configuring built-in panel", StatusMessageType.Info); var builtInPanels = new List<PanelConfig>();
foreach (var panelHandle in builtInPanelHandles) foreach (var panelHandle in builtInPanelHandles)
{ {
@ -284,9 +308,10 @@ namespace MSFSPopoutPanelManager.Orchestration
if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.BuiltInPopout && p.IsPopOutSuccess != null && !(bool)p.IsPopOutSuccess) || if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.BuiltInPopout && p.IsPopOutSuccess != null && !(bool)p.IsPopOutSuccess) ||
ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.BuiltInPopout) == 0) ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.BuiltInPopout) == 0)
StatusMessageWriter.WriteFailureStatusMessage(); return false;
else else
StatusMessageWriter.WriteOkStatusMessage(); return true;
});
} }
} }
@ -295,13 +320,11 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled) if (!ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled)
return; return;
StatusMessageWriter.WriteMessage("Opening HUD Bar", StatusMessageType.Info); WorkflowStepWithMessage.Execute("Opening HUD Bar", () =>
{
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.HudBarWindow); var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.HudBarWindow);
OnHudBarOpened?.Invoke(this, panelConfig); OnHudBarOpened?.Invoke(this, panelConfig);
});
StatusMessageWriter.WriteOkStatusMessage();
} }
public void SetupRefocusDisplay() public void SetupRefocusDisplay()
@ -309,13 +332,21 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!ActiveProfile.ProfileSetting.RefocusOnDisplay.IsEnabled) if (!ActiveProfile.ProfileSetting.RefocusOnDisplay.IsEnabled)
return; return;
foreach (var panelConfig in ActiveProfile.PanelConfigs.Where(p => p.PanelType == PanelType.RefocusDisplay)) var panelConfigs = ActiveProfile.PanelConfigs.Where(p => p.PanelType == PanelType.RefocusDisplay);
if (panelConfigs.Count() == 0)
return;
StatusMessageWriter.WriteMessageWithNewLine("Configurating panels for auto refocus on touch", StatusMessageType.Info);
foreach (var panelConfig in panelConfigs)
{ {
if (panelConfig != null) if (panelConfig != null)
{ {
StatusMessageWriter.WriteMessage($"Configurating {panelConfig.PanelName} for auto refocus on touch", StatusMessageType.Info); WorkflowStepWithMessage.Execute(panelConfig.PanelName, () =>
{
panelConfig.PanelHandle = new IntPtr(1); panelConfig.PanelHandle = new IntPtr(1);
StatusMessageWriter.WriteOkStatusMessage(); }, true);
} }
} }
} }
@ -349,9 +380,9 @@ namespace MSFSPopoutPanelManager.Orchestration
PanelConfigurationOrchestrator.StartTouchHook(); PanelConfigurationOrchestrator.StartTouchHook();
if (CheckForPopOutError()) if (CheckForPopOutError())
StatusMessageWriter.WriteMessageNewLine("Pop out has been completed with error.", StatusMessageType.Info, 10); StatusMessageWriter.WriteMessageWithNewLine("Pop out has been completed with error.", StatusMessageType.Info);
else else
StatusMessageWriter.WriteMessageNewLine("Pop out has been completed successfully.", StatusMessageType.Info, 10); StatusMessageWriter.WriteMessageWithNewLine("Pop out has been completed successfully.", StatusMessageType.Info);
Thread.Sleep(1000); Thread.Sleep(1000);
OnPopOutCompleted?.Invoke(this, null); OnPopOutCompleted?.Invoke(this, null);
@ -461,15 +492,41 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled) if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled)
return; return;
StatusMessageWriter.WriteMessageWithNewLine("Applying cockpit view after pop out", StatusMessageType.Info);
switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView) switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView)
{ {
case AfterPopOutCameraViewType.CockpitCenterView: case AfterPopOutCameraViewType.CockpitCenterView:
InputEmulationManager.CenterView(); WorkflowStepWithMessage.Execute("Resetting camera view", () =>
{
ResetCockpitView();
Thread.Sleep(1000);
}, true);
WorkflowStepWithMessage.Execute("Setting camera zoom level", () =>
{
SetCockpitZoomLevel(_prePopOutCockpitZoomLevel); SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
}, true);
break; break;
case AfterPopOutCameraViewType.CustomCameraView: case AfterPopOutCameraViewType.CustomCameraView:
WorkflowStepWithMessage.Execute("Resetting camera view", () =>
{
ResetCockpitView();
Thread.Sleep(1000);
}, true);
WorkflowStepWithMessage.Execute("Loading custom camera view", () =>
{
LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding);
Thread.Sleep(1000);
}, true);
WorkflowStepWithMessage.Execute("Setting camera zoom level", () =>
{
SetCockpitZoomLevel(_prePopOutCockpitZoomLevel); SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
}, true);
break; break;
} }
} }
@ -479,13 +536,25 @@ namespace MSFSPopoutPanelManager.Orchestration
return ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null && (bool)p.IsPopOutSuccess) != ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null); return ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null && (bool)p.IsPopOutSuccess) != ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null);
} }
private void ResetCockpitView()
{
int retry = 10;
for (var i = 0; i < retry; i++)
{
FlightSimOrchestrator.ResetCameraView();
Thread.Sleep(1000); // wait for flightsimdata to be updated
if (_flightSimData.CameraViewTypeAndIndex1 == 0) // 0 = reset view
break;
}
}
private void LoadCustomView(string keybinding) private void LoadCustomView(string keybinding)
{ {
int retry = 20; int retry = 20;
for(var i = 0; i < retry; i++) for(var i = 0; i < retry; i++)
{ {
InputEmulationManager.LoadCustomView(keybinding); InputEmulationManager.LoadCustomView(keybinding);
Thread.Sleep(750); // wait for flightsimdata to be updated Thread.Sleep(1000); // wait for flightsimdata to be updated
if (_flightSimData.CameraViewTypeAndIndex1 == 7) // 7 = custom camera view enum if (_flightSimData.CameraViewTypeAndIndex1 == 7) // 7 = custom camera view enum
break; break;
} }
@ -497,7 +566,7 @@ namespace MSFSPopoutPanelManager.Orchestration
for (var i = 0; i < retry; i++) for (var i = 0; i < retry; i++)
{ {
FlightSimOrchestrator.SetCockpitCameraZoomLevel(zoom); FlightSimOrchestrator.SetCockpitCameraZoomLevel(zoom);
Thread.Sleep(500); // wait for flightsimdata to be updated Thread.Sleep(1000); // wait for flightsimdata to be updated
if (_flightSimData.CockpitCameraZoom == zoom) if (_flightSimData.CockpitCameraZoom == zoom)
break; break;

View file

@ -75,7 +75,7 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
// Turn off TrackIR if TrackIR is started // Turn off TrackIR if TrackIR is started
FlightSimOrchestrator.TurnOffTrackIR(false); FlightSimOrchestrator.TurnOffTrackIR();
} }
public async Task EndEditPanelSources() public async Task EndEditPanelSources()
@ -88,19 +88,22 @@ namespace MSFSPopoutPanelManager.Orchestration
// Save last auto panning camera angle // Save last auto panning camera angle
if (AppSetting.PopOutSetting.AutoPanning.IsEnabled) if (AppSetting.PopOutSetting.AutoPanning.IsEnabled)
{ {
InputEmulationManager.SaveCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
// If using windows mode, save MSFS game window configuration // If using windows mode, save MSFS game window configuration
if (_appSettingData.ApplicationSetting.WindowedModeSetting.AutoResizeMsfsGameWindow) if (_appSettingData.ApplicationSetting.WindowedModeSetting.AutoResizeMsfsGameWindow)
_profileData.SaveMsfsGameWindowConfig(); _profileData.SaveMsfsGameWindowConfig();
InputEmulationManager.SaveCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
} }
await Task.Run(() => await Task.Run(() =>
{ {
Thread.Sleep(500); // wait for custom view save to be completed
// Recenter game or return to after pop out camera view // Recenter game or return to after pop out camera view
if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled) if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled)
{ {
InputEmulationManager.CenterView(); FlightSimOrchestrator.ResetCameraView();
Thread.Sleep(500);
SetCockpitZoomLevel(_prePanelConfigurationCockpitZoomLevel); SetCockpitZoomLevel(_prePanelConfigurationCockpitZoomLevel);
} }
else else
@ -108,7 +111,8 @@ namespace MSFSPopoutPanelManager.Orchestration
switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView) switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView)
{ {
case AfterPopOutCameraViewType.CockpitCenterView: case AfterPopOutCameraViewType.CockpitCenterView:
InputEmulationManager.CenterView(); FlightSimOrchestrator.ResetCameraView();
Thread.Sleep(500);
SetCockpitZoomLevel(_prePanelConfigurationCockpitZoomLevel); SetCockpitZoomLevel(_prePanelConfigurationCockpitZoomLevel);
break; break;
case AfterPopOutCameraViewType.CustomCameraView: case AfterPopOutCameraViewType.CustomCameraView:
@ -121,7 +125,7 @@ namespace MSFSPopoutPanelManager.Orchestration
WindowActionManager.BringWindowToForeground(ApplicationHandle); WindowActionManager.BringWindowToForeground(ApplicationHandle);
// Turn TrackIR back on // Turn TrackIR back on
FlightSimOrchestrator.TurnOnTrackIR(false); FlightSimOrchestrator.TurnOnTrackIR();
}); });
} }

View file

@ -8,20 +8,9 @@ namespace MSFSPopoutPanelManager.Shared
public StatusMessageEventArg(List<StatusMessage> messages) public StatusMessageEventArg(List<StatusMessage> messages)
{ {
Messages = messages; Messages = messages;
Duration = -1;
}
public StatusMessageEventArg(List<StatusMessage> messages, int duration)
{
Messages = messages;
Duration = duration;
} }
public List<StatusMessage> Messages { get; set; } public List<StatusMessage> Messages { get; set; }
public StatusMessageType StatusMessageType { get; set; }
public int Duration { get; set; }
} }
public class StatusMessage public class StatusMessage

View file

@ -5,6 +5,7 @@
Info, Info,
Success, Success,
Failure, Failure,
Executing,
Error, Error,
Debug Debug
} }

View file

@ -7,44 +7,57 @@ namespace MSFSPopoutPanelManager.Shared
{ {
private static List<StatusMessage> _messages = new List<StatusMessage>(); private static List<StatusMessage> _messages = new List<StatusMessage>();
public static event EventHandler<StatusMessageEventArg> OnStatusMessage; public static event EventHandler<List<StatusMessage>> OnStatusMessage;
public static void WriteMessage(string message, StatusMessageType statusMessageType, int duration = -1) public static void WriteMessage(string message, StatusMessageType statusMessageType)
{ {
_messages.Add(new StatusMessage { Message = message, StatusMessageType = statusMessageType, NewLine = false }); _messages.Add(new StatusMessage { Message = message, StatusMessageType = statusMessageType });
if (IsEnabled) if (IsEnabled)
OnStatusMessage?.Invoke(null, new StatusMessageEventArg(_messages, duration)); OnStatusMessage?.Invoke(null, _messages);
} }
public static void WriteMessageNewLine(string message, StatusMessageType statusMessageType, int duration = -1) public static void WriteMessageWithNewLine(string message, StatusMessageType statusMessageType)
{ {
_messages.Add(new StatusMessage { Message = message, StatusMessageType = statusMessageType, NewLine = true }); _messages.Add(new StatusMessage { Message = message, StatusMessageType = statusMessageType, NewLine = true });
if (IsEnabled) if (IsEnabled)
OnStatusMessage?.Invoke(null, new StatusMessageEventArg(_messages, duration)); OnStatusMessage?.Invoke(null, _messages);
} }
public static void WriteOkStatusMessage(int duration = -1) public static void WriteExecutingStatusMessage()
{
_messages.Add(new StatusMessage { Message = " (Executing)", StatusMessageType = StatusMessageType.Executing, NewLine = false });
if (IsEnabled)
OnStatusMessage?.Invoke(null, _messages);
}
public static void WriteOkStatusMessage()
{ {
_messages.Add(new StatusMessage { Message = " (OK)", StatusMessageType = StatusMessageType.Success, NewLine = true }); _messages.Add(new StatusMessage { Message = " (OK)", StatusMessageType = StatusMessageType.Success, NewLine = true });
if (IsEnabled) if (IsEnabled)
OnStatusMessage?.Invoke(null, new StatusMessageEventArg(_messages, duration)); OnStatusMessage?.Invoke(null, _messages);
} }
public static void WriteFailureStatusMessage(int duration = -1) public static void WriteFailureStatusMessage()
{ {
_messages.Add(new StatusMessage { Message = " (FAILED)", StatusMessageType = StatusMessageType.Failure, NewLine = true }); _messages.Add(new StatusMessage { Message = " (FAILED)", StatusMessageType = StatusMessageType.Failure, NewLine = true });
if (IsEnabled) if (IsEnabled)
OnStatusMessage?.Invoke(null, new StatusMessageEventArg(_messages, duration)); OnStatusMessage?.Invoke(null, _messages);
}
public static void RemoveLastMessage()
{
_messages.RemoveAt(_messages.Count - 1);
} }
public static void ClearMessage() public static void ClearMessage()
{ {
_messages.Clear(); _messages.Clear();
OnStatusMessage?.Invoke(null, new StatusMessageEventArg(new List<StatusMessage>())); OnStatusMessage?.Invoke(null, new List<StatusMessage>());
} }
public static bool IsEnabled { get; set; } public static bool IsEnabled { get; set; }

View file

@ -0,0 +1,38 @@
using System;
namespace MSFSPopoutPanelManager.Shared
{
public static class WorkflowStepWithMessage
{
public static void Execute(string message, Func<bool> function, bool isSubTask = false)
{
if (isSubTask)
message = " " + message;
StatusMessageWriter.WriteMessage(message, StatusMessageType.Info);
StatusMessageWriter.WriteExecutingStatusMessage();
var result = function.Invoke();
StatusMessageWriter.RemoveLastMessage();
if (result)
StatusMessageWriter.WriteOkStatusMessage();
else
StatusMessageWriter.WriteFailureStatusMessage();
}
public static void Execute(string message, Action function, bool isSubTask = false)
{
if (isSubTask)
message = " " + message;
StatusMessageWriter.WriteMessage(message, StatusMessageType.Info);
StatusMessageWriter.WriteExecutingStatusMessage();
function.Invoke();
StatusMessageWriter.RemoveLastMessage();
StatusMessageWriter.WriteOkStatusMessage();
}
}
}

View file

@ -6,6 +6,7 @@
HUDBAR_DEFINITION, HUDBAR_DEFINITION,
WRITEABLE_TRACKIR_DEFINITION, WRITEABLE_TRACKIR_DEFINITION,
WRITEABLE_COCKPITCAMERAZOOM_DEFINITION, WRITEABLE_COCKPITCAMERAZOOM_DEFINITION,
WRITEABLE_CAMERAREQUESTACTION_DEFINITION,
NA NA
} }

View file

@ -236,6 +236,11 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
_simConnector.SetDataObject(WriteableVariableName.CockpitCameraZoom, Convert.ToDouble(zoomLevel)); _simConnector.SetDataObject(WriteableVariableName.CockpitCameraZoom, Convert.ToDouble(zoomLevel));
} }
public void SetCameraRequestAction(int actionEnum)
{
_simConnector.SetDataObject(WriteableVariableName.CameraRequestAction, Convert.ToDouble(actionEnum));
}
private void SetTrackIREnable(bool enable) private void SetTrackIREnable(bool enable)
{ {
_simConnector.SetDataObject(WriteableVariableName.TrackIREnable, enable ? Convert.ToDouble(1) : Convert.ToDouble(0)); _simConnector.SetDataObject(WriteableVariableName.TrackIREnable, enable ? Convert.ToDouble(1) : Convert.ToDouble(0));

View file

@ -192,6 +192,9 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
case WriteableVariableName.CockpitCameraZoom: case WriteableVariableName.CockpitCameraZoom:
_simConnect.SetDataOnSimObject(DATA_DEFINITION.WRITEABLE_COCKPITCAMERAZOOM_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct); _simConnect.SetDataOnSimObject(DATA_DEFINITION.WRITEABLE_COCKPITCAMERAZOOM_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
break; break;
case WriteableVariableName.CameraRequestAction:
_simConnect.SetDataOnSimObject(DATA_DEFINITION.WRITEABLE_CAMERAREQUESTACTION_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
break;
} }
} }
catch (Exception ex) catch (Exception ex)
@ -309,6 +312,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
_simConnect.AddToDataDefinition(DATA_DEFINITION.WRITEABLE_TRACKIR_DEFINITION, "TRACK IR ENABLE", "bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.AddToDataDefinition(DATA_DEFINITION.WRITEABLE_TRACKIR_DEFINITION, "TRACK IR ENABLE", "bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.AddToDataDefinition(DATA_DEFINITION.WRITEABLE_COCKPITCAMERAZOOM_DEFINITION, "COCKPIT CAMERA ZOOM", "percentage", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.AddToDataDefinition(DATA_DEFINITION.WRITEABLE_COCKPITCAMERAZOOM_DEFINITION, "COCKPIT CAMERA ZOOM", "percentage", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.AddToDataDefinition(DATA_DEFINITION.WRITEABLE_CAMERAREQUESTACTION_DEFINITION, "CAMERA REQUEST ACTION", "enum", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DATA_DEFINITION.REQUIRED_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DATA_DEFINITION.REQUIRED_DEFINITION);
_simConnect.RegisterDataDefineStruct<SimConnectStruct>(DATA_DEFINITION.WRITEABLE_TRACKIR_DEFINITION); _simConnect.RegisterDataDefineStruct<SimConnectStruct>(DATA_DEFINITION.WRITEABLE_TRACKIR_DEFINITION);

View file

@ -94,7 +94,8 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
public enum WriteableVariableName public enum WriteableVariableName
{ {
TrackIREnable, TrackIREnable,
CockpitCameraZoom CockpitCameraZoom,
CameraRequestAction
} }
} }