123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- // Amplify Shader Editor - Visual Shader Editing Tool
- // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
- using UnityEditor;
- using UnityEngine;
- using System.Collections.Generic;
- namespace AmplifyShaderEditor
- {
- class NodeDescriptionInfo
- {
- public bool FoldoutValue;
- public string Category;
- public string[,] Contents;
- }
- public sealed class PortLegendInfo : EditorWindow
- {
- private const string NoASEWindowWarning = "Please Open the ASE to get access to shortcut info";
- private const float PixelSeparator = 5;
- private const string EditorShortcutsTitle = "Editor Shortcuts";
- private const string MenuShortcutsTitle = "Menu Shortcuts";
- private const string NodesShortcutsTitle = "Nodes Shortcuts";
- private const string PortShortcutsTitle = "Port Shortcuts";
- private const string PortLegendTitle = "Port Legend";
- private const string NodesDescTitle = "Node Info";
- private const string CompatibleAssetsTitle = "Compatible Assets";
- private const string KeyboardUsageTemplate = "[{0}] - {1}";
- private const string m_lockedStr = "Locked Port";
- private const float WindowSizeX = 350;
- private const float WindowSizeY = 300;
- private const float WindowPosX = 5;
- private const float WindowPosY = 5;
- private int TitleLabelWidth = 150;
- private Rect m_availableArea;
- private bool m_portAreaFoldout = true;
- private bool m_editorShortcutAreaFoldout = true;
- private bool m_menuShortcutAreaFoldout = true;
- private bool m_nodesShortcutAreaFoldout = true;
- private bool m_nodesDescriptionAreaFoldout = true;
- private bool m_compatibleAssetsFoldout = true;
- private Vector2 m_currentScrollPos;
- private GUIStyle m_portStyle;
- private GUIStyle m_labelStyleBold;
- private GUIStyle m_labelStyle;
- private GUIStyle m_nodeInfoLabelStyleBold;
- private GUIStyle m_nodeInfoLabelStyle;
- private GUIStyle m_nodeInfoFoldoutStyle;
- private GUIContent m_content = new GUIContent( "Helper", "Shows helper info for ASE users" );
- private bool m_init = true;
- private List<ShortcutItem> m_editorShortcuts = null;
- private List<ShortcutItem> m_nodesShortcuts = null;
- private List<NodeDescriptionInfo> m_nodeDescriptionsInfo = null;
- private List<string[]> m_compatibleAssetsInfo = null;
- public static PortLegendInfo OpenWindow()
- {
- PortLegendInfo currentWindow = ( PortLegendInfo ) PortLegendInfo.GetWindow( typeof( PortLegendInfo ), false );
- currentWindow.minSize = new Vector2( WindowSizeX, WindowSizeY );
- currentWindow.maxSize = new Vector2( WindowSizeX * 2, 2 * WindowSizeY ); ;
- currentWindow.wantsMouseMove = true;
- return currentWindow;
- }
- public void Init()
- {
- m_init = false;
- wantsMouseMove = false;
- titleContent = m_content;
- m_portStyle = new GUIStyle( UIUtils.GetCustomStyle( CustomStyle.PortEmptyIcon ) );
- m_portStyle.alignment = TextAnchor.MiddleLeft;
- m_portStyle.imagePosition = ImagePosition.ImageOnly;
- m_portStyle.margin = new RectOffset( 5, 0, 5, 0 );
- m_labelStyleBold = new GUIStyle( UIUtils.InputPortLabel );
- m_labelStyleBold.fontStyle = FontStyle.Bold;
- m_labelStyleBold.fontSize = ( int ) ( Constants.TextFieldFontSize );
- m_labelStyle = new GUIStyle( UIUtils.InputPortLabel );
- m_labelStyle.clipping = TextClipping.Overflow;
- m_labelStyle.imagePosition = ImagePosition.TextOnly;
- m_labelStyle.contentOffset = new Vector2( -10, 0 );
- m_labelStyle.fontSize = ( int ) ( Constants.TextFieldFontSize );
- m_nodeInfoLabelStyleBold = new GUIStyle( UIUtils.InputPortLabel );
- m_nodeInfoLabelStyleBold.fontStyle = FontStyle.Bold;
- m_nodeInfoLabelStyleBold.fontSize = ( int ) ( Constants.TextFieldFontSize );
- m_nodeInfoLabelStyle = new GUIStyle( UIUtils.InputPortLabel );
- m_nodeInfoLabelStyle.clipping = TextClipping.Clip;
- m_nodeInfoLabelStyle.imagePosition = ImagePosition.TextOnly;
- m_nodeInfoLabelStyle.fontSize = ( int ) ( Constants.TextFieldFontSize );
-
- m_nodeInfoFoldoutStyle = new GUIStyle( ( GUIStyle ) "foldout" );
- m_nodeInfoFoldoutStyle.fontStyle = FontStyle.Bold;
- if ( !EditorGUIUtility.isProSkin )
- {
- m_labelStyleBold.normal.textColor = m_labelStyle.normal.textColor = Color.black;
- m_nodeInfoLabelStyleBold.normal.textColor = m_labelStyle.normal.textColor = Color.black;
- m_nodeInfoLabelStyle.normal.textColor = m_labelStyle.normal.textColor = Color.black;
- }
- m_availableArea = new Rect( WindowPosX, WindowPosY, WindowSizeX - 2 * WindowPosX, WindowSizeY - 2 * WindowPosY );
- }
- void DrawPort( WirePortDataType type )
- {
- EditorGUILayout.BeginHorizontal();
- {
- GUI.color = UIUtils.GetColorForDataType( type, false );
- GUILayout.Box( string.Empty, m_portStyle, GUILayout.Width( UIUtils.PortsSize.x ), GUILayout.Height( UIUtils.PortsSize.y ) );
- GUI.color = Color.white;
- EditorGUILayout.LabelField( UIUtils.GetNameForDataType( type ), m_labelStyle );
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.Separator();
- }
- void OnGUI()
- {
- if ( !UIUtils.Initialized || UIUtils.CurrentWindow == null )
- {
- EditorGUILayout.LabelField( NoASEWindowWarning );
- return;
- }
- if ( m_init )
- {
- Init();
- }
- TitleLabelWidth = (int)(this.position.width * 0.42f);
- KeyCode key = Event.current.keyCode;
- if ( key == ShortcutsManager.ScrollUpKey )
- {
- m_currentScrollPos.y -= 10;
- if ( m_currentScrollPos.y < 0 )
- {
- m_currentScrollPos.y = 0;
- }
- Event.current.Use();
- }
- if ( key == ShortcutsManager.ScrollDownKey )
- {
- m_currentScrollPos.y += 10;
- Event.current.Use();
- }
- if ( Event.current.type == EventType.MouseDrag && Event.current.button > 0 )
- {
- m_currentScrollPos.x += Constants.MenuDragSpeed * Event.current.delta.x;
- if ( m_currentScrollPos.x < 0 )
- {
- m_currentScrollPos.x = 0;
- }
- m_currentScrollPos.y += Constants.MenuDragSpeed * Event.current.delta.y;
- if ( m_currentScrollPos.y < 0 )
- {
- m_currentScrollPos.y = 0;
- }
- }
- m_availableArea = new Rect( WindowPosX, WindowPosY, position.width - 2 * WindowPosX, position.height - 2 * WindowPosY );
- GUILayout.BeginArea( m_availableArea );
- {
- if ( GUILayout.Button( "Wiki Page" ) )
- {
- Application.OpenURL( Constants.HelpURL );
- }
- m_currentScrollPos = GUILayout.BeginScrollView( m_currentScrollPos );
- {
- EditorGUILayout.BeginVertical();
- {
- NodeUtils.DrawPropertyGroup( ref m_portAreaFoldout, PortLegendTitle, DrawPortInfo );
- float currLabelWidth = EditorGUIUtility.labelWidth;
- EditorGUIUtility.labelWidth = 1;
- NodeUtils.DrawPropertyGroup( ref m_editorShortcutAreaFoldout, EditorShortcutsTitle, DrawEditorShortcuts );
- NodeUtils.DrawPropertyGroup( ref m_menuShortcutAreaFoldout, MenuShortcutsTitle, DrawMenuShortcuts );
- NodeUtils.DrawPropertyGroup( ref m_nodesShortcutAreaFoldout, NodesShortcutsTitle, DrawNodesShortcuts );
- NodeUtils.DrawPropertyGroup( ref m_compatibleAssetsFoldout, CompatibleAssetsTitle, DrawCompatibleAssets );
- NodeUtils.DrawPropertyGroup( ref m_nodesDescriptionAreaFoldout, NodesDescTitle, DrawNodeDescriptions );
- EditorGUIUtility.labelWidth = currLabelWidth;
- }
- EditorGUILayout.EndVertical();
- }
- GUILayout.EndScrollView();
- }
- GUILayout.EndArea();
- }
- void DrawPortInfo()
- {
- Color originalColor = GUI.color;
- DrawPort( WirePortDataType.OBJECT );
- DrawPort( WirePortDataType.INT );
- DrawPort( WirePortDataType.FLOAT );
- DrawPort( WirePortDataType.FLOAT2 );
- DrawPort( WirePortDataType.FLOAT3 );
- DrawPort( WirePortDataType.FLOAT4 );
- DrawPort( WirePortDataType.COLOR );
- DrawPort( WirePortDataType.SAMPLER2D );
- DrawPort( WirePortDataType.FLOAT3x3 );
- DrawPort( WirePortDataType.FLOAT4x4 );
- EditorGUILayout.BeginHorizontal();
- {
- GUI.color = Constants.LockedPortColor;
- GUILayout.Box( string.Empty, m_portStyle, GUILayout.Width( UIUtils.PortsSize.x ), GUILayout.Height( UIUtils.PortsSize.y ) );
- GUI.color = Color.white;
- EditorGUILayout.LabelField( m_lockedStr, m_labelStyle );
- }
- EditorGUILayout.EndHorizontal();
- GUI.color = originalColor;
- }
- public void DrawEditorShortcuts()
- {
- AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
- if ( window != null )
- {
- if ( m_editorShortcuts == null )
- {
- m_editorShortcuts = window.ShortcutManagerInstance.AvailableEditorShortcutsList;
- }
- EditorGUI.indentLevel--;
- int count = m_editorShortcuts.Count;
- for ( int i = 0; i < count; i++ )
- {
- DrawItem( m_editorShortcuts[ i ].Name, m_editorShortcuts[ i ].Description );
- }
- DrawItem( "Q", "Alternative Pan modifier" );
- DrawItem( "Ctrl + F", "Find nodes" );
- DrawItem( "LMB Drag", "Box selection" );
- DrawItem( "MMB/RMB Drag", "Camera pan" );
- DrawItem( "Alt + MMB/RMB Drag", "Zoom graph" );
- DrawItem( "Shift/Ctrl + Node Select", "Add/Remove from selection" );
- DrawItem( "Shift + Node Drag", "Node move with offset" );
- DrawItem( "Ctrl + Node Drag", "Node move with snap" );
- DrawItem( "MMB/RMB + Drag Panel", "Scroll panel" );
- DrawItem( "Alt + LMB Drag", "Additive box selection" );
- DrawItem( "Alt + Shift + Drag", "Subtractive box selection" );
- DrawItem( "Alt + Node Drag", "Auto-(Dis)Connect node on existing wire connection" );
- EditorGUI.indentLevel++;
- }
- else
- {
- EditorGUILayout.LabelField( NoASEWindowWarning );
- }
- }
- public void DrawMenuShortcuts()
- {
- AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
- if ( window != null )
- {
- EditorGUI.indentLevel--;
- DrawItem( ShortcutsManager.ScrollUpKey.ToString(), "Scroll Up Menu" );
- DrawItem( ShortcutsManager.ScrollDownKey.ToString(), "Scroll Down Menu" );
- DrawItem( "RMB Drag", "Scroll Menu" );
- EditorGUI.indentLevel++;
- }
- else
- {
- EditorGUILayout.LabelField( NoASEWindowWarning );
- }
- }
- void DrawItem( string name, string description )
- {
- GUILayout.BeginHorizontal();
- GUILayout.Label( name, m_labelStyleBold , GUILayout.Width( TitleLabelWidth ) );
- GUILayout.Label( description, m_labelStyle );
- GUILayout.EndHorizontal();
- GUILayout.Space( PixelSeparator );
- }
- public void DrawNodesShortcuts()
- {
- AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
- if ( window != null )
- {
- if ( m_nodesShortcuts == null || m_nodesShortcuts.Count == 0 )
- {
- m_nodesShortcuts = window.ShortcutManagerInstance.AvailableNodesShortcutsList;
- }
- EditorGUI.indentLevel--;
- int count = m_nodesShortcuts.Count;
- for ( int i = 0; i < count; i++ )
- {
- DrawItem( m_nodesShortcuts[ i ].Name, m_nodesShortcuts[ i ].Description );
- }
- EditorGUI.indentLevel++;
- }
- else
- {
- EditorGUILayout.LabelField( NoASEWindowWarning );
- }
- }
- string CreateCompatibilityString( string source )
- {
- string[] split = source.Split( '.' );
- if ( split != null && split.Length > 1 )
- {
- return split[ 1 ];
- }
- else
- {
- return source;
- }
- }
- public void DrawCompatibleAssets()
- {
- AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
- if ( window != null )
- {
- if ( m_compatibleAssetsInfo == null )
- {
- m_compatibleAssetsInfo = new List<string[]>();
- List<ContextMenuItem> items = window.ContextMenuInstance.MenuItems;
- int count = items.Count;
- for ( int i = 0; i < count; i++ )
- {
- if ( items[ i ].NodeAttributes != null && items[ i ].NodeAttributes.CastType != null )
- {
- string types = string.Empty;
- if ( items[ i ].NodeAttributes.CastType.Length > 1 )
- {
- for ( int j = 0; j < items[ i ].NodeAttributes.CastType.Length; j++ )
- {
- types += CreateCompatibilityString( items[ i ].NodeAttributes.CastType[ j ].ToString() );
- if ( j < items[ i ].NodeAttributes.CastType.Length - 1 )
- {
- types += ", ";
- }
- }
- }
- else
- {
- types = CreateCompatibilityString( items[ i ].NodeAttributes.CastType[ 0 ].ToString() );
- }
- m_compatibleAssetsInfo.Add( new string[] { items[ i ].NodeAttributes.Name + ": ", types } );
- }
- }
- }
- EditorGUI.indentLevel--;
- int nodeCount = m_compatibleAssetsInfo.Count;
- for ( int j = 0; j < nodeCount; j++ )
- {
- DrawItem( m_compatibleAssetsInfo[ j ][ 0 ], m_compatibleAssetsInfo[ j ][ 1 ] );
- }
- EditorGUI.indentLevel++;
- }
- else
- {
- EditorGUILayout.LabelField( NoASEWindowWarning );
- }
- }
- public void DrawNodeDescriptions()
- {
- AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
- if ( window != null )
- {
- if ( m_nodeDescriptionsInfo == null )
- {
- //fetch node info
- m_nodeDescriptionsInfo = new List<NodeDescriptionInfo>();
- Dictionary<string, PaletteFilterData> nodeData = window.CurrentPaletteWindow.BuildFullList();
- var enumerator = nodeData.GetEnumerator();
- while ( enumerator.MoveNext() )
- {
- List<ContextMenuItem> nodes = enumerator.Current.Value.Contents;
- int count = nodes.Count;
- NodeDescriptionInfo currInfo = new NodeDescriptionInfo();
- currInfo.Contents = new string[ count, 2 ];
- currInfo.Category = enumerator.Current.Key;
- for ( int i = 0; i < count; i++ )
- {
- currInfo.Contents[ i, 0 ] = nodes[ i ].Name + ':';
- currInfo.Contents[ i, 1 ] = nodes[ i ].Description;
- }
- m_nodeDescriptionsInfo.Add( currInfo );
- }
- }
- //draw
- {
- GUILayout.Space( 5 );
- int count = m_nodeDescriptionsInfo.Count;
- EditorGUI.indentLevel--;
- for ( int i = 0; i < count; i++ )
- {
- m_nodeDescriptionsInfo[ i ].FoldoutValue = EditorGUILayout.Foldout( m_nodeDescriptionsInfo[ i ].FoldoutValue, m_nodeDescriptionsInfo[ i ].Category, m_nodeInfoFoldoutStyle );
- if ( m_nodeDescriptionsInfo[ i ].FoldoutValue )
- {
- EditorGUI.indentLevel++;
- int nodeCount = m_nodeDescriptionsInfo[ i ].Contents.GetLength( 0 );
- for ( int j = 0; j < nodeCount; j++ )
- {
- GUILayout.Label( m_nodeDescriptionsInfo[ i ].Contents[ j, 0 ], m_nodeInfoLabelStyleBold );
- GUILayout.Label( m_nodeDescriptionsInfo[ i ].Contents[ j, 1 ], m_nodeInfoLabelStyle );
- GUILayout.Space( PixelSeparator );
- }
- EditorGUI.indentLevel--;
- }
- GUILayout.Space( PixelSeparator );
- }
- EditorGUI.indentLevel++;
- }
- }
- else
- {
- EditorGUILayout.LabelField( NoASEWindowWarning );
- }
- }
- private void OnDestroy()
- {
- m_nodesShortcuts = null;
- m_editorShortcuts = null;
- m_portStyle = null;
- m_labelStyle = null;
- m_labelStyleBold = null;
- m_nodeInfoLabelStyle = null;
- m_nodeInfoLabelStyleBold = null;
- m_nodeInfoFoldoutStyle = null;
- m_init = false;
- if ( m_nodeDescriptionsInfo != null )
- {
- m_nodeDescriptionsInfo.Clear();
- m_nodeDescriptionsInfo = null;
- }
- if( m_compatibleAssetsInfo != null )
- {
- m_compatibleAssetsInfo.Clear();
- m_compatibleAssetsInfo = null;
- }
- }
- }
- }
|