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
+1 -1
View File
@@ -1,4 +1,4 @@
extends Object
extends Node
var table = null
+48
View File
@@ -0,0 +1,48 @@
extends "res://db/MBase.gd"
var m_langue = { "id": null, "value": null }
var m_gyroscope = { "id": null, "value": null }
var m_ambiant_sound = { "id": null, "value": null }
const ROW = 0
func _init():
print("[MSetting#_ready]")
table = Global.database.get_table_by_name("settings")
var datas = table.get_data_at_row_idx(ROW)
m_langue = _get_data_info(datas, 0)
m_gyroscope = _get_data_info(datas, 1)
m_ambiant_sound = _get_data_info(datas, 2)
func _get_data_info(datas, id):
return {
"id": id,
"value": _get_data(datas, id)
}
func get_langue():
return m_langue["value"]
func get_gyroscope():
return int(m_gyroscope["value"]) as bool
func get_ambiant_sound():
print("[msetting#get_ambiant_sound] "+String(m_ambiant_sound))
return int(m_ambiant_sound["value"]) as bool
func set_langue(value):
m_langue["value"] = _set_data(value, m_langue["id"], gddb_types.e_prop_type_string)
return get_langue()
func set_gyroscope(value):
m_gyroscope["value"] = _set_data(value, m_gyroscope["id"], gddb_types.e_prop_type_bool)
return get_gyroscope()
func set_ambiant_sound(value):
print("[msetting#get_ambiant_sound] save new value of mabiant sound")
m_ambiant_sound["value"] = _set_data(value, m_ambiant_sound["id"], gddb_types.e_prop_type_bool)
return get_ambiant_sound()
+4 -3
View File
@@ -6,9 +6,10 @@
"table_name":"settings",
"props":[
{"name":"langue","type":"3","auto_increment":"0"},
{"name":"gyroscope","type":"0","auto_increment":"0"}
{"name":"gyroscope","type":"0","auto_increment":"0"},
{"name":"ambiant_sound","type":"0","auto_increment":"0"}
],
"data":["fr","0"]
"data":["fr","0","0"]
},
{
"table_name":"levels",
@@ -30,7 +31,7 @@
{"name":"mesh","type":"3","auto_increment":"0"},
{"name":"label_id","type":"1","auto_increment":"0"}
],
"data":["0.0","True","Dagger","0","dagger","0","dagger","0","0.0","0","Fiole","0","fiole1","0","fioles/fiole1","1","0.0","0","Fiole","0","fiole2","0","fioles/fiole2","1","0.0","0","Fiole","0","fiole3","0","fioles/fiole_socle/fiole3","1","0.0","0","Spyglass","0","spyglass","0","spyglass","2","0.0","0","Coins","0","coin1","0","golds/coin1","3","0.0","0","Coins","0","coin2","0","golds/coin2","3","0.0","0","Coins","0","coin3","0","golds/coin3","3","0.0","0","Weapon Gun","0","weapon","0","weapon","4","0.0","0","Apple","0","apple1","0","apples/apple1","5","0.0","0","Apple","0","apple2","0","apples/apple2","5","0.0","0","Apple","0","apple3","0","apples/apple3","5","0.0","0","Apple","0","apple4","0","apples/apple4","5","0.0","0","Beer","0","beer","0","beer","6","0.0","0","SuperDagger","0","gadder","1","sm_super_dager","0"]
"data":["0.0","True","Dagger","0","dagger","0","dagger","0","0.0","0","Fiole","197246","fiole1","0","fioles/fiole1","1","0.97","0","Fiole","0","fiole2","0","fioles/fiole2","1","0.0","0","Fiole","0","fiole3","0","fioles/fiole_socle/fiole3","1","0.0","0","Spyglass","0","spyglass","0","spyglass","2","0.0","0","Coins","0","coin1","0","golds/coin1","3","0.0","0","Coins","0","coin2","0","golds/coin2","3","0.0","0","Coins","0","coin3","0","golds/coin3","3","0.0","0","Weapon Gun","0","weapon","0","weapon","4","0.0","0","Apple","0","apple1","0","apples/apple1","5","0.0","0","Apple","0","apple2","0","apples/apple2","5","0.0","0","Apple","0","apple3","0","apples/apple3","5","0.0","0","Apple","0","apple4","0","apples/apple4","5","0.0","0","Beer","0","beer","0","beer","6","0.0","0","SuperDagger","0","gadder","1","sm_super_dager","0"]
}
]
}
+3 -3
View File
@@ -207,8 +207,8 @@ config/quit_on_go_back=false
[autoload]
Global="*res://scenes/Global.gd"
Loading="*res://scenes/UI/loading/Loading.tscn"
Global="*res://scenes/Global.gd"
gddb_constants="*res://addons/godot_db_manager/core/GDDBConstants.gd"
gddb_types="*res://addons/godot_db_manager/core/GDDBTypes.gd"
gddb_globals="*res://addons/godot_db_manager/core/GDDBGlobals.gd"
@@ -219,8 +219,8 @@ settings/stdout/print_fps=true
[display]
window/size/width=1440
window/size/height=900
window/size/width=1280
window/size/height=720
window/dpi/allow_hidpi=true
window/handheld/orientation="sensor_landscape"
window/stretch/mode="2d"
+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)
func _apply_settings_language():
$VBoxContainer/Langue/HBoxContainer/data.set_text(Global.get_setting_language())
$VBoxContainer/Langue/HBoxContainer/data.set_text(lang)
$VBoxContainer/gyroscope/HBoxContainer/data.set_pressed(int(gyro) as bool)
func _apply_settings_gyroscope():
$VBoxContainer/gyroscope/HBoxContainer/data.set_pressed(Global.get_setting_gyrosocpe())
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 _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"]