diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index 299b21d60..08d3fb589 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -354,6 +354,27 @@ func open_image_as_spritesheet(path : String, image : Image, horizontal : int, v set_new_tab(project, path) +func open_image_as_new_frame(image : Image, layer_index := 0) -> void: + var project = Global.current_project + image.crop(project.size.x, project.size.y) + + var frame := Frame.new() + for i in project.layers.size(): + if i == layer_index: + image.convert(Image.FORMAT_RGBA8) + image.lock() + frame.cels.append(Cel.new(image, 1)) + else: + var empty_image := Image.new() + empty_image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) + empty_image.lock() + frame.cels.append(Cel.new(empty_image, 1)) + + project.frames.append(frame) + project.frames = project.frames # Just to call frames_changed() + project.current_frame = project.frames.size() - 1 + + func set_new_tab(project : Project, path : String) -> void: Global.tabs.current_tab = Global.tabs.get_tab_count() - 1 Global.canvas.camera_zoom() diff --git a/src/UI/Dialogs/PreviewDialog.gd b/src/UI/Dialogs/PreviewDialog.gd index 4972c8bc6..c2e017dfa 100644 --- a/src/UI/Dialogs/PreviewDialog.gd +++ b/src/UI/Dialogs/PreviewDialog.gd @@ -1,7 +1,7 @@ extends ConfirmationDialog -enum ImageImportOptions {NEW_TAB, SPRITESHEET, NEW_FRAME, NEW_LAYER, PALETTE} +enum ImageImportOptions {NEW_TAB, SPRITESHEET, NEW_FRAME, NEW_LAYER, PALETTE, BRUSH, PATTERN} var path : String var image : Image @@ -35,6 +35,8 @@ func _on_PreviewDialog_confirmed() -> void: OpenSave.open_image_as_new_tab(path, image) elif current_import_option == ImageImportOptions.SPRITESHEET: OpenSave.open_image_as_spritesheet(path, image, spritesheet_horizontal, spritesheet_vertical) + elif current_import_option == ImageImportOptions.NEW_FRAME: + OpenSave.open_image_as_new_frame(image) elif current_import_option == ImageImportOptions.PALETTE: Global.palette_container.on_palette_import_file_selected(path) diff --git a/src/UI/Dialogs/PreviewDialog.tscn b/src/UI/Dialogs/PreviewDialog.tscn index 720509031..995247455 100644 --- a/src/UI/Dialogs/PreviewDialog.tscn +++ b/src/UI/Dialogs/PreviewDialog.tscn @@ -64,7 +64,7 @@ margin_right = 151.0 margin_bottom = 20.0 mouse_default_cursor_shape = 2 text = "New tab" -items = [ "New tab", null, false, 0, null, "Spritesheet (new tab)", null, false, 1, null, "New frame", null, true, 2, null, "New layer", null, true, 3, null, "New palette", null, false, 4, null ] +items = [ "New tab", null, false, 0, null, "Spritesheet (new tab)", null, false, 1, null, "New frame", null, false, 2, null, "New layer", null, true, 3, null, "New palette", null, false, 4, null, "New brush", null, true, 5, null, "New pattern", null, true, 6, null ] selected = 0 [node name="SpritesheetOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]