From ebb36fbd285dd7391407f58c3f32a9fd93f1e284 Mon Sep 17 00:00:00 2001 From: Emre Dogan <48212096+EmreDogann@users.noreply.github.com> Date: Sat, 7 Oct 2023 04:44:35 +0100 Subject: [PATCH] Changed group resizing, no longer snaps to cursor position. Changed rename textfield styling to account for custom styling on NodeEditor.cs classes. --- Scripts/Editor/NodeEditor.cs | 8 + Scripts/Editor/NodeEditorAction.cs | 4 +- Scripts/Editor/NodeGroupEditor.cs | 46 ++++-- Scripts/Editor/RenameTextField.cs | 7 +- Scripts/Editor/Resources/xnode_corner.png | Bin 0 -> 16041 bytes .../Editor/Resources/xnode_corner.png.meta | 140 ++++++++++++++++++ 6 files changed, 188 insertions(+), 17 deletions(-) create mode 100644 Scripts/Editor/Resources/xnode_corner.png create mode 100644 Scripts/Editor/Resources/xnode_corner.png.meta diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index b728aff..6c73af4 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -151,6 +151,11 @@ namespace XNodeEditor return NodeEditorResources.styles.nodeBody; } + public virtual GUIStyle GetHeaderStyle() + { + return NodeEditorResources.styles.nodeHeader; + } + public virtual GUIStyle GetBodyHighlightStyle() { return NodeEditorResources.styles.nodeHighlight; @@ -216,6 +221,9 @@ namespace XNodeEditor /// Called after this node's name has changed. public virtual void OnRename() {} + /// Called when exiting rename mode for this node. + public virtual void OnRenameDeactive() {} + [AttributeUsage(AttributeTargets.Class)] public class CustomNodeEditorAttribute : Attribute, INodeEditorAttrib diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index e7b1bc9..4b9ed62 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -429,7 +429,7 @@ namespace XNodeEditor !(e.control || e.shift)) { selectedReroutes.Clear(); - SelectNode(hoveredNode, false); + // SelectNode(hoveredNode, false); // Double click to rename node if (isDoubleClick) @@ -718,7 +718,7 @@ namespace XNodeEditor public void RenameSelectedNodeTextField() { - if (Selection.objects.Length == 1 && Selection.activeObject is Node) + if (Selection.activeObject is Node) { currentActivity = NodeActivity.Renaming; RenameTextField.Show(Selection.activeObject); diff --git a/Scripts/Editor/NodeGroupEditor.cs b/Scripts/Editor/NodeGroupEditor.cs index 669d179..f5a00c6 100644 --- a/Scripts/Editor/NodeGroupEditor.cs +++ b/Scripts/Editor/NodeGroupEditor.cs @@ -11,18 +11,29 @@ namespace XNodeEditor.NodeGroups { private NodeGroup group => _group != null ? _group : _group = target as NodeGroup; private NodeGroup _group; + public static Texture2D corner => + _corner != null ? _corner : _corner = Resources.Load("xnode_corner"); + private static Texture2D _corner; private bool _isDragging; private Vector2 _size; private float _currentHeight; + private Vector2 _draggingOffset; + + private const int mouseRectPadding = 4; + private const int mouseRectMargin = 30; + + private GUIStyle headerStyle; public override void OnCreate() { _currentHeight = group.height; + headerStyle = new GUIStyle(NodeEditorResources.styles.nodeHeader); + headerStyle.fontSize = 18; } public override void OnHeaderGUI() { - GUILayout.Label(target.name, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); + GUILayout.Label(target.name, headerStyle, GUILayout.Height(30)); } public override void OnBodyGUI() @@ -33,8 +44,8 @@ namespace XNodeEditor.NodeGroups case EventType.MouseDrag: if (_isDragging) { - group.width = Mathf.Max(200, (int)e.mousePosition.x + 16); - group.height = Mathf.Max(100, (int)e.mousePosition.y - 34); + group.width = Mathf.Max(200, (int)e.mousePosition.x + (int)_draggingOffset.x + 16); + group.height = Mathf.Max(100, (int)e.mousePosition.y + (int)_draggingOffset.y - 34); _currentHeight = group.height; NodeEditorWindow.current.Repaint(); } @@ -50,10 +61,13 @@ namespace XNodeEditor.NodeGroups if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size)) { // Mouse position checking is in node local space - Rect lowerRight = new Rect(_size.x - 34, _size.y - 34, 30, 30); + Rect lowerRight = new Rect(_size.x - (mouseRectMargin + mouseRectPadding), + _size.y - (mouseRectMargin + mouseRectPadding), mouseRectMargin, mouseRectMargin); if (lowerRight.Contains(e.mousePosition)) { _isDragging = true; + _draggingOffset = _size - e.mousePosition - new Vector2(GetBodyStyle().padding.right, + GetBodyStyle().padding.bottom); } } @@ -129,28 +143,29 @@ namespace XNodeEditor.NodeGroups // Add scale cursors if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size)) { - Rect lowerRight = new Rect(target.position, new Vector2(30, 30)); - lowerRight.y += _size.y - 34; - lowerRight.x += _size.x - 34; + Rect lowerRight = new Rect(target.position, new Vector2(mouseRectMargin, mouseRectMargin)); + lowerRight.y += _size.y - (mouseRectMargin + mouseRectPadding); + lowerRight.x += _size.x - (mouseRectMargin + mouseRectPadding); lowerRight = NodeEditorWindow.current.GridToWindowRect(lowerRight); - NodeEditorWindow.current.onLateGUI += () => AddMouseRect(lowerRight); + NodeEditorWindow.current.onLateGUI += () => AddMouseRect(lowerRight, MouseCursor.ResizeUpLeft); } break; } GUILayout.Space(_currentHeight); + GUI.DrawTexture(new Rect(group.width - 34, group.height + 16, 24, 24), corner); } public override void OnRenameActive() { _currentHeight += 30 - NodeEditorResources.styles.nodeHeaderRename.fixedHeight - - NodeEditorResources.styles.nodeHeaderRename.margin.top + - NodeEditorResources.styles.nodeHeaderRename.margin.bottom / 2; + NodeEditorResources.styles.nodeHeaderRename.margin.top + + NodeEditorResources.styles.nodeHeaderRename.margin.bottom / 2; } - public override void OnRename() + public override void OnRenameDeactive() { _currentHeight = group.height; } @@ -165,9 +180,14 @@ namespace XNodeEditor.NodeGroups return group.color; } - public static void AddMouseRect(Rect rect) + public override GUIStyle GetHeaderStyle() { - EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeUpLeft); + return headerStyle; + } + + public static void AddMouseRect(Rect rect, MouseCursor mouseCursor) + { + EditorGUIUtility.AddCursorRect(rect, mouseCursor); } public override void AddContextMenuItems(GenericMenu menu) diff --git a/Scripts/Editor/RenameTextField.cs b/Scripts/Editor/RenameTextField.cs index 11e2217..46ee6a3 100644 --- a/Scripts/Editor/RenameTextField.cs +++ b/Scripts/Editor/RenameTextField.cs @@ -35,7 +35,10 @@ namespace XNodeEditor public void DrawRenameTextField() { GUI.SetNextControlName(inputControlName); - input = GUILayout.TextField(input, NodeEditorResources.styles.nodeHeaderRename); + GUIStyle stylesNodeHeaderRename = NodeEditorResources.styles.nodeHeaderRename; + stylesNodeHeaderRename.fontSize = + NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).GetHeaderStyle().fontSize; + input = GUILayout.TextField(input, stylesNodeHeaderRename); EditorGUI.FocusTextInControl(inputControlName); if (firstFrame) @@ -80,7 +83,6 @@ namespace XNodeEditor Undo.RecordObject(target, $"Renamed Node: [{target.name}] -> [{input}]"); target.name = input; - NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).OnRename(); if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) { AssetDatabase.SetMainObject((target as Node).graph, AssetDatabase.GetAssetPath(target)); @@ -97,6 +99,7 @@ namespace XNodeEditor current = null; EditorGUIUtility.editingTextField = false; + NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).OnRenameDeactive(); NodeEditorWindow.current.Repaint(); // If another action has not taken precedence, then just return to an idle state. diff --git a/Scripts/Editor/Resources/xnode_corner.png b/Scripts/Editor/Resources/xnode_corner.png new file mode 100644 index 0000000000000000000000000000000000000000..12d25faf2759fea34844b56ce2ed47c84409f84f GIT binary patch literal 16041 zcmeI3eN+=y7QhDsR`G*UtD>IO5JjvSCf|@4f|w{ojUeCxD+t460wYN#Ccy-%Xvm7C zUC&lm&`PbfipQeXs@1lOV(QA)TI*NE#M8HWWdSVcKL(8u;bXpFzRk`-<)0D)2MdlALWrkRc=J zPY|-@?Far)))(g{xJoxfUyBAdLiqIIrUQ`R{!H(+@XKPx5$DQ!~MHQLp%y8YB!(j^R&rzYxW7Bklq2AU8*isCnx6 zKMkndF_emE8j~9_Z%n4(8vYUtX!ExUitn6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+LRC4N_A^ z%BrLEgi5GHd+YAi3jBpg_5FiTX(&542_wzmD2WR65HKXb1%19LK%oIik9jvZh}xqM z9-l=Q3}cCRe5^uW=cbEpMVbg48(?B(B>bG2EChaOwM>MEAz=}SE6<(g{;CYcy z$)r-TREfgfuth5AB#c=a5*!say5xyLB(Dvu=+!X0FT(&uhoLW<0-o%=Wy04Bo*Tg< zE86wU+M|MW72032;h)hj=@s(D27!Pui!3f?K9H8h1p#3eSzOF~AT5gv0>Uh^xS07s zS{4@sgjr;9G4p}6EG`HLv&iCN<^yS2To4duk;TQ#2hy^*ARx>li;I~Lq-AkIK$t}q z7c(D7%i@B7FpDfMW}203j)F{vbdP}Kw1_T1cX^+aWV6Ov@9+N z2(!rIV&(&BSzHhhW|76k%m>o4xF8_RB8!We52R&rK|q*A78f%gNXz1afG~?JE@nQE zmc<1DVHR0j%zPj%iwgq6EV8(m`9NA07X*Y^WW*Kfe+!f_gI7Nt;2qC@HJ8)xTyyc{ zG#!GJMIp#)H-faZgWrE3NQnSJ?&O14OE)9PXlg@V(;P7NyjGK#;k>%@>o13&;J!HX z!aR;^U2FR`QgXF&*C$0&i}IZt+dhp9QB1X%b#LdoK8yb;w>i?dEJEq198fa^8TgfA znC-#dwh2P(=4UC9x58?!&8&PHeDG*|>i7FxJZi|Gqfy*PW$&ISc1_*H5oLa{>B5W!@z7 zU;Es{{e4h$&TlerC(XovJA?Z2`JlZ{Phnn8e$WwRO5qO4j*QZS^@o0J6C)$e=ghhI T`IvoRZisgF0?h}r@+ literal 0 HcmV?d00001 diff --git a/Scripts/Editor/Resources/xnode_corner.png.meta b/Scripts/Editor/Resources/xnode_corner.png.meta new file mode 100644 index 0000000..5b45fe5 --- /dev/null +++ b/Scripts/Editor/Resources/xnode_corner.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 0babe8a4377248fcacd576e5da1a27e5 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 1 + swizzle: 50462976 + cookieLightType: 2 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: