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

GDScript: Fix Inspector "Add Input" button, improve tweening, add print in chat, fix entry signals, add export vars #184

Merged
merged 5 commits into from
May 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ signal inspector_category_visibility_changed(new_visibility: bool)
@export var expand_speed: float = 10.0
@export var properties: Node

## The text to show as a tooltip when hovering.
## Use this instead of Godot's tooltip_text property.
@export var hover_tooltip_text: String = ""

var _is_category_visible: bool = false
var _properties_child: Control
var _plus_texture: TextureRect
Expand Down Expand Up @@ -55,3 +59,17 @@ func set_category_visible(new_is_visible):

func _on_toggle_button_pressed():
set_category_visible(not _is_category_visible)


func _on_hoverable_button_mouse_entered() -> void:
if hover_tooltip_text == "":
return
GameUI.set_hover_tooltip_text(hover_tooltip_text)


func _on_hoverable_button_mouse_exited() -> void:
GameUI.hide_hover_tooltip_text()


func _on_hoverable_button_pressed() -> void:
GameUI.hide_hover_tooltip_text()
27 changes: 27 additions & 0 deletions mirror-godot-app/creator/selection/inspector/inspector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const _ENVIRONMENT_CATEGORY = preload("res://creator/selection/inspector/categor
const _LIGHT_CATEGORY = preload("res://creator/selection/inspector/categories/inspector_light.tscn")
const _PHYSICS_CATEGORY = preload("res://creator/selection/inspector/categories/inspector_physics.tscn")
const _VISIBILITY_CATEGORY = preload("res://creator/selection/inspector/categories/inspector_visibility.tscn")
const _SCRIPT_OBJECT_VARS_CATEGORY = preload("res://creator/selection/inspector/script/inspector_script_object_vars.tscn")
const _SCRIPT_INSTANCE_CATEGORY = preload("res://creator/selection/inspector/script/inspector_script_instance.tscn")
const _MODEL_NODES_CATEGORY = preload("res://creator/selection/inspector/nodes/inspector_model_nodes.tscn")
const _EXTRA_NODE_CATEGORY = preload("res://creator/selection/inspector/nodes/inspector_extra_node.tscn")
Expand Down Expand Up @@ -43,6 +44,7 @@ var _deletion_target_category: InspectorCategoryBase

@onready var _categories: VBoxContainer = _tab_cont.get_node(^"Properties/MarginContainer/Categories")
@onready var _script_main_vbox: VBoxContainer = _tab_cont.get_node(^"Scripting/MarginContainer/VBoxContainer")
@onready var _script_obj_vars: Control = _script_main_vbox.get_node(^"ScriptObjectVars")
@onready var _script_instances: VBoxContainer = _script_main_vbox.get_node(^"ScriptInstances")
@onready var _script_add_button: Button = _script_main_vbox.get_node(^"AddScriptButton")
@onready var _model_nodes_main_vbox: VBoxContainer = _tab_cont.get_node(^"Nodes/MarginContainer/VBoxContainer")
Expand Down Expand Up @@ -189,6 +191,7 @@ func inspect_nodes(new_nodes: Array[Node], force_rebuild: bool = false) -> void:
# The first step is to delete old categories if they exist.
_remove_old_category_children(_categories)
_remove_old_category_children(_script_instances)
_remove_old_category_children(_script_obj_vars)
_remove_old_category_children(_model_nodes)
# Update a few misc things.
_button_sound.refresh()
Expand Down Expand Up @@ -278,6 +281,7 @@ func _setup_new_categories(target_nodes: Array[Node]) -> void:
prim_model_cat.request_convert_to_local.connect(_on_request_convert_prim_model_to_local.bind(target_node))
target_node.scripts_changed.connect(_on_scripts_changed)
_setup_script_instances(target_node)
_setup_script_obj_vars(target_node)
_script_main_vbox.show()
_tab_cont.tabs_visible = true
_setup_extra_model_nodes(target_node)
Expand All @@ -287,6 +291,7 @@ func _setup_new_categories(target_nodes: Array[Node]) -> void:
_tab_cont.current_tab = 1
target_node.scripts_changed.connect(_on_scripts_changed)
_setup_script_instances(target_node)
_setup_script_obj_vars(target_node)
_script_main_vbox.show()
else:
_tab_cont.current_tab = 0
Expand Down Expand Up @@ -390,6 +395,28 @@ func _setup_script_instances(space_object_or_global_scripts: Node) -> void:
_setup_script_instance(script_instance)


func _setup_script_obj_vars(space_object_or_global_scripts: Node) -> void:
# Set up script object variables inspector, if it has any.
var object_variables: Dictionary
if space_object_or_global_scripts.has_meta(&"MirrorScriptObjectVariables"):
object_variables = space_object_or_global_scripts.get_meta(&"MirrorScriptObjectVariables")
if object_variables.is_empty():
if not _is_any_script_instance_gdscript(space_object_or_global_scripts):
return
var obj_var_cat = _SCRIPT_OBJECT_VARS_CATEGORY.instantiate()
obj_var_cat.setup(space_object_or_global_scripts, Util.can_local_user_edit_scripts())
_script_obj_vars.add_child(obj_var_cat)
obj_var_cat.setup_object_vars(object_variables)


func _is_any_script_instance_gdscript(space_object_or_global_scripts: Node) -> bool:
var script_instances: Array[ScriptInstance] = space_object_or_global_scripts.get_script_instances()
for script_inst in script_instances:
if script_inst is GDScriptInstance:
return true
return false


func _setup_script_instance(script_instance: ScriptInstance) -> void:
var cat: InspectorCategoryBase = _setup_category(script_instance.target_node, _SCRIPT_INSTANCE_CATEGORY, "", _script_instances)
cat.setup(script_instance)
Expand Down
5 changes: 5 additions & 0 deletions mirror-godot-app/creator/selection/inspector/inspector.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ metadata/_edit_layout_mode = 1
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/TabContainer/Scripting/MarginContainer"]
layout_mode = 2

[node name="ScriptObjectVars" type="MarginContainer" parent="VBoxContainer/TabContainer/Scripting/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_top = 0
theme_override_constants/margin_bottom = 8

[node name="ScriptInstances" type="VBoxContainer" parent="VBoxContainer/TabContainer/Scripting/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ func _setup_parameter(parameter_name: String, parameter_data: Array) -> void:


func _on_parameter_changed(value, which: Control) -> void:
var parameters_for_entry: Dictionary = _target_script_instance.entry_parameters[_entry_id]
var param_name = which.label_text
var param_data = parameters_for_entry[param_name]
param_data[1] = value
_target_script_instance.apply_inspector_parameter_values()
var param_name: String = which.label_text
_target_script_instance.set_inspector_parameter_input_value(_entry_id, param_name, value)
_target_script_instance.script_instance_changed()


Expand All @@ -69,12 +66,7 @@ func _on_toggle_button_inspector_category_visibility_changed(new_visibility: boo


func _on_create_parameter(parameter_port_array: Array) -> void:
for entry_block in _target_script_instance.script_builder.entry_blocks:
if entry_block.entry_id == _entry_id:
entry_block.parameters.create_inspector_parameter(parameter_port_array)
entry_block.reset_entry_output_ports()
break
_target_script_instance.sync_script_inst_params_with_script_data()
_target_script_instance.create_inspector_parameter_input(_entry_id, parameter_port_array)
_target_script_instance.script_data_contents_changed()
refresh_inspected_nodes.emit()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
[node name="InspectorScriptEntryInputs" instance=ExtResource("1_amxtn")]
script = ExtResource("2_adill")

[node name="ToggleButton" parent="CategoryTitle" index="0" node_paths=PackedStringArray("properties")]
properties = NodePath("../../Properties")

[node name="Text" parent="CategoryTitle/ToggleButton/Name" index="3"]
text = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
extends InspectorCategoryBase


const _TRASH_BUTTON = preload("res://creator/selection/inspector/script/entry_input_trash_button.tscn")

var target_node: Node # SpaceObject or SpaceGlobalScripts
var _is_editable: bool = false
var _object_vars: Dictionary
var _property_list: Control


## Must run before _ready()
func setup(target_object: Node, is_editable: bool) -> void:
target_node = target_object
_property_list = $Properties/MarginContainer/PropertyList
_is_editable = is_editable


func setup_object_vars(object_vars: Dictionary) -> void:
_object_vars = object_vars
for obj_var_name in _object_vars:
_setup_object_var(obj_var_name, _object_vars[obj_var_name])
if _property_list.get_child_count() < 5:
if _property_list.get_child_count() != 0:
$CategoryTitle/ToggleButton.hover_tooltip_text = ""
set_visible_to_maximum_size()


func _setup_object_var(obj_var_name: String, obj_var_value: Variant) -> void:
var obj_var_type: int = typeof(obj_var_value)
if obj_var_type == TYPE_NIL or not obj_var_type in ScriptParameterCreationMenu.INSPECTOR_PRIMITIVE_SCENES:
return
var obj_var_scene = ScriptParameterCreationMenu.INSPECTOR_PRIMITIVE_SCENES[obj_var_type].instantiate()
obj_var_scene.label_text = obj_var_name
obj_var_scene.reset_value = Serialization.type_convert_any(_get_default_value_of_obj_var(obj_var_name), obj_var_type)
# Be careful, the order matters here! Value editors with setters
# that use onready vars can only be used after adding as a child,
# and then we need to refresh if a refresh method exists.
_property_list.add_child(obj_var_scene)
obj_var_scene.current_value = obj_var_value
if obj_var_scene.has_method(&"refresh"):
obj_var_scene.refresh()
obj_var_scene.value_changed.connect(_on_object_var_changed.bind(obj_var_scene))
if _is_editable and GameplaySettings.script_show_add_inspector_input:
var trash_button: Node = _TRASH_BUTTON.instantiate()
obj_var_scene.add_child(trash_button)
trash_button.pressed.connect(_on_delete_object_var.bind(obj_var_name))


func _on_object_var_changed(value, which: Control) -> void:
var obj_var_name: String = which.label_text
Zone.script_network_sync.set_variable_on_node(target_node, obj_var_name, value)


func _on_delete_object_var(obj_var_name: String) -> void:
Zone.script_network_sync.set_variable_on_node(target_node, obj_var_name, null)
for child in _property_list.get_children():
child.cleanup_and_delete()
_property_list.remove_child(child)
var vars = target_node.get_meta(&"MirrorScriptObjectVariables")
vars.erase(obj_var_name)
setup_object_vars(vars)


func _get_default_value_of_obj_var(obj_var_name: String) -> Variant:
var script_instances: Array[ScriptInstance] = target_node.get_script_instances()
for script_inst in script_instances:
if script_inst.has_method(&"get_default_value_of_exposed_variable"):
var def = script_inst.get_default_value_of_exposed_variable(obj_var_name)
if def != null:
return def
return null
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[gd_scene load_steps=3 format=3 uid="uid://bhbojmr3nuwrc"]

[ext_resource type="PackedScene" uid="uid://dkxqj3l0xm8uw" path="res://creator/selection/inspector/categories/inspector_category_base.tscn" id="1_ov2tq"]
[ext_resource type="Script" path="res://creator/selection/inspector/script/inspector_script_object_vars.gd" id="2_abj1i"]

[node name="InspectorScriptObjectVars" instance=ExtResource("1_ov2tq")]
script = ExtResource("2_abj1i")

[node name="ToggleButton" parent="CategoryTitle" index="0" node_paths=PackedStringArray("properties")]
properties = NodePath("../../Properties")
hover_tooltip_text = "Use @export in GDScript"

[node name="Text" parent="CategoryTitle/ToggleButton/Name" index="3"]
text = "OBJECT VARIABLES"

[connection signal="mouse_entered" from="CategoryTitle/ToggleButton" to="CategoryTitle/ToggleButton" method="_on_hoverable_button_mouse_entered"]
[connection signal="mouse_exited" from="CategoryTitle/ToggleButton" to="CategoryTitle/ToggleButton" method="_on_hoverable_button_mouse_exited"]
[connection signal="pressed" from="CategoryTitle/ToggleButton" to="CategoryTitle/ToggleButton" method="_on_hoverable_button_pressed"]
1 change: 1 addition & 0 deletions mirror-godot-app/script/editor/abstract_script_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends Control

signal request_save_script_as_asset(script_instance: ScriptInstance)
signal request_show_entry_creation_dialog(target_node: Node)
signal request_show_custom_entry_creation_dialog(target_node: Node)
signal request_toggle_variable_editor()
signal request_script_editor_visibility(is_visible: bool)
signal request_track_recently_used_space_script(script_instance: ScriptInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,39 @@ func _ready() -> void:

func populate_and_show(target_node: Node) -> void:
title = "Create Script Entry"
_entry_creation_menu.populate_selection_tree(target_node)
_entry_creation_menu.populate_selection_tree(target_node, false)
GameUI.grab_input_lock(self)
popup_centered()
_entry_creation_menu.focus_search_bar()


func populate_and_show_for_custom(target_node: Node) -> void:
_entry_creation_menu.populate_selection_tree(target_node, true)
_show_custom_entry_menu()
GameUI.grab_input_lock(self)
_entry_creation_menu.focus_search_bar()


func _on_confirmed() -> void:
var signal_dict = _entry_creation_menu.get_desired_signal_signature()
if signal_dict == null:
title = "Create Entry With Custom Signal"
popup_centered()
_show_custom_entry_menu()
return
var block_dict: Dictionary = signal_dict.duplicate(false)
create_entry_block.emit(block_dict)


func _show_custom_entry_menu() -> void:
title = "Create Entry With Custom Signal"
popup_centered()
_entry_creation_menu.size = Vector2.ZERO
size = Vector2i.ZERO
await get_tree().process_frame
popup_centered()
_entry_creation_menu.size = Vector2.ZERO
size = Vector2i.ZERO


func _on_script_entry_creation_menu_confirmed() -> void:
hide()
_on_confirmed()
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ func setup(signal_tree_populator: ScriptEntrySignalTreePopulator) -> void:
_signal_selection.setup(signal_tree_populator)


func populate_selection_tree(target_node: Node) -> void:
func populate_selection_tree(target_node: Node, for_custom: bool) -> void:
_target_node = target_node
_custom_signal_parameters.clear()
_add_input_button.show()
_custom_signal_name.text = ""
_signal_parameters_label.text = "Signal Inputs:"
_signal_selection.populate_selection_tree(target_node)
_signal_selection.show()
_custom_signal.hide()
if for_custom:
_show_custom_entry_menu()
else:
_signal_selection.populate_selection_tree(target_node)
_signal_selection.show()
_custom_signal.hide()


func focus_search_bar() -> void:
Expand All @@ -43,14 +46,17 @@ func get_desired_signal_signature():
return _get_custom_signal_signature()


func _show_custom_entry_menu() -> void:
_signal_selection.hide()
_custom_signal.show()


func _get_selected_signal_signature():
var signal_dict = _signal_selection.get_selected_signal()
if signal_dict == null:
return null
if String(signal_dict["signal"]) == "custom_signal":
_signal_selection.hide()
_custom_signal.show()
_add_input_button.show()
_show_custom_entry_menu()
return null
return signal_dict

Expand All @@ -68,10 +74,14 @@ func _get_custom_signal_signature():
if not existing_signature.is_empty():
existing_signature = existing_signature.duplicate()
existing_signature["path"] = "self"
existing_signature["type"] = "entry"
return existing_signature
var ret = {
"entry_id": "self_" + signal_name + "_" + str(randi() % 1000000),
"name": "On " + signal_name.capitalize(),
"path": "self",
"signal": signal_name,
"type": "entry",
}
if not _custom_signal_parameters.is_empty():
ret["signalParameters"] = _custom_signal_parameters.duplicate(true)
Expand Down
4 changes: 4 additions & 0 deletions mirror-godot-app/script/editor/script_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ func _on_request_show_entry_creation_dialog(target_node: Node) -> void:
_script_entry_creation_dialog.populate_and_show(target_node)


func _on_request_show_custom_entry_creation_dialog(target_node: Node) -> void:
_script_entry_creation_dialog.populate_and_show_for_custom(target_node)


func _on_script_entry_creation_dialog_create_entry_block(block_json: Dictionary) -> void:
if _gd_script_editor.visible:
if block_json["type"] == "entry":
Expand Down
2 changes: 2 additions & 0 deletions mirror-godot-app/script/editor/script_editor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ script = ExtResource("7_w8ott")

[connection signal="request_save_script_as_asset" from="VisualScriptEditor" to="." method="_on_request_save_script_as_asset"]
[connection signal="request_script_editor_visibility" from="VisualScriptEditor" to="." method="set_visual_script_editor_visibility"]
[connection signal="request_show_custom_entry_creation_dialog" from="VisualScriptEditor" to="." method="_on_request_show_custom_entry_creation_dialog"]
[connection signal="request_show_entry_creation_dialog" from="VisualScriptEditor" to="." method="_on_request_show_entry_creation_dialog"]
[connection signal="request_toggle_variable_editor" from="VisualScriptEditor" to="." method="_on_request_toggle_variable_editor"]
[connection signal="request_track_recently_used_space_script" from="VisualScriptEditor" to="." method="_on_request_track_recently_used_space_script"]
[connection signal="request_save_script_as_asset" from="GDScriptEditor" to="." method="_on_request_save_script_as_asset"]
[connection signal="request_script_editor_visibility" from="GDScriptEditor" to="." method="set_gd_script_editor_visibility"]
[connection signal="request_show_custom_entry_creation_dialog" from="GDScriptEditor" to="." method="_on_request_show_custom_entry_creation_dialog"]
[connection signal="request_show_entry_creation_dialog" from="GDScriptEditor" to="." method="_on_request_show_entry_creation_dialog"]
[connection signal="request_toggle_variable_editor" from="GDScriptEditor" to="." method="_on_request_toggle_variable_editor"]
[connection signal="request_track_recently_used_space_script" from="GDScriptEditor" to="." method="_on_request_track_recently_used_space_script"]
Expand Down
15 changes: 15 additions & 0 deletions mirror-godot-app/script/gd/gdscript_entry.gd
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ func _value_to_gdscript_literal(value: Variant, type_enum: int) -> String:
return str(value)


func connect_entry_signal(script_instance_object: Object, inst_entry_parameters: Dictionary) -> void:
# Trivial case: No inspector parameter inputs, no bindv needed.
if inst_entry_parameters.is_empty():
entry_node.connect(entry_signal, Callable(script_instance_object, function_name))
return
# If the user added inspector parameters via "Add Input", we need to bind them to the signal.
var insp_inputs: Array = []
if inst_entry_parameters.has(entry_id):
var params_for_entry: Dictionary = inst_entry_parameters[entry_id]
for insp_param_name in params_for_entry:
var insp_param_data: Array = params_for_entry[insp_param_name]
insp_inputs.append(insp_param_data[1])
entry_node.connect(entry_signal, Callable(script_instance_object, function_name).bindv(insp_inputs))


static func create_node_for_entry_signal(entry_signal: String) -> Node:
if entry_signal == "timeout":
var timer: Timer = Timer.new()
Expand Down
Loading
Loading