Browse Source

[animgraph] Added AnimList to AnimGraphEditor

Clément Espeute 8 months ago
parent
commit
5ccd700aae
3 changed files with 52 additions and 13 deletions
  1. 1 0
      bin/style.css
  2. 1 1
      bin/style.less
  3. 50 12
      hide/view/animgraph/AnimGraphEditor.hx

+ 1 - 0
bin/style.css

@@ -4261,6 +4261,7 @@ graph-editor-root properties-container {
 graph-editor-root properties-container graph-parameters {
   display: flex;
   flex-direction: column;
+  flex-grow: 1;
 }
 graph-editor-root properties-container graph-parameters h1 {
   font-size: 1.2em;

+ 1 - 1
bin/style.less

@@ -5042,7 +5042,7 @@ graph-editor-root {
 		graph-parameters {
 			display: flex;
 			flex-direction: column;
-
+			flex-grow: 1;
 
 			h1 {
 				font-size: 1.2em;

+ 50 - 12
hide/view/animgraph/AnimGraphEditor.hx

@@ -54,27 +54,65 @@ class AnimGraphEditor extends GenericGraphEditor {
 
         refreshPamamList();
 
+        new AnimList(propertiesContainer, null, scenePreview.listAnims(animGraph.animFolder));
+
         graphEditor.element.get(0).addEventListener("dragover", (e: js.html.DragEvent) -> {
-            var paramIndex = Std.parseInt(e.dataTransfer.getData("index"));
-            if (paramIndex != null)
+            if (e.dataTransfer.types.contains("index"))
                 e.preventDefault(); // prevent default to allow drop
+
+            if (e.dataTransfer.types.contains(AnimList.dragEventKey))
+                e.preventDefault();
         });
 
         graphEditor.element.get(0).addEventListener("drop", (e: js.html.DragEvent) -> {
+            var posCursor = new h2d.col.Point(graphEditor.lX(e.clientX - 25), graphEditor.lY(e.clientY - 10));
+
+            // Handle drag from Parameters list
+
+
             var paramIndex = Std.parseInt(e.dataTransfer.getData("index"));
-            if (paramIndex == null)
+            if (paramIndex != null) {
+                e.preventDefault();
+                var inst = new hrt.animgraph.nodes.FloatParameter();
+                @:privateAccess var id = animGraph.nodeIdCount++;
+                inst.id = id;
+                inst.parameter = animGraph.parameters[paramIndex];
+                inst.setPos(posCursor);
+
+                graphEditor.opBox(inst, true, graphEditor.currentUndoBuffer);
+                graphEditor.commitUndo();
                 return;
+            }
 
+            // Handle drag from anim list
+            var path = e.dataTransfer.getData(AnimList.dragEventKey);
+            if (path.length > 0) {
 
-            var posCursor = new h2d.col.Point(graphEditor.lX(e.clientX - 25), graphEditor.lY(e.clientY - 10));
-			var inst = new hrt.animgraph.nodes.FloatParameter();
-			@:privateAccess var id = animGraph.nodeIdCount++;
-			inst.id = id;
-            inst.parameter = animGraph.parameters[paramIndex];
-			inst.setPos(posCursor);
-
-			graphEditor.opBox(inst, true, graphEditor.currentUndoBuffer);
-			graphEditor.commitUndo();
+                if (StringTools.endsWith(path, ".fbx")) {
+                    e.preventDefault();
+                    var inst = new hrt.animgraph.nodes.Input();
+                    @:privateAccess var id = animGraph.nodeIdCount++;
+                    inst.id = id;
+                    inst.path = path;
+                    inst.setPos(posCursor);
+
+                    graphEditor.opBox(inst, true, graphEditor.currentUndoBuffer);
+                    graphEditor.commitUndo();
+                    return;
+                }
+                else if (StringTools.endsWith(path, ".bs2d")) {
+                    e.preventDefault();
+                    var inst = new hrt.animgraph.nodes.BlendSpace2D();
+                    @:privateAccess var id = animGraph.nodeIdCount++;
+                    inst.id = id;
+                    inst.path = path;
+                    inst.setPos(posCursor);
+
+                    graphEditor.opBox(inst, true, graphEditor.currentUndoBuffer);
+                    graphEditor.commitUndo();
+                    return;
+                }
+            }
         });
     }