engine: client: fix inconsistent mouse state caused by mis-use of touch_emulate by cs16-client

This commit is contained in:
Alibek Omarov 2025-02-23 07:13:39 +03:00
parent 8b9a40ff1f
commit ccf342f4fe
4 changed files with 13 additions and 23 deletions

View file

@ -161,7 +161,7 @@ static CVAR_DEFINE_AUTO( touch_dpad_radius, "1.0", FCVAR_FILTERABLE, "dpad radiu
static CVAR_DEFINE_AUTO( touch_joy_radius, "1.0", FCVAR_FILTERABLE, "joy radius multiplier" ); static CVAR_DEFINE_AUTO( touch_joy_radius, "1.0", FCVAR_FILTERABLE, "joy radius multiplier" );
static CVAR_DEFINE_AUTO( touch_move_indicator, "0.0", FCVAR_FILTERABLE, "indicate move events (0 to disable)" ); static CVAR_DEFINE_AUTO( touch_move_indicator, "0.0", FCVAR_FILTERABLE, "indicate move events (0 to disable)" );
static CVAR_DEFINE_AUTO( touch_joy_texture, "touch_default/joy", FCVAR_FILTERABLE, "texture for move indicator"); static CVAR_DEFINE_AUTO( touch_joy_texture, "touch_default/joy", FCVAR_FILTERABLE, "texture for move indicator");
static CVAR_DEFINE_AUTO( touch_emulate, "0", FCVAR_PRIVILEGED, "emulate touch with mouse" ); static CVAR_DEFINE( touch_emulate, "_touch_emulate", "0", FCVAR_PRIVILEGED, "emulate touch with mouse" );
CVAR_DEFINE_AUTO( touch_enable, DEFAULT_TOUCH_ENABLE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "enable touch controls" ); CVAR_DEFINE_AUTO( touch_enable, DEFAULT_TOUCH_ENABLE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "enable touch controls" );
// code looks smaller with it // code looks smaller with it
@ -536,9 +536,15 @@ void Touch_SetClientOnly( byte state )
touch.forward = touch.side = 0; touch.forward = touch.side = 0;
if( state ) if( state )
{
Platform_SetCursorType( dc_arrow );
IN_DeactivateMouse(); IN_DeactivateMouse();
}
else else
{
Platform_SetCursorType( dc_none );
IN_ActivateMouse(); IN_ActivateMouse();
}
} }
static void Touch_SetClientOnly_f( void ) static void Touch_SetClientOnly_f( void )
@ -2182,15 +2188,9 @@ void Touch_KeyEvent( int key, int down )
float x, y; float x, y;
int finger, xi, yi; int finger, xi, yi;
if( !Touch_Emulated( )) if( !Touch_WantVisibleCursor( ))
{
if( touch_enable.value )
return; return;
if( !touch.clientonly )
return;
}
if( !key ) if( !key )
{ {
if( kidNamedFinger < 0 ) if( kidNamedFinger < 0 )
@ -2214,10 +2214,6 @@ void Touch_KeyEvent( int key, int down )
} }
} }
// don't deactivate mouse in game
// checking a case when mouse and touchscreen
// can be used simultaneously
Platform_SetCursorType( dc_arrow );
Platform_GetMousePos( &xi, &yi ); Platform_GetMousePos( &xi, &yi );
x = xi / (float)refState.width; x = xi / (float)refState.width;
@ -2233,12 +2229,7 @@ void Touch_KeyEvent( int key, int down )
qboolean Touch_WantVisibleCursor( void ) qboolean Touch_WantVisibleCursor( void )
{ {
return ( touch_enable.value && touch_emulate.value ) || touch.clientonly; return ( touch_enable.value && touch_emulate.value ) || touch.clientonly || touch_in_menu.value;
}
qboolean Touch_Emulated( void )
{
return touch_emulate.value || touch_in_menu.value;
} }
void Touch_Shutdown( void ) void Touch_Shutdown( void )

View file

@ -332,7 +332,7 @@ static void IN_MouseMove( void )
if( !in_mouseinitialized ) if( !in_mouseinitialized )
return; return;
if( Touch_Emulated( )) if( Touch_WantVisibleCursor( ))
{ {
// touch emulation overrides all input // touch emulation overrides all input
Touch_KeyEvent( 0, 0 ); Touch_KeyEvent( 0, 0 );
@ -363,7 +363,7 @@ void IN_MouseEvent( int key, int down )
else ClearBits( in_mstate, BIT( key )); else ClearBits( in_mstate, BIT( key ));
// touch emulation overrides all input // touch emulation overrides all input
if( Touch_Emulated( )) if( Touch_WantVisibleCursor( ))
{ {
Touch_KeyEvent( K_MOUSE1 + key, down ); Touch_KeyEvent( K_MOUSE1 + key, down );
} }

View file

@ -74,7 +74,6 @@ void Touch_ResetDefaultButtons( void );
int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy ); int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy );
void Touch_KeyEvent( int key, int down ); void Touch_KeyEvent( int key, int down );
qboolean Touch_WantVisibleCursor( void ); qboolean Touch_WantVisibleCursor( void );
qboolean Touch_Emulated( void );
void Touch_NotifyResize( void ); void Touch_NotifyResize( void );
// //

View file

@ -221,7 +221,7 @@ void Platform_SetCursorType( VGUI_DefaultCursor type )
} }
// never disable cursor in touch emulation mode // never disable cursor in touch emulation mode
if( !visible && Touch_Emulated( )) if( !visible && Touch_WantVisibleCursor( ))
return; return;
host.mouse_visible = visible; host.mouse_visible = visible;