1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00

Changed group resizing, no longer snaps to cursor position.

Changed rename textfield styling to account for custom styling on NodeEditor.cs classes.
This commit is contained in:
Emre Dogan 2023-10-07 04:44:35 +01:00
parent ef83d77a72
commit ebb36fbd28
6 changed files with 188 additions and 17 deletions

View File

@ -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
/// <summary> Called after this node's name has changed. </summary>
public virtual void OnRename() {}
/// <summary> Called when exiting rename mode for this node. </summary>
public virtual void OnRenameDeactive() {}
[AttributeUsage(AttributeTargets.Class)]
public class CustomNodeEditorAttribute : Attribute,
INodeEditorAttrib

View File

@ -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);

View File

@ -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<Texture2D>("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)

View File

@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -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: