From c6f28925e2aec9889132932356a041a1693ca812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Waldson=20Patr=C3=ADcio?= Date: Wed, 6 Dec 2017 19:27:45 -0300 Subject: [PATCH] Add method to set main screen plugin icon --- editor/editor_node.cpp | 17 +++++++++++++++-- editor/editor_plugin.cpp | 9 +++++++++ editor/editor_plugin.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index d6c8d651939..604f15a76f4 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -337,7 +337,13 @@ void EditorNode::_notification(int p_what) { //_update_icons for (int i = 0; i < singleton->main_editor_buttons.size(); i++) { - main_editor_buttons[i]->set_icon(gui_base->get_icon(singleton->main_editor_buttons[i]->get_name(), "EditorIcons")); + Ref icon = singleton->main_editor_buttons[i]->get_icon(); + + if (icon.is_valid()) { + main_editor_buttons[i]->set_icon(icon); + } else if (singleton->gui_base->has_icon(singleton->main_editor_buttons[i]->get_name(), "EditorIcons")) { + main_editor_buttons[i]->set_icon(gui_base->get_icon(singleton->main_editor_buttons[i]->get_name(), "EditorIcons")); + } } play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons")); play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons")); @@ -2670,7 +2676,14 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor) { tb->set_toggle_mode(true); tb->connect("pressed", singleton, "_editor_select", varray(singleton->main_editor_buttons.size())); tb->set_text(p_editor->get_name()); - tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons")); + Ref icon = p_editor->get_icon(); + + if (icon.is_valid()) { + tb->set_icon(icon); + } else if (singleton->gui_base->has_icon(p_editor->get_name(), "EditorIcons")) { + tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons")); + } + tb->set_name(p_editor->get_name()); singleton->main_editor_buttons.push_back(tb); singleton->main_editor_button_vb->add_child(tb); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index c1fbcde6ac8..9b1a3cbd72e 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -466,6 +466,14 @@ String EditorPlugin::get_name() const { return String(); } +const Ref EditorPlugin::get_icon() const { + + if (get_script_instance() && get_script_instance()->has_method("get_plugin_icon")) { + return get_script_instance()->call("get_plugin_icon"); + } + + return Ref(); +} bool EditorPlugin::has_main_screen() const { if (get_script_instance() && get_script_instance()->has_method("has_main_screen")) { @@ -644,6 +652,7 @@ void EditorPlugin::_bind_methods() { gizmo.return_val.hint_string = "EditorSpatialGizmo"; ClassDB::add_virtual_method(get_class_static(), gizmo); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_plugin_name")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::OBJECT, "get_plugin_icon")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "has_main_screen")); ClassDB::add_virtual_method(get_class_static(), MethodInfo("make_visible", PropertyInfo(Variant::BOOL, "visible"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo("edit", PropertyInfo(Variant::OBJECT, "object"))); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 11f43786671..31b887b30f4 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -165,6 +165,7 @@ public: virtual void forward_force_draw_over_viewport(Control *p_overlay); virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref &p_event); virtual String get_name() const; + virtual const Ref get_icon() const; virtual bool has_main_screen() const; virtual void make_visible(bool p_visible); virtual void selected_notify() {} //notify that it was raised by the user, not the editor