Example #1
0
 public void PopulateDefaultArguments(RSActionData ioData)
 {
     if (Parameters == null || Parameters.Length == 0)
     {
         ioData.Arguments = null;
     }
     else
     {
         Array.Resize(ref ioData.Arguments, Parameters.Length);
         for (int i = 0; i < Parameters.Length; ++i)
         {
             RSResolvableValueData.SetAsValue(ref ioData.Arguments[i], Parameters[i].Default);
         }
     }
 }
Example #2
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();
        }
Example #3
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;
                        }
                    }
                }
            }
        }