From 0862d5ef2d87974e23340ba5f290d0f8d90d3104 Mon Sep 17 00:00:00 2001 From: hawkeye Date: Mon, 14 Aug 2023 00:35:14 -0400 Subject: [PATCH] Update load custom view logic --- DomainModel/DomainModel.csproj | 6 +++--- MainApp/MainApp.csproj | 6 +++--- Orchestration/FlightSimData.cs | 2 ++ Orchestration/FlightSimOrchestrator.cs | 4 ++++ Orchestration/Orchestration.csproj | 6 +++--- Orchestration/PanelPopOutOrchestrator.cs | 18 ++++++++++++++++-- Orchestration/PanelSourceOrchestrator.cs | 17 +++++++++++++++-- RELEASENOTES.md | 3 +++ Shared/Shared.csproj | 6 +++--- SimconnectAgent/SimConnector.cs | 7 ------- SimconnectAgent/SimDataDefinitions.cs | 2 ++ SimconnectAgent/SimconnectAgent.csproj | 6 +++--- VERSION.md | 2 ++ WindowsAgent/InputEmulationManager.cs | 5 +++-- WindowsAgent/WindowsAgent.csproj | 6 +++--- 15 files changed, 65 insertions(+), 31 deletions(-) diff --git a/DomainModel/DomainModel.csproj b/DomainModel/DomainModel.csproj index 1e0ff45..1141d08 100644 --- a/DomainModel/DomainModel.csproj +++ b/DomainModel/DomainModel.csproj @@ -11,9 +11,9 @@ https://github.com/hawkeye-stan/msfs-popout-panel-manager MSFSPopoutPanelManager.DomainModel x64 - 4.0.2.0 - 4.0.2.0 - 4.0.2.0 + 4.0.2.1 + 4.0.2.1 + 4.0.2.1 win-x64 Embedded Debug;Release;Local diff --git a/MainApp/MainApp.csproj b/MainApp/MainApp.csproj index e076419..5384fc8 100644 --- a/MainApp/MainApp.csproj +++ b/MainApp/MainApp.csproj @@ -14,9 +14,9 @@ MSFSPopoutPanelManager.MainApp logo.ico x64 - 4.0.2.0 - 4.0.2.0 - 4.0.2.0 + 4.0.2.1 + 4.0.2.1 + 4.0.2.1 embedded en diff --git a/Orchestration/FlightSimData.cs b/Orchestration/FlightSimData.cs index 908e787..15e5c01 100644 --- a/Orchestration/FlightSimData.cs +++ b/Orchestration/FlightSimData.cs @@ -33,6 +33,8 @@ namespace MSFSPopoutPanelManager.Orchestration public int CockpitCameraZoom { get; set; } + public int CameraViewTypeAndIndex1 { get; set; } + public bool PlaneInParkingSpot { get; set; } public bool IsSimulatorStarted { get; set; } diff --git a/Orchestration/FlightSimOrchestrator.cs b/Orchestration/FlightSimOrchestrator.cs index 7bbd7fb..c341b62 100644 --- a/Orchestration/FlightSimOrchestrator.cs +++ b/Orchestration/FlightSimOrchestrator.cs @@ -80,6 +80,10 @@ namespace MSFSPopoutPanelManager.Orchestration var cockpitCameraZoom = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CockpitCameraZoom).Value); if (cockpitCameraZoom != _flightSimData.CockpitCameraZoom) _flightSimData.CockpitCameraZoom = cockpitCameraZoom; + + var cameraViewTypeAndIndex1 = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex1).Value); + if (cameraViewTypeAndIndex1 != _flightSimData.CameraViewTypeAndIndex1) + _flightSimData.CameraViewTypeAndIndex1 = cameraViewTypeAndIndex1; }; _simConnectProvider.OnSimConnectDataHudBarRefreshed += (sender, e) => diff --git a/Orchestration/Orchestration.csproj b/Orchestration/Orchestration.csproj index c6034c6..57dfeb6 100644 --- a/Orchestration/Orchestration.csproj +++ b/Orchestration/Orchestration.csproj @@ -11,9 +11,9 @@ https://github.com/hawkeye-stan/msfs-popout-panel-manager MSFSPopoutPanelManager.Orchestration x64 - 4.0.2.0 - 4.0.2.0 - 4.0.2.0 + 4.0.2.1 + 4.0.2.1 + 4.0.2.1 win-x64 Embedded Debug;Release;Local diff --git a/Orchestration/PanelPopOutOrchestrator.cs b/Orchestration/PanelPopOutOrchestrator.cs index b252e8e..d490ba7 100644 --- a/Orchestration/PanelPopOutOrchestrator.cs +++ b/Orchestration/PanelPopOutOrchestrator.cs @@ -5,6 +5,7 @@ using MSFSPopoutPanelManager.WindowsAgent; using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -185,7 +186,7 @@ namespace MSFSPopoutPanelManager.Orchestration // Remember current game's zoom level to be recall after pop out _prePopOutCockpitZoomLevel = _flightSimData.CockpitCameraZoom; - InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); + LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); FlightSimOrchestrator.SetCockpitCameraZoomLevel(50); Thread.Sleep(1000); StatusMessageWriter.WriteOkStatusMessage(); @@ -488,7 +489,7 @@ namespace MSFSPopoutPanelManager.Orchestration FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePopOutCockpitZoomLevel); break; case AfterPopOutCameraViewType.CustomCameraView: - InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); + LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePopOutCockpitZoomLevel); break; } @@ -498,6 +499,19 @@ namespace MSFSPopoutPanelManager.Orchestration { return ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null && (bool)p.IsPopOutSuccess) != ActiveProfile.PanelConfigs.Count(p => p.IsPopOutSuccess != null); } + + private void LoadCustomView(string keybinding) + { + int retry = 5; + for(var i = 0; i < retry; i++) + { + InputEmulationManager.LoadCustomView(keybinding); + Thread.Sleep(500); // wait for flightsimdata to be updated + + if (_flightSimData.CameraViewTypeAndIndex1 == 7) // 7 = custom camera view enum + break; + } + } } } diff --git a/Orchestration/PanelSourceOrchestrator.cs b/Orchestration/PanelSourceOrchestrator.cs index b79645a..5d0bfb2 100644 --- a/Orchestration/PanelSourceOrchestrator.cs +++ b/Orchestration/PanelSourceOrchestrator.cs @@ -62,7 +62,7 @@ namespace MSFSPopoutPanelManager.Orchestration if (AppSetting.PopOutSetting.AutoPanning.IsEnabled) { _prePanelConfigurationCockpitZoomLevel = _flightSimData.CockpitCameraZoom; - InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); + LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); FlightSimOrchestrator.SetCockpitCameraZoomLevel(50); WindowActionManager.BringWindowToForeground(ApplicationHandle); } @@ -114,7 +114,7 @@ namespace MSFSPopoutPanelManager.Orchestration FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel); break; case AfterPopOutCameraViewType.CustomCameraView: - InputEmulationManager.LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); + LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); FlightSimOrchestrator.SetCockpitCameraZoomLevel(_prePanelConfigurationCockpitZoomLevel); break; } @@ -185,5 +185,18 @@ namespace MSFSPopoutPanelManager.Orchestration _profileData.ActiveProfile.PanelConfigs.Remove(panelConfig); } + + private void LoadCustomView(string keybinding) + { + int retry = 5; + for (var i = 0; i < retry; i++) + { + InputEmulationManager.LoadCustomView(keybinding); + Thread.Sleep(500); // wait for flightsimdata to be updated + + if (_flightSimData.CameraViewTypeAndIndex1 == 7) // 7 = custom camera view enum + break; + } + } } } diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f9516b3..14bdc2f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -4,3 +4,6 @@ * Added workaround fix when using camera zoom setting with value other than 50 in MSFS general options will cause Pop Out Panel Manager pop out to fail. This is an existing MSFS bug where saving and loading of custom camera view is currently broken for zoom level other than 50. * Fixed issue where full screen mode for pop out panel does not work on certain aircraft configuration. + +* Updated logic to verify custom camera view has been loaded before starting pop out process. + diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 5147edc..dd2de59 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -11,9 +11,9 @@ https://github.com/hawkeye-stan/msfs-popout-panel-manager MSFSPopoutPanelManager.Shared x64 - 4.0.2.0 - 4.0.2.0 - 4.0.2.0 + 4.0.2.1 + 4.0.2.1 + 4.0.2.1 win-x64 Embedded Debug;Release;Local diff --git a/SimconnectAgent/SimConnector.cs b/SimconnectAgent/SimConnector.cs index b7f8718..110c5a7 100644 --- a/SimconnectAgent/SimConnector.cs +++ b/SimconnectAgent/SimConnector.cs @@ -462,13 +462,6 @@ namespace MSFSPopoutPanelManager.SimConnectAgent aircraftName = aircraftName.Replace("_", " ").ToUpper(); OnActiveAircraftChanged?.Invoke(this, aircraftName); - - //var def = _simConnectDataDefinitions.Find(s => s.PropName == SimDataDefinitions.PropName.AircraftName); - //if(def != null) - //{ - // def.Value = aircraftName; - // OnReceivedData?.Invoke(this, _simConnectDataDefinitions); - //} } } } diff --git a/SimconnectAgent/SimDataDefinitions.cs b/SimconnectAgent/SimDataDefinitions.cs index 5c8a668..b119c85 100644 --- a/SimconnectAgent/SimDataDefinitions.cs +++ b/SimconnectAgent/SimDataDefinitions.cs @@ -13,6 +13,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent definitions.Add(new SimConnectDataDefinition() { DefinitionId = DATA_DEFINITION.REQUIRED_DEFINITION, RequestId = DATA_REQUEST.REQUIRED_REQUEST, DataDefinitionType = DataDefinitionType.SimConnect, PropName = PropName.PlaneInParkingSpot, VariableName = "ATC ON PARKING SPOT", SimConnectUnit = "Bool", DataType = DataType.Float64 }); definitions.Add(new SimConnectDataDefinition() { DefinitionId = DATA_DEFINITION.REQUIRED_DEFINITION, RequestId = DATA_REQUEST.REQUIRED_REQUEST, DataDefinitionType = DataDefinitionType.SimConnect, PropName = PropName.CameraState, VariableName = "CAMERA STATE", SimConnectUnit = "Number", DataType = DataType.Float64 }); definitions.Add(new SimConnectDataDefinition() { DefinitionId = DATA_DEFINITION.REQUIRED_DEFINITION, RequestId = DATA_REQUEST.REQUIRED_REQUEST, DataDefinitionType = DataDefinitionType.SimConnect, PropName = PropName.CockpitCameraZoom, VariableName = "COCKPIT CAMERA ZOOM", SimConnectUnit = "Percentage", DataType = DataType.Float64 }); + definitions.Add(new SimConnectDataDefinition() { DefinitionId = DATA_DEFINITION.REQUIRED_DEFINITION, RequestId = DATA_REQUEST.REQUIRED_REQUEST, DataDefinitionType = DataDefinitionType.SimConnect, PropName = PropName.CameraViewTypeAndIndex1, VariableName = "CAMERA VIEW TYPE AND INDEX:1", SimConnectUnit = "Enum", DataType = DataType.Float64 }); return definitions; } @@ -76,6 +77,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent public static string CameraState = "CameraState"; public static string AircraftName = "AircraftName"; public static string CockpitCameraZoom = "CockpitCameraZoom"; + public static string CameraViewTypeAndIndex1 = "CameraViewTypeAndIndex1"; // Hud Bar data public static string ElevatorTrim = "ElevatorTrim"; diff --git a/SimconnectAgent/SimconnectAgent.csproj b/SimconnectAgent/SimconnectAgent.csproj index c18fab9..45b5341 100644 --- a/SimconnectAgent/SimconnectAgent.csproj +++ b/SimconnectAgent/SimconnectAgent.csproj @@ -11,9 +11,9 @@ https://github.com/hawkeye-stan/msfs-popout-panel-manager MSFSPopoutPanelManager.SimConnectAgent x64 - 4.0.2.0 - 4.0.2.0 - 4.0.2.0 + 4.0.2.1 + 4.0.2.1 + 4.0.2.1 win-x64 Embedded Debug;Release;Local diff --git a/VERSION.md b/VERSION.md index 997733a..239fe62 100644 --- a/VERSION.md +++ b/VERSION.md @@ -8,6 +8,8 @@ * Fixed issue where full screen mode for pop out panel does not work on certain aircraft configuration. +* Updated logic to verify custom camera view has been loaded before starting pop out process. + ## Version 4.0.1.2 * Hotfix - Fixed issue where using touch panel feature may freeze computer and the application. diff --git a/WindowsAgent/InputEmulationManager.cs b/WindowsAgent/InputEmulationManager.cs index 0717e83..324b05d 100644 --- a/WindowsAgent/InputEmulationManager.cs +++ b/WindowsAgent/InputEmulationManager.cs @@ -132,8 +132,9 @@ namespace MSFSPopoutPanelManager.WindowsAgent { Debug.WriteLine("Loading custom view..."); - // First center view to make sure recalling custom camera works on the first press - CenterView(); + var hwnd = WindowProcessManager.SimulatorProcess.Handle; + PInvoke.SetForegroundWindow(hwnd); + Thread.Sleep(200); uint customViewKey = (uint)(Convert.ToInt32(keybinding) + KEY_0); diff --git a/WindowsAgent/WindowsAgent.csproj b/WindowsAgent/WindowsAgent.csproj index f2e670e..89d6a3c 100644 --- a/WindowsAgent/WindowsAgent.csproj +++ b/WindowsAgent/WindowsAgent.csproj @@ -11,9 +11,9 @@ https://github.com/hawkeye-stan/msfs-popout-panel-manager MSFSPopoutPanelManager.WindowsAgent x64 - 4.0.2.0 - 4.0.2.0 - 4.0.2.0 + 4.0.2.1 + 4.0.2.1 + 4.0.2.1 win-x64 Embedded Debug;Release;Local