add custom image picker

This commit is contained in:
Fabien Freling 2020-06-16 19:28:50 +02:00
parent 42fd81b914
commit e90eb40630
12 changed files with 310 additions and 43 deletions

View file

@ -88,22 +88,22 @@ func fade_out():
tween.interpolate_callback(self, fade_duration, "hide")
tween.start()
func flip_over():
func flip_over(new_panel: Panel) -> void:
tween.remove_all()
var mid_duration = flip_duration / 2.0
tween.interpolate_property(self, "rect_scale:x", 1.0, 0.0, mid_duration)
tween.interpolate_callback($Panel, mid_duration, "hide")
tween.interpolate_callback($EditPanel, mid_duration, "show")
tween.interpolate_callback(new_panel, mid_duration, "show")
tween.interpolate_property(self, "rect_scale:x", 0.0, 1.0, mid_duration, Tween.TRANS_LINEAR, Tween.EASE_IN, mid_duration)
tween.start()
func flip_back():
func flip_back(previous_panel: Panel) -> void:
_update_description()
tween.remove_all()
var mid_duration = flip_duration / 2.0
tween.interpolate_property(self, "rect_scale:x", 1.0, 0.0, mid_duration)
tween.interpolate_callback($Panel, mid_duration, "show")
tween.interpolate_callback($EditPanel, mid_duration, "hide")
tween.interpolate_callback(previous_panel, mid_duration, "hide")
tween.interpolate_property(self, "rect_scale:x", 0.0, 1.0, mid_duration, Tween.TRANS_LINEAR, Tween.EASE_IN, mid_duration)
tween.start()
@ -208,21 +208,18 @@ func _on_NewGamePanel_about_to_show():
# $Panel/Start.grab_focus()
fade_in()
func _on_Edit_pressed():
flip_over()
func _on_Edit_Cancel_pressed():
columns_spinbox.value = preferences.get_value("game", "custom_columns", normal_columns)
rows_spinbox.value = preferences.get_value("game", "custom_rows", normal_rows)
iterations_spinbox.value = preferences.get_value("game", "custom_shuffle_iterations", normal_iterations)
flip_back()
flip_back($EditPanel)
func _on_Edit_Save_pressed():
print_debug(columns_spinbox.value)
preferences.set_value("game", "custom_columns", columns_spinbox.value as int)
preferences.set_value("game", "custom_rows", rows_spinbox.value as int)
preferences.set_value("game", "custom_shuffle_iterations", iterations_spinbox.value as int)
flip_back()
flip_back($EditPanel)
func _on_Easy_pressed():
_update_description()
@ -235,10 +232,13 @@ func _on_Hard_pressed():
func _on_Custom_pressed():
_update_description()
flip_over()
flip_over($EditPanel)
func _on_LoadImage_pressed():
$FileDialog.popup_centered(rect_size)
flip_over($ImagePicker)
# if OS.get_name() == "Android":
# $FileDialog.current_dir = "/storage/emulated/0/"
# $FileDialog.popup_centered(rect_size)
func _on_FileDialog_file_selected(path: String):
var texture := load(path)
@ -256,3 +256,25 @@ func _on_FileDialog_file_selected(path: String):
_artwork_path = path
else:
_artwork_path = cached_artwork_path
func _on_FileDialog_dir_selected(dir):
print_debug("dir selected")
func _on_ImagePicker_file_selected(path):
print_debug(path)
var texture := load(path)
if texture == null:
print_debug("Cannot load image from path: ", path)
return
preview.texture = texture
var directory = Directory.new()
# TODO: remove previous artwork.png, artwork.jpg files
var cached_artwork_path := "user://artwork.%s" % [path.get_extension()]
var error = directory.copy(path, cached_artwork_path)
if error != OK:
print_debug("Cannot cache image")
_artwork_path = path
else:
_artwork_path = cached_artwork_path
flip_back($ImagePicker)