예제 #1
0
//------------------------------------------------------------------------
int CScriptBind_UIAction::GetVariable( IFunctionHandler *pH, const char * elementName, int instanceID, const char* varName )
{
	IUIElement* pElement = GetElement( elementName, instanceID );
	if ( pElement )
	{
		const SUIParameterDesc* pVarDesc = pElement->GetVariableDesc( varName );
		if ( pVarDesc )
		{
			TUIData value;
			if ( pElement->GetVariable( pVarDesc, value ) )
			{
				bool ok;
				ScriptAnyValue res = SUIToLuaConversationHelper::UIValueToLuaValue(value, ok);
				if (!ok)
				{
					UIACTION_WARNING( "LUA: Error reading variable %s from UI Element %s", varName, elementName );
				}
				return pH->EndFunctionAny( res );
			}
		}
		UIACTION_WARNING( "LUA: Element %s has no variable %s", elementName, varName );
	}
	else
	{
		UIACTION_WARNING( "LUA: UIElement %s does not exist", elementName );
	}
	return pH->EndFunction( false );
}
예제 #2
0
//------------------------------------------------------------------------
int CScriptBind_UIAction::SetVariable( IFunctionHandler *pH, const char * elementName, int instanceID, const char* varName )
{
	if (pH->GetParamCount() != 4)
	{
		UIACTION_ERROR( "LUA: UIAction.SetVariable - wrong number of arguments!");
		return pH->EndFunction(false);
	}

	IUIElement* pElement = GetElement( elementName, instanceID );
	if ( pElement )
	{
		const SUIParameterDesc* pVarDesc = pElement->GetVariableDesc( varName );
		if ( pVarDesc )
		{
			bool bRet = true;
			TUIData value;
			if (SUIToLuaConversationHelper::LuaArgToUIArg(pH, 4, value))
			{
				bool bVarOk = true;
				if ( instanceID < 0 )
				{
					IUIElementIteratorPtr elements = pElement->GetInstances();
					while ( IUIElement* pInstance = elements->Next() )
						bVarOk &= pInstance->SetVariable( pVarDesc, value );
				}
				else
				{
					bVarOk = pElement->SetVariable( pVarDesc, value );
				}

				if ( bVarOk )
					return pH->EndFunction(true);
				else
				{
					UIACTION_WARNING( "LUA: Element %s has no variable %s", elementName, varName );
				}
			}
			else
			{
				UIACTION_WARNING( "LUA: Element %s: wrong datatype for variable %s", elementName, varName );
			}
		}
		else
		{
			UIACTION_WARNING( "LUA: Element %s has no variable %s", elementName, varName );
		}
	}
	else
	{
		UIACTION_WARNING( "LUA: UIElement %s does not exist", elementName );
	}
	return pH->EndFunction(false);
}