Various improvements
- Improved performance by only sending the file path to the debugger - By default, shutter window will queue free if not running in the Editor - Remember shutter window position - Do not remember camera roll
This commit is contained in:
1 parent
8d49e3035d
commit
7233a3ca4d
6 files changed
+129
-107
No files matched your search
@@ -16,22 +16,39 @@ signal burst_ended
|
||||
var _input_action: String
|
||||
|
||||
func _ready() -> void:
|
||||
var saved_position = _local_data.settings.load_value("misc", "ShutterWindowPosition")
|
||||
if saved_position:
|
||||
position = saved_position
|
||||
old_position = position
|
||||
var only_run_in_editor = _local_data.settings.load_value("misc", "OnlyRunInEditorCheckBox", true)
|
||||
|
||||
if only_run_in_editor and not OS.has_feature("editor"):
|
||||
queue_free()
|
||||
return
|
||||
|
||||
visible = _local_data.settings.load_value("misc", "ShowShutterCheckBox", true)
|
||||
_input_action = _local_data.settings.load_value("misc", "InputActionLineEdit", "")
|
||||
%ShutterButton.pressed.connect(take_burst)
|
||||
close_requested.connect(_on_close_requested)
|
||||
|
||||
|
||||
func _on_close_requested() -> void:
|
||||
hide()
|
||||
|
||||
var old_position : Vector2i
|
||||
func _input(event: InputEvent) -> void:
|
||||
if old_position != position:
|
||||
_local_data.settings.save("misc", "ShutterWindowPosition", position)
|
||||
old_position = position
|
||||
if not InputMap.has_action(_input_action):
|
||||
return
|
||||
if event.is_action_pressed(_input_action):
|
||||
take_burst()
|
||||
|
||||
|
||||
## Takes one or more screenshots (a burst) using settings specified in the Debugger panel
|
||||
func take_burst() -> void:
|
||||
var old_position = position
|
||||
_local_data.settings.load_config()
|
||||
burst_starting.emit()
|
||||
var pause_game = _local_data.settings.load_value("misc", "PausesGameCheckBox", true)
|
||||
@@ -46,7 +63,7 @@ func take_burst() -> void:
|
||||
if pause_game:
|
||||
tree.paused = true
|
||||
var prev_size = DisplayServer.window_get_size()
|
||||
var timestamp = Time.get_time_string_from_system()
|
||||
|
||||
|
||||
|
||||
# Take screenshots for each configured size
|
||||
@@ -59,24 +76,89 @@ func take_burst() -> void:
|
||||
TranslationServer.set_locale(locale)
|
||||
await get_tree().process_frame
|
||||
|
||||
_send_viewport_texture_to_debugger(timestamp, TranslationServer.get_locale())
|
||||
save_image()
|
||||
|
||||
TranslationServer.set_locale(previous_locale)
|
||||
DisplayServer.window_set_size(prev_size)
|
||||
|
||||
# Print clickable paths
|
||||
print_rich("[color=green][Screenshots] Done! (%s)[/color]" % timestamp)
|
||||
|
||||
tree.paused = game_was_paused
|
||||
visible = shutter_was_visible
|
||||
burst_ended.emit()
|
||||
position = old_position
|
||||
|
||||
func _send_viewport_texture_to_debugger(timestamp: String, locale: String) -> void:
|
||||
func save_image() -> void:
|
||||
var locale = TranslationServer.get_locale()
|
||||
var timestamp = Time.get_time_string_from_system()
|
||||
var play_shutter_sounds = _local_data.settings.load_value("misc", "ShutterSoundsCheckBox", true)
|
||||
# Save the screenshot
|
||||
var image = get_parent().get_viewport().get_texture().get_image()
|
||||
EngineDebugger.send_message("screenshot:take", [image.save_png_to_buffer(), timestamp, locale])
|
||||
image_captured.emit(image)
|
||||
|
||||
if play_shutter_sounds:
|
||||
%AudioStreamPlayer.play()
|
||||
var save_folder: String = _local_data.settings.load_value("misc", "PathLineEdit", "user://screenshots")
|
||||
var project_title = ProjectSettings.get_setting("application/config/name")
|
||||
var screenshot_size = image.get_size()
|
||||
|
||||
# Build the save path with optional subfolders
|
||||
var target_folder = save_folder
|
||||
if _local_data.settings.load_value("misc", "UseSubFoldersCheckBox", false):
|
||||
# Create subfolder structure: Project_timestamp/locale/resolution
|
||||
var timestamp_folder = "%s_%s" % [project_title, timestamp.replace(":", "-")]
|
||||
var locale_folder = locale
|
||||
var resolution_folder = "%dx%d" % [screenshot_size.x, screenshot_size.y]
|
||||
|
||||
target_folder = save_folder.path_join(timestamp_folder).path_join(locale_folder).path_join(resolution_folder)
|
||||
|
||||
# Ensure target folder exists
|
||||
if not DirAccess.dir_exists_absolute(target_folder):
|
||||
DirAccess.make_dir_recursive_absolute(target_folder)
|
||||
|
||||
var formats = {
|
||||
"PNGCheckBox": ["png", image.save_png, true],
|
||||
"JPGCheckBox": ["jpg", image.save_jpg, false],
|
||||
"WEBPCheckBox": ["webp", image.save_webp, false]
|
||||
}
|
||||
|
||||
for setting_key in formats:
|
||||
var default = formats[setting_key][2]
|
||||
if _local_data.settings.load_value("misc", setting_key, default):
|
||||
var extension = formats[setting_key][0]
|
||||
var save_method = formats[setting_key][1]
|
||||
|
||||
var filename: String
|
||||
if _local_data.settings.load_value("misc", "UseSubFoldersCheckBox", false):
|
||||
filename = "%s_%s" % [project_title, timestamp.replace(":", "-")]
|
||||
else:
|
||||
filename = "%s_%s_%s_%dx%d" % [project_title, timestamp.replace(":", "-"), locale, screenshot_size.x, screenshot_size.y]
|
||||
|
||||
var file_path = target_folder.path_join("%s.%s" % [filename, extension])
|
||||
|
||||
# Get unique filepath to avoid overwriting
|
||||
file_path = get_unique_filepath(file_path)
|
||||
|
||||
save_method.call(file_path)
|
||||
EngineDebugger.send_message("screenshot:taken", [file_path, timestamp, locale])
|
||||
|
||||
print_rich("[Screenshots] Saved at: [url=%s]%s[/url]" % [ProjectSettings.globalize_path(file_path.get_base_dir()), file_path])
|
||||
|
||||
print_rich("[color=green][Screenshots] Done! (%s)[/color]" % timestamp)
|
||||
|
||||
func get_unique_filepath(base_path: String) -> String:
|
||||
if not FileAccess.file_exists(base_path):
|
||||
return base_path
|
||||
|
||||
var dir = base_path.get_base_dir()
|
||||
var filename = base_path.get_file().get_basename()
|
||||
var extension = base_path.get_extension()
|
||||
|
||||
var counter = 1
|
||||
var new_path = "%s/%s_%d.%s" % [dir, filename, counter, extension]
|
||||
|
||||
while FileAccess.file_exists(new_path):
|
||||
counter += 1
|
||||
new_path = "%s/%s_%d.%s" % [dir, filename, counter, extension]
|
||||
|
||||
return new_path
|
||||
|
||||
Reference in new issue
Block a user