aboutsummaryrefslogtreecommitdiff
path: root/game/src/OptionMenu
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-03-22 17:56:24 +0100
committer GitHub <noreply@github.com>2023-03-22 17:56:24 +0100
commiteb87e2af53bd693e04739aaee84fde408e72f3a9 (patch)
treedf2d5211157f9222c3c7fc21888bea08411c8c9b /game/src/OptionMenu
parent540dddf46e80a91c77e465cbf6fdb81dd9977057 (diff)
Basic Game Session skeleton (#67)
* Fixed grab_focus error on not is_inside_tree * Moved SampleGame to GameSession/GameSession * Basic GameSession and GameSessionMenu/Escape Menu * Map Control Panel skeleton * Added requirement comments * Removed unnecessary CenterContainer
Diffstat (limited to 'game/src/OptionMenu')
-rw-r--r--game/src/OptionMenu/GeneralTab.gd5
-rw-r--r--game/src/OptionMenu/VideoTab.gd5
-rw-r--r--game/src/OptionMenu/VolumeGrid.gd8
3 files changed, 14 insertions, 4 deletions
diff --git a/game/src/OptionMenu/GeneralTab.gd b/game/src/OptionMenu/GeneralTab.gd
index 8aed783..3d98678 100644
--- a/game/src/OptionMenu/GeneralTab.gd
+++ b/game/src/OptionMenu/GeneralTab.gd
@@ -1,8 +1,9 @@
extends HBoxContainer
-@export var initial_focus: Button
+@export var initial_focus: Control
func _notification(what : int) -> void:
match(what):
NOTIFICATION_VISIBILITY_CHANGED:
- if visible: initial_focus.grab_focus()
+ if visible and is_inside_tree():
+ initial_focus.grab_focus()
diff --git a/game/src/OptionMenu/VideoTab.gd b/game/src/OptionMenu/VideoTab.gd
index 8aed783..3d98678 100644
--- a/game/src/OptionMenu/VideoTab.gd
+++ b/game/src/OptionMenu/VideoTab.gd
@@ -1,8 +1,9 @@
extends HBoxContainer
-@export var initial_focus: Button
+@export var initial_focus: Control
func _notification(what : int) -> void:
match(what):
NOTIFICATION_VISIBILITY_CHANGED:
- if visible: initial_focus.grab_focus()
+ if visible and is_inside_tree():
+ initial_focus.grab_focus()
diff --git a/game/src/OptionMenu/VolumeGrid.gd b/game/src/OptionMenu/VolumeGrid.gd
index 297de6f..5b1d13f 100644
--- a/game/src/OptionMenu/VolumeGrid.gd
+++ b/game/src/OptionMenu/VolumeGrid.gd
@@ -4,6 +4,8 @@ const RATIO_FOR_LINEAR : float = 100
var _slider_dictionary : Dictionary
+var initial_focus : Control
+
func get_db_as_volume_value(db : float) -> float:
# db_to_linear produces a float between 0 and 1 from a db value
return db_to_linear(db) * RATIO_FOR_LINEAR
@@ -29,6 +31,7 @@ func add_volume_row(bus_name : StringName, bus_index : int) -> HSlider:
add_child(volume_slider)
_slider_dictionary[volume_label.text] = volume_slider
+ if not initial_focus: initial_focus = volume_slider
return volume_slider
# REQUIREMENTS
@@ -37,6 +40,11 @@ func _ready():
for bus_index in AudioServer.bus_count:
add_volume_row(AudioServer.get_bus_name(bus_index), bus_index)
+func _notification(what : int) -> void:
+ match(what):
+ NOTIFICATION_VISIBILITY_CHANGED:
+ if visible and is_inside_tree() and initial_focus: initial_focus.grab_focus()
+
# REQUIREMENTS
# * UIFUN-30
func _on_slider_value_changed(value : float, bus_index : int) -> void: