diff --git a/addons/block_code/block_code_plugin.gd b/addons/block_code/block_code_plugin.gd index 96b9b7ab..ed5cac39 100644 --- a/addons/block_code/block_code_plugin.gd +++ b/addons/block_code/block_code_plugin.gd @@ -174,6 +174,9 @@ static func is_block_code_editable(block_code: BlockCode) -> bool: if not block_code: return false + if not Engine.is_editor_hint(): + return true + # A BlockCode node can be edited if it belongs to the edited scene, or it # is an editable instance. diff --git a/addons/block_code/ui/block_canvas/block_canvas.gd b/addons/block_code/ui/block_canvas/block_canvas.gd index cd67f309..66e9afb5 100644 --- a/addons/block_code/ui/block_canvas/block_canvas.gd +++ b/addons/block_code/ui/block_canvas/block_canvas.gd @@ -94,8 +94,11 @@ func set_child(n: Node): func _on_context_changed(): clear_canvas() - var edited_node = EditorInterface.get_inspector().get_edited_object() as Node + var edited_node: Node + if Engine.is_editor_hint(): + edited_node = EditorInterface.get_inspector().get_edited_object() as Node + if _context.block_script != _current_block_script: _window.position = Vector2(0, 0) zoom = 1 diff --git a/addons/block_code/ui/block_canvas/block_canvas.tscn b/addons/block_code/ui/block_canvas/block_canvas.tscn index 0d3e8e4c..fd544a52 100644 --- a/addons/block_code/ui/block_canvas/block_canvas.tscn +++ b/addons/block_code/ui/block_canvas/block_canvas.tscn @@ -22,6 +22,7 @@ layout_mode = 2 [node name="Window" type="Control" parent="WindowContainer"] unique_name_in_owner = true +visible = false layout_mode = 2 anchors_preset = 0 offset_right = 1152.0 @@ -60,10 +61,12 @@ theme_override_constants/margin_bottom = 4 [node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"] unique_name_in_owner = true +visible = false modulate = Color(1, 1, 1, 0.470588) layout_mode = 2 focus_mode = 0 theme_override_font_sizes/font_size = 24 +text = "1.0x" [node name="MouseOverride" type="MarginContainer" parent="."] unique_name_in_owner = true @@ -72,7 +75,6 @@ mouse_filter = 2 [node name="EmptyBox" type="VBoxContainer" parent="."] unique_name_in_owner = true -visible = false layout_mode = 2 size_flags_vertical = 4 @@ -90,7 +92,7 @@ size_flags_vertical = 4 [node name="Label" type="Label" parent="SelectedNodeBox"] custom_minimum_size = Vector2(200, 0) layout_mode = 2 -text = "Use block coding to create custom behavior and game mechanics for \"{node}\"." +text = "Use block coding to create custom behavior and game mechanics for \"BlockCanvas\"." horizontal_alignment = 1 autowrap_mode = 2 @@ -103,6 +105,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 4 theme_type_variation = &"InspectorActionButton" +disabled = true text = "Add Block Code" icon = ExtResource("2_710vn") @@ -128,6 +131,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 4 theme_type_variation = &"InspectorActionButton" +disabled = true text = "Open in Editor" [node name="ReplaceBlockCodeButton" type="Button" parent="SelectedNodeWithBlockCodeBox/ButtonsBox"] @@ -135,6 +139,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 4 theme_type_variation = &"InspectorActionButton" +disabled = true text = "Override Block Code" icon = ExtResource("2_710vn") diff --git a/addons/block_code/ui/main_panel.gd b/addons/block_code/ui/main_panel.gd index cb4dabd5..62ace701 100644 --- a/addons/block_code/ui/main_panel.gd +++ b/addons/block_code/ui/main_panel.gd @@ -18,13 +18,12 @@ const VariableDefinition = preload("res://addons/block_code/code_generation/vari @onready var _drag_manager: DragManager = %DragManager @onready var _title_bar: TitleBar = %TitleBar @onready var _delete_node_button: Button = %DeleteNodeButton -@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector() @onready var _picker_split: HSplitContainer = %PickerSplit @onready var _collapse_button: Button = %CollapseButton -@onready var _icon_delete := EditorInterface.get_editor_theme().get_icon("Remove", "EditorIcons") -@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons") -@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons") +@onready var _icon_delete := EditorInterface.get_editor_theme().get_icon("Remove", "EditorIcons") if Engine.is_editor_hint() else null +@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons") if Engine.is_editor_hint() else null +@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons") if Engine.is_editor_hint() else null const Constants = preload("res://addons/block_code/ui/constants.gd") @@ -61,12 +60,16 @@ func _on_undo_redo_version_changed(): func _on_show_script_button_pressed(): var script: String = _block_canvas.generate_script_from_current_window() + print("_on_show_script_button_pressed ", _block_canvas._context.block_code_node) script_window_requested.emit(script) func _on_delete_node_button_pressed(): - var scene_root = EditorInterface.get_edited_scene_root() + var scene_root: Node + + if Engine.is_editor_hint(): + scene_root = EditorInterface.get_edited_scene_root() if not scene_root: return @@ -130,7 +133,7 @@ func save_script(): print("No script loaded to save.") return - var scene_node = EditorInterface.get_edited_scene_root() + var scene_node = EditorInterface.get_edited_scene_root() if Engine.is_editor_hint() else null if not BlockCodePlugin.is_block_code_editable(_context.block_code_node): print("Block code for {node} is not editable.".format({"node": _context.block_code_node})) @@ -141,29 +144,36 @@ func save_script(): var resource_path_split = block_script.resource_path.split("::", true, 1) var resource_scene = resource_path_split[0] - undo_redo.create_action("Modify %s's block code script" % _context.parent_node.name, UndoRedo.MERGE_DISABLE, _context.block_code_node) + if undo_redo: + undo_redo.create_action("Modify %s's block code script" % _context.parent_node.name, UndoRedo.MERGE_DISABLE, _context.block_code_node) - if resource_scene and resource_scene != scene_node.scene_file_path: + if resource_scene and scene_node and resource_scene != scene_node.scene_file_path: # This resource is from another scene. Since the user is changing it # here, we'll make a copy for this scene rather than changing it in the # other scene file. - undo_redo.add_undo_property(_context.block_code_node, "block_script", _context.block_script) + if undo_redo: + undo_redo.add_undo_property(_context.block_code_node, "block_script", _context.block_script) block_script = block_script.duplicate(true) - undo_redo.add_do_property(_context.block_code_node, "block_script", block_script) + if undo_redo: + undo_redo.add_do_property(_context.block_code_node, "block_script", block_script) - undo_redo.add_undo_property(block_script, "block_serialization_trees", block_script.block_serialization_trees) + if undo_redo: + undo_redo.add_undo_property(block_script, "block_serialization_trees", block_script.block_serialization_trees) _block_canvas.rebuild_ast_list() _block_canvas.rebuild_block_serialization_trees() - undo_redo.add_do_property(block_script, "block_serialization_trees", block_script.block_serialization_trees) + if undo_redo: + undo_redo.add_do_property(block_script, "block_serialization_trees", block_script.block_serialization_trees) var generated_script = _block_canvas.generate_script_from_current_window() if generated_script != block_script.generated_script: - undo_redo.add_undo_property(block_script, "generated_script", block_script.generated_script) - undo_redo.add_do_property(block_script, "generated_script", generated_script) - + if undo_redo: + undo_redo.add_undo_property(block_script, "generated_script", block_script.generated_script) + undo_redo.add_do_property(block_script, "generated_script", generated_script) + block_script.version = Constants.CURRENT_DATA_VERSION - undo_redo.commit_action() + if undo_redo: + undo_redo.commit_action() func _input(event): @@ -273,13 +283,18 @@ func _create_variable(variable: VariableDefinition): var block_script: BlockScriptSerialization = _context.block_script - undo_redo.create_action("Create variable %s in %s's block code script" % [variable.var_name, _context.parent_node.name]) - undo_redo.add_undo_property(_context.block_script, "variables", _context.block_script.variables) + if undo_redo: + undo_redo.create_action("Create variable %s in %s's block code script" % [variable.var_name, _context.parent_node.name]) + undo_redo.add_undo_property(_context.block_script, "variables", _context.block_script.variables) - var new_variables = block_script.variables.duplicate() - new_variables.append(variable) + var new_variables = block_script.variables.duplicate() + new_variables.append(variable) - undo_redo.add_do_property(_context.block_script, "variables", new_variables) - undo_redo.commit_action() + undo_redo.add_do_property(_context.block_script, "variables", new_variables) + undo_redo.commit_action() + else: + var new_variables = block_script.variables.duplicate() + new_variables.append(variable) + block_script.variables = new_variables _picker.reload_blocks() diff --git a/addons/block_code/ui/main_panel.tscn b/addons/block_code/ui/main_panel.tscn index 78520466..81e2cc8b 100644 --- a/addons/block_code/ui/main_panel.tscn +++ b/addons/block_code/ui/main_panel.tscn @@ -6,7 +6,7 @@ [ext_resource type="PackedScene" uid="uid://c6vumewgnfquy" path="res://addons/block_code/ui/block_canvas/block_canvas.tscn" id="4_cu87g"] [ext_resource type="PackedScene" uid="uid://cph1k5cfximbf" path="res://addons/block_code/drag_manager/drag_manager.tscn" id="4_yijtu"] -[sub_resource type="Image" id="Image_p76b5"] +[sub_resource type="Image" id="Image_ao3hu"] data = { "data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 92, 92, 92, 64, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 92, 92, 92, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 192, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 192, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 192, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 192, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 192, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 192, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 128, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 128, 90, 90, 90, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 249, 90, 90, 90, 192, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 192, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 192, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 192, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 192, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 192, 90, 90, 90, 249, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 197, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 195, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 52, 90, 90, 90, 238, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 236, 92, 92, 92, 50, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 96, 96, 96, 24, 91, 91, 91, 101, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 90, 90, 90, 128, 91, 91, 91, 101, 100, 100, 100, 23, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0), "format": "RGBA8", @@ -16,9 +16,9 @@ data = { } [sub_resource type="ImageTexture" id="ImageTexture_mrr6q"] -image = SubResource("Image_p76b5") +image = SubResource("Image_ao3hu") -[sub_resource type="Image" id="Image_jif7k"] +[sub_resource type="Image" id="Image_urx76"] data = { "data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 92, 92, 92, 72, 91, 91, 91, 73, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 116, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 71, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 41, 90, 90, 90, 248, 90, 90, 90, 255, 90, 90, 90, 255, 92, 92, 92, 75, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 170, 170, 170, 3, 90, 90, 90, 201, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 200, 170, 170, 170, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 119, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 247, 96, 96, 96, 40, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 41, 90, 90, 90, 248, 90, 90, 90, 255, 90, 90, 90, 255, 91, 91, 91, 118, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 170, 170, 170, 3, 90, 90, 90, 201, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 200, 170, 170, 170, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 119, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 247, 96, 96, 96, 40, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 41, 90, 90, 90, 248, 90, 90, 90, 255, 90, 90, 90, 255, 91, 91, 91, 118, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 170, 170, 170, 3, 90, 90, 90, 201, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 200, 170, 170, 170, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 91, 91, 91, 84, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 96, 96, 96, 40, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 91, 91, 91, 84, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 255, 93, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 170, 170, 170, 3, 90, 90, 90, 200, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 200, 170, 170, 170, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 41, 90, 90, 90, 248, 90, 90, 90, 255, 90, 90, 90, 255, 91, 91, 91, 118, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 119, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 248, 93, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 170, 170, 170, 3, 90, 90, 90, 200, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 200, 170, 170, 170, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 41, 90, 90, 90, 248, 90, 90, 90, 255, 90, 90, 90, 255, 91, 91, 91, 118, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 119, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 248, 93, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 170, 170, 170, 3, 90, 90, 90, 200, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 200, 170, 170, 170, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 93, 93, 41, 90, 90, 90, 248, 90, 90, 90, 255, 90, 90, 90, 255, 92, 92, 92, 75, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 116, 90, 90, 90, 255, 90, 90, 90, 255, 90, 90, 90, 71, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 90, 90, 90, 71, 92, 92, 92, 72, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0), "format": "RGBA8", @@ -28,7 +28,7 @@ data = { } [sub_resource type="ImageTexture" id="ImageTexture_2e128"] -image = SubResource("Image_jif7k") +image = SubResource("Image_urx76") [node name="MainPanel" type="MarginContainer"] anchors_preset = 15 @@ -69,6 +69,7 @@ text = "Show Generated Script" unique_name_in_owner = true layout_mode = 2 tooltip_text = "Delete Block Code" +disabled = true icon = SubResource("ImageTexture_mrr6q") [node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/ScriptVBox"] diff --git a/addons/block_code/ui/picker/categories/block_category_button.tscn b/addons/block_code/ui/picker/categories/block_category_button.tscn index 33210926..8009423b 100644 --- a/addons/block_code/ui/picker/categories/block_category_button.tscn +++ b/addons/block_code/ui/picker/categories/block_category_button.tscn @@ -9,7 +9,7 @@ corner_radius_top_right = 100 corner_radius_bottom_right = 100 corner_radius_bottom_left = 100 -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ousiv"] +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_dgecf"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fyk0j"] bg_color = Color(1, 1, 1, 0.196078) @@ -17,7 +17,7 @@ bg_color = Color(1, 1, 1, 0.196078) [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ha83k"] bg_color = Color(1, 1, 1, 0.392157) -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_dgecf"] +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ousiv"] [node name="BlockCategoryButton" type="MarginContainer"] custom_minimum_size = Vector2(150, 0) @@ -49,9 +49,9 @@ text = "Example" [node name="Button" type="Button" parent="."] layout_mode = 2 mouse_default_cursor_shape = 2 -theme_override_styles/normal = SubResource("StyleBoxEmpty_ousiv") +theme_override_styles/focus = SubResource("StyleBoxEmpty_dgecf") theme_override_styles/hover = SubResource("StyleBoxFlat_fyk0j") theme_override_styles/pressed = SubResource("StyleBoxFlat_ha83k") -theme_override_styles/focus = SubResource("StyleBoxEmpty_dgecf") +theme_override_styles/normal = SubResource("StyleBoxEmpty_ousiv") [connection signal="pressed" from="Button" to="." method="_on_button_pressed"] diff --git a/addons/block_code/ui/title_bar/title_bar.gd b/addons/block_code/ui/title_bar/title_bar.gd index f2dfc45c..5125fdaf 100644 --- a/addons/block_code/ui/title_bar/title_bar.gd +++ b/addons/block_code/ui/title_bar/title_bar.gd @@ -8,8 +8,6 @@ signal node_name_changed(node_name: String) @onready var _context := BlockEditorContext.get_default() @onready var _block_code_icon = load("res://addons/block_code/block_code_node/block_code_node.svg") as Texture2D -@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector() -@onready var _editor_selection: EditorSelection = EditorInterface.get_selection() @onready var _node_option_button: OptionButton = %NodeOptionButton @@ -34,7 +32,7 @@ func _on_context_changed(): func _update_node_option_button_items(): _node_option_button.clear() - var scene_root = EditorInterface.get_edited_scene_root() + var scene_root = EditorInterface.get_edited_scene_root() if Engine.is_editor_hint() else null if not scene_root: return @@ -61,6 +59,7 @@ func _get_block_script_index(block_script: BlockScriptSerialization) -> int: func _on_node_option_button_item_selected(index): + var _editor_selection := EditorInterface.get_selection() var block_code_node = _node_option_button.get_item_metadata(index) as BlockCode var parent_node = block_code_node.get_parent() as Node _editor_selection.clear() diff --git a/addons/block_code/ui/title_bar/title_bar.tscn b/addons/block_code/ui/title_bar/title_bar.tscn index 9b10be36..debeffd0 100644 --- a/addons/block_code/ui/title_bar/title_bar.tscn +++ b/addons/block_code/ui/title_bar/title_bar.tscn @@ -18,3 +18,4 @@ layout_mode = 2 unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 +disabled = true diff --git a/block_code_demo.gd b/block_code_demo.gd new file mode 100644 index 00000000..15009edc --- /dev/null +++ b/block_code_demo.gd @@ -0,0 +1,43 @@ +extends Control + +@onready var _context := BlockEditorContext.get_default() + +@onready var _block_code := %BlockCode + +@onready var MainPanel := %MainPanel + +func _ready() -> void: + if _block_code.block_script == null: + var new_block_script: BlockScriptSerialization = load("res://addons/block_code/serialization/default_block_script.tres").duplicate(true) + new_block_script.script_inherits = _block_code._get_custom_or_native_class(_block_code.get_parent()) + new_block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits) + _block_code.block_script = new_block_script + + + #_context.set_block_code_node.call_deferred(_block_code) + await get_tree().process_frame + MainPanel.switch_block_code_node(_block_code) + MainPanel.script_window_requested.connect(script_window_requested) + print("_block_code ", _block_code) + + var ShowScriptButton = MainPanel.get_node("%TitleBar").get_parent().get_node("ShowScriptButton") + ShowScriptButton.text = "Load Block Code" + +var showscriptwindowfirst = true +const ScriptWindow := preload("res://addons/block_code/ui/script_window/script_window.tscn") +func script_window_requested(scriptcontent): + if showscriptwindowfirst: + var script_window = ScriptWindow.instantiate() + script_window.script_content = scriptcontent + add_child(script_window) + await script_window.close_requested + script_window.queue_free() + script_window = null + + var block_code_parent = _block_code.get_parent() + var script := GDScript.new() + script.set_source_code(scriptcontent) + script.reload() + block_code_parent.set_script(script) + block_code_parent._ready() + block_code_parent.set_process(true) diff --git a/block_code_demo.tscn b/block_code_demo.tscn new file mode 100644 index 00000000..4dbf9847 --- /dev/null +++ b/block_code_demo.tscn @@ -0,0 +1,83 @@ +[gd_scene load_steps=13 format=3 uid="uid://d2sgdkbau3tfv"] + +[ext_resource type="PackedScene" uid="uid://bq37yla8ya707" path="res://addons/block_code/ui/main_panel.tscn" id="1_kvne0"] +[ext_resource type="Script" path="res://block_code_demo.gd" id="1_obq7i"] +[ext_resource type="Texture2D" uid="uid://dr8e0tvfxjy1f" path="res://icon.svg" id="2_liip2"] +[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="2_x7fcc"] +[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization_tree.gd" id="3_73e6f"] +[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="4_1yrvj"] +[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="5_bnd5w"] +[ext_resource type="Script" path="res://addons/block_code/code_generation/variable_definition.gd" id="6_h8s2d"] + +[sub_resource type="Resource" id="Resource_lqg8c"] +script = ExtResource("4_1yrvj") +name = &"print" +children = Array[ExtResource("4_1yrvj")]([]) +arguments = { +"text": "ffsdfsdfsdfsdf" +} + +[sub_resource type="Resource" id="Resource_1jtnx"] +script = ExtResource("4_1yrvj") +name = &"ready" +children = Array[ExtResource("4_1yrvj")]([SubResource("Resource_lqg8c")]) +arguments = {} + +[sub_resource type="Resource" id="Resource_l46eq"] +script = ExtResource("3_73e6f") +root = SubResource("Resource_1jtnx") +canvas_position = Vector2(100, 50) + +[sub_resource type="Resource" id="Resource_ho2y6"] +script = ExtResource("5_bnd5w") +script_inherits = "Sprite2D" +block_serialization_trees = Array[ExtResource("3_73e6f")]([SubResource("Resource_l46eq")]) +variables = Array[ExtResource("6_h8s2d")]([]) +generated_script = "extends Sprite2D + + +func _ready(): + print('ffsdfsdfsdfsdf') + +" +version = 0 + +[node name="BlockCodeDemo" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_obq7i") + +[node name="VSplitContainer" type="VSplitContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="SubViewportContainer" type="SubViewportContainer" parent="VSplitContainer"] +layout_mode = 2 +size_flags_vertical = 3 +stretch = true + +[node name="SubViewport" type="SubViewport" parent="VSplitContainer/SubViewportContainer"] +handle_input_locally = false +size = Vector2i(1152, 318) +render_target_update_mode = 4 + +[node name="Sprite2D" type="Sprite2D" parent="VSplitContainer/SubViewportContainer/SubViewport"] +position = Vector2(537, 188) +texture = ExtResource("2_liip2") + +[node name="BlockCode" type="Node" parent="VSplitContainer/SubViewportContainer/SubViewport/Sprite2D"] +unique_name_in_owner = true +script = ExtResource("2_x7fcc") +block_script = SubResource("Resource_ho2y6") + +[node name="MainPanel" parent="VSplitContainer" instance=ExtResource("1_kvne0")] +unique_name_in_owner = true +layout_mode = 2 diff --git a/project.godot b/project.godot index 4e23f05a..2bc61d72 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Block Coding Plugin" -run/main_scene="res://addons/block_code/examples/pong_game/pong_game.tscn" +run/main_scene="res://block_code_demo.tscn" config/features=PackedStringArray("4.3", "GL Compatibility") config/icon="res://icon.svg"