Example #1
0
        /// <summary>
        /// Rebuilds the editor layout. Cleans the whole UI with child elements/editors and then builds new hierarchy. Call it only when necessary.
        /// </summary>
        public void RebuildLayout()
        {
            // Special case for root objects to run normal layout build
            if (_presenter.Selection == Values)
            {
                _presenter.BuildLayout();
                return;
            }

            var values        = _values;
            var presenter     = _presenter;
            var layout        = _layout;
            var control       = layout.ContainerControl;
            var parent        = _parent;
            var parentScrollV = (_presenter.Panel.Parent as Panel)?.VScrollBar?.Value ?? -1;

            control.IsLayoutLocked = true;
            control.DisposeChildren();

            layout.ClearLayout();
            Cleanup();

            _parent = parent;
            Initialize(presenter, layout, values);

            control.IsLayoutLocked = false;
            control.PerformLayout();

            // Restore scroll value
            if (parentScrollV > -1 && _presenter != null && _presenter.Panel.Parent is Panel panel && panel.VScrollBar != null)
            {
                panel.VScrollBar.Value = parentScrollV;
            }
        }
Example #2
0
        /// <summary>
        /// Rebuilds the editor layout. Cleans the whole UI with child elements/editors and then builds new hierarchy. Call it only when necessary.
        /// </summary>
        public void RebuildLayout()
        {
            var values        = _values;
            var presenter     = _presenter;
            var layout        = _layout;
            var control       = layout.ContainerControl;
            var parent        = _parent;
            var parentScrollV = (_presenter.Panel.Parent as Panel)?.VScrollBar?.Value ?? -1;

            control.IsLayoutLocked = true;
            control.DisposeChildren();

            layout.ClearLayout();
            Cleanup();

            _parent = parent;
            Initialize(presenter, layout, values);

            control.UnlockChildrenRecursive();
            control.PerformLayout();

            // Restore scroll value
            if (parentScrollV > -1)
            {
                ((Panel)_presenter.Panel.Parent).VScrollBar.Value = parentScrollV;
            }
        }
Example #3
0
        /// <summary>
        /// Adds new group element.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="linkedEditor">The custom editor to be linked for a group. Used to provide more utility functions for a drop panel UI via context menu.</param>
        /// <param name="useTransparentHeader">True if use drop down icon and transparent group header, otherwise use normal style.</param>
        /// <returns>The created element.</returns>
        public GroupElement Group(string title, CustomEditor linkedEditor, bool useTransparentHeader = false)
        {
            var element = Group(title, useTransparentHeader);

            element.Panel.Tag = linkedEditor;
            element.Panel.MouseButtonRightClicked += OnGroupPanelMouseButtonRightClicked;
            return(element);
        }
Example #4
0
        /// <summary>
        /// Called when editor is added.
        /// </summary>
        /// <param name="editor">The editor.</param>
        protected virtual void OnAddEditor(CustomEditor editor)
        {
            // This could be passed by the calling code but it's easier to hide it from the user
            // Note: we need that custom editor to link generated editor into the parent
            var customEditor = CustomEditor.CurrentCustomEditor;

            Assert.IsNotNull(customEditor);
            customEditor.OnChildCreated(editor);
        }
Example #5
0
 private Actor FindPrefabRoot(CustomEditor editor)
 {
     if (editor.Values[0] is Actor actor)
     {
         return(FindPrefabRoot(actor));
     }
     if (editor.ParentEditor != null)
     {
         return(FindPrefabRoot(editor.ParentEditor));
     }
     return(null);
 }
Example #6
0
        /// <inheritdoc />
        protected override bool OnDirty(CustomEditor editor, object value, object token = null)
        {
            // End any active Undo action batching
            if (token != _setValueToken)
            {
                EndUndoRecord();
            }
            _setValueToken = token;

            // Mark as modified and don't pass event further
            _isDirty = true;
            return(false);
        }
Example #7
0
        /// <summary>
        /// Adds object(s) editor. Selects proper <see cref="CustomEditor"/> based on overrides.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="overrideEditor">The custom editor to use. If null will detect it by auto.</param>
        /// <returns>The created element.</returns>
        public CustomEditor Object(ValueContainer values, CustomEditor overrideEditor = null)
        {
            if (values == null)
            {
                throw new ArgumentNullException();
            }

            var editor = CustomEditorsUtil.CreateEditor(values, overrideEditor);

            OnAddEditor(editor);
            editor.Initialize(CustomEditor.CurrentCustomEditor.Presenter, this, values);

            return(editor);
        }
Example #8
0
        /// <summary>
        /// Cleanups this editor resources and child editors.
        /// </summary>
        internal void Cleanup()
        {
            for (int i = 0; i < _children.Count; i++)
            {
                _children[i].Cleanup();
            }

            _children.Clear();
            _presenter     = null;
            _parent        = null;
            _hasValueDirty = false;
            _valueToSet    = null;
            _values        = null;
            _isSetBlocked  = false;
        }
Example #9
0
        internal static CustomEditor CreateEditor(ValueContainer values, CustomEditor overrideEditor, bool canUseRefPicker = true)
        {
            // Check if use provided editor
            if (overrideEditor != null)
            {
                return(overrideEditor);
            }

            // Special case if property is a pure object type and all values are the same type
            if (values.Type.Type == typeof(object) && values.Count > 0 && values[0] != null && !values.HasDifferentTypes)
            {
                return(CreateEditor(TypeUtils.GetObjectType(values[0]), canUseRefPicker));
            }

            // Use editor for the property type
            return(CreateEditor(values.Type, canUseRefPicker));
        }
Example #10
0
        /// <summary>
        /// Cleanups this editor resources and child editors.
        /// </summary>
        internal void Cleanup()
        {
            Deinitialize();

            for (int i = 0; i < _children.Count; i++)
            {
                _children[i].Cleanup();
            }

            _children.Clear();
            _presenter        = null;
            _parent           = null;
            _hasValueDirty    = false;
            _valueToSet       = null;
            _values           = null;
            _isSetBlocked     = false;
            _rebuildOnRefresh = false;
            LinkedLabel       = null;
        }
Example #11
0
        private void RevertDiffToReference(CustomEditor editor)
        {
            if (editor.ChildrenEditors.Count == 0)
            {
                // Skip if no change detected
                if (!editor.Values.IsReferenceValueModified)
                {
                    return;
                }

                editor.SetValueToReference();
            }
            else
            {
                for (int i = 0; i < editor.ChildrenEditors.Count; i++)
                {
                    RevertDiffToReference(editor.ChildrenEditors[i]);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Adds object property editor. Selects proper <see cref="CustomEditor"/> based on overrides.
        /// </summary>
        /// <param name="label">The property label.</param>
        /// <param name="values">The values.</param>
        /// <param name="overrideEditor">The custom editor to use. If null will detect it by auto.</param>
        /// <param name="tooltip">The property label tooltip text.</param>
        /// <returns>The created element.</returns>
        public CustomEditor Property(PropertyNameLabel label, ValueContainer values, CustomEditor overrideEditor = null, string tooltip = null)
        {
            var editor = CustomEditorsUtil.CreateEditor(values, overrideEditor);
            var style  = editor.Style;

            if (style == DisplayStyle.InlineIntoParent)
            {
                return(Object(values, editor));
            }

            if (style == DisplayStyle.Group)
            {
                var group = Group(label.Name, true);
                group.Panel.Close(false);
                return(group.Object(values, editor));
            }

            var property = AddPropertyItem(label, tooltip);

            return(property.Object(values, editor));
        }
Example #13
0
        /// <summary>
        /// Adds object property editor. Selects proper <see cref="CustomEditor"/> based on overrides.
        /// </summary>
        /// <param name="name">The property name.</param>
        /// <param name="values">The values.</param>
        /// <param name="overrideEditor">The custom editor to use. If null will detect it by auto.</param>
        /// <param name="tooltip">The property label tooltip text.</param>
        /// <returns>The created element.</returns>
        public CustomEditor Property(string name, ValueContainer values, CustomEditor overrideEditor = null, string tooltip = null)
        {
            var editor = CustomEditorsUtil.CreateEditor(values, overrideEditor);
            var style  = editor.Style;

            if (style == DisplayStyle.InlineIntoParent || name == EditorDisplayAttribute.InlineStyle)
            {
                return(Object(values, editor));
            }

            if (style == DisplayStyle.Group)
            {
                var group = Group(name, editor, true);
                group.Panel.Close(false);
                group.Panel.TooltipText = tooltip;
                return(group.Object(values, editor));
            }

            var property = AddPropertyItem(name, tooltip);

            return(property.Object(values, editor));
        }
Example #14
0
            /// <inheritdoc />
            public override void Initialize(LayoutElementsContainer layout)
            {
                var selection = Presenter.Selection;

                if (selection.Count > 0)
                {
                    Type type = typeof(object);
                    if (selection.HasDiffrentTypes == false)
                    {
                        type = selection[0].GetType();
                    }
                    Editor = CustomEditorsUtil.CreateEditor(type, false);
                    Editor.Initialize(Presenter, Presenter, selection);
                    OnChildCreated(Editor);
                }
                else
                {
                    var label = layout.Label(_noSelectionText, TextAlignment.Center);
                    label.Label.Height = 20.0f;
                }

                base.Initialize(layout);
            }
Example #15
0
        /// <summary>
        /// Adds object(s) editor with name label. Selects proper <see cref="CustomEditor"/> based on overrides.
        /// </summary>
        /// <param name="name">The property name.</param>
        /// <param name="values">The values.</param>
        /// <param name="overrideEditor">The custom editor to use. If null will detect it by auto.</param>
        /// <param name="tooltip">The property label tooltip text.</param>
        /// <returns>The created element.</returns>
        public CustomEditor Object(string name, ValueContainer values, CustomEditor overrideEditor = null, string tooltip = null)
        {
            var property = AddPropertyItem(name, tooltip);

            return(property.Object(values, overrideEditor));
        }
Example #16
0
 /// <inheritdoc />
 protected override bool OnDirty(CustomEditor editor, object value)
 {
     // Mark as modified and don't pass event futher
     _isDirty = true;
     return(false);
 }
Example #17
0
 /// <summary>
 /// Called when custom editor gets dirty (UI value has been modified).
 /// Allows to filter the event, block it or handle in a custom way.
 /// </summary>
 /// <param name="editor">The editor.</param>
 /// <param name="value">The value.</param>
 /// <param name="token">The source editor token used by the value setter to support batching Undo actions (eg. for sliders or color pickers).</param>
 /// <returns>True if allow to handle this event, otherwise false.</returns>
 protected virtual bool OnDirty(CustomEditor editor, object value, object token = null)
 {
     ParentEditor.OnDirty(editor, value, token);
     return(true);
 }
Example #18
0
 internal void OnChildCreated(CustomEditor child)
 {
     // Link
     _children.Add(child);
     child._parent = this;
 }