engine: implement changing cursor type in gameui

This commit is contained in:
Alibek Omarov 2024-06-02 12:24:00 +03:00
parent bd60c88c7d
commit 999b43b89f
6 changed files with 23 additions and 14 deletions

2
3rdparty/mainui vendored

@ -1 +1 @@
Subproject commit dc467364d01e0216c6c55d1c0523c1ad823c2e2c
Subproject commit f01dda5ddde934572fa378af86e700e888ef2885

View File

@ -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;
}
}

View File

@ -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

View File

@ -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 <SDL.h>
@ -123,11 +124,6 @@ static void IN_StartupMouse( void )
in_mouseinitialized = true;
}
void GAME_EXPORT IN_SetCursor( void *hCursor )
{
// stub
}
/*
===========
IN_MouseSavePos

View File

@ -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 );

View File

@ -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 ) )
{