Skip to content

Commit

Permalink
Merge pull request #90161 from magian1127/4.0sTip
Browse files Browse the repository at this point in the history
Implement tooltips for shader uniform in the inspector.
  • Loading branch information
akien-mga committed Apr 29, 2024
2 parents c205f02 + e3a7c75 commit 9286ac7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
7 changes: 6 additions & 1 deletion editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/text_shader_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
43 changes: 43 additions & 0 deletions scene/resources/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 9286ac7

Please sign in to comment.