예제 #1
0
        /// <summary>
        /// A query selector for a unknown entity.
        /// </summary>
        static public int QuerySelectorUnknown(Rect inPosition, int inCurrentId, RSTypeInfo inReturnType, bool inbNoParams, RSLibrary inLibrary)
        {
            RSEditorUtility.s_QueryElements.Clear();
            inLibrary.GetAllLocalQueries(RSEditorUtility.s_QueryElements, inReturnType, inbNoParams);

            return(RSGUI.RSElementSelector(inPosition, inCurrentId, RSEditorUtility.s_QueryElements));
        }
예제 #2
0
        /// <summary>
        /// A query selector for a specific entity.
        /// </summary>
        static public int QuerySelector(int inCurrentId, IRSEntity inEntity, RSTypeInfo inReturnType, bool inbNoParams, RSLibrary inLibrary)
        {
            RSEditorUtility.s_QueryElements.Clear();
            inLibrary.GetAllQueriesForEntity(inEntity, RSEditorUtility.s_QueryElements, inReturnType, inbNoParams);

            return(RSGUILayout.RSElementSelector(inCurrentId, RSEditorUtility.s_QueryElements));
        }
예제 #3
0
        static private void ValidateCondition(RSConditionData inCondition, RSValidationState ioState, RSValidationContext inContext)
        {
            ioState.PushContext("Query");
            ValidateResolvableValue(inCondition.Query, null, RSValidationFlags.None.ForConditionQuery(), ioState, inContext);
            ioState.PopContext();

            RSTypeInfo expectedType = inCondition.Query.TypeInfo(inContext.Trigger, inContext.Library);

            if (inCondition.Query.Mode != ResolvableValueMode.Value && expectedType != null)
            {
                ioState.PushContext("Operator");
                CompareOperator op = inCondition.Operator;
                if (!expectedType.IsOperatorAllowed(op))
                {
                    ioState.Error("Operator {0} is not allowed for type {1}", op, expectedType);
                }
                ioState.PopContext();

                if (op.IsBinary())
                {
                    ioState.PushContext("Target");
                    ValidateResolvableValue(inCondition.Target, expectedType, RSValidationFlags.None.ForConditionTarget(), ioState, inContext);
                    ioState.PopContext();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// A query selector for the global scope.
        /// </summary>
        static public int QuerySelectorGlobal(GUIContent inLabel, int inCurrentId, RSTypeInfo inReturnType, bool inbNoParams, RSLibrary inLibrary)
        {
            RSEditorUtility.s_QueryElements.Clear();
            inLibrary.GetAllGlobalQueries(RSEditorUtility.s_QueryElements, inReturnType, inbNoParams);

            return(RSGUILayout.RSElementSelector(inLabel, inCurrentId, RSEditorUtility.s_QueryElements));
        }
예제 #5
0
 /// <summary>
 /// Renders a layout editor for a NestedValue.
 /// </summary>
 static public NestedValue NestedValueField(NestedValue inValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoNestedValueField(GUIContent.none, inValue, inExpectedType, inDefaultValue, inFlags, inContext));
     }
 }
예제 #6
0
        static private void ValidateValue(RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            Type systemType = inExpectedType.SystemType;

            if (systemType.IsEnum)
            {
                try
                {
                    Enum currentValue = inValue.AsEnum();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    ioState.Error("Enum {0} cannot be represented as type {1}", inValue, inExpectedType);
                }
                return;
            }

            if (inExpectedType == RSBuiltInTypes.Entity)
            {
                EntityScopeData scope = inValue.AsEntity;
                ValidateEntityScope(scope, inFlags.ForEntityValue(), ioState, inContext);
            }
            else if (inExpectedType == RSBuiltInTypes.GroupId)
            {
                RSGroupId group = inValue.AsGroupId;
                ValidateGroupId(group, inFlags, ioState, inContext);
            }
            else if (inExpectedType == RSBuiltInTypes.TriggerId)
            {
                RSTriggerId triggerId = inValue.AsTriggerId;
                ValidateTriggerId(triggerId, inFlags, ioState, inContext);
            }
        }
예제 #7
0
        /// <summary>
        /// A trigger selector.
        /// </summary>
        static public RSTriggerId TriggerSelector(RSTriggerId inCurrentId, RSTypeInfo inParameterType, RSLibrary inLibrary)
        {
            RSEditorUtility.s_TriggerElements.Clear();
            inLibrary.GetAllTriggers(RSEditorUtility.s_TriggerElements, inParameterType ?? RSBuiltInTypes.Void);

            int trigger = RSGUILayout.RSElementSelector((int)inCurrentId, RSEditorUtility.s_TriggerElements);

            return(new RSTriggerId(trigger));
        }
예제 #8
0
        static private RSTriggerInfo ValidateTriggerId(RSTriggerId inTriggerId, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            RSTypeInfo restrictTriggerType = inContext.Parameter?.TriggerParameterType;

            if (inTriggerId == RSTriggerId.Null)
            {
                if (restrictTriggerType != null)
                {
                    ioState.Error("Null trigger id provided - require trigger with parameter type {0}", restrictTriggerType);
                }
                else
                {
                    ioState.Warn("Null trigger provided");
                }
                return(null);
            }
            else
            {
                RSTriggerInfo triggerInfo = inContext.Library.GetTrigger(inTriggerId);
                if (triggerInfo == null)
                {
                    ioState.Error("Trigger {0} does not exist", inTriggerId);
                }
                else
                {
                    if (restrictTriggerType != null)
                    {
                        if (restrictTriggerType == RSBuiltInTypes.Void)
                        {
                            if (triggerInfo.ParameterType != null)
                            {
                                ioState.Error("Trigger with no parameter required, but trigger {0} with parameter {1} provided", triggerInfo.Name, triggerInfo.ParameterType.Type);
                            }
                        }
                        else
                        {
                            if (triggerInfo.ParameterType == null)
                            {
                                ioState.Error("Trigger with parameter {0} required, but trigger {1} with no parameter provided", restrictTriggerType, triggerInfo.Name);
                            }
                            else if (!restrictTriggerType.CanConvert(triggerInfo.ParameterType.Type))
                            {
                                ioState.Error("Trigger with parameter {0} required, but trigger {1} with incompatible parameter {2} provided", restrictTriggerType, triggerInfo.Name, triggerInfo.ParameterType.Type);
                            }
                        }
                    }
                }
                return(triggerInfo);
            }
        }
예제 #9
0
 static private void ValidateTriggerArgument(RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
 {
     if (inContext.Trigger == null)
     {
         ioState.Error("Cannot use trigger parameter - no trigger");
     }
     else if (inContext.Trigger.ParameterType == null)
     {
         ioState.Error("Cannot use trigger parameter - trigger {0} has no parameter", inContext.Trigger.Name);
     }
     else if (inExpectedType != null && !inContext.Trigger.ParameterType.Type.CanConvert(inExpectedType))
     {
         ioState.Error("Cannot use trigger parameter - trigger {0} has incompatible parameter type {1}, which cannot convert to {2}", inContext.Trigger.Name, inContext.Trigger.ParameterType.Type, inExpectedType);
     }
 }
예제 #10
0
        static internal NamedItemList <ResolvableValueMode> GetResolvableValueModes(RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            bool bDisallowDirectValue = (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue));
            bool bDisallowRegister    = inFlags.Has(RSValidationFlags.DisallowRegisters);

            if (bDisallowDirectValue)
            {
                if (bDisallowDirectValue)
                {
                    return(s_ResolvableValueModesNoValueOrRegister);
                }
                return(s_ResolvableValueModesNoRegister);
            }
            if (bDisallowRegister)
            {
                return(s_ResolvableValueModesNoRegister);
            }
            return(s_ResolvableValueModes);
        }
예제 #11
0
        static private void ValidateNestedValue(NestedValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            bool bDisallowDirectValue = (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue));

            switch (inValue.Mode)
            {
            case ResolvableValueMode.Argument:
            {
                ValidateTriggerArgument(inExpectedType, inFlags, ioState, inContext);
                break;
            }

            case ResolvableValueMode.Register:
            {
                if (inFlags.Has(RSValidationFlags.DisallowRegisters))
                {
                    ioState.Error("Cannot use a register in this context");
                }
                break;
            }

            case ResolvableValueMode.Value:
            {
                if (bDisallowDirectValue)
                {
                    ioState.Error("Cannot specify a direct value in this context");
                }
                else
                {
                    ValidateValue(inValue.Value, inExpectedType, inFlags, ioState, inContext);
                }
                break;
            }

            case ResolvableValueMode.Query:
            {
                ValidateQueryId(inValue.Query, inExpectedType, inFlags.ForMethod(false), ioState, inContext);
                break;
            }
            }
        }
예제 #12
0
        static private EntityScopedIdentifier DoQueryField(GUIContent inLabel, EntityScopedIdentifier inIdentifier, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            EntityScopeData scope     = inIdentifier.Scope;
            int             queryId   = inIdentifier.Id;
            bool            bNoParams = inFlags.Has(RSValidationFlags.DisallowParameters);

            using (new EditorGUILayout.VerticalScope())
            {
                scope = EntityScopeField(inLabel, scope, inFlags.ForMethodScope(), inContext);
                using (new EditorGUI.IndentLevelScope())
                {
                    switch (scope.Type)
                    {
                    case EntityScopeType.Global:
                        queryId = LibraryGUILayout.QuerySelectorGlobal(Content.QueryIdLabel, queryId, inExpectedType, bNoParams, inContext.Library);
                        break;

                    case EntityScopeType.Null:
                        EditorGUILayout.HelpBox("Cannot perform query on null entity", MessageType.Error);
                        break;

                    case EntityScopeType.Invalid:
                        EditorGUILayout.HelpBox("Cannot perform query on missing entity", MessageType.Error);
                        break;

                    case EntityScopeType.Self:
                    {
                        if (inFlags.Has(RSValidationFlags.FilterSelection) && !scope.HasLinks() && inContext.Entity != null)
                        {
                            queryId = LibraryGUILayout.QuerySelector(Content.QueryIdLabel, queryId, inContext.Entity, inExpectedType, bNoParams, inContext.Library);
                        }
                        else
                        {
                            queryId = LibraryGUILayout.QuerySelectorUnknown(Content.QueryIdLabel, queryId, inExpectedType, bNoParams, inContext.Library);
                        }
                        break;
                    }

                    case EntityScopeType.ObjectById:
                    {
                        RSEntityId entityId = scope.IdArg;
                        IRSEntity  entity   = null;
                        if (inFlags.Has(RSValidationFlags.FilterSelection) && entityId != RSEntityId.Null && !scope.HasLinks() && inContext.Manager != null && (entity = inContext.Manager.Lookup.EntityWithId(entityId)) != null)
                        {
                            queryId = LibraryGUILayout.QuerySelector(Content.QueryIdLabel, queryId, entity, inExpectedType, bNoParams, inContext.Library);
                        }
                        else
                        {
                            queryId = LibraryGUILayout.QuerySelectorUnknown(Content.QueryIdLabel, queryId, inExpectedType, bNoParams, inContext.Library);
                        }
                        break;
                    }

                    default:
                        queryId = LibraryGUILayout.QuerySelectorUnknown(Content.QueryIdLabel, queryId, inExpectedType, bNoParams, inContext.Library);
                        break;
                    }

                    if (queryId == 0)
                    {
                        EditorGUILayout.HelpBox("Cannot perform null query", MessageType.Error);
                    }
                }
            }

            return(new EntityScopedIdentifier(scope, queryId));
        }
예제 #13
0
 /// <summary>
 /// Renders a layout editor for a scoped query identifier.
 /// </summary>
 static public EntityScopedIdentifier QueryField(EntityScopedIdentifier inIdentifier, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoQueryField(GUIContent.none, inIdentifier, inExpectedType, inFlags, inContext));
     }
 }
예제 #14
0
 /// <summary>
 /// Renders a layout editor for a scoped query identifier.
 /// </summary>
 static public EntityScopedIdentifier QueryField(GUIContent inLabel, EntityScopedIdentifier inIdentifier, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoQueryField(inLabel, inIdentifier, inExpectedType, inFlags, inContext));
 }
예제 #15
0
        static private NestedValue DoNestedValueField(GUIContent inLabel, NestedValue inValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            EditorGUILayout.BeginVertical();
            ResolvableValueMode nextType = ListGUILayout.Popup(inLabel, inValue.Mode, RSEditorUtility.GetResolvableValueModes(inExpectedType, inFlags, inContext));

            RSValue value = inDefaultValue;
            EntityScopedIdentifier query    = new EntityScopedIdentifier(EntityScopeData.Self(), 0);
            RegisterIndex          register = RegisterIndex.Register0;

            using (new EditorGUI.IndentLevelScope())
            {
                switch (inValue.Mode)
                {
                case ResolvableValueMode.Argument:
                {
                    if (inContext.Trigger == null)
                    {
                        EditorGUILayout.HelpBox("No parameter available: No Trigger", MessageType.Error);
                    }
                    else if (inContext.Trigger.ParameterType == null)
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has no parameter", inContext.Trigger.Name), MessageType.Error);
                    }
                    else if (inExpectedType != null && !inContext.Trigger.ParameterType.Type.CanConvert(inExpectedType))
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has incompatible parameter type {1}, which cannot convert to {2}", inContext.Trigger.Name, inContext.Trigger.ParameterType.Type, inExpectedType), MessageType.Error);
                    }
                    break;
                }

                case ResolvableValueMode.Value:
                {
                    if (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue))
                    {
                        EditorGUILayout.HelpBox("Cannot specify a value in this context", MessageType.Error);
                    }
                    else
                    {
                        value = RSValueField(EditorGUIUtility.TrTempContent(inExpectedType.FriendlyName), inValue.Value, inExpectedType, inFlags, inContext);
                    }
                    break;
                }

                case ResolvableValueMode.Query:
                {
                    query = ValueGUILayout.QueryField(RuleGUILayout.Content.ResolvableValueQueryLabel, inValue.Query, inExpectedType, inFlags.ForMethod(false), inContext);
                    break;
                }

                case ResolvableValueMode.Register:
                {
                    register = (RegisterIndex)EnumGUILayout.EnumField(RuleGUILayout.Content.ResolvableValueRegisterLabel, inValue.Register);
                    break;
                }
                }
            }

            EditorGUILayout.EndVertical();

            switch (nextType)
            {
            case ResolvableValueMode.Argument:
                return(NestedValue.FromArgument());

            case ResolvableValueMode.Query:
                return(NestedValue.FromQuery(query));

            case ResolvableValueMode.Register:
                return(NestedValue.FromRegister(register));

            case ResolvableValueMode.Value:
            default:
                return(NestedValue.FromValue(value));
            }
        }
예제 #16
0
 /// <summary>
 /// Renders a layout editor for a NestedValue.
 /// </summary>
 static public NestedValue NestedValueField(GUIContent inLabel, NestedValue inValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoNestedValueField(inLabel, inValue, inExpectedType, inDefaultValue, inFlags, inContext));
 }
예제 #17
0
        static private void ValidateResolvableValue(RSResolvableValueData inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            bool bDisallowDirectValue = (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue));

            switch (inValue.Mode)
            {
            case ResolvableValueMode.Argument:
            {
                ValidateTriggerArgument(inExpectedType, inFlags, ioState, inContext);
                break;
            }

            case ResolvableValueMode.Value:
            {
                if (bDisallowDirectValue)
                {
                    ioState.Error("Cannot specify a direct value in this context");
                }
                else
                {
                    ValidateValue(inValue.Value, inExpectedType, inFlags, ioState, inContext);
                }
                break;
            }

            case ResolvableValueMode.Register:
            {
                if (inFlags.Has(RSValidationFlags.DisallowRegisters))
                {
                    ioState.Error("Cannot use a register in this context");
                }
                break;
            }

            case ResolvableValueMode.Query:
            {
                ioState.PushContext("Query Id");
                RSQueryInfo queryInfo = ValidateQueryId(inValue.Query, inExpectedType, inFlags.ForMethod(true), ioState, inContext);
                ioState.PopContext();

                ioState.PushContext("Arguments");
                if (queryInfo != null)
                {
                    int argCount = queryInfo.Parameters.Length;
                    if (argCount <= 0)
                    {
                        if (inValue.QueryArguments != null && inValue.QueryArguments.Length > 0)
                        {
                            ioState.Error("Arguments provided for action {0} but none required", queryInfo.Name);
                        }
                    }
                    else
                    {
                        if (inValue.QueryArguments == null)
                        {
                            ioState.Error("No arguments provided for action {0} but {1} required", queryInfo.Name, argCount);
                        }
                        else if (inValue.QueryArguments.Length != argCount)
                        {
                            ioState.Error("Argument count mismatch for action {0} - {1} required but {2} provided", queryInfo.Name, argCount, inValue.QueryArguments.Length);
                        }
                        else
                        {
                            for (int i = 0; i < argCount; ++i)
                            {
                                ValidateNestedParameter(queryInfo.Parameters[i], inValue.QueryArguments[i], ioState, inContext);
                            }
                        }
                    }
                }
                ioState.PopContext();
                break;
            }
            }
        }
예제 #18
0
 /// <summary>
 /// Renders a layout editor for a ResolvableValue.
 /// </summary>
 static public void ResolvableValueData(UndoTarget inUndo, GUIContent inLabel, RSResolvableValueData ioValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     DoResolvableValueData(inUndo, inLabel, ioValue, inExpectedType, inDefaultValue, inFlags, inContext);
 }
예제 #19
0
        static private RSQueryInfo ValidateQueryId(EntityScopedIdentifier inIdentifier, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            bool bNoParams = inFlags.Has(RSValidationFlags.DisallowParameters);

            ValidateEntityScope(inIdentifier.Scope, inFlags.ForMethodScope(), ioState, inContext);

            if (inIdentifier.Id == 0)
            {
                ioState.Error("Null query not allowed");
                return(null);
            }
            else
            {
                RSQueryInfo queryInfo = inContext.Library.GetQuery(inIdentifier.Id);
                if (queryInfo == null)
                {
                    ioState.Error("Query {0} does not exist", inIdentifier.Id);
                }
                else
                {
                    if (inExpectedType != null && !queryInfo.ReturnType.CanConvert(inExpectedType))
                    {
                        ioState.Error("Query {0} returns incompatible type {1}, which cannot convert to desired type {2}", queryInfo.Name, queryInfo.ReturnType, inExpectedType);
                    }

                    if (bNoParams && queryInfo.Parameters != null && queryInfo.Parameters.Length > 0)
                    {
                        ioState.Error("Query {0} has parameters, which is not allowed in this context", queryInfo.Name);
                    }

                    switch (inIdentifier.Scope.Type)
                    {
                    case EntityScopeType.Global:
                    {
                        if (queryInfo.OwnerType != null)
                        {
                            ioState.Error("Query {0} is bound to type {1} but was specified as a global query", queryInfo.Name, queryInfo.OwnerType.Name);
                        }
                        break;
                    }

                    case EntityScopeType.Null:
                    case EntityScopeType.Invalid:
                        break;

                    default:
                    {
                        if (queryInfo.OwnerType == null)
                        {
                            ioState.Error("Query {0} is bound to global scope but was specified as a local query", queryInfo.Name);
                        }
                        break;
                    }
                    }
                }

                return(queryInfo);
            }
        }
예제 #20
0
        static private RSValue DoRSValueField(GUIContent inLabel, RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            Type systemType = inExpectedType.SystemType;

            if (systemType.IsEnum)
            {
                Enum currentValue;
                try
                {
                    currentValue = inValue.AsEnum();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    currentValue = inExpectedType.DefaultValue.AsEnum();
                }
                Enum nextValue = EnumGUILayout.EnumField(inLabel, currentValue);
                return(RSValue.FromEnum(nextValue));
            }

            if (inExpectedType == RSBuiltInTypes.Int)
            {
                int currentValue = inValue.AsInt;
                int nextValue    = EditorGUILayout.DelayedIntField(inLabel, currentValue);
                return(RSValue.FromInt(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Float)
            {
                float currentValue = inValue.AsFloat;
                float nextValue    = EditorGUILayout.DelayedFloatField(inLabel, currentValue);
                return(RSValue.FromFloat(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Bool)
            {
                bool currentValue = inValue.AsBool;
                bool nextValue    = EditorGUILayout.Toggle(inLabel, currentValue);
                return(RSValue.FromBool(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Color)
            {
                Color currentValue = inValue.AsColor;
                Color nextValue    = EditorGUILayout.ColorField(inLabel, currentValue);
                return(RSValue.FromColor(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.String)
            {
                string currentValue = inValue.AsString;
                string nextValue    = EditorGUILayout.TextField(inLabel, currentValue);
                return(RSValue.FromString(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Vector2)
            {
                Vector2 currentValue = inValue.AsVector2;
                Vector2 nextValue    = EditorGUILayout.Vector2Field(inLabel, currentValue);
                return(RSValue.FromVector2(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Vector3)
            {
                Vector3 currentValue = inValue.AsVector3;
                Vector3 nextValue    = EditorGUILayout.Vector3Field(inLabel, currentValue);
                return(RSValue.FromVector3(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Vector4)
            {
                Vector4 currentValue = inValue.AsVector4;
                Vector4 nextValue    = EditorGUILayout.Vector4Field(inLabel, currentValue);
                return(RSValue.FromVector4(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Entity)
            {
                EntityScopeData currentValue = inValue.AsEntity;
                EntityScopeData nextValue    = EntityScopeField(inLabel, currentValue, inFlags.ForEntityValue(), inContext);
                return(RSValue.FromEntity(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.GroupId)
            {
                RSGroupId currentValue = inValue.AsGroupId;
                RSGroupId nextValue    = LibraryGUILayout.GroupSelector(inLabel, currentValue, inContext.Library);
                return(RSValue.FromGroupId(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.TriggerId)
            {
                RSTriggerId currentValue        = inValue.AsTriggerId;
                RSTypeInfo  restrictTriggerType = inContext.Parameter?.TriggerParameterType;
                RSTriggerId nextValue;
                if (restrictTriggerType != null)
                {
                    nextValue = LibraryGUILayout.TriggerSelector(inLabel, currentValue, restrictTriggerType, inContext.Library);
                }
                else
                {
                    nextValue = LibraryGUILayout.TriggerSelector(inLabel, currentValue, inContext.Library);
                }
                return(RSValue.FromTriggerId(nextValue));
            }
            else
            {
                EditorGUILayout.HelpBox(string.Format("Unable to display editor for type {0}", inExpectedType), MessageType.Error);
            }

            return(inValue);
        }
예제 #21
0
        /// <summary>
        /// Renders editor for condition info.
        /// </summary>
        static public void ConditionData(UndoTarget inUndo, RSConditionData ioCondition, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            string preview = ioCondition.GetPreviewString(inContext.Trigger, inContext.Library);

            GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle);

            EditorGUILayout.Space();

            // Enabled
            bool bEnabled = EditorGUILayout.Toggle(Content.ConditionEnabledLabel, ioCondition.Enabled);

            if (bEnabled != ioCondition.Enabled)
            {
                inUndo.MarkDirty("Changed Condition Enabled");
                ioCondition.Enabled = bEnabled;
            }

            EditorGUILayout.Space();

            using (new EditorGUI.DisabledGroupScope(!bEnabled))
            {
                RSTypeInfo prevQueryType = ioCondition.Query.TypeInfo(inContext.Trigger, inContext.Library);

                // Query
                ResolvableValueData(inUndo, Content.ConditionValueLabel, ioCondition.Query, null, inFlags.ForConditionQuery(), inContext);

                // comparison
                RSTypeInfo queryTypeInfo = ioCondition.Query.TypeInfo(inContext.Trigger, inContext.Library);
                if (ioCondition.Query.Mode != ResolvableValueMode.Value && queryTypeInfo != null)
                {
                    EditorGUILayout.Space();

                    RSEditorUtility.s_ComparisonOperators.Clear();
                    foreach (var comparison in queryTypeInfo.AllowedOperators())
                    {
                        RSEditorUtility.s_ComparisonOperators.Add(comparison, comparison.Name(), (int)comparison);
                    }

                    CompareOperator nextOperator = ioCondition.Operator;
                    if (!RSEditorUtility.s_ComparisonOperators.Contains(nextOperator))
                    {
                        nextOperator = RSEditorUtility.s_ComparisonOperators.Get(0);
                    }

                    nextOperator = ListGUILayout.Popup(Content.ConditionComparisonLabel, nextOperator, RSEditorUtility.s_ComparisonOperators);
                    if (nextOperator != ioCondition.Operator)
                    {
                        inUndo.MarkDirty("Changed Condition Operator");
                        ioCondition.Operator = nextOperator;
                    }

                    if (nextOperator.IsBinary())
                    {
                        EditorGUILayout.Space();

                        if (prevQueryType != queryTypeInfo)
                        {
                            inUndo.MarkDirty("Changed Condition Query Type");
                            RSResolvableValueData.SetAsValue(ref ioCondition.Target, queryTypeInfo.DefaultValue);
                        }

                        ResolvableValueData(inUndo, Content.ConditionTargetLabel, ioCondition.Target, queryTypeInfo, inFlags.ForConditionTarget(), inContext);
                    }
                    else
                    {
                        if (ioCondition.Target != null)
                        {
                            inUndo.MarkDirty("Removed Condition Comparison Target");
                            ioCondition.Target = null;
                        }
                    }

                    if (ioCondition.Query.IsMultiValue())
                    {
                        EditorGUILayout.Space();
                        Subset subset = (Subset)EditorGUILayout.EnumPopup(Content.ConditionSubsetLabel, ioCondition.MultiQuerySubset);
                        if (subset != ioCondition.MultiQuerySubset)
                        {
                            inUndo.MarkDirty("Changed Condition MultiQuerySubset");
                            ioCondition.MultiQuerySubset = subset;
                        }
                    }
                }
            }
        }
예제 #22
0
        /// <summary>
        /// A trigger selector for a specific entity.
        /// </summary>
        static public RSTriggerId TriggerSelector(Rect inPosition, RSTriggerId inCurrentId, IRSEntity inEntity, RSTypeInfo inParameterType, RSLibrary inLibrary)
        {
            RSEditorUtility.s_TriggerElements.Clear();
            inLibrary.GetAllTriggersForEntity(inEntity, RSEditorUtility.s_TriggerElements, inParameterType ?? RSBuiltInTypes.Void);
            inLibrary.GetAllGlobalTriggers(RSEditorUtility.s_TriggerElements, inParameterType ?? RSBuiltInTypes.Void);

            int trigger = RSGUI.RSElementSelector(inPosition, (int)inCurrentId, RSEditorUtility.s_TriggerElements);

            return(new RSTriggerId(trigger));
        }
예제 #23
0
        static private void DoResolvableValueData(UndoTarget inUndo, GUIContent inLabel, RSResolvableValueData ioValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            EditorGUILayout.BeginVertical();

            bool bDisallowDirectValue = (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue));

            ResolvableValueMode nextMode = ListGUILayout.Popup(inLabel, ioValue.Mode, RSEditorUtility.GetResolvableValueModes(inExpectedType, inFlags, inContext));

            if (nextMode != ioValue.Mode)
            {
                inUndo.MarkDirty("Changed Resolvable Value Mode");
                ioValue.Mode = nextMode;

                switch (nextMode)
                {
                case ResolvableValueMode.Argument:
                    RSResolvableValueData.SetAsArgument(ref ioValue);
                    break;

                case ResolvableValueMode.Query:
                    RSResolvableValueData.SetAsQuery(ref ioValue, new EntityScopedIdentifier(EntityScopeData.Self(), 0));
                    break;

                case ResolvableValueMode.Value:
                    RSResolvableValueData.SetAsValue(ref ioValue, inDefaultValue);
                    break;

                case ResolvableValueMode.Register:
                    RSResolvableValueData.SetAsRegister(ref ioValue, RegisterIndex.Register0);
                    break;
                }
            }

            using (new EditorGUI.IndentLevelScope())
            {
                switch (ioValue.Mode)
                {
                case ResolvableValueMode.Argument:
                {
                    if (inContext.Trigger == null)
                    {
                        EditorGUILayout.HelpBox("No parameter available: No Trigger", MessageType.Error);
                    }
                    else if (inContext.Trigger.ParameterType == null)
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has no parameter", inContext.Trigger.Name), MessageType.Error);
                    }
                    else if (inExpectedType != null && !inContext.Trigger.ParameterType.Type.CanConvert(inExpectedType))
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has incompatible parameter type {1}, which cannot convert to {2}", inContext.Trigger.Name, inContext.Trigger.ParameterType.Type, inExpectedType), MessageType.Error);
                    }
                    break;
                }

                case ResolvableValueMode.Value:
                {
                    if (bDisallowDirectValue)
                    {
                        EditorGUILayout.HelpBox("Cannot specify a value in this context", MessageType.Error);
                    }
                    else
                    {
                        RSValue nextValue = ValueGUILayout.RSValueField(EditorGUIUtility.TrTempContent(inExpectedType.FriendlyName), ioValue.Value, inExpectedType, inFlags, inContext);
                        if (nextValue != ioValue.Value)
                        {
                            inUndo.MarkDirty("Changed Resolvable Value Value");
                            ioValue.Value = nextValue;
                        }
                    }
                    break;
                }

                case ResolvableValueMode.Register:
                {
                    RegisterIndex nextRegister = (RegisterIndex)EnumGUILayout.EnumField(Content.ResolvableValueRegisterLabel, ioValue.Register);
                    if (nextRegister != ioValue.Register)
                    {
                        inUndo.MarkDirty("Changed Resolvable Value Register");
                        ioValue.Register = nextRegister;
                    }
                    break;
                }

                case ResolvableValueMode.Query:
                {
                    EntityScopedIdentifier query     = ValueGUILayout.QueryField(Content.ResolvableValueQueryLabel, ioValue.Query, inExpectedType, inFlags.ForMethod(true), inContext);
                    RSQueryInfo            queryInfo = inContext.Library.GetQuery(query.Id);
                    if (query != ioValue.Query)
                    {
                        bool bChangedId = query.Id != ioValue.Query.Id;
                        inUndo.MarkDirty("Changed Resolvable Value Query", true);
                        ioValue.Query = query;

                        if (bChangedId)
                        {
                            if (queryInfo == null)
                            {
                                ioValue.QueryArguments = null;
                            }
                            else
                            {
                                queryInfo.PopulateDefaultArguments(ioValue);
                            }
                        }
                    }

                    int currentArgsLength = 0;
                    if (ioValue.QueryArguments != null)
                    {
                        currentArgsLength = ioValue.QueryArguments.Length;
                    }
                    int desiredArgsLength = 0;
                    if (queryInfo != null && queryInfo.Parameters != null)
                    {
                        desiredArgsLength = queryInfo.Parameters.Length;
                    }

                    if (desiredArgsLength == 0 && ioValue.QueryArguments != null)
                    {
                        inUndo.MarkDirtyWithoutUndo("Resizing Arguments", true);
                        ioValue.QueryArguments = null;
                    }
                    else if (desiredArgsLength > 0 && currentArgsLength != desiredArgsLength)
                    {
                        inUndo.MarkDirtyWithoutUndo("Resizing Arguments", true);
                        queryInfo.PopulateDefaultArguments(ioValue, currentArgsLength);
                    }

                    if (ioValue.QueryArguments != null && ioValue.QueryArguments.Length > 0)
                    {
                        using (new EditorGUI.IndentLevelScope())
                        {
                            EditorGUILayout.Space();
                            EditorGUILayout.LabelField(Content.ResolvableValueQueryArgsLabel, RSGUIStyles.SubHeaderStyle);
                            for (int i = 0; i < ioValue.QueryArguments.Length && i < queryInfo.Parameters.Length; ++i)
                            {
                                NestedValue nextValue = ValueGUILayout.NestedParameterField(queryInfo.Parameters[i], ioValue.QueryArguments[i], inFlags, inContext);
                                if (nextValue != ioValue.QueryArguments[i])
                                {
                                    inUndo.MarkDirty("Changed Resolvable Value Query Argument");
                                    ioValue.QueryArguments[i] = nextValue;
                                }
                            }
                        }
                    }

                    break;
                }
                }
            }

            EditorGUILayout.EndVertical();
        }
예제 #24
0
 /// <summary>
 /// Renders a layout editor for an RSValue.
 /// </summary>
 static public RSValue RSValueField(GUIContent inLabel, RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoRSValueField(inLabel, inValue, inExpectedType, inFlags, inContext));
 }