From 59d870993923b9be6eead05be106b94f58c2c572 Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Wed, 15 Nov 2023 05:22:55 -0700 Subject: [PATCH] More resizing fixes in FNA Fixed gamepad is connected on first frame after screen restart. --- .../FlatRedBall/Input/Xbox360Gamepad.cs | 23 +++++++++++++++---- .../GlueControl/Views/GameHostView.xaml.cs | 13 ++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Engines/FlatRedBallXNA/FlatRedBall/Input/Xbox360Gamepad.cs b/Engines/FlatRedBallXNA/FlatRedBall/Input/Xbox360Gamepad.cs index cbbff5132..b5c9278ce 100644 --- a/Engines/FlatRedBallXNA/FlatRedBall/Input/Xbox360Gamepad.cs +++ b/Engines/FlatRedBallXNA/FlatRedBall/Input/Xbox360Gamepad.cs @@ -1304,7 +1304,7 @@ public void Clear() var isConnected = mGamePadState.IsConnected; var wasConnected = mGamePadState.IsConnected; -#if MONOGAME +#if MONOGAME || FNA // In MonoGame, calling the GamePadState constructor makes it connected. if(isConnected) { @@ -1312,23 +1312,38 @@ public void Clear() } else { +#if FNA + mGamePadState = new GamePadState(); +#endif + +#if MONOGAME mGamePadState = GamePadState.Default; +#endif } - if(wasConnected) + if (wasConnected) { mLastGamePadState = new GamePadState(new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(), new GamePadDPad()); } else { +#if FNA + mLastGamePadState = new GamePadState(); +#endif + +#if MONOGAME mLastGamePadState = GamePadState.Default; +#endif } #else - // XNA doesn't have .Default - mGamePadState = new GamePadState(); + // XNA doesn't have .Default + mGamePadState = new GamePadState(); mLastGamePadState = new GamePadState() ; #endif + + + mLeftStick.Clear(); mRightStick.Clear(); diff --git a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/Views/GameHostView.xaml.cs b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/Views/GameHostView.xaml.cs index 65f738ea9..64f62994f 100644 --- a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/Views/GameHostView.xaml.cs +++ b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/Views/GameHostView.xaml.cs @@ -216,6 +216,12 @@ private void WinformsHost_SizeChanged(object sender, SizeChangedEventArgs e) { SetGameToEmbeddedGameWindow(); + // In FNA, if the game resizes externally, the internal methods for resizing do not get called, so the + // camera doesn't adjust, aspect ratio isn't fixed, etc. We need to force this + if (GlueState.Self.CurrentMainProject is FnaDesktopProject && ViewModel.IsRunning && ViewModel.IsWindowEmbedded) + { + _ = CommandSender.Self.Send(new ForceClientSizeUpdatesDto()); + } } static double? windowsScaleFactor = null; @@ -393,12 +399,7 @@ private void ToolsSidePanel_DragEnter(object sender, DragEventArgs e) public async void ReactToMainWindowResizeEnd() { await ForceRefreshGameArea(); - // In FNA, if the game resizes externally, the internal methods for resizing do not get called, so the - // camera doesn't adjust, aspect ratio isn't fixed, etc. We need to force this - if(GlueState.Self.CurrentMainProject is FnaDesktopProject && ViewModel.IsRunning && ViewModel.IsWindowEmbedded) - { - _=CommandSender.Self.Send(new ForceClientSizeUpdatesDto()); - } + } ///