Skip to content

Commit a38351a

Browse files
authored
Settings: Add option to disable the input HUD (#2133)
Settings: Add option to disable the input HUD I wanted this for a slightly cleaner screenshot. Rather than duplicating the code from the fullscreen toggle, make the script more generic. It now toggles a named property on the Settings singleton. Use the existing fullscreen methods as the getter/setter of a new property, and add a new property for whether the input HUD is visible. Remove a stale signal connection from the video_settings scene - the target method does not exist.
1 parent ef05fce commit a38351a

6 files changed

Lines changed: 77 additions & 28 deletions

File tree

scenes/globals/settings/settings.gd

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const DEFAULT_VOLUMES: Dictionary[String, float] = {
1515
"Music": 0.5,
1616
}
1717

18+
const DISPLAY_SECTION := "Display"
19+
const SHOW_HUD_KEY := "Show HUD"
20+
1821
const LANGUAGE_SECTION := "Language"
1922
const LOCALE_KEY := "Locale"
2023
const DEFAULT_LOCALE := "en"
@@ -25,6 +28,17 @@ const MINIMUM_ASPECT_RATIO := 1.25
2528
## An arbitrary wide ratio, lower than 21:9 ("ultrawide").
2629
const MAXIMUM_ASPECT_RATIO := 2.2
2730

31+
@export var fullscreen: bool:
32+
get = is_fullscreen,
33+
set = set_fullscreen
34+
35+
@export var show_input_hud := true:
36+
get:
37+
return _settings.get_value(DISPLAY_SECTION, SHOW_HUD_KEY, true)
38+
set(new_value):
39+
_settings.set_value(DISPLAY_SECTION, SHOW_HUD_KEY, new_value)
40+
_save()
41+
2842
var _settings := ConfigFile.new()
2943

3044
var _overrides_path: String
@@ -99,7 +113,7 @@ func is_fullscreen() -> bool:
99113
return DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN
100114

101115

102-
func toggle_fullscreen(toggled_on: bool) -> void:
116+
func set_fullscreen(toggled_on: bool) -> void:
103117
if toggled_on:
104118
set_window_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
105119
else:

scenes/menus/options/components/fullscreen_toggle.gd

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-FileCopyrightText: The Threadbare Authors
2+
# SPDX-License-Identifier: MPL-2.0
3+
@tool
4+
extends CheckButton
5+
## A [CheckButton] that toggles a property of [Settings].
6+
7+
## The name of a property of the [Settings] singleton.
8+
@export var setting: StringName:
9+
set = set_setting
10+
11+
12+
func set_setting(new_value: StringName) -> void:
13+
setting = new_value
14+
update_configuration_warnings()
15+
16+
17+
func _get_configuration_warnings() -> PackedStringArray:
18+
var warnings: PackedStringArray
19+
20+
if not setting:
21+
warnings.append("Setting name is not set.")
22+
elif setting not in Settings:
23+
warnings.append("Settings singleton has no property named " + setting)
24+
25+
return warnings
26+
27+
28+
func _ready() -> void:
29+
if Engine.is_editor_hint():
30+
return
31+
32+
# There are two instances of this toggle in the game: one on the title screen, and
33+
# another in the pause overlay. At most one is displayed at a time, so we can keep them in
34+
# synch by reading the setting each time each toggle is displayed.
35+
visibility_changed.connect(_refresh)
36+
_refresh()
37+
38+
toggled.connect(_on_toggled)
39+
40+
41+
func _refresh() -> void:
42+
set_pressed_no_signal(Settings.get(setting))
43+
44+
45+
func _on_toggled(toggled_on: bool) -> void:
46+
Settings.set(setting, toggled_on)

scenes/menus/options/components/fullscreen_toggle.gd.uid renamed to scenes/menus/options/components/settings_toggle.gd.uid

File renamed without changes.

scenes/menus/options/components/video_settings.tscn

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[gd_scene format=3 uid="uid://tahf2q1d3e74"]
22

33
[ext_resource type="Theme" uid="uid://cvitou84ni7qe" path="res://scenes/ui_elements/components/theme.tres" id="1_qb52c"]
4-
[ext_resource type="Script" uid="uid://c63sfg6wgj2uy" path="res://scenes/menus/options/components/fullscreen_toggle.gd" id="2_qb52c"]
4+
[ext_resource type="Script" uid="uid://c63sfg6wgj2uy" path="res://scenes/menus/options/components/settings_toggle.gd" id="2_qb52c"]
55

66
[node name="VideoSettings" type="VBoxContainer" unique_id=1199621136]
77
offset_left = 96.0
@@ -21,12 +21,17 @@ text = "Video Settings"
2121

2222
[node name="GridContainer" type="GridContainer" parent="." unique_id=277212195]
2323
layout_mode = 2
24-
columns = 2
24+
theme_override_constants/v_separation = 0
2525

26-
[node name="CheckButton" type="CheckButton" parent="GridContainer" unique_id=409098937]
26+
[node name="ShowControlsButton" type="CheckButton" parent="GridContainer" unique_id=153771304]
27+
layout_mode = 2
28+
text = "Show Controls"
29+
script = ExtResource("2_qb52c")
30+
setting = &"show_input_hud"
31+
32+
[node name="FullscreenButton" type="CheckButton" parent="GridContainer" unique_id=409098937]
2733
layout_mode = 2
2834
size_flags_horizontal = 3
2935
text = "Fullscreen"
3036
script = ExtResource("2_qb52c")
31-
32-
[connection signal="toggled" from="GridContainer/CheckButton" to="." method="_on_check_button_toggled"]
37+
setting = &"fullscreen"

scenes/ui_elements/input_hints/components/input_hud.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ func _on_scene_changed() -> void:
6363

6464

6565
func _update_visibility() -> void:
66-
visible = not get_tree().paused and not Transitions.is_running() and (player or sokoban_ruleset)
66+
visible = (
67+
Settings.show_input_hud
68+
and not get_tree().paused
69+
and not Transitions.is_running()
70+
and (player or sokoban_ruleset)
71+
)
6772

6873

6974
func _notification(what: int) -> void:

0 commit comments

Comments
 (0)