コード例 #1
0
/*
 *******************************************************************
 * Function: CKBehavior* GetTargetCommand(const int commandId, const CKBehaviorContext& behaviorContext)
 *
 * Description : Gets target behavior object given the command ID
 *		
 * Paramters :
 *
 *   commandId			r   command id of the target object to get 
 *   behaviorContext    r   context
 *
 * Returns : 
 *              pointer to the behavior object, NULL if no object found
 *
 *******************************************************************
 */
CKBehavior* CGBLCommandController::GetTargetCommand(const int commandId, const CKBehaviorContext& behaviorContext)
{
    CKBehavior* targetBehavior = NULL;
	CKContext* context = behaviorContext.Context;

	int behaviorCount = context->GetObjectsCountByClassID(CKCID_BEHAVIOR);
	CK_ID* behaviorIds = context->GetObjectsListByClassID(CKCID_BEHAVIOR);

	int currentID;
	for (int i = 0; i < behaviorCount; ++i) 
	{
		CKBehavior* behavior = (CKBehavior*)context->GetObject(behaviorIds[i]);
		if (behavior->GetPrototypeGuid() == GUID_GBLWAITFORCOMMAND_PROTOTYPE)
		{
			CKParameterLocal *localParam = NULL;
            localParam = behavior->GetLocalParameter(2); //Get command ID
			if (localParam != NULL)
			{
				localParam->GetValue(&currentID); //Get command ID's value
				localParam = NULL;
			}
			else
			{
                break;
			}

			if (currentID == commandId)
			{
                targetBehavior = behavior;
                break;
			}
		}
	}
	return targetBehavior;
}
コード例 #2
0
/*
*******************************************************************
* Function: CreateWidgetInfo()
*
* Description :	CreateWidgetInfo returns an handy info about an parameter type an a
						given string value of this parameter.
                        
* Parameters :	CKContext* context, r : the virtools context.
						CKParameterType parameterType, r : the type to test.
						XString stringValue,r : the string value of the given type.

* Returns : WidgetInfo
*******************************************************************
*/
vtTools::Structs::WidgetInfo* 
vtTools::ParameterTools::
CreateWidgetInfo(CKContext* context,
				 CKParameterType parameterType,
				 XString stringValue)
{
	using namespace vtTools::Structs;
	using namespace vtTools::Enums;
	using namespace vtTools::ParameterTools;


	CKParameterManager *pm = static_cast<CKParameterManager *>(context->GetParameterManager());

	CKGUID guid =pm->ParameterTypeToGuid(parameterType);

	WidgetInfo* result = new WidgetInfo();

	result->parameterInfo  =  GetParameterInfo(context,parameterType);

	CKParameterLocal *localCopy = context->CreateCKParameterLocal("buffer",guid,TRUE);

	localCopy->SetStringValue(stringValue.Str());


	switch(result->parameterInfo.superType) {

		//////////////////////////////////////////////////////////////////////////	color  //////////////////////////////////////////////////////////////////////////
		case vtCOLOUR:
			{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
				VxColor realValue;
				localCopy->GetValue(&realValue);

				DWORD32 dColor = realValue.GetRGBA();

				int r = ColorGetRed(dColor);
				int g = ColorGetGreen(dColor);
				int b = ColorGetBlue(dColor);
				int a = ColorGetAlpha(dColor);

				item->value << r << "," << g << "," << b << "," << a;

				item->widgetType = EVT_WIDGET_COLOR_SELECTION;
				result->items.PushBack(item);
				break;
			}
		//////////////////////////////////////////////////////////////////////////	integer //////////////////////////////////////////////////////////////////////////
		case vtFLOAT:
			{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
				float realValue;
				localCopy->GetValue(&realValue);
				item->value << realValue;
				item->widgetType = EVT_WIDGET_EDIT_TEXT;
				result->items.PushBack(item);
				break;
			}
		//////////////////////////////////////////////////////////////////////////	integer //////////////////////////////////////////////////////////////////////////
		case vtINTEGER:
			{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
				int realValue;
				localCopy->GetValue(&realValue);
				item->value << realValue;
				item->widgetType = EVT_WIDGET_EDIT_TEXT;
				result->items.PushBack(item);
				break;
			}
		//////////////////////////////////////////////////////////////////////////	bool //////////////////////////////////////////////////////////////////////////
		case vtBOOL:
			{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
				CKBOOL realValue;
				localCopy->GetValue(&realValue);
				item->value << realValue;
				item->widgetType = EVT_WIDGET_CHECK_BUTTON;
				result->items.PushBack(item);
				break;
			}

		//////////////////////////////////////////////////////////////////////////	string or file //////////////////////////////////////////////////////////////////////////
		case vtFile :
			{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
				item->value = stringValue;
				item->widgetType = EVT_WIDGET_FILE_SELECTION;
				result->items.PushBack(item);
				break;
			}
		case vtSTRING:
			{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
				item->value = stringValue;
				item->widgetType = EVT_WIDGET_EDIT_TEXT;
				result->items.PushBack(item);
				break;
			}
		//////////////////////////////////////////////////////////////////////////	box	//////////////////////////////////////////////////////////////////////////
		case vtBOX:
		{
			for (int i = 0 ; i < 6 ; i ++ )
				{
				WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();

				VxBbox realValue;
				localCopy->GetValue(&realValue);
				item->widgetType = EVT_WIDGET_EDIT_TEXT;
				switch(i) 
					{
					case 0:
						item->value << realValue.v[i];
						item->label = "min x: ";
						break;
					case 1:
						item->value << realValue.v[i];
						item->label = "min y: ";
						break;
					case 2:
						item->value << realValue.v[i];
						item->label = "min z: ";
						break;
					case 3:
						item->value << realValue.v[i];
						item->label = "max x: ";
						break;
					case 4:
						item->value << realValue.v[i];
						item->label = "max y: ";
						break;
					case 5:
						item->value << realValue.v[i];
						item->label = "max z: ";
						break;
					}
				result->items.PushBack(item);
				}
			break;
			}
		//////////////////////////////////////////////////////////////////////////	rectangle	//////////////////////////////////////////////////////////////////////////
		case vtRECTANGLE:
			{
				for (int i = 0 ; i < 4 ; i ++ )
				{
					WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();

					VxRect realValue;
					localCopy->GetValue(&realValue);
					item->widgetType = EVT_WIDGET_EDIT_TEXT;
					switch(i) 
						{
							case 0:
								item->value << realValue.left;
								item->label = "Left: ";
								break;
							case 1:
								item->value << realValue.top;
								item->label = "Top: ";
								break;
							case 2:
								item->value << realValue.right;
								item->label = "Right: ";
								break;
							case 3:
								item->value << realValue.bottom;
								item->label = "Bottom: ";
								break;
						}
					result->items.PushBack(item);
				}
				break;
			}
		//////////////////////////////////////////////////////////////////////////	vector 2	//////////////////////////////////////////////////////////////////////////
		case vtVECTOR2D:
			{
				for (int i = 0 ; i < 2 ; i ++ )
				{

					WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
					Vx2DVector VectorValue;
					localCopy->GetValue(&VectorValue);
					item->value << VectorValue[i];
					item->widgetType = EVT_WIDGET_EDIT_TEXT;
					switch(i) 
					{
						case 0:
							item->label = "x: ";
							break;
						case 1:
							item->label = "y: ";
					}
					result->items.PushBack(item);
				}
				break;
			}
		//////////////////////////////////////////////////////////////////////////	vector 3	//////////////////////////////////////////////////////////////////////////
		case vtVECTOR:
			{
				for (int i = 0 ; i < 3 ; i ++ )
				{

					WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
					VxVector VectorValue;
					localCopy->GetValue(&VectorValue);
					item->value << VectorValue[i];
					item->widgetType = EVT_WIDGET_EDIT_TEXT;

					switch(i) 
					{
						case 0:
							item->label = "x";
							break;
						case 1:
							item->label = "y";
							break;
						case 2:
							item->label = "z";
							break;
						}
					result->items.PushBack(item);
					}
				break;
			}
		//////////////////////////////////////////////////////////////////////////	vector4	//////////////////////////////////////////////////////////////////////////
		case vtQUATERNION:
			{

				for (int i = 0 ; i < 4 ; i ++ )
				{

					WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
					VxQuaternion realValue;
					localCopy->GetValue(&realValue);
					item->value << realValue[i];
					item->widgetType = EVT_WIDGET_EDIT_TEXT;
					switch(i) 
					{
						case 0:
							item->label = "x: ";
							break;
						case 1:
							item->label = "y: ";
							break;
						case 2:
							item->label = "z: ";
							break;
						case 3:
							item->label = "w: ";
							break;
					}
					result->items.PushBack(item);
				}
				break;
			}
		//////////////////////////////////////////////////////////////////////////	enumeration //////////////////////////////////////////////////////////////////////////
		case vtENUMERATION:
			{

				CKEnumStruct *enumStruct = pm->GetEnumDescByType(parameterType);
				if ( enumStruct )
				{
					for (int i = 0 ; i < enumStruct->GetNumEnums() ; i ++ )
					{
						WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
						item->value = enumStruct->GetEnumDescription(i);
						item->widgetType = EVT_WIDGET_COMBO_BOX;
						result->items.PushBack(item);
					}
				}
			break;
			}
		//////////////////////////////////////////////////////////////////////////	flags	 //////////////////////////////////////////////////////////////////////////
		case vtFLAGS:
			{
				CKFlagsStruct*flagStruct = pm->GetFlagsDescByType(parameterType);
				if ( flagStruct )
				{
					for (int i = 0 ; i < flagStruct->GetNumFlags() ; i ++ )
					{
						WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem();
						item->value = flagStruct->GetFlagDescription(i);
						item->widgetType = EVT_WIDGET_CHECK_BUTTON;
						result->items.PushBack(item);
					}
				}
				break;
			}
	}
	return result;
}