diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 5d13e999f..350201c00 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -216,6 +216,7 @@ onready var move_down_layer_button: BaseButton = animation_timeline.find_node("M onready var merge_down_layer_button: BaseButton = animation_timeline.find_node("MergeDownLayer") onready var layer_opacity_slider: ValueSlider = animation_timeline.find_node("OpacitySlider") +onready var tile_mode_offset_dialog: AcceptDialog = control.find_node("TileModeOffsetsDialog") onready var open_sprites_dialog: FileDialog = control.find_node("OpenSprite") onready var save_sprites_dialog: FileDialog = control.find_node("SaveSprite") onready var save_sprites_html5_dialog: ConfirmationDialog = control.find_node("SaveSpriteHTML5") diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 1a9aeaab8..59014f82e 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -260,6 +260,7 @@ func change_project() -> void: camera.emit_signal("rotation_changed") camera.emit_signal("zoom_changed") i += 1 + Global.tile_mode_offset_dialog.change_mask() func serialize() -> Dictionary: @@ -308,10 +309,6 @@ func serialize() -> Dictionary: for reference_image in reference_images: reference_image_data.append(reference_image.serialize()) - var tile_mask_data := { - "size_x": tiles.tile_mask.get_size().x, "size_y": tiles.tile_mask.get_size().y - } - var metadata := _serialize_metadata(self) var project_data := { @@ -319,8 +316,6 @@ func serialize() -> Dictionary: "name": name, "size_x": size.x, "size_y": size.y, - "has_mask": tiles.has_mask, - "tile_mask": tile_mask_data, "tile_mode_x_basis_x": tiles.x_basis.x, "tile_mode_x_basis_y": tiles.x_basis.y, "tile_mode_y_basis_x": tiles.y_basis.x, @@ -352,8 +347,6 @@ func deserialize(dict: Dictionary) -> void: size.y = dict.size_y tiles.tile_size = size selection_map.crop(size.x, size.y) - if dict.has("has_mask"): - tiles.has_mask = dict.has_mask if dict.has("tile_mode_x_basis_x") and dict.has("tile_mode_x_basis_y"): tiles.x_basis.x = dict.tile_mode_x_basis_x tiles.x_basis.y = dict.tile_mode_x_basis_y @@ -472,7 +465,7 @@ func _size_changed(value: Vector2) -> void: else: tiles.y_basis = Vector2(0, value.y) tiles.tile_size = value - tiles.reset_mask() + Global.tile_mode_offset_dialog.change_mask() size = value Global.canvas.crop_rect.reset() diff --git a/src/UI/Dialogs/TileModeOffsetsDialog.gd b/src/UI/Dialogs/TileModeOffsetsDialog.gd index afa072b20..9e5afe9de 100644 --- a/src/UI/Dialogs/TileModeOffsetsDialog.gd +++ b/src/UI/Dialogs/TileModeOffsetsDialog.gd @@ -6,9 +6,12 @@ onready var y_basis_x_spinbox: SpinBox = $VBoxContainer/HBoxContainer/OptionsCon onready var y_basis_y_spinbox: SpinBox = $VBoxContainer/HBoxContainer/OptionsContainer/YBasisY onready var preview_rect: Control = $VBoxContainer/AspectRatioContainer/Preview onready var tile_mode: Node2D = $VBoxContainer/AspectRatioContainer/Preview/TileMode -onready var load_button: Button = $VBoxContainer/HBoxContainer/Mask/LoadMask -onready var reset_mask: Button = $VBoxContainer/HBoxContainer/Mask/ResetMask -onready var mask_hint: TextureRect = $VBoxContainer/HBoxContainer/Mask/MaskHint + + +func _ready() -> void: + Global.connect("cel_changed", self, "change_mask") + yield(get_tree(), "idle_frame") + change_mask() func _on_TileModeOffsetsDialog_about_to_show() -> void: @@ -38,10 +41,6 @@ func _on_TileModeOffsetsDialog_about_to_show() -> void: $VBoxContainer/HBoxContainer/OptionsContainer/XBasisXLabel.visible = false $VBoxContainer/HBoxContainer/OptionsContainer/XBasisYLabel.visible = false - reset_mask.disabled = true - if Global.current_project.tiles.has_mask: - reset_mask.disabled = false - update_preview() @@ -97,11 +96,6 @@ func update_preview() -> void: tile_mode.update() preview_rect.get_node("TransparentChecker").rect_size = preview_rect.rect_size - # Also update the tile_mask preview - var tex := ImageTexture.new() - tex.create_from_image(Global.current_project.tiles.tile_mask) - mask_hint.texture = tex - func _on_TileModeOffsetsDialog_popup_hide() -> void: Global.dialog_open(false) @@ -123,7 +117,9 @@ func _on_Reset_pressed(): update_preview() -func _on_LoadMask_pressed() -> void: +func change_mask(): + if Global.current_project.tiles.mode == Tiles.MODE.NONE: + return var frame_idx = Global.current_project.current_frame var current_frame = Global.current_project.frames[frame_idx] var tiles = Global.current_project.tiles @@ -131,21 +127,19 @@ func _on_LoadMask_pressed() -> void: var image := Image.new() image.create(size.x, size.y, false, Image.FORMAT_RGBA8) Export.blend_all_layers(image, current_frame) - if image.get_used_rect().size == Vector2.ZERO: - reset_mask.disabled = true + if ( + image.get_used_rect().size == Vector2.ZERO + or not $VBoxContainer/HBoxContainer/Masking.pressed + ): tiles.reset_mask() else: load_mask(image) - update_preview() func load_mask(image: Image): - reset_mask.disabled = false Global.current_project.tiles.tile_mask = image Global.current_project.tiles.has_mask = true -func _on_ResetMask_pressed() -> void: - reset_mask.disabled = true - Global.current_project.tiles.reset_mask() - update_preview() +func _on_Masking_toggled(_button_pressed: bool) -> void: + change_mask() diff --git a/src/UI/Dialogs/TileModeOffsetsDialog.tscn b/src/UI/Dialogs/TileModeOffsetsDialog.tscn index 300adb391..391c38a95 100644 --- a/src/UI/Dialogs/TileModeOffsetsDialog.tscn +++ b/src/UI/Dialogs/TileModeOffsetsDialog.tscn @@ -29,11 +29,11 @@ text = "Tile Mode Offsets" [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] margin_top = 18.0 margin_right = 285.0 -margin_bottom = 174.0 +margin_bottom = 150.0 [node name="OptionsContainer" type="GridContainer" parent="VBoxContainer/HBoxContainer"] margin_right = 137.0 -margin_bottom = 156.0 +margin_bottom = 132.0 custom_constants/vseparation = 4 custom_constants/hseparation = 2 columns = 2 @@ -111,72 +111,25 @@ text = "Reset" [node name="VSeparator" type="VSeparator" parent="VBoxContainer/HBoxContainer"] margin_left = 141.0 margin_right = 145.0 -margin_bottom = 156.0 - -[node name="Mask" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"] -margin_left = 149.0 -margin_right = 285.0 -margin_bottom = 156.0 -size_flags_horizontal = 3 - -[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Mask"] -margin_right = 136.0 -margin_bottom = 14.0 -text = "Tile Mask" -align = 1 - -[node name="HSeparator" type="HSeparator" parent="VBoxContainer/HBoxContainer/Mask"] -margin_top = 18.0 -margin_right = 136.0 -margin_bottom = 22.0 - -[node name="MaskHint" type="TextureRect" parent="VBoxContainer/HBoxContainer/Mask"] -margin_top = 26.0 -margin_right = 136.0 -margin_bottom = 100.0 -rect_min_size = Vector2( 136, 74 ) -hint_tooltip = "Mask will only allow the drawing to remain within it's bounds -(Used for custom tiles)" -size_flags_vertical = 3 -expand = true -stretch_mode = 6 - -[node name="HSeparator2" type="HSeparator" parent="VBoxContainer/HBoxContainer/Mask"] -margin_top = 104.0 -margin_right = 136.0 -margin_bottom = 108.0 - -[node name="LoadMask" type="Button" parent="VBoxContainer/HBoxContainer/Mask"] -margin_top = 112.0 -margin_right = 136.0 margin_bottom = 132.0 -rect_min_size = Vector2( 100, 0 ) -hint_tooltip = "Create the Tile Mask from Current Frame" -mouse_default_cursor_shape = 2 -text = "Use Current Frame" -clip_text = true -[node name="ResetMask" type="Button" parent="VBoxContainer/HBoxContainer/Mask"] -margin_top = 136.0 -margin_right = 136.0 -margin_bottom = 156.0 -rect_min_size = Vector2( 100, 0 ) -hint_tooltip = "Create the Tile Mask from Current Frame" -mouse_default_cursor_shape = 2 -disabled = true -text = "Reset Mask" -clip_text = true +[node name="Masking" type="CheckButton" parent="VBoxContainer/HBoxContainer"] +margin_left = 149.0 +margin_right = 281.0 +margin_bottom = 40.0 +size_flags_vertical = 0 +text = "Masking" [node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"] -margin_top = 178.0 +margin_top = 154.0 margin_right = 285.0 margin_bottom = 378.0 size_flags_vertical = 3 [node name="Preview" type="Control" parent="VBoxContainer/AspectRatioContainer"] -margin_left = 42.5 -margin_right = 242.5 -margin_bottom = 200.0 +margin_left = 30.5 +margin_right = 254.5 +margin_bottom = 224.0 rect_min_size = Vector2( 200, 200 ) [node name="TileMode" type="Node2D" parent="VBoxContainer/AspectRatioContainer/Preview"] @@ -199,5 +152,4 @@ margin_bottom = 0.0 [connection signal="value_changed" from="VBoxContainer/HBoxContainer/OptionsContainer/YBasisX" to="." method="_on_YBasisX_value_changed"] [connection signal="value_changed" from="VBoxContainer/HBoxContainer/OptionsContainer/YBasisY" to="." method="_on_YBasisY_value_changed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/OptionsContainer/Reset" to="." method="_on_Reset_pressed"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Mask/LoadMask" to="." method="_on_LoadMask_pressed"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Mask/ResetMask" to="." method="_on_ResetMask_pressed"] +[connection signal="toggled" from="VBoxContainer/HBoxContainer/Masking" to="." method="_on_Masking_toggled"] diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index cf91005fe..90a5d16f9 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -483,6 +483,7 @@ func _tile_mode_submenu_id_pressed(id: int) -> void: Global.canvas.tile_mode.update() Global.canvas.pixel_grid.update() Global.canvas.grid.update() + Global.tile_mode_offset_dialog.change_mask() func _snap_to_submenu_id_pressed(id: int) -> void: