void CFlashUIFunctionNode::ProcessEvent( EFlowEvent event,SActivationInfo* pActInfo ) { if (event == eFE_Activate && IsPortActive(pActInfo, eI_Call)) { int port = GetDynStartPort(); SUIArguments args; for (TUIParams::const_iterator iter = m_funcDesc.InputParams.Params.begin(); iter != m_funcDesc.InputParams.Params.end(); ++iter) { GetDynInput( args, *iter, pActInfo, port++ ); } TUIData res; const int instanceId = GetPortInt( pActInfo, eI_InstanceID ); if (IsTemplate() && !UpdateTmplDesc( GetPortString(pActInfo, eI_TemplateInstanceName), pActInfo )) return; SPerInstanceCall2< const SUIArguments &, TUIData & > caller; caller.Execute(m_pElement, instanceId, functor(*this, &CFlashUIFunctionNode::CallFunction), args, res); string out; res.GetValueWithConversion( out ); ActivateOutput( pActInfo, eO_RetVal, out ); ActivateOutput( pActInfo, eO_OnCall, true ); } }
//------------------------------------------------------------------------ int CScriptBind_UIAction::CallFunction( IFunctionHandler *pH, const char * elementName, int instanceID, const char* functionName ) { SUIArguments args; if (!SUIToLuaConversationHelper::LuaArgsToUIArgs(pH, 4, args)) { UIACTION_WARNING( "LUA: Failed to call function %s on element %s: Invalid arguments", functionName, elementName ); return pH->EndFunction(false); } IUIElement* pElement = GetElement( elementName, instanceID, true ); if ( pElement ) { const SUIEventDesc* pFctDesc = pElement->GetFunctionDesc( functionName ); if ( pFctDesc ) { TUIData res; bool bFctOk = true; if ( instanceID < 0 ) { IUIElementIteratorPtr elements = pElement->GetInstances(); while ( IUIElement* pInstance = elements->Next() ) bFctOk &= pInstance->CallFunction( pFctDesc, args, &res); } else { bFctOk = pElement->CallFunction( pFctDesc, args, &res); } if ( bFctOk ) { string sRes; res.GetValueWithConversion( sRes ); return pH->EndFunction( sRes.c_str() ); } } UIACTION_WARNING( "LUA: UIElement %s does not have function %s", elementName, functionName ); } else if (IUIEventSystem* pEventSystem = GetEventSystem( elementName, IUIEventSystem::eEST_UI_TO_SYSTEM )) { uint eventid = pEventSystem->GetEventId( functionName ); if ( eventid != ~0 ) { SUIArguments res = pEventSystem->SendEvent( SUIEvent( eventid, args ) ); SmartScriptTable table = gEnv->pScriptSystem->CreateTable(); SUIToLuaConversationHelper::UIArgsToLuaTable(res, table); return pH->EndFunction( table ); } UIACTION_WARNING( "LUA: UIEventSystem %s does not have event %s", elementName, functionName ); } else { UIACTION_WARNING( "LUA: UIElement or UIEventSystem %s does not exist", elementName ); } return pH->EndFunction(false); }
void CFlashUIVariableBaseNode::ProcessEvent( EFlowEvent event, SActivationInfo* pActInfo ) { if (event == eFE_Initialize) { UpdateObjectDesc( GetPortString( pActInfo, GetInputPort(eI_UIVariable)), pActInfo, m_isTemplate ); } else if (event == eFE_Activate) { if (IsPortActive( pActInfo, GetInputPort(eI_UIVariable))) { UpdateObjectDesc( GetPortString( pActInfo, GetInputPort(eI_UIVariable)), pActInfo, m_isTemplate ); } if (IsTemplate() && !UpdateTmplDesc( GetPortString( pActInfo, GetInputPort(eI_TemplateInstanceName)), pActInfo )) return; const int instanceId = GetPortInt( pActInfo, GetInputPort(eI_InstanceID)); if (IsPortActive ( pActInfo, GetInputPort(eI_Set))) { const TFlowInputData &data = GetPortAny( pActInfo, GetInputPort(eI_Value)); TUIData value; ConvertToUIData(data, value, pActInfo); SPerInstanceCall1< const TUIData & > caller; caller.Execute( GetElement(), instanceId, functor(*this, &CFlashUIVariableBaseNode::SetVariable), value ); ActivateOutput( pActInfo, eO_OnSet, true ); } if (IsPortActive( pActInfo, GetInputPort(eI_Get))) { TUIData out; SPerInstanceCall1< TUIData & > caller; if (!caller.Execute( GetElement(), instanceId, functor(*this, &CFlashUIVariableBaseNode::GetVariable), out, false )) { UIACTION_WARNING( "FG: UIElement \"%s\" called get Variable for multiple instances! (passed instanceId %i), referenced at node \"%s\"", GetElement()->GetName(),instanceId, pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); } string res; out.GetValueWithConversion( res ); ActivateOutput( pActInfo, eO_Value, res ); } } }
//------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ ScriptAnyValue SUIToLuaConversationHelper::UIValueToLuaValue(const TUIData& value, bool& ok) { ok = true; switch ( value.GetType() ) { case eUIDT_Bool: return SUIConvHelperTmpl::GetValueRaw<bool>(value); case eUIDT_Int: return SUIConvHelperTmpl::GetValueRaw<int>(value); case eUIDT_EntityId: return SUIConvHelperTmpl::GetValueRaw<EntityId>(value); case eUIDT_Float: return SUIConvHelperTmpl::GetValueRaw<float>(value); case eUIDT_Vec3: return SUIConvHelperTmpl::GetValueRaw<Vec3>(value); case eUIDT_String: case eUIDT_WString: { string val; if ( value.GetValueWithConversion( val ) ) return ScriptAnyValue( val.c_str() ); } } ok = false; return ScriptAnyValue( false ); }
// --------------------------------------------------------------- void CFlashUIBaseNodeDynPorts::ActivateDynOutput( const TUIData &arg, const SUIParameterDesc &desc, SActivationInfo* pActInfo, int port) { switch (desc.eType) { case SUIParameterDesc::eUIPT_Bool: { bool val; const bool ok = arg.GetValueWithConversion(val); if (!ok) UIACTION_WARNING( "FG: Node \"%s\" received wrong data on typed input!", pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); ActivateOutput(pActInfo, port, val); } break; case SUIParameterDesc::eUIPT_Int: { int val; const bool ok = arg.GetValueWithConversion(val); if (!ok) UIACTION_WARNING( "FG: Node \"%s\" received wrong data on typed input!", pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); ActivateOutput(pActInfo, port, val); } break; case SUIParameterDesc::eUIPT_Float: { float val; const bool ok = arg.GetValueWithConversion(val); if (!ok) UIACTION_WARNING( "FG: Node \"%s\" received wrong data on typed input!", pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); ActivateOutput(pActInfo, port, val); } break; case SUIParameterDesc::eUIPT_String: case SUIParameterDesc::eUIPT_WString: default: { string val; const bool ok = arg.GetValueWithConversion(val); if (!ok) UIACTION_WARNING( "FG: Node \"%s\" received wrong data on typed input!", pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); ActivateOutput(pActInfo, port, val); } break; } }