示例#1
0
        /// <summary>
        /// Draws the element, returning an event that indicates how the minibuttons are pressed.
        /// </summary>
        /// <param name="containingRect">The rect to draw the element inside.</param>
        /// <param name = "guiOptions">Options to use when drawing the operation GUI.</param>
        /// <returns>A ListButtonEvent indicating if a button was clicked.</returns>
        public RenameOperationSortingButtonEvent DrawGUI(Rect containingRect, RenameOperationGUIOptions guiOptions)
        {
            var paddedContainer = containingRect.AddPadding(Padding.left, Padding.right, Padding.top, Padding.bottom);
            var operationStyle  = new GUIStyle("ScriptText");

            GUI.Box(containingRect, "", operationStyle);
            var headerRect = new Rect(paddedContainer);

            headerRect.height = HeaderHeight;
            RenameOperationSortingButtonEvent buttonEvent = this.DrawHeaderAndReorderButtons(
                headerRect,
                this.HeadingLabel,
                guiOptions.DisableUpButton,
                guiOptions.DisableDownButton);

            EditorGUI.indentLevel++;
            var contentsRect = new Rect(paddedContainer);

            contentsRect.y      += headerRect.height + HeaderAndContentSpacing;
            contentsRect.height -= headerRect.height;
            this.DrawContents(contentsRect, guiOptions.ControlPrefix);
            EditorGUI.indentLevel--;

            var coloredHighlightRect = new Rect(containingRect);

            coloredHighlightRect.yMin += 2.0f;
            coloredHighlightRect.yMax -= 1.0f;
            coloredHighlightRect.xMin += 2.0f;
            coloredHighlightRect.width = 3.0f;
            var oldColor = GUI.color;

            GUI.color = this.HighlightColor;
            GUI.DrawTexture(coloredHighlightRect, Texture2D.whiteTexture);
            GUI.color = oldColor;

            return(buttonEvent);
        }
示例#2
0
        private void DrawRenameOperations(Rect operationRect, float spacing)
        {
            var headerRect = new Rect(operationRect);

            headerRect.height = 18.0f;
            var operationStyle = new GUIStyle("ScriptText");

            GUI.Box(headerRect, "", operationStyle);
            var headerStyle = new GUIStyle(EditorStyles.boldLabel);

            headerStyle.alignment = TextAnchor.MiddleCenter;
            EditorGUI.LabelField(headerRect, "Rename Operations", headerStyle);

            // Store the op before buttons are pressed because buttons change focus
            var              focusedOpBeforeButtonPresses = this.FocusedRenameOp;
            bool             saveOpsToPreferences         = false;
            IRenameOperation operationToFocus             = null;

            var totalHeightDrawn = 0.0f;

            for (int i = 0; i < this.NumRenameOperations; ++i)
            {
                var currentElement = this.RenameOperationsToApplyWithBindings[i];
                var rect           = new Rect(operationRect);
                rect.y           += totalHeightDrawn + spacing + headerRect.height;
                rect.height       = currentElement.Drawer.GetPreferredHeight();
                totalHeightDrawn += rect.height + spacing;

                var guiOptions = new RenameOperationGUIOptions();
                guiOptions.ControlPrefix     = i;
                guiOptions.DisableUpButton   = i == 0;
                guiOptions.DisableDownButton = i == this.NumRenameOperations - 1;
                var buttonClickEvent = currentElement.Drawer.DrawGUI(rect, guiOptions);
                switch (buttonClickEvent)
                {
                case RenameOperationSortingButtonEvent.MoveUp:
                {
                    this.RenameOperationsToApplyWithBindings.MoveElementFromIndexToIndex(i, i - 1);
                    saveOpsToPreferences = true;

                    // Move focus with the RenameOp. This techincally changes their focus within the
                    // rename op, but it's better than focus getting swapped to whatever op replaces this one.
                    operationToFocus = focusedOpBeforeButtonPresses;
                    break;
                }

                case RenameOperationSortingButtonEvent.MoveDown:
                {
                    this.RenameOperationsToApplyWithBindings.MoveElementFromIndexToIndex(i, i + 1);
                    saveOpsToPreferences = true;
                    operationToFocus     = focusedOpBeforeButtonPresses;
                    break;
                }

                case RenameOperationSortingButtonEvent.Delete:
                {
                    var removingFocusedOperation = focusedOpBeforeButtonPresses == currentElement;

                    this.RenameOperationsToApplyWithBindings.RemoveAt(i);
                    saveOpsToPreferences = true;

                    if (removingFocusedOperation && this.NumRenameOperations > 0)
                    {
                        // Focus the RenameOp that took this one's place, if there is one.
                        var indexToFocus = Mathf.Min(this.NumRenameOperations - 1, i);
                        operationToFocus = this.RenameOperationsToApplyWithBindings[indexToFocus].Operation;
                    }
                    else
                    {
                        operationToFocus = focusedOpBeforeButtonPresses;
                    }

                    break;
                }

                case RenameOperationSortingButtonEvent.None:
                {
                    // Do nothing
                    break;
                }

                default:
                {
                    Debug.LogError(string.Format(
                                       "RenamerWindow found Unrecognized ListButtonEvent [{0}] in OnGUI. Add a case to handle this event.",
                                       buttonClickEvent));
                    return;
                }
                }

                if (operationToFocus != null)
                {
                    this.FocusRenameOperationDeferred(operationToFocus);
                }

                if (saveOpsToPreferences)
                {
                    this.SaveRenameOperationsToPreferences();
                }
            }
        }