mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-24 06:40:09 +00:00
Fix bug
This commit is contained in:
parent
6cb154abe9
commit
592ca22f32
5 changed files with 53 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
@ -27,11 +28,6 @@ namespace MSFSPopoutPanelManager.MainApp.AppWindow
|
||||||
WindowActionManager.OnPopOutManagerAlwaysOnTopChanged += (_, e) => { Topmost = e; };
|
WindowActionManager.OnPopOutManagerAlwaysOnTopChanged += (_, e) => { Topmost = e; };
|
||||||
MouseLeftButtonDown += (_, _) => DragMove();
|
MouseLeftButtonDown += (_, _) => DragMove();
|
||||||
|
|
||||||
GotFocus += (_, _) =>
|
|
||||||
{
|
|
||||||
if (_viewModel.AppSettingData.ApplicationSetting.GeneralSetting.AlwaysOnTop)
|
|
||||||
WindowActionManager.ApplyAlwaysOnTop(_viewModel.ApplicationHandle, PanelType.PopOutManager, true);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AppWindow_Loaded(object sender, RoutedEventArgs e)
|
private void AppWindow_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
|
|
@ -72,6 +72,10 @@ namespace MSFSPopoutPanelManager.Orchestration
|
||||||
MapHudBarSimConnectData(e);
|
MapHudBarSimConnectData(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _lastDynamicLodPause = DateTime.Now;
|
||||||
|
var _isDynamicLodPausePrevously = true;
|
||||||
|
var _lastDyanmicLodUpdatedTime = DateTime.Now;
|
||||||
|
|
||||||
_simConnectProvider.OnSimConnectDataDynamicLodRefreshed += (_, e) =>
|
_simConnectProvider.OnSimConnectDataDynamicLodRefreshed += (_, e) =>
|
||||||
{
|
{
|
||||||
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted)
|
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted)
|
||||||
|
@ -80,9 +84,25 @@ namespace MSFSPopoutPanelManager.Orchestration
|
||||||
var isPaused = (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseWhenMsfsLoseFocus && !WindowActionManager.IsMsfsInFocus()) ||
|
var isPaused = (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseWhenMsfsLoseFocus && !WindowActionManager.IsMsfsInFocus()) ||
|
||||||
(AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit);
|
(AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit);
|
||||||
|
|
||||||
if (isPaused)
|
if (_isDynamicLodPausePrevously && !isPaused)
|
||||||
|
{
|
||||||
|
if (DateTime.Now - _lastDynamicLodPause <= TimeSpan.FromSeconds(3))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_lastDynamicLodPause = DateTime.Now;
|
||||||
|
_isDynamicLodPausePrevously = false;
|
||||||
|
}
|
||||||
|
else if (isPaused)
|
||||||
|
{
|
||||||
|
_isDynamicLodPausePrevously = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DateTime.Now - _lastDyanmicLodUpdatedTime <= TimeSpan.FromSeconds(0.4)) // take FPS sample every 0.4 seconds
|
||||||
|
return;
|
||||||
|
|
||||||
|
_lastDyanmicLodUpdatedTime = DateTime.Now;
|
||||||
|
|
||||||
MapDynamicLodSimConnectData(e);
|
MapDynamicLodSimConnectData(e);
|
||||||
_dynamicLodOrchestrator.UpdateLod();
|
_dynamicLodOrchestrator.UpdateLod();
|
||||||
};
|
};
|
||||||
|
|
|
@ -429,14 +429,14 @@ namespace MSFSPopoutPanelManager.Orchestration
|
||||||
ApplyPanelConfig(panelConfig);
|
ApplyPanelConfig(panelConfig);
|
||||||
|
|
||||||
// Set title bar color
|
// Set title bar color
|
||||||
if (AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.IsEnabled && !panelConfig.FullScreen)
|
//if (AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.IsEnabled && !panelConfig.FullScreen)
|
||||||
{
|
//{
|
||||||
WindowActionManager.SetWindowTitleBarColor(panelConfig.PanelHandle, AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.HexColor);
|
// WindowActionManager.SetWindowTitleBarColor(panelConfig.PanelHandle, AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.HexColor);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ActiveProfile.PanelConfigs.Any(p => p.AlwaysOnTop))
|
//if(ActiveProfile.PanelConfigs.Any(p => p.AlwaysOnTop))
|
||||||
WindowActionManager.ApplyAlwaysOnTop(WindowProcessManager.SimulatorProcess.Handle, PanelType.FlightSimMainWindow, true);
|
// WindowActionManager.ApplyAlwaysOnTop(WindowProcessManager.SimulatorProcess.Handle, PanelType.FlightSimMainWindow, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task StepPostPopout()
|
private async Task StepPostPopout()
|
||||||
|
@ -534,11 +534,10 @@ namespace MSFSPopoutPanelManager.Orchestration
|
||||||
|
|
||||||
if (!panel.FullScreen)
|
if (!panel.FullScreen)
|
||||||
{
|
{
|
||||||
// Apply always on top
|
// Set title bar color
|
||||||
if (panel.AlwaysOnTop)
|
if (AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.IsEnabled)
|
||||||
{
|
{
|
||||||
WindowActionManager.ApplyAlwaysOnTop(panel.PanelHandle, panel.PanelType, panel.AlwaysOnTop);
|
WindowActionManager.SetWindowTitleBarColor(panel.PanelHandle, AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.HexColor);
|
||||||
Thread.Sleep(250);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply hide title bar
|
// Apply hide title bar
|
||||||
|
@ -547,6 +546,13 @@ namespace MSFSPopoutPanelManager.Orchestration
|
||||||
WindowActionManager.ApplyHidePanelTitleBar(panel.PanelHandle, true);
|
WindowActionManager.ApplyHidePanelTitleBar(panel.PanelHandle, true);
|
||||||
Thread.Sleep(250);
|
Thread.Sleep(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply always on top (must apply this last)
|
||||||
|
if (panel.AlwaysOnTop)
|
||||||
|
{
|
||||||
|
WindowActionManager.ApplyAlwaysOnTop(panel.PanelHandle, panel.PanelType, panel.AlwaysOnTop);
|
||||||
|
Thread.Sleep(250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panel.FullScreen && !panel.AlwaysOnTop && !panel.HideTitlebar)
|
if (panel.FullScreen && !panel.AlwaysOnTop && !panel.HideTitlebar)
|
||||||
|
|
|
@ -5,10 +5,11 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
||||||
{
|
{
|
||||||
public class FpsCalc
|
public class FpsCalc
|
||||||
{
|
{
|
||||||
private const int FPS_LEN = 20;
|
private const int FPS_LEN = 5;
|
||||||
private static readonly float[] FpsStatistic = new float[FPS_LEN];
|
private static readonly float[] FpsStatistic = new float[FPS_LEN];
|
||||||
private static int _fpsIndex = -1;
|
private static int _fpsIndex = -1;
|
||||||
private static int _avgFps;
|
private static int _avgFps;
|
||||||
|
private static int _ignoreFpsSpikeCount = 0;
|
||||||
|
|
||||||
public static int GetAverageFps(int newValue)
|
public static int GetAverageFps(int newValue)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +24,16 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var isSpike = Math.Abs(newValue - _avgFps) / (_avgFps * 1.0) > 0.1;
|
||||||
|
|
||||||
|
if (_ignoreFpsSpikeCount != 3 && isSpike) // if new FPS spikes more than 10%, ignore the value
|
||||||
|
{
|
||||||
|
_ignoreFpsSpikeCount++;
|
||||||
|
return _avgFps;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ignoreFpsSpikeCount = 0;
|
||||||
|
|
||||||
var deltaFps = newValue - _avgFps;
|
var deltaFps = newValue - _avgFps;
|
||||||
|
|
||||||
if (deltaFps < 0 && Math.Abs(deltaFps) > _avgFps * 0.1) // FPS suddenly drops more than 10%
|
if (deltaFps < 0 && Math.Abs(deltaFps) > _avgFps * 0.1) // FPS suddenly drops more than 10%
|
||||||
|
|
|
@ -49,6 +49,8 @@ namespace MSFSPopoutPanelManager.WindowsAgent
|
||||||
if (panelType == PanelType.PopOutManager)
|
if (panelType == PanelType.PopOutManager)
|
||||||
{
|
{
|
||||||
OnPopOutManagerAlwaysOnTopChanged?.Invoke(null, alwaysOnTop);
|
OnPopOutManagerAlwaysOnTopChanged?.Invoke(null, alwaysOnTop);
|
||||||
|
if(alwaysOnTop)
|
||||||
|
PInvoke.SetWindowPos(hwnd, new IntPtr(PInvokeConstant.HWND_TOPMOST), 0, 0, 0, 0, PInvokeConstant.SWP_ALWAYS_ON_TOP);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue