diff --git a/MainApp/ViewModel/OrchestratorUIHelper.cs b/MainApp/ViewModel/OrchestratorUIHelper.cs index ac9b17a..0bc8593 100644 --- a/MainApp/ViewModel/OrchestratorUIHelper.cs +++ b/MainApp/ViewModel/OrchestratorUIHelper.cs @@ -48,7 +48,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel if (panel?.PanelId == panelConfig.Id) { panel.Close(); - break; } } } @@ -114,6 +113,9 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel Application.Current.Dispatcher.Invoke(() => { + // Remove existing overlay if exist + HandleRemoveOverlay(this, panelConfig); + PanelCoorOverlay overlay = new PanelCoorOverlay(panelConfig.Id, !nonEdit); overlay.IsEditingPanelLocation = true; overlay.WindowStartupLocation = WindowStartupLocation.Manual; diff --git a/Orchestration/PanelSourceOrchestrator.cs b/Orchestration/PanelSourceOrchestrator.cs index 04adf2a..33ff6ea 100644 --- a/Orchestration/PanelSourceOrchestrator.cs +++ b/Orchestration/PanelSourceOrchestrator.cs @@ -18,6 +18,7 @@ namespace MSFSPopoutPanelManager.Orchestration private AppSettingData _appSettingData; private FlightSimData _flightSimData; private int _prePanelConfigurationCockpitZoomLevel = 50; + private bool _isEditingPanelSourceLock = false; public PanelSourceOrchestrator(ProfileData profileData, AppSettingData appSettingData, FlightSimData flightSimData) { @@ -49,7 +50,7 @@ namespace MSFSPopoutPanelManager.Orchestration public void StartPanelSelection(PanelConfig panelConfig) { - _profileData.ActiveProfile.IsEditingPanelSource = true; + ActiveProfile.IsEditingPanelSource = true; InputHookManager.OnLeftClick += (sender, e) => HandleOnPanelSelectionAdded(panelConfig, e); InputHookManager.StartMouseHook(); @@ -57,6 +58,11 @@ namespace MSFSPopoutPanelManager.Orchestration public async Task StartEditPanelSources() { + if (_isEditingPanelSourceLock) + return; + + _isEditingPanelSourceLock = true; + await Task.Run(() => { // Set Windowed Display Mode window's configuration if needed @@ -79,24 +85,22 @@ namespace MSFSPopoutPanelManager.Orchestration WindowActionManager.BringWindowToForeground(ApplicationHandle); } + + foreach (var panel in _profileData.ActiveProfile.PanelConfigs) + { + if (panel.HasPanelSource) + OnOverlayShowed?.Invoke(this, panel); + } + + // Turn off TrackIR if TrackIR is started + FlightSimOrchestrator.TurnOffTrackIR(); }); - - foreach (var panel in _profileData.ActiveProfile.PanelConfigs) - { - if (panel.HasPanelSource) - OnOverlayShowed?.Invoke(this, panel); - } - - // Turn off TrackIR if TrackIR is started - FlightSimOrchestrator.TurnOffTrackIR(); } public async Task EndEditPanelSources() { - foreach (var panel in _profileData.ActiveProfile.PanelConfigs) - { - OnOverlayRemoved?.Invoke(this, panel); - } + if (!_isEditingPanelSourceLock) + return; // Save last auto panning camera angle if (AppSetting.PopOutSetting.AutoPanning.IsEnabled) @@ -113,11 +117,17 @@ namespace MSFSPopoutPanelManager.Orchestration { // !!! Fix MSFS bug that without setting zoom, everything will be off by few pixels at a time SetCockpitZoomLevel(_flightSimData.CockpitCameraZoom); - InputEmulationManager.SaveCustomView(AppSetting.PopOutSetting.AutoPanning.KeyBinding); } } + _isEditingPanelSourceLock = false; + + foreach (var panel in _profileData.ActiveProfile.PanelConfigs) + { + OnOverlayRemoved?.Invoke(this, panel); + } + await Task.Run(() => { Thread.Sleep(500); // wait for custom view save to be completed @@ -146,6 +156,7 @@ namespace MSFSPopoutPanelManager.Orchestration if (ActiveProfile != null) { ActiveProfile.IsEditingPanelSource = false; + _isEditingPanelSourceLock = false; foreach (var panelConfig in ActiveProfile.PanelConfigs) OnOverlayRemoved?.Invoke(this, panelConfig); diff --git a/WindowsAgent/InputEmulationManager.cs b/WindowsAgent/InputEmulationManager.cs index 438866e..c6ad2cf 100644 --- a/WindowsAgent/InputEmulationManager.cs +++ b/WindowsAgent/InputEmulationManager.cs @@ -49,6 +49,7 @@ namespace MSFSPopoutPanelManager.WindowsAgent Debug.WriteLine($"Pop out panel at: {x}/{y} ..."); PInvoke.SetForegroundWindow(WindowProcessManager.SimulatorProcess.Handle); + Thread.Sleep(200); MoveAppWindowFromLeftClickPoint(x, y);