summaryrefslogtreecommitdiffstats
path: root/editor/plugins/shader_editor_plugin.cpp
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2024-07-12 11:56:49 -0700
committerAaron Franke <arnfranke@yahoo.com>2024-08-15 15:12:39 -0700
commit99e997ae15dae35de9f8b320d03796b75c852d5f (patch)
treef078a8e1563e0363899dd61932095e14b4336acf /editor/plugins/shader_editor_plugin.cpp
parentee363af0ed65f6ca9a906f6065d0bd9c19dcf9e4 (diff)
downloadredot-engine-99e997ae15dae35de9f8b320d03796b75c852d5f.tar.gz
Make shader language editors inherit the same base class
Diffstat (limited to 'editor/plugins/shader_editor_plugin.cpp')
-rw-r--r--editor/plugins/shader_editor_plugin.cpp54
1 files changed, 20 insertions, 34 deletions
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index 9d1576cdf2..82c436d3a5 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -142,7 +142,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
}
es.shader_inc = Ref<ShaderInclude>(si);
es.shader_editor = memnew(TextShaderEditor);
- es.shader_editor->edit(si);
+ es.shader_editor->edit_shader_include(si);
shader_tabs->add_child(es.shader_editor);
} else {
Shader *s = Object::cast_to<Shader>(p_object);
@@ -156,20 +156,18 @@ void ShaderEditorPlugin::edit(Object *p_object) {
es.shader = Ref<Shader>(s);
Ref<VisualShader> vs = es.shader;
if (vs.is_valid()) {
- es.visual_shader_editor = memnew(VisualShaderEditor);
- shader_tabs->add_child(es.visual_shader_editor);
- es.visual_shader_editor->edit(vs.ptr());
+ es.shader_editor = memnew(VisualShaderEditor);
} else {
es.shader_editor = memnew(TextShaderEditor);
- shader_tabs->add_child(es.shader_editor);
- es.shader_editor->edit(s);
}
+ shader_tabs->add_child(es.shader_editor);
+ es.shader_editor->edit_shader(es.shader);
}
- if (es.shader_editor) {
- es.shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list));
-
- CodeTextEditor *cte = es.shader_editor->get_code_editor();
+ TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(es.shader_editor);
+ if (text_shader_editor) {
+ text_shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list));
+ CodeTextEditor *cte = text_shader_editor->get_code_editor();
if (cte) {
cte->set_zoom_factor(text_shader_zoom_factor);
cte->connect("zoomed", callable_mp(this, &ShaderEditorPlugin::_set_text_shader_zoom_factor));
@@ -194,7 +192,7 @@ void ShaderEditorPlugin::make_visible(bool p_visible) {
void ShaderEditorPlugin::selected_notify() {
}
-TextShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_shader) {
+ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_shader) {
for (EditedShader &edited_shader : edited_shaders) {
if (edited_shader.shader == p_for_shader) {
return edited_shader.shader_editor;
@@ -203,15 +201,6 @@ TextShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for
return nullptr;
}
-VisualShaderEditor *ShaderEditorPlugin::get_visual_shader_editor(const Ref<Shader> &p_for_shader) {
- for (EditedShader &edited_shader : edited_shaders) {
- if (edited_shader.shader == p_for_shader) {
- return edited_shader.visual_shader_editor;
- }
- }
- return nullptr;
-}
-
void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
if (EDITOR_GET("interface/multi_window/restore_windows_on_load") && window_wrapper->is_window_available() && p_layout->has_section_key("ShaderEditor", "window_rect")) {
window_wrapper->restore_window_from_saved_position(
@@ -280,7 +269,7 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
String selected_shader;
for (int i = 0; i < shader_tabs->get_tab_count(); i++) {
EditedShader edited_shader = edited_shaders[i];
- if (edited_shader.shader_editor || edited_shader.visual_shader_editor) {
+ if (edited_shader.shader_editor) {
String shader_path;
if (edited_shader.shader.is_valid()) {
shader_path = edited_shader.shader->get_path();
@@ -290,10 +279,9 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
}
shaders.push_back(shader_path);
- TextShaderEditor *shader_editor = Object::cast_to<TextShaderEditor>(shader_tabs->get_current_tab_control());
- VisualShaderEditor *visual_shader_editor = Object::cast_to<VisualShaderEditor>(shader_tabs->get_current_tab_control());
+ ShaderEditor *shader_editor = Object::cast_to<ShaderEditor>(shader_tabs->get_current_tab_control());
- if ((shader_editor && edited_shader.shader_editor == shader_editor) || (visual_shader_editor && edited_shader.visual_shader_editor == visual_shader_editor)) {
+ if (shader_editor && edited_shader.shader_editor == shader_editor) {
selected_shader = shader_path;
}
}
@@ -366,10 +354,6 @@ void ShaderEditorPlugin::_shader_selected(int p_index) {
edited_shaders[p_index].shader_editor->validate_script();
}
- if (edited_shaders[p_index].visual_shader_editor) {
- edited_shaders[p_index].visual_shader_editor->validate_script();
- }
-
shader_tabs->set_current_tab(p_index);
shader_list->select(p_index);
}
@@ -440,7 +424,7 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) {
case FILE_SAVE: {
int index = shader_tabs->get_current_tab();
ERR_FAIL_INDEX(index, shader_tabs->get_tab_count());
- TextShaderEditor *editor = edited_shaders[index].shader_editor;
+ TextShaderEditor *editor = Object::cast_to<TextShaderEditor>(edited_shaders[index].shader_editor);
if (editor) {
if (editor->get_trim_trailing_whitespace_on_save()) {
editor->trim_trailing_whitespace();
@@ -462,7 +446,7 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) {
case FILE_SAVE_AS: {
int index = shader_tabs->get_current_tab();
ERR_FAIL_INDEX(index, shader_tabs->get_tab_count());
- TextShaderEditor *editor = edited_shaders[index].shader_editor;
+ TextShaderEditor *editor = Object::cast_to<TextShaderEditor>(edited_shaders[index].shader_editor);
if (editor) {
if (editor->get_trim_trailing_whitespace_on_save()) {
editor->trim_trailing_whitespace();
@@ -623,8 +607,9 @@ void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) {
if (text_shader_zoom_factor != p_zoom_factor) {
text_shader_zoom_factor = p_zoom_factor;
for (const EditedShader &edited_shader : edited_shaders) {
- if (edited_shader.shader_editor) {
- CodeTextEditor *cte = edited_shader.shader_editor->get_code_editor();
+ TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(edited_shader.shader_editor);
+ if (text_shader_editor) {
+ CodeTextEditor *cte = text_shader_editor->get_code_editor();
if (cte && cte->get_zoom_factor() != text_shader_zoom_factor) {
cte->set_zoom_factor(text_shader_zoom_factor);
}
@@ -655,12 +640,13 @@ void ShaderEditorPlugin::_res_saved_callback(const Ref<Resource> &p_res) {
}
ERR_FAIL_COND(shader_res.is_null());
- if (!edited.shader_editor || !shader_res->is_built_in()) {
+ TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(edited.shader_editor);
+ if (!text_shader_editor || !shader_res->is_built_in()) {
continue;
}
if (shader_res->get_path().get_slice("::", 0) == path) {
- edited.shader_editor->tag_saved_version();
+ text_shader_editor->tag_saved_version();
_update_shader_list();
}
}