// --------------------------------------------------------------- void CFlashUIBaseNodeDynPorts::GetDynInput( SUIArguments &args, const SUIParameterDesc &desc, SActivationInfo* pActInfo, int port) { switch (desc.eType) { case SUIParameterDesc::eUIPT_Bool: args.AddArgument( GetPortBool(pActInfo, port)); break; case SUIParameterDesc::eUIPT_Int: args.AddArgument( GetPortInt(pActInfo, port)); break; case SUIParameterDesc::eUIPT_Float: args.AddArgument( GetPortFloat(pActInfo, port)); break; case SUIParameterDesc::eUIPT_String: args.AddArgument( GetPortString(pActInfo, port)); break; case SUIParameterDesc::eUIPT_WString: args.AddArgument( GetPortString(pActInfo, port), eUIDT_WString ); break; case SUIParameterDesc::eUIPT_Vec3: args.AddArgument( GetPortVec3(pActInfo, port)); break; default: { string val; const TFlowInputData data = GetPortAny(pActInfo, port); data.GetValueWithConversion(val); args.AddArgument(val, eUIDT_Any); } break; } }
void CFlashUIVariableBaseNode::ConvertToUIData( const TFlowInputData &in, TUIData &out, SActivationInfo* pActInfo) { if (!GetObjectDesc()) { UIACTION_WARNING( "FG: No valid Variable \"%s\"! (Referenced at node \"%s\")", GetPortString(pActInfo, GetInputPort(eI_UIVariable)).c_str(), pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); return; } bool ok = false; const char* vartype = "any"; switch (GetObjectDesc()->eType) { case SUIParameterDesc::eUIPT_Bool: { bool value; ok = in.GetValueWithConversion(value); out = TUIData(value); vartype = "bool"; } break; case SUIParameterDesc::eUIPT_Int: { int value; ok = in.GetValueWithConversion(value); out = TUIData(value); vartype = "int"; } break; case SUIParameterDesc::eUIPT_Float: { float value; ok = in.GetValueWithConversion(value); out = TUIData(value); vartype = "float"; } break; case SUIParameterDesc::eUIPT_String: // fall through, just change the type desc vartype = "string"; case SUIParameterDesc::eUIPT_Any: default: { string value; ok = in.GetValueWithConversion(value); out = TUIData(value); } break; } if (!ok) { UIACTION_WARNING( "FG: UIElement \"%s\" Variable \"%s\" expected type \"%s\" given value was not compatible! (Referenced at node \"%s\")", GetElement()->GetName(),GetObjectDesc()->sDisplayName, vartype, pActInfo->pGraph->GetNodeTypeName( pActInfo->myID )); } }
string ConvertToString( const TFlowInputData &value ) { string out; CFlowDataWriteVisitor visitor(out); value.Visit(visitor); return out; }
void CFlowTrackEventNode::OnTrackEvent(IAnimSequence *pSequence, int reason, const char* event, void* pUserData) { if (reason != ITrackEventListener::eTrackEventReason_Triggered) return; // Find output port and call it for (int i = 0; i < m_nOutputs; ++i) { if (m_outputs[i].name && strcmp(m_outputs[i].name, event) == 0) { // Call it TFlowInputData value; const char* param = (const char*)pUserData; value.Set(string(param)); ActivateOutput(&m_actInfo, i, value); return; } } }
void CFlashUIToArrayNode::ProcessEvent( EFlowEvent event, SActivationInfo* pActInfo ) { if (event == eFE_Activate && IsPortActive( pActInfo, eI_Set )) { int count = GetPortInt( pActInfo, eI_Count ); int port = eI_Val1; SUIArguments args; for (int i = 0; i < count; ++i) { TFlowInputData data = GetPortAny( pActInfo, port + i ); string val; data.GetValueWithConversion( val ); args.AddArgument( val ); } ActivateOutput( pActInfo, eO_OnSet, true ); ActivateOutput( pActInfo, eO_ArgList, string( args.GetAsString())); } }
int CScriptBind_GameToken::SetToken( IFunctionHandler *pH) { SCRIPT_CHECK_PARAMETERS(2); const char* tokenName = 0; if (pH->GetParams(tokenName) == false) { GameWarning("[GameToken.SetToken] Usage: GameToken.SetToken TokenName TokenValue]"); return pH->EndFunction(); } ScriptAnyValue val; TFlowInputData data; if (pH->GetParamAny( 2, val) == false) { GameWarning("[GameToken.SetToken(%s)] Usage: GameToken.SetToken TokenName TokenValue]", tokenName); return pH->EndFunction(); } switch (val.type) { case ANY_TBOOLEAN: { bool v; val.CopyTo(v); data.Set(v); } break; case ANY_TNUMBER: { float v; val.CopyTo(v); data.Set(v); } break; case ANY_TSTRING: { const char* v; val.CopyTo(v); data.Set(string(v)); } break; case ANY_TVECTOR: { Vec3 v; val.CopyTo(v); data.Set(v); } case ANY_TTABLE: { float x,y,z; IScriptTable * pTable = val.table; assert (pTable != 0); if (pTable->GetValue( "x", x ) && pTable->GetValue( "y", y ) && pTable->GetValue( "z", z )) { data.Set(Vec3(x,y,z)); } else { GameWarning("[GameToken.SetToken(%s)] Cannot convert parameter type '%s' to Vec3", tokenName, ScriptAnyTypeToString(val.type)); return pH->EndFunction(); } } break; case ANY_THANDLE: { ScriptHandle handle; val.CopyTo(handle); data.Set((EntityId)handle.n); } break; default: GameWarning("[GameToken.SetToken(%s)] Cannot convert parameter type '%s'", tokenName, ScriptAnyTypeToString(val.type)); return pH->EndFunction(); break; // dummy ;-) } #ifdef SCRIPT_GAMETOKEN_ALWAYS_CREATE m_pTokenSystem->SetOrCreateToken(tokenName, data); #else IGameToken *pToken = m_pTokenSystem->FindToken(tokenName); if (!pToken) GameWarning("[GameToken.SetToken] Cannot find token '%s'", tokenName); else { pToken->SetValue(data); } #endif return pH->EndFunction(); }
bool SetFromString( TFlowInputData &value, const char* str ) { CFlowDataReadVisitor visitor(str); value.Visit(visitor); return !!visitor; }
bool CTweakMetadataGameToken::ChangeValue(bool bIncrement) { // Get delta double fDelta = m_fDelta; if (!bIncrement) fDelta *= -1.0f; // Get and check CVAR IGameToken* pGameToken = GetGameToken(); if(!pGameToken) return false; string sValue; // Deal with appropriate type switch (pGameToken->GetType()) { case eFDT_Bool: { bool value = false; pGameToken->GetValueAs(value); TFlowInputData newValue; newValue.SetValueWithConversion(!value); pGameToken->SetValue(newValue); } break; case eFDT_Int: { int value = 0; pGameToken->GetValueAs(value); TFlowInputData newValue; newValue.SetValueWithConversion((int)ClampToLimits(value + fDelta)); pGameToken->SetValue(newValue); } break; case eFDT_Float: { float value = 0.0f; pGameToken->GetValueAs(value); TFlowInputData newValue; newValue.SetValueWithConversion((float)ClampToLimits(value + fDelta)); pGameToken->SetValue(newValue); } break; case eFDT_String: { // bools pretending to be strings string value = pGameToken->GetValueAsString(); if(!value.compareNoCase("true")) pGameToken->SetValueAsString("false"); else if(!value.compareNoCase("false")) pGameToken->SetValueAsString("true"); // other strings are non-obvious } break; default: break; } return true; }
void CGameTokenSystem::Serialize( TSerialize ser ) { // when writing game tokens we store the per-level tokens (Level.xxx) in a group // with the real level name TFlowInputData data; std::vector<CGameToken*> levelTokens; static const char* levelPrefix = "Level."; static const size_t prefixLength = 6; assert(strlen(levelPrefix) == prefixLength); const bool bSaving = ser.IsWriting(); if (bSaving) { // Saving. if (m_levelToLevelSave) { IXmlStringData* xmlData = m_levelToLevelSave->getXMLData(5000); string strXMLData( xmlData->GetString() ); ser.Value("LTLGameTokensData", strXMLData); xmlData->Release(); } int nTokens = 0; ser.BeginGroup("GlobalTokens"); if (!m_pGameTokensMap->empty()) { GameTokensMap::iterator iter = m_pGameTokensMap->begin(); GameTokensMap::iterator iterEnd = m_pGameTokensMap->end(); while (iter != iterEnd) { CGameToken *pToken = iter->second; if (0 == strncmp(levelPrefix, pToken->m_name.c_str(), prefixLength)) { levelTokens.push_back(pToken); } else { nTokens++; ser.BeginGroup("Token"); ser.Value( "name",pToken->m_name ); ser.Value( "flags", pToken->m_nFlags ); pToken->m_value.Serialize(ser); ser.EndGroup(); } ++iter; } } ser.Value( "count",nTokens ); ser.EndGroup(); nTokens = (int)levelTokens.size(); ser.BeginGroup( "LevelTokens" ); ser.Value( "count",nTokens ); if (!levelTokens.empty()) { std::vector<CGameToken*>::iterator iter = levelTokens.begin(); std::vector<CGameToken*>::iterator iterEnd = levelTokens.end(); while (iter != iterEnd) { CGameToken *pToken = *iter; { ser.BeginGroup("Token"); ser.Value( "name",pToken->m_name ); ser.Value( "flags", pToken->m_nFlags ); pToken->m_value.Serialize(ser); ser.EndGroup(); } ++iter; } } ser.EndGroup(); } else { #ifdef _GAMETOKENSDEBUGINFO ClearDebugHistory(); #endif // Loading. { string strXMLData; ser.Value("LTLGameTokensData", strXMLData); m_levelToLevelSave = gEnv->pSystem->LoadXmlFromBuffer(strXMLData.c_str(), strXMLData.length()); } for (int pass = 0; pass < 2; pass++) { if (pass == 0) ser.BeginGroup("GlobalTokens"); else ser.BeginGroup("LevelTokens"); string tokenName; int nTokens = 0; ser.Value( "count",nTokens ); uint32 flags = 0; for (int i = 0; i < nTokens; i++) { ser.BeginGroup("Token"); ser.Value( "name",tokenName ); ser.Value( "flags", flags ); data.Serialize(ser); CGameToken *pToken = (CGameToken*)FindToken(tokenName); if (pToken) { pToken->m_value = data; pToken->m_nFlags = flags; } else { // Create token. pToken = (CGameToken*)SetOrCreateToken( tokenName,data ); pToken->m_nFlags = flags; } ser.EndGroup(); } ser.EndGroup(); } } }
void CFlashMenuObject::UpdateSingleplayerDifficulties() { if(!m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]) return; if(!m_pPlayerProfileManager) return; IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(m_pPlayerProfileManager->GetCurrentUser()); if(!pProfile) return; string sGeneralPath = "Singleplayer.Difficulty"; int iDifficulties = 8; /* for(int i=0; i<EDifficulty_END; ++i) { string sPath = sGeneralPath; char c[5]; itoa(i, c, 10); sPath.append(c); sPath.append(".available"); TFlowInputData data; pProfile->GetAttribute(sPath, data, false); bool bDone = false; data.GetValueWithConversion(bDone); if(bDone) { iDifficulties += i*2; } } */ int iDifficultiesDone = 0; for(int i=0; i<EDifficulty_END; ++i) { string sPath = sGeneralPath; char c[5]; itoa(i, c, 10); sPath.append(c); sPath.append(".done"); TFlowInputData data; pProfile->GetAttribute(sPath, data, false); bool bDone = false; data.GetValueWithConversion(bDone); if(bDone) { iDifficultiesDone += std::max(i*2,1); } } TFlowInputData data; pProfile->GetAttribute("Singleplayer.LastSelectedDifficulty", data, false); int iDiff = 2; data.GetValueWithConversion(iDiff); if(iDiff<=0) { iDiff = 2; } m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]->Invoke("Root.MainMenu.SinglePlayer.enableDifficulties", iDifficulties); m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]->Invoke("Root.MainMenu.SinglePlayer.enableDifficultiesStats", iDifficultiesDone); m_apFlashMenuScreens[MENUSCREEN_FRONTENDSTART]->Invoke("Root.MainMenu.SinglePlayer.selectDifficulty", iDiff); }