Global Sounds system
This commit is contained in:
parent
5677971bf0
commit
ba3306c04c
15 changed files with 232 additions and 1 deletions
17
addons/capri_tools/capri_tools.gd
Normal file
17
addons/capri_tools/capri_tools.gd
Normal 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)
|
1
addons/capri_tools/capri_tools.gd.uid
Normal file
1
addons/capri_tools/capri_tools.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://b6rylu4028qec
|
46
addons/capri_tools/global_sound_selector.gd
Normal file
46
addons/capri_tools/global_sound_selector.gd
Normal 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)
|
1
addons/capri_tools/global_sound_selector.gd.uid
Normal file
1
addons/capri_tools/global_sound_selector.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bwr5g1ae4dxs4
|
16
addons/capri_tools/global_sound_selector_plugin.gd
Normal file
16
addons/capri_tools/global_sound_selector_plugin.gd
Normal 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
|
1
addons/capri_tools/global_sound_selector_plugin.gd.uid
Normal file
1
addons/capri_tools/global_sound_selector_plugin.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://c3qk8q16lbsk6
|
7
addons/capri_tools/plugin.cfg
Normal file
7
addons/capri_tools/plugin.cfg
Normal 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"
|
Loading…
Add table
Add a link
Reference in a new issue