Skip to content

Commit 26529bf

Browse files
authored
Merge pull request #30 from megalon/fixes
v0.4.2 Enum fixes
2 parents 6b6dd81 + 263041f commit 26529bf

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System.Linq;
2+
using UnityEngine;
3+
using UnityEditor;
4+
using XNodeEditor;
5+
using NASB_Moveset_Editor.FloatSources;
6+
using static MovesetParser.FloatSources.FSMovement;
7+
8+
namespace NASB_Moveset_Editor
9+
{
10+
[CustomNodeEditor(typeof(FSJumpsNode))]
11+
public class FSJumpsNodeEditor : FloatSourceNodeEditor
12+
{
13+
public override void OnBodyGUI()
14+
{
15+
serializedObject.Update();
16+
string[] excludes = { "m_Script", "graph", "position", "ports" };
17+
18+
SerializedProperty iterator = serializedObject.GetIterator();
19+
20+
var nameof = GUI.GetNameOfFocusedControl();
21+
22+
bool enterChildren = true;
23+
while (iterator.NextVisible(enterChildren))
24+
{
25+
enterChildren = false;
26+
if (excludes.Contains(iterator.name)) continue;
27+
28+
if (iterator.name.Equals("Value"))
29+
{
30+
continue;
31+
}
32+
33+
if (iterator.type.Equals("string"))
34+
{
35+
EditorGUILayout.LabelField(iterator.displayName);
36+
iterator.stringValue = EditorGUILayout.TextField(iterator.stringValue);
37+
}
38+
else if (iterator.type.Equals("bool"))
39+
{
40+
iterator.boolValue = EditorGUILayout.ToggleLeft(iterator.displayName, iterator.boolValue);
41+
}
42+
else if (iterator.type.Equals("Enum"))
43+
{
44+
EditorGUILayout.LabelField(iterator.displayName);
45+
46+
// Since this enum skips from 18 to 27
47+
if (iterator.intValue > 18)
48+
{
49+
iterator.intValue = iterator.intValue - 9;
50+
}
51+
52+
iterator.intValue = EditorGUILayout.Popup(iterator.intValue, iterator.enumDisplayNames);
53+
54+
// If we don't do this the wrong value gets saved
55+
if (iterator.intValue > 18)
56+
{
57+
iterator.intValue = iterator.intValue + 9;
58+
}
59+
}
60+
else
61+
{
62+
NodeEditorGUILayout.PropertyField(iterator, true);
63+
}
64+
}
65+
66+
// Iterate through dynamic ports and draw them in the order in which they are serialized
67+
foreach (XNode.NodePort dynamicPort in target.DynamicPorts)
68+
{
69+
if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
70+
NodeEditorGUILayout.PortField(dynamicPort);
71+
}
72+
73+
serializedObject.ApplyModifiedProperties();
74+
}
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System.Linq;
2+
using UnityEngine;
3+
using UnityEditor;
4+
using XNodeEditor;
5+
using NASB_Moveset_Editor.FloatSources;
6+
using static MovesetParser.FloatSources.FSMovement;
7+
8+
namespace NASB_Moveset_Editor
9+
{
10+
[CustomNodeEditor(typeof(FSMovementNode))]
11+
public class FSMovementNodeEditor : FloatSourceNodeEditor
12+
{
13+
public override void OnBodyGUI()
14+
{
15+
serializedObject.Update();
16+
string[] excludes = { "m_Script", "graph", "position", "ports" };
17+
18+
SerializedProperty iterator = serializedObject.GetIterator();
19+
20+
var nameof = GUI.GetNameOfFocusedControl();
21+
22+
bool enterChildren = true;
23+
while (iterator.NextVisible(enterChildren))
24+
{
25+
enterChildren = false;
26+
if (excludes.Contains(iterator.name)) continue;
27+
28+
if (iterator.name.Equals("Value"))
29+
{
30+
continue;
31+
}
32+
33+
if (iterator.type.Equals("string"))
34+
{
35+
EditorGUILayout.LabelField(iterator.displayName);
36+
iterator.stringValue = EditorGUILayout.TextField(iterator.stringValue);
37+
}
38+
else if (iterator.type.Equals("bool"))
39+
{
40+
iterator.boolValue = EditorGUILayout.ToggleLeft(iterator.displayName, iterator.boolValue);
41+
}
42+
else if (iterator.type.Equals("Enum"))
43+
{
44+
EditorGUILayout.LabelField(iterator.displayName);
45+
46+
// Since this enum skips from 71 to 83 we need to set it 72
47+
// so that it displays correctly in the editor
48+
if (iterator.intValue == 83)
49+
{
50+
iterator.intValue = 72;
51+
}
52+
53+
iterator.intValue = EditorGUILayout.Popup(iterator.intValue, iterator.enumDisplayNames);
54+
55+
// If we don't do this the wrong value gets saved
56+
if (iterator.intValue == 72)
57+
{
58+
iterator.intValue = 83;
59+
}
60+
}
61+
else
62+
{
63+
NodeEditorGUILayout.PropertyField(iterator, true);
64+
}
65+
}
66+
67+
// Iterate through dynamic ports and draw them in the order in which they are serialized
68+
foreach (XNode.NodePort dynamicPort in target.DynamicPorts)
69+
{
70+
if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
71+
NodeEditorGUILayout.PortField(dynamicPort);
72+
}
73+
74+
serializedObject.ApplyModifiedProperties();
75+
}
76+
}
77+
}

Scripts/Nodes/FloatSources/FSMovementNode.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using NASB_Moveset_Editor.ObjectSources;
2626
using NASB_Moveset_Editor.Unity;
2727
using static MovesetParser.FloatSources.FloatSource;
28+
using static MovesetParser.FloatSources.FSMovement;
2829

2930
namespace NASB_Moveset_Editor.FloatSources
3031
{

0 commit comments

Comments
 (0)