game/client: fix messagemode, add acceleration for touch, GameUI: add touch options

This commit is contained in:
nillerusr
2022-04-16 12:58:59 +03:00
parent 0feeab91dd
commit ab5c1c0b3a
12 changed files with 505 additions and 76 deletions

View File

@@ -52,6 +52,7 @@
#include "replay/vgui/replaymessagepanel.h"
#include "econ/econ_controls.h"
#include "econ/confirm_dialog.h"
extern IClientReplayContext *g_pClientReplayContext;
extern ConVar replay_rendersetting_renderglow;
#endif
@@ -144,6 +145,18 @@ CON_COMMAND( hud_reloadscheme, "Reloads hud layout and animation scripts." )
mode->ReloadScheme();
}
CON_COMMAND( messagemode, "Opens chat dialog" )
{
ClientModeShared *mode = ( ClientModeShared * )GetClientModeNormal();
mode->StartMessageMode( MM_SAY );
}
CON_COMMAND( messagemode2, "Opens chat dialog" )
{
ClientModeShared *mode = ( ClientModeShared * )GetClientModeNormal();
mode->StartMessageMode( MM_SAY_TEAM );
}
#ifdef _DEBUG
CON_COMMAND_F( crash, "Crash the client. Optional parameter -- type of crash:\n 0: read from NULL\n 1: write to NULL\n 2: DmCrashDump() (xbox360 only)", FCVAR_CHEAT )
{
@@ -632,28 +645,6 @@ int ClientModeShared::KeyInput( int down, ButtonCode_t keynum, const char *pszCu
if ( engine->Con_IsVisible() )
return 1;
// Should we start typing a message?
if ( pszCurrentBinding &&
( Q_strcmp( pszCurrentBinding, "messagemode" ) == 0 ||
Q_strcmp( pszCurrentBinding, "say" ) == 0 ) )
{
if ( down )
{
StartMessageMode( MM_SAY );
}
return 0;
}
else if ( pszCurrentBinding &&
( Q_strcmp( pszCurrentBinding, "messagemode2" ) == 0 ||
Q_strcmp( pszCurrentBinding, "say_team" ) == 0 ) )
{
if ( down )
{
StartMessageMode( MM_SAY_TEAM );
}
return 0;
}
// If we're voting...
#ifdef VOTING_ENABLED
CHudVote *pHudVote = GET_HUDELEMENT( CHudVote );

View File

@@ -947,7 +947,8 @@ void CInput::ControllerMove( float frametime, CUserCmd *cmd )
}
JoyStickMove( frametime, cmd);
gTouch.Move( frametime, cmd );
TouchMove( cmd );
// NVNT if we have a haptic device..
if(haptics && haptics->HasDevice())
@@ -1194,9 +1195,9 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo
// Using joystick?
#ifdef SIXENSE
if ( in_joystick.GetInt() || g_pSixenseInput->IsEnabled() )
if ( in_joystick.GetInt() || g_pSixenseInput->IsEnabled() || touch_enable.GetInt() )
#else
if ( in_joystick.GetInt() )
if ( in_joystick.GetInt() || touch_enable.GetInt() )
#endif
{
if ( cmd->forwardmove > 0 )

113
game/client/in_touch.cpp Normal file
View File

@@ -0,0 +1,113 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Mouse input routines
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//===========================================================================//
#if defined( WIN32 ) && !defined( _X360 )
#define _WIN32_WINNT 0x0502
#include <windows.h>
#endif
#include "cbase.h"
#include "hud.h"
#include "cdll_int.h"
#include "kbutton.h"
#include "basehandle.h"
#include "usercmd.h"
#include "input.h"
#include "iviewrender.h"
#include "iclientmode.h"
#include "tier0/icommandline.h"
#include "vgui/ISurface.h"
#include "vgui_controls/Controls.h"
#include "vgui/Cursor.h"
#include "cdll_client_int.h"
#include "cdll_util.h"
#include "tier1/convar_serverbounded.h"
#include "cam_thirdperson.h"
#include "inputsystem/iinputsystem.h"
#include "touch.h"
// up / down
#define PITCH 0
// left / right
#define YAW 1
extern ConVar cl_sidespeed;
extern ConVar cl_forwardspeed;
extern ConVar sensitivity;
extern ConVar lookstrafe;
extern ConVar thirdperson_platformer;
extern ConVar touch_pitch;
extern ConVar touch_yaw;
extern ConVar default_fov;
#ifdef PORTAL
extern bool g_bUpsideDown;
#endif
ConVar touch_enable_accel( "touch_enable_accel", "0", FCVAR_ARCHIVE );
ConVar touch_accel( "touch_accel", "1.f", FCVAR_ARCHIVE );
ConVar touch_reverse( "touch_reverse", "0", FCVAR_ARCHIVE );
ConVar touch_sensitivity( "touch_sensitivity", "3.0", FCVAR_ARCHIVE, "touch look sensitivity" );
void CInput::TouchScale( float &dx, float &dy )
{
dx *= touch_yaw.GetFloat();
dy *= touch_pitch.GetFloat();
float sensitivity = touch_sensitivity.GetFloat() * gHUD.GetFOVSensitivityAdjust() * ( touch_reverse.GetBool() ? -1.f : 1.f );
if( touch_enable_accel.GetBool() )
{
float raw_touch_movement_distance_squared = dx * dx + dy * dy;
float fExp = MAX(0.0f, (touch_accel.GetFloat() - 1.0f) / 2.0f);
float accelerated_sensitivity = powf( raw_touch_movement_distance_squared, fExp ) * sensitivity;
dx *= accelerated_sensitivity;
dy *= accelerated_sensitivity;
}
else
{
dx *= sensitivity;
dy *= sensitivity;
}
}
void CInput::ApplyTouch( QAngle &viewangles, CUserCmd *cmd, float dx, float dy )
{
viewangles[YAW] -= dx;
viewangles[PITCH] += dy;
cmd->mousedx = dx;
cmd->mousedy = dy;
}
void CInput::TouchMove( CUserCmd *cmd )
{
QAngle viewangles;
float dx,dy,side,forward,pitch,yaw;
engine->GetViewAngles( viewangles );
view->StopPitchDrift();
gTouch.GetTouchAccumulators( &side, &forward, &yaw, &pitch );
cmd->sidemove -= cl_sidespeed.GetFloat() * side;
cmd->forwardmove += cl_forwardspeed.GetFloat() * forward;
gTouch.GetTouchDelta( yaw, pitch, &dx, &dy );
TouchScale( dx, dy );
// Let the client mode at the mouse input before it's used
g_pClientMode->OverrideMouseInput( &dx, &dy );
// Add mouse X/Y movement to cmd
ApplyTouch( viewangles, cmd, dx, dy );
// Store out the new viewangles.
engine->SetViewAngles( viewangles );
}

View File

@@ -135,7 +135,10 @@ private:
void GetMouseDelta( float inmousex, float inmousey, float *pOutMouseX, float *pOutMouseY );
void ScaleMouse( float *x, float *y );
void ApplyMouse( QAngle& viewangles, CUserCmd *cmd, float mouse_x, float mouse_y );
void MouseMove ( CUserCmd *cmd );
void MouseMove( CUserCmd *cmd );
void TouchMove( CUserCmd *cmd );
void TouchScale( float &dx, float &dy );
void ApplyTouch( QAngle &viewangles, CUserCmd *cmd, float dx, float dy );
// Joystick movement input helpers
void ControllerMove ( float frametime, CUserCmd *cmd );
@@ -287,4 +290,4 @@ extern void KeyUp( kbutton_t *b, const char *c );
#endif // INPUT_H

View File

@@ -28,6 +28,8 @@ extern ConVar sensitivity;
#define TOUCH_DEFAULT_CFG "touch_default.cfg"
ConVar touch_enable( "touch_enable", TOUCH_DEFAULT, FCVAR_ARCHIVE );
ConVar touch_draw( "touch_draw", "1", FCVAR_ARCHIVE );
ConVar touch_filter( "touch_filter", "0", FCVAR_ARCHIVE );
ConVar touch_forwardzone( "touch_forwardzone", "0.06", FCVAR_ARCHIVE, "forward touch zone" );
ConVar touch_sidezone( "touch_sidezone", "0.06", FCVAR_ARCHIVE, "side touch zone" );
ConVar touch_pitch( "touch_pitch", "90", FCVAR_ARCHIVE, "touch pitch sensitivity" );
@@ -258,6 +260,36 @@ CON_COMMAND( touch_toggleselection, "toggle visibility on selected button in edi
}*/
void CTouchControls::GetTouchAccumulators( float *side, float *forward, float *yaw, float *pitch )
{
*forward = this->forward;
*side = this->side;
*pitch = this->pitch;
*yaw = this->yaw;
this->yaw = 0.f;
this->pitch = 0.f;
}
void CTouchControls::GetTouchDelta( float yaw, float pitch, float *dx, float *dy )
{
// Apply filtering?
if( touch_filter.GetBool() )
{
// Average over last two samples
*dx = ( yaw + m_flPreviousYaw ) * 0.5f;
*dy = ( pitch + m_flPreviousPitch ) * 0.5f;
}
else
{
*dx = yaw;
*dy = pitch;
}
// Latch previous
m_flPreviousYaw = yaw;
m_flPreviousPitch = pitch;
}
void CTouchControls::ResetToDefaults()
{
rgba_t color(255, 255, 255, 155);
@@ -291,7 +323,7 @@ void CTouchControls::ResetToDefaults()
else
{
Q_snprintf(buf, sizeof buf, "exec %s", TOUCH_DEFAULT_CFG);
engine->ClientCmd_Unrestricted(buf);
engine->ExecuteClientCmd(buf);
}
WriteConfig();
@@ -307,7 +339,8 @@ void CTouchControls::Init()
config_loaded = false;
btns.EnsureCapacity( 64 );
look_finger = move_finger = resize_finger = -1;
forward = side = 0;
forward = side = 0.f;
pitch = yaw = 0.f;
scolor = rgba_t( -1, -1, -1, -1 );
state = state_none;
swidth = 1;
@@ -317,6 +350,7 @@ void CTouchControls::Init()
precision = false;
mouse_events = 0;
move_start_x = move_start_y = 0.0f;
m_flPreviousYaw = m_flPreviousPitch = 0.f;
showtexture = hidetexture = resettexture = closetexture = joytexture = 0;
configchanged = false;
@@ -344,12 +378,15 @@ void CTouchControls::Init()
AddButton( "menu", "vgui/touch/menu", "gameui_activate", 0.000000, 0.00000, 0.080000, 0.142222, color );
char buf[256];
Q_snprintf(buf, sizeof buf, "exec %s\n", touch_config_file.GetString());
engine->ClientCmd_Unrestricted(buf);
Q_snprintf(buf, sizeof buf, "cfg/%s", touch_config_file.GetString());
if( !filesystem->FileExists(buf) )
WriteConfig();
if( filesystem->FileExists(buf, "MOD") )
{
Q_snprintf(buf, sizeof buf, "exec %s\n", touch_config_file.GetString());
engine->ClientCmd_Unrestricted(buf);
}
else
ResetToDefaults();
initialized = true;
}
@@ -405,32 +442,10 @@ void CTouchControls::IN_CheckCoords( float *x1, float *y1, float *x2, float *y2
void CTouchControls::Move( float /*frametime*/, CUserCmd *cmd )
{
cmd->sidemove -= cl_sidespeed.GetFloat() * side;
cmd->forwardmove += cl_forwardspeed.GetFloat() * forward;
}
void CTouchControls::IN_Look()
{
C_BasePlayer *pl = C_BasePlayer::GetLocalPlayer();
float diff = 1.0f;
if( pl )
{
float def_fov = default_fov.GetFloat();
float fov = pl->GetFOV();
diff = fov/def_fov;
}
if( !pitch && !yaw )
return;
QAngle ang;
engine->GetViewAngles( ang );
ang.x += pitch*diff;
ang.y += yaw*diff;
engine->SetViewAngles( ang );
pitch = yaw = 0;
}
void CTouchControls::Frame()
@@ -438,9 +453,7 @@ void CTouchControls::Frame()
if (!initialized)
return;
IN_Look();
if( touch_enable.GetBool() && !enginevgui->IsGameUIVisible() ) Paint();
if( touch_enable.GetBool() && touch_draw.GetBool() && !enginevgui->IsGameUIVisible() ) Paint();
}
void CTouchControls::Paint( )
@@ -448,12 +461,11 @@ void CTouchControls::Paint( )
if (!initialized)
return;
if( state == state_edit )
{
vgui::surface()->DrawSetColor(255, 0, 0, 200);
float x,y;
for( x = 0.0f; x < 1.0f; x += GRID_X )
vgui::surface()->DrawLine( screen_w*x, 0, screen_w*x, screen_h );
@@ -472,7 +484,7 @@ void CTouchControls::Paint( )
vgui::surface()->DrawSetColor(btn->color.r, btn->color.g, btn->color.b, btn->color.a);
vgui::surface()->DrawTexturedRect( btn->x1*screen_w, btn->y1*screen_h, btn->x2*screen_w, btn->y2*screen_h );
}
if( state == state_edit && !(btn->flags & TOUCH_FL_NOEDIT) )
{
vgui::surface()->DrawSetColor(255, 0, 0, 50);
@@ -694,8 +706,8 @@ void CTouchControls::FingerMotion(touch_event_t *ev) // finger in my ass
}
else if( btn->type == touch_look )
{
yaw -= touch_yaw.GetFloat() * ev->dx * sensitivity.GetFloat();
pitch += touch_pitch.GetFloat() * ev->dy * sensitivity.GetFloat();
yaw += ev->dx;
pitch += ev->dy;
}
}
}
@@ -707,7 +719,7 @@ void CTouchControls::FingerPress(touch_event_t *ev)
const float y = ev->y;
CUtlLinkedList<CTouchButton*>::iterator it;
if( ev->type == IE_FingerDown )
{
for( it = btns.begin(); it != btns.end(); it++ )
@@ -717,7 +729,7 @@ void CTouchControls::FingerPress(touch_event_t *ev)
{
if( btn->flags & TOUCH_FL_HIDE )
continue;
btn->finger = ev->fingerid;
if( btn->type == touch_move )
{

View File

@@ -174,24 +174,25 @@ public:
void SetCommand( const char *name, const char *cmd );
void SetFlags( const char *name, int flags );
void WriteConfig();
void IN_CheckCoords( float *x1, float *y1, float *x2, float *y2 );
void InitGrid();
void Move( float frametime, CUserCmd *cmd );
void IN_Look( );
void ProcessEvent( touch_event_t *ev );
void FingerPress( touch_event_t *ev );
void FingerMotion( touch_event_t *ev );
void GetTouchAccumulators( float *forward, float *side, float *yaw, float *pitch );
void GetTouchDelta( float yaw, float pitch, float *dx, float *dy );
void EditEvent( touch_event_t *ev );
void EnableTouchEdit(bool enable);
CTouchPanel *touchPanel;
float screen_h, screen_w;
float forward, side, movecount;
float yaw, pitch;
private:
bool initialized = false;
@@ -199,11 +200,10 @@ private:
CUtlLinkedList<CTouchButton*> btns;
int look_finger, move_finger, wheel_finger;
float forward, side, movecount;
float yaw, pitch;
CTouchButton *move_button;
float move_start_x, move_start_y;
float m_flPreviousYaw, m_flPreviousPitch;
// editing
CTouchButton *edit;

View File

@@ -15,6 +15,7 @@ games = {
'hl2': ['client_base.vpc', 'client_hl2.vpc'],
'hl2mp': ['client_base.vpc', 'client_hl2mp.vpc'],
'hl1': ['client_base.vpc', 'client_hl1.vpc'],
'episodic': ['client_base.vpc', 'client_episodic.vpc'],
'portal': ['client_base.vpc', 'client_portal.vpc'],
'hl1mp': ['client_base.vpc', 'client_hl1.vpc'],
'cstrike': ['client_base.vpc', 'client_cstrike.vpc'],
@@ -25,6 +26,8 @@ def configure(conf):
game = conf.options.GAMES
conf.env.GAMES = game
conf.env.append_unique('DEFINES', ['DISABLE_STEAM=1'])
if game not in games.keys():
conf.fatal("Couldn't find game: ", game)
@@ -66,7 +69,7 @@ def build(bld):
if bld.env.DEST_OS != 'android':
install_path += '/'+bld.env.GAMES+'/bin'
source = [ 'touch.cpp' ]
source = [ 'touch.cpp', 'in_touch.cpp' ]
source += game["sources"]
includes += game["includes"]