Esempio n. 1
0
/*
=================
CG_KeysStringForBinding
=================
*/
void CG_KeysStringForBinding(const char *binding, char *string, int stringSize ) {
	char name2[32];
	int keys[2];
	int i, key;

	for ( i = 0, key = 0; i < 2; i++ )
	{
		key = trap_Key_GetKey( binding, key );
		keys[i] = key;
		key++;
	}

	if (keys[0] == -1) {
		Q_strncpyz( string, "???", stringSize );
		return;
	}

	trap_Key_KeynumToStringBuf( keys[0], string, MIN( 32, stringSize ) );
	Q_strupr(string);

	if (keys[1] != -1)
	{
		trap_Key_KeynumToStringBuf( keys[1], name2, 32 );
		Q_strupr(name2);

		Q_strcat( string, stringSize, " or " );
		Q_strcat( string, stringSize, name2 );
	}
}
Esempio n. 2
0
/*
================
CG_KeyBinding
================
*/
char *CG_KeyBinding( const char *bind )
{
	static char key[ 32 ];
	char        bindbuff[ MAX_CVAR_VALUE_STRING ];
	int         i;

	key[ 0 ] = '\0';

	// NOTE: change K_LAST_KEY to MAX_KEYS for full key support (eventually)
	for ( i = 0; i < K_LAST_KEY; i++ )
	{
		trap_Key_GetBindingBuf( i, bindbuff, sizeof( bindbuff ) );

		if ( !Q_stricmp( bindbuff, bind ) )
		{
			trap_Key_KeynumToStringBuf( i, key, sizeof( key ) );
			break;
		}
	}

	if ( !key[ 0 ] )
	{
		Q_strncpyz( key, "\\", sizeof( key ) );
		Q_strcat( key, sizeof( key ), bind );
	}

	return key;
}
Esempio n. 3
0
/*
===============
CG_KeyNameForCommand
===============
*/
static const char *CG_KeyNameForCommand( const char *command )
{
	unsigned    i;
	static char buffer[ 2 ][ MAX_STRING_CHARS ];
	static int  which = 1;
	char        keyName[ 2 ][ 32 ];

	which ^= 1;

	buffer[ which ][ 0 ] = '\0';

	for ( i = 0; i < numBindings; i++ )
	{
		if ( !Q_stricmp( command, bindings[ i ].command ) )
		{
			if ( bindings[ i ].keys[ 0 ] != K_NONE )
			{
				trap_Key_KeynumToStringBuf( bindings[ i ].keys[ 0 ],
				                            keyName[ 0 ], sizeof( keyName[ 0 ] ) );

				if ( bindings[ i ].keys[ 1 ] != K_NONE )
				{
					trap_Key_KeynumToStringBuf( bindings[ i ].keys[ 1 ],
					                            keyName[ 1 ], sizeof( keyName[ 1 ] ) );
					Q_snprintf( buffer[ which ], sizeof( buffer[ 0 ] ), _("%s or %s"),
					            Q_strupr( keyName[ 0 ] ), Q_strupr( keyName[ 1 ] ) );
				}
				else
				{
					Q_strncpyz( buffer[ which ], Q_strupr( keyName[ 0 ] ), sizeof( buffer[ 0 ] ) );
				}
			}
			else
			{
				Com_sprintf( buffer[ which ], MAX_STRING_CHARS, _( "\"%s\" (unbound)" ),
				             _( bindings[ i ].humanName ) );
			}

			return buffer[ which ];
		}
	}

	return "(⚠ BUG)"; // shouldn't happen: if it does, BUG
}
/*
===============
CG_KeyNameForCommand
===============
*/
static const char *CG_KeyNameForCommand( const char *command )
{
  int         i, j;
  static char buffer[ MAX_STRING_CHARS ];
  int         firstKeyLength;

  buffer[ 0 ] = '\0';

  for( i = 0; i < numBindings; i++ )
  {
    if( !Q_stricmp( command, bindings[ i ].command ) )
    {
      if( bindings[ i ].keys[ 0 ] != K_NONE )
      {
        trap_Key_KeynumToStringBuf( bindings[ i ].keys[ 0 ],
            buffer, MAX_STRING_CHARS );
        firstKeyLength = strlen( buffer );

        for( j = 0; j < firstKeyLength; j++ )
          buffer[ j ] = toupper( buffer[ j ] );

        if( bindings[ i ].keys[ 1 ] != K_NONE )
        {
          Q_strcat( buffer, MAX_STRING_CHARS, " or " );
          trap_Key_KeynumToStringBuf( bindings[ i ].keys[ 1 ],
              buffer + strlen( buffer ), MAX_STRING_CHARS - strlen( buffer ) );

          for( j = firstKeyLength + 4; j < strlen( buffer ); j++ )
            buffer[ j ] = toupper( buffer[ j ] );
        }
      }
      else
      {
        Q_strncpyz( buffer, va( "\"%s\"", bindings[ i ].humanName ),
            MAX_STRING_CHARS );
        Q_strcat( buffer, MAX_STRING_CHARS, " (unbound)" );
      }

      return buffer;
    }
  }

  return "";
}
Esempio n. 5
0
char *CG_getBindKeyName(const char *cmd, char *buf, int len)
{
	int j;

	for(j=0; j<256; j++) {
		trap_Key_GetBindingBuf(j, buf, len);
		if(*buf == 0) continue;

		if(!Q_stricmp(buf, cmd)) {
			trap_Key_KeynumToStringBuf(j, buf, MAX_STRING_TOKENS);
			Q_strupr(buf);
			return(buf);
		}
	}

	Q_strncpyz(buf, va("(%s)", cmd), len);
	return(buf);
}
/*
=================
Controls_DrawKeyBinding
=================
*/
static void Controls_DrawKeyBinding( void *self )
{
	menuaction_s*	a;
	int				x;
	int				y;
	int				b1;
	int				b2;
	qboolean		c;
	char			name[32];
	char			name2[32];

	a = (menuaction_s*) self;

	x =	a->generic.x;
	y = a->generic.y;

	c = (Menu_ItemAtCursor( a->generic.parent ) == a);

	b1 = g_bindings[a->generic.id].bind1;
	if (b1 == -1)
		strcpy(name,"???");
	else
	{
		trap_Key_KeynumToStringBuf( b1, name, 32 );
		Q_strupr(name);

		b2 = g_bindings[a->generic.id].bind2;
		if (b2 != -1)
		{
			trap_Key_KeynumToStringBuf( b2, name2, 32 );
			Q_strupr(name2);

			strcat( name, " or " );
			strcat( name, name2 );
		}
	}

	if (c)
	{
		UI_FillRect( a->generic.left, a->generic.top, a->generic.right-a->generic.left+1, a->generic.bottom-a->generic.top+1, listbar_color ); 

		UI_DrawString( x - SMALLCHAR_WIDTH, y, g_bindings[a->generic.id].label, UI_RIGHT|UI_SMALLFONT, text_color_highlight );
		UI_DrawString( x + SMALLCHAR_WIDTH, y, name, UI_LEFT|UI_SMALLFONT|UI_PULSE, text_color_highlight );

		if (s_controls.waitingforkey)
		{
			UI_DrawChar( x, y, '=', UI_CENTER|UI_BLINK|UI_SMALLFONT, text_color_highlight);
			UI_DrawString(500, SCREEN_HEIGHT * 0.85, "Waiting for new key ... ESCAPE to cancel", UI_SMALLFONT|UI_CENTER|UI_PULSE, colorWhite );
		}
		else
		{
			UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, text_color_highlight);
			UI_DrawString(500, SCREEN_HEIGHT * 0.83, "Press ENTER or CLICK to change", UI_SMALLFONT|UI_CENTER, colorWhite );
			UI_DrawString(500, SCREEN_HEIGHT * 0.87, "Press BACKSPACE to clear", UI_SMALLFONT|UI_CENTER, colorWhite );
		}
	}
	else
	{
		if (a->generic.flags & QMF_GRAYED)
		{
			UI_DrawString( x - SMALLCHAR_WIDTH, y, g_bindings[a->generic.id].label, UI_RIGHT|UI_SMALLFONT, text_color_disabled );
			UI_DrawString( x + SMALLCHAR_WIDTH, y, name, UI_LEFT|UI_SMALLFONT, text_color_disabled );
		}
		else
		{
			UI_DrawString( x - SMALLCHAR_WIDTH, y, g_bindings[a->generic.id].label, UI_RIGHT|UI_SMALLFONT, controls_binding_color );
			UI_DrawString( x + SMALLCHAR_WIDTH, y, name, UI_LEFT|UI_SMALLFONT, controls_binding_color );
		}
	}
}