mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
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:
parent
a8de56ed68
commit
8e2fe8dac3
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]
|
||||
|
|
Loading…
Reference in a new issue