Skip to content

Commit

Permalink
Merge pull request godotengine#4174 from Hodes/master
Browse files Browse the repository at this point in the history
Multiple editor plugins for same obj type
  • Loading branch information
akien-mga committed Apr 6, 2016
2 parents 2f12c2d + 7a1d7af commit aad31ee
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 37 deletions.
10 changes: 10 additions & 0 deletions tools/editor/editor_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ EditorPlugin* EditorData::get_subeditor(Object *p_object) {
return NULL;
}

Vector<EditorPlugin*> EditorData::get_subeditors(Object* p_object) {
Vector<EditorPlugin*> sub_plugins;
for (int i = 0; i < editor_plugins.size(); i++) {
if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
sub_plugins.push_back(editor_plugins[i]);
}
}
return sub_plugins;
}

EditorPlugin* EditorData::get_editor(String p_name) {

for(int i=0;i<editor_plugins.size();i++) {
Expand Down
1 change: 1 addition & 0 deletions tools/editor/editor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class EditorData {

EditorPlugin* get_editor(Object *p_object);
EditorPlugin* get_subeditor(Object *p_object);
Vector<EditorPlugin*> get_subeditors(Object *p_object);
EditorPlugin* get_editor(String p_name);

void copy_object_params(Object *p_object);
Expand Down
116 changes: 92 additions & 24 deletions tools/editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,15 +1571,27 @@ void EditorNode::_imported(Node *p_node) {
}


void EditorNode::_hide_top_editors() {

_display_top_editors(false);

void EditorNode::_hide_top_editors() {
editor_plugins_over->clear();
}

void EditorNode::_display_top_editors(bool p_display) {
editor_plugins_over->make_visible(p_display);
}

void EditorNode::_set_top_editors(Vector<EditorPlugin*> p_editor_plugins_over) {
editor_plugins_over->set_plugins_list(p_editor_plugins_over);
}

if (editor_plugin_over)
editor_plugin_over->make_visible(false);
editor_plugin_over=NULL;
void EditorNode::_set_editing_top_editors(Object* p_current_object) {
editor_plugins_over->edit(p_current_object);
}



void EditorNode::_edit_current() {

uint32_t current = editor_history.get_current();
Expand All @@ -1598,8 +1610,7 @@ void EditorNode::_edit_current() {
property_editor->edit( NULL );
object_menu->set_disabled(true);

if (editor_plugin_over)
editor_plugin_over->make_visible(false);
_display_top_editors(false);

return;
}
Expand Down Expand Up @@ -1679,20 +1690,18 @@ void EditorNode::_edit_current() {

}

EditorPlugin *sub_plugin = editor_data.get_subeditor(current_obj);

if (sub_plugin) {
Vector<EditorPlugin*> sub_plugins = editor_data.get_subeditors(current_obj);

if (!sub_plugins.empty()) {
_display_top_editors(false);

if (editor_plugin_over)
editor_plugin_over->make_visible(false);
editor_plugin_over=sub_plugin;
editor_plugin_over->edit(current_obj);
editor_plugin_over->make_visible(true);
} else if (editor_plugin_over) {
_set_top_editors(sub_plugins);
_set_editing_top_editors(current_obj);
_display_top_editors(true);

} else if (!editor_plugins_over->get_plugins_list().empty()) {

editor_plugin_over->make_visible(false);
editor_plugin_over=NULL;
_hide_top_editors();

}
/*
Expand Down Expand Up @@ -2583,10 +2592,9 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
}

editor_data.get_undo_redo().clear_history();
if (editor_plugin_over) { //reload editor plugin
editor_plugin_over->edit(NULL);
editor_plugin_over->edit(current);
}

_set_editing_top_editors(NULL);
_set_editing_top_editors(current);

} break;
case OBJECT_CALL_METHOD: {
Expand Down Expand Up @@ -6138,7 +6146,7 @@ EditorNode::EditorNode() {
_rebuild_import_menu();

editor_plugin_screen=NULL;
editor_plugin_over=NULL;
editor_plugins_over = memnew(EditorPluginList);

// force_top_viewport(true);
_edit_current();
Expand Down Expand Up @@ -6270,12 +6278,72 @@ EditorNode::EditorNode() {


EditorNode::~EditorNode() {



memdelete( EditorHelp::get_doc_data() );
memdelete(editor_selection);
memdelete(editor_plugins_over);
memdelete(file_server);
EditorSettings::destroy();
}

/*
* EDITOR PLUGIN LIST
*/


void EditorPluginList::make_visible(bool p_visible) {
if (!plugins_list.empty()) {
for (int i = 0; i < plugins_list.size(); i++) {
plugins_list[i]->make_visible(p_visible);
}
}
}

void EditorPluginList::edit(Object* p_object) {
if (!plugins_list.empty()) {
for (int i = 0; i < plugins_list.size(); i++) {
plugins_list[i]->edit(p_object);
}
}
}

bool EditorPluginList::forward_input_event(const InputEvent& p_event) {
bool discard = false;
if (!plugins_list.empty()) {
for (int i = 0; i < plugins_list.size(); i++) {
if (plugins_list[i]->forward_input_event(p_event)) {
discard = true;
}
}
}
return discard;
}

bool EditorPluginList::forward_spatial_input_event(Camera* p_camera, const InputEvent& p_event) {
bool discard = false;
if (!plugins_list.empty()) {
for (int i = 0; i < plugins_list.size(); i++) {
if (plugins_list[i]->forward_spatial_input_event(p_camera, p_event)) {
discard = true;
}
}
}
return discard;
}

bool EditorPluginList::empty() {
return plugins_list.empty();
}

void EditorPluginList::clear() {
plugins_list.clear();
}

EditorPluginList::EditorPluginList() {
}

EditorPluginList::~EditorPluginList() {
}



36 changes: 33 additions & 3 deletions tools/editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

typedef void (*EditorNodeInitCallback)();


class EditorPluginList;

class EditorNode : public Node {

Expand Down Expand Up @@ -372,7 +372,7 @@ class EditorNode : public Node {

Vector<EditorPlugin*> editor_plugins;
EditorPlugin *editor_plugin_screen;
EditorPlugin *editor_plugin_over;
EditorPluginList *editor_plugins_over;

EditorHistory editor_history;
EditorData editor_data;
Expand Down Expand Up @@ -449,6 +449,10 @@ class EditorNode : public Node {
void _transform_keyed(Object *sp,const String& p_sub,const Transform& p_key);

void _hide_top_editors();
void _display_top_editors(bool p_display);
void _set_top_editors(Vector<EditorPlugin*> p_editor_plugins_over);
void _set_editing_top_editors(Object * p_current_object);

void _quick_opened();
void _quick_run();

Expand Down Expand Up @@ -575,7 +579,7 @@ class EditorNode : public Node {


EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
EditorPlugin *get_editor_plugin_over() { return editor_plugin_over; }
EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
PropertyEditor *get_property_editor() { return property_editor; }

static void add_editor_plugin(EditorPlugin *p_editor);
Expand Down Expand Up @@ -710,6 +714,32 @@ struct EditorProgress {
~EditorProgress() { EditorNode::progress_end_task(task); }
};

class EditorPluginList : public Object {
private:
Vector<EditorPlugin*> plugins_list;

public:

void set_plugins_list(Vector<EditorPlugin*> p_plugins_list) {
plugins_list = p_plugins_list;
}

Vector<EditorPlugin*> get_plugins_list() {
return plugins_list;
}

void make_visible(bool p_visible);
void edit(Object *p_object);
bool forward_input_event(const InputEvent& p_event);
bool forward_spatial_input_event(Camera* p_camera, const InputEvent& p_event);
void clear();
bool empty();

EditorPluginList();
~EditorPluginList();

} ;

struct EditorProgressBG {

String task;
Expand Down
6 changes: 3 additions & 3 deletions tools/editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,10 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
{

EditorNode *en = editor;
EditorPlugin *over_plugin = en->get_editor_plugin_over();
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();

if (over_plugin) {
bool discard = over_plugin->forward_input_event(p_event);
if (!over_plugin_list->empty()) {
bool discard = over_plugin_list->forward_input_event(p_event);
if (discard) {
accept_event();
return;
Expand Down
10 changes: 5 additions & 5 deletions tools/editor/plugins/spatial_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,10 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
{

EditorNode *en = editor;
EditorPlugin *over_plugin = en->get_editor_plugin_over();
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();

if (over_plugin) {
bool discard = over_plugin->forward_spatial_input_event(camera,p_event);
if (!over_plugin_list->empty()) {
bool discard = over_plugin_list->forward_spatial_input_event(camera,p_event);
if (discard)
return;
}
Expand Down Expand Up @@ -3576,9 +3576,9 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) {
{

EditorNode *en = editor;
EditorPlugin *over_plugin = en->get_editor_plugin_over();
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();

if (over_plugin && over_plugin->forward_input_event(p_event)) {
if (!over_plugin_list->empty() && over_plugin_list->forward_input_event(p_event)) {

return; //ate the over input event
}
Expand Down
3 changes: 1 addition & 2 deletions tools/editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,8 +1098,7 @@ void SceneTreeDock::_delete_confirm() {
return;


if (editor->get_editor_plugin_over())
editor->get_editor_plugin_over()->make_visible(false);
editor->get_editor_plugins_over()->make_visible(false);

editor_data->get_undo_redo().create_action("Remove Node(s)");

Expand Down

0 comments on commit aad31ee

Please sign in to comment.