Beispiel #1
0
            /// <inheritdoc />
            public override DragDropEffect OnDragEnter(ref Vector2 location, DragData data)
            {
                var result = base.OnDragEnter(ref location, data);

                if (result == DragDropEffect.None)
                {
                    if (_dragHandlers == null)
                    {
                        _dragHandlers = new DragHandlers();
                    }
                    if (_dragAssets == null)
                    {
                        _dragAssets = new DragAssets(ValidateDragAsset);
                        _dragHandlers.Add(_dragAssets);
                    }
                    if (_dragAssets.OnDragEnter(data))
                    {
                        return(_dragAssets.Effect);
                    }
                    if (_dragActorType == null)
                    {
                        _dragActorType = new DragActorType(ValidateDragActorType);
                        _dragHandlers.Add(_dragActorType);
                    }
                    if (_dragActorType.OnDragEnter(data))
                    {
                        return(_dragActorType.Effect);
                    }
                }
                return(result);
            }
Beispiel #2
0
        /// <inheritdoc />
        public override DragDropEffect OnDragEnter(ref Float2 location, DragData data)
        {
            var result = base.OnDragEnter(ref location, data);

            if (Editor.StateMachine.CurrentState.CanEditScene)
            {
                if (_dragHandlers == null)
                {
                    _dragHandlers = new DragHandlers();
                }
                if (_dragAssets == null)
                {
                    _dragAssets = new DragAssets(ValidateDragAsset);
                    _dragHandlers.Add(_dragAssets);
                }
                if (_dragAssets.OnDragEnter(data) && result == DragDropEffect.None)
                {
                    return(_dragAssets.Effect);
                }
                if (_dragActorType == null)
                {
                    _dragActorType = new DragActorType(ValidateDragActorType);
                    _dragHandlers.Add(_dragActorType);
                }
                if (_dragActorType.OnDragEnter(data) && result == DragDropEffect.None)
                {
                    return(_dragActorType.Effect);
                }
            }
            return(result);
        }
Beispiel #3
0
        /// <inheritdoc />
        protected override DragDropEffect OnDragEnterHeader(DragData data)
        {
            // Check if cannot edit scene or there is no scene loaded (handle case for actors in prefab editor)
            if (_actorNode?.ParentScene != null)
            {
                if (!Editor.Instance.StateMachine.CurrentState.CanEditScene || !Level.IsAnySceneLoaded)
                {
                    return(DragDropEffect.None);
                }
            }
            else
            {
                if (!Editor.Instance.StateMachine.CurrentState.CanEditContent)
                {
                    return(DragDropEffect.None);
                }
            }

            if (_dragHandlers == null)
            {
                _dragHandlers = new DragHandlers();
            }

            // Check if drop actors
            if (_dragActors == null)
            {
                _dragActors = new DragActors(ValidateDragActor);
                _dragHandlers.Add(_dragActors);
            }
            if (_dragActors.OnDragEnter(data))
            {
                return(_dragActors.Effect);
            }

            // Check if drag assets
            if (_dragAssets == null)
            {
                _dragAssets = new DragAssets(ValidateDragAsset);
                _dragHandlers.Add(_dragAssets);
            }
            if (_dragAssets.OnDragEnter(data))
            {
                return(_dragAssets.Effect);
            }

            // Check if drag actor type
            if (_dragActorType == null)
            {
                _dragActorType = new DragActorType(ValidateDragActorType);
                _dragHandlers.Add(_dragActorType);
            }
            if (_dragActorType.OnDragEnter(data))
            {
                return(_dragActorType.Effect);
            }

            return(DragDropEffect.None);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PrefabWindowViewport"/> class.
        /// </summary>
        /// <param name="window">Editor window.</param>
        public PrefabWindowViewport(PrefabWindow window)
            : base(true)
        {
            _window = window;
            _window.SelectionChanged += OnSelectionChanged;
            Undo           = window.Undo;
            ViewportCamera = new FPSCamera();

            // Prepare rendering task
            Task.ActorsSource = ActorsSources.CustomActors;
            Task.ViewFlags    = ViewFlags.DefaultEditor & ~ViewFlags.EditorSprites;
            Task.PostRender  += OnPostRender;

            // Create post effects
            SelectionOutline = FlaxEngine.Object.New <SelectionOutline>();
            SelectionOutline.SelectionGetter = () => TransformGizmo.SelectedParents;
            Task.CustomPostFx.Add(SelectionOutline);
            EditorPrimitives          = FlaxEngine.Object.New <EditorPrimitives>();
            EditorPrimitives.Viewport = this;
            Task.CustomPostFx.Add(EditorPrimitives);

            // Add transformation gizmo
            TransformGizmo = new TransformGizmo(this);
            TransformGizmo.ApplyTransformation += ApplyTransform;
            TransformGizmo.ModeChanged         += OnGizmoModeChanged;
            TransformGizmo.Duplicate           += _window.Duplicate;
            Gizmos.Active = TransformGizmo;

            // Transform space widget
            var transformSpaceWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var transformSpaceToggle = new ViewportWidgetButton(string.Empty, window.Editor.Icons.World16, null, true)
            {
                Checked     = TransformGizmo.ActiveTransformSpace == TransformGizmoBase.TransformSpace.World,
                TooltipText = "Gizmo transform space (world or local)",
                Parent      = transformSpaceWidget
            };

            transformSpaceToggle.Toggled += OnTransformSpaceToggle;
            transformSpaceWidget.Parent   = this;

            // Scale snapping widget
            var scaleSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableScaleSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.ScaleStep16, null, true)
            {
                Checked     = TransformGizmo.ScaleSnapEnabled,
                TooltipText = "Enable scale snapping",
                Parent      = scaleSnappingWidget
            };

            enableScaleSnapping.Toggled += OnScaleSnappingToggle;

            var scaleSnappingCM = new ContextMenu();

            _scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
            {
                TooltipText = "Scale snapping values"
            };

            for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
            {
                var v      = EditorViewportScaleSnapValues[i];
                var button = scaleSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            scaleSnappingCM.ButtonClicked  += OnWidgetScaleSnapClick;
            scaleSnappingCM.VisibleChanged += OnWidgetScaleSnapShowHide;
            _scaleSnapping.Parent           = scaleSnappingWidget;
            scaleSnappingWidget.Parent      = this;

            // Rotation snapping widget
            var rotateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableRotateSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.RotateStep16, null, true)
            {
                Checked     = TransformGizmo.RotationSnapEnabled,
                TooltipText = "Enable rotation snapping",
                Parent      = rotateSnappingWidget
            };

            enableRotateSnapping.Toggled += OnRotateSnappingToggle;

            var rotateSnappingCM = new ContextMenu();

            _rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
            {
                TooltipText = "Rotation snapping values"
            };

            for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
            {
                var v      = EditorViewportRotateSnapValues[i];
                var button = rotateSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            rotateSnappingCM.ButtonClicked  += OnWidgetRotateSnapClick;
            rotateSnappingCM.VisibleChanged += OnWidgetRotateSnapShowHide;
            _rotateSnapping.Parent           = rotateSnappingWidget;
            rotateSnappingWidget.Parent      = this;

            // Translation snapping widget
            var translateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableTranslateSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Grid16, null, true)
            {
                Checked     = TransformGizmo.TranslationSnapEnable,
                TooltipText = "Enable position snapping",
                Parent      = translateSnappingWidget
            };

            enableTranslateSnapping.Toggled += OnTranslateSnappingToggle;

            var translateSnappingCM = new ContextMenu();

            _translateSnappng = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
            {
                TooltipText = "Position snapping values"
            };

            for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
            {
                var v      = EditorViewportTranslateSnapValues[i];
                var button = translateSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            translateSnappingCM.ButtonClicked  += OnWidgetTranslateSnapClick;
            translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide;
            _translateSnappng.Parent            = translateSnappingWidget;
            translateSnappingWidget.Parent      = this;

            // Gizmo mode widget
            var gizmoMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);

            _gizmoModeTranslate = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Translate16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Translate,
                TooltipText = "Translate gizmo mode",
                Checked     = true,
                Parent      = gizmoMode
            };
            _gizmoModeTranslate.Toggled += OnGizmoModeToggle;
            _gizmoModeRotate             = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Rotate16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Rotate,
                TooltipText = "Rotate gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeRotate.Toggled += OnGizmoModeToggle;
            _gizmoModeScale           = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Scale16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Scale,
                TooltipText = "Scale gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeScale.Toggled += OnGizmoModeToggle;
            gizmoMode.Parent         = this;

            _dragHandlers.Add(_dragActorType);
            _dragHandlers.Add(_dragAssets);

            // Setup input actions
            InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
            InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode    = TransformGizmoBase.Mode.Rotate);
            InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode     = TransformGizmoBase.Mode.Scale);
            InputActions.Add(options => options.FocusSelection, ShowSelectedActors);

            SetUpdate(ref _update, OnUpdate);
        }
Beispiel #5
0
 /// <inheritdoc />
 public VisualScriptSurface(IVisjectSurfaceOwner owner, Action onSave, FlaxEditor.Undo undo)
     : base(owner, onSave, undo, null, null, true)
 {
     _supportsImplicitCastFromObjectToBoolean = true;
     DragHandlers.Add(_dragActors             = new DragActors(ValidateDragActor));
 }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainEditorGizmoViewport"/> class.
        /// </summary>
        /// <param name="editor">Editor instance.</param>
        public MainEditorGizmoViewport(Editor editor)
            : base(FlaxEngine.Rendering.RenderTask.Create <SceneRenderTask>(), editor.Undo)
        {
            _editor = editor;

            // Prepare rendering task
            Task.ActorsSource = ActorsSources.ScenesAndCustomActors;
            Task.Flags        = ViewFlags.DefaultEditor;
            Task.Begin       += RenderTaskOnBegin;
            Task.Draw        += RenderTaskOnDraw;
            Task.End         += RenderTaskOnEnd;

            // Render task after the main game task so streaming and render state data will use main game task instead of editor preview
            Task.Order = 1;

            // Create post effects
            SelectionOutline = FlaxEngine.Object.New <SelectionOutline>();
            SelectionOutline.SelectionGetter = () => _editor.SceneEditing.Selection;
            Task.CustomPostFx.Add(SelectionOutline);
            EditorPrimitives = FlaxEngine.Object.New <EditorPrimitives>();
            EditorPrimitives.DrawDebugDraw = true;
            EditorPrimitives.Viewport      = this;
            Task.CustomPostFx.Add(EditorPrimitives);

            // Add transformation gizmo
            TransformGizmo = new TransformGizmo(this);
            TransformGizmo.OnApplyTransformation += ApplyTransform;
            TransformGizmo.ModeChanged           += OnGizmoModeChanged;
            TransformGizmo.Duplicate             += Editor.Instance.SceneEditing.Duplicate;
            Gizmos.Active = TransformGizmo;

            // Add grid
            Grid = new GridGizmo(this);
            Grid.EnabledChanged += gizmo => _showGridButton.Icon = gizmo.Enabled ? Style.Current.CheckBoxTick : Sprite.Invalid;

            editor.SceneEditing.SelectionChanged += OnSelectionChanged;

            // Transform space widget
            var transformSpaceWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var transformSpaceToggle = new ViewportWidgetButton(string.Empty, editor.Icons.World16, null, true)
            {
                Checked     = TransformGizmo.ActiveTransformSpace == TransformGizmo.TransformSpace.World,
                TooltipText = "Gizmo transform space (world or local)",
                Parent      = transformSpaceWidget
            };

            transformSpaceToggle.OnToggle += OnTransformSpaceToggle;
            transformSpaceWidget.Parent    = this;

            // Scale snapping widget
            var scaleSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableScaleSnapping = new ViewportWidgetButton(string.Empty, editor.Icons.ScaleStep16, null, true)
            {
                Checked     = TransformGizmo.ScaleSnapEnabled,
                TooltipText = "Enable scale snapping",
                Parent      = scaleSnappingWidget
            };

            enableScaleSnapping.OnToggle += OnScaleSnappingToggle;
            var scaleSnappingCM = new ContextMenu();

            _scaleSnapping             = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), Sprite.Invalid, scaleSnappingCM);
            _scaleSnapping.TooltipText = "Scale snapping values";
            for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
            {
                var v      = EditorViewportScaleSnapValues[i];
                var button = scaleSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            scaleSnappingCM.ButtonClicked  += OnWidgetScaleSnapClick;
            scaleSnappingCM.VisibleChanged += OnWidgetScaleSnapShowHide;
            _scaleSnapping.Parent           = scaleSnappingWidget;
            scaleSnappingWidget.Parent      = this;

            // Rotation snapping widget
            var rotateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableRotateSnapping = new ViewportWidgetButton(string.Empty, editor.Icons.RotateStep16, null, true)
            {
                Checked     = TransformGizmo.RotationSnapEnabled,
                TooltipText = "Enable rotation snapping",
                Parent      = rotateSnappingWidget
            };

            enableRotateSnapping.OnToggle += OnRotateSnappingToggle;
            var rotateSnappingCM = new ContextMenu();

            _rotateSnapping             = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), Sprite.Invalid, rotateSnappingCM);
            _rotateSnapping.TooltipText = "Rotation snapping values";
            for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
            {
                var v      = EditorViewportRotateSnapValues[i];
                var button = rotateSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            rotateSnappingCM.ButtonClicked  += OnWidgetRotateSnapClick;
            rotateSnappingCM.VisibleChanged += OnWidgetRotateSnapShowHide;
            _rotateSnapping.Parent           = rotateSnappingWidget;
            rotateSnappingWidget.Parent      = this;

            // Translation snapping widget
            var translateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableTranslateSnapping = new ViewportWidgetButton(string.Empty, editor.Icons.Grid16, null, true)
            {
                Checked     = TransformGizmo.TranslationSnapEnable,
                TooltipText = "Enable position snapping",
                Parent      = translateSnappingWidget
            };

            enableTranslateSnapping.OnToggle += OnTranslateSnappingToggle;
            var translateSnappingCM = new ContextMenu();

            _translateSnapping             = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), Sprite.Invalid, translateSnappingCM);
            _translateSnapping.TooltipText = "Position snapping values";
            for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
            {
                var v      = EditorViewportTranslateSnapValues[i];
                var button = translateSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            translateSnappingCM.ButtonClicked  += OnWidgetTranslateSnapClick;
            translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide;
            _translateSnapping.Parent           = translateSnappingWidget;
            translateSnappingWidget.Parent      = this;

            // Gizmo mode widget
            var gizmoMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);

            _gizmoModeTranslate = new ViewportWidgetButton(string.Empty, editor.Icons.Translate16, null, true)
            {
                Tag         = TransformGizmo.Mode.Translate,
                TooltipText = "Translate gizmo mode",
                Checked     = true,
                Parent      = gizmoMode
            };
            _gizmoModeTranslate.OnToggle += OnGizmoModeToggle;
            _gizmoModeRotate              = new ViewportWidgetButton(string.Empty, editor.Icons.Rotate16, null, true)
            {
                Tag         = TransformGizmo.Mode.Rotate,
                TooltipText = "Rotate gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeRotate.OnToggle += OnGizmoModeToggle;
            _gizmoModeScale            = new ViewportWidgetButton(string.Empty, editor.Icons.Scale16, null, true)
            {
                Tag         = TransformGizmo.Mode.Scale,
                TooltipText = "Scale gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeScale.OnToggle += OnGizmoModeToggle;
            gizmoMode.Parent          = this;

            // Show grid widget
            _showGridButton               = ViewWidgetButtonMenu.AddButton("Show grid", () => Grid.Enabled = !Grid.Enabled);
            _showGridButton.Icon          = Style.Current.CheckBoxTick;
            _showGridButton.IndexInParent = 1;

            // Create camera widget
            ViewWidgetButtonMenu.AddSeparator();
            ViewWidgetButtonMenu.AddButton("Create camera here", CreateCameraAtView);

            DragHandlers.Add(_dragActorType);
            DragHandlers.Add(_dragAssets);

            InitModes();
        }
        /// <inheritdoc />
        protected override void SetupDragDrop()
        {
            base.SetupDragDrop();

            DragHandlers.Add(new DragHandler(new DragAssets(IsValidAsset), OnDragAsset));
        }