⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menujoystickaxis.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	// clear the bindings
	char str[512];
	sprintf (str, "rangebind \"%s\" \"%s\" 0 0 \"\"", m_sDeviceName, m_sTriggerName);
	pClientDE->RunConsoleString (str);

	// write out the new bindings
	if (m_bInvertAxis)
	{
		sprintf (str, "rangebind \"%s\" \"%s\" \"%f\" \"%f\" \"%s\" \"%f\" \"%f\" \"%s\"", m_sDeviceName, m_sTriggerName,
				 fRightLow, fRightHigh, m_sActionDigitalLow, fLeftLow, fLeftHigh, m_sActionDigitalHigh);
	}
	else
	{
		sprintf (str, "rangebind \"%s\" \"%s\" \"%f\" \"%f\" \"%s\" \"%f\" \"%f\" \"%s\"", m_sDeviceName, m_sTriggerName,
				 fLeftLow, fLeftHigh, m_sActionDigitalLow, fRightLow, fRightHigh, m_sActionDigitalHigh);
	}

	pClientDE->RunConsoleString (str);
	//pClientDE->CPrint("Joystick Digital Binding : %s", str ); // BLB TEMP
}


// Save variables to the console
void CMenuJoystickAxisBase::SaveToConsole(CClientDE *pClientDE)
{
	// figure out the new trigger name
	strncpy(m_sTriggerName, m_aryAxisInfo[m_nAxis].GetName(), INPUTNAME_LEN);
	m_sTriggerName[INPUTNAME_LEN-1] = '\0';

	// set the new dead zone if it has been adjusted or was never read in
	m_fDeadZone = ScaleToRange((float)m_nDeadZone, (float)DEADZONESLIDERLOW, (float)DEADZONESLIDERHIGH, 0.0f, 0.90f);
	if (m_nDeadZone == DEADZONESLIDERLOW) m_fDeadZone = 0.0f;

	// do the analog or digital binding
	if (m_nAxis > MENUJOYSTICK_AXIS_NONE) 
	{
		// clear any previous bindings to this axis
		ClearRangeBind(pClientDE, m_sDeviceName, m_sTriggerName);

		// write out the new actions in case they are not in the autoexec.cfg
		SaveNewActions(pClientDE);

		// save out analog options
		if (m_bAnalog) SaveToConsoleAnalog(pClientDE);

		// save out digital options
		else SaveToConsoleDigital(pClientDE);
	}

	// write out the dead zone console variable
	if ((m_sDeviceName[0] != '\0') && (m_sTriggerName[0] != '\0') && (m_sActionName[0] != '\0'))
	{
		float fDeadZone = m_fDeadZone;
		if (m_bAnalog) fDeadZone = m_fDeadZone * m_fScale;
		if (fDeadZone < 0.0f) fDeadZone = 0.0f;
		SetConsoleVar(pClientDE, m_sDeadZoneConsoleVar, fDeadZone);
		//pClientDE->CPrint("Saving Dead Zone : fDeadZone = %f m_fDeadZone = %f", fDeadZone, m_fDeadZone ); // BLB TEMP
	}
}

/**************************************************************************/
// Joystick Axis turn class
/**************************************************************************/

// Load from the console
void CMenuJoystickAxisTurn::LoadFromConsole(CClientDE *pClientDE)
{
	m_bBindingsRead = DFALSE;

	m_bAddDigitalBindingsToAnalog = DFALSE;

	// set up range of sensitivity scaling
	m_fScaleCenter = 0.51f;
	m_fScaleRangeDiv2 = 0.5f;

	if (!m_bBindingsRead)
	{
		// set up the default variables for this axis
		strncpy(m_sTriggerName, "none", INPUTNAME_LEN);
		m_sTriggerName[INPUTNAME_LEN-1] = '\0';
		m_fRangeScaleMin = -1.0f;
		m_fRangeScaleMax = 1.0f;
		m_nAxis = GetAxisIndex(pClientDE, m_sTriggerName);
		m_bInvertAxis = DFALSE;	
		m_nDeadZone = 2;
		m_bAnalog = DFALSE;
		m_nSensitivity = 10;		
		m_bCenterOffset = DFALSE;
	}

	// set the string names for this axis
	strncpy(m_sActionDigitalLow, "Left", MAX_ACTIONNAME_LEN);
	m_sActionDigitalLow[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionDigitalHigh, "Right", MAX_ACTIONNAME_LEN);
	m_sActionDigitalHigh[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionAnalog, "AxisYaw", MAX_ACTIONNAME_LEN);
	m_sActionAnalog[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sDeadZoneConsoleVar, "AxisYawDeadZone", MAX_ACTIONNAME_LEN+16);
	m_sDeadZoneConsoleVar[MAX_ACTIONNAME_LEN+16-1] = '\0';

	// call the base code to load everything in and set up the variables
	CMenuJoystickAxisBase::LoadFromConsole(pClientDE);
}

// Save to the console
void CMenuJoystickAxisTurn::SaveToConsole(CClientDE *pClientDE)
{
	// call base class to save bindings
	CMenuJoystickAxisBase::SaveToConsole(pClientDE);
}

/**************************************************************************/
// Joystick Axis look class
/**************************************************************************/

// Constructor
CMenuJoystickAxisLook::CMenuJoystickAxisLook()
{
	CMenuJoystickAxisBase::CMenuJoystickAxisBase();

	// Members
	m_bFixedPosition=DTRUE;

	// String IDs
	m_nFixedPositionID=IDS_MENU_JOYSTICK_LOOKUPDOWNFIXEDBYPOSITION;

	// Controls
	m_pFixedPositionCtrl=DNULL;

}

// Build the menu items
void CMenuJoystickAxisLook::Build(CClientDE *pClientDE, CMenuBase *pDestMenu)
{
	// Get the main menus pointer
	CMainMenus *pMainMenus=pDestMenu->GetMainMenus();
	if (!pMainMenus)
	{
		return;
	}

	// Call the base class
	CMenuJoystickAxisBase::Build(pClientDE, pDestMenu);

	// The center offset axis control
	m_pFixedPositionCtrl=pDestMenu->AddOnOffOption(m_nFixedPositionID, pMainMenus->GetSmallFont(), MENUJOYSTICK_ONOFFOFFSET,
												   &m_bFixedPosition);
}

// Updates the enable/disable status of each control.
// bJoystickOn indicates if the joystick is enabled in the menus.
void CMenuJoystickAxisLook::UpdateEnable(DBOOL bJoystickOn)
{
	// Call the base class
	CMenuJoystickAxisBase::UpdateEnable(bJoystickOn);

	DBOOL bEnable=DTRUE;
	if (bJoystickOn && m_bAnalog)
	{
		bEnable=DTRUE;
	}
	else
	{
		bEnable=DFALSE;
	}

	if (m_pFixedPositionCtrl)
	{
		m_pFixedPositionCtrl->Enable(bEnable);
	}
}

// Load from the console
void CMenuJoystickAxisLook::LoadFromConsole(CClientDE *pClientDE)
{
	m_bBindingsRead = DFALSE;

	m_bAddDigitalBindingsToAnalog = DFALSE;

	// read in and set up the fixed position variable
	HCONSOLEVAR hVar = pClientDE->GetConsoleVar( "FixedAxisPitch");
	if (hVar != NULL) 
	{
		if (pClientDE->GetVarValueFloat(hVar) == 1) m_bFixedPosition = TRUE;
		else m_bFixedPosition = FALSE;
	}
	else m_bFixedPosition = FALSE;

	// set up range of sensitivity scaling
	if (m_bFixedPosition) m_fScaleCenter = 1.0f;
	else m_fScaleCenter = 0.51f;
	m_fScaleRangeDiv2 = 0.5f;

	if (!m_bBindingsRead)
	{
		// set up the default variables for this axis
		strncpy(m_sTriggerName, "none", INPUTNAME_LEN);
		m_sTriggerName[INPUTNAME_LEN-1] = '\0';
		m_fRangeScaleMin = -1.0f;
		m_fRangeScaleMax = 1.0f;
		m_nAxis = GetAxisIndex(pClientDE, m_sTriggerName);
		m_bInvertAxis = DFALSE;	
		m_nDeadZone = 2;
		m_bAnalog = DFALSE;
		m_nSensitivity = 10;		
		m_bCenterOffset = DFALSE;
	}

	// set the string names for this axis
	strncpy(m_sActionDigitalLow, "LookUp", MAX_ACTIONNAME_LEN);
	m_sActionDigitalLow[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionDigitalHigh, "LookDown", MAX_ACTIONNAME_LEN);
	m_sActionDigitalHigh[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionAnalog, "AxisPitch", MAX_ACTIONNAME_LEN);
	m_sActionAnalog[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sDeadZoneConsoleVar, "AxisPitchDeadZone", MAX_ACTIONNAME_LEN+16);
	m_sDeadZoneConsoleVar[MAX_ACTIONNAME_LEN+16-1] = '\0';

	// call the base code to load everything in and set up the variables
	CMenuJoystickAxisBase::LoadFromConsole(pClientDE);
}

// Save to the console
void CMenuJoystickAxisLook::SaveToConsole(CClientDE *pClientDE)
{
	// figure out correct rangescale values based on fixedposition
	if (m_bFixedPosition)
	{
		m_fRangeScaleMin = -(3.14159265f/2.0f);
		m_fRangeScaleMax = (3.14159265f/2.0f);
		m_fScaleCenter = 1.0f;
	}
	else
	{
		m_fRangeScaleMin = -1.0;
		m_fRangeScaleMax = 1.0;
		m_fScaleCenter = 0.51f;
	}

	// call base class to save bindings
	CMenuJoystickAxisBase::SaveToConsole(pClientDE);

	// write out the fixed axis pitch console variable
	if ((m_bFixedPosition) && (m_bAnalog) && (m_nAxis > MENUJOYSTICK_AXIS_NONE)) SetConsoleVar(pClientDE, "FixedAxisPitch", 1.0);
	else SetConsoleVar(pClientDE, "FixedAxisPitch", 0.0);
}

/**************************************************************************/
// Joystick Axis move class
/**************************************************************************/

// Contructor
CMenuJoystickAxisMove::CMenuJoystickAxisMove()
{
	CMenuJoystickAxisBase::CMenuJoystickAxisBase();
}

// Load from the console
void CMenuJoystickAxisMove::LoadFromConsole(CClientDE *pClientDE)
{
	m_bBindingsRead = DFALSE;

	m_bAddDigitalBindingsToAnalog = DTRUE;

	// set up range of sensitivity scaling
	m_fScaleCenter = 1.0f;
	m_fScaleRangeDiv2 = 0.5f;

	if (!m_bBindingsRead)
	{
		// set up the default variables for this axis
		strncpy(m_sTriggerName, "none", INPUTNAME_LEN);
		m_sTriggerName[INPUTNAME_LEN-1] = '\0';
		m_fRangeScaleMin = -1.0f;
		m_fRangeScaleMax = 1.0f;
		m_nAxis = GetAxisIndex(pClientDE, m_sTriggerName);
		m_bInvertAxis = DFALSE;	
		m_nDeadZone = 2;
		m_bAnalog = DFALSE;
		m_nSensitivity = 10;		
		m_bCenterOffset = DFALSE;
	}

	// set the string names for this axis
	strncpy(m_sActionDigitalLow, "Forward", MAX_ACTIONNAME_LEN);
	m_sActionDigitalLow[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionDigitalHigh, "Backward", MAX_ACTIONNAME_LEN);
	m_sActionDigitalHigh[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionAnalog, "AxisForwardBackward", MAX_ACTIONNAME_LEN);
	m_sActionAnalog[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sDeadZoneConsoleVar, "AxisForwardBackwardDeadZone", MAX_ACTIONNAME_LEN+16);
	m_sDeadZoneConsoleVar[MAX_ACTIONNAME_LEN+16-1] = '\0';

	// call the base code to load everything in and set up the variables
	CMenuJoystickAxisBase::LoadFromConsole(pClientDE);
}

// Save to the console
void CMenuJoystickAxisMove::SaveToConsole(CClientDE *pClientDE)
{
	// call base class to save bindings
	CMenuJoystickAxisBase::SaveToConsole(pClientDE);
}

/**************************************************************************/
// Joystick Axis stafe class
/**************************************************************************/

void CMenuJoystickAxisStrafe::LoadFromConsole(CClientDE *pClientDE)
{
	m_bBindingsRead = DFALSE;

	m_bAddDigitalBindingsToAnalog = DTRUE;

	// set up range of sensitivity scaling
	m_fScaleCenter = 1.0f;
	m_fScaleRangeDiv2 = 0.5f;

	if (!m_bBindingsRead)
	{
		// set up the default variables for this axis
		strncpy(m_sTriggerName, "none", INPUTNAME_LEN);
		m_sTriggerName[INPUTNAME_LEN-1] = '\0';
		m_fRangeScaleMin = -1.0f;
		m_fRangeScaleMax = 1.0f;
		m_nAxis = GetAxisIndex(pClientDE, m_sTriggerName);
		m_bInvertAxis = DFALSE;	
		m_nDeadZone = 2;
		m_bAnalog = DFALSE;
		m_nSensitivity = 10;		
		m_bCenterOffset = DFALSE;
	}

	// set the string names for this axis
	strncpy(m_sActionDigitalLow, "StrafeLeft", MAX_ACTIONNAME_LEN);
	m_sActionDigitalLow[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionDigitalHigh, "StrafeRight", MAX_ACTIONNAME_LEN);
	m_sActionDigitalHigh[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sActionAnalog, "AxisLeftRight", MAX_ACTIONNAME_LEN);
	m_sActionAnalog[MAX_ACTIONNAME_LEN-1] = '\0';

	strncpy(m_sDeadZoneConsoleVar, "AxisLeftRightDeadZone", MAX_ACTIONNAME_LEN+16);
	m_sDeadZoneConsoleVar[MAX_ACTIONNAME_LEN+16-1] = '\0';

	// call the base code to load everything in and set up the variables
	CMenuJoystickAxisBase::LoadFromConsole(pClientDE);
}

void CMenuJoystickAxisStrafe::SaveToConsole(CClientDE *pClientDE)
{
	// call base class to save bindings
	CMenuJoystickAxisBase::SaveToConsole(pClientDE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -