summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/doc_data.cpp34
-rw-r--r--editor/editor_data.cpp4
-rw-r--r--editor/editor_data.h2
-rw-r--r--editor/editor_help.cpp14
-rw-r--r--editor/editor_node.cpp7
-rw-r--r--editor/editor_settings.cpp2
-rw-r--r--editor/import/resource_importer_shader_file.cpp90
-rw-r--r--editor/import/resource_importer_shader_file.h27
-rw-r--r--editor/node_3d_editor_gizmos.cpp15
-rw-r--r--editor/node_3d_editor_gizmos.h5
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp22
-rw-r--r--editor/plugins/node_3d_editor_plugin.h9
-rw-r--r--editor/plugins/script_text_editor.cpp2
-rw-r--r--editor/plugins/shader_file_editor_plugin.cpp303
-rw-r--r--editor/plugins/shader_file_editor_plugin.h64
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp11
-rw-r--r--editor/scene_tree_dock.cpp1
17 files changed, 597 insertions, 15 deletions
diff --git a/editor/doc_data.cpp b/editor/doc_data.cpp
index 096be1fe4b..310e78ee60 100644
--- a/editor/doc_data.cpp
+++ b/editor/doc_data.cpp
@@ -40,6 +40,9 @@
#include "core/version.h"
#include "scene/resources/theme.h"
+// Used for a hack preserving Mono properties on non-Mono builds.
+#include "modules/modules_enabled.gen.h"
+
void DocData::merge_from(const DocData &p_data) {
for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
@@ -154,6 +157,23 @@ void DocData::merge_from(const DocData &p_data) {
break;
}
}
+
+#ifndef MODULE_MONO_ENABLED
+ // The Mono module defines some properties that we want to keep when
+ // re-generating docs with a non-Mono build, to prevent pointless diffs
+ // (and loss of descriptions) depending on the config of the doc writer.
+ // We use a horrible hack to force keeping the relevant properties,
+ // hardcoded below. At least it's an ad hoc hack... ¯\_(ツ)_/¯
+ // Don't show this to your kids.
+ if (c.name == "@GlobalScope") {
+ // Retrieve GodotSharp singleton.
+ for (int j = 0; j < cf.properties.size(); j++) {
+ if (cf.properties[j].name == "GodotSharp") {
+ c.properties.push_back(cf.properties[j]);
+ }
+ }
+ }
+#endif
}
}
@@ -173,6 +193,8 @@ static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const Property
p_method.return_type = "int";
} else if (p_retinfo.class_name != StringName()) {
p_method.return_type = p_retinfo.class_name;
+ } else if (p_retinfo.type == Variant::ARRAY && p_retinfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+ p_method.return_type = p_retinfo.hint_string + "[]";
} else if (p_retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
p_method.return_type = p_retinfo.hint_string;
} else if (p_retinfo.type == Variant::NIL && p_retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
@@ -195,6 +217,8 @@ static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const Pr
p_argument.type = "int";
} else if (p_arginfo.class_name != StringName()) {
p_argument.type = p_arginfo.class_name;
+ } else if (p_arginfo.type == Variant::ARRAY && p_arginfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+ p_argument.type = p_arginfo.hint_string + "[]";
} else if (p_arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
p_argument.type = p_arginfo.hint_string;
} else if (p_arginfo.type == Variant::NIL) {
@@ -243,6 +267,12 @@ void DocData::generate(bool p_basic_types) {
Set<StringName> setters_getters;
String name = classes.front()->get();
+ if (!ClassDB::is_class_exposed(name)) {
+ print_verbose(vformat("Class '%s' is not exposed, skipping.", name));
+ classes.pop_front();
+ continue;
+ }
+
String cname = name;
if (cname.begins_with("_")) //proxy class
cname = cname.substr(1, name.length());
@@ -271,7 +301,7 @@ void DocData::generate(bool p_basic_types) {
EO = EO->next();
}
- if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL)
+ if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL)
continue;
PropertyDoc prop;
@@ -328,6 +358,8 @@ void DocData::generate(bool p_basic_types) {
prop.type = "int";
} else if (retinfo.class_name != StringName()) {
prop.type = retinfo.class_name;
+ } else if (retinfo.type == Variant::ARRAY && retinfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+ prop.type = retinfo.hint_string + "[]";
} else if (retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
prop.type = retinfo.hint_string;
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 942b4a8ee6..9c739474d1 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -1066,9 +1066,9 @@ Array EditorSelection::_get_transformable_selected_nodes() {
return ret;
}
-Array EditorSelection::get_selected_nodes() {
+TypedArray<Node> EditorSelection::get_selected_nodes() {
- Array ret;
+ TypedArray<Node> ret;
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
diff --git a/editor/editor_data.h b/editor/editor_data.h
index 4f5d68bfed..e4f4c67c8e 100644
--- a/editor/editor_data.h
+++ b/editor/editor_data.h
@@ -257,7 +257,7 @@ protected:
static void _bind_methods();
public:
- Array get_selected_nodes();
+ TypedArray<Node> get_selected_nodes();
void add_node(Node *p_node);
void remove_node(Node *p_node);
bool is_selected(Node *) const;
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index a36e2f360e..bad70d9714 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -198,7 +198,12 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
const Color text_color = get_theme_color("default_color", "RichTextLabel");
const Color type_color = get_theme_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
class_desc->push_color(type_color);
+ bool add_array = false;
if (can_ref) {
+ if (t.ends_with("[]")) {
+ add_array = true;
+ t = t.replace("[]", "");
+ }
if (p_enum.empty()) {
class_desc->push_meta("#" + t); //class
} else {
@@ -206,8 +211,15 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
}
}
class_desc->add_text(t);
- if (can_ref)
+ if (can_ref) {
class_desc->pop();
+ if (add_array) {
+ class_desc->add_text(" ");
+ class_desc->push_meta("#Array"); //class
+ class_desc->add_text("[]");
+ class_desc->pop();
+ }
+ }
class_desc->pop();
}
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 849908c132..3569cd411d 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -98,6 +98,7 @@
#include "editor/import/resource_importer_layered_texture.h"
#include "editor/import/resource_importer_obj.h"
#include "editor/import/resource_importer_scene.h"
+#include "editor/import/resource_importer_shader_file.h"
#include "editor/import/resource_importer_texture.h"
#include "editor/import/resource_importer_texture_atlas.h"
#include "editor/import/resource_importer_wav.h"
@@ -148,6 +149,7 @@
#include "editor/plugins/script_editor_plugin.h"
#include "editor/plugins/script_text_editor.h"
#include "editor/plugins/shader_editor_plugin.h"
+#include "editor/plugins/shader_file_editor_plugin.h"
#include "editor/plugins/skeleton_2d_editor_plugin.h"
#include "editor/plugins/skeleton_3d_editor_plugin.h"
#include "editor/plugins/skeleton_ik_3d_editor_plugin.h"
@@ -5716,6 +5718,10 @@ EditorNode::EditorNode() {
import_obj.instance();
ResourceFormatImporter::get_singleton()->add_importer(import_obj);
+ Ref<ResourceImporterShaderFile> import_shader_file;
+ import_shader_file.instance();
+ ResourceFormatImporter::get_singleton()->add_importer(import_shader_file);
+
Ref<ResourceImporterScene> import_scene;
import_scene.instance();
ResourceFormatImporter::get_singleton()->add_importer(import_scene);
@@ -6633,6 +6639,7 @@ EditorNode::EditorNode() {
add_editor_plugin(VersionControlEditorPlugin::get_singleton());
add_editor_plugin(memnew(ShaderEditorPlugin(this)));
+ add_editor_plugin(memnew(ShaderFileEditorPlugin(this)));
add_editor_plugin(memnew(VisualShaderEditorPlugin(this)));
add_editor_plugin(memnew(Camera3DEditorPlugin(this)));
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 5d5bb1242d..9b58c18f51 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -559,6 +559,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
hints["editors/3d/navigation_feel/manipulation_translation_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/manipulation_translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
// 3D: Freelook
+ _initial_set("editors/3d/freelook/freelook_navigation_scheme", false);
+ hints["editors/3d/freelook/freelook_navigation_scheme"] = PropertyInfo(Variant::INT, "editors/3d/freelook/freelook_navigation_scheme", PROPERTY_HINT_ENUM, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)");
_initial_set("editors/3d/freelook/freelook_inertia", 0.1);
hints["editors/3d/freelook/freelook_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/freelook/freelook_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
_initial_set("editors/3d/freelook/freelook_base_speed", 5.0);
diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp
new file mode 100644
index 0000000000..a2f178de12
--- /dev/null
+++ b/editor/import/resource_importer_shader_file.cpp
@@ -0,0 +1,90 @@
+#include "resource_importer_shader_file.h"
+
+#include "core/io/marshalls.h"
+#include "core/io/resource_saver.h"
+#include "core/os/file_access.h"
+#include "editor/editor_node.h"
+#include "editor/plugins/shader_file_editor_plugin.h"
+#include "servers/rendering/rendering_device_binds.h"
+
+String ResourceImporterShaderFile::get_importer_name() const {
+
+ return "glsl";
+}
+
+String ResourceImporterShaderFile::get_visible_name() const {
+
+ return "GLSL Shader File";
+}
+void ResourceImporterShaderFile::get_recognized_extensions(List<String> *p_extensions) const {
+
+ p_extensions->push_back("glsl");
+}
+String ResourceImporterShaderFile::get_save_extension() const {
+ return "res";
+}
+
+String ResourceImporterShaderFile::get_resource_type() const {
+
+ return "RDShaderFile";
+}
+
+int ResourceImporterShaderFile::get_preset_count() const {
+ return 0;
+}
+String ResourceImporterShaderFile::get_preset_name(int p_idx) const {
+
+ return String();
+}
+
+void ResourceImporterShaderFile::get_import_options(List<ImportOption> *r_options, int p_preset) const {
+}
+
+bool ResourceImporterShaderFile::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
+ return true;
+}
+static String _include_function(const String &p_path, void *userpointer) {
+ Error err;
+
+ String *base_path = (String *)userpointer;
+
+ String include = p_path;
+ if (include.is_rel_path()) {
+ include = base_path->plus_file(include);
+ }
+
+ FileAccessRef file_inc = FileAccess::open(include, FileAccess::READ, &err);
+ if (err != OK) {
+ return String();
+ }
+ return file_inc->get_as_utf8_string();
+}
+
+Error ResourceImporterShaderFile::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+
+ /* STEP 1, Read shader code */
+
+ Error err;
+ FileAccessRef file = FileAccess::open(p_source_file, FileAccess::READ, &err);
+ ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN);
+ ERR_FAIL_COND_V(!file.operator->(), ERR_CANT_OPEN);
+
+ String file_txt = file->get_as_utf8_string();
+ Ref<RDShaderFile> shader_file;
+ shader_file.instance();
+ String base_path = p_source_file.get_base_dir();
+ err = shader_file->parse_versions_from_text(file_txt, _include_function, &base_path);
+
+ if (err != OK) {
+ if (!ShaderFileEditor::singleton->is_visible_in_tree()) {
+ EditorNode::get_singleton()->add_io_error(vformat(TTR("Error importing GLSL shader file: '%s'. Open the file in the filesystem dock in order to see the reason."), p_source_file));
+ }
+ }
+
+ ResourceSaver::save(p_save_path + ".res", shader_file);
+
+ return OK;
+}
+
+ResourceImporterShaderFile::ResourceImporterShaderFile() {
+}
diff --git a/editor/import/resource_importer_shader_file.h b/editor/import/resource_importer_shader_file.h
new file mode 100644
index 0000000000..f6b50bee9e
--- /dev/null
+++ b/editor/import/resource_importer_shader_file.h
@@ -0,0 +1,27 @@
+#ifndef RESOURCE_IMPORTER_SHADER_FILE_H
+#define RESOURCE_IMPORTER_SHADER_FILE_H
+
+#include "core/io/resource_importer.h"
+
+class ResourceImporterShaderFile : public ResourceImporter {
+ GDCLASS(ResourceImporterShaderFile, ResourceImporter);
+
+public:
+ virtual String get_importer_name() const;
+ virtual String get_visible_name() const;
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual String get_save_extension() const;
+ virtual String get_resource_type() const;
+
+ virtual int get_preset_count() const;
+ virtual String get_preset_name(int p_idx) const;
+
+ virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
+ virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
+
+ virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr);
+
+ ResourceImporterShaderFile();
+};
+
+#endif // RESOURCE_IMPORTER_SHADER_FILE_H
diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp
index 724782ac44..31a8320209 100644
--- a/editor/node_3d_editor_gizmos.cpp
+++ b/editor/node_3d_editor_gizmos.cpp
@@ -4219,6 +4219,21 @@ Joint3DGizmoPlugin::Joint3DGizmoPlugin() {
create_material("joint_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)));
create_material("joint_body_a_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint_body_a", Color(0.6, 0.8, 1)));
create_material("joint_body_b_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint_body_b", Color(0.6, 0.9, 1)));
+
+ update_timer = memnew(Timer);
+ update_timer->set_name("JointGizmoUpdateTimer");
+ update_timer->set_wait_time(1.0 / 120.0);
+ update_timer->connect("timeout", callable_mp(this, &Joint3DGizmoPlugin::incremental_update_gizmos));
+ update_timer->set_autostart(true);
+ EditorNode::get_singleton()->call_deferred("add_child", update_timer);
+}
+
+void Joint3DGizmoPlugin::incremental_update_gizmos() {
+ if (!current_gizmos.empty()) {
+ update_idx++;
+ update_idx = update_idx % current_gizmos.size();
+ redraw(current_gizmos[update_idx]);
+ }
}
bool Joint3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
diff --git a/editor/node_3d_editor_gizmos.h b/editor/node_3d_editor_gizmos.h
index 8bc52b6ba9..6432feeecb 100644
--- a/editor/node_3d_editor_gizmos.h
+++ b/editor/node_3d_editor_gizmos.h
@@ -409,6 +409,11 @@ class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin);
+ Timer *update_timer;
+ uint64_t update_idx = 0;
+
+ void incremental_update_gizmos();
+
public:
bool has_gizmo(Node3D *p_spatial);
String get_name() const;
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 354c951a7c..f51b9b20e4 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -2287,9 +2287,27 @@ void Node3DEditorViewport::_update_freelook(real_t delta) {
return;
}
- const Vector3 forward = camera->get_transform().basis.xform(Vector3(0, 0, -1));
+ const FreelookNavigationScheme navigation_scheme = (FreelookNavigationScheme)EditorSettings::get_singleton()->get("editors/3d/freelook/freelook_navigation_scheme").operator int();
+
+ Vector3 forward;
+ if (navigation_scheme == FREELOOK_FULLY_AXIS_LOCKED) {
+ // Forward/backward keys will always go straight forward/backward, never moving on the Y axis.
+ forward = Vector3(0, 0, -1).rotated(Vector3(0, 1, 0), camera->get_rotation().y);
+ } else {
+ // Forward/backward keys will be relative to the camera pitch.
+ forward = camera->get_transform().basis.xform(Vector3(0, 0, -1));
+ }
+
const Vector3 right = camera->get_transform().basis.xform(Vector3(1, 0, 0));
- const Vector3 up = camera->get_transform().basis.xform(Vector3(0, 1, 0));
+
+ Vector3 up;
+ if (navigation_scheme == FREELOOK_PARTIALLY_AXIS_LOCKED || navigation_scheme == FREELOOK_FULLY_AXIS_LOCKED) {
+ // Up/down keys will always go up/down regardless of camera pitch.
+ up = Vector3(0, 1, 0);
+ } else {
+ // Up/down keys will be relative to the camera pitch.
+ up = camera->get_transform().basis.xform(Vector3(0, 1, 0));
+ }
Vector3 direction;
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index 2c3b15cfc8..71da14ae1a 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -241,6 +241,12 @@ public:
NAVIGATION_MODO,
};
+ enum FreelookNavigationScheme {
+ FREELOOK_DEFAULT,
+ FREELOOK_PARTIALLY_AXIS_LOCKED,
+ FREELOOK_FULLY_AXIS_LOCKED,
+ };
+
private:
float cpu_time_history[FRAME_TIME_HISTORY];
int cpu_time_history_index;
@@ -850,12 +856,11 @@ public:
static const int HIDDEN = 1;
static const int ON_TOP = 2;
-private:
+protected:
int current_state;
List<EditorNode3DGizmo *> current_gizmos;
HashMap<String, Vector<Ref<StandardMaterial3D>>> materials;
-protected:
static void _bind_methods();
virtual bool has_gizmo(Node3D *p_spatial);
virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 4b8383e1e5..1a77eeb9de 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -172,7 +172,7 @@ void ScriptTextEditor::_update_member_keywords() {
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
String name = E->get().name;
- if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP)
+ if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP)
continue;
if (name.find("/") != -1)
continue;
diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp
new file mode 100644
index 0000000000..296c7a01b6
--- /dev/null
+++ b/editor/plugins/shader_file_editor_plugin.cpp
@@ -0,0 +1,303 @@
+#include "shader_file_editor_plugin.h"
+
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
+#include "core/os/keyboard.h"
+#include "core/os/os.h"
+#include "editor/editor_node.h"
+#include "editor/editor_scale.h"
+#include "editor/editor_settings.h"
+#include "editor/property_editor.h"
+#include "servers/display_server.h"
+#include "servers/rendering/shader_types.h"
+
+/*** SHADER SCRIPT EDITOR ****/
+
+/*** SCRIPT EDITOR ******/
+
+void ShaderFileEditor::_update_version(const StringName &p_version_txt, const RD::ShaderStage p_stage) {
+}
+
+void ShaderFileEditor::_version_selected(int p_option) {
+
+ int c = versions->get_current();
+ StringName version_txt = versions->get_item_metadata(c);
+
+ RD::ShaderStage stage = RD::SHADER_STAGE_MAX;
+ int first_found = -1;
+
+ Ref<RDShaderBytecode> bytecode = shader_file->get_bytecode(version_txt);
+ ERR_FAIL_COND(bytecode.is_null());
+
+ for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
+ if (bytecode->get_stage_bytecode(RD::ShaderStage(i)).empty() && bytecode->get_stage_compile_error(RD::ShaderStage(i)) == String()) {
+ stages[i]->set_icon(Ref<Texture2D>());
+ continue;
+ }
+
+ Ref<Texture2D> icon;
+ if (bytecode->get_stage_compile_error(RD::ShaderStage(i)) != String()) {
+ icon = get_theme_icon("ImportFail", "EditorIcons");
+ } else {
+ icon = get_theme_icon("ImportCheck", "EditorIcons");
+ }
+ stages[i]->set_icon(icon);
+
+ if (first_found == -1) {
+ first_found = i;
+ }
+
+ if (stages[i]->is_pressed()) {
+ stage = RD::ShaderStage(i);
+ break;
+ }
+ }
+
+ error_text->clear();
+
+ if (stage == RD::SHADER_STAGE_MAX) { //need to change stage, does not have it
+ if (first_found == -1) {
+ error_text->add_text(TTR("No valid shader stages found."));
+ return; //well you did not put any stage I guess?
+ }
+ stages[first_found]->set_pressed(true);
+ stage = RD::ShaderStage(first_found);
+ }
+
+ String error = bytecode->get_stage_compile_error(stage);
+
+ error_text->push_font(get_theme_font("source", "EditorFonts"));
+
+ if (error == String()) {
+ error_text->add_text(TTR("Shader stage compiled without errors."));
+ } else {
+ error_text->add_text(error);
+ }
+}
+
+void ShaderFileEditor::_update_options() {
+
+ ERR_FAIL_COND(shader_file.is_null());
+
+ if (shader_file->get_base_error() != String()) {
+ stage_hb->hide();
+ versions->hide();
+ error_text->clear();
+ error_text->push_font(get_theme_font("source", "EditorFonts"));
+ error_text->add_text(vformat(TTR("File structure for '%s' contains unrecoverable errors:\n\n"), shader_file->get_path().get_file()));
+ error_text->add_text(shader_file->get_base_error());
+ return;
+ }
+
+ stage_hb->show();
+ versions->show();
+
+ int c = versions->get_current();
+ //remember current
+ versions->clear();
+ Vector<StringName> version_list = shader_file->get_version_list();
+
+ if (c >= version_list.size()) {
+ c = version_list.size() - 1;
+ }
+ if (c < 0) {
+ c = 0;
+ }
+
+ StringName current_version;
+
+ for (int i = 0; i < version_list.size(); i++) {
+ String title = version_list[i];
+ if (title == "") {
+ title = "default";
+ }
+
+ Ref<Texture2D> icon;
+
+ Ref<RDShaderBytecode> bytecode = shader_file->get_bytecode(version_list[i]);
+ ERR_FAIL_COND(bytecode.is_null());
+
+ bool failed = false;
+ for (int j = 0; j < RD::SHADER_STAGE_MAX; j++) {
+ String error = bytecode->get_stage_compile_error(RD::ShaderStage(j));
+ if (error != String()) {
+ failed = true;
+ }
+ }
+
+ if (failed) {
+ icon = get_theme_icon("ImportFail", "EditorIcons");
+ } else {
+ icon = get_theme_icon("ImportCheck", "EditorIcons");
+ }
+
+ versions->add_item(title, icon);
+ versions->set_item_metadata(i, version_list[i]);
+
+ if (i == c) {
+ versions->select(i);
+ current_version = version_list[i];
+ }
+ }
+
+ if (version_list.size() == 0) {
+ for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
+ stages[i]->set_disabled(true);
+ }
+ return;
+ }
+
+ Ref<RDShaderBytecode> bytecode = shader_file->get_bytecode(current_version);
+ ERR_FAIL_COND(bytecode.is_null());
+ int first_valid = -1;
+ int current = -1;
+ for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
+ Vector<uint8_t> bc = bytecode->get_stage_bytecode(RD::ShaderStage(i));
+ String error = bytecode->get_stage_compile_error(RD::ShaderStage(i));
+ bool disable = error == String() && bc.empty();
+ stages[i]->set_disabled(disable);
+ if (!disable) {
+ if (stages[i]->is_pressed()) {
+ current = i;
+ }
+ first_valid = i;
+ }
+ }
+
+ if (current == -1 && first_valid != -1) {
+ stages[first_valid]->set_pressed(true);
+ }
+
+ _version_selected(0);
+}
+
+void ShaderFileEditor::_notification(int p_what) {
+
+ if (p_what == NOTIFICATION_WM_FOCUS_IN) {
+ if (is_visible_in_tree() && shader_file.is_valid()) {
+ _update_options();
+ }
+ }
+}
+
+void ShaderFileEditor::_editor_settings_changed() {
+
+ if (is_visible_in_tree() && shader_file.is_valid()) {
+ _update_options();
+ }
+}
+
+void ShaderFileEditor::_bind_methods() {
+}
+
+void ShaderFileEditor::edit(const Ref<RDShaderFile> &p_shader) {
+
+ if (p_shader.is_null()) {
+ if (shader_file.is_valid()) {
+ shader_file->disconnect("changed", callable_mp(this, &ShaderFileEditor::_shader_changed));
+ }
+ return;
+ }
+
+ if (shader_file == p_shader)
+ return;
+
+ shader_file = p_shader;
+
+ if (shader_file.is_valid()) {
+ shader_file->connect("changed", callable_mp(this, &ShaderFileEditor::_shader_changed));
+ }
+
+ _update_options();
+}
+
+void ShaderFileEditor::_shader_changed() {
+
+ if (is_visible_in_tree()) {
+ _update_options();
+ }
+}
+
+ShaderFileEditor *ShaderFileEditor::singleton = nullptr;
+
+ShaderFileEditor::ShaderFileEditor(EditorNode *p_node) {
+ singleton = this;
+ HSplitContainer *main_hs = memnew(HSplitContainer);
+
+ add_child(main_hs);
+
+ versions = memnew(ItemList);
+ versions->connect("item_selected", callable_mp(this, &ShaderFileEditor::_version_selected));
+ versions->set_custom_minimum_size(Size2i(200 * EDSCALE, 0));
+ main_hs->add_child(versions);
+
+ VBoxContainer *main_vb = memnew(VBoxContainer);
+ main_vb->set_h_size_flags(SIZE_EXPAND_FILL);
+ main_hs->add_child(main_vb);
+
+ static const char *stage_str[RD::SHADER_STAGE_MAX] = {
+ "Vertex",
+ "Fragment",
+ "TessControl",
+ "TessEval",
+ "Compute"
+ };
+
+ stage_hb = memnew(HBoxContainer);
+ main_vb->add_child(stage_hb);
+
+ Ref<ButtonGroup> bg;
+ bg.instance();
+ for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
+ Button *button = memnew(Button(stage_str[i]));
+ button->set_toggle_mode(true);
+ button->set_focus_mode(FOCUS_NONE);
+ stage_hb->add_child(button);
+ stages[i] = button;
+ button->set_button_group(bg);
+ button->connect("pressed", callable_mp(this, &ShaderFileEditor::_version_selected), varray(i));
+ }
+
+ error_text = memnew(RichTextLabel);
+ error_text->set_v_size_flags(SIZE_EXPAND_FILL);
+ main_vb->add_child(error_text);
+}
+
+void ShaderFileEditorPlugin::edit(Object *p_object) {
+
+ RDShaderFile *s = Object::cast_to<RDShaderFile>(p_object);
+ shader_editor->edit(s);
+}
+
+bool ShaderFileEditorPlugin::handles(Object *p_object) const {
+
+ RDShaderFile *shader = Object::cast_to<RDShaderFile>(p_object);
+ return shader != nullptr;
+}
+
+void ShaderFileEditorPlugin::make_visible(bool p_visible) {
+
+ if (p_visible) {
+ button->show();
+ editor->make_bottom_panel_item_visible(shader_editor);
+
+ } else {
+
+ button->hide();
+ if (shader_editor->is_visible_in_tree())
+ editor->hide_bottom_panel();
+ }
+}
+
+ShaderFileEditorPlugin::ShaderFileEditorPlugin(EditorNode *p_node) {
+
+ editor = p_node;
+ shader_editor = memnew(ShaderFileEditor(p_node));
+
+ shader_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
+ button = editor->add_bottom_panel_item(TTR("ShaderFile"), shader_editor);
+ button->hide();
+}
+
+ShaderFileEditorPlugin::~ShaderFileEditorPlugin() {
+}
diff --git a/editor/plugins/shader_file_editor_plugin.h b/editor/plugins/shader_file_editor_plugin.h
new file mode 100644
index 0000000000..44d32de2f1
--- /dev/null
+++ b/editor/plugins/shader_file_editor_plugin.h
@@ -0,0 +1,64 @@
+#ifndef SHADER_FILE_EDITOR_PLUGIN_H
+#define SHADER_FILE_EDITOR_PLUGIN_H
+
+#include "editor/code_editor.h"
+#include "editor/editor_plugin.h"
+#include "scene/gui/menu_button.h"
+#include "scene/gui/panel_container.h"
+#include "scene/gui/rich_text_label.h"
+#include "scene/gui/tab_container.h"
+#include "scene/gui/text_edit.h"
+#include "scene/main/timer.h"
+#include "servers/rendering/rendering_device_binds.h"
+
+class ShaderFileEditor : public PanelContainer {
+
+ GDCLASS(ShaderFileEditor, PanelContainer);
+
+ Ref<RDShaderFile> shader_file;
+
+ HBoxContainer *stage_hb;
+ ItemList *versions;
+ Button *stages[RD::SHADER_STAGE_MAX];
+ RichTextLabel *error_text;
+
+ void _update_version(const StringName &p_version_txt, const RenderingDevice::ShaderStage p_stage);
+ void _version_selected(int p_stage);
+ void _editor_settings_changed();
+
+ void _update_options();
+ void _shader_changed();
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ static ShaderFileEditor *singleton;
+ void edit(const Ref<RDShaderFile> &p_shader);
+
+ ShaderFileEditor(EditorNode *p_node);
+};
+
+class ShaderFileEditorPlugin : public EditorPlugin {
+
+ GDCLASS(ShaderFileEditorPlugin, EditorPlugin);
+
+ ShaderFileEditor *shader_editor;
+ EditorNode *editor;
+ Button *button;
+
+public:
+ virtual String get_name() const { return "ShaderFile"; }
+ bool has_main_screen() const { return false; }
+ virtual void edit(Object *p_object);
+ virtual bool handles(Object *p_object) const;
+ virtual void make_visible(bool p_visible);
+
+ ShaderFileEditor *get_shader_editor() const { return shader_editor; }
+
+ ShaderFileEditorPlugin(EditorNode *p_node);
+ ~ShaderFileEditorPlugin();
+};
+
+#endif // SHADER_FILE_EDITOR_PLUGIN_H
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index ce421ac0a5..9e88cd8889 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -57,17 +57,18 @@ void TileMapEditor::_notification(int p_what) {
} break;
+ case NOTIFICATION_ENTER_TREE: {
+
+ get_tree()->connect("node_removed", callable_mp(this, &TileMapEditor::_node_removed));
+ [[fallthrough]];
+ }
+
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
if (is_visible_in_tree()) {
_update_palette();
}
- [[fallthrough]];
- }
- case NOTIFICATION_ENTER_TREE: {
-
- get_tree()->connect("node_removed", callable_mp(this, &TileMapEditor::_node_removed));
paint_button->set_icon(get_theme_icon("Edit", "EditorIcons"));
bucket_fill_button->set_icon(get_theme_icon("Bucket", "EditorIcons"));
picker_button->set_icon(get_theme_icon("ColorPick", "EditorIcons"));
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index a729f62123..4041256dd5 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -2867,6 +2867,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
edit_local->set_h_size_flags(SIZE_EXPAND_FILL);
edit_local->set_text(TTR("Local"));
edit_local->set_toggle_mode(true);
+ edit_local->set_pressed(true);
edit_local->connect("pressed", callable_mp(this, &SceneTreeDock::_local_tree_selected));
remote_tree = nullptr;