Ejemplo n.º 1
0
        public AbstractParameterDrawer GetDrawer(AbstractParameter parameter)
        {
            AbstractParameterDrawer paramDrawer;
            var result = drawersByParameterType.TryGetValue(parameter.GetType(), out paramDrawer);

            if (!result)
            {
                Debug.LogError("Fail to get ParamDrawer for type: " + parameter.GetType() +
                               " probably drawer is not implemented or not added to factory.");
            }
            return(paramDrawer);
        }
 public abstract void EditorDraw(AbstractParameter parameter,
                                 Rect rect, MethodInfo methodInfo);
Ejemplo n.º 3
0
        private void DrawUserClickInfo(Rect rect, int index, bool isActive, bool isFocused)
        {
            float topLineHeight  = EditorGUIUtility.singleLineHeight;
            var   rectToDrawWith = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);

            var userAction = (UserActionInfo)reorderableList.list[index];

            if (userAction.SelectedAssertation == null || userAction.SelectedAssertation.methodInfo == null)
            {
                Debug.LogError(String.Format("UITestFlowRecorderWindow: SELECTED ASSERTATION OR ITS METHOD INFO IS NULL FOR ELEMENT #{0}", index));

                toRemove = userAction;

                return;
            }

            AbstractParameter[] parameters = new AbstractParameter[0];
            if (userAction.SelectedCodeGenerator != null)
            {
                var generators = userAction.SelectedCodeGenerator.CalculateGeneratorSequence();
                parameters = generators.OfType <AbstractParameter>().ToArray();
            }

            var shiftY = (heights[index] - EditorGUIUtility.singleLineHeight) / (parameters.Length + 2);

            rectToDrawWith.y += EditorGUIUtility.singleLineHeight * 0.5f;

            rectToDrawWith.width -= 64;

            rectToDrawWith.width -= 62;
            rectToDrawWith.x     += 30;

            var style = new GUIStyle(GUI.skin.label)
            {
                fontSize = INDEX_SIZE, normal = new GUIStyleState()
                {
                    textColor = indexColor
                }, stretchWidth = true, fixedHeight = INDEX_SIZE + 10
            };

            EditorGUI.LabelField(new Rect(rectToDrawWith.x - 30, rectToDrawWith.y, 30, rectToDrawWith.height), (index + 1).ToString(), style);

            if (userAction.SelectedAssertation == null)
            {
                return;
            }

            var labelForButton = userAction.SelectedAssertation.AssertationMethodDescription;

            labelForButton = labelForButton.Replace("/", " / ");
            if (GUI.Button(rectToDrawWith, labelForButton))
            {
                GenericMenu menu = new GenericMenu();
                for (int i = 0; i < userAction.AvailableAssertations.Count; i++)
                {
                    AddMenuItem(menu, userAction.AvailableAssertations[i].AssertationMethodDescription, userAction, i);
                }

                menu.ShowAsContext();
            }

            rectToDrawWith.width += 62;
            rectToDrawWith.x     -= 30;


            Rect buttonRect = new Rect();

            buttonRect.x      = rectToDrawWith.width + rectToDrawWith.x - 30;
            buttonRect.y      = rectToDrawWith.y;
            buttonRect.height = 16;
            buttonRect.width  = 30;


            EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying);
            if (GUI.Button(buttonRect, "►"))
            {
                controller.ApplyAction(userAction);
            }

            buttonRect.x    += 32;
            buttonRect.width = 37;
            EditorGUI.EndDisabledGroup();

            if (CopyShortcutPressed && isFocused)
            {
                indexToCopy = index;

                Repaint();
            }

            if (GUI.Button(buttonRect, "copy"))
            {
                indexToCopy = index;
            }
            buttonRect.x      = rectToDrawWith.width + rectToDrawWith.x + 41;
            buttonRect.y      = rectToDrawWith.y;
            buttonRect.height = 16;
            buttonRect.width  = 22;

            if (GUI.Button(buttonRect, "x"))
            {
                toRemove = (UserActionInfo)reorderableList.list[index];
            }
            rectToDrawWith.width += 64 - 28;

            rectToDrawWith.y           += shiftY + 4;
            rectToDrawWith.x           += 28;
            EditorGUIUtility.labelWidth = 100;

            userAction.Description = EditorGUI.TextField(rectToDrawWith, "Description: ", userAction.Description);

            foreach (var parameter in parameters)
            {
                rectToDrawWith.y += shiftY;
                var drawer = drawersFactory.GetDrawer(parameter);
                if (drawer != null)
                {
                    drawer.EditorDraw(parameter, rectToDrawWith,
                                      userAction.SelectedAssertation.methodInfo);
                }
            }
        }