static void MoveMap( int &sel, IPreference &opt, bool ToSel, const T *mapping, unsigned cnt )
{
	if( ToSel )
	{
		RString sOpt = opt.ToString();
		// This should really be T, but we can't FromString an enum.
		float val;
		FromString( sOpt, val );
		sel = FindClosestEntry( val, mapping, cnt );
	} else {
		// sel -> opt
		RString sOpt = ToString( mapping[sel] );
		opt.FromString( sOpt );
	}
}
예제 #2
0
 static int GetPreference( T* p, lua_State *L )
 {
     CString sName = SArg(1);
     IPreference *pPref = PREFSMAN->GetPreferenceByName( sName );
     if( pPref == NULL )
     {
         LOG->Warn( "GetPreference: unknown preference \"%s\"", sName.c_str() );
         lua_pushnil( L );
     }
     else
     {
         pPref->PushValue( L );
     }
     return 1;
 }
예제 #3
0
static void MovePref( int &iSel, bool bToSel, const ConfOption *pConfOption )
{
	IPreference *pPref = PREFSMAN->GetPreferenceByName( pConfOption->name );
	ASSERT_M( pPref != NULL, pConfOption->name );

	if( bToSel )
	{
		const CString sVal = pPref->ToString();
		iSel = atoi( sVal );
	}
	else
	{
		const CString sVal = ToString(iSel);
		pPref->FromString( sVal );
	}
}
static void MovePref( int &iSel, bool bToSel, const ConfOption *pConfOption )
{
	IPreference *pPref = IPreference::GetPreferenceByName( pConfOption->m_sPrefName );
	ASSERT_M( pPref != NULL, pConfOption->m_sPrefName );

	if( bToSel )
	{
		// TODO: why not get the int directly from pPref?
		// Why are we writing it to a string and then back?
		T t;
		FromString( pPref->ToString(), t );
		iSel = static_cast<int>( t );
	}
	else
	{
		pPref->FromString( ToString( static_cast<T>( iSel ) ) );
	}
}
예제 #5
0
    static int SetPreference( T* p, lua_State *L )
    {
        CString sName = SArg(1);

        IPreference *pPref = PREFSMAN->GetPreferenceByName( sName );
        if( pPref == NULL )
        {
            LOG->Warn( "GetPreference: unknown preference \"%s\"", sName.c_str() );
        }
        else
        {
            lua_pushvalue( L, 2 );
            pPref->SetFromStack( L );
        }
        PREFSMAN->SaveGlobalPrefsToDisk();

        return 0;
    }
void MovePref<bool>( int &iSel, bool bToSel, const ConfOption *pConfOption )
{
	IPreference *pPref = IPreference::GetPreferenceByName( pConfOption->m_sPrefName );
	ASSERT_M( pPref != NULL, pConfOption->m_sPrefName );

	if( bToSel )
	{
		// TODO: why not get the int directly from pPref?
		// Why are we writing it to a string and then back?
		bool b;
		FromString( pPref->ToString(), b );
		iSel = b ? 1 : 0;
	}
	else
	{
		// If we don't make a specific instantiation of MovePref<bool>, there is
		// a compile warning here because of static_cast<bool>( iSel ) where
		// iSel is an int. What is the best way to remove that compile warning?
		pPref->FromString( ToString<bool>( iSel ? true : false ) );
	}
}