From 095f1e5d0cead88e4f06ddc0d88066efc1e12098 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 20 Feb 2026 13:40:12 +0100 Subject: [PATCH] Animations now selectable using OptionButton. --- blendalot_animation_node.h | 1 + .../blendalot/animation_graph_editor.gd | 6 ++++- demo/addons/blendalot/blend_tree_editor.gd | 22 ++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/blendalot_animation_node.h b/blendalot_animation_node.h index e3d07b3..9c97a82 100644 --- a/blendalot_animation_node.h +++ b/blendalot_animation_node.h @@ -350,6 +350,7 @@ public: void set_animation_player(AnimationPlayer *p_player); bool set_animation(const StringName &p_name); StringName get_animation() const; + AnimationPlayer *get_animation_player() const; TypedArray get_animations_as_typed_array() const; diff --git a/demo/addons/blendalot/animation_graph_editor.gd b/demo/addons/blendalot/animation_graph_editor.gd index 759653e..ce7c30e 100644 --- a/demo/addons/blendalot/animation_graph_editor.gd +++ b/demo/addons/blendalot/animation_graph_editor.gd @@ -6,12 +6,13 @@ class_name AnimationGraphEditor @onready var breadcrumb_button_container: HBoxContainer = %BreadcrumbButtons @onready var active_graph_control: Control = %ActiveGraphControl -var active_animation_graph_node:BLTAnimationGraph = null +var animation_graph:BLTAnimationGraph = null var animation_graph_root_node:BLTAnimationNode = null var graph_node_stack:Array[BLTAnimationNode] = [] var active_graph_edit:Control = null var active_graph_edit_index = -1 + func reset_graph_control(): for child in active_graph_control.get_children(): active_graph_control.remove_child(child) @@ -19,6 +20,7 @@ func reset_graph_control(): func edit_animation_root_node(blt_node:BLTAnimationNode): + print("Setting root node") graph_node_stack = [] active_graph_edit_index = -1 truncate_graph_stack(0) @@ -31,6 +33,8 @@ func edit_animation_root_node(blt_node:BLTAnimationNode): edit_graph(blt_node) return + assert(is_instance_valid(animation_graph)) + push_warning("Cannot edit node %s. Graph type %s not yet supported." % [blt_node.resource_name, blt_node.get_class()]) diff --git a/demo/addons/blendalot/blend_tree_editor.gd b/demo/addons/blendalot/blend_tree_editor.gd index 32b6f69..e1f1b34 100644 --- a/demo/addons/blendalot/blend_tree_editor.gd +++ b/demo/addons/blendalot/blend_tree_editor.gd @@ -105,12 +105,25 @@ func create_graph_node_for_blt_node(blt_node: BLTAnimationNode) -> GraphNode: result_graph_node.add_child(slot_label) result_graph_node.set_slot(i + result_slot_offset, true, 1, Color.WHITE, false, 1, Color.BLACK) + if blt_node.get_class() == "BLTAnimationNodeSampler": + var animation_sampler_node:BLTAnimationNodeSampler = blt_node as BLTAnimationNodeSampler + var animation_selector_button = OptionButton.new() + var animation_player:AnimationPlayer = animation_sampler_node.get_animation_player() + for animation_name in animation_player.get_animation_list(): + animation_selector_button.add_item(animation_name) + if animation_name == animation_sampler_node.animation: + animation_selector_button.select(animation_selector_button.item_count - 1) + + animation_selector_button.item_selected.connect(_on_animation_select.bind(animation_sampler_node, animation_selector_button)) + + result_graph_node.add_child(animation_selector_button) + blt_node.node_changed.connect(_trigger_graph_changed) return result_graph_node -func _trigger_graph_changed(): +func _trigger_graph_changed(_node_name): graph_changed.emit() @@ -253,3 +266,10 @@ func _on_node_double_click(graph_node:GraphNode): if blend_tree_node is BLTAnimationNodeBlendTree: edit_subgraph.emit(blend_tree_node) + +# +# Animation selection for BltAnimationNodeSampler +# +func _on_animation_select(index:int, blt_node_sampler:BLTAnimationNodeSampler, option_button:OptionButton): + blt_node_sampler.animation = option_button.get_item_text(index) + blt_node_sampler.node_changed.emit(blt_node_sampler.resource_name)