summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/editor_node.cpp2
-rw-r--r--tools/editor/editor_plugin.cpp7
-rw-r--r--tools/editor/editor_plugin.h3
-rw-r--r--tools/editor/editor_resource_preview.cpp42
-rw-r--r--tools/editor/editor_resource_preview.h8
5 files changed, 60 insertions, 2 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 655652ced9..56170e1489 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -4139,6 +4139,8 @@ void EditorNode::register_editor_types() {
//ObjectTypeDB::register_type<EditorImportExport>();
ObjectTypeDB::register_type<EditorSettings>();
ObjectTypeDB::register_type<EditorSpatialGizmo>();
+ ObjectTypeDB::register_type<EditorResourcePreview>();
+ ObjectTypeDB::register_type<EditorResourcePreviewGenerator>();
//ObjectTypeDB::register_type<EditorImporter>();
diff --git a/tools/editor/editor_plugin.cpp b/tools/editor/editor_plugin.cpp
index fa5de096e0..752e961c87 100644
--- a/tools/editor/editor_plugin.cpp
+++ b/tools/editor/editor_plugin.cpp
@@ -32,6 +32,7 @@
#include "plugins/spatial_editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "tools/editor/editor_settings.h"
+#include "editor_resource_preview.h"
void EditorPlugin::add_custom_type(const String& p_type, const String& p_base,const Ref<Script>& p_script, const Ref<Texture>& p_icon) {
@@ -272,6 +273,10 @@ EditorSettings *EditorPlugin::get_editor_settings() {
return EditorSettings::get_singleton();
}
+EditorResourcePreview *EditorPlugin::get_resource_previewer() {
+ return EditorResourcePreview::get_singleton();
+}
+
void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) {
EditorNode::get_singleton()->add_editor_import_plugin(p_editor_import);
@@ -319,6 +324,8 @@ void EditorPlugin::_bind_methods() {
ObjectTypeDB::bind_method(_MD("add_export_plugin","plugin:EditorExportPlugin"),&EditorPlugin::add_export_plugin);
ObjectTypeDB::bind_method(_MD("remove_export_plugin","plugin:EditorExportPlugin"),&EditorPlugin::remove_export_plugin);
+ ObjectTypeDB::bind_method(_MD("get_resource_previewer:EditorResourcePreview"),&EditorPlugin::get_resource_previewer);
+
ObjectTypeDB::bind_method(_MD("inspect_object","object","for_property"),&EditorPlugin::inspect_object,DEFVAL(String()));
ObjectTypeDB::bind_method(_MD("get_base_control:Control"),&EditorPlugin::get_base_control);
diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h
index 69aea402d5..ed949c74f6 100644
--- a/tools/editor/editor_plugin.h
+++ b/tools/editor/editor_plugin.h
@@ -34,6 +34,7 @@
#include "scene/resources/texture.h"
#include "undo_redo.h"
#include "io/config_file.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -47,6 +48,7 @@ class EditorSettings;
class SpatialEditorGizmo;
class EditorImportPlugin;
class EditorExportPlugin;
+class EditorResourcePreview;
class EditorPlugin : public Node {
@@ -134,6 +136,7 @@ public:
EditorSelection* get_selection();
//EditorImportExport *get_import_export();
EditorSettings *get_editor_settings();
+ EditorResourcePreview *get_resource_previewer();
virtual void restore_global_state();
virtual void save_global_state();
diff --git a/tools/editor/editor_resource_preview.cpp b/tools/editor/editor_resource_preview.cpp
index a02fe2a531..6afc3e2a34 100644
--- a/tools/editor/editor_resource_preview.cpp
+++ b/tools/editor/editor_resource_preview.cpp
@@ -35,14 +35,46 @@
#include "editor_scale.h"
#include "message_queue.h"
+bool EditorResourcePreviewGenerator::handles(const String& p_type) const {
+
+ if (get_script_instance() && get_script_instance()->has_method("handles")) {
+ return get_script_instance()->call("handles",p_type);
+ }
+ ERR_EXPLAIN("EditorResourcePreviewGenerator::handles needs to be overriden");
+ ERR_FAIL_V(false);
+}
+Ref<Texture> EditorResourcePreviewGenerator::generate(const RES& p_from){
+
+ if (get_script_instance() && get_script_instance()->has_method("generate")) {
+ return get_script_instance()->call("generate",p_from);
+ }
+ ERR_EXPLAIN("EditorResourcePreviewGenerator::generate needs to be overriden");
+ ERR_FAIL_V(Ref<Texture>());
+
+}
+
+
Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String& p_path) {
+ if (get_script_instance() && get_script_instance()->has_method("generate_from_path")) {
+ return get_script_instance()->call("generate_from_path",p_path);
+ }
+
RES res = ResourceLoader::load(p_path);
if (!res.is_valid())
return res;
return generate(res);
}
+
+void EditorResourcePreviewGenerator::_bind_methods() {
+
+ ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"handles",PropertyInfo(Variant::STRING,"type")));
+ ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::OBJECT,"generate:Texture",PropertyInfo(Variant::OBJECT,"from",PROPERTY_HINT_RESOURCE_TYPE,"Resource")));
+ ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::OBJECT,"generate_from_path:Texture",PropertyInfo(Variant::STRING,"path",PROPERTY_HINT_FILE)));
+
+}
+
EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() {
@@ -330,6 +362,11 @@ void EditorResourcePreview::add_preview_generator(const Ref<EditorResourcePrevie
preview_generators.push_back(p_generator);
}
+void EditorResourcePreview::remove_preview_generator(const Ref<EditorResourcePreviewGenerator>& p_generator) {
+
+ preview_generators.erase(p_generator);
+}
+
EditorResourcePreview* EditorResourcePreview::get_singleton() {
return singleton;
@@ -338,6 +375,11 @@ EditorResourcePreview* EditorResourcePreview::get_singleton() {
void EditorResourcePreview::_bind_methods() {
ObjectTypeDB::bind_method("_preview_ready",&EditorResourcePreview::_preview_ready);
+
+ ObjectTypeDB::bind_method(_MD("queue_resource_preview","path","receiver","receiver_func","userdata:Variant"),&EditorResourcePreview::queue_resource_preview);
+ ObjectTypeDB::bind_method(_MD("queue_edited_resource_preview","resource:Resource","receiver","receiver_func","userdata:Variant"),&EditorResourcePreview::queue_edited_resource_preview);
+ ObjectTypeDB::bind_method(_MD("add_preview_generator","generator:EditorResourcePreviewGenerator"),&EditorResourcePreview::add_preview_generator);
+ ObjectTypeDB::bind_method(_MD("remove_preview_generator","generator:EditorResourcePreviewGenerator"),&EditorResourcePreview::remove_preview_generator);
ObjectTypeDB::bind_method(_MD("check_for_invalidation","path"),&EditorResourcePreview::check_for_invalidation);
diff --git a/tools/editor/editor_resource_preview.h b/tools/editor/editor_resource_preview.h
index 51a00965eb..2756360130 100644
--- a/tools/editor/editor_resource_preview.h
+++ b/tools/editor/editor_resource_preview.h
@@ -57,10 +57,13 @@ class EditorResourcePreviewGenerator : public Reference {
OBJ_TYPE(EditorResourcePreviewGenerator,Reference );
+protected:
+
+ static void _bind_methods();
public:
- virtual bool handles(const String& p_type) const=0;
- virtual Ref<Texture> generate(const RES& p_from)=0;
+ virtual bool handles(const String& p_type) const;
+ virtual Ref<Texture> generate(const RES& p_from);
virtual Ref<Texture> generate_from_path(const String& p_path);
EditorResourcePreviewGenerator();
@@ -121,6 +124,7 @@ public:
void queue_edited_resource_preview(const Ref<Resource>& p_path, Object* p_receiver, const StringName& p_receiver_func, const Variant& p_userdata);
void add_preview_generator(const Ref<EditorResourcePreviewGenerator>& p_generator);
+ void remove_preview_generator(const Ref<EditorResourcePreviewGenerator>& p_generator);
void check_for_invalidation(const String& p_path);
EditorResourcePreview();