cambios
This commit is contained in:
BIN
game/ui/menus/options/flags/de.png
Normal file
BIN
game/ui/menus/options/flags/de.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
game/ui/menus/options/flags/en.png
Normal file
BIN
game/ui/menus/options/flags/en.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
BIN
game/ui/menus/options/flags/fr.png
Normal file
BIN
game/ui/menus/options/flags/fr.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
157
game/ui/menus/options/options.gd
Normal file
157
game/ui/menus/options/options.gd
Normal file
@@ -0,0 +1,157 @@
|
||||
# An options menu
|
||||
extends Control
|
||||
|
||||
|
||||
# The back button was pressed
|
||||
signal back_button_pressed
|
||||
|
||||
|
||||
# Custom setting key
|
||||
const CUSTOM_SETTING: String = "a_custom_setting"
|
||||
|
||||
|
||||
# The current settings
|
||||
var backup_settings
|
||||
|
||||
|
||||
# A list of languages already added to the language selection
|
||||
var _loaded_languages: Array = []
|
||||
|
||||
|
||||
# The settings changed
|
||||
onready var settings_changed = false
|
||||
|
||||
|
||||
# Initialize the flags
|
||||
func _ready() -> void:
|
||||
var _flags_container: HBoxContainer = \
|
||||
$VBoxContainer/MarginContainer/options/flags
|
||||
for child in _flags_container.get_children():
|
||||
_flags_container.remove_child(child)
|
||||
child.queue_free()
|
||||
|
||||
_loaded_languages = []
|
||||
|
||||
for lang in TranslationServer.get_loaded_locales():
|
||||
if not lang in _loaded_languages:
|
||||
_loaded_languages.append(lang)
|
||||
var _lang = TextureRect.new()
|
||||
_lang.texture = load(
|
||||
"res://addons/escoria-core/ui_library" + \
|
||||
"/menus/options/flags/%s.png" % lang
|
||||
)
|
||||
_flags_container.add_child(_lang)
|
||||
_lang.connect("gui_input", self, "_on_language_input", [lang])
|
||||
|
||||
|
||||
# Show the options
|
||||
func show():
|
||||
backup_settings = escoria.settings_manager.get_settings()
|
||||
initialize_options(backup_settings)
|
||||
visible = true
|
||||
|
||||
|
||||
# Set the sliders to the values of the settings
|
||||
#
|
||||
# #### Parameters
|
||||
# - p_settings: The settings to use
|
||||
func initialize_options(p_settings):
|
||||
var _options = $VBoxContainer/MarginContainer/options
|
||||
_options.get_node("general_volume").value = p_settings["master_volume"]
|
||||
_options.get_node("sound_volume").value = p_settings["sfx_volume"]
|
||||
_options.get_node("music_volume").value = p_settings["music_volume"]
|
||||
_options.get_node("speech_volume").value = p_settings["speech_volume"]
|
||||
|
||||
|
||||
# The language was changed
|
||||
#
|
||||
# #### Parameters
|
||||
# - event: The input event from the flag
|
||||
# - language: The language to set
|
||||
func _on_language_input(event: InputEvent, language: String):
|
||||
if event.is_pressed():
|
||||
TranslationServer.set_locale(language)
|
||||
ESCProjectSettingsManager.set_setting(
|
||||
ESCProjectSettingsManager.TEXT_LANG,
|
||||
language
|
||||
)
|
||||
settings_changed = true
|
||||
|
||||
|
||||
# Sound volume was changed
|
||||
#
|
||||
# #### Parameters
|
||||
# - value: The new volume level
|
||||
func _on_sound_volume_changed(value):
|
||||
if ESCProjectSettingsManager.get_setting(
|
||||
ESCProjectSettingsManager.SFX_VOLUME
|
||||
) != value:
|
||||
ESCProjectSettingsManager.set_setting(
|
||||
ESCProjectSettingsManager.SFX_VOLUME,
|
||||
value
|
||||
)
|
||||
escoria.settings_manager.apply_settings()
|
||||
settings_changed = true
|
||||
|
||||
|
||||
# Music volume was changed
|
||||
#
|
||||
# #### Parameters
|
||||
# - value: The new volume level
|
||||
func _on_music_volume_changed(value):
|
||||
if ESCProjectSettingsManager.get_setting(
|
||||
ESCProjectSettingsManager.MUSIC_VOLUME
|
||||
) != value:
|
||||
ESCProjectSettingsManager.set_setting(
|
||||
ESCProjectSettingsManager.MUSIC_VOLUME,
|
||||
value
|
||||
)
|
||||
escoria.settings_manager.apply_settings()
|
||||
settings_changed = true
|
||||
|
||||
|
||||
# General volume was changed
|
||||
#
|
||||
# #### Parameters
|
||||
# - value: The new volume level
|
||||
func _on_general_volume_changed(value):
|
||||
if ESCProjectSettingsManager.get_setting(
|
||||
ESCProjectSettingsManager.MASTER_VOLUME
|
||||
) != value:
|
||||
ESCProjectSettingsManager.set_setting(
|
||||
ESCProjectSettingsManager.MASTER_VOLUME,
|
||||
value
|
||||
)
|
||||
escoria.settings_manager.apply_settings()
|
||||
settings_changed = true
|
||||
|
||||
|
||||
# Speech volume was changed
|
||||
#
|
||||
# #### Parameters
|
||||
# - value: The new volume level
|
||||
func _on_speech_volume_value_changed(value: float) -> void:
|
||||
if ESCProjectSettingsManager.get_setting(
|
||||
ESCProjectSettingsManager.SPEECH_VOLUME
|
||||
) != value:
|
||||
ESCProjectSettingsManager.set_setting(
|
||||
ESCProjectSettingsManager.SPEECH_VOLUME,
|
||||
value
|
||||
)
|
||||
escoria.settings_manager.apply_settings()
|
||||
settings_changed = true
|
||||
|
||||
|
||||
# Save the settings
|
||||
func _on_apply_pressed():
|
||||
escoria.settings_manager.custom_settings[CUSTOM_SETTING] = 100
|
||||
escoria.settings_manager.save_settings()
|
||||
settings_changed = false
|
||||
emit_signal("back_button_pressed")
|
||||
|
||||
|
||||
# The back button was pressed
|
||||
func _on_back_pressed():
|
||||
escoria.settings_manager.save_settings_resource_to_project_settings(backup_settings)
|
||||
escoria.settings_manager.apply_settings()
|
||||
emit_signal("back_button_pressed")
|
||||
164
game/ui/menus/options/options.tscn
Normal file
164
game/ui/menus/options/options.tscn
Normal file
@@ -0,0 +1,164 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/ui_library/menus/options/flags/de.png" type="Texture" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/ui_library/menus/options/options.gd" type="Script" id=4]
|
||||
|
||||
[node name="options" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_editor_description_": ""
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||
margin_left = 391.0
|
||||
margin_top = 340.0
|
||||
margin_right = 888.0
|
||||
margin_bottom = 535.0
|
||||
size_flags_horizontal = 6
|
||||
custom_constants/margin_right = 20
|
||||
custom_constants/margin_top = 20
|
||||
custom_constants/margin_left = 20
|
||||
custom_constants/margin_bottom = 20
|
||||
|
||||
[node name="options" type="GridContainer" parent="VBoxContainer/MarginContainer"]
|
||||
margin_left = 20.0
|
||||
margin_top = 20.0
|
||||
margin_right = 477.0
|
||||
margin_bottom = 175.0
|
||||
size_flags_vertical = 6
|
||||
custom_constants/hseparation = 40
|
||||
columns = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="label" type="Label" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_top = 30.0
|
||||
margin_right = 137.0
|
||||
margin_bottom = 44.0
|
||||
text = "OPTIONS_LANGUAGE"
|
||||
|
||||
[node name="flags" type="HBoxContainer" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_left = 177.0
|
||||
margin_right = 457.0
|
||||
margin_bottom = 75.0
|
||||
size_flags_vertical = 3
|
||||
custom_constants/separation = 30
|
||||
alignment = 1
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="VBoxContainer/MarginContainer/options/flags"]
|
||||
margin_right = 125.0
|
||||
margin_bottom = 75.0
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="VBoxContainer/MarginContainer/options/flags"]
|
||||
margin_left = 155.0
|
||||
margin_right = 280.0
|
||||
margin_bottom = 75.0
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="label2" type="Label" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_top = 80.0
|
||||
margin_right = 137.0
|
||||
margin_bottom = 94.0
|
||||
text = "GENERAL_VOLUME"
|
||||
|
||||
[node name="general_volume" type="HSlider" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_left = 177.0
|
||||
margin_top = 79.0
|
||||
margin_right = 457.0
|
||||
margin_bottom = 95.0
|
||||
size_flags_horizontal = 3
|
||||
max_value = 1.0
|
||||
step = 0.001
|
||||
|
||||
[node name="label3" type="Label" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_top = 100.0
|
||||
margin_right = 137.0
|
||||
margin_bottom = 114.0
|
||||
text = "SOUND_VOLUME"
|
||||
|
||||
[node name="sound_volume" type="HSlider" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_left = 177.0
|
||||
margin_top = 99.0
|
||||
margin_right = 457.0
|
||||
margin_bottom = 115.0
|
||||
size_flags_horizontal = 3
|
||||
max_value = 1.0
|
||||
step = 0.001
|
||||
|
||||
[node name="label4" type="Label" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_top = 120.0
|
||||
margin_right = 137.0
|
||||
margin_bottom = 134.0
|
||||
text = "MUSIC_VOLUME"
|
||||
|
||||
[node name="music_volume" type="HSlider" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_left = 177.0
|
||||
margin_top = 119.0
|
||||
margin_right = 457.0
|
||||
margin_bottom = 135.0
|
||||
size_flags_horizontal = 3
|
||||
max_value = 1.0
|
||||
step = 0.001
|
||||
|
||||
[node name="label5" type="Label" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_top = 140.0
|
||||
margin_right = 137.0
|
||||
margin_bottom = 154.0
|
||||
text = "SPEECH_VOLUME"
|
||||
|
||||
[node name="speech_volume" type="HSlider" parent="VBoxContainer/MarginContainer/options"]
|
||||
margin_left = 177.0
|
||||
margin_top = 139.0
|
||||
margin_right = 457.0
|
||||
margin_bottom = 155.0
|
||||
size_flags_horizontal = 3
|
||||
max_value = 1.0
|
||||
step = 0.001
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 539.0
|
||||
margin_right = 1280.0
|
||||
margin_bottom = 559.0
|
||||
custom_constants/separation = 20
|
||||
alignment = 1
|
||||
|
||||
[node name="back" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 549.0
|
||||
margin_right = 660.0
|
||||
margin_bottom = 20.0
|
||||
text = "OPTIONS_BACK"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="apply" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 680.0
|
||||
margin_right = 731.0
|
||||
margin_bottom = 20.0
|
||||
text = "APPLY"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[connection signal="value_changed" from="VBoxContainer/MarginContainer/options/general_volume" to="." method="_on_general_volume_changed"]
|
||||
[connection signal="value_changed" from="VBoxContainer/MarginContainer/options/sound_volume" to="." method="_on_sound_volume_changed"]
|
||||
[connection signal="value_changed" from="VBoxContainer/MarginContainer/options/music_volume" to="." method="_on_music_volume_changed"]
|
||||
[connection signal="value_changed" from="VBoxContainer/MarginContainer/options/speech_volume" to="." method="_on_speech_volume_value_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/back" to="." method="_on_back_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/apply" to="." method="_on_apply_pressed"]
|
||||
Reference in New Issue
Block a user