Global Sounds system

This commit is contained in:
Haze Weathers 2025-03-08 16:32:47 -05:00
parent 5677971bf0
commit ba3306c04c
15 changed files with 232 additions and 1 deletions

View file

@ -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)

View file

@ -0,0 +1 @@
uid://b6rylu4028qec

View file

@ -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)

View file

@ -0,0 +1 @@
uid://bwr5g1ae4dxs4

View file

@ -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

View file

@ -0,0 +1 @@
uid://c3qk8q16lbsk6

View file

@ -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"