diff --git a/addons/capri_tools/capri_tools.gd b/addons/capri_tools/capri_tools.gd new file mode 100644 index 0000000..5532114 --- /dev/null +++ b/addons/capri_tools/capri_tools.gd @@ -0,0 +1,17 @@ +@tool +extends EditorPlugin + + +const GlobalSoundSelectorPlugin = preload("global_sound_selector_plugin.gd") + + +var global_sound_selector_plugin: EditorInspectorPlugin + + +func _enter_tree() -> void: + global_sound_selector_plugin = GlobalSoundSelectorPlugin.new() + add_inspector_plugin(global_sound_selector_plugin) + + +func _exit_tree() -> void: + remove_inspector_plugin(global_sound_selector_plugin) diff --git a/addons/capri_tools/capri_tools.gd.uid b/addons/capri_tools/capri_tools.gd.uid new file mode 100644 index 0000000..cc84e25 --- /dev/null +++ b/addons/capri_tools/capri_tools.gd.uid @@ -0,0 +1 @@ +uid://b6rylu4028qec diff --git a/addons/capri_tools/global_sound_selector.gd b/addons/capri_tools/global_sound_selector.gd new file mode 100644 index 0000000..65fcd12 --- /dev/null +++ b/addons/capri_tools/global_sound_selector.gd @@ -0,0 +1,46 @@ +extends EditorProperty + + +var _dropdown_button := Button.new() + +var _popup_menu := PopupMenu.new() + + +func _init() -> void: + _dropdown_button.pressed.connect(_show_popup) + _dropdown_button.icon = EditorInterface.get_editor_theme().get_icon("AudioStreamPlayer", "EditorIcons") + + _popup_menu.index_pressed.connect(_on_sound_selected) + + add_child(_dropdown_button) + add_child(_popup_menu) + add_focusable(_dropdown_button) + + +func _update_property() -> void: + var new_value: StringName = get_edited_object()[get_edited_property()] + _dropdown_button.text = new_value.capitalize() + + +func _show_popup() -> void: + var sounds = GlobalSounds.sounds.keys() + + _popup_menu.clear() + for sound: StringName in sounds: + _popup_menu.add_icon_item( + EditorInterface.get_editor_theme().get_icon("AudioStreamPlayer", "EditorIcons"), + sound.capitalize() + ) + + var button_rect = _dropdown_button.get_global_rect() + _popup_menu.reset_size() + var popup_pos = button_rect.position + Vector2(DisplayServer.window_get_position()) + _popup_menu.position = popup_pos + _popup_menu.min_size.x = button_rect.size.x + _popup_menu.popup() + + +func _on_sound_selected(index: int) -> void: + var sound = GlobalSounds.sounds.keys()[index] + _dropdown_button.grab_focus() + emit_changed(get_edited_property(), sound) diff --git a/addons/capri_tools/global_sound_selector.gd.uid b/addons/capri_tools/global_sound_selector.gd.uid new file mode 100644 index 0000000..146a83e --- /dev/null +++ b/addons/capri_tools/global_sound_selector.gd.uid @@ -0,0 +1 @@ +uid://bwr5g1ae4dxs4 diff --git a/addons/capri_tools/global_sound_selector_plugin.gd b/addons/capri_tools/global_sound_selector_plugin.gd new file mode 100644 index 0000000..d963c34 --- /dev/null +++ b/addons/capri_tools/global_sound_selector_plugin.gd @@ -0,0 +1,16 @@ +extends EditorInspectorPlugin + + +const GlobalSoundSelector = preload("global_sound_selector.gd") + + +func _can_handle(object: Object) -> bool: + return true + + +func _parse_property(object: Object, type: Variant.Type, name: String, hint_type: PropertyHint, hint_string: String, usage_flags: int, wide: bool) -> bool: + if type == TYPE_STRING_NAME and hint_string == "global_sound": + add_property_editor(name, GlobalSoundSelector.new()) + return true + else: + return false diff --git a/addons/capri_tools/global_sound_selector_plugin.gd.uid b/addons/capri_tools/global_sound_selector_plugin.gd.uid new file mode 100644 index 0000000..fdc9d0a --- /dev/null +++ b/addons/capri_tools/global_sound_selector_plugin.gd.uid @@ -0,0 +1 @@ +uid://c3qk8q16lbsk6 diff --git a/addons/capri_tools/plugin.cfg b/addons/capri_tools/plugin.cfg new file mode 100644 index 0000000..98c00f8 --- /dev/null +++ b/addons/capri_tools/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Capri Tools" +description="Bespoke tools for Capri's systems that require an editor plugin to be nicer to use." +author="fogwaves" +version="0.1.0" +script="capri_tools.gd" diff --git a/autoloads/global_sounds.gd b/autoloads/global_sounds.gd new file mode 100644 index 0000000..81a3cfb --- /dev/null +++ b/autoloads/global_sounds.gd @@ -0,0 +1,18 @@ +@tool +extends Node + + +@export_tool_button("Update Sounds") var _update_sounds_action = _update_sounds +@export var sounds: Dictionary[StringName, AudioStreamPlayer] + + +func play_sound(id: StringName) -> void: + var sound := sounds.get(id) as AudioStreamPlayer + sound.play() + +func _update_sounds() -> void: + sounds.clear() + for node in get_children(): + if node is AudioStreamPlayer: + sounds[node.name] = node + notify_property_list_changed() diff --git a/autoloads/global_sounds.gd.uid b/autoloads/global_sounds.gd.uid new file mode 100644 index 0000000..764c3a9 --- /dev/null +++ b/autoloads/global_sounds.gd.uid @@ -0,0 +1 @@ +uid://c1yco1xiqppw diff --git a/autoloads/global_sounds.tscn b/autoloads/global_sounds.tscn new file mode 100644 index 0000000..8a1de4a --- /dev/null +++ b/autoloads/global_sounds.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=4 format=3 uid="uid://cof2sm0drv2i"] + +[ext_resource type="Script" uid="uid://c1yco1xiqppw" path="res://autoloads/global_sounds.gd" id="1_22s5s"] +[ext_resource type="AudioStream" uid="uid://sci5aqar0oyx" path="res://assets/audio/bgs/amb_sog.wav" id="2_3njyb"] +[ext_resource type="AudioStream" uid="uid://flc817bekeh6" path="res://assets/audio/sfx/level_win.ogg" id="3_pqonv"] + +[node name="GlobalSounds" type="Node" node_paths=PackedStringArray("sounds")] +script = ExtResource("1_22s5s") +sounds = { +&"SoggyAmbience": NodePath("SoggyAmbience"), +&"WinSound": NodePath("WinSound") +} + +[node name="SoggyAmbience" type="AudioStreamPlayer" parent="."] +stream = ExtResource("2_3njyb") +volume_db = -10.0 +autoplay = true +bus = &"Background Sound" + +[node name="WinSound" type="AudioStreamPlayer" parent="."] +stream = ExtResource("3_pqonv") +volume_db = -6.558 +bus = &"Sound Effects" diff --git a/project.godot b/project.godot index 592be74..93a1a87 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,7 @@ config/icon="res://icon.svg" SceneManager="*res://autoloads/scene_manager.tscn" Levels="*res://autoloads/levels.tscn" +GlobalSounds="*res://autoloads/global_sounds.tscn" [display] @@ -27,7 +28,7 @@ window/size/viewport_height=216 [editor_plugins] -enabled=PackedStringArray("res://addons/godot_state_charts/plugin.cfg") +enabled=PackedStringArray("res://addons/capri_tools/plugin.cfg", "res://addons/godot_state_charts/plugin.cfg") [file_customization] diff --git a/scripts/global_sound_player/global_sound_player.gd b/scripts/global_sound_player/global_sound_player.gd new file mode 100644 index 0000000..ecb6a61 --- /dev/null +++ b/scripts/global_sound_player/global_sound_player.gd @@ -0,0 +1,11 @@ +@tool +@icon("global_sound_player.svg") +class_name GlobalSoundPlayer +extends Node + + +@export_custom(0, "global_sound") var sound: StringName + + +func play() -> void: + GlobalSounds.play_sound(sound) diff --git a/scripts/global_sound_player/global_sound_player.gd.uid b/scripts/global_sound_player/global_sound_player.gd.uid new file mode 100644 index 0000000..2455541 --- /dev/null +++ b/scripts/global_sound_player/global_sound_player.gd.uid @@ -0,0 +1 @@ +uid://cg3hwyafaokvs diff --git a/scripts/global_sound_player/global_sound_player.svg b/scripts/global_sound_player/global_sound_player.svg new file mode 100644 index 0000000..d65c569 --- /dev/null +++ b/scripts/global_sound_player/global_sound_player.svg @@ -0,0 +1,50 @@ + + diff --git a/scripts/global_sound_player/global_sound_player.svg.import b/scripts/global_sound_player/global_sound_player.svg.import new file mode 100644 index 0000000..53ebc8d --- /dev/null +++ b/scripts/global_sound_player/global_sound_player.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d228m7ctf8oxw" +path="res://.godot/imported/global_sound_player.svg-1b6f31c64d0990ab1d53b6cd3019a357.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scripts/global_sound_player/global_sound_player.svg" +dest_files=["res://.godot/imported/global_sound_player.svg-1b6f31c64d0990ab1d53b6cd3019a357.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false