From 224c388915d81221b67e59dcb4a00eed2ccfd7cf Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sun, 24 Jan 2021 14:33:02 +1030 Subject: [PATCH] Refactor OptionPanel to use GUI signals for ease of modification --- OptionPanel.tscn | 31 +++++++++++++++++++++---------- scripts/OptionPanel.gd | 37 +++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/OptionPanel.tscn b/OptionPanel.tscn index 7291a3f..e215eba 100644 --- a/OptionPanel.tscn +++ b/OptionPanel.tscn @@ -3,21 +3,21 @@ [ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1] [ext_resource path="res://scripts/OptionPanel.gd" type="Script" id=2] -[sub_resource type="DynamicFont" id=4] +[sub_resource type="DynamicFont" id=1] outline_size = 1 outline_color = Color( 0, 0, 0, 1 ) font_data = ExtResource( 1 ) -[sub_resource type="Theme" id=5] -default_font = SubResource( 4 ) +[sub_resource type="Theme" id=2] +default_font = SubResource( 1 ) -[sub_resource type="DynamicFont" id=1] +[sub_resource type="DynamicFont" id=3] size = 24 outline_size = 1 outline_color = Color( 0, 0, 0, 1 ) font_data = ExtResource( 1 ) -[sub_resource type="GDScript" id=2] +[sub_resource type="GDScript" id=4] script/source = "extends Label var fps: float = 0.0 @@ -30,7 +30,7 @@ func _process(delta): update() " -[sub_resource type="GDScript" id=3] +[sub_resource type="GDScript" id=5] script/source = "extends Label var audio_latency: float = 0.0 @@ -51,7 +51,7 @@ margin_right = 269.0 margin_bottom = 234.0 size_flags_horizontal = 3 size_flags_vertical = 3 -theme = SubResource( 5 ) +theme = SubResource( 2 ) script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false @@ -60,9 +60,9 @@ __meta__ = { [node name="lbl_fps" type="Label" parent="."] margin_right = 281.0 margin_bottom = 34.0 -custom_fonts/font = SubResource( 1 ) +custom_fonts/font = SubResource( 3 ) text = "FPS: " -script = SubResource( 2 ) +script = SubResource( 4 ) __meta__ = { "_edit_use_anchors_": false } @@ -72,7 +72,7 @@ margin_top = 38.0 margin_right = 281.0 margin_bottom = 61.0 text = "Audio Latency: " -script = SubResource( 3 ) +script = SubResource( 5 ) __meta__ = { "_edit_use_anchors_": false } @@ -204,7 +204,18 @@ margin_left = 87.0 margin_right = 281.0 margin_bottom = 29.0 size_flags_horizontal = 3 +text = "Native" align = 1 +items = [ "Native", null, false, 0, null, "Romaji", null, false, 1, null, "English", null, false, 2, null ] +selected = 0 __meta__ = { "_edit_use_anchors_": false } + +[connection signal="toggled" from="HBoxContainer/btn_vsync" to="." method="_on_btn_vsync_toggled"] +[connection signal="toggled" from="HBoxContainer/btn_wakelock" to="." method="_on_btn_wakelock_toggled"] +[connection signal="value_changed" from="sl_SSX" to="." method="_on_sl_SSX_value_changed"] +[connection signal="value_changed" from="sl_SSY" to="." method="_on_sl_SSY_value_changed"] +[connection signal="value_changed" from="sl_screenfilter" to="." method="_on_sl_screenfilter_value_changed"] +[connection signal="value_changed" from="sl_volume" to="." method="_on_sl_volume_value_changed"] +[connection signal="item_selected" from="hbox_language/btn_language" to="." method="_on_btn_language_item_selected"] diff --git a/scripts/OptionPanel.gd b/scripts/OptionPanel.gd index 6872211..5aa7c39 100644 --- a/scripts/OptionPanel.gd +++ b/scripts/OptionPanel.gd @@ -1,25 +1,22 @@ extends VBoxContainer -export var btn_language: NodePath = @"hbox_language/btn_language" -onready var BtnLanguage = get_node(btn_language) -func _ready() -> void: - $HBoxContainer/btn_vsync.connect('toggled', OS, 'set_use_vsync') - $HBoxContainer/btn_wakelock.connect('toggled', OS, 'set_keep_screen_on') # This is waiting on godotengine/godot#35536 to be merged to do anything in Linux :( - $sl_screenfilter.connect('value_changed', self, 'update_filter') - $sl_volume.connect('value_changed', self, 'update_volume') - $sl_SSX.connect('value_changed', Settings, 'SSX_set') - $sl_SSY.connect('value_changed', Settings, 'SSY_set') - BtnLanguage.add_item('Native') - BtnLanguage.add_item('Romaji') - BtnLanguage.add_item('English') - BtnLanguage.connect('item_selected', self, 'update_display_language') +func _on_btn_vsync_toggled(button_pressed: bool) -> void: + OS.set_use_vsync(button_pressed) +func _on_btn_wakelock_toggled(button_pressed: bool) -> void: + OS.set_keep_screen_on(button_pressed) # This is waiting on godotengine/godot#35536 to be merged to do anything in Linux :( -func update_filter(alpha: float): - GameTheme.screen_filter_min_alpha = alpha - -func update_volume(volume: float): - AudioServer.set_bus_volume_db(0, volume) - -func update_display_language(index: int): +func _on_btn_language_item_selected(index: int) -> void: GameTheme.display_language = ['n', 'tl', 'en'][index] + +func _on_sl_volume_value_changed(value: float) -> void: + AudioServer.set_bus_volume_db(0, value) + +func _on_sl_screenfilter_value_changed(value: float) -> void: + GameTheme.screen_filter_min_alpha = value + +func _on_sl_SSX_value_changed(value: float) -> void: + Settings.SSX_set(value) + +func _on_sl_SSY_value_changed(value: float) -> void: + Settings.SSY_set(value)