summaryrefslogtreecommitdiff
path: root/editor/editor_properties.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r--editor/editor_properties.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index e679222567..7f6b7d334c 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -35,6 +35,9 @@
#include "editor_node.h"
#include "editor_properties_array_dict.h"
#include "editor_scale.h"
+#include "scene/2d/gpu_particles_2d.h"
+#include "scene/3d/fog_volume.h"
+#include "scene/3d/gpu_particles_3d.h"
#include "scene/main/window.h"
#include "scene/resources/font.h"
@@ -2969,6 +2972,35 @@ void EditorPropertyResource::_update_property_bg() {
update();
}
+void EditorPropertyResource::_update_preferred_shader() {
+ Node *parent = get_parent();
+ EditorProperty *parent_property = nullptr;
+
+ while (parent && !parent_property) {
+ parent_property = Object::cast_to<EditorProperty>(parent);
+ parent = parent->get_parent();
+ }
+
+ if (parent_property) {
+ EditorShaderPicker *shader_picker = Object::cast_to<EditorShaderPicker>(resource_picker);
+ Object *object = parent_property->get_edited_object();
+ const StringName &property = parent_property->get_edited_property();
+
+ // Set preferred shader based on edited parent type.
+ if ((Object::cast_to<GPUParticles2D>(object) || Object::cast_to<GPUParticles3D>(object)) && property == SNAME("process_material")) {
+ shader_picker->set_preferred_mode(Shader::MODE_PARTICLES);
+ } else if (Object::cast_to<FogVolume>(object)) {
+ shader_picker->set_preferred_mode(Shader::MODE_FOG);
+ } else if (Object::cast_to<CanvasItem>(object)) {
+ shader_picker->set_preferred_mode(Shader::MODE_CANVAS_ITEM);
+ } else if (Object::cast_to<Node3D>(object)) {
+ shader_picker->set_preferred_mode(Shader::MODE_SPATIAL);
+ } else if (Object::cast_to<Sky>(object)) {
+ shader_picker->set_preferred_mode(Shader::MODE_SKY);
+ }
+ }
+}
+
void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
Node *to_node = get_node(p_path);
if (!Object::cast_to<Viewport>(to_node)) {
@@ -3000,6 +3032,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const
EditorShaderPicker *shader_picker = memnew(EditorShaderPicker);
shader_picker->set_edited_material(Object::cast_to<ShaderMaterial>(p_object));
resource_picker = shader_picker;
+ connect(SNAME("ready"), callable_mp(this, &EditorPropertyResource::_update_preferred_shader));
} else {
resource_picker = memnew(EditorResourcePicker);
}