From 27aeda205cb3d01dbb8f35a3b7d950dbfa5f4df3 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 17 Mar 2024 04:03:27 +0100 Subject: [PATCH] Make Sys_SetInteractiveIngameGuiActive() work better it could happen that UIs are added to the internal list twice, and also that the last UI wasn't removed from the list when a new one was focused fast enough. That should work better now, I hope I didn't break anything.. --- neo/d3xp/Player.cpp | 5 +++++ neo/game/Player.cpp | 5 +++++ neo/sys/events.cpp | 7 +++++-- neo/sys/sys_public.h | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/neo/d3xp/Player.cpp b/neo/d3xp/Player.cpp index ca1385939..837447979 100644 --- a/neo/d3xp/Player.cpp +++ b/neo/d3xp/Player.cpp @@ -5539,6 +5539,11 @@ void idPlayer::UpdateFocus( void ) { if ( focusGUIent && focusUI ) { if ( !oldFocus || oldFocus != focusGUIent ) { + // DG: tell the old UI it isn't focused anymore + if ( oldFocus != NULL && oldUI != NULL ) { + command = oldUI->Activate( false, gameLocal.time ); + // TODO: HandleGuiCommands( oldFocus, command ); ? + } // DG end command = focusUI->Activate( true, gameLocal.time ); HandleGuiCommands( focusGUIent, command ); StartSound( "snd_guienter", SND_CHANNEL_ANY, 0, false, NULL ); diff --git a/neo/game/Player.cpp b/neo/game/Player.cpp index 3565d5f2d..ec9b3ff8b 100644 --- a/neo/game/Player.cpp +++ b/neo/game/Player.cpp @@ -4559,6 +4559,11 @@ void idPlayer::UpdateFocus( void ) { if ( focusGUIent && focusUI ) { if ( !oldFocus || oldFocus != focusGUIent ) { + // DG: tell the old UI it isn't focused anymore + if ( oldFocus != NULL && oldUI != NULL ) { + command = oldUI->Activate( false, gameLocal.time ); + // TODO: HandleGuiCommands( oldFocus, command ); ? + } // DG end command = focusUI->Activate( true, gameLocal.time ); HandleGuiCommands( focusGUIent, command ); StartSound( "snd_guienter", SND_CHANNEL_ANY, 0, false, NULL ); diff --git a/neo/sys/events.cpp b/neo/sys/events.cpp index 7da003bf1..2890ff7a7 100644 --- a/neo/sys/events.cpp +++ b/neo/sys/events.cpp @@ -1038,7 +1038,9 @@ void Sys_SetInteractiveIngameGuiActive( bool active, idUserInterface* ui ) if ( sessLocal.GetActiveMenu() == NULL && active ) { // add ui to lastuis, if it has been activated and no proper menu // (like main menu) is currently open - lastuis.Append( ui ); + if ( idx == -1 ) { + lastuis.Append( ui ); + } } else if ( idx != -1 ) { // if the UI is in lastuis and has been deactivated, or there // is a proper menu opened, remove it from the list. @@ -1049,7 +1051,8 @@ void Sys_SetInteractiveIngameGuiActive( bool active, idUserInterface* ui ) // And because it's possible that we have an ingame UI focussed while opening // the multiplayer-main-menu, we keep a list of lastuis, instead of just one, // so D3_IN_interactiveIngameGuiActive remains true in that case - // (the ingame UI is still in the list) + // (the ingame UI is still in the list); the lastuis list is also needed + // for the case of opening the PDA while an ingame GUI is focused lastuis.RemoveIndex( idx ); } diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index b006a394c..66a72b160 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -251,6 +251,7 @@ void Sys_GrabMouseCursor( bool grabIt ); // DG: added this for an ungodly hack for gamepad support // active = true means "currently a GUI with a cursor is active/focused" // active = false means "that GUI is not active anymore" +// ui == NULL means "clear all currently remembered GUIs" class idUserInterface; void Sys_SetInteractiveIngameGuiActive( bool active, idUserInterface* ui );