Skip to content

Generate value blocks for AnimationPlayer animations #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions addons/block_code/ui/main_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ func _ready():
func _on_undo_redo_version_changed():
if _current_block_code_node == null:
return

var block_script: BlockScriptSerialization = _current_block_code_node.block_script
_picker.block_script_selected(block_script)
_title_bar.block_script_selected(block_script)
_block_canvas.block_script_selected(block_script)
_refresh_selected_block_script()


func _on_show_script_button_pressed():
Expand Down Expand Up @@ -117,7 +113,12 @@ func switch_block_code_node(block_code_node: BlockCode):
_delete_node_button.disabled = _current_block_code_node == null
if _current_block_code_node != null:
_try_migration()
_picker.block_script_selected(block_script)
_refresh_selected_block_script()


func _refresh_selected_block_script():
var block_script: BlockScriptSerialization = _current_block_code_node.block_script
_picker.block_script_selected(block_script, _current_block_code_node.get_parent() if _current_block_code_node else null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this would be a bit more readable without a ternary operator. Or at least moving the conditional to a variable:

var parent_node: Node = _current_block_code_node.get_parent() if _current_block_code_node else null
_picker.block_script_selected(block_script, parent_node)

_title_bar.block_script_selected(block_script)
_block_canvas.block_script_selected(block_script)

Expand Down Expand Up @@ -278,3 +279,8 @@ func _create_variable(variable: VariableResource):
undo_redo.commit_action()

_picker.reload_variables(new_variables)


func _on_visibility_changed():
if visible:
_refresh_selected_block_script()
1 change: 1 addition & 0 deletions addons/block_code/ui/main_panel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ mouse_filter = 2
picker_path = NodePath("../PickerSplit/Picker")
block_canvas_path = NodePath("../PickerSplit/MarginContainer/VBoxContainer/BlockCanvas")

[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
[connection signal="pressed" from="MarginContainer/HBoxContainer/ScriptVBox/HBoxContainer/ShowScriptButton" to="." method="_on_show_script_button_pressed"]
[connection signal="pressed" from="MarginContainer/HBoxContainer/ScriptVBox/HBoxContainer/DeleteNodeButton" to="." method="_on_delete_node_button_pressed"]
[connection signal="add_block_code" from="MarginContainer/HBoxContainer/ScriptVBox/MarginContainer/PickerSplit/MarginContainer/VBoxContainer/BlockCanvas" to="." method="_on_block_canvas_add_block_code"]
Expand Down
17 changes: 17 additions & 0 deletions addons/block_code/ui/picker/categories/category_factory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,23 @@ static func blocks_from_property_list(property_list: Array, selected_props: Dict
return block_list


static func get_blocks_for_object(object: Object) -> Array[Block]:
var blocks: Array[Block] = []

if object is AnimationPlayer:
var animation_player := object as AnimationPlayer
for animation_key in animation_player.get_animation_list():
var b = BLOCKS["parameter_block"].instantiate()
b.variant_type = TYPE_STRING
b.block_format = animation_key
b.statement = animation_key
b.tooltip_text = "The animation '%s' which is attached to this AnimationPlayer." % animation_key
b.category = "Graphics | Animation"
blocks.append(b)

return blocks


static func get_inherited_blocks(_class_name: String) -> Array[Block]:
var blocks: Array[Block] = []

Expand Down
3 changes: 2 additions & 1 deletion addons/block_code/ui/picker/picker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var scroll_tween: Tween
var _variable_category_display: VariableCategoryDisplay = null


func block_script_selected(block_script: BlockScriptSerialization):
func block_script_selected(block_script: BlockScriptSerialization, parent_node: Node):
if not block_script:
reset_picker()
return
Expand All @@ -41,6 +41,7 @@ func block_script_selected(block_script: BlockScriptSerialization):
break

blocks_to_add.append_array(CategoryFactory.get_inherited_blocks(parent_class))
blocks_to_add.append_array(CategoryFactory.get_blocks_for_object(parent_node))

init_picker(blocks_to_add, categories_to_add)
reload_variables(block_script.variables)
Expand Down