can remove image and sounds in image and sound loader
This commit is contained in:
@@ -16,26 +16,26 @@ func _ready() -> void:
|
||||
var description_line: = description_line_class.instantiate()
|
||||
description_container.add_child(description_line)
|
||||
description_line.set_gp(res)
|
||||
|
||||
Database.db.query("SELECT * FROM Syllables")
|
||||
for res in Database.db.query_result:
|
||||
var description_line: = description_line_class.instantiate()
|
||||
description_container.add_child(description_line)
|
||||
res.Grapheme = res.Syllable
|
||||
res.Phoneme = ""
|
||||
description_line.set_gp(res)
|
||||
description_line.image_preview.hide()
|
||||
description_line.image_upload_button.hide()
|
||||
|
||||
Database.db.query("SELECT * FROM Words")
|
||||
for res in Database.db.query_result:
|
||||
var description_line: = description_line_class.instantiate()
|
||||
description_container.add_child(description_line)
|
||||
res.Grapheme = res.Word
|
||||
res.Phoneme = ""
|
||||
description_line.set_gp(res)
|
||||
description_line.image_preview.hide()
|
||||
description_line.image_upload_button.hide()
|
||||
#
|
||||
#Database.db.query("SELECT * FROM Syllables WHERE Syllables.Exception=0")
|
||||
#for res in Database.db.query_result:
|
||||
#var description_line: = description_line_class.instantiate()
|
||||
#description_container.add_child(description_line)
|
||||
#res.Grapheme = res.Syllable
|
||||
#res.Phoneme = ""
|
||||
#description_line.set_gp(res)
|
||||
#description_line.image_preview.hide()
|
||||
#description_line.image_upload_button.hide()
|
||||
#
|
||||
#Database.db.query("SELECT * FROM Words WHERE Words.Exception=0")
|
||||
#for res in Database.db.query_result:
|
||||
#var description_line: = description_line_class.instantiate()
|
||||
#description_container.add_child(description_line)
|
||||
#res.Grapheme = res.Word
|
||||
#res.Phoneme = ""
|
||||
#description_line.set_gp(res)
|
||||
#description_line.image_preview.hide()
|
||||
#description_line.image_upload_button.hide()
|
||||
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
|
||||
@@ -9,6 +9,8 @@ signal delete
|
||||
@onready var sound_upload_button: = %SoundUploadButton
|
||||
@onready var file_dialog: = $FileDialog
|
||||
@onready var sound_player: = $AudioStreamPlayer
|
||||
@onready var image_clear_button: = %ImageClearButton
|
||||
@onready var sound_clear_button: = %SoundClearButton
|
||||
|
||||
var gp: Dictionary
|
||||
|
||||
@@ -25,15 +27,31 @@ func _image_file_selected(file_path: String) -> void:
|
||||
|
||||
|
||||
func set_image_preview(img_path: String) -> void:
|
||||
var image: = Image.load_from_file(img_path)
|
||||
image_preview.texture = ImageTexture.create_from_image(image)
|
||||
if img_path.is_empty():
|
||||
image_clear_button.hide()
|
||||
image_upload_button.show()
|
||||
image_preview.texture = null
|
||||
else:
|
||||
var image: = Image.load_from_file(img_path)
|
||||
image_preview.texture = ImageTexture.create_from_image(image)
|
||||
image_clear_button.show()
|
||||
image_upload_button.hide()
|
||||
|
||||
|
||||
func set_sound_preview(sound_path: String) -> void:
|
||||
var file = FileAccess.open(sound_path, FileAccess.READ)
|
||||
var sound = AudioStreamMP3.new()
|
||||
sound.data = file.get_buffer(file.get_length())
|
||||
sound_player.stream = sound
|
||||
if sound_path.is_empty():
|
||||
sound_clear_button.hide()
|
||||
sound_upload_button.show()
|
||||
sound_player.stream = null
|
||||
sound_preview.hide()
|
||||
else:
|
||||
var file = FileAccess.open(sound_path, FileAccess.READ)
|
||||
var sound = AudioStreamMP3.new()
|
||||
sound.data = file.get_buffer(file.get_length())
|
||||
sound_player.stream = sound
|
||||
sound_clear_button.show()
|
||||
sound_upload_button.hide()
|
||||
sound_preview.show()
|
||||
|
||||
|
||||
func _sound_file_selected(file_path: String) -> void:
|
||||
@@ -55,6 +73,8 @@ func set_gp(value: Dictionary) -> void:
|
||||
var image_path: = Database.get_gp_look_and_learn_image_path(gp)
|
||||
if FileAccess.file_exists(image_path):
|
||||
set_image_preview(image_path)
|
||||
else:
|
||||
image_clear_button.hide()
|
||||
|
||||
var sound_path: = Database.get_gp_look_and_learn_sound_path(gp)
|
||||
if FileAccess.file_exists(sound_path):
|
||||
@@ -62,6 +82,7 @@ func set_gp(value: Dictionary) -> void:
|
||||
sound_preview.show()
|
||||
else:
|
||||
sound_preview.hide()
|
||||
sound_clear_button.hide()
|
||||
|
||||
|
||||
func _on_image_upload_button_pressed() -> void:
|
||||
@@ -97,3 +118,19 @@ func _on_button_pressed() -> void:
|
||||
func _on_sound_preview_pressed() -> void:
|
||||
if sound_player.stream:
|
||||
sound_player.play()
|
||||
|
||||
|
||||
func _on_image_clear_button_pressed():
|
||||
var current_file: = Database.get_gp_look_and_learn_image_path(gp)
|
||||
if FileAccess.file_exists(current_file):
|
||||
DirAccess.remove_absolute(current_file)
|
||||
|
||||
set_image_preview("")
|
||||
|
||||
|
||||
func _on_sound_clear_button_pressed():
|
||||
var current_file: = Database.get_gp_look_and_learn_sound_path(gp)
|
||||
if FileAccess.file_exists(current_file):
|
||||
DirAccess.remove_absolute(current_file)
|
||||
|
||||
set_sound_preview("")
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cfpx5q6dd2gq7"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cfpx5q6dd2gq7"]
|
||||
|
||||
[ext_resource type="Script" path="res://sources/language_tool/image_and_sound_gp_description.gd" id="1_rm4b8"]
|
||||
[ext_resource type="PackedScene" uid="uid://dbl3r8426473v" path="res://sources/language_tool/plus_button.tscn" id="1_uutsu"]
|
||||
[ext_resource type="Texture2D" uid="uid://5fffpm7hc12k" path="res://assets/menus/upload.png" id="2_0hqnp"]
|
||||
[ext_resource type="Texture2D" uid="uid://b8tctfnsj3prx" path="res://assets/menus/minus_button.png" id="3_q62yc"]
|
||||
|
||||
[node name="ImageAndSoundGPDescription" type="HBoxContainer"]
|
||||
offset_right = 2780.0
|
||||
offset_bottom = 240.0
|
||||
script = ExtResource("1_rm4b8")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
@@ -40,6 +43,13 @@ custom_minimum_size = Vector2(200, 100)
|
||||
layout_mode = 2
|
||||
expand_mode = 1
|
||||
|
||||
[node name="ImageClearButton" parent="ImageContainer/HBoxContainer" instance=ExtResource("1_uutsu")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TextureRect" parent="ImageContainer/HBoxContainer/ImageClearButton" index="0"]
|
||||
texture = ExtResource("3_q62yc")
|
||||
|
||||
[node name="ImageUploadButton" parent="ImageContainer/HBoxContainer" instance=ExtResource("1_uutsu")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
@@ -65,6 +75,13 @@ layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
text = "Play"
|
||||
|
||||
[node name="SoundClearButton" parent="MarginContainer3/HBoxContainer" instance=ExtResource("1_uutsu")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TextureRect" parent="MarginContainer3/HBoxContainer/SoundClearButton" index="0"]
|
||||
texture = ExtResource("3_q62yc")
|
||||
|
||||
[node name="SoundUploadButton" parent="MarginContainer3/HBoxContainer" instance=ExtResource("1_uutsu")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
@@ -84,9 +101,13 @@ access = 2
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[connection signal="pressed" from="ImageContainer/HBoxContainer/ImageClearButton" to="." method="_on_image_clear_button_pressed"]
|
||||
[connection signal="pressed" from="ImageContainer/HBoxContainer/ImageUploadButton" to="." method="_on_image_upload_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer3/HBoxContainer/SoundPreview" to="." method="_on_sound_preview_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer3/HBoxContainer/SoundClearButton" to="." method="_on_sound_clear_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer3/HBoxContainer/SoundUploadButton" to="." method="_on_sound_upload_button_pressed"]
|
||||
|
||||
[editable path="ImageContainer/HBoxContainer/ImageClearButton"]
|
||||
[editable path="ImageContainer/HBoxContainer/ImageUploadButton"]
|
||||
[editable path="MarginContainer3/HBoxContainer/SoundClearButton"]
|
||||
[editable path="MarginContainer3/HBoxContainer/SoundUploadButton"]
|
||||
|
||||
Reference in New Issue
Block a user