summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp52
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h3
2 files changed, 51 insertions, 4 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 589964f620..0bfe366a6d 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -41,6 +41,7 @@
#include "scene/gui/panel.h"
#include "scene/main/viewport.h"
#include "scene/resources/visual_shader_nodes.h"
+#include "servers/visual/shader_types.h"
Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
@@ -1598,6 +1599,9 @@ void VisualShaderEditor::_notification(int p_what) {
preview_text->add_color_override("symbol_color", symbol_color);
preview_text->add_color_region("/*", "*/", comment_color, false);
preview_text->add_color_region("//", "", comment_color, false);
+
+ error_text->add_font_override("font", get_font("status_source", "EditorFonts"));
+ error_text->add_color_override("font_color", get_color("error_color", "Editor"));
}
tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Tools", "EditorIcons"));
@@ -2052,11 +2056,43 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
void VisualShaderEditor::_show_preview_text() {
preview_showed = !preview_showed;
- preview_text->set_visible(preview_showed);
+ preview_vbox->set_visible(preview_showed);
+ if (preview_showed) {
+ if (shader_error) {
+ error_text->set_visible(true);
+ } else {
+ error_text->set_visible(false);
+ }
+ }
}
void VisualShaderEditor::_update_preview() {
- preview_text->set_text(visual_shader->get_code());
+
+ String code = visual_shader->get_code();
+
+ preview_text->set_text(code);
+
+ ShaderLanguage sl;
+
+ Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_types());
+
+ for (int i = 0; i < preview_text->get_line_count(); i++) {
+ preview_text->set_line_as_marked(i, false);
+ }
+ if (err != OK) {
+ preview_text->set_line_as_marked(sl.get_error_line() - 1, true);
+ if (preview_showed) {
+ error_text->set_visible(true);
+ }
+ String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
+ error_text->set_text(text);
+ shader_error = true;
+ } else {
+ if (preview_showed) {
+ error_text->set_visible(false);
+ }
+ shader_error = false;
+ }
}
void VisualShaderEditor::_bind_methods() {
@@ -2127,6 +2163,7 @@ VisualShaderEditor::VisualShaderEditor() {
ShaderLanguage::get_keyword_list(&keyword_list);
preview_showed = false;
+ shader_error = false;
to_node = -1;
to_slot = -1;
@@ -2201,15 +2238,22 @@ VisualShaderEditor::VisualShaderEditor() {
// PREVIEW PANEL
///////////////////////////////////////
+ preview_vbox = memnew(VBoxContainer);
+ preview_vbox->set_visible(preview_showed);
+ main_box->add_child(preview_vbox);
preview_text = memnew(TextEdit);
- main_box->add_child(preview_text);
+ preview_vbox->add_child(preview_text);
preview_text->set_h_size_flags(SIZE_EXPAND_FILL);
preview_text->set_v_size_flags(SIZE_EXPAND_FILL);
- preview_text->set_visible(preview_showed);
preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
preview_text->set_syntax_coloring(true);
+ preview_text->set_show_line_numbers(true);
preview_text->set_readonly(true);
+ error_text = memnew(Label);
+ preview_vbox->add_child(error_text);
+ error_text->set_visible(false);
+
///////////////////////////////////////
// SHADER NODES TREE
///////////////////////////////////////
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 1556c7cd43..5be214f9a9 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -70,7 +70,10 @@ class VisualShaderEditor : public VBoxContainer {
PanelContainer *error_panel;
Label *error_label;
+ bool shader_error;
+ VBoxContainer *preview_vbox;
TextEdit *preview_text;
+ Label *error_text;
UndoRedo *undo_redo;
Point2 saved_node_pos;