소스 검색

[animgraph] Custom anim override api

Clément Espeute 8 달 전
부모
커밋
5b6953fd0c
4개의 변경된 파일85개의 추가작업 그리고 53개의 파일을 삭제
  1. 68 0
      hide/view/animgraph/AnimPicker.hx
  2. 4 50
      hide/view/animgraph/BlendSpace2DEditor.hx
  3. 12 2
      hrt/animgraph/AnimGraph.hx
  4. 1 1
      hrt/animgraph/nodes/Input.hx

+ 68 - 0
hide/view/animgraph/AnimPicker.hx

@@ -0,0 +1,68 @@
+package hide.view.animgraph;
+
+
+
+class AnimPicker extends hide.comp.Component {
+	var button : hide.comp.Button;
+
+	public function new(parent = null, undo: hide.ui.UndoHistory, get: () -> String, set: (string: String) -> Void, lister: (ctx: hrt.animgraph.AnimGraph.EditorProviderContext) -> Array<String>) {
+		button = new hide.comp.Button(parent, null, "", {hasDropdown: true});
+		super(parent, button.element);
+
+		button.label = get();
+
+		var items : Array<hide.comp.ContextMenu.MenuItem> = [];
+
+		function setPointPath(path: String) {
+			var old = get();
+			function exec(isUndo: Bool) {
+				var toSet = !isUndo ? path : old;
+				set(toSet);
+				setAnim(toSet);
+			};
+			exec(false);
+			undo.change(Custom(exec));
+		}
+
+		items.push({
+			label: "Choose File ...",
+			click: () -> {
+			ide.chooseFile(["fbx"], setPointPath, true);
+			}
+		});
+
+		if (lister != null) {
+			items.push({isSeparator: true});
+
+			var anims = lister(null);
+			for (anim in anims) {
+				items.push({
+					label: anim,
+					click: setPointPath.bind(anim),
+				});
+			}
+		}
+
+		button.onClick = () -> {
+			hide.comp.ContextMenu.createDropdown(button.element.get(0), items, {search: Visible, autoWidth: true});
+		};
+
+		button.element.get(0).ondragover = (e:js.html.DragEvent) -> {
+			if (e.dataTransfer.types.contains(AnimList.dragEventKey))
+				e.preventDefault();
+		};
+
+		button.element.get(0).ondrop = (e:js.html.DragEvent) -> {
+			var data = e.dataTransfer.getData(AnimList.dragEventKey);
+			if (data.length == 0)
+				return;
+			e.preventDefault();
+
+			setPointPath(data);
+		};
+	}
+
+	public function setAnim(string: String) {
+		button.label = string;
+	}
+}

+ 4 - 50
hide/view/animgraph/BlendSpace2DEditor.hx

@@ -430,58 +430,12 @@ class BlendSpace2DEditor extends hide.view.FileView {
 			var div = new Element("<div></div>").appendTo(editor.find("dl"));
 			new Element("<dt>Anim</dt>").appendTo(div);
 			var dd = new Element("<dd>").appendTo(div);
-			var button = new hide.comp.Button(dd, null, "", {hasDropdown: true});
-			button.label = blendSpace2D.points[selectedPoint].animPath;
 
-			var items : Array<hide.comp.ContextMenu.MenuItem> = [];
-
-			function setPointPath(path: String) {
-				var old = blendSpace2D.points[selectedPoint].animPath;
-				blendSpace2D.points[selectedPoint].animPath = path;
-				undo.change(Field(blendSpace2D.points[selectedPoint], "animPath", old), () -> {
-					button.label = blendSpace2D.points[selectedPoint].animPath;
-					refreshPreviewAnimation();
-				});
-				button.label = blendSpace2D.points[selectedPoint].animPath;
+			var selectedSave = selectedPoint;
+			new AnimPicker(dd, undo, () -> blendSpace2D.points[selectedSave].animPath, (s) -> {
+				blendSpace2D.points[selectedSave].animPath = s;
 				refreshPreviewAnimation();
-			}
-
-			items.push({
-				label: "Choose File ...",
-				click: () -> {
-				ide.chooseFile(["fbx"], setPointPath, true);
-				}
-			});
-
-			if (hrt.animgraph.AnimGraph.customAnimNameLister != null) {
-				items.push({isSeparator: true});
-
-				var anims = hrt.animgraph.AnimGraph.customAnimNameLister(null);
-				for (anim in anims) {
-					items.push({
-						label: anim,
-						click: setPointPath.bind(anim),
-					});
-				}
-			}
-
-			button.onClick = () -> {
-				hide.comp.ContextMenu.createDropdown(button.element.get(0), items, {search: Visible, autoWidth: true});
-			};
-
-			button.element.get(0).ondragover = (e:js.html.DragEvent) -> {
-				if (e.dataTransfer.types.contains(AnimList.dragEventKey))
-					e.preventDefault();
-			};
-
-			button.element.get(0).ondrop = (e:js.html.DragEvent) -> {
-				var data = e.dataTransfer.getData(AnimList.dragEventKey);
-				if (data.length == 0)
-					return;
-				e.preventDefault();
-
-				setPointPath(data);
-			};
+			}, hrt.animgraph.AnimGraph.customAnimNameLister);
 		}
 
 		var preview = new hide.Element('

+ 12 - 2
hrt/animgraph/AnimGraph.hx

@@ -16,6 +16,12 @@ typedef SerializedEdge = {
 	outputId: Int,
 };
 
+#if editor
+typedef EditorProviderContext = {
+	source: String,
+}
+#end
+
 
 @:access(hrt.animgraph.AnimGraphInstance)
 class AnimGraph extends hrt.prefab.Prefab {
@@ -180,9 +186,13 @@ class AnimGraph extends hrt.prefab.Prefab {
 	/**
 		Used to display a list of valid animation names to use with the animResolver feature
 	**/
-	public static var customAnimNameLister : (graph: AnimGraph) -> Array<String>;
+	public static var customAnimNameLister : (context: EditorProviderContext) -> Array<String>;
 
-	public static var customEditorResolverProvider : (graph: AnimGraph) -> Array<{name: String, resolver: hrt.animgraph.AnimGraphInstance.AnimResolver}>;
+	/**
+		Return a list of resolvers to use in the editor to preview various configurations.
+		name is the string that will be displayed in the Anim Set selection box in the editor
+	**/
+	public static var customEditorResolverProvider : (context: EditorProviderContext) -> Array<{name: String, resolver: hrt.animgraph.AnimGraphInstance.AnimResolver}>;
 	#end
 
 	static var _ = hrt.prefab.Prefab.register("animgraph", AnimGraph, "animgraph");

+ 1 - 1
hrt/animgraph/nodes/Input.hx

@@ -19,7 +19,7 @@ class Input extends AnimNode {
 
 	override function getBones(ctx: hrt.animgraph.nodes.AnimNode.GetBoneContext):Map<String, Int> {
 		proxy = new AnimProxy();
-		anim = hxd.res.Loader.currentInstance.load(path).toModel().toHmd().loadAnimation().createInstance(proxy);
+		anim = hxd.res.Loader.currentInstance.load(ctx.resolver(path)).toModel().toHmd().loadAnimation().createInstance(proxy);
 
 		var map : Map<String, Int> = [];
 		for (id => obj in anim.getObjects()) {