From b29c236bf9171962c082e8c875658e5b47772aa3 Mon Sep 17 00:00:00 2001 From: hawkeye Date: Fri, 29 Sep 2023 02:15:02 -0400 Subject: [PATCH] Added turbo mode --- DomainModel/DomainModel.csproj | 6 +- DomainModel/Setting/GeneralSetting.cs | 3 + MainApp/MainApp.csproj | 6 +- MainApp/UserControl/PreferenceDrawer.xaml | 15 ++- MainApp/ViewModel/BaseViewModel.cs | 2 +- Orchestration/Orchestration.csproj | 6 +- Orchestration/PanelPopOutOrchestrator.cs | 106 ++++++++++++---------- Shared/Shared.csproj | 6 +- SimconnectAgent/SimconnectAgent.csproj | 6 +- WindowsAgent/InputEmulationManager.cs | 30 ++++-- WindowsAgent/WindowsAgent.csproj | 6 +- 11 files changed, 113 insertions(+), 79 deletions(-) diff --git a/DomainModel/DomainModel.csproj b/DomainModel/DomainModel.csproj index 91b48d1..26dbfce 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.9 - 4.0.2.9 - 4.0.2.9 + 4.0.3.0 + 4.0.3.0 + 4.0.3.0 win-x64 Embedded Debug;Release;Local diff --git a/DomainModel/Setting/GeneralSetting.cs b/DomainModel/Setting/GeneralSetting.cs index 6ef5d11..803fdfc 100644 --- a/DomainModel/Setting/GeneralSetting.cs +++ b/DomainModel/Setting/GeneralSetting.cs @@ -12,6 +12,7 @@ namespace MSFSPopoutPanelManager.DomainModel.Setting StartMinimized = false; AutoClose = true; CheckForUpdate = true; + TurboMode = false; InitializeChildPropertyChangeBinding(); } @@ -26,6 +27,8 @@ namespace MSFSPopoutPanelManager.DomainModel.Setting public bool CheckForUpdate { get; set; } + public bool TurboMode { get; set; } + [JsonIgnore, IgnorePropertyChanged] public bool AutoStart { diff --git a/MainApp/MainApp.csproj b/MainApp/MainApp.csproj index 8603042..b6d6aed 100644 --- a/MainApp/MainApp.csproj +++ b/MainApp/MainApp.csproj @@ -14,9 +14,9 @@ MSFSPopoutPanelManager.MainApp logo.ico x64 - 4.0.2.9 - 4.0.2.9 - 4.0.2.9 + 4.0.3.0 + 4.0.3.0 + 4.0.3.0 embedded en diff --git a/MainApp/UserControl/PreferenceDrawer.xaml b/MainApp/UserControl/PreferenceDrawer.xaml index 5268e81..0c9d181 100644 --- a/MainApp/UserControl/PreferenceDrawer.xaml +++ b/MainApp/UserControl/PreferenceDrawer.xaml @@ -181,6 +181,19 @@ Automatically close the application when exiting MSFS. + + Turbo Mode + + + + + WARNING! + This may not work for all PC. Enable turbo mode to pop out panels as fast as possible. If you have a fast PC, this will let Pop Out Panel Manager executes pop out much faster. + + Check for Update - Enable checking for update of application through Github. + Enable check for application update through Github. diff --git a/MainApp/ViewModel/BaseViewModel.cs b/MainApp/ViewModel/BaseViewModel.cs index 75f93ad..a8a2611 100644 --- a/MainApp/ViewModel/BaseViewModel.cs +++ b/MainApp/ViewModel/BaseViewModel.cs @@ -47,7 +47,7 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel run.Foreground = new SolidColorBrush(Colors.IndianRed); break; case StatusMessageType.Executing: - run.Foreground = new SolidColorBrush(Colors.Yellow); + run.Foreground = new SolidColorBrush(Colors.NavajoWhite); break; case StatusMessageType.Info: break; diff --git a/Orchestration/Orchestration.csproj b/Orchestration/Orchestration.csproj index 68a85ff..bc1fedf 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.9 - 4.0.2.9 - 4.0.2.9 + 4.0.3.0 + 4.0.3.0 + 4.0.3.0 win-x64 Embedded Debug;Release;Local diff --git a/Orchestration/PanelPopOutOrchestrator.cs b/Orchestration/PanelPopOutOrchestrator.cs index 3fe9288..030e831 100644 --- a/Orchestration/PanelPopOutOrchestrator.cs +++ b/Orchestration/PanelPopOutOrchestrator.cs @@ -202,19 +202,19 @@ namespace MSFSPopoutPanelManager.Orchestration if (_flightSimData.CameraViewTypeAndIndex1 == CAMERA_VIEW_HOME_COCKPIT_MODE) { - SetCockpitZoomLevel(_profileData.ActiveProfile.PanelSourceCockpitZoomFactor); + SetCockpitZoomLevel(_profileData.ActiveProfile.PanelSourceCockpitZoomFactor, AppSetting.GeneralSetting.TurboMode); } else { WorkflowStepWithMessage.Execute("Resetting camera view", () => { - ResetCockpitView(); + ResetCockpitView(AppSetting.GeneralSetting.TurboMode); }, true); var success = WorkflowStepWithMessage.Execute("Loading custom camera view", () => { - return LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); + return LoadCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding, AppSetting.GeneralSetting.TurboMode); }, true); if (!success) @@ -222,7 +222,7 @@ namespace MSFSPopoutPanelManager.Orchestration WorkflowStepWithMessage.Execute("Setting camera zoom level", () => { - SetCockpitZoomLevel(50); + SetCockpitZoomLevel(50, AppSetting.GeneralSetting.TurboMode); }, true); } } @@ -249,7 +249,22 @@ namespace MSFSPopoutPanelManager.Orchestration WorkflowStepWithMessage.Execute(panelConfig.PanelName, () => { panelConfig.IsSelectedPanelSource = true; - ExecuteCustomPopout(panelConfig, builtInPanelHandles, index++); + + if(AppSetting.GeneralSetting.TurboMode) + { + InputEmulationManager.PrepareToPopOutPanel((int)panelConfig.PanelSource.X, (int)panelConfig.PanelSource.Y, AppSetting.GeneralSetting.TurboMode); + PanelSourceOrchestrator.ShowPanelSourceNonEdit(panelConfig); + ExecuteCustomPopout(panelConfig, builtInPanelHandles, index++); + PanelSourceOrchestrator.ClosePanelSourceNonEdit(panelConfig); + } + else + { + PanelSourceOrchestrator.ShowPanelSourceNonEdit(panelConfig); + InputEmulationManager.PrepareToPopOutPanel((int)panelConfig.PanelSource.X, (int)panelConfig.PanelSource.Y, AppSetting.GeneralSetting.TurboMode); + PanelSourceOrchestrator.ClosePanelSourceNonEdit(panelConfig); + ExecuteCustomPopout(panelConfig, builtInPanelHandles, index++); + } + ApplyPanelLocation(panelConfig); panelConfig.IsSelectedPanelSource = false; @@ -430,51 +445,44 @@ namespace MSFSPopoutPanelManager.Orchestration private void ExecuteCustomPopout(PanelConfig panel, List builtInPanelHandles, int index) { - if (panel.PanelType == PanelType.CustomPopout) + // There should only be one handle that is not in both builtInPanelHandles vs latestAceAppWindowsWithCaptionHandles + var handle = TryPopOutCustomPanel(panel.PanelSource, builtInPanelHandles, AppSetting.GeneralSetting.TurboMode); + + if (handle == IntPtr.Zero) { - PanelSourceOrchestrator.ShowPanelSourceNonEdit(panel); - InputEmulationManager.PrepareToPopOutPanel((int)panel.PanelSource.X, (int)panel.PanelSource.Y); - PanelSourceOrchestrator.ClosePanelSourceNonEdit(panel); + panel.PanelHandle = IntPtr.Zero; + return; + } - // There should only be one handle that is not in both builtInPanelHandles vs latestAceAppWindowsWithCaptionHandles - var handle = TryPopOutCustomPanel(panel.PanelSource, builtInPanelHandles); + // 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) + { + panel.PanelHandle = IntPtr.Zero; + return; + } - if (handle == IntPtr.Zero) - { - panel.PanelHandle = IntPtr.Zero; - return; - } + panel.PanelHandle = handle; + WindowActionManager.SetWindowCaption(panel.PanelHandle, $"{panel.PanelName} (Custom)"); - // 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) - { - panel.PanelHandle = IntPtr.Zero; - return; - } - - panel.PanelHandle = handle; - WindowActionManager.SetWindowCaption(panel.PanelHandle, $"{panel.PanelName} (Custom)"); - - // First time popping out - if (panel.Width == 0 && panel.Height == 0) - { - var rect = WindowActionManager.GetWindowRectangle(panel.PanelHandle); - panel.Top = 0 + index * 30; - panel.Left = 0 + index * 30; - panel.Width = rect.Width; - panel.Height = rect.Height; - } + // First time popping out + if (panel.Width == 0 && panel.Height == 0) + { + var rect = WindowActionManager.GetWindowRectangle(panel.PanelHandle); + panel.Top = 0 + index * 30; + panel.Left = 0 + index * 30; + panel.Width = rect.Width; + panel.Height = rect.Height; } } - private IntPtr TryPopOutCustomPanel(PanelSource panelSource, List builtInPanelHandles) + private IntPtr TryPopOutCustomPanel(PanelSource panelSource, List builtInPanelHandles, bool isTurbo) { - // Try to pop out 3 times before failure with 1/2 second wait in between + // Try to pop out 5 times before failure with 1/2 second wait in between int count = 0; do { - InputEmulationManager.PopOutPanel((int)panelSource.X, (int)panelSource.Y, AppSetting.PopOutSetting.UseLeftRightControlToPopOut); - + InputEmulationManager.PopOutPanel((int)panelSource.X, (int)panelSource.Y, AppSetting.PopOutSetting.UseLeftRightControlToPopOut, isTurbo); + var latestAceAppWindowsWithCaptionHandles = WindowActionManager.GetWindowsByPanelType(new List() { PanelType.BuiltInPopout }); // There should only be one handle that is not in both builtInPanelHandles vs latestAceAppWindowsWithCaptionHandles @@ -486,7 +494,7 @@ namespace MSFSPopoutPanelManager.Orchestration Thread.Sleep(500); count++; } - while (count < 3); + while (count < 5); return IntPtr.Zero; } @@ -548,19 +556,19 @@ namespace MSFSPopoutPanelManager.Orchestration case AfterPopOutCameraViewType.CockpitCenterView: WorkflowStepWithMessage.Execute("Resetting camera view", () => { - ResetCockpitView(); + ResetCockpitView(AppSetting.GeneralSetting.TurboMode); }, true); break; case AfterPopOutCameraViewType.CustomCameraView: WorkflowStepWithMessage.Execute("Resetting camera view", () => { - ResetCockpitView(); + ResetCockpitView(AppSetting.GeneralSetting.TurboMode); }, true); WorkflowStepWithMessage.Execute("Loading custom camera view", () => { - return LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding); + return LoadCustomView(AppSetting.PopOutSetting.AfterPopOutCameraView.KeyBinding, AppSetting.GeneralSetting.TurboMode); }, true); break; @@ -573,25 +581,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() + private void ResetCockpitView(bool isTurboMode) { int retry = 10; for (var i = 0; i < retry; i++) { FlightSimOrchestrator.ResetCameraView(); - Thread.Sleep(1000); // wait for flightsimdata to be updated + Thread.Sleep(isTurboMode ? 600 : 1000); // wait for flightsimdata to be updated if (_flightSimData.CameraViewTypeAndIndex1 == 0) // 0 = reset view break; } } - private bool LoadCustomView(string keybinding) + private bool LoadCustomView(string keybinding, bool isTurboMode) { int retry = 10; for(var i = 0; i < retry; i++) { InputEmulationManager.LoadCustomView(keybinding); - Thread.Sleep(1000); // wait for flightsimdata to be updated + Thread.Sleep(isTurboMode ? 600 : 1000); // wait for flightsimdata to be updated if (_flightSimData.CameraViewTypeAndIndex1 == CAMERA_VIEW_CUSTOM_CAMERA) // custom camera view enum return true; } @@ -599,13 +607,13 @@ namespace MSFSPopoutPanelManager.Orchestration return false; } - private void SetCockpitZoomLevel(int zoom) + private void SetCockpitZoomLevel(int zoom, bool isTurboMode) { int retry = 10; for (var i = 0; i < retry; i++) { FlightSimOrchestrator.SetCockpitCameraZoomLevel(zoom); - Thread.Sleep(1000); // wait for flightsimdata to be updated + Thread.Sleep(isTurboMode ? 600 : 1000); // wait for flightsimdata to be updated if (_flightSimData.CockpitCameraZoom == zoom) break; diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 04e9530..b7612cb 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.9 - 4.0.2.9 - 4.0.2.9 + 4.0.3.0 + 4.0.3.0 + 4.0.3.0 win-x64 Embedded Debug;Release;Local diff --git a/SimconnectAgent/SimconnectAgent.csproj b/SimconnectAgent/SimconnectAgent.csproj index 9a44020..f1490bd 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.9 - 4.0.2.9 - 4.0.2.9 + 4.0.3.0 + 4.0.3.0 + 4.0.3.0 win-x64 Embedded Debug;Release;Local diff --git a/WindowsAgent/InputEmulationManager.cs b/WindowsAgent/InputEmulationManager.cs index 78465bb..43f9f3a 100644 --- a/WindowsAgent/InputEmulationManager.cs +++ b/WindowsAgent/InputEmulationManager.cs @@ -44,35 +44,40 @@ namespace MSFSPopoutPanelManager.WindowsAgent PInvoke.mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); } - public static void PrepareToPopOutPanel(int x, int y) + public static void PrepareToPopOutPanel(int x, int y, bool isTurboMode) { PInvoke.SetForegroundWindow(WindowProcessManager.SimulatorProcess.Handle); - Thread.Sleep(250); + Thread.Sleep(isTurboMode ? 0 : 250); MoveAppWindowFromLeftClickPoint(x, y); - // Left click outside the cirlce area to focus game window - LeftClick(x + 30, y); + if(!isTurboMode) + LeftClick(x + 30, y); // Left click outside the cirlce area to focus game window // Force cursor reset and focus PInvoke.SetCursorPos(x, y); - Thread.Sleep(500); + Thread.Sleep(isTurboMode ? 50 : 500); } - public static void PopOutPanel(int x, int y, bool useSecondaryKeys) + public static void PopOutPanel(int x, int y, bool useSecondaryKeys, bool isTurbo) { if (useSecondaryKeys) { InputSimulator.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.LCONTROL); InputSimulator.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.RCONTROL); - Thread.Sleep(500); + + Thread.Sleep(isTurbo ? 0: 500); + PInvoke.mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); Thread.Sleep(200); PInvoke.mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); - Thread.Sleep(200); + + Thread.Sleep(isTurbo ? 0 : 200); + PInvoke.mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); Thread.Sleep(200); PInvoke.mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); + InputSimulator.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.RCONTROL); InputSimulator.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.LCONTROL); Thread.Sleep(100); @@ -82,14 +87,19 @@ namespace MSFSPopoutPanelManager.WindowsAgent else { InputSimulator.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.RMENU); - Thread.Sleep(500); + + Thread.Sleep(isTurbo ? 0 : 500); + PInvoke.mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); Thread.Sleep(200); PInvoke.mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); - Thread.Sleep(200); + + Thread.Sleep(isTurbo ? 0 : 200); + PInvoke.mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); Thread.Sleep(200); PInvoke.mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); + InputSimulator.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.RMENU); Thread.Sleep(100); InputSimulator.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.RMENU); // resend to make sure Alt key is up diff --git a/WindowsAgent/WindowsAgent.csproj b/WindowsAgent/WindowsAgent.csproj index 8060fbe..566d14a 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.9 - 4.0.2.9 - 4.0.2.9 + 4.0.3.0 + 4.0.3.0 + 4.0.3.0 win-x64 Embedded Debug;Release;Local