-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
304 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
extends CanvasLayer | ||
|
||
|
||
var options_scene = preload("res://scenes/ui/options_menu.tscn") | ||
|
||
|
||
func _ready(): | ||
%PlayButton.pressed.connect(on_play_pressed) | ||
%OptionsButton.pressed.connect(on_options_pressed) | ||
%QuitButton.pressed.connect(on_quit_pressed) | ||
|
||
|
||
func on_play_pressed(): | ||
get_tree().change_scene_to_file("res://scenes/main/main.tscn") | ||
|
||
|
||
func on_options_pressed(): | ||
var options_instance = options_scene.instantiate() as OptionsMenu | ||
add_child(options_instance) | ||
options_instance.back_pressed.connect(on_options_closed.bind(options_instance)) | ||
|
||
|
||
func on_quit_pressed(): | ||
get_tree().quit() | ||
|
||
|
||
func on_options_closed(options_instance: OptionsMenu): | ||
options_instance.queue_free() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
extends CanvasLayer | ||
class_name OptionsMenu | ||
|
||
signal back_pressed | ||
|
||
@onready var window_button: Button = %WindowButton | ||
@onready var music_slider: Slider = %MusicSlider | ||
@onready var sfx_slider: Slider = %SfxSlider | ||
@onready var back_button: Button = %BackButton | ||
|
||
|
||
func _ready(): | ||
back_button.pressed.connect(on_back_pressed) | ||
window_button.pressed.connect(on_window_button_pressed) | ||
music_slider.value_changed.connect(on_audio_slider_changed.bind("music")) | ||
sfx_slider.value_changed.connect(on_audio_slider_changed.bind("sfx")) | ||
update_display() | ||
|
||
|
||
func update_display(): | ||
match DisplayServer.window_get_mode(): | ||
DisplayServer.WINDOW_MODE_FULLSCREEN: | ||
window_button.text = "Fullscreen" | ||
_: | ||
window_button.text = "Windowed" | ||
music_slider.value = get_bus_volume_percent("music") | ||
sfx_slider.value = get_bus_volume_percent("sfx") | ||
|
||
|
||
func get_bus_volume_percent(bus_name: String): | ||
var bus_index = AudioServer.get_bus_index(bus_name) | ||
if bus_index == -1: | ||
# TODO: assert or warn | ||
return 0 | ||
var volume_db = AudioServer.get_bus_volume_db(bus_index) | ||
return db_to_linear(volume_db) | ||
|
||
|
||
func set_bus_volume_percent(bus_name: String, percent: float) -> void: | ||
var bus_index = AudioServer.get_bus_index(bus_name) | ||
if bus_index == -1: | ||
# TODO: assert or warn | ||
return | ||
var volume_db = linear_to_db(percent) | ||
AudioServer.set_bus_volume_db(bus_index, volume_db) | ||
|
||
|
||
func on_window_button_pressed(): | ||
var mode := DisplayServer.window_get_mode() | ||
if mode != DisplayServer.WINDOW_MODE_FULLSCREEN: | ||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) | ||
else: | ||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) | ||
|
||
update_display() | ||
|
||
|
||
func on_audio_slider_changed(value: float, bus_name: String): | ||
set_bus_volume_percent(bus_name, value) | ||
|
||
|
||
|
||
func on_back_pressed(): | ||
back_pressed.emit() |
Large diffs are not rendered by default.
Oops, something went wrong.