From f299c72a5446dd65737888f4abf98d90e178428f Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Thu, 24 Oct 2024 20:58:41 -0700 Subject: [PATCH 1/2] Add code template to block tooltips --- addons/block_code/ui/blocks/block/block.gd | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/block_code/ui/blocks/block/block.gd b/addons/block_code/ui/blocks/block/block.gd index 38123c5c..989e48b8 100644 --- a/addons/block_code/ui/blocks/block/block.gd +++ b/addons/block_code/ui/blocks/block/block.gd @@ -217,10 +217,18 @@ func _get_tooltip(at_position: Vector2) -> String: if not definition: return "" - if definition.variant_type == Variant.Type.TYPE_NIL: - return definition.description - - return "{description}\n\nType: [b]{type}[/b]".format({"description": definition.description, "type": type_string(definition.variant_type)}) + var lines: Array[String] + + lines.append(definition.description) + + lines.append("") + lines.append("[code]{0}[/code]".format([definition.code_template.strip_edges()])) + + if definition.variant_type != Variant.Type.TYPE_NIL: + lines.append("") + lines.append("Type: [b]{0}[/b]".format([type_string(definition.variant_type)])) + + return "\n".join(lines) func _make_custom_tooltip(for_text) -> Control: From 6958eb3dda5cf945dae774650b37523d13f71b01 Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Thu, 24 Oct 2024 20:59:54 -0700 Subject: [PATCH 2/2] Add parameters list to block tooltips --- .../code_generation/block_definition.gd | 9 +++++++++ addons/block_code/ui/blocks/block/block.gd | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/addons/block_code/code_generation/block_definition.gd b/addons/block_code/code_generation/block_definition.gd index 26ac9e70..bab521c6 100644 --- a/addons/block_code/code_generation/block_definition.gd +++ b/addons/block_code/code_generation/block_definition.gd @@ -81,6 +81,15 @@ func _to_string(): return "%s - %s" % [name, target_node_class] +func get_input_parameters() -> Dictionary: + var result: Dictionary + for item in parse_display_template(display_template): + if item.has("in_parameter"): + var parameter = item.get("in_parameter") + result[parameter["name"]] = parameter["type"] + return result + + func get_output_parameters() -> Dictionary: var result: Dictionary for item in parse_display_template(display_template): diff --git a/addons/block_code/ui/blocks/block/block.gd b/addons/block_code/ui/blocks/block/block.gd index 989e48b8..5b733be2 100644 --- a/addons/block_code/ui/blocks/block/block.gd +++ b/addons/block_code/ui/blocks/block/block.gd @@ -218,16 +218,30 @@ func _get_tooltip(at_position: Vector2) -> String: return "" var lines: Array[String] - + lines.append(definition.description) lines.append("") lines.append("[code]{0}[/code]".format([definition.code_template.strip_edges()])) + var input_parameters := definition.get_input_parameters() + var output_parameters := definition.get_output_parameters() + + if input_parameters or output_parameters: + lines.append("") + + for parameter_name in input_parameters: + var parameter_type = input_parameters[parameter_name] + lines.append("{0}: [b]{1}[/b]".format([parameter_name, type_string(parameter_type)])) + + for parameter_name in output_parameters: + var parameter_type = output_parameters[parameter_name] + lines.append("{0}: [b]{1}[/b]".format([parameter_name, type_string(parameter_type)])) + if definition.variant_type != Variant.Type.TYPE_NIL: lines.append("") lines.append("Type: [b]{0}[/b]".format([type_string(definition.variant_type)])) - + return "\n".join(lines)