diff --git a/Autoload/Graphics.gd b/Autoload/Graphics.gd index c0053acd..cc00e0f5 100644 --- a/Autoload/Graphics.gd +++ b/Autoload/Graphics.gd @@ -5,8 +5,8 @@ func load_extra_images_from_harddrive(): var custom_images_dir = Settings.unearthdata.plus_file("custom-object-images") var image_paths = Utils.get_filetype_in_directory(custom_images_dir, "png") for image_path in image_paths: - var texture = load(image_path) - if texture is Texture: + var texture = Utils.load_external_texture(image_path) + if texture is ImageTexture: var image_name = image_path.get_file().get_basename().to_upper() sprite_id[image_name] = texture else: diff --git a/Autoload/Utils.gd b/Autoload/Utils.gd index b32ac0a2..59559e13 100644 --- a/Autoload/Utils.gd +++ b/Autoload/Utils.gd @@ -35,6 +35,13 @@ func string_has_letters(string): return true return false +func load_external_texture(path): + var img = Image.new() + img.load(path) + var texture = ImageTexture.new() + texture.create_from_image(img) + return texture + func get_filetype_in_directory(directory_path: String, file_extension: String) -> Array: var files = [] var directory = Directory.new() diff --git a/Scenes/TextureEditingWindow.gd b/Scenes/TextureEditingWindow.gd index a4b3440f..34b414e4 100644 --- a/Scenes/TextureEditingWindow.gd +++ b/Scenes/TextureEditingWindow.gd @@ -41,7 +41,6 @@ func _on_TextureEditingHelpButton_pressed(): var helptxt = "" helptxt += "After you load a tileset, a bunch of .PNG files will be saved to your hard drive. Edit these files in your favourite image editor.\n" helptxt += "Unearth will actively reload the textures in real-time as you edit and save those .PNGs. So any edits you make will be shown in real-time in Unearth. This applies to the 3D view too, so press Spacebar while in the 3D view to stop the camera from moving.\n" - helptxt += "Be aware that 'Load tileset' may overwrite your .PNGs, so be sure to press 'Save tileset' when you're done otherwise you could lose data.\n" oMessage.big("Help",helptxt) @@ -213,6 +212,9 @@ func _on_ExportTmapaDatDialog_file_selected(path): +var user_cancelled = false + + func _on_ChooseTmapaFileDialog_file_selected(path): var sourceImg = oTextureCache.convert_tmapa_to_image(path) if sourceImg == null: return @@ -232,7 +234,6 @@ func _on_ChooseTmapaFileDialog_file_selected(path): flContent = flContent.replace("textures_pack_number", "textures_pack_" + numberString) filelistFile.close() - var lineArray = Array(flContent.split('\n', false)) lineArray.pop_front() # For the array remove the first line: textures_pack_number 8 68 32 32 @@ -279,14 +280,33 @@ func _on_ChooseTmapaFileDialog_file_selected(path): # Save PNGs (separate loop so we're iterating once on each file, rather than every single filelist line) + var checkForExistingFolderOnce = 0 + var dir = Directory.new() for localPath in imageDictionary: var savePath = outputDir.plus_file(localPath) var packFolder = savePath.get_base_dir() + if dir.dir_exists(packFolder) == false: dir.make_dir_recursive(packFolder) + else: + if checkForExistingFolderOnce == 0: + var confirmDialog = ConfirmationDialog.new() + confirmDialog.dialog_text = "The folder of .PNGs already exists, they will be overwritten: \n" + packFolder + "\n\n If overwriting the files here causes you data loss then Cancel and go backup the folder." + confirmDialog.window_title = "Confirm File Replacement" + confirmDialog.popup_exclusive = true + confirmDialog.connect("confirmed", self, "_on_confirmation_confirmed") + confirmDialog.connect("popup_hide", self, "_on_confirmation_hide") + add_child(confirmDialog) + confirmDialog.popup_centered() + yield(confirmDialog, "visibility_changed") + yield(get_tree(),'idle_frame') + if user_cancelled == true: + return + + checkForExistingFolderOnce = 1 var createNewImage = imageDictionary[localPath] createNewImage.save_png(savePath) @@ -299,6 +319,14 @@ func _on_ChooseTmapaFileDialog_file_selected(path): save_new_filelist_txt_file(flContent, numberString, outputDir) # This goes after the "make_dir_recursive" commands print('Exported Filelist in: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms') +func _on_confirmation_confirmed(): + user_cancelled = false + +func _on_confirmation_hide(): + if not user_cancelled: + user_cancelled = true + + func save_new_filelist_txt_file(flContent, numberString, outputDir): var file = File.new() var path = outputDir.plus_file("filelist_tmapa"+numberString+".txt")