summaryrefslogtreecommitdiff
path: root/editor/editor_audio_buses.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_audio_buses.cpp')
-rw-r--r--editor/editor_audio_buses.cpp360
1 files changed, 139 insertions, 221 deletions
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index 3f773c646a..adb09532eb 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -30,8 +30,8 @@
#include "editor_audio_buses.h"
+#include "core/input/input.h"
#include "core/io/resource_saver.h"
-#include "core/os/input.h"
#include "core/os/keyboard.h"
#include "editor_node.h"
#include "editor_scale.h"
@@ -40,10 +40,8 @@
#include "servers/audio_server.h"
void EditorAudioBus::_update_visible_channels() {
-
int i = 0;
for (; i < cc; i++) {
-
if (!channel[i].vu_l->is_visible()) {
channel[i].vu_l->show();
}
@@ -53,7 +51,6 @@ void EditorAudioBus::_update_visible_channels() {
}
for (; i < CHANNELS_MAX; i++) {
-
if (channel[i].vu_l->is_visible()) {
channel[i].vu_l->hide();
}
@@ -64,54 +61,50 @@ void EditorAudioBus::_update_visible_channels() {
}
void EditorAudioBus::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_READY: {
-
for (int i = 0; i < CHANNELS_MAX; i++) {
- channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
- channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
- channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
- channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
+ channel[i].vu_l->set_under_texture(get_theme_icon("BusVuEmpty", "EditorIcons"));
+ channel[i].vu_l->set_progress_texture(get_theme_icon("BusVuFull", "EditorIcons"));
+ channel[i].vu_r->set_under_texture(get_theme_icon("BusVuEmpty", "EditorIcons"));
+ channel[i].vu_r->set_progress_texture(get_theme_icon("BusVuFull", "EditorIcons"));
channel[i].prev_active = true;
}
- disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
+ disabled_vu = get_theme_icon("BusVuFrozen", "EditorIcons");
Color solo_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0, 0.89, 0.22) : Color(1.0, 0.92, 0.44);
Color mute_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0, 0.16, 0.16) : Color(1.0, 0.44, 0.44);
Color bypass_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(0.13, 0.8, 1.0) : Color(0.44, 0.87, 1.0);
- solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
- solo->add_color_override("icon_color_pressed", solo_color);
- mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
- mute->add_color_override("icon_color_pressed", mute_color);
- bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
- bypass->add_color_override("icon_color_pressed", bypass_color);
+ solo->set_icon(get_theme_icon("AudioBusSolo", "EditorIcons"));
+ solo->add_theme_color_override("icon_color_pressed", solo_color);
+ mute->set_icon(get_theme_icon("AudioBusMute", "EditorIcons"));
+ mute->add_theme_color_override("icon_color_pressed", mute_color);
+ bypass->set_icon(get_theme_icon("AudioBusBypass", "EditorIcons"));
+ bypass->add_theme_color_override("icon_color_pressed", bypass_color);
- bus_options->set_icon(get_icon("GuiTabMenu", "EditorIcons"));
+ bus_options->set_icon(get_theme_icon("GuiTabMenuHl", "EditorIcons"));
update_bus();
set_process(true);
} break;
case NOTIFICATION_DRAW: {
-
if (is_master) {
- draw_style_box(get_stylebox("disabled", "Button"), Rect2(Vector2(), get_size()));
+ draw_style_box(get_theme_stylebox("disabled", "Button"), Rect2(Vector2(), get_size()));
} else if (has_focus()) {
- draw_style_box(get_stylebox("focus", "Button"), Rect2(Vector2(), get_size()));
+ draw_style_box(get_theme_stylebox("focus", "Button"), Rect2(Vector2(), get_size()));
} else {
- draw_style_box(get_stylebox("panel", "TabContainer"), Rect2(Vector2(), get_size()));
+ draw_style_box(get_theme_stylebox("panel", "TabContainer"), Rect2(Vector2(), get_size()));
}
if (get_index() != 0 && hovering_drop) {
- Color accent = get_color("accent_color", "Editor");
+ Color accent = get_theme_color("accent_color", "Editor");
accent.a *= 0.7;
draw_rect(Rect2(Point2(), get_size()), accent, false);
}
} break;
case NOTIFICATION_PROCESS: {
-
if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) {
cc = AudioServer::get_singleton()->get_bus_channels(get_index());
_update_visible_channels();
@@ -144,8 +137,8 @@ void EditorAudioBus::_notification(int p_what) {
if (activity_found != channel[i].prev_active) {
if (activity_found) {
- channel[i].vu_l->set_over_texture(Ref<Texture>());
- channel[i].vu_r->set_over_texture(Ref<Texture>());
+ channel[i].vu_l->set_over_texture(Ref<Texture2D>());
+ channel[i].vu_r->set_over_texture(Ref<Texture2D>());
} else {
channel[i].vu_l->set_over_texture(disabled_vu);
channel[i].vu_r->set_over_texture(disabled_vu);
@@ -156,7 +149,6 @@ void EditorAudioBus::_notification(int p_what) {
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
for (int i = 0; i < CHANNELS_MAX; i++) {
channel[i].peak_l = -100;
channel[i].peak_r = -100;
@@ -166,26 +158,24 @@ void EditorAudioBus::_notification(int p_what) {
set_process(is_visible_in_tree());
} break;
case NOTIFICATION_THEME_CHANGED: {
-
for (int i = 0; i < CHANNELS_MAX; i++) {
- channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
- channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
- channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
- channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
+ channel[i].vu_l->set_under_texture(get_theme_icon("BusVuEmpty", "EditorIcons"));
+ channel[i].vu_l->set_progress_texture(get_theme_icon("BusVuFull", "EditorIcons"));
+ channel[i].vu_r->set_under_texture(get_theme_icon("BusVuEmpty", "EditorIcons"));
+ channel[i].vu_r->set_progress_texture(get_theme_icon("BusVuFull", "EditorIcons"));
channel[i].prev_active = true;
}
- disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
+ disabled_vu = get_theme_icon("BusVuFrozen", "EditorIcons");
- solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
- mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
- bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
+ solo->set_icon(get_theme_icon("AudioBusSolo", "EditorIcons"));
+ mute->set_icon(get_theme_icon("AudioBusMute", "EditorIcons"));
+ bypass->set_icon(get_theme_icon("AudioBusBypass", "EditorIcons"));
- bus_options->set_icon(get_icon("GuiTabMenu", "EditorIcons"));
+ bus_options->set_icon(get_theme_icon("GuiTabMenuHl", "EditorIcons"));
} break;
case NOTIFICATION_MOUSE_EXIT:
case NOTIFICATION_DRAG_END: {
-
if (hovering_drop) {
hovering_drop = false;
update();
@@ -195,7 +185,6 @@ void EditorAudioBus::_notification(int p_what) {
}
void EditorAudioBus::update_send() {
-
send->clear();
if (is_master) {
send->set_disabled(true);
@@ -218,9 +207,9 @@ void EditorAudioBus::update_send() {
}
void EditorAudioBus::update_bus() {
-
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
updating_bus = true;
@@ -229,8 +218,9 @@ void EditorAudioBus::update_bus() {
float db_value = AudioServer::get_singleton()->get_bus_volume_db(index);
slider->set_value(_scaled_db_to_normalized_volume(db_value));
track_name->set_text(AudioServer::get_singleton()->get_bus_name(index));
- if (is_master)
+ if (is_master) {
track_name->set_editable(false);
+ }
solo->set_pressed(AudioServer::get_singleton()->is_bus_solo(index));
mute->set_pressed(AudioServer::get_singleton()->is_bus_mute(index));
@@ -240,7 +230,6 @@ void EditorAudioBus::update_bus() {
TreeItem *root = effects->create_item();
for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
-
Ref<AudioEffect> afx = AudioServer::get_singleton()->get_bus_effect(index, i);
TreeItem *fx = effects->create_item(root);
@@ -263,18 +252,16 @@ void EditorAudioBus::update_bus() {
}
void EditorAudioBus::_name_changed(const String &p_new_name) {
-
- if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index()))
+ if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) {
return;
+ }
String attempt = p_new_name;
int attempts = 1;
while (true) {
-
bool name_free = true;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
-
if (AudioServer::get_singleton()->get_bus_name(i) == attempt) {
name_free = false;
break;
@@ -317,9 +304,9 @@ void EditorAudioBus::_name_changed(const String &p_new_name) {
}
void EditorAudioBus::_volume_changed(float p_normalized) {
-
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
updating_bus = true;
@@ -384,7 +371,6 @@ float EditorAudioBus::_scaled_db_to_normalized_volume(float db) {
}
void EditorAudioBus::_show_value(float slider_value) {
-
float db;
if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
// Display the correct (snapped) value when holding Ctrl
@@ -415,7 +401,6 @@ void EditorAudioBus::_hide_value_preview() {
}
void EditorAudioBus::_solo_toggled() {
-
updating_bus = true;
UndoRedo *ur = EditorNode::get_undo_redo();
@@ -428,8 +413,8 @@ void EditorAudioBus::_solo_toggled() {
updating_bus = false;
}
-void EditorAudioBus::_mute_toggled() {
+void EditorAudioBus::_mute_toggled() {
updating_bus = true;
UndoRedo *ur = EditorNode::get_undo_redo();
@@ -442,8 +427,8 @@ void EditorAudioBus::_mute_toggled() {
updating_bus = false;
}
-void EditorAudioBus::_bypass_toggled() {
+void EditorAudioBus::_bypass_toggled() {
updating_bus = true;
UndoRedo *ur = EditorNode::get_undo_redo();
@@ -458,7 +443,6 @@ void EditorAudioBus::_bypass_toggled() {
}
void EditorAudioBus::_send_selected(int p_which) {
-
updating_bus = true;
UndoRedo *ur = EditorNode::get_undo_redo();
@@ -473,14 +457,13 @@ void EditorAudioBus::_send_selected(int p_which) {
}
void EditorAudioBus::_effect_selected() {
-
TreeItem *effect = effects->get_selected();
- if (!effect)
+ if (!effect) {
return;
+ }
updating_bus = true;
if (effect->get_metadata(0) != Variant()) {
-
int index = effect->get_metadata(0);
Ref<AudioEffect> effect2 = AudioServer::get_singleton()->get_bus_effect(get_index(), index);
if (effect2.is_valid()) {
@@ -492,13 +475,14 @@ void EditorAudioBus::_effect_selected() {
}
void EditorAudioBus::_effect_edited() {
-
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
TreeItem *effect = effects->get_edited();
- if (!effect)
+ if (!effect) {
return;
+ }
if (effect->get_metadata(0) == Variant()) {
Rect2 area = effects->get_item_rect(effect);
@@ -523,9 +507,9 @@ void EditorAudioBus::_effect_edited() {
}
void EditorAudioBus::_effect_add(int p_which) {
-
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
StringName name = effect_options->get_item_metadata(p_which);
@@ -547,24 +531,32 @@ void EditorAudioBus::_effect_add(int p_which) {
}
void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventKey> k = p_event;
- if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) {
+ if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && !k->is_echo()) {
accept_event();
emit_signal("delete_request");
}
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
-
Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y);
bus_popup->set_position(get_global_position() + pos);
bus_popup->popup();
}
}
-void EditorAudioBus::_bus_popup_pressed(int p_option) {
+void EditorAudioBus::_unhandled_key_input(Ref<InputEvent> p_event) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == KEY_DELETE) {
+ TreeItem *current_effect = effects->get_selected();
+ if (current_effect && current_effect->get_metadata(0).get_type() == Variant::INT) {
+ _delete_effect_pressed(0);
+ accept_event();
+ }
+ }
+}
+void EditorAudioBus::_bus_popup_pressed(int p_option) {
if (p_option == 2) {
// Reset volume
emit_signal("vol_reset_request");
@@ -577,7 +569,6 @@ void EditorAudioBus::_bus_popup_pressed(int p_option) {
}
Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
-
if (get_index() == 0) {
return Variant();
}
@@ -586,7 +577,7 @@ Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
Panel *p = memnew(Panel);
c->add_child(p);
p->set_modulate(Color(1, 1, 1, 0.7));
- p->add_style_override("panel", get_stylebox("focus", "Button"));
+ p->add_theme_style_override("panel", get_theme_stylebox("focus", "Button"));
p->set_size(get_size());
p->set_position(-p_point);
set_drag_preview(c);
@@ -602,7 +593,6 @@ Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
}
bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
-
if (get_index() == 0) {
return false;
}
@@ -617,13 +607,11 @@ bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data)
}
void EditorAudioBus::drop_data(const Point2 &p_point, const Variant &p_data) {
-
Dictionary d = p_data;
emit_signal("dropped", d["index"], get_index());
}
Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
-
TreeItem *item = effects->get_item_at_position(p_point);
if (!item) {
return Variant();
@@ -647,14 +635,15 @@ Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from)
}
bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
-
Dictionary d = p_data;
- if (!d.has("type") || String(d["type"]) != "audio_bus_effect")
+ if (!d.has("type") || String(d["type"]) != "audio_bus_effect") {
return false;
+ }
TreeItem *item = effects->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return false;
+ }
effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
@@ -662,12 +651,12 @@ bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
}
void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
-
Dictionary d = p_data;
TreeItem *item = effects->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return;
+ }
int pos = effects->get_drop_section_at_position(p_point);
Variant md = item->get_metadata(0);
@@ -677,8 +666,9 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data,
if (md.get_type() == Variant::INT) {
paste_at = md;
- if (pos > 0)
+ if (pos > 0) {
paste_at++;
+ }
if (bus == get_index() && paste_at > effect) {
paste_at--;
@@ -720,13 +710,14 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
void EditorAudioBus::_delete_effect_pressed(int p_option) {
-
TreeItem *item = effects->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
- if (item->get_metadata(0).get_type() != Variant::INT)
+ if (item->get_metadata(0).get_type() != Variant::INT) {
return;
+ }
int index = item->get_metadata(0);
@@ -741,41 +732,27 @@ void EditorAudioBus::_delete_effect_pressed(int p_option) {
}
void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) {
-
TreeItem *item = effects->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
- if (item->get_metadata(0).get_type() != Variant::INT)
+ if (item->get_metadata(0).get_type() != Variant::INT) {
return;
+ }
delete_effect_popup->set_position(get_global_mouse_position());
delete_effect_popup->popup();
}
void EditorAudioBus::_bind_methods() {
-
ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
- ClassDB::bind_method("_name_changed", &EditorAudioBus::_name_changed);
- ClassDB::bind_method("_volume_changed", &EditorAudioBus::_volume_changed);
- ClassDB::bind_method("_show_value", &EditorAudioBus::_show_value);
- ClassDB::bind_method("_hide_value_preview", &EditorAudioBus::_hide_value_preview);
- ClassDB::bind_method("_solo_toggled", &EditorAudioBus::_solo_toggled);
- ClassDB::bind_method("_mute_toggled", &EditorAudioBus::_mute_toggled);
- ClassDB::bind_method("_bypass_toggled", &EditorAudioBus::_bypass_toggled);
- ClassDB::bind_method("_name_focus_exit", &EditorAudioBus::_name_focus_exit);
- ClassDB::bind_method("_send_selected", &EditorAudioBus::_send_selected);
- ClassDB::bind_method("_effect_edited", &EditorAudioBus::_effect_edited);
- ClassDB::bind_method("_effect_selected", &EditorAudioBus::_effect_selected);
- ClassDB::bind_method("_effect_add", &EditorAudioBus::_effect_add);
ClassDB::bind_method("_gui_input", &EditorAudioBus::_gui_input);
- ClassDB::bind_method("_bus_popup_pressed", &EditorAudioBus::_bus_popup_pressed);
+ ClassDB::bind_method("_unhandled_key_input", &EditorAudioBus::_unhandled_key_input);
ClassDB::bind_method("get_drag_data_fw", &EditorAudioBus::get_drag_data_fw);
ClassDB::bind_method("can_drop_data_fw", &EditorAudioBus::can_drop_data_fw);
ClassDB::bind_method("drop_data_fw", &EditorAudioBus::drop_data_fw);
- ClassDB::bind_method("_delete_effect_pressed", &EditorAudioBus::_delete_effect_pressed);
- ClassDB::bind_method("_effect_rmb", &EditorAudioBus::_effect_rmb);
ADD_SIGNAL(MethodInfo("duplicate_request"));
ADD_SIGNAL(MethodInfo("delete_request"));
@@ -785,7 +762,6 @@ void EditorAudioBus::_bind_methods() {
}
EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
-
buses = p_buses;
updating_bus = false;
is_master = p_is_master;
@@ -797,31 +773,35 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
add_child(vb);
set_v_size_flags(SIZE_EXPAND_FILL);
+ set_process_unhandled_key_input(true);
track_name = memnew(LineEdit);
- track_name->connect("text_entered", this, "_name_changed");
- track_name->connect("focus_exited", this, "_name_focus_exit");
+ track_name->connect("text_entered", callable_mp(this, &EditorAudioBus::_name_changed));
+ track_name->connect("focus_exited", callable_mp(this, &EditorAudioBus::_name_focus_exit));
vb->add_child(track_name);
HBoxContainer *hbc = memnew(HBoxContainer);
vb->add_child(hbc);
- solo = memnew(ToolButton);
+ solo = memnew(Button);
+ solo->set_flat(true);
solo->set_toggle_mode(true);
solo->set_tooltip(TTR("Solo"));
solo->set_focus_mode(FOCUS_NONE);
- solo->connect("pressed", this, "_solo_toggled");
+ solo->connect("pressed", callable_mp(this, &EditorAudioBus::_solo_toggled));
hbc->add_child(solo);
- mute = memnew(ToolButton);
+ mute = memnew(Button);
+ mute->set_flat(true);
mute->set_toggle_mode(true);
mute->set_tooltip(TTR("Mute"));
mute->set_focus_mode(FOCUS_NONE);
- mute->connect("pressed", this, "_mute_toggled");
+ mute->connect("pressed", callable_mp(this, &EditorAudioBus::_mute_toggled));
hbc->add_child(mute);
- bypass = memnew(ToolButton);
+ bypass = memnew(Button);
+ bypass->set_flat(true);
bypass->set_toggle_mode(true);
bypass->set_tooltip(TTR("Bypass"));
bypass->set_focus_mode(FOCUS_NONE);
- bypass->connect("pressed", this, "_bypass_toggled");
+ bypass->connect("pressed", callable_mp(this, &EditorAudioBus::_bypass_toggled));
hbc->add_child(bypass);
hbc->add_spacer();
@@ -834,10 +814,10 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty);
for (int i = 0; i < hbc->get_child_count(); i++) {
Control *child = Object::cast_to<Control>(hbc->get_child(i));
- child->add_style_override("normal", sbempty);
- child->add_style_override("hover", sbempty);
- child->add_style_override("focus", sbempty);
- child->add_style_override("pressed", sbempty);
+ child->add_theme_style_override("normal", sbempty);
+ child->add_theme_style_override("hover", sbempty);
+ child->add_theme_style_override("focus", sbempty);
+ child->add_theme_style_override("pressed", sbempty);
}
HSeparator *separator = memnew(HSeparator);
@@ -856,7 +836,6 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
HBoxContainer *audioprev_hbc = memnew(HBoxContainer);
audioprev_hbc->set_v_size_flags(SIZE_EXPAND_FILL);
audioprev_hbc->set_h_size_flags(SIZE_EXPAND_FILL);
- audioprev_hbc->set_mouse_filter(MOUSE_FILTER_PASS);
audio_value_preview_box->add_child(audioprev_hbc);
audio_value_preview_label = memnew(Label);
@@ -870,7 +849,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
audio_value_preview_box->set_as_toplevel(true);
Ref<StyleBoxFlat> panel_style = memnew(StyleBoxFlat);
panel_style->set_bg_color(Color(0.0f, 0.0f, 0.0f, 0.8f));
- audio_value_preview_box->add_style_override("panel", panel_style);
+ audio_value_preview_box->add_theme_style_override("panel", panel_style);
audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS);
audio_value_preview_box->hide();
@@ -879,9 +858,9 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
preview_timer->set_one_shot(true);
add_child(preview_timer);
- slider->connect("value_changed", this, "_volume_changed");
- slider->connect("value_changed", this, "_show_value");
- preview_timer->connect("timeout", this, "_hide_value_preview");
+ slider->connect("value_changed", callable_mp(this, &EditorAudioBus::_volume_changed));
+ slider->connect("value_changed", callable_mp(this, &EditorAudioBus::_show_value));
+ preview_timer->connect("timeout", callable_mp(this, &EditorAudioBus::_hide_value_preview));
hb->add_child(slider);
cc = 0;
@@ -919,33 +898,34 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
effects->set_hide_folding(true);
effects->set_v_size_flags(SIZE_EXPAND_FILL);
vb->add_child(effects);
- effects->connect("item_edited", this, "_effect_edited");
- effects->connect("cell_selected", this, "_effect_selected");
+ effects->connect("item_edited", callable_mp(this, &EditorAudioBus::_effect_edited));
+ effects->connect("cell_selected", callable_mp(this, &EditorAudioBus::_effect_selected));
effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
effects->set_drag_forwarding(this);
- effects->connect("item_rmb_selected", this, "_effect_rmb");
+ effects->connect("item_rmb_selected", callable_mp(this, &EditorAudioBus::_effect_rmb));
effects->set_allow_rmb_select(true);
effects->set_focus_mode(FOCUS_CLICK);
effects->set_allow_reselect(true);
send = memnew(OptionButton);
send->set_clip_text(true);
- send->connect("item_selected", this, "_send_selected");
+ send->connect("item_selected", callable_mp(this, &EditorAudioBus::_send_selected));
vb->add_child(send);
set_focus_mode(FOCUS_CLICK);
effect_options = memnew(PopupMenu);
- effect_options->connect("index_pressed", this, "_effect_add");
+ effect_options->connect("index_pressed", callable_mp(this, &EditorAudioBus::_effect_add));
add_child(effect_options);
List<StringName> effects;
ClassDB::get_inheriters_from_class("AudioEffect", &effects);
effects.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = effects.front(); E; E = E->next()) {
- if (!ClassDB::can_instance(E->get()))
+ if (!ClassDB::can_instance(E->get())) {
continue;
+ }
- Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(E->get());
+ Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(E->get());
String name = E->get().operator String().replace("AudioEffect", "");
effect_options->add_item(name);
effect_options->set_item_metadata(effect_options->get_item_count() - 1, E->get());
@@ -957,28 +937,26 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
bus_popup->add_item(TTR("Delete"));
bus_popup->set_item_disabled(1, is_master);
bus_popup->add_item(TTR("Reset Volume"));
- bus_popup->connect("index_pressed", this, "_bus_popup_pressed");
+ bus_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_bus_popup_pressed));
delete_effect_popup = memnew(PopupMenu);
delete_effect_popup->add_item(TTR("Delete Effect"));
add_child(delete_effect_popup);
- delete_effect_popup->connect("index_pressed", this, "_delete_effect_pressed");
+ delete_effect_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_delete_effect_pressed));
}
void EditorAudioBusDrop::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_DRAW: {
- draw_style_box(get_stylebox("normal", "Button"), Rect2(Vector2(), get_size()));
+ draw_style_box(get_theme_stylebox("normal", "Button"), Rect2(Vector2(), get_size()));
if (hovering_drop) {
- Color accent = get_color("accent_color", "Editor");
+ Color accent = get_theme_color("accent_color", "Editor");
accent.a *= 0.7;
draw_rect(Rect2(Point2(), get_size()), accent, false);
}
} break;
case NOTIFICATION_MOUSE_ENTER: {
-
if (!hovering_drop) {
hovering_drop = true;
update();
@@ -986,7 +964,6 @@ void EditorAudioBusDrop::_notification(int p_what) {
} break;
case NOTIFICATION_MOUSE_EXIT:
case NOTIFICATION_DRAG_END: {
-
if (hovering_drop) {
hovering_drop = false;
update();
@@ -996,76 +973,64 @@ void EditorAudioBusDrop::_notification(int p_what) {
}
bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
-
Dictionary d = p_data;
return (d.has("type") && String(d["type"]) == "move_audio_bus");
}
void EditorAudioBusDrop::drop_data(const Point2 &p_point, const Variant &p_data) {
-
Dictionary d = p_data;
emit_signal("dropped", d["index"], AudioServer::get_singleton()->get_bus_count());
}
void EditorAudioBusDrop::_bind_methods() {
-
ADD_SIGNAL(MethodInfo("dropped"));
}
EditorAudioBusDrop::EditorAudioBusDrop() {
-
hovering_drop = false;
}
void EditorAudioBuses::_update_buses() {
-
while (bus_hb->get_child_count() > 0) {
memdelete(bus_hb->get_child(0));
}
- drop_end = NULL;
+ drop_end = nullptr;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
-
bool is_master = (i == 0);
EditorAudioBus *audio_bus = memnew(EditorAudioBus(this, is_master));
bus_hb->add_child(audio_bus);
- audio_bus->connect("delete_request", this, "_delete_bus", varray(audio_bus), CONNECT_DEFERRED);
- audio_bus->connect("duplicate_request", this, "_duplicate_bus", varray(), CONNECT_DEFERRED);
- audio_bus->connect("vol_reset_request", this, "_reset_bus_volume", varray(audio_bus), CONNECT_DEFERRED);
- audio_bus->connect("drop_end_request", this, "_request_drop_end");
- audio_bus->connect("dropped", this, "_drop_at_index", varray(), CONNECT_DEFERRED);
+ audio_bus->connect("delete_request", callable_mp(this, &EditorAudioBuses::_delete_bus), varray(audio_bus), CONNECT_DEFERRED);
+ audio_bus->connect("duplicate_request", callable_mp(this, &EditorAudioBuses::_duplicate_bus), varray(), CONNECT_DEFERRED);
+ audio_bus->connect("vol_reset_request", callable_mp(this, &EditorAudioBuses::_reset_bus_volume), varray(audio_bus), CONNECT_DEFERRED);
+ audio_bus->connect("drop_end_request", callable_mp(this, &EditorAudioBuses::_request_drop_end));
+ audio_bus->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), varray(), CONNECT_DEFERRED);
}
}
EditorAudioBuses *EditorAudioBuses::register_editor() {
-
EditorAudioBuses *audio_buses = memnew(EditorAudioBuses);
EditorNode::get_singleton()->add_bottom_panel_item(TTR("Audio"), audio_buses);
return audio_buses;
}
void EditorAudioBuses::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
-
- bus_scroll->add_style_override("bg", get_stylebox("bg", "Tree"));
+ bus_scroll->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree"));
} break;
case NOTIFICATION_READY: {
-
_update_buses();
} break;
case NOTIFICATION_DRAG_END: {
-
if (drop_end) {
drop_end->queue_delete();
- drop_end = NULL;
+ drop_end = nullptr;
}
} break;
case NOTIFICATION_PROCESS: {
-
// Check if anything was edited.
bool edited = AudioServer::get_singleton()->is_edited();
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
@@ -1088,7 +1053,6 @@ void EditorAudioBuses::_notification(int p_what) {
}
void EditorAudioBuses::_add_bus() {
-
UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Add Audio Bus"));
@@ -1100,22 +1064,20 @@ void EditorAudioBuses::_add_bus() {
}
void EditorAudioBuses::_update_bus(int p_index) {
-
- if (p_index >= bus_hb->get_child_count())
+ if (p_index >= bus_hb->get_child_count()) {
return;
+ }
bus_hb->get_child(p_index)->call("update_bus");
}
void EditorAudioBuses::_update_sends() {
-
for (int i = 0; i < bus_hb->get_child_count(); i++) {
bus_hb->get_child(i)->call("update_send");
}
}
void EditorAudioBuses::_delete_bus(Object *p_which) {
-
EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
int index = bus->get_index();
if (index == 0) {
@@ -1135,7 +1097,6 @@ void EditorAudioBuses::_delete_bus(Object *p_which) {
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", index, AudioServer::get_singleton()->is_bus_mute(index));
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", index, AudioServer::get_singleton()->is_bus_bypassing_effects(index));
for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
-
ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", index, AudioServer::get_singleton()->get_bus_effect(index, i));
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", index, i, AudioServer::get_singleton()->is_bus_effect_enabled(index, i));
}
@@ -1145,7 +1106,6 @@ void EditorAudioBuses::_delete_bus(Object *p_which) {
}
void EditorAudioBuses::_duplicate_bus(int p_which) {
-
int add_at_pos = p_which + 1;
UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Duplicate Audio Bus"));
@@ -1157,7 +1117,6 @@ void EditorAudioBuses::_duplicate_bus(int p_which) {
ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", add_at_pos, AudioServer::get_singleton()->is_bus_mute(p_which));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", add_at_pos, AudioServer::get_singleton()->is_bus_bypassing_effects(p_which));
for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(p_which); i++) {
-
ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", add_at_pos, AudioServer::get_singleton()->get_bus_effect(p_which, i));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", add_at_pos, i, AudioServer::get_singleton()->is_bus_effect_enabled(p_which, i));
}
@@ -1168,7 +1127,6 @@ void EditorAudioBuses::_duplicate_bus(int p_which) {
}
void EditorAudioBuses::_reset_bus_volume(Object *p_which) {
-
EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
int index = bus->get_index();
@@ -1182,18 +1140,16 @@ void EditorAudioBuses::_reset_bus_volume(Object *p_which) {
}
void EditorAudioBuses::_request_drop_end() {
-
if (!drop_end && bus_hb->get_child_count()) {
drop_end = memnew(EditorAudioBusDrop);
bus_hb->add_child(drop_end);
drop_end->set_custom_minimum_size(Object::cast_to<Control>(bus_hb->get_child(0))->get_size());
- drop_end->connect("dropped", this, "_drop_at_index", varray(), CONNECT_DEFERRED);
+ drop_end->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), varray(), CONNECT_DEFERRED);
}
}
void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
-
UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Move Audio Bus"));
@@ -1208,45 +1164,39 @@ void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
}
void EditorAudioBuses::_server_save() {
-
Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout();
ResourceSaver::save(edited_path, state);
}
void EditorAudioBuses::_select_layout() {
-
EditorNode::get_singleton()->get_filesystem_dock()->select_file(edited_path);
}
void EditorAudioBuses::_save_as_layout() {
-
- file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
+ file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_title(TTR("Save Audio Bus Layout As..."));
file_dialog->set_current_path(edited_path);
- file_dialog->popup_centered_ratio();
+ file_dialog->popup_file_dialog();
new_layout = false;
}
void EditorAudioBuses::_new_layout() {
-
- file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
+ file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_title(TTR("Location for New Layout..."));
file_dialog->set_current_path(edited_path);
- file_dialog->popup_centered_ratio();
+ file_dialog->popup_file_dialog();
new_layout = true;
}
void EditorAudioBuses::_load_layout() {
-
- file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
+ file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
file_dialog->set_title(TTR("Open Audio Bus Layout"));
file_dialog->set_current_path(edited_path);
- file_dialog->popup_centered_ratio();
+ file_dialog->popup_file_dialog();
new_layout = false;
}
void EditorAudioBuses::_load_default_layout() {
-
String layout_path = ProjectSettings::get_singleton()->get("audio/default_bus_layout");
Ref<AudioBusLayout> state = ResourceLoader::load(layout_path, "", true);
@@ -1264,8 +1214,7 @@ void EditorAudioBuses::_load_default_layout() {
}
void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
-
- if (file_dialog->get_mode() == EditorFileDialog::MODE_OPEN_FILE) {
+ if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_OPEN_FILE) {
Ref<AudioBusLayout> state = ResourceLoader::load(p_string, "", true);
if (state.is_null()) {
EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout."));
@@ -1279,8 +1228,7 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
EditorNode::get_singleton()->get_undo_redo()->clear_history();
call_deferred("_select_layout");
- } else if (file_dialog->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
-
+ } else if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
if (new_layout) {
Ref<AudioBusLayout> empty_state;
empty_state.instance();
@@ -1303,29 +1251,14 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
}
void EditorAudioBuses::_bind_methods() {
-
- ClassDB::bind_method("_add_bus", &EditorAudioBuses::_add_bus);
ClassDB::bind_method("_update_buses", &EditorAudioBuses::_update_buses);
ClassDB::bind_method("_update_bus", &EditorAudioBuses::_update_bus);
ClassDB::bind_method("_update_sends", &EditorAudioBuses::_update_sends);
- ClassDB::bind_method("_delete_bus", &EditorAudioBuses::_delete_bus);
- ClassDB::bind_method("_request_drop_end", &EditorAudioBuses::_request_drop_end);
- ClassDB::bind_method("_drop_at_index", &EditorAudioBuses::_drop_at_index);
- ClassDB::bind_method("_server_save", &EditorAudioBuses::_server_save);
ClassDB::bind_method("_select_layout", &EditorAudioBuses::_select_layout);
- ClassDB::bind_method("_save_as_layout", &EditorAudioBuses::_save_as_layout);
- ClassDB::bind_method("_load_layout", &EditorAudioBuses::_load_layout);
- ClassDB::bind_method("_load_default_layout", &EditorAudioBuses::_load_default_layout);
- ClassDB::bind_method("_new_layout", &EditorAudioBuses::_new_layout);
- ClassDB::bind_method("_duplicate_bus", &EditorAudioBuses::_duplicate_bus);
- ClassDB::bind_method("_reset_bus_volume", &EditorAudioBuses::_reset_bus_volume);
-
- ClassDB::bind_method("_file_dialog_callback", &EditorAudioBuses::_file_dialog_callback);
}
EditorAudioBuses::EditorAudioBuses() {
-
- drop_end = NULL;
+ drop_end = nullptr;
top_hb = memnew(HBoxContainer);
add_child(top_hb);
@@ -1340,7 +1273,7 @@ EditorAudioBuses::EditorAudioBuses() {
top_hb->add_child(add);
add->set_text(TTR("Add Bus"));
add->set_tooltip(TTR("Add a new Audio Bus to this layout."));
- add->connect("pressed", this, "_add_bus");
+ add->connect("pressed", callable_mp(this, &EditorAudioBuses::_add_bus));
VSeparator *separator = memnew(VSeparator);
top_hb->add_child(separator);
@@ -1349,25 +1282,25 @@ EditorAudioBuses::EditorAudioBuses() {
load->set_text(TTR("Load"));
load->set_tooltip(TTR("Load an existing Bus Layout."));
top_hb->add_child(load);
- load->connect("pressed", this, "_load_layout");
+ load->connect("pressed", callable_mp(this, &EditorAudioBuses::_load_layout));
save_as = memnew(Button);
save_as->set_text(TTR("Save As"));
save_as->set_tooltip(TTR("Save this Bus Layout to a file."));
top_hb->add_child(save_as);
- save_as->connect("pressed", this, "_save_as_layout");
+ save_as->connect("pressed", callable_mp(this, &EditorAudioBuses::_save_as_layout));
_default = memnew(Button);
_default->set_text(TTR("Load Default"));
_default->set_tooltip(TTR("Load the default Bus Layout."));
top_hb->add_child(_default);
- _default->connect("pressed", this, "_load_default_layout");
+ _default->connect("pressed", callable_mp(this, &EditorAudioBuses::_load_default_layout));
_new = memnew(Button);
_new->set_text(TTR("Create"));
_new->set_tooltip(TTR("Create a new Bus Layout."));
top_hb->add_child(_new);
- _new->connect("pressed", this, "_new_layout");
+ _new->connect("pressed", callable_mp(this, &EditorAudioBuses::_new_layout));
bus_scroll = memnew(ScrollContainer);
bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
@@ -1382,7 +1315,7 @@ EditorAudioBuses::EditorAudioBuses() {
save_timer->set_wait_time(0.8);
save_timer->set_one_shot(true);
add_child(save_timer);
- save_timer->connect("timeout", this, "_server_save");
+ save_timer->connect("timeout", callable_mp(this, &EditorAudioBuses::_server_save));
set_v_size_flags(SIZE_EXPAND_FILL);
@@ -1395,13 +1328,12 @@ EditorAudioBuses::EditorAudioBuses() {
file_dialog->add_filter("*." + E->get() + "; Audio Bus Layout");
}
add_child(file_dialog);
- file_dialog->connect("file_selected", this, "_file_dialog_callback");
+ file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback));
set_process(true);
}
void EditorAudioBuses::open_layout(const String &p_path) {
-
EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", true);
@@ -1419,9 +1351,7 @@ void EditorAudioBuses::open_layout(const String &p_path) {
}
void AudioBusesEditorPlugin::edit(Object *p_node) {
-
if (Object::cast_to<AudioBusLayout>(p_node)) {
-
String path = Object::cast_to<AudioBusLayout>(p_node)->get_path();
if (path.is_resource_file()) {
audio_bus_editor->open_layout(path);
@@ -1430,15 +1360,13 @@ void AudioBusesEditorPlugin::edit(Object *p_node) {
}
bool AudioBusesEditorPlugin::handles(Object *p_node) const {
-
- return (Object::cast_to<AudioBusLayout>(p_node) != NULL);
+ return (Object::cast_to<AudioBusLayout>(p_node) != nullptr);
}
void AudioBusesEditorPlugin::make_visible(bool p_visible) {
}
AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) {
-
audio_bus_editor = p_node;
}
@@ -1446,13 +1374,11 @@ AudioBusesEditorPlugin::~AudioBusesEditorPlugin() {
}
void EditorAudioMeterNotches::add_notch(float p_normalized_offset, float p_db_value, bool p_render_value) {
-
notches.push_back(AudioNotch(p_normalized_offset, p_db_value, p_render_value));
}
Size2 EditorAudioMeterNotches::get_minimum_size() const {
-
- Ref<Font> font = get_font("font", "Label");
+ Ref<Font> font = get_theme_font("font", "Label");
float font_height = font->get_height();
float width = 0;
@@ -1470,13 +1396,11 @@ Size2 EditorAudioMeterNotches::get_minimum_size() const {
}
void EditorAudioMeterNotches::_bind_methods() {
-
ClassDB::bind_method("add_notch", &EditorAudioMeterNotches::add_notch);
ClassDB::bind_method("_draw_audio_notches", &EditorAudioMeterNotches::_draw_audio_notches);
}
void EditorAudioMeterNotches::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0);
@@ -1488,8 +1412,7 @@ void EditorAudioMeterNotches::_notification(int p_what) {
}
void EditorAudioMeterNotches::_draw_audio_notches() {
-
- Ref<Font> font = get_font("font", "Label");
+ Ref<Font> font = get_theme_font("font", "Label");
float font_height = font->get_height();
for (int i = 0; i < notches.size(); i++) {
@@ -1509,11 +1432,6 @@ void EditorAudioMeterNotches::_draw_audio_notches() {
}
}
-EditorAudioMeterNotches::EditorAudioMeterNotches() :
- line_length(5.0f),
- label_space(2.0f),
- btm_padding(9.0f),
- top_padding(5.0f) {
-
+EditorAudioMeterNotches::EditorAudioMeterNotches() {
notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0);
}