From 999b43b89fcb3cae08aa716c301cd6cb0716387c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 2 Jun 2024 12:24:00 +0300 Subject: [PATCH] engine: implement changing cursor type in gameui --- 3rdparty/mainui | 2 +- engine/client/cl_gameui.c | 22 ++++++++++++++++++---- engine/client/client.h | 2 +- engine/client/input.c | 6 +----- engine/client/input.h | 1 - engine/client/keys.c | 4 ++-- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/3rdparty/mainui b/3rdparty/mainui index dc467364..f01dda5d 160000 --- a/3rdparty/mainui +++ b/3rdparty/mainui @@ -1 +1 @@ -Subproject commit dc467364d01e0216c6c55d1c0523c1ad823c2e2c +Subproject commit f01dda5ddde934572fa378af86e700e888ef2885 diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index a2f164a8..0d3f5d2d 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -1097,6 +1097,20 @@ static void GAME_EXPORT pfnCon_DefaultColor( int r, int g, int b ) Con_DefaultColor( r, g, b, true ); } +static void GAME_EXPORT pfnSetCursor( void *hCursor ) +{ + uintptr_t cursor; + + if( !gameui.use_extended_api ) + return; // ignore original Xash menus + + cursor = (uintptr_t)hCursor; + if( cursor < dc_user || cursor > dc_last ) + return; + + Platform_SetCursorType( cursor ); +} + // engine callbacks static ui_enginefuncs_t gEngfuncs = { @@ -1176,7 +1190,7 @@ static ui_enginefuncs_t gEngfuncs = pfnHostEndGame, COM_RandomFloat, COM_RandomLong, - IN_SetCursor, + pfnSetCursor, pfnIsMapValid, GL_ProcessTexture, COM_CompareFileTime, @@ -1286,7 +1300,7 @@ qboolean UI_LoadProgs( void ) } - gameui.use_text_api = false; + gameui.use_extended_api = false; // make local copy of engfuncs to prevent overwrite it with user dll memcpy( &gpEngfuncs, &gEngfuncs, sizeof( gpEngfuncs )); @@ -1313,7 +1327,7 @@ qboolean UI_LoadProgs( void ) if( GetExtAPI( MENU_EXTENDED_API_VERSION, &gameui.dllFuncs2, &gpExtendedfuncs ) ) { Con_Reportf( "UI_LoadProgs: extended Menu API initialized\n" ); - gameui.use_text_api = true; + gameui.use_extended_api = true; } } else // otherwise, fallback to old and deprecated extensions @@ -1325,7 +1339,7 @@ qboolean UI_LoadProgs( void ) if( GiveTextApi( &gpExtendedfuncs ) ) // they are binary compatible, so we can just pass extended funcs API to menu { Con_Reportf( "UI_LoadProgs: extended text API initialized\n" ); - gameui.use_text_api = true; + gameui.use_extended_api = true; } } diff --git a/engine/client/client.h b/engine/client/client.h index fc055aa6..549a6dca 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -520,7 +520,7 @@ typedef struct int logo_yres; float logo_length; - qboolean use_text_api; + qboolean use_extended_api; } gameui_static_t; typedef struct diff --git a/engine/client/input.c b/engine/client/input.c index f0536462..4674c546 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -17,6 +17,7 @@ GNU General Public License for more details. #include "input.h" #include "client.h" #include "vgui_draw.h" +#include "cursor_type.h" #if XASH_SDL #include @@ -123,11 +124,6 @@ static void IN_StartupMouse( void ) in_mouseinitialized = true; } -void GAME_EXPORT IN_SetCursor( void *hCursor ) -{ - // stub -} - /* =========== IN_MouseSavePos diff --git a/engine/client/input.h b/engine/client/input.h index bd5aafb1..fc126ea4 100644 --- a/engine/client/input.h +++ b/engine/client/input.h @@ -40,7 +40,6 @@ void IN_DeactivateMouse( void ); void IN_MouseSavePos( void ); void IN_MouseRestorePos( void ); void IN_ToggleClientMouse( int newstate, int oldstate ); -void IN_SetCursor( void *hCursor ); uint IN_CollectInputDevices( void ); void IN_LockInputDevices( qboolean lock ); diff --git a/engine/client/keys.c b/engine/client/keys.c index 919f6e0b..f0ea13d1 100644 --- a/engine/client/keys.c +++ b/engine/client/keys.c @@ -749,10 +749,10 @@ void GAME_EXPORT Key_Event( int key, int down ) if( cls.key_dest == key_menu ) { // only non printable keys passed - if( !gameui.use_text_api ) + if( !gameui.use_extended_api ) Key_EnableTextInput( true, false ); //pass printable chars for old menus - if( !gameui.use_text_api && !host.textmode && down && ( key >= 32 ) && ( key <= 'z' ) ) + if( !gameui.use_extended_api && !host.textmode && down && ( key >= 32 ) && ( key <= 'z' ) ) { if( Key_IsDown( K_SHIFT ) ) {