Skip to content
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

Add tooltip code details #291

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions addons/block_code/code_generation/block_definition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
28 changes: 25 additions & 3 deletions addons/block_code/ui/blocks/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,32 @@ func _get_tooltip(at_position: Vector2) -> String:
if not definition:
return ""

if definition.variant_type == Variant.Type.TYPE_NIL:
return definition.description
var lines: Array[String]

return "{description}\n\nType: [b]{type}[/b]".format({"description": definition.description, "type": type_string(definition.variant_type)})
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)


func _make_custom_tooltip(for_text) -> Control:
Expand Down