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 6e17ae1f..66e9afb5 100644 --- a/addons/block_code/ui/block_canvas/block_canvas.gd +++ b/addons/block_code/ui/block_canvas/block_canvas.gd @@ -98,7 +98,7 @@ func _on_context_changed(): 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/main_panel.gd b/addons/block_code/ui/main_panel.gd index f645b8ec..62ace701 100644 --- a/addons/block_code/ui/main_panel.gd +++ b/addons/block_code/ui/main_panel.gd @@ -60,6 +60,7 @@ 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) @@ -132,10 +133,7 @@ func save_script(): print("No script loaded to save.") return - if not Engine.is_editor_hint(): - 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})) @@ -146,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): @@ -278,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 cf8ea415..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_2p4as"] +[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_2p4as") +image = SubResource("Image_ao3hu") -[sub_resource type="Image" id="Image_talbb"] +[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_talbb") +image = SubResource("Image_urx76") [node name="MainPanel" type="MarginContainer"] anchors_preset = 15 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.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 index f06a943f..15009edc 100644 --- a/block_code_demo.gd +++ b/block_code_demo.gd @@ -4,10 +4,40 @@ extends Control @onready var _block_code := %BlockCode +@onready var MainPanel := %MainPanel func _ready() -> void: - #var block_script: BlockScriptSerialization = - #block_script.script_inherits = _get_custom_or_native_class(get_parent()) - #block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits) + 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) + + #_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 index f5c6ec92..4dbf9847 100644 --- a/block_code_demo.tscn +++ b/block_code_demo.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://d2sgdkbau3tfv"] +[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"] @@ -9,23 +9,37 @@ [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_oalom"] +[sub_resource type="Resource" id="Resource_lqg8c"] script = ExtResource("4_1yrvj") -name = &"ready" +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_8sqy5"] +[sub_resource type="Resource" id="Resource_l46eq"] script = ExtResource("3_73e6f") -root = SubResource("Resource_oalom") -canvas_position = Vector2(54, 47) +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_8sqy5")]) +block_serialization_trees = Array[ExtResource("3_73e6f")]([SubResource("Resource_l46eq")]) variables = Array[ExtResource("6_h8s2d")]([]) -generated_script = "extends Sprite2D" +generated_script = "extends Sprite2D + + +func _ready(): + print('ffsdfsdfsdfsdf') + +" version = 0 [node name="BlockCodeDemo" type="Control"] @@ -65,4 +79,5 @@ 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