-
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
6 changed files
with
234 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Godot; | ||
|
||
namespace Game.Autoload; | ||
|
||
public partial class OptionsHelper : Node | ||
{ | ||
public static void SetBusVolumePercent(string busName, float volumePercent) | ||
{ | ||
var busIndex = AudioServer.GetBusIndex(busName); | ||
AudioServer.SetBusVolumeDb(busIndex, Mathf.LinearToDb(volumePercent)); | ||
} | ||
|
||
public static float GetBusVolumePercent(string busName) | ||
{ | ||
var busIndex = AudioServer.GetBusIndex(busName); | ||
return Mathf.DbToLinear(AudioServer.GetBusVolumeDb(busIndex)); | ||
} | ||
|
||
public static void ToggleWindowMode() | ||
{ | ||
DisplayServer.WindowSetMode( | ||
IsFullscreen() | ||
? DisplayServer.WindowMode.Windowed | ||
: DisplayServer.WindowMode.ExclusiveFullscreen | ||
); | ||
} | ||
|
||
public static bool IsFullscreen() | ||
{ | ||
return DisplayServer.WindowGetMode() == DisplayServer.WindowMode.ExclusiveFullscreen; | ||
} | ||
} |
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,6 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://ksnmqy1k41ki"] | ||
|
||
[ext_resource type="Script" path="res://scenes/autoload/OptionsHelper.cs" id="1_uklwt"] | ||
|
||
[node name="OptionsHelper" type="Node"] | ||
script = ExtResource("1_uklwt") |
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,74 @@ | ||
using Game.Autoload; | ||
using Godot; | ||
|
||
namespace Game.UI; | ||
|
||
public partial class OptionsMenu : CanvasLayer | ||
{ | ||
private const string SFX_BUS = "SFX"; | ||
private const string MUSIC_BUS = "Music"; | ||
private Button sfxUpButton; | ||
private Button sfxDownButton; | ||
private Label sfxLabel; | ||
|
||
private Button musicUpButton; | ||
private Button musicDownButton; | ||
private Label musicLabel; | ||
|
||
private Button windowButton; | ||
private Button doneButton; | ||
|
||
public override void _Ready() | ||
{ | ||
sfxUpButton = GetNode<Button>("%SFXUpButton"); | ||
sfxDownButton = GetNode<Button>("%SFXDownButton"); | ||
sfxLabel = GetNode<Label>("%SFXLabel"); | ||
|
||
musicUpButton = GetNode<Button>("%MusicUpButton"); | ||
musicDownButton = GetNode<Button>("%MusicDownButton"); | ||
musicLabel = GetNode<Label>("%MusicLabel"); | ||
|
||
windowButton = GetNode<Button>("%WindowButton"); | ||
doneButton = GetNode<Button>("%DoneButton"); | ||
|
||
AudioHelpers.RegisterButtons( | ||
new Button[] | ||
{ | ||
sfxUpButton, | ||
sfxDownButton, | ||
musicUpButton, | ||
musicDownButton, | ||
windowButton, | ||
doneButton, | ||
} | ||
); | ||
UpdateDisplay(); | ||
|
||
sfxUpButton.Pressed += () => ChangeBusVolume(SFX_BUS, .1f); | ||
sfxDownButton.Pressed += () => ChangeBusVolume(SFX_BUS, -.1f); | ||
musicUpButton.Pressed += () => ChangeBusVolume(MUSIC_BUS, .1f); | ||
musicDownButton.Pressed += () => ChangeBusVolume(MUSIC_BUS, -.1f); | ||
windowButton.Pressed += () => | ||
{ | ||
OptionsHelper.ToggleWindowMode(); | ||
UpdateDisplay(); | ||
}; | ||
} | ||
|
||
public override void _Process(double delta) { } | ||
|
||
private void UpdateDisplay() | ||
{ | ||
sfxLabel.Text = Mathf.Round(OptionsHelper.GetBusVolumePercent(SFX_BUS) * 10).ToString(); | ||
musicLabel.Text = Mathf.Round(OptionsHelper.GetBusVolumePercent(MUSIC_BUS) * 10).ToString(); | ||
windowButton.Text = OptionsHelper.IsFullscreen() ? "Fullscreen" : "Windowed"; | ||
} | ||
|
||
private void ChangeBusVolume(string busName, float change) | ||
{ | ||
var busVolumePercent = OptionsHelper.GetBusVolumePercent(busName); | ||
busVolumePercent = Mathf.Clamp(busVolumePercent + change, 0, 1); | ||
OptionsHelper.SetBusVolumePercent(busName, busVolumePercent); | ||
UpdateDisplay(); | ||
} | ||
} |
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,119 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://b2pwlhr1ygp6j"] | ||
|
||
[ext_resource type="Script" path="res://scenes/ui/OptionsMenu.cs" id="1_455uv"] | ||
|
||
[node name="OptionsMenu" type="CanvasLayer"] | ||
script = ExtResource("1_455uv") | ||
|
||
[node name="MarginContainer" type="MarginContainer" parent="."] | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="PanelContainer" type="PanelContainer" parent="MarginContainer"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 4 | ||
size_flags_vertical = 4 | ||
|
||
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/PanelContainer"] | ||
layout_mode = 2 | ||
theme_override_constants/margin_left = 8 | ||
theme_override_constants/margin_top = 8 | ||
theme_override_constants/margin_right = 8 | ||
theme_override_constants/margin_bottom = 8 | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer"] | ||
layout_mode = 2 | ||
|
||
[node name="SFXContainer" type="PanelContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"PanelContainerAlternate" | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SFXContainer"] | ||
layout_mode = 2 | ||
theme_override_constants/separation = 64 | ||
|
||
[node name="Label" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SFXContainer/HBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"OptionLabel" | ||
text = "SFX" | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SFXContainer/HBoxContainer"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 10 | ||
theme_override_constants/separation = 16 | ||
|
||
[node name="SFXDownButton" type="Button" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SFXContainer/HBoxContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "-" | ||
|
||
[node name="SFXLabel" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SFXContainer/HBoxContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
theme_type_variation = &"OptionLabel" | ||
text = "10" | ||
|
||
[node name="SFXUpButton" type="Button" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SFXContainer/HBoxContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "+" | ||
|
||
[node name="MusicContainer" type="PanelContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"PanelContainerAlternate" | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/MusicContainer"] | ||
layout_mode = 2 | ||
theme_override_constants/separation = 64 | ||
|
||
[node name="Label" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/MusicContainer/HBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"OptionLabel" | ||
text = "Music" | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/MusicContainer/HBoxContainer"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 10 | ||
theme_override_constants/separation = 16 | ||
|
||
[node name="MusicDownButton" type="Button" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/MusicContainer/HBoxContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "-" | ||
|
||
[node name="MusicLabel" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/MusicContainer/HBoxContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
theme_type_variation = &"OptionLabel" | ||
text = "10" | ||
|
||
[node name="MusicUpButton" type="Button" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/MusicContainer/HBoxContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "+" | ||
|
||
[node name="WindowContainer" type="PanelContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"PanelContainerAlternate" | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/WindowContainer"] | ||
layout_mode = 2 | ||
theme_override_constants/separation = 64 | ||
|
||
[node name="Label" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/WindowContainer/HBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"OptionLabel" | ||
text = "Window Mode" | ||
|
||
[node name="WindowButton" type="Button" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/WindowContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Fullscreen" | ||
|
||
[node name="DoneButton" type="Button" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Done" |