Ejemplo n.º 1
0
// Save an analog binding to the consle
void CMenuJoystickAxisBase::SaveToConsoleAnalog(CClientDE *pClientDE)
{
	// set the new scale if it has been adjusted or was never read in
	m_fScale = ScaleToRange((float)m_nSensitivity, (float)SENSITIVITYSLIDERLOW, (float)SENSITIVITYSLIDERHIGH, m_fScaleCenter-m_fScaleRangeDiv2, m_fScaleCenter+m_fScaleRangeDiv2);
	if (m_fScale < 0.001) m_fScale = 0.001f; // don't let the scale get too small

	// adjust values for the invert axis flag if it has been adjusted or was never read in
	if (m_bInvertAxis)
	{
		if (m_fRangeScaleMin < m_fRangeScaleMax)
		{
			float fTemp;
			fTemp = m_fRangeScaleMin;
			m_fRangeScaleMin = m_fRangeScaleMax;
			m_fRangeScaleMax = fTemp;
		}
	}
	else
	{
		if (m_fRangeScaleMin > m_fRangeScaleMax)
		{
			float fTemp;
			fTemp = m_fRangeScaleMin;
			m_fRangeScaleMin = m_fRangeScaleMax;
			m_fRangeScaleMax = fTemp;
		}
	}

	// set the center offsets if it has changed or was never read in
	if (m_bCenterOffset) m_fRangeScalePreCenterOffset = 100.0f;
	else m_fRangeScalePreCenterOffset = 0.0f;

	// write out the rangebind and rangescale
	if ((m_sDeviceName[0] != '\0') && (m_sTriggerName[0] != '\0') && (m_sActionName[0] != '\0'))
	{
		char tempStr[1024];
		if (m_bAddDigitalBindingsToAnalog)
		{
			if (m_bInvertAxis)
			{
				sprintf(tempStr, "rangebind \"%s\" \"%s\" %f %f \"%s\" %f %f \"%s\" %f %f \"%s\"", m_sDeviceName, m_sTriggerName, 0.0f, 0.0f, m_sActionAnalog,
					(m_fDeadZone*m_fScale)-0.001f, (1.0f*m_fScale)+0.001f, m_sActionDigitalLow, -((m_fDeadZone*m_fScale)-0.001f), -((1.0f*m_fScale)+0.001f), m_sActionDigitalHigh);
			}
			else
			{
				sprintf(tempStr, "rangebind \"%s\" \"%s\" %f %f \"%s\" %f %f \"%s\" %f %f \"%s\"", m_sDeviceName, m_sTriggerName, 0.0f, 0.0f, m_sActionAnalog,
					(m_fDeadZone*m_fScale)-0.001f, (1.0f*m_fScale)+0.001f, m_sActionDigitalHigh, -((m_fDeadZone*m_fScale)-0.001f), -((1.0f*m_fScale)+0.001f), m_sActionDigitalLow);
			}
		}
		else
		{
			sprintf(tempStr, "rangebind \"%s\" \"%s\" %f %f \"%s\"", m_sDeviceName, m_sTriggerName, 0.0f, 0.0f, m_sActionAnalog);
		}
		pClientDE->RunConsoleString(tempStr);
		DoRangeScale(pClientDE, m_sDeviceName, m_sTriggerName, m_fScale, m_fRangeScaleMin, m_fRangeScaleMax, m_fRangeScalePreCenterOffset);
		//pClientDE->CPrint("Joystick Analog Binding : %s m_fScale=%f m_fRangeScaleMin=%f m_fRangeScaleMax=%f m_fRangeScalePreCenterOffset=%f ", tempStr, m_fScale, m_fRangeScaleMin, m_fRangeScaleMax, m_fRangeScalePreCenterOffset ); // BLB TEMP
	}
}
// Save variables to the console
void CJoystickAxisBase::SaveToConsole(ILTClient *pClientDE)
{
		// clear the old binding
	if (m_bBindingsRead)
	{
		if (m_nOrigAxis > JOYSTICK_AXIS_NONE)
		{
			strncpy(m_sTriggerName, m_aryAxisInfo[m_nOrigAxis].GetName(), INPUTNAME_LEN);
			m_sTriggerName[INPUTNAME_LEN-1] = '\0';

			ClearRangeBind(pClientDE, m_sDeviceName, m_sTriggerName);
		}
	}

	// 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 > JOYSTICK_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
	}

	g_pLTClient->WriteConfigFile("autoexec.cfg");

	if (m_bBindingsRead)
	{
		GetJoystickBindingInfo(pClientDE);
	}

}
Ejemplo n.º 3
0
// Load variables from the console
void CMenuJoystickAxisBase::LoadFromConsole(CClientDE *pClientDE)
{

	if (!m_bBindingsRead)
	{
		// try to read digital bindings
		GetJoystickBindingInfo(pClientDE);
	}

	// read in the dead zone console variable
	HCONSOLEVAR hVar = pClientDE->GetConsoleVar(m_sDeadZoneConsoleVar);
	if (m_bAnalog) 
	{
		if (hVar != NULL) m_fDeadZone = pClientDE->GetVarValueFloat(hVar) / m_fScale;
		//pClientDE->CPrint("Read Dead Zone Analog : m_fDeadZone = %f m_fScale = %f ", m_fDeadZone, m_fScale ); // BLB TEMP
	}
	else
	{
		if (hVar != NULL) m_fDeadZone = pClientDE->GetVarValueFloat(hVar);
		//pClientDE->CPrint("Read Dead Zone Digital : m_fDeadZone = %f", m_fDeadZone ); // BLB TEMP
	}

	// convert all of the variables read in from the bindings to our internal controls variables
	if (m_bBindingsRead)
	{
		// figure out the index of the axis that we found
		m_nAxis = GetAxisIndex(pClientDE, m_sTriggerName);

		// scale the sensitivity slider bar from the rangescale values that we read in
		if (m_bAnalog) m_nSensitivity = (int)ScaleToRange(m_fScale, m_fScaleCenter-m_fScaleRangeDiv2, m_fScaleCenter+m_fScaleRangeDiv2, (float)SENSITIVITYSLIDERLOW, (float)SENSITIVITYSLIDERHIGH);

		// scale the dead zone that we read in to the dead zone slider bar
		m_nDeadZone = (int)ScaleToRange(m_fDeadZone, 0.0f, 0.90f, (float)DEADZONESLIDERLOW, (float)DEADZONESLIDERHIGH);

		// figure out if the bindings that were read in had inverted axis
		if (m_bAnalog)
		{
			if (m_fRangeScaleMin > m_fRangeScaleMax) m_bInvertAxis = DTRUE;
			else m_bInvertAxis = DFALSE;
		}
		else
		{
			if (stricmp(m_sActionName, m_sActionDigitalLow) == 0)
			{
				if (m_fRangeLow < m_fRangeLow2) m_bInvertAxis = DFALSE;
				else m_bInvertAxis = DTRUE;
			}
			else	
			{
				if (m_fRangeLow <= m_fRangeLow2) m_bInvertAxis = DTRUE;
				else m_bInvertAxis = DFALSE;
			}
		}

		// figure out the correct value of the center offset flag from the data read in
		if ((long)m_fRangeScalePreCenterOffset != 100) m_bCenterOffset = DFALSE;
		else m_bCenterOffset = DTRUE;
	}

	// save off the original values
	m_nOrigAxis=m_nAxis;
	m_nOrigSensitivity=m_nSensitivity;
	m_nOrigDeadZone=m_nDeadZone;
	m_bOrigInvertAxis=m_bInvertAxis;
	m_bOrigCenterOffset=m_bCenterOffset;
	m_bOrigAnalog = m_bAnalog;

	// clear the old binding
	if (m_bBindingsRead)
	{
		if (m_nAxis > MENUJOYSTICK_AXIS_NONE)
		{
			strncpy(m_sTriggerName, m_aryAxisInfo[m_nAxis].GetName(), INPUTNAME_LEN);
			m_sTriggerName[INPUTNAME_LEN-1] = '\0';

			ClearRangeBind(pClientDE, m_sDeviceName, m_sTriggerName);
		}
	}
}