Ejemplo n.º 1
0
        private void OnAddButtonClicked()
        {
            var menu = new ContextMenu.ContextMenu();

            OnShowAddContextMenu(menu);
            menu.Show(_addButton.Parent, _addButton.BottomLeft);
        }
Ejemplo n.º 2
0
        private void ShowContextMenu(DockWindow tab, ref Vector2 location)
        {
            var menu = new ContextMenu.ContextMenu();

            menu.Tag = tab;
            tab.OnShowContextMenu(menu);
            menu.AddButton("Close", OnTabMenuCloseClicked);
            menu.AddButton("Close All", OnTabMenuCloseAllClicked);
            menu.AddButton("Close All But This", OnTabMenuCloseAllButThisClicked);
            if (_panel.Tabs.IndexOf(tab) + 1 < _panel.TabsCount)
            {
                menu.AddButton("Close All To The Right", OnTabMenuCloseAllToTheRightClicked);
            }
            if (!_panel.IsFloating)
            {
                menu.AddSeparator();
                menu.AddButton("Undock", OnTabMenuUndockClicked);
            }
            else if (!tab.RootWindow?.IsMaximized ?? false)
            {
                menu.AddSeparator();
                menu.AddButton("Maximize", OnTabMenuMaximizeClicked);
            }
            else if (tab.RootWindow?.IsMaximized ?? false)
            {
                menu.AddSeparator();
                menu.AddButton("Restore", OnTabMenuRestoreClicked);
            }
            menu.Show(this, location);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        protected override void OnContextMenu(ContextMenu.ContextMenu menu)
        {
            base.OnContextMenu(menu);

            menu.AddSeparator();
            OnSelectActorContextMenu(menu);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public override void OnTimelineContextMenu(ContextMenu.ContextMenu menu, float time, Control controlUnderMouse)
        {
            if (((CameraCutTrack)Track).Camera)
            {
                menu.AddButton("Refresh thumbnails", () => UpdateThumbnails());
            }

            base.OnTimelineContextMenu(menu, time, controlUnderMouse);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        protected override void OnContextMenu(ContextMenu.ContextMenu menu)
        {
            base.OnContextMenu(menu);

            menu.AddSeparator();
            menu.AddButton("Copy Preview Value", () =>
            {
                var value      = Keyframes.Evaluate(Timeline.CurrentTime);
                Clipboard.Text = FlaxEngine.Json.JsonSerializer.Serialize(value);
            }).LinkTooltip("Copies the current track value to the clipboard").Enabled = Timeline.ShowPreviewValues;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds the object properties animation track options to menu.
        /// </summary>
        /// <param name="parentTrack">The parent track.</param>
        /// <param name="menu">The menu.</param>
        /// <param name="type">The object type.</param>
        /// <param name="memberCheck">The custom callback that can reject the members that should not be animated. Returns true if member is valid. Can be null to skip this feature.</param>
        /// <returns>The added options count.</returns>
        public static int AddProperties(Track parentTrack, ContextMenu.ContextMenu menu, Type type, Func <MemberInfo, bool> memberCheck = null)
        {
            int count = 0;

            menu.Tag = parentTrack;

            // TODO: implement editor-wide cache for animated properties per object type (add this in CodeEditingModule)
            var members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance);

            for (int i = 0; i < members.Length; i++)
            {
                var m = members[i];

                // Prevent from adding the same track twice
                if (parentTrack.SubTracks.Any(x => x is MemberTrack y && y.MemberName == m.Name))
                {
                    continue;
                }

                if (GetPropertyTrackType(m, out var t))
                {
                    continue;
                }

                if (memberCheck != null && !memberCheck(m))
                {
                    continue;
                }

                var attributes = m.GetCustomAttributes();

                // Check if has attribute to skip animating
                if (attributes.Any(x => x is NoAnimateAttribute))
                {
                    continue;
                }

                // Validate value type and pick the track archetype
                if (GetPropertyTrackArchetype(t, out var archetype, out var name))
                {
                    continue;
                }

                AddMemberTag tag;
                tag.Member    = m;
                tag.Archetype = archetype;
                var tooltip = Surface.SurfaceUtils.GetVisualScriptMemberInfoDescription(new ScriptMemberInfo(m));
                menu.AddButton(name + " " + m.Name, OnAddMemberTrack).LinkTooltip(tooltip).Tag = tag;
                count++;
            }

            return(count);
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        protected override void OnShowAddContextMenu(ContextMenu.ContextMenu menu)
        {
            base.OnShowAddContextMenu(menu);

            OnSelectActorContextMenu(menu);

            var actor = Actor;

            if (actor == null)
            {
                return;
            }
            var type = actor.GetType();

            menu.AddSeparator();

            // Properties and events
            if (AddProperties(this, menu, type) != 0)
            {
                menu.AddSeparator();
            }
            if (AddEvents(this, menu, type) != 0)
            {
                menu.AddSeparator();
            }

            // Child scripts
            var scripts = actor.Scripts;

            for (int i = 0; i < scripts.Length; i++)
            {
                var script = scripts[i];

                // Skip invalid or hidden scripts
                if (script == null || script.GetType().GetCustomAttributes(true).Any(x => x is HideInEditorAttribute))
                {
                    continue;
                }

                // Prevent from adding the same track twice
                if (SubTracks.Any(x => x is IObjectTrack y && y.Object == script))
                {
                    continue;
                }

                var name = CustomEditorsUtil.GetPropertyNameUI(script.GetType().Name);
                menu.AddButton(name, OnAddScriptTrack).Tag = script;
            }
        }
Ejemplo n.º 8
0
        private void OnSelectActorContextMenu(ContextMenu.ContextMenu menu)
        {
            var actor     = Actor;
            var selection = Editor.Instance.SceneEditing.Selection;

            foreach (var node in selection)
            {
                if (node is ActorNode actorNode && IsActorValid(actorNode.Actor) && actorNode.Actor != actor)
                {
                    var b = menu.AddButton("Select " + actorNode.Actor, OnClickedSelectActor);
                    b.Tag         = actorNode.Actor;
                    b.TooltipText = Utilities.Utils.GetTooltip(actorNode.Actor);
                }
            }
            menu.AddButton("Select...", OnClickedSelect).TooltipText = "Opens actor picker dialog to select the target actor for this track";
        }
Ejemplo n.º 9
0
        private void OnAddButtonClicked()
        {
            var menu = new ContextMenu.ContextMenu();

            var obj = Object;

            if (obj == null)
            {
                menu.AddButton("Missing object");
                return;
            }

            var type = obj.GetType();

            ObjectTrack.AddProperties(this, menu, type, m => m is FieldInfo);

            menu.Show(_addButton.Parent, _addButton.BottomLeft);
        }
Ejemplo n.º 10
0
        private void ShowContextMenu(DockWindow tab, ref Vector2 location)
        {
            var menu = new ContextMenu.ContextMenu();

            menu.Tag = tab;
            tab.OnShowContextMenu(menu);
            menu.AddButton("Close", OnTabMenuCloseClicked);
            menu.AddButton("Close All", OnTabMenuCloseAllClicked);
            menu.AddButton("Close All But This", OnTabMenuCloseAllButThisClicked);
            if (_panel.Tabs.IndexOf(tab) + 1 < _panel.TabsCount)
            {
                menu.AddButton("Close All To the Right", OnTabMenuCloseAllToTheRightClicked);
            }
            if (!_panel.IsFloating)
            {
                menu.AddSeparator();
                menu.AddButton("Float", OnTabMenuFloatClicked);
            }
            menu.Show(this, location);
        }
Ejemplo n.º 11
0
        private void OnAddButtonClicked()
        {
            var menu = new ContextMenu.ContextMenu();

            var obj = Object;

            if (obj == null)
            {
                menu.AddButton("Missing object");
                return;
            }

            var type = obj.GetType();

            if (ObjectTrack.AddProperties(this, menu, type) != 0)
            {
                menu.AddSeparator();
            }
            ObjectTrack.AddEvents(this, menu, type);

            menu.Show(_addButton.Parent, _addButton.BottomLeft);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds the object events track options to menu.
        /// </summary>
        /// <param name="parentTrack">The parent track.</param>
        /// <param name="menu">The menu.</param>
        /// <param name="type">The object type.</param>
        /// <param name="memberCheck">The custom callback that can reject the members that should not be animated. Returns true if member is valid. Can be null to skip this feature.</param>
        /// <returns>The added options count.</returns>
        public static int AddEvents(Track parentTrack, ContextMenu.ContextMenu menu, Type type, Func <MemberInfo, bool> memberCheck = null)
        {
            int count = 0;

            menu.Tag = parentTrack;

            // TODO: implement editor-wide cache for animated properties per object type (add this in CodeEditingModule)
            var members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance);

            var sb = new StringBuilder();

            for (int i = 0; i < members.Length; i++)
            {
                var m = members[i] as MethodInfo;
                if (m == null)
                {
                    continue;
                }
                if (memberCheck != null && !memberCheck(m))
                {
                    continue;
                }

                // Skip properties getters/setters and events add/remove
                var mName = m.Name;
                if (mName.StartsWith("get_", StringComparison.Ordinal) ||
                    mName.StartsWith("set_", StringComparison.Ordinal) ||
                    mName.StartsWith("add_", StringComparison.Ordinal) ||
                    mName.StartsWith("remove_", StringComparison.Ordinal))
                {
                    continue;
                }

                // Allow to invoke only void functions with basic parameter types
                var parameters = m.GetParameters();
                if (m.ReturnType != typeof(void) ||
                    parameters.Length > 8 ||
                    m.IsGenericMethod ||
                    parameters.Any(IsEventParamInvalid))
                {
                    continue;
                }

                var attributes = m.GetCustomAttributes();

                // Check if has attribute to skip animating
                if (attributes.Any(x => x is NoAnimateAttribute))
                {
                    continue;
                }

                // Prevent from adding the same track twice
                if (parentTrack.SubTracks.Any(x => x is MemberTrack y && y.MemberName == m.Name))
                {
                    continue;
                }

                // Build function name for UI
                sb.Clear();
                sb.Append(mName);
                sb.Append('(');
                for (int j = 0; j < parameters.Length; j++)
                {
                    if (j != 0)
                    {
                        sb.Append(", ");
                    }
                    var p = parameters[j];
                    if (!CustomEditorsUtil.InBuildTypeNames.TryGetValue(p.ParameterType, out var pName))
                    {
                        pName = p.ParameterType.Name;
                    }
                    sb.Append(pName);
                    sb.Append(' ');
                    sb.Append(p.Name);
                }
                sb.Append(')');

                AddMemberTag tag;
                tag.Member    = m;
                tag.Archetype = EventTrack.GetArchetype();
                var tooltip = Surface.SurfaceUtils.GetVisualScriptMemberInfoDescription(new ScriptMemberInfo(m));
                menu.AddButton(sb.ToString(), OnAddMemberTrack).LinkTooltip(tooltip).Tag = tag;
                count++;
            }

            return(count);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Called when showing the context menu for add button (for sub-tracks adding).
 /// </summary>
 /// <param name="menu">The menu.</param>
 protected virtual void OnShowAddContextMenu(ContextMenu.ContextMenu menu)
 {
 }
Ejemplo n.º 14
0
        public static ContextMenu.ContextMenu GetContextMenu()
        {
            var c = new ContextMenu.ContextMenu("ContextMenu", "olContextMenu");

            return(c);
        }