diff --git a/db/MBase.gd b/db/MBase.gd index 0018d15..01698ff 100644 --- a/db/MBase.gd +++ b/db/MBase.gd @@ -1,4 +1,4 @@ -extends Object +extends Node var table = null diff --git a/db/MSetting.gd b/db/MSetting.gd new file mode 100644 index 0000000..e9b4622 --- /dev/null +++ b/db/MSetting.gd @@ -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() diff --git a/db/ahog.json b/db/ahog.json index 40d994c..2a82739 100644 --- a/db/ahog.json +++ b/db/ahog.json @@ -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"] } ] } \ No newline at end of file diff --git a/project.godot b/project.godot index 2d2a104..eb6b279 100644 --- a/project.godot +++ b/project.godot @@ -177,8 +177,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" @@ -189,8 +189,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" diff --git a/scenes/Global.gd b/scenes/Global.gd index 5017c7e..834d8c5 100644 --- a/scenes/Global.gd +++ b/scenes/Global.gd @@ -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() diff --git a/scenes/UI/settings/Settings.gd b/scenes/UI/settings/Settings.gd index ec623d9..bdc64b9 100644 --- a/scenes/UI/settings/Settings.gd +++ b/scenes/UI/settings/Settings.gd @@ -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)) diff --git a/scenes/UI/settings/Settings.tscn b/scenes/UI/settings/Settings.tscn index e408589..e49c343 100644 --- a/scenes/UI/settings/Settings.tscn +++ b/scenes/UI/settings/Settings.tscn @@ -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"] diff --git a/scenes/levels/levels.gd b/scenes/levels/levels.gd index f1ebe1a..a344d1c 100644 --- a/scenes/levels/levels.gd +++ b/scenes/levels/levels.gd @@ -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() diff --git a/scenes/levels/warcraft/WarCraft.gd b/scenes/levels/warcraft/WarCraft.gd index d24944e..4b9c09e 100644 --- a/scenes/levels/warcraft/WarCraft.gd +++ b/scenes/levels/warcraft/WarCraft.gd @@ -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 diff --git a/scenes/levels/warcraft/WarCraft.tscn b/scenes/levels/warcraft/WarCraft.tscn index ba011f2..fc16e59 100644 --- a/scenes/levels/warcraft/WarCraft.tscn +++ b/scenes/levels/warcraft/WarCraft.tscn @@ -271,7 +271,7 @@ cell_center_y = false cell_center_z = false baked_meshes = [ SubResource( 4 ) ] data = { -"cells": PoolIntArray( 0, 0, 3, 65531, 0, 3, 65532, 0, 3, 65533, 0, 3, 65534, 0, 536870915, 65535, 0, -1610612733, 0, 1, 3, 65531, 1, 3, 65532, 1, 3, 65533, 1, 3, 65534, 1, 3, 65535, 1, 3, 0, 2, 3, 65531, 2, 3, 65532, 2, 3, 65533, 2, 3, 65534, 2, 3, 65535, 2, 3, 0, 65533, -1610612733, 65532, 65533, 3, 65533, 65533, 3, 65534, 65533, 3, 65535, 65533, 3, 0, 65534, 3, 65531, 65534, 3, 65532, 65534, 3, 65533, 65534, 3, 65534, 65534, 3, 65535, 65534, 3, 0, 65535, 3, 65531, 65535, 3, 65532, 65535, 3, 65533, 65535, 3, 65534, 65535, 3, 65535, 65535, 3 ) +"cells": PoolIntArray( 0, 0, 3, 65531, 0, 3, 65532, 0, -1073741821, 65533, 0, -536870909, 65534, 0, 3, 65535, 0, -1610612733, 0, 1, 3, 65531, 1, 3, 65532, 1, 3, 65533, 1, 3, 65534, 1, 3, 65535, 1, 3, 0, 2, 3, 65531, 2, 3, 65532, 2, 3, 65533, 2, 3, 65534, 2, 3, 65535, 2, 3, 0, 65533, 3, 65532, 65533, 3, 65533, 65533, 3, 65534, 65533, 3, 65535, 65533, 3, 0, 65534, 3, 65531, 65534, 3, 65532, 65534, 3, 65533, 65534, 3, 65534, 65534, 3, 65535, 65534, 3, 0, 65535, 3, 65531, 65535, 3, 65532, 65535, 3, 65533, 65535, 3, 65534, 65535, 3, 65535, 65535, 3 ) } __meta__ = { "_editor_clip_": 0, @@ -747,7 +747,7 @@ shape = SubResource( 18 ) [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"] diff --git a/scenes/main.tscn b/scenes/main.tscn index dbe1a8a..798a022 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -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"]