Ability to import an image file as a pattern

Also moved some pattern importing code from Import.gd to Global.create_pattern_button()
This commit is contained in:
OverloadedOrama 2020-06-24 00:25:54 +03:00
parent a8de56ed68
commit 8e2fe8dac3
4 changed files with 30 additions and 10 deletions

View file

@ -35,18 +35,24 @@ func _on_PreviewDialog_popup_hide() -> void:
func _on_PreviewDialog_confirmed() -> void:
if current_import_option == ImageImportOptions.NEW_TAB:
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:
var layer_index : int = new_frame_options.get_node("AtLayerSpinbox").value
OpenSave.open_image_as_new_frame(image, layer_index)
elif current_import_option == ImageImportOptions.NEW_LAYER:
var frame_index : int = new_layer_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
elif current_import_option == ImageImportOptions.PALETTE:
Global.palette_container.on_palette_import_file_selected(path)
elif current_import_option == ImageImportOptions.BRUSH:
var file_name : String = path.get_basename().get_file()
image.convert(Image.FORMAT_RGBA8)
Global.file_brushes.append(image)
Global.create_brush_button(image, Global.Brush_Types.FILE, file_name)
@ -55,6 +61,17 @@ func _on_PreviewDialog_confirmed() -> void:
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
elif current_import_option == ImageImportOptions.PATTERN:
var file_name : String = path.get_basename().get_file()
image.convert(Image.FORMAT_RGBA8)
Global.patterns.append(image)
Global.create_pattern_button(image, file_name)
# Copy the image file into the "pixelorama/Patterns" directory
var location := "Patterns".plus_file(path.get_file())
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
func _on_ImportOption_item_selected(id : int) -> void:
current_import_option = id

View file

@ -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, false, 2, null, "New layer", null, false, 3, null, "New palette", null, false, 4, null, "New brush", null, false, 5, null, "New pattern", null, true, 6, null ]
items = [ "New tab", null, false, 0, null, "Spritesheet (new tab)", null, false, 1, null, "New frame", null, false, 2, null, "New layer", null, false, 3, null, "New palette", null, false, 4, null, "New brush", null, false, 5, null, "New pattern", null, false, 6, null ]
selected = 0
[node name="SpritesheetOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]