示例#1
0
	// Used by menu to focus keybinding
	void Keymapper::FocusBindAction(std::string p_actionId)
	{
		std::string processedActionId = KeybindString(p_actionId);
		if(m_actionMap.find(processedActionId) == m_actionMap.end())
			ActionFromString(m_actionMap[processedActionId], processedActionId);
		m_bindAction = &m_actionMap[KeybindString(p_actionId)];
	}
示例#2
0
	void Keymapper::SetActionBinding(std::string p_actionId, SDL_Scancode p_key)
	{
		std::string processedActionId = KeybindString(p_actionId);
		ActionFromString(m_actionMap[processedActionId], processedActionId);
		m_actionMap[processedActionId].Bindings.clear();
		m_actionMap[processedActionId].Bindings.push_back(p_key);
	}
// add a binding to the list. Calls should be in the form:
//   AddBinding( "left", "button_press", "start", "+dota_camera_follow", "" );
//
// args:
//   hand_str = "left" or "right"
//   action_str = 'button_press' 'trigger_press' 'tilt_gesture' 'point_gesture' 'velocity_gesture' or 'joystick_move'
//   argument_str depends on action_str, see below for details
//   press_command_str is the concommand executed on start of the action (ie button press) and release_command_str on stop (ie button release)
//   release_command_str can be the empty string if no stop action is desired
//   if the press_command_str begins with "+", an equivalent "-" is set to the release_command automatically
void SixenseGestureBindings::AddBinding( CUtlString hand_str, CUtlString action_str, CUtlString argument_str, CUtlString press_command_str, CUtlString release_command_str ) 
{
	GestureBinding binding;

	// Convert from strings to enums
	sixenseUtils::IButtonStates::ActionType action;
	if( !ActionFromString( action_str, &action ) ) 
	{
		return;
	}

	binding.m_Action = action;

	int hand;
	if( !HandFromString( hand_str, &hand ) ) {
		return;
	}

	binding.m_iHand = hand;


	// handle argument_str per-action type
	if( action == sixenseUtils::IButtonStates::ACTION_BUTTON_PRESS ) 
	{

		// button_press takes a button argument
		unsigned short button_token;
		if( !ButtonMaskFromString( argument_str, &button_token ) )
		{
			return;
		}

		binding.m_iArgument = button_token;
	} 
	else if( action == sixenseUtils::IButtonStates::ACTION_TRIGGER_PRESS ) 
	{
		// trigger press has no argument
		binding.m_iArgument = 0;
	}
	else
	{
		// all other actions take a direction
		sixenseUtils::IButtonStates::Direction dir;
		if( !DirectionFromString( argument_str, &dir ) )
		{
			return;
		}

		binding.m_iArgument = dir;

	}


	// copy the activate command
	binding.m_pActivateCommand = strdup( press_command_str.String() );

	binding.m_bAutoMirrored = false;

	// if there is an explicit release_command, use it
	if ( !release_command_str.IsEmpty() )
	{
		binding.m_pDeactivateCommand = strdup( release_command_str.String() );
	}
	else
	{
		// otherwise try to generate a release command

		// see if it starts with a +, if so, add an off command
		if( press_command_str[0] == '+' ) 
		{
			binding.m_pDeactivateCommand = strdup( press_command_str.String() );
			binding.m_pDeactivateCommand[0] = '-';
			binding.m_bAutoMirrored = true;
		}
		else
		{
			// Just leave release command null
			binding.m_pDeactivateCommand = NULL;
		}
	}

	// Try to keep a single binding per 'action' 'hand' 'arg' pair, ie one per button.
	// We may want to allow multiple if people think it would be useful...
	FOR_EACH_LL( m_GestureBindingList, it )
	{
		GestureBinding existing_binding = m_GestureBindingList[it];

		if( binding.m_Action == existing_binding.m_Action &&
			binding.m_iArgument == existing_binding.m_iArgument &&
			binding.m_iHand == existing_binding.m_iHand ) 
		{
			// Already the same binding active, delete it
			FreeStrings( existing_binding );
			m_GestureBindingList.Remove( it );
			break;
		}
	}