Skip to content

Commit

Permalink
Merge branch 'main' into main-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Maaack committed May 8, 2024
2 parents 79c1721 + c3e35b1 commit 9bda4aa
Show file tree
Hide file tree
Showing 59 changed files with 796 additions and 383 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ The `examples/` folder contains an example project using inherited scenes from t
- Loading Screen w/ Shader Pre-caching

### How it Works
- `AppConfig.tscn` is set as the first autoload. It loads all the configuration settings from the config file (if it exists).
- `AppConfig.tscn` is set as the first autoload. It calls `AppSettings.gd` to load all the configuration settings from the config file (if it exists) through `Config.gd`.
- `SceneLoader.tscn` is set as the second autoload. It can load scenes in the background or with a loading screen (`LoadingScreen.tscn` by default).
- `Opening.tscn` is a simple scene for fading in/out a few images at the start of the game. It then loads the next scene (`MainMenu.tscn`).
- `MainMenu.tscn` is where a player can start the game, change settings, watch credits, or quit. It can link to the path of a game scene to play, and the packed scene of an options menu to use.
- `OptionControl.tscn` and its inherited scenes are used for most configurable options in the menus. They work with `Config.gd` to keep settings persistent between runs.
- `Credits.tscn` reads from `ATTRIBUTION.md` to automatically generate the content for it's scrolling text label.
- The `UISoundController` node automatically attaches sounds to buttons, tab bars, sliders, and line edits in the scene. `ProjectUISoundController.tscn` is an autload used to apply UI sounds project-wide.
- `ProjectMusicController.tscn` is an autoload that keeps music playing between scenes. It detects music stream players as they are added to the scene tree, reparents them to itself, and blends the tracks.
Expand Down
3 changes: 2 additions & 1 deletion addons/maaacks_game_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ The `examples/` folder contains an example project using inherited scenes from t
- Loading Screen w/ Shader Pre-caching

### How it Works
- `AppConfig.tscn` is set as the first autoload. It loads all the configuration settings from the config file (if it exists).
- `AppConfig.tscn` is set as the first autoload. It calls `AppSettings.gd` to load all the configuration settings from the config file (if it exists) through `Config.gd`.
- `SceneLoader.tscn` is set as the second autoload. It can load scenes in the background or with a loading screen (`LoadingScreen.tscn` by default).
- `Opening.tscn` is a simple scene for fading in/out a few images at the start of the game. It then loads the next scene (`MainMenu.tscn`).
- `MainMenu.tscn` is where a player can start the game, change settings, watch credits, or quit. It can link to the path of a game scene to play, and the packed scene of an options menu to use.
- `OptionControl.tscn` and its inherited scenes are used for most configurable options in the menus. They work with `Config.gd` to keep settings persistent between runs.
- `Credits.tscn` reads from `ATTRIBUTION.md` to automatically generate the content for it's scrolling text label.
- The `UISoundController` node automatically attaches sounds to buttons, tab bars, sliders, and line edits in the scene. `ProjectUISoundController.tscn` is an autload used to apply UI sounds project-wide.
- `ProjectMusicController.tscn` is an autoload that keeps music playing between scenes. It detects music stream players as they are added to the scene tree, reparents them to itself, and blends the tracks.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ extends Control
@export var audio_control_scene : PackedScene
@export var hide_busses : Array[String]

@onready var mute_button = $VBoxContainer/MuteControl/MuteButton
@onready var mute_control = %MuteControl

func _on_bus_changed(bus_value : float, bus_name : String):
AppSettings.set_bus_volume_from_linear(bus_name, bus_value)

func _add_audio_control(bus_name, bus_value):
if audio_control_scene == null or bus_name in hide_busses:
return
var audio_control = audio_control_scene.instantiate()
audio_control.bus_name = bus_name
audio_control.bus_value = bus_value
%AudioControlContainer.call_deferred("add_child", audio_control)
audio_control.connect("bus_value_changed", AppSettings.set_bus_volume_from_linear)
if audio_control is OptionControl:
audio_control.option_section = OptionControl.OptionSections.AUDIO
audio_control.option_name = bus_name
audio_control.value = bus_value
audio_control.connect("setting_changed", _on_bus_changed.bind(bus_name))

func _add_audio_bus_controls():
for bus_iter in AudioServer.bus_count:
Expand All @@ -22,10 +27,10 @@ func _add_audio_bus_controls():

func _update_ui():
_add_audio_bus_controls()
mute_button.button_pressed = AppSettings.is_muted()
mute_control.value = AppSettings.is_muted()

func _ready():
_update_ui()

func _on_MuteButton_toggled(button_pressed):
AppSettings.set_mute(button_pressed)
func _on_mute_control_setting_changed(value):
AppSettings.set_mute(value)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://c8vnncjwqcpab"]
[gd_scene load_steps=5 format=3 uid="uid://c8vnncjwqcpab"]

[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Audio/AudioOptionsMenu.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://bosy6wwf0vleq" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Audio/AudioControl/AudioControl.tscn" id="2_0jh6g"]
[ext_resource type="PackedScene" uid="uid://cl416gdb1fgwr" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/OptionControl/SliderOptionControl.tscn" id="2_raehj"]
[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/CaptureFocus.gd" id="3_dtraq"]
[ext_resource type="PackedScene" uid="uid://bsxh6v7j0257h" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/OptionControl/ToggleOptionControl.tscn" id="4_ojfec"]

[node name="Audio" type="MarginContainer"]
custom_minimum_size = Vector2(305, 0)
Expand All @@ -14,7 +15,7 @@ grow_vertical = 2
theme_override_constants/margin_top = 24
theme_override_constants/margin_bottom = 24
script = ExtResource("1")
audio_control_scene = ExtResource("2_0jh6g")
audio_control_scene = ExtResource("2_raehj")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(400, 0)
Expand All @@ -30,16 +31,12 @@ unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 8

[node name="MuteControl" type="HBoxContainer" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 40)
layout_mode = 2

[node name="MuteLabel" type="Label" parent="VBoxContainer/MuteControl"]
layout_mode = 2
size_flags_horizontal = 3
text = "Mute :"

[node name="MuteButton" type="CheckButton" parent="VBoxContainer/MuteControl"]
[node name="MuteControl" parent="VBoxContainer" instance=ExtResource("4_ojfec")]
unique_name_in_owner = true
layout_mode = 2
option_name = "Mute"
option_section = 2
key = "Mute"
section = "AudioSettings"

[connection signal="toggled" from="VBoxContainer/MuteControl/MuteButton" to="." method="_on_MuteButton_toggled"]
[connection signal="setting_changed" from="VBoxContainer/MuteControl" to="." method="_on_mute_control_setting_changed"]
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ size_flags_horizontal = 4
theme_override_constants/separation = 8
script = ExtResource("2_wft4x")

[node name="Tree" type="Tree" parent="VBoxContainer"]
[node name="InputMappingContainer" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer/InputMappingContainer"]
layout_mode = 2
text = "Actions & Inputs"
horizontal_alignment = 1

[node name="Tree" type="Tree" parent="VBoxContainer/InputMappingContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
hide_root = true

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/InputMappingContainer"]
layout_mode = 2
alignment = 1

[node name="ResetButton" type="Button" parent="VBoxContainer/HBoxContainer"]
[node name="ResetButton" type="Button" parent="VBoxContainer/InputMappingContainer/HBoxContainer"]
layout_mode = 2
text = "Reset"

Expand All @@ -58,9 +67,9 @@ size = Vector2i(398, 100)
title = "Already Assigned"
size = Vector2i(398, 100)

[connection signal="button_clicked" from="VBoxContainer/Tree" to="." method="_on_tree_button_clicked"]
[connection signal="item_activated" from="VBoxContainer/Tree" to="." method="_on_tree_item_activated"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ResetButton" to="." method="_on_reset_button_pressed"]
[connection signal="button_clicked" from="VBoxContainer/InputMappingContainer/Tree" to="." method="_on_tree_button_clicked"]
[connection signal="item_activated" from="VBoxContainer/InputMappingContainer/Tree" to="." method="_on_tree_item_activated"]
[connection signal="pressed" from="VBoxContainer/InputMappingContainer/HBoxContainer/ResetButton" to="." method="_on_reset_button_pressed"]
[connection signal="canceled" from="KeyAssignmentDialog" to="." method="_on_key_assignment_dialog_canceled"]
[connection signal="confirmed" from="KeyAssignmentDialog" to="." method="_on_key_assignment_dialog_confirmed"]
[connection signal="confirmed" from="KeyDeletionDialog" to="." method="_on_key_deletion_dialog_confirmed"]
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
extends Control

@onready var mute_button = $MuteControl/MuteButton
@onready var fullscreen_button = $FullscreenControl/FullscreenButton
@onready var mute_control = %MuteControl
@onready var fullscreen_control = %FullscreenControl

@export var audio_control_scene : PackedScene
@export var hide_busses : Array[String]

func _on_bus_changed(bus_value : float, bus_name : String):
AppSettings.set_bus_volume_from_linear(bus_name, bus_value)

func _add_audio_control(bus_name, bus_value):
if audio_control_scene == null or bus_name in hide_busses:
return
var audio_control = audio_control_scene.instantiate()
audio_control.bus_name = bus_name
audio_control.bus_value = bus_value
%AudioControlContainer.call_deferred("add_child", audio_control)
audio_control.connect("bus_value_changed", AppSettings.set_bus_volume_from_linear)
if audio_control is OptionControl:
audio_control.option_section = OptionControl.OptionSections.AUDIO
audio_control.option_name = bus_name
audio_control.value = bus_value
audio_control.connect("setting_changed", _on_bus_changed.bind(bus_name))

func _add_audio_bus_controls():
for bus_iter in AudioServer.bus_count:
Expand All @@ -23,17 +28,17 @@ func _add_audio_bus_controls():

func _update_ui():
_add_audio_bus_controls()
mute_button.button_pressed = AppSettings.is_muted()
fullscreen_button.button_pressed = AppSettings.is_fullscreen(get_window())
mute_control.value = AppSettings.is_muted()
fullscreen_control.value = AppSettings.is_fullscreen(get_window())

func _sync_with_config() -> void:
_update_ui()

func _ready():
_sync_with_config()

func _on_mute_button_toggled(button_pressed):
AppSettings.set_mute(button_pressed)
func _on_mute_control_setting_changed(value):
AppSettings.set_mute(value)

func _on_fullscreen_button_toggled(button_pressed):
AppSettings.set_fullscreen_enabled(button_pressed, get_window())
func _on_fullscreen_control_setting_changed(value):
AppSettings.set_fullscreen_enabled(value, get_window())
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://vh1ucj2rfbby"]
[gd_scene load_steps=5 format=3 uid="uid://vh1ucj2rfbby"]

[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MiniOptionsMenu.gd" id="1_32vm2"]
[ext_resource type="PackedScene" uid="uid://bosy6wwf0vleq" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Audio/AudioControl/AudioControl.tscn" id="2_0006y"]
[ext_resource type="PackedScene" uid="uid://cl416gdb1fgwr" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/OptionControl/SliderOptionControl.tscn" id="2_kpc65"]
[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/CaptureFocus.gd" id="3_7qt1o"]
[ext_resource type="PackedScene" uid="uid://bsxh6v7j0257h" path="res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/OptionControl/ToggleOptionControl.tscn" id="4_b20fb"]

[node name="MiniOptionsMenu" type="VBoxContainer"]
custom_minimum_size = Vector2(400, 260)
Expand All @@ -21,7 +22,7 @@ size_flags_horizontal = 4
theme_override_constants/separation = 8
alignment = 1
script = ExtResource("1_32vm2")
audio_control_scene = ExtResource("2_0006y")
audio_control_scene = ExtResource("2_kpc65")

[node name="AudioControlContainer" type="VBoxContainer" parent="."]
unique_name_in_owner = true
Expand All @@ -30,29 +31,21 @@ theme_override_constants/separation = 8
script = ExtResource("3_7qt1o")
search_depth = 2

[node name="MuteControl" type="HBoxContainer" parent="."]
custom_minimum_size = Vector2(0, 40)
layout_mode = 2

[node name="MuteLabel" type="Label" parent="MuteControl"]
layout_mode = 2
size_flags_horizontal = 3
text = "Mute :"

[node name="MuteButton" type="CheckButton" parent="MuteControl"]
layout_mode = 2

[node name="FullscreenControl" type="HBoxContainer" parent="."]
custom_minimum_size = Vector2(0, 40)
layout_mode = 2

[node name="FullscreenLabel" type="Label" parent="FullscreenControl"]
[node name="MuteControl" parent="." instance=ExtResource("4_b20fb")]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Fullscreen :"
option_name = "Mute"
option_section = 2
key = "Mute"
section = "AudioSettings"

[node name="FullscreenButton" type="CheckButton" parent="FullscreenControl"]
[node name="FullscreenControl" parent="." instance=ExtResource("4_b20fb")]
unique_name_in_owner = true
layout_mode = 2
option_name = "Fullscreen"
option_section = 3
key = "FullscreenEnabled"
section = "VideoSettings"

[connection signal="toggled" from="MuteControl/MuteButton" to="." method="_on_mute_button_toggled"]
[connection signal="toggled" from="FullscreenControl/FullscreenButton" to="." method="_on_fullscreen_button_toggled"]
[connection signal="setting_changed" from="MuteControl" to="." method="_on_mute_control_setting_changed"]
[connection signal="setting_changed" from="FullscreenControl" to="." method="_on_fullscreen_control_setting_changed"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@tool
class_name ListOptionControl
extends OptionControl

@export var option_values : Array :
set(value) :
option_values = value
_on_option_values_changed()

@export var option_titles : Array[String] :
set(value):
option_titles = value
if is_inside_tree():
_set_option_list(option_titles)

@export var lock_titles : bool = false
var custom_option_values : Array

func _on_option_values_changed():
if option_values.is_empty(): return
custom_option_values = option_values.duplicate()
_set_titles_from_values()

func _on_setting_changed(value):
if value < option_values.size():
super._on_setting_changed(option_values[value])

func _set_titles_from_values():
if lock_titles: return
var mapped_titles : Array[String] = []
for option_value in custom_option_values:
mapped_titles.append(_value_title_map(option_value))
option_titles = mapped_titles

func _value_title_map(value : Variant) -> String:
return "%s" % value

func _match_value_to_other(value : Variant, other : Variant) -> Variant:
# Primarily for when the editor saves floats as ints instead
if value is int and other is float:
return float(value)
if value is float and other is int:
return int(round(value))
return value

func set_value(value : Variant):
if option_values.is_empty(): return
if value == null:
return super.set_value(-1)
custom_option_values = option_values.duplicate()
value = _match_value_to_other(value, custom_option_values.front())
if value not in custom_option_values:
custom_option_values.append(value)
custom_option_values.sort()
_set_titles_from_values()
if value not in option_values:
disable_option(custom_option_values.find(value))
value = custom_option_values.find(value)
super.set_value(value)

func _set_option_list(option_titles_list : Array):
%OptionButton.clear()
for option_title in option_titles_list:
%OptionButton.add_item(option_title)

func disable_option(option_index : int, disabled : bool = true):
%OptionButton.set_item_disabled(option_index, disabled)

func _ready():
option_titles = option_titles
option_values = option_values
super._ready()
Loading

0 comments on commit 9bda4aa

Please sign in to comment.