diff --git a/addons/block_code/ui/block_canvas/block_canvas.gd b/addons/block_code/ui/block_canvas/block_canvas.gd index f2c086f8..7a083da6 100644 --- a/addons/block_code/ui/block_canvas/block_canvas.gd +++ b/addons/block_code/ui/block_canvas/block_canvas.gd @@ -33,9 +33,14 @@ const ZOOM_FACTOR: float = 1.1 @onready var _replace_block_code_button: Button = %ReplaceBlockCodeButton @onready var _open_scene_icon = _open_scene_button.get_theme_icon("Load", "EditorIcons") +@onready var _icon_zoom_out := EditorInterface.get_editor_theme().get_icon("ZoomLess", "EditorIcons") +@onready var _icon_zoom_in := EditorInterface.get_editor_theme().get_icon("ZoomMore", "EditorIcons") @onready var _mouse_override: Control = %MouseOverride +@onready var _zoom_buttons: HBoxContainer = %ZoomButtons +@onready var _zoom_out_button: Button = %ZoomOutButton @onready var _zoom_button: Button = %ZoomButton +@onready var _zoom_in_button: Button = %ZoomInButton var _current_block_script: BlockScriptSerialization var _current_ast_list: ASTList @@ -58,6 +63,10 @@ func _ready(): if not _open_scene_button.icon and not Util.node_is_part_of_edited_scene(self): _open_scene_button.icon = _open_scene_icon + if not _zoom_out_button.icon: + _zoom_out_button.icon = _icon_zoom_out + if not _zoom_in_button.icon: + _zoom_in_button.icon = _icon_zoom_in func _can_drop_data(at_position: Vector2, data: Variant) -> bool: @@ -140,7 +149,7 @@ func _on_context_changed(): zoom = 1 _window.visible = false - _zoom_button.visible = false + _zoom_buttons.visible = false _empty_box.visible = false _selected_node_box.visible = false @@ -152,7 +161,7 @@ func _on_context_changed(): if _context.block_script != null: _load_block_script(_context.block_script) _window.visible = true - _zoom_button.visible = true + _zoom_buttons.visible = true if _context.block_script != _current_block_script: reset_window_position() @@ -437,6 +446,16 @@ func generate_script_from_current_window() -> String: return ScriptGenerator.generate_script(_current_ast_list, _context.block_script) +func _on_zoom_out_button_pressed() -> void: + if zoom > 0.2: + zoom /= ZOOM_FACTOR + + func _on_zoom_button_pressed(): zoom = 1.0 reset_window_position() + + +func _on_zoom_in_button_pressed() -> void: + if zoom < 2: + zoom *= ZOOM_FACTOR diff --git a/addons/block_code/ui/block_canvas/block_canvas.tscn b/addons/block_code/ui/block_canvas/block_canvas.tscn index a7c47b59..4c0dac88 100644 --- a/addons/block_code/ui/block_canvas/block_canvas.tscn +++ b/addons/block_code/ui/block_canvas/block_canvas.tscn @@ -24,6 +24,7 @@ mouse_filter = 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,9 +61,31 @@ theme_override_constants/margin_top = 4 theme_override_constants/margin_right = 4 theme_override_constants/margin_bottom = 4 -[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer"] +[node name="ZoomButtons" type="HBoxContainer" parent="WindowContainer/Overlay/MarginContainer"] +unique_name_in_owner = true +visible = false +layout_mode = 2 + +[node name="ZoomOutButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"] +unique_name_in_owner = true +modulate = Color(1, 1, 1, 0.470588) +custom_minimum_size = Vector2(25, 0) +layout_mode = 2 +focus_mode = 0 +theme_override_font_sizes/font_size = 24 + +[node name="ZoomButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"] +unique_name_in_owner = true +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="ZoomInButton" type="Button" parent="WindowContainer/Overlay/MarginContainer/ZoomButtons"] unique_name_in_owner = true modulate = Color(1, 1, 1, 0.470588) +custom_minimum_size = Vector2(25, 0) layout_mode = 2 focus_mode = 0 theme_override_font_sizes/font_size = 24 @@ -140,7 +163,9 @@ theme_type_variation = &"InspectorActionButton" text = "Override Block Code" icon = ExtResource("2_710vn") -[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButton" to="." method="_on_zoom_button_pressed"] +[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomOutButton" to="." method="_on_zoom_out_button_pressed"] +[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomButton" to="." method="_on_zoom_button_pressed"] +[connection signal="pressed" from="WindowContainer/Overlay/MarginContainer/ZoomButtons/ZoomInButton" to="." method="_on_zoom_in_button_pressed"] [connection signal="pressed" from="SelectedNodeBox/ButtonsBox/AddBlockCodeButton" to="." method="_on_add_block_code_button_pressed"] [connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/OpenSceneButton" to="." method="_on_open_scene_button_pressed"] [connection signal="pressed" from="SelectedNodeWithBlockCodeBox/ButtonsBox/ReplaceBlockCodeButton" to="." method="_on_replace_block_code_button_pressed"]