Browse Source

Fix MeshLibrary editor

Michael Alexsander Silva Dias 7 years ago
parent
commit
d0f55ab6e4

+ 1 - 1
editor/editor_node.cpp

@@ -84,7 +84,6 @@
 #include "editor/plugins/collision_polygon_editor_plugin.h"
 #include "editor/plugins/collision_shape_2d_editor_plugin.h"
 #include "editor/plugins/cpu_particles_editor_plugin.h"
-#include "editor/plugins/cube_grid_theme_editor_plugin.h"
 #include "editor/plugins/curve_editor_plugin.h"
 #include "editor/plugins/editor_preview_plugins.h"
 #include "editor/plugins/gi_probe_editor_plugin.h"
@@ -95,6 +94,7 @@
 #include "editor/plugins/material_editor_plugin.h"
 #include "editor/plugins/mesh_editor_plugin.h"
 #include "editor/plugins/mesh_instance_editor_plugin.h"
+#include "editor/plugins/mesh_library_editor_plugin.h"
 #include "editor/plugins/multimesh_editor_plugin.h"
 #include "editor/plugins/navigation_polygon_editor_plugin.h"
 #include "editor/plugins/particles_2d_editor_plugin.h"

+ 22 - 19
editor/plugins/cube_grid_theme_editor_plugin.cpp → editor/plugins/mesh_library_editor_plugin.cpp

@@ -1,5 +1,5 @@
 /*************************************************************************/
-/*  cube_grid_theme_editor_plugin.cpp                                    */
+/*  mesh_library_editor_plugin.cpp                                       */
 /*************************************************************************/
 /*                       This file is part of:                           */
 /*                           GODOT ENGINE                                */
@@ -28,7 +28,7 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 
-#include "cube_grid_theme_editor_plugin.h"
+#include "mesh_library_editor_plugin.h"
 
 #include "editor/editor_node.h"
 #include "editor/editor_settings.h"
@@ -38,6 +38,7 @@
 #include "scene/3d/physics_body.h"
 #include "scene/main/viewport.h"
 #include "scene/resources/packed_scene.h"
+#include "spatial_editor_plugin.h"
 
 void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_theme) {
 
@@ -241,21 +242,20 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) {
 	add_child(file);
 	file->connect("file_selected", this, "_import_scene_cbk");
 
-	Panel *panel = memnew(Panel);
-	panel->set_anchors_and_margins_preset(Control::PRESET_WIDE);
-	add_child(panel);
-	MenuButton *options = memnew(MenuButton);
-	panel->add_child(options);
-	options->set_position(Point2(1, 1));
-	options->set_text("Theme");
-	options->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM);
-	options->get_popup()->add_item(TTR("Remove Selected Item"), MENU_OPTION_REMOVE_ITEM);
-	options->get_popup()->add_separator();
-	options->get_popup()->add_item(TTR("Import from Scene"), MENU_OPTION_IMPORT_FROM_SCENE);
-	options->get_popup()->add_item(TTR("Update from Scene"), MENU_OPTION_UPDATE_FROM_SCENE);
-	options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), true);
-	options->get_popup()->connect("id_pressed", this, "_menu_cbk");
-	menu = options;
+	menu = memnew(MenuButton);
+	SpatialEditor::get_singleton()->add_control_to_menu_panel(menu);
+	menu->set_position(Point2(1, 1));
+	menu->set_text("Mesh Library");
+	menu->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshLibrary", "EditorIcons"));
+	menu->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM);
+	menu->get_popup()->add_item(TTR("Remove Selected Item"), MENU_OPTION_REMOVE_ITEM);
+	menu->get_popup()->add_separator();
+	menu->get_popup()->add_item(TTR("Import from Scene"), MENU_OPTION_IMPORT_FROM_SCENE);
+	menu->get_popup()->add_item(TTR("Update from Scene"), MENU_OPTION_UPDATE_FROM_SCENE);
+	menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), true);
+	menu->get_popup()->connect("id_pressed", this, "_menu_cbk");
+	menu->hide();
+
 	editor = p_editor;
 	cd = memnew(ConfirmationDialog);
 	add_child(cd);
@@ -278,10 +278,13 @@ bool MeshLibraryEditorPlugin::handles(Object *p_node) const {
 
 void MeshLibraryEditorPlugin::make_visible(bool p_visible) {
 
-	if (p_visible)
+	if (p_visible) {
 		theme_editor->show();
-	else
+		theme_editor->get_menu_button()->show();
+	} else {
 		theme_editor->hide();
+		theme_editor->get_menu_button()->hide();
+	}
 }
 
 MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) {

+ 6 - 4
editor/plugins/cube_grid_theme_editor_plugin.h → editor/plugins/mesh_library_editor_plugin.h

@@ -1,5 +1,5 @@
 /*************************************************************************/
-/*  cube_grid_theme_editor_plugin.h                                      */
+/*  mesh_library_editor_plugin.h                                         */
 /*************************************************************************/
 /*                       This file is part of:                           */
 /*                           GODOT ENGINE                                */
@@ -28,8 +28,8 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 
-#ifndef CUBE_GRID_THEME_EDITOR_PLUGIN_H
-#define CUBE_GRID_THEME_EDITOR_PLUGIN_H
+#ifndef MESH_LIBRARY_EDITOR_PLUGIN_H
+#define MESH_LIBRARY_EDITOR_PLUGIN_H
 
 #include "editor/editor_node.h"
 #include "scene/resources/mesh_library.h"
@@ -65,6 +65,8 @@ protected:
 	static void _bind_methods();
 
 public:
+	MenuButton *get_menu_button() const { return menu; }
+
 	void edit(const Ref<MeshLibrary> &p_theme);
 	static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge = true);
 
@@ -88,4 +90,4 @@ public:
 	MeshLibraryEditorPlugin(EditorNode *p_node);
 };
 
-#endif // CUBE_GRID_THEME_EDITOR_PLUGIN_H
+#endif // MESH_LIBRARY_EDITOR_PLUGIN_H