Add setting true/false audio background in war level

This commit is contained in:
VAILLANT Jeremy
2021-05-23 21:21:10 +02:00
parent d2c6aef9c5
commit c46cb1f41e
11 changed files with 189 additions and 91 deletions
+26 -27
View File
@@ -3,18 +3,23 @@ extends Control
const TICKS_TIME_MAX = 100 # msec
onready var current_scene = null
onready var current_scene_int = null
onready var loader = null
onready var wait_frames = 1
onready var database = null
onready var table_settings = null
onready var data_settings = null
onready var table_levels = null
var msetting = preload("res://db/MSetting.gd")
var setting = null
func _ready():
print("[global#_ready]")
_initialize_current_scene()
_initialize_database()
_initialize_setting()
_initialize_current_scene()
func _initialize_setting():
print("global#_initialize_setting")
setting = msetting.new()
func goto_scene(path):
print("[global#goto_scene]")
@@ -28,11 +33,23 @@ func goto_scene(path):
wait_frames = 1
Loading.get_node("VBoxContainer/ProgressBar").set_max(loader.get_stage_count())
func gyroscope_enabled():
if _gyroscope_enabled():
return true
else:
return false
func get_setting_language():
return setting.get_langue()
func set_setting_language(value):
setting.set_langue(value)
func get_setting_gyrosocpe():
return setting.get_gyroscope()
func set_setting_gyroscope(value):
setting.set_gyroscope(value)
func get_setting_ambiant_sound():
return setting.get_ambiant_sound()
func set_setting_ambiant_sound(value):
setting.set_ambiant_sound(value)
func _process(_delta):
print("[global#_process]")
@@ -81,31 +98,13 @@ func _initialize_database():
OS.set_exit_code(1)
database = database_manager.get_db_by_id(db_id)
table_settings = database.get_table_by_name("settings")
data_settings = table_settings.get_data_at_row_idx(0)
table_levels = database.get_table_by_name("levels")
func _get_settings_data(name, index, table, datas):
var data = null
if table.get_prop_at(index).get_prop_name() == name:
data = datas[index].get_data()
return data
func _gyroscope_enabled():
for index in range(0, table_settings.get_props_count()):
_get_settings_data("gyroscope", index, table_settings, data_settings)
func _update_progress():
print("[global#update_progress]")
Loading.visible = true
Loading.get_node("VBoxContainer/ProgressBar").set_value(loader.get_stage())
func _set_new_scene():
print("[global#set_new_scene]")
var resource = loader.get_resource()
loader = null
current_scene = resource.instance()
+15 -28
View File
@@ -1,43 +1,30 @@
extends Node
onready var language_id = null
onready var gyroscope_id = null
func _ready():
print("[Settings#_ready]")
_translation()
_apply_settings()
_apply_settings_language()
_apply_settings_gyroscope()
_apply_settings_sound_ambiant()
## PRIVATE
func _translation():
print("[Settings#_translation]")
$VBoxContainer/Langue/HBoxContainer/Label.text = tr("SETTINGS_LABEL_LANGUE")
$VBoxContainer/gyroscope/HBoxContainer/Label.text = tr("SETTINGS_LABEL_GYROSCOPE")
func _apply_settings():
print("[Settings#_apply_settings]")
var lang = _get_settings_data("langue", Global.table_settings, Global.data_settings)
var gyro = _get_settings_data("gyroscope", Global.table_settings, Global.data_settings)
$VBoxContainer/Langue/HBoxContainer/data.set_text(lang)
$VBoxContainer/gyroscope/HBoxContainer/data.set_pressed(int(gyro) as bool)
func _apply_settings_language():
$VBoxContainer/Langue/HBoxContainer/data.set_text(Global.get_setting_language())
func _get_settings_data(name, table, datas):
for index in range(0, Global.table_settings.get_props_count()):
if table.get_prop_at(index).get_prop_name() == name:
_save_id(name, table.get_prop_at(index).get_prop_id())
return datas[index].get_data()
func _apply_settings_gyroscope():
$VBoxContainer/gyroscope/HBoxContainer/data.set_pressed(Global.get_setting_gyrosocpe())
func _save_id(name, id):
if name == "langue":
language_id = id
if name == "gyroscope":
gyroscope_id = id
func _apply_settings_sound_ambiant():
$VBoxContainer/ambiant_sound/HBoxContainer/data.set_pressed(Global.get_setting_ambiant_sound())
func _on_gyroscope_pressed():
print("[Settings#_on_gyroscop_toggled] change value to database ...........")
Global.table_settings.edit_data(gyroscope_id,
gddb_types.e_prop_type_bool,
int($CenterContainer/VBoxContainer/gyroscope/HBoxContainer/data.pressed) as String)
Global.database.save_db()
print("[Settings#_on_gyroscope_pressed] change value to database ...........")
Global.set_setting_gyroscope(int($VBoxContainer/gyroscope/HBoxContainer/data.pressed))
func _on_ambiant_sound_pressed():
print("[Settings#_on_ambiant_sound_pressed] change value to database ...........")
Global.set_setting_ambiant_sound(int($VBoxContainer/ambiant_sound/HBoxContainer/data.pressed))
+33 -9
View File
@@ -5,25 +5,27 @@
[node name="Settings" type="CenterContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -1.12244
margin_right = -1.12244
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 643.0
margin_top = 421.0
margin_right = 796.0
margin_bottom = 479.0
margin_left = 547.0
margin_top = 309.0
margin_right = 732.0
margin_bottom = 411.0
alignment = 1
[node name="Langue" type="CenterContainer" parent="VBoxContainer"]
margin_right = 153.0
margin_right = 185.0
margin_bottom = 14.0
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Langue"]
margin_left = 42.0
margin_right = 111.0
margin_left = 58.0
margin_right = 127.0
margin_bottom = 14.0
[node name="Label" type="Label" parent="VBoxContainer/Langue/HBoxContainer"]
@@ -42,11 +44,12 @@ __meta__ = {
[node name="gyroscope" type="CenterContainer" parent="VBoxContainer"]
margin_top = 18.0
margin_right = 153.0
margin_right = 185.0
margin_bottom = 58.0
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/gyroscope"]
margin_right = 153.0
margin_left = 16.0
margin_right = 169.0
margin_bottom = 40.0
[node name="Label" type="Label" parent="VBoxContainer/gyroscope/HBoxContainer"]
@@ -61,4 +64,25 @@ margin_right = 153.0
margin_bottom = 40.0
align = 1
[node name="ambiant_sound" type="CenterContainer" parent="VBoxContainer"]
margin_top = 62.0
margin_right = 185.0
margin_bottom = 102.0
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/ambiant_sound"]
margin_right = 185.0
margin_bottom = 40.0
[node name="Label" type="Label" parent="VBoxContainer/ambiant_sound/HBoxContainer"]
margin_top = 13.0
margin_right = 105.0
margin_bottom = 27.0
text = "Ambiant sound :"
[node name="data" type="CheckButton" parent="VBoxContainer/ambiant_sound/HBoxContainer"]
margin_left = 109.0
margin_right = 185.0
margin_bottom = 40.0
[connection signal="pressed" from="VBoxContainer/gyroscope/HBoxContainer/data" to="." method="_on_gyroscope_pressed"]
[connection signal="pressed" from="VBoxContainer/ambiant_sound/HBoxContainer/data" to="." method="_on_ambiant_sound_pressed"]
-4
View File
@@ -15,7 +15,6 @@ onready var mscene = load("res://db/MScene.gd")
func _ready():
_load_translations()
_play_ambiant_sound()
_load_meshes()
func _process(_delta):
@@ -145,6 +144,3 @@ func _check_collider(space_state):
var node = result["collider"].get_parent()
if node != null:
_start_dissolve(node.name)
func _play_ambiant_sound():
$AmbiantSound.play()
+9 -4
View File
@@ -8,6 +8,7 @@ onready var last_btn = null
func _ready():
_display_hud_menu()
_play_ambiant_sound()
func _display_hud_menu():
var counter = 0
@@ -22,21 +23,20 @@ func _display_hud_menu():
# Back to main scene
func _on_TextureButton_pressed():
print("[levels#_on_TextureButton_pressed] quit to menu")
Global.goto_scene("res://scenes/main.tscn")
func _create_button_info(scene, counter, label_id):
var btn = null
if counter == 0:
print("[warCraft#_create_button_info] ["+String(counter)+"] use first")
btn = object_first.instance()
#print("[warCraft#_create_button_info] ["+String(counter)+"] use first")
elif counter == meshes.size() - 1:
btn = object_last.instance()
print("[warCraft#_create_button_info] ["+String(counter)+"] use last")
#print("[warCraft#_create_button_info] ["+String(counter)+"] use last")
else:
btn = object_std.instance()
print("[warCraft#_create_button_info] ["+String(counter)+"] use standar")
#print("[warCraft#_create_button_info] ["+String(counter)+"] use standar")
if label_id != null and label_id == scene.label_id():
last_btn.get_node("Label").set_text(last_btn.get_node("Label").text + " X")
@@ -45,3 +45,8 @@ func _create_button_info(scene, counter, label_id):
btn.get_node("Label").set_text(scene.label())
last_btn = btn
func _play_ambiant_sound():
if Global.get_setting_ambiant_sound():
$AmbiantSound.play()
$AmbiantSound.stream_paused = false
+1 -1
View File
@@ -738,7 +738,7 @@ shape = SubResource( 17 )
[node name="AmbiantSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 46 )
volume_db = -15.0
autoplay = true
stream_paused = true
[connection signal="pressed" from="Quit/TextureButton" to="." method="_on_TextureButton_pressed"]
+49 -11
View File
@@ -82,35 +82,73 @@ __meta__ = {
}
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
margin_right = 1440.0
margin_bottom = 900.0
margin_right = 1280.0
margin_bottom = 720.0
[node name="UI_summary" parent="MarginContainer/HBoxContainer" instance=ExtResource( 8 )]
anchor_bottom = 0.0
margin_right = 446.0
margin_bottom = 900.0
margin_bottom = 720.0
size_flags_horizontal = 0
size_flags_vertical = 3
[node name="PanelWood" parent="MarginContainer/HBoxContainer/UI_summary" index="0"]
margin_bottom = 720.0
[node name="CenterContainer" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="0"]
margin_bottom = 147.0
[node name="TextureRect" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/CenterContainer" index="0"]
margin_top = 9.0
margin_bottom = 137.0
[node name="ButtonPuzzle" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="1"]
margin_top = 177.0
margin_bottom = 254.0
[node name="ButtonSetting" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="2"]
margin_top = 284.0
margin_bottom = 361.0
[node name="MarginContainer" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="3"]
margin_top = 391.0
margin_bottom = 539.0
[node name="ButtonQuit" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="4"]
margin_top = 569.0
margin_bottom = 646.0
[node name="LabelVersion" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="5"]
margin_top = 676.0
margin_bottom = 690.0
[node name="MarginContainerBottom" parent="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer" index="6"]
margin_top = 720.0
margin_bottom = 720.0
[node name="TextureRect" parent="MarginContainer/HBoxContainer/UI_summary" index="1"]
margin_bottom = 720.0
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer"]
margin_left = 450.0
margin_right = 1440.0
margin_bottom = 900.0
margin_right = 1280.0
margin_bottom = 720.0
size_flags_horizontal = 7
size_flags_vertical = 3
[node name="Title" parent="MarginContainer/HBoxContainer/MarginContainer" instance=ExtResource( 2 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 990.0
margin_bottom = 900.0
margin_right = 830.0
margin_bottom = 720.0
[node name="Settings" parent="MarginContainer/HBoxContainer/MarginContainer" instance=ExtResource( 4 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 990.0
margin_bottom = 900.0
margin_left = 0.0
margin_right = 830.0
margin_bottom = 720.0
[node name="ChooseScene" parent="MarginContainer/HBoxContainer/MarginContainer" instance=ExtResource( 3 )]
visible = false
@@ -118,8 +156,8 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 0.0
margin_top = 0.0
margin_right = 990.0
margin_bottom = 900.0
margin_right = 830.0
margin_bottom = 720.0
[connection signal="pressed" from="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/CenterContainer/TextureRect" to="." method="_on_TextureRect_pressed"]
[connection signal="pressed" from="MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonPuzzle" to="." method="_on_ButtonPuzzle_pressed"]