From 8e2fe8dac3db8f09fc5be1e95689b0d6baaa80e8 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 24 Jun 2020 00:25:54 +0300 Subject: [PATCH] Ability to import an image file as a pattern Also moved some pattern importing code from Import.gd to Global.create_pattern_button() --- src/Autoload/Global.gd | 11 +++++++++++ src/Autoload/Import.gd | 10 +--------- src/UI/Dialogs/PreviewDialog.gd | 17 +++++++++++++++++ src/UI/Dialogs/PreviewDialog.tscn | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index b2e49786e..5417721d3 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -611,6 +611,17 @@ func create_brush_button(brush_img : Image, brush_type := Brush_Types.CUSTOM, hi brush_container.add_child(brush_button) +func create_pattern_button(image : Image, hint_tooltip := "") -> void: + var pattern_button : BaseButton = load("res://src/UI/PatternButton.tscn").instance() + pattern_button.image = image + var pattern_tex := ImageTexture.new() + pattern_tex.create_from_image(image, 0) + pattern_button.get_child(0).texture = pattern_tex + pattern_button.hint_tooltip = hint_tooltip + pattern_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + patterns_popup.get_node("ScrollContainer/PatternContainer").add_child(pattern_button) + + func remove_brush_buttons() -> void: current_brush_types[0] = Brush_Types.PIXEL current_brush_types[1] = Brush_Types.PIXEL diff --git a/src/Autoload/Import.gd b/src/Autoload/Import.gd index 2bb80b432..12e1ff9ff 100644 --- a/src/Autoload/Import.gd +++ b/src/Autoload/Import.gd @@ -236,15 +236,7 @@ func import_patterns(priority_ordered_search_path: Array) -> void: if err == OK: image.convert(Image.FORMAT_RGBA8) Global.patterns.append(image) - - var pattern_button : BaseButton = load("res://src/UI/PatternButton.tscn").instance() - pattern_button.image = image - var pattern_tex := ImageTexture.new() - pattern_tex.create_from_image(image, 0) - pattern_button.get_child(0).texture = pattern_tex - pattern_button.hint_tooltip = pattern - pattern_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND - Global.patterns_popup.get_node("ScrollContainer/PatternContainer").add_child(pattern_button) + Global.create_pattern_button(image, pattern) if Global.patterns.size() > 0: var image_size = Global.patterns[0].get_size() diff --git a/src/UI/Dialogs/PreviewDialog.gd b/src/UI/Dialogs/PreviewDialog.gd index a53275e34..9ceec919a 100644 --- a/src/UI/Dialogs/PreviewDialog.gd +++ b/src/UI/Dialogs/PreviewDialog.gd @@ -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 diff --git a/src/UI/Dialogs/PreviewDialog.tscn b/src/UI/Dialogs/PreviewDialog.tscn index a1834c979..368594907 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, 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"]