public ContextGenericMenuPopup(GitOverlay gitOverlay, GitAnimation gitAnimation) { this.gitOverlay = gitOverlay; this.gitAnimation = gitAnimation; elements = new List <Element>(); transitionTween = GitAnimation.Empty; }
private void DrawElementList(Rect rect, List <Element> elements, bool drawBack) { float height = 0; if (drawBack) { Rect backRect = new Rect(rect.x, rect.y + height, rect.width, elementStyle.fixedHeight); int backControlId = GUIUtility.GetControlID(GitGUI.GetTempContent("Back"), FocusType.Passive, backRect); if (Event.current.type == EventType.Repaint) { EditorGUIUtility.AddCursorRect(backRect, MouseCursor.Link); elementStyle.Draw(backRect, GitGUI.GetTempContent("Back"), false, false, backRect.Contains(Event.current.mousePosition), false); ((GUIStyle)"AC LeftArrow").Draw(new Rect(backRect.x, backRect.y + ((backRect.height - 16) / 2f), 16, 16), GUIContent.none, false, false, false, false); if (backRect.Contains(Event.current.mousePosition) && !transitionTween.Valid) { if (lastHoverControlId != backControlId) { lastHoverControlId = backControlId; lastHoverStartTime = EditorApplication.timeSinceStartup; } isClickHovering = true; DrawHoverClickIndicator(); } } else if (((Event.current.type == EventType.MouseDown && Event.current.button == 0 && backRect.Contains(Event.current.mousePosition)) || (lastHoverControlId == backControlId && EditorApplication.timeSinceStartup > lastHoverStartTime + HoverPressTime)) && !transitionTween.Valid && currentElement != null) { lastElement = currentElement; currentElement = currentElement.parent; transitionTween = gitAnimation.StartAnimation(AnimationTime, editorWindow, GitSettingsJson.AnimationTypeEnum.ContextMenu); lastHoverStartTime = EditorApplication.timeSinceStartup; animDir = -1; } height = elementStyle.fixedHeight; } for (int i = 0; i < elements.Count; i++) { var element = elements[i]; Rect elementRect = new Rect(rect.x, rect.y + height, rect.width, elementStyle.fixedHeight); int controlId = GUIUtility.GetControlID(element.Content, FocusType.Passive, elementRect); if (element.isSeparator) { if (Event.current.type == EventType.Repaint) { GUI.backgroundColor = new Color(1, 1, 1, 0.2f); Rect separatorRect = new Rect(rect.x + separatorStyle.margin.left, rect.y + height, rect.width - separatorStyle.margin.left - separatorStyle.margin.right, separatorStyle.fixedHeight); separatorStyle.Draw(separatorRect, element.Content, false, false, false, false); GUI.backgroundColor = Color.white; } height += separatorStyle.fixedHeight; } else { if (Event.current.type == EventType.Repaint) { GUI.enabled = !element.isDisabled; if (GUI.enabled) { EditorGUIUtility.AddCursorRect(elementRect, MouseCursor.Link); } elementStyle.Draw(elementRect, element.Content, controlId, elementRect.Contains(Event.current.mousePosition)); if (element.children != null) { ((GUIStyle)"AC RightArrow").Draw(new Rect(elementRect.x + elementRect.width - 21, elementRect.y + ((elementRect.height - 21) / 2f), 21, 21), GUIContent.none, false, false, false, false); } if (elementRect.Contains(Event.current.mousePosition) && !transitionTween.Valid) { if (element.IsParent) { if (lastHoverControlId != controlId) { lastHoverControlId = controlId; lastHoverStartTime = EditorApplication.timeSinceStartup; } isClickHovering = true; DrawHoverClickIndicator(); } else { lastHoverControlId = controlId; lastHoverStartTime = EditorApplication.timeSinceStartup; isClickHovering = false; } } } else if (element.IsParent && ((lastHoverControlId == controlId && EditorApplication.timeSinceStartup > lastHoverStartTime + HoverPressTime) || (Event.current.type == EventType.MouseDown && elementRect.Contains(Event.current.mousePosition)))) { lastElement = currentElement; currentElement = element; transitionTween = gitAnimation.StartAnimation(AnimationTime, GitSettingsJson.AnimationTypeEnum.ContextMenu); lastHoverStartTime = EditorApplication.timeSinceStartup; animDir = 1; editorWindow.Repaint(); } else if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && elementRect.Contains(Event.current.mousePosition) && !transitionTween.Valid) { editorWindow.Close(); if (element.Func != null) { element.Func.Invoke(); } else if (element.Func2 != null) { element.Func2.Invoke(element.data); } } height += elementStyle.fixedHeight; } } }