summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-01-23 23:12:08 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-01-23 23:12:41 -0300
commit3b019bf644f61aaa2eaf9276448d97fb6e6a868a (patch)
treed9ccb2ad27aedad99d9781be1d1030bd28baf661 /tools/editor
parent2527566ca899e2ac9d8baa8b4e68a22bf7077f35 (diff)
Ability to delete, drag and drop audio buses!
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/editor_audio_buses.cpp194
-rw-r--r--tools/editor/editor_audio_buses.h30
-rw-r--r--tools/editor/editor_node.cpp10
3 files changed, 229 insertions, 5 deletions
diff --git a/tools/editor/editor_audio_buses.cpp b/tools/editor/editor_audio_buses.cpp
index d570abcc82..5e34dbd07e 100644
--- a/tools/editor/editor_audio_buses.cpp
+++ b/tools/editor/editor_audio_buses.cpp
@@ -1,7 +1,7 @@
#include "editor_audio_buses.h"
#include "editor_node.h"
#include "servers/audio_server.h"
-
+#include "os/keyboard.h"
void EditorAudioBus::_notification(int p_what) {
@@ -372,6 +372,68 @@ void EditorAudioBus::_effect_add(int p_which) {
ur->commit_action();
}
+void EditorAudioBus::_gui_input(const InputEvent& p_event) {
+
+ if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && !p_event.key.echo) {
+ accept_event();
+ emit_signal("delete_request");
+ }
+ if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==2 && p_event.mouse_button.pressed) {
+
+ Vector2 pos = Vector2(p_event.mouse_button.x,p_event.mouse_button.y);
+ delete_popup->set_pos(get_global_pos()+pos);
+ delete_popup->popup();
+ }
+}
+
+void EditorAudioBus::_delete_pressed(int p_option) {
+
+ if (p_option==1) {
+ emit_signal("delete_request");
+ }
+
+}
+
+
+Variant EditorAudioBus::get_drag_data(const Point2& p_point) {
+
+ if (get_index()==0) {
+ return Variant();
+ }
+
+ Control *c = memnew(Control);
+ Panel *p = memnew( Panel );
+ c->add_child(p);
+ p->add_style_override("panel",get_stylebox("focus","Button"));
+ p->set_size(get_size());
+ p->set_pos(-p_point);
+ set_drag_preview(c);
+ Dictionary d;
+ d["type"]="move_audio_bus";
+ d["index"]=get_index();
+ emit_signal("drop_end_request");
+ return d;
+}
+
+bool EditorAudioBus::can_drop_data(const Point2& p_point,const Variant& p_data) const {
+
+ if (get_index()==0)
+ return false;
+ Dictionary d=p_data;
+ if (d.has("type") && String(d["type"])=="move_audio_bus") {
+ return true;
+ }
+
+ return false;
+}
+void EditorAudioBus::drop_data(const Point2& p_point,const Variant& p_data) {
+
+ Dictionary d=p_data;
+ emit_signal("dropped",d["index"],get_index());
+
+}
+
+
void EditorAudioBus::_bind_methods() {
ClassDB::bind_method("update_bus",&EditorAudioBus::update_bus);
@@ -386,6 +448,13 @@ void EditorAudioBus::_bind_methods() {
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("_delete_pressed",&EditorAudioBus::_delete_pressed);
+
+ ADD_SIGNAL(MethodInfo("delete_request"));
+ ADD_SIGNAL(MethodInfo("drop_end_request"));
+ ADD_SIGNAL(MethodInfo("dropped"));
+
}
EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) {
@@ -455,7 +524,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) {
scale = memnew( TextureRect );
hb->add_child(scale);
- add_child(hb);
+ //add_child(hb);
effects = memnew( Tree );
effects->set_hide_root(true);
@@ -494,6 +563,40 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) {
effect_options->set_item_icon(effect_options->get_item_count()-1,icon);
}
+ delete_popup = memnew( PopupMenu );
+ delete_popup->add_item("Duplicate");
+ delete_popup->add_item("Delete");
+ add_child(delete_popup);
+ delete_popup->connect("index_pressed",this,"_delete_pressed");
+
+
+}
+
+
+
+bool EditorAudioBusDrop::can_drop_data(const Point2& p_point,const Variant& p_data) const {
+
+ Dictionary d=p_data;
+ if (d.has("type") && String(d["type"])=="move_audio_bus") {
+ return true;
+ }
+
+ return false;
+}
+void EditorAudioBusDrop::drop_data(const Point2& p_point,const Variant& p_data){
+
+ Dictionary d=p_data;
+ emit_signal("dropped",d["index"],-1);
+
+}
+
+void EditorAudioBusDrop::_bind_methods() {
+
+ ADD_SIGNAL(MethodInfo("dropped"));
+}
+
+EditorAudioBusDrop::EditorAudioBusDrop() {
+
}
@@ -504,6 +607,8 @@ void EditorAudioBuses::_update_buses() {
memdelete(bus_hb->get_child(0));
}
+ drop_end=NULL;
+
for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) {
EditorAudioBus *audio_bus = memnew( EditorAudioBus(this) );
@@ -511,6 +616,11 @@ void EditorAudioBuses::_update_buses() {
audio_bus->set_self_modulate(Color(1,0.9,0.9));
}
bus_hb->add_child(audio_bus);
+ audio_bus->connect("delete_request",this,"_delete_bus",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);
+
+
}
}
@@ -526,6 +636,13 @@ void EditorAudioBuses::_notification(int p_what) {
if (p_what==NOTIFICATION_READY) {
_update_buses();
}
+
+ if (p_what==NOTIFICATION_DRAG_END) {
+ if (drop_end) {
+ drop_end->queue_delete();
+ drop_end=NULL;
+ }
+ }
}
@@ -558,17 +675,90 @@ void EditorAudioBuses::_update_sends() {
}
}
+void EditorAudioBuses::_delete_bus(Object* p_which) {
+
+ EditorAudioBus *bus = p_which->cast_to<EditorAudioBus>();
+ int index = bus->get_index();
+ if (index==0) {
+ EditorNode::get_singleton()->show_warning("Master bus can't be deleted!");
+ return;
+ }
+
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+
+ ur->create_action("Delete Audio Bus");
+ ur->add_do_method(AudioServer::get_singleton(),"remove_bus",index);
+ ur->add_undo_method(AudioServer::get_singleton(),"add_bus",index);
+ ur->add_undo_method(AudioServer::get_singleton(),"set_bus_name",index,AudioServer::get_singleton()->get_bus_name(index));
+ ur->add_undo_method(AudioServer::get_singleton(),"set_bus_volume_db",index,AudioServer::get_singleton()->get_bus_volume_db(index));
+ ur->add_undo_method(AudioServer::get_singleton(),"set_bus_send",index,AudioServer::get_singleton()->get_bus_send(index));
+ ur->add_undo_method(AudioServer::get_singleton(),"set_bus_solo",index,AudioServer::get_singleton()->is_bus_solo(index));
+ 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));
+ }
+ ur->add_do_method(this,"_update_buses");
+ ur->add_undo_method(this,"_update_buses");
+ ur->commit_action();
+
+}
+
+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(bus_hb->get_child(0)->cast_to<Control>()->get_size());
+ drop_end->connect("dropped",this,"_drop_at_index",varray(),CONNECT_DEFERRED);
+ }
+}
+
+void EditorAudioBuses::_drop_at_index(int p_bus,int p_index) {
+
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+
+ //need to simulate new name, so we can undi :(
+ ur->create_action("Move Audio Bus");
+ ur->add_do_method(AudioServer::get_singleton(),"move_bus",p_bus,p_index);
+ int final_pos;
+ if (p_index==p_bus) {
+ final_pos=p_bus;
+ } else if (p_index==-1) {
+ final_pos = AudioServer::get_singleton()->get_bus_count()-1;
+ } else if (p_index<p_bus) {
+ final_pos = p_index;
+ } else {
+ final_pos = p_index -1;
+ }
+ ur->add_undo_method(AudioServer::get_singleton(),"move_bus",final_pos,p_bus);
+
+ ur->add_do_method(this,"_update_buses");
+ ur->add_undo_method(this,"_update_buses");
+ ur->commit_action();
+}
+
+
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);
}
EditorAudioBuses::EditorAudioBuses()
{
+ drop_end = NULL;
top_hb = memnew( HBoxContainer );
add_child(top_hb);
diff --git a/tools/editor/editor_audio_buses.h b/tools/editor/editor_audio_buses.h
index 8787101393..137c78de30 100644
--- a/tools/editor/editor_audio_buses.h
+++ b/tools/editor/editor_audio_buses.h
@@ -13,6 +13,7 @@
#include "scene/gui/line_edit.h"
#include "scene/gui/tree.h"
#include "scene/gui/option_button.h"
+#include "scene/gui/panel.h"
class EditorAudioBuses;
@@ -33,6 +34,7 @@ class EditorAudioBus : public PanelContainer {
OptionButton *send;
PopupMenu *effect_options;
+ PopupMenu *delete_popup;
Button *solo;
Button *mute;
@@ -42,6 +44,9 @@ class EditorAudioBus : public PanelContainer {
bool updating_bus;
+ void _gui_input(const InputEvent& p_event);
+ void _delete_pressed(int p_option);
+
void _name_changed(const String& p_new_name);
void _name_focus_exit() { _name_changed(track_name->get_text()); }
void _volume_db_changed(float p_db);
@@ -53,6 +58,11 @@ class EditorAudioBus : public PanelContainer {
void _effect_add(int p_which);
void _effect_selected();
+ virtual Variant get_drag_data(const Point2& p_point);
+ virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
+ virtual void drop_data(const Point2& p_point,const Variant& p_data);
+
+
friend class EditorAudioBuses;
EditorAudioBuses *buses;
@@ -70,6 +80,20 @@ public:
};
+class EditorAudioBusDrop : public Panel {
+
+ GDCLASS(EditorAudioBusDrop,Panel);
+
+ virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
+ virtual void drop_data(const Point2& p_point,const Variant& p_data);
+protected:
+
+ static void _bind_methods();
+public:
+
+ EditorAudioBusDrop();
+};
+
class EditorAudioBuses : public VBoxContainer {
GDCLASS(EditorAudioBuses,VBoxContainer)
@@ -84,11 +108,17 @@ class EditorAudioBuses : public VBoxContainer {
ScrollContainer *group_scroll;
HBoxContainer *group_hb;
+ EditorAudioBusDrop *drop_end;
+
void _add_bus();
void _update_buses();
void _update_bus(int p_index);
void _update_sends();
+ void _delete_bus(Object* p_which);
+
+ void _request_drop_end();
+ void _drop_at_index(int p_bus,int p_index);
protected:
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 9adb82a3b4..2d66429ea5 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -55,7 +55,7 @@
#include "animation_editor.h"
#include "io/stream_peer_ssl.h"
#include "main/input_default.h"
-
+#include "os/input.h"
// plugins
#include "plugins/sprite_frames_editor_plugin.h"
#include "plugins/texture_region_editor_plugin.h"
@@ -2405,8 +2405,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
case EDIT_UNDO: {
- if (OS::get_singleton()->get_mouse_button_state())
+
+
+ if (Input::get_singleton()->get_mouse_button_mask()&0x7) {
+ print_line("no because state");
break; // can't undo while mouse buttons are pressed
+ }
String action = editor_data.get_undo_redo().get_current_action_name();
if (action!="")
@@ -2416,7 +2420,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
} break;
case EDIT_REDO: {
- if (OS::get_singleton()->get_mouse_button_state())
+ if (Input::get_singleton()->get_mouse_button_mask()&0x7)
break; // can't redo while mouse buttons are pressed
editor_data.get_undo_redo().redo();