Skip to content

Commit

Permalink
feat: Move context menu options to the toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarianZ committed May 21, 2024
1 parent 3eb7c87 commit 267ea65
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Editor/Scripts/Element.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions Editor/Scripts/Element/ToolbarDropdownToggle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace GBG.PlayableGraphMonitor.Editor
{
public class ToolbarDropdownToggle : VisualElement, INotifyValueChanged<bool>
{
private readonly ToolbarToggle _toggle;
private readonly ToolbarMenu _menu;

public string text
{
get => _toggle.text;
set => _toggle.text = value;
}
public string label
{
get => _toggle.label;
set => _toggle.label = value;
}
public Label labelElement => _toggle.labelElement;
public new string tooltip
{
get => _toggle.tooltip;
set => _toggle.tooltip = value;
}
public bool value
{
get => _toggle.value;
set => _toggle.value = value;
}
public string menuTooltip
{
get => _menu.tooltip;
set => _menu.tooltip = value;
}
public DropdownMenu menu => _menu.menu;
public ToolbarMenu.Variant menuVariant
{
get => _menu.variant;
set => _menu.variant = value;
}


public ToolbarDropdownToggle()
{
style.flexDirection = FlexDirection.Row;
style.flexShrink = 0;

_toggle = new ToolbarToggle();
_toggle.style.borderRightWidth = 0;
_toggle.style.minWidth = 0;
Add(_toggle);

_menu = new ToolbarMenu();
_menu.style.borderLeftWidth = 0;
Add(_menu);
}

public void SetValueWithoutNotify(bool newValue)
{
_toggle.SetValueWithoutNotify(newValue);
}
}
}
11 changes: 11 additions & 0 deletions Editor/Scripts/Element/ToolbarDropdownToggle.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions Editor/Scripts/Window/PlayableGraphMonitorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,13 @@ private void OnDestroyingGraph(PlayableGraph graph)

void IHasCustomMenu.AddItemsToMenu(GenericMenu menu)
{
#if UNITY_2021_1_OR_NEWER
menu.AddItem(new GUIContent("Show clip progress bar title (will degrade performance)"),
_viewUpdateContext.ShowClipProgressBarTitle, OnToggleShowClipProgressBarTitle);
menu.AddSeparator("");
#endif

// Source Code
menu.AddItem(new GUIContent("Source Code"), false, () =>
{
Application.OpenURL("https://github.com/SolarianZ/UnityPlayableGraphMonitorTool");
});
}

private void OnToggleShowClipProgressBarTitle()
{
_viewUpdateContext.ShowClipProgressBarTitle = !_viewUpdateContext.ShowClipProgressBarTitle;
}

#endregion
}
}
33 changes: 27 additions & 6 deletions Editor/Scripts/Window/PlayableGraphMonitorWindow_Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,29 @@ private void CreateToolbar()
_toolbar.Add(_inspectorToggle);

// Clip ProgressBar toggle
var clipProgressBarToggle = new ToolbarToggle()
var clipProgressDropdownToggle = new ToolbarDropdownToggle()
{
text = "Clip Progress",
tooltip = "Disabling this option can significantly improve performance.",
value = _viewUpdateContext.ShowClipProgressBar,
};
clipProgressBarToggle.RegisterValueChangedCallback(ToggleDisplayClipProgressBar);
clipProgressBarToggle.Q<TextElement>(className: "unity-text-element").style.color = NormalTextColor;
_toolbar.Add(clipProgressBarToggle);
clipProgressDropdownToggle.RegisterValueChangedCallback(ToggleDisplayClipProgressBar);
clipProgressDropdownToggle.Q<TextElement>(className: "unity-text-element").style.color = NormalTextColor;
clipProgressDropdownToggle.menu.AppendAction("Progress Text (Low-Performance)",
ToggleDisplayClipProgressBarText,
(_) =>
{
var @checked = _viewUpdateContext.ShowClipProgressBarTitle
? DropdownMenuAction.Status.Checked
: DropdownMenuAction.Status.Normal;
var disabled = _viewUpdateContext.ShowClipProgressBar
? DropdownMenuAction.Status.Normal
: DropdownMenuAction.Status.Disabled;
return @checked | disabled;
});
_toolbar.Add(clipProgressDropdownToggle);

// Update edge toggle
var updateEdgeToggle = new ToolbarToggle()
{
text = "Always Update Edges",
Expand Down Expand Up @@ -157,6 +170,7 @@ private void CreateToolbar()
var frameAllButton = new ToolbarButton(OnFrameAllButtonClicked)
{
text = "Frame All",
style = { flexShrink = 0 },
};
frameAllButton.Q<TextElement>(className: "unity-text-element").style.color = NormalTextColor;
_toolbar.Add(frameAllButton);
Expand All @@ -165,15 +179,17 @@ private void CreateToolbar()
_toolbar.Add(new ToolbarSpacer());
_selectOutputNodeMenu = new ToolbarMenu
{
text = "Select Output Node"
text = "Select Output Node",
style = { flexShrink = 0 },
};
_selectOutputNodeMenu.RegisterCallback<PointerEnterEvent>(OnHoverSelectOutputNodeMenu);
_toolbar.Add(_selectOutputNodeMenu);

// Select root node
_selectRootNodeMenu = new ToolbarMenu
{
text = "Select Root Node"
text = "Select Root Node",
style = { flexShrink = 0 },
};
_selectRootNodeMenu.RegisterCallback<PointerEnterEvent>(OnHoverSelectRootNodeMenu);
_toolbar.Add(_selectRootNodeMenu);
Expand Down Expand Up @@ -221,6 +237,11 @@ private void ToggleDisplayClipProgressBar(ChangeEvent<bool> evt)
_viewUpdateContext.ShowClipProgressBar = evt.newValue;
}

private void ToggleDisplayClipProgressBarText(DropdownMenuAction _)
{
_viewUpdateContext.ShowClipProgressBarTitle = !_viewUpdateContext.ShowClipProgressBarTitle;
}

private void ToggleKeepUpdatingEdges(ChangeEvent<bool> evt)
{
_viewUpdateContext.KeepUpdatingEdges = evt.newValue;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.greenbamboogames.playablegraphmonitor",
"version": "2.5.8",
"version": "2.5.9",
"displayName": "PlayableGraph Monitor!",
"description": "PlayableGraph monitor.",
"unity": "2019.4",
Expand Down

0 comments on commit 267ea65

Please sign in to comment.