1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-21 13:20:11 +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:
run.Foreground = new SolidColorBrush(Colors.IndianRed);
break;
case StatusMessageType.Executing:
run.Foreground = new SolidColorBrush(Colors.Yellow);
break;
case StatusMessageType.Info:
break;
}

View file

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

View file

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

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.Orchestration
{
@ -86,7 +87,7 @@ namespace MSFSPopoutPanelManager.Orchestration
StatusMessageWriter.IsEnabled = true;
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();
@ -141,10 +142,11 @@ namespace MSFSPopoutPanelManager.Orchestration
// Set Windowed Display Mode window's configuration if needed
if (_appSettingData.ApplicationSetting.WindowedModeSetting.AutoResizeMsfsGameWindow && WindowActionManager.IsMsfsGameInWindowedMode())
{
StatusMessageWriter.WriteMessage("Moving and resizing MSFS game window", StatusMessageType.Info);
WindowActionManager.SetMsfsGameWindowLocation(ActiveProfile.MsfsGameWindowConfig);
Thread.Sleep(500);
StatusMessageWriter.WriteOkStatusMessage();
WorkflowStepWithMessage.Execute("Moving and resizing MSFS game window", () =>
{
WindowActionManager.SetMsfsGameWindowLocation(ActiveProfile.MsfsGameWindowConfig);
Thread.Sleep(1000);
});
}
// 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
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
_prePopOutCockpitZoomLevel = _flightSimData.CockpitCameraZoom;
LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
SetCockpitZoomLevel(50);
StatusMessageWriter.WriteOkStatusMessage();
WorkflowStepWithMessage.Execute("Resetting camera view", () =>
{
ResetCockpitView();
Thread.Sleep(2000);
}, true);
WorkflowStepWithMessage.Execute("Loading custom camera view", () =>
{
LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding);
Thread.Sleep(2000);
}, true);
WorkflowStepWithMessage.Execute("Setting camera zoom level", () =>
{
SetCockpitZoomLevel(50);
}, true);
}
});
}
@ -181,25 +198,29 @@ namespace MSFSPopoutPanelManager.Orchestration
// Save current application location to restore it after pop out
var appLocation = WindowActionManager.GetWindowRectangle(WindowProcessManager.GetApplicationProcess().Handle);
if(ActiveProfile.PanelConfigs.Count > 0)
StatusMessageWriter.WriteMessageWithNewLine("Popping out user defined panels", StatusMessageType.Info);
int index = 0;
foreach (var panelConfig in ActiveProfile.PanelConfigs)
{
if (panelConfig.PanelType == PanelType.CustomPopout)
{
StatusMessageWriter.WriteMessage($"Popping out panel '{panelConfig.PanelName}'", StatusMessageType.Info);
WorkflowStepWithMessage.Execute(panelConfig.PanelName, () =>
{
panelConfig.IsSelectedPanelSource = true;
//PanelSourceOrchestrator.ShowPanelSourceNonEdit(panelConfig);
//Thread.Sleep(500);
//PanelSourceOrchestrator.ClosePanelSourceNonEdit(panelConfig);
ExecuteCustomPopout(panelConfig, builtInPanelHandles, index++);
ApplyPanelLocation(panelConfig);
panelConfig.IsSelectedPanelSource = false;
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();
if (panelConfig.IsPopOutSuccess != null && !(bool)panelConfig.IsPopOutSuccess)
return false;
else
return true;
}, true);
}
}
@ -225,10 +246,7 @@ namespace MSFSPopoutPanelManager.Orchestration
FlightSimOrchestrator.TurnOffActivePause();
// Return to custom camera view if set
var task = Task.Run(() => {
//SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
ReturnToAfterPopOutCameraView();
});
ReturnToAfterPopOutCameraView();
});
}
@ -236,57 +254,64 @@ namespace MSFSPopoutPanelManager.Orchestration
{
if (ActiveProfile.ProfileSetting.IncludeInGamePanels)
{
var builtInPanels = new List<PanelConfig>();
StatusMessageWriter.WriteMessage("Configuring built-in panel", StatusMessageType.Info);
foreach (var panelHandle in builtInPanelHandles)
WorkflowStepWithMessage.Execute("Configuring built-in panel", () =>
{
var panelCaption = WindowActionManager.GetWindowCaption(panelHandle);
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelName == panelCaption);
if (panelConfig == null)
int count = 0;
while (builtInPanelHandles.Count == 0 && count < 5)
{
if (!ActiveProfile.IsLocked)
{
var rectangle = WindowActionManager.GetWindowRectangle(panelHandle);
panelConfig = new PanelConfig()
{
PanelHandle = panelHandle,
PanelType = PanelType.BuiltInPopout,
PanelName = panelCaption,
Top = rectangle.Top,
Left = rectangle.Left,
Width = rectangle.Width,
Height = rectangle.Height,
AutoGameRefocus = false
};
builtInPanelHandles = WindowActionManager.GetWindowsByPanelType(new List<PanelType>() { PanelType.BuiltInPopout });
}
ActiveProfile.PanelConfigs.Add(panelConfig);
var builtInPanels = new List<PanelConfig>();
foreach (var panelHandle in builtInPanelHandles)
{
var panelCaption = WindowActionManager.GetWindowCaption(panelHandle);
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelName == panelCaption);
if (panelConfig == null)
{
if (!ActiveProfile.IsLocked)
{
var rectangle = WindowActionManager.GetWindowRectangle(panelHandle);
panelConfig = new PanelConfig()
{
PanelHandle = panelHandle,
PanelType = PanelType.BuiltInPopout,
PanelName = panelCaption,
Top = rectangle.Top,
Left = rectangle.Left,
Width = rectangle.Width,
Height = rectangle.Height,
AutoGameRefocus = false
};
ActiveProfile.PanelConfigs.Add(panelConfig);
}
}
else
{
panelConfig.PanelHandle = panelHandle;
// Need to do it twice for MSFS to take this setting (MSFS bug)
ApplyPanelLocation(panelConfig);
ApplyPanelLocation(panelConfig);
}
}
else
// Set handles for missing built-in panels
foreach (var panelConfig in ActiveProfile.PanelConfigs)
{
panelConfig.PanelHandle = panelHandle;
// Need to do it twice for MSFS to take this setting (MSFS bug)
ApplyPanelLocation(panelConfig);
ApplyPanelLocation(panelConfig);
if (panelConfig.PanelType == PanelType.BuiltInPopout && panelConfig.PanelHandle == IntPtr.MaxValue)
panelConfig.PanelHandle = IntPtr.Zero;
}
}
// 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;
}
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();
if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.BuiltInPopout && p.IsPopOutSuccess != null && !(bool)p.IsPopOutSuccess) ||
ActiveProfile.PanelConfigs.Count(p => p.PanelType == PanelType.BuiltInPopout) == 0)
return false;
else
return true;
});
}
}
@ -295,13 +320,11 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled)
return;
StatusMessageWriter.WriteMessage("Opening HUD Bar", StatusMessageType.Info);
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.HudBarWindow);
OnHudBarOpened?.Invoke(this, panelConfig);
StatusMessageWriter.WriteOkStatusMessage();
WorkflowStepWithMessage.Execute("Opening HUD Bar", () =>
{
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.HudBarWindow);
OnHudBarOpened?.Invoke(this, panelConfig);
});
}
public void SetupRefocusDisplay()
@ -309,13 +332,21 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!ActiveProfile.ProfileSetting.RefocusOnDisplay.IsEnabled)
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)
{
StatusMessageWriter.WriteMessage($"Configurating {panelConfig.PanelName} for auto refocus on touch", StatusMessageType.Info);
panelConfig.PanelHandle = new IntPtr(1);
StatusMessageWriter.WriteOkStatusMessage();
WorkflowStepWithMessage.Execute(panelConfig.PanelName, () =>
{
panelConfig.PanelHandle = new IntPtr(1);
}, true);
}
}
}
@ -349,9 +380,9 @@ namespace MSFSPopoutPanelManager.Orchestration
PanelConfigurationOrchestrator.StartTouchHook();
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
StatusMessageWriter.WriteMessageNewLine("Pop out has been completed successfully.", StatusMessageType.Info, 10);
StatusMessageWriter.WriteMessageWithNewLine("Pop out has been completed successfully.", StatusMessageType.Info);
Thread.Sleep(1000);
OnPopOutCompleted?.Invoke(this, null);
@ -461,15 +492,41 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!AppSetting.PopOutSetting.AfterPopOutCameraView.IsEnabled)
return;
StatusMessageWriter.WriteMessageWithNewLine("Applying cockpit view after pop out", StatusMessageType.Info);
switch (AppSetting.PopOutSetting.AfterPopOutCameraView.CameraView)
{
case AfterPopOutCameraViewType.CockpitCenterView:
InputEmulationManager.CenterView();
SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
WorkflowStepWithMessage.Execute("Resetting camera view", () =>
{
ResetCockpitView();
Thread.Sleep(1000);
}, true);
WorkflowStepWithMessage.Execute("Setting camera zoom level", () =>
{
SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
}, true);
break;
case AfterPopOutCameraViewType.CustomCameraView:
LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding);
SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
WorkflowStepWithMessage.Execute("Resetting camera view", () =>
{
ResetCockpitView();
Thread.Sleep(1000);
}, true);
WorkflowStepWithMessage.Execute("Loading custom camera view", () =>
{
LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding);
Thread.Sleep(1000);
}, true);
WorkflowStepWithMessage.Execute("Setting camera zoom level", () =>
{
SetCockpitZoomLevel(_prePopOutCockpitZoomLevel);
}, true);
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);
}
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)
{
int retry = 20;
for(var i = 0; i < retry; i++)
{
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
break;
}
@ -497,7 +566,7 @@ namespace MSFSPopoutPanelManager.Orchestration
for (var i = 0; i < retry; i++)
{
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)
break;

View file

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

View file

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

View file

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

View file

@ -7,44 +7,57 @@ namespace MSFSPopoutPanelManager.Shared
{
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)
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 });
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 });
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 });
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()
{
_messages.Clear();
OnStatusMessage?.Invoke(null, new StatusMessageEventArg(new List<StatusMessage>()));
OnStatusMessage?.Invoke(null, new List<StatusMessage>());
}
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,
WRITEABLE_TRACKIR_DEFINITION,
WRITEABLE_COCKPITCAMERAZOOM_DEFINITION,
WRITEABLE_CAMERAREQUESTACTION_DEFINITION,
NA
}

View file

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

View file

@ -192,6 +192,9 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
case WriteableVariableName.CockpitCameraZoom:
_simConnect.SetDataOnSimObject(DATA_DEFINITION.WRITEABLE_COCKPITCAMERAZOOM_DEFINITION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dataStruct);
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)
@ -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_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.WRITEABLE_TRACKIR_DEFINITION);

View file

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