Example #1
0
/*
* CG_RegisterWeaponModel
*/
struct weaponinfo_s *CG_RegisterWeaponModel( char *cgs_name, int weaponTag )
{
	char filename[MAX_QPATH];
	weaponinfo_t *weaponinfo;

	Q_strncpyz( filename, cgs_name, sizeof( filename ) );
	COM_StripExtension( filename );

	weaponinfo = CG_FindWeaponModelSpot( filename );

	if( weaponinfo->inuse == true )
		return weaponinfo;

	weaponinfo->inuse = CG_WeaponModelUpdateRegistration( weaponinfo, filename );
	if( !weaponinfo->inuse )
	{
		if( cg_debugWeaponModels->integer )
			CG_Printf( "%sWEAPmodel: Failed:%s%s\n", S_COLOR_YELLOW, filename, S_COLOR_WHITE );

		return NULL;
	}

	// find the item for this weapon and try to assign the outline color
	if( weaponTag )
	{
		gsitem_t *item = GS_FindItemByTag( weaponTag );
		if( item )
		{
			if( item->color && strlen( item->color ) > 1 )
			{
				byte_vec4_t colorByte;

				Vector4Scale( color_table[ColorIndex( item->color[1] )], 255, colorByte );
				CG_SetOutlineColor( weaponinfo->outlineColor, colorByte );
			}
		}
	}

	return weaponinfo;
}
void Rocket_GetProperty( const char *name, void *out, int len, rocketVarType_t type )
{
    if ( activeElement )
    {
        const Rocket::Core::Property *property = activeElement->GetProperty( name );

        if ( !property )
        {
            return;
        }

        switch ( type )
        {
        case ROCKET_STRING:
        {
            char *string = ( char * ) out;

            if ( property )
            {
                Q_strncpyz( string, property->Get<Rocket::Core::String>().CString(), len );
            }

            return;
        }

        case ROCKET_FLOAT:
        {
            float *f = ( float * ) out;

            if ( len != sizeof( float ) )
            {
                return;
            }

            // HACK: special case for width and height specified in non absolute units

            if ( !Q_stricmp( "width", name ) && property->unit & Rocket::Core::Property::RELATIVE_UNIT )
            {
                float base_size = 0;
                Rocket::Core::Element *parent = activeElement;

                while ( ( parent = parent->GetParentNode() ) )
                {
                    if ( ( base_size = parent->GetOffsetWidth() ) != 0 )
                    {
                        *f = activeElement->ResolveProperty( "width", base_size );
                        return;
                    }
                }
            }

            if ( !Q_stricmp( "height", name ) && property->unit & Rocket::Core::Property::RELATIVE_UNIT )
            {
                float base_size = 0;
                Rocket::Core::Element *parent = activeElement;

                while ( ( parent = parent->GetParentNode() ) )
                {
                    if ( ( base_size = parent->GetOffsetHeight() ) != 0 )
                    {
                        *f = activeElement->ResolveProperty( "height", base_size );
                        return;
                    }
                }
            }

            *f = property->Get<float>();
            return;
        }

        case ROCKET_INT:
        {
            int *i = ( int * ) out;

            if ( len != sizeof( int ) )
            {
                return;
            }

            *i = property->Get<int>();
            return;
        }

        case ROCKET_COLOR:
        {
            vec_t *outColor = ( vec_t * ) out;

            if ( len != sizeof( vec4_t ) )
            {
                return;
            }

            Rocket::Core::Colourb color = property->Get<Rocket::Core::Colourb>();
            outColor[ 0 ] = color.red, outColor[ 1 ] = color.green, outColor[ 2 ] = color.blue, outColor[ 3 ] = color.alpha;
            Vector4Scale( outColor, 1 / 255.0f, outColor );
            return;
        }
        }
    }
}