diff options
author | Magian <zang_magian@163.com> | 2024-04-26 17:48:11 +0800 |
---|---|---|
committer | Magian <zang_magian@163.com> | 2024-04-26 17:48:11 +0800 |
commit | e3a7c751f284347fe97a940af74352da65bbf8ec (patch) | |
tree | 6b054758a8ae9c63093df6e37126057209708f35 | |
parent | 4a0160241fd0c1e874e297f6b08676cf0761e5e8 (diff) | |
download | redot-engine-e3a7c751f284347fe97a940af74352da65bbf8ec.tar.gz |
Implement tooltips for shader uniform in the inspector.
using regular expressions
-rw-r--r-- | editor/editor_inspector.cpp | 7 | ||||
-rw-r--r-- | editor/plugins/text_shader_editor.cpp | 3 | ||||
-rw-r--r-- | scene/resources/shader.cpp | 43 |
3 files changed, 52 insertions, 1 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 50cc89c618..41396a2ed1 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3379,7 +3379,12 @@ void EditorInspector::update_tree() { if (use_doc_hints) { // `|` separators used in `EditorHelpBit`. if (theme_item_name.is_empty()) { - if (p.usage & PROPERTY_USAGE_INTERNAL) { + if (p.name.contains("shader_parameter/")) { + ShaderMaterial *shader_material = Object::cast_to<ShaderMaterial>(object); + if (shader_material) { + ep->set_tooltip_text("property|" + shader_material->get_shader()->get_path() + "|" + property_prefix + p.name); + } + } else if (p.usage & PROPERTY_USAGE_INTERNAL) { ep->set_tooltip_text("internal_property|" + classname + "|" + property_prefix + p.name); } else { ep->set_tooltip_text("property|" + classname + "|" + property_prefix + p.name); diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 6e786c1d94..40bd51a442 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -311,6 +311,9 @@ void ShaderTextEditor::_load_theme_settings() { syntax_highlighter->add_color_region("/*", "*/", comment_color, false); syntax_highlighter->add_color_region("//", "", comment_color, true); + const Color doc_comment_color = EDITOR_GET("text_editor/theme/highlighting/doc_comment_color"); + syntax_highlighter->add_color_region("/**", "*/", doc_comment_color, false); + // Disabled preprocessor branches use translucent text color to be easier to distinguish from comments. syntax_highlighter->set_disabled_branch_color(Color(EDITOR_GET("text_editor/theme/highlighting/text_color")) * Color(1, 1, 1, 0.5)); diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 5b375905cc..296c914c65 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -37,6 +37,15 @@ #include "servers/rendering_server.h" #include "texture.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_help.h" + +#include "modules/modules_enabled.gen.h" // For regex. +#ifdef MODULE_REGEX_ENABLED +#include "modules/regex/regex.h" +#endif +#endif + Shader::Mode Shader::get_mode() const { return mode; } @@ -121,6 +130,11 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_gr List<PropertyInfo> local; RenderingServer::get_singleton()->get_shader_parameter_list(shader, &local); +#ifdef TOOLS_ENABLED + DocData::ClassDoc class_doc; + class_doc.name = get_path(); + class_doc.is_script_doc = true; +#endif for (PropertyInfo &pi : local) { bool is_group = pi.usage == PROPERTY_USAGE_GROUP || pi.usage == PROPERTY_USAGE_SUBGROUP; if (!p_get_groups && is_group) { @@ -136,9 +150,38 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_gr if (pi.type == Variant::RID) { pi.type = Variant::OBJECT; } +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { +#ifdef MODULE_REGEX_ENABLED + const RegEx pattern("/\\*\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/\\s*uniform\\s+\\w+\\s+" + pi.name + "(?=[\\s:;=])"); + Ref<RegExMatch> pattern_ref = pattern.search(code); + if (pattern_ref != nullptr) { + RegExMatch *match = pattern_ref.ptr(); + const RegEx pattern_tip("\\/\\*\\*([\\s\\S]*?)\\*/"); + Ref<RegExMatch> pattern_tip_ref = pattern_tip.search(match->get_string(0)); + RegExMatch *match_tip = pattern_tip_ref.ptr(); + const RegEx pattern_stripped("\\n\\s*\\*\\s*"); + DocData::PropertyDoc prop_doc; + prop_doc.name = "shader_parameter/" + pi.name; + prop_doc.description = pattern_stripped.sub(match_tip->get_string(1), "\n", true); + class_doc.properties.push_back(prop_doc); + } +#else + DocData::PropertyDoc prop_doc; + prop_doc.name = "shader_parameter/" + pi.name; + // prop_doc.description = "(Regex module is not enabled, shader parameter documentation will not be available.)"; + class_doc.properties.push_back(prop_doc); +#endif + } +#endif p_params->push_back(pi); } } +#ifdef TOOLS_ENABLED + if (!class_doc.name.is_empty() && p_params) { + EditorHelp::get_doc_data()->add_doc(class_doc); + } +#endif } RID Shader::get_rid() const { |