diff options
Diffstat (limited to 'editor/plugins/shader_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/shader_editor_plugin.cpp | 106 |
1 files changed, 74 insertions, 32 deletions
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 260933ddb9..213a332bab 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -32,14 +32,15 @@ #include "editor/editor_command_palette.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" +#include "editor/gui/editor_bottom_panel.h" #include "editor/inspector_dock.h" #include "editor/plugins/text_shader_editor.h" #include "editor/plugins/visual_shader_editor_plugin.h" #include "editor/shader_create_dialog.h" +#include "editor/themes/editor_scale.h" #include "editor/window_wrapper.h" #include "scene/gui/item_list.h" #include "scene/gui/texture_rect.h" @@ -84,7 +85,8 @@ void ShaderEditorPlugin::_update_shader_list() { Ref<Texture2D> icon = shader_list->get_editor_theme_icon(_class); shader_list->add_item(text, icon); - shader_list->set_item_tooltip(shader_list->get_item_count() - 1, path); + shader_list->set_item_tooltip(-1, path); + edited_shader.name = text; } if (shader_tabs->get_tab_count()) { @@ -142,7 +144,6 @@ void ShaderEditorPlugin::edit(Object *p_object) { es.shader_editor = memnew(TextShaderEditor); es.shader_editor->edit(si); shader_tabs->add_child(es.shader_editor); - es.shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list)); } else { Shader *s = Object::cast_to<Shader>(p_object); for (uint32_t i = 0; i < edited_shaders.size(); i++) { @@ -162,7 +163,16 @@ void ShaderEditorPlugin::edit(Object *p_object) { es.shader_editor = memnew(TextShaderEditor); shader_tabs->add_child(es.shader_editor); es.shader_editor->edit(s); - es.shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list)); + } + } + + 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(); + if (cte) { + cte->set_zoom_factor(text_shader_zoom_factor); + cte->connect("zoomed", callable_mp(this, &ShaderEditorPlugin::_set_text_shader_zoom_factor)); } } @@ -177,7 +187,7 @@ bool ShaderEditorPlugin::handles(Object *p_object) const { void ShaderEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - EditorNode::get_singleton()->make_bottom_panel_item_visible(window_wrapper); + EditorNode::get_bottom_panel()->make_item_visible(window_wrapper); } } @@ -243,6 +253,8 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { _update_shader_list(); _shader_selected(selected_shader_idx); + + _set_text_shader_zoom_factor(p_layout->get_value("ShaderEditor", "text_shader_zoom_factor", 1.0f)); } void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { @@ -289,14 +301,10 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { p_layout->set_value("ShaderEditor", "open_shaders", shaders); p_layout->set_value("ShaderEditor", "split_offset", main_split->get_split_offset()); p_layout->set_value("ShaderEditor", "selected_shader", selected_shader); + p_layout->set_value("ShaderEditor", "text_shader_zoom_factor", text_shader_zoom_factor); } String ShaderEditorPlugin::get_unsaved_status(const String &p_for_scene) const { - if (!p_for_scene.is_empty()) { - // TODO: handle built-in shaders. - return String(); - } - // TODO: This should also include visual shaders and shader includes, but save_external_data() doesn't seem to save them... PackedStringArray unsaved_shaders; for (uint32_t i = 0; i < edited_shaders.size(); i++) { @@ -305,10 +313,30 @@ String ShaderEditorPlugin::get_unsaved_status(const String &p_for_scene) const { if (unsaved_shaders.is_empty()) { unsaved_shaders.append(TTR("Save changes to the following shaders(s) before quitting?")); } - unsaved_shaders.append(edited_shaders[i].shader_editor->get_name()); + unsaved_shaders.append(edited_shaders[i].name.trim_suffix("(*)")); } } } + + if (!p_for_scene.is_empty()) { + PackedStringArray unsaved_built_in_shaders; + + const String scene_file = p_for_scene.get_file(); + for (const String &E : unsaved_shaders) { + if (!E.is_resource_file() && E.contains(scene_file)) { + if (unsaved_built_in_shaders.is_empty()) { + unsaved_built_in_shaders.append(TTR("There are unsaved changes in the following built-in shaders(s):")); + } + unsaved_built_in_shaders.append(E); + } + } + + if (!unsaved_built_in_shaders.is_empty()) { + return String("\n").join(unsaved_built_in_shaders); + } + return String(); + } + return String("\n").join(unsaved_shaders); } @@ -517,7 +545,7 @@ bool ShaderEditorPlugin::can_drop_data_fw(const Point2 &p_point, const Variant & } for (int i = 0; i < files.size(); i++) { - String file = files[i]; + const String &file = files[i]; if (ResourceLoader::exists(file, "Shader")) { Ref<Shader> shader = ResourceLoader::load(file); if (shader.is_valid()) { @@ -558,7 +586,7 @@ void ShaderEditorPlugin::drop_data_fw(const Point2 &p_point, const Variant &p_da Vector<String> files = d["files"]; for (int i = 0; i < files.size(); i++) { - String file = files[i]; + const String &file = files[i]; Ref<Resource> res; if (ResourceLoader::exists(file, "Shader") || ResourceLoader::exists(file, "ShaderInclude")) { res = ResourceLoader::load(file); @@ -574,6 +602,20 @@ void ShaderEditorPlugin::_window_changed(bool p_visible) { make_floating->set_visible(!p_visible); } +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(); + if (cte && cte->get_zoom_factor() != text_shader_zoom_factor) { + cte->set_zoom_factor(text_shader_zoom_factor); + } + } + } + } +} + void ShaderEditorPlugin::_file_removed(const String &p_removed_file) { for (uint32_t i = 0; i < edited_shaders.size(); i++) { if (edited_shaders[i].path == p_removed_file) { @@ -610,6 +652,7 @@ void ShaderEditorPlugin::_res_saved_callback(const Ref<Resource> &p_res) { void ShaderEditorPlugin::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { + EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ShaderEditorPlugin::_resource_saved), CONNECT_DEFERRED); EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ShaderEditorPlugin::_close_builtin_shaders_from_scene)); FileSystemDock::get_singleton()->connect("file_removed", callable_mp(this, &ShaderEditorPlugin::_file_removed)); EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ShaderEditorPlugin::_res_saved_callback)); @@ -633,13 +676,13 @@ ShaderEditorPlugin::ShaderEditorPlugin() { file_menu = memnew(MenuButton); file_menu->set_text(TTR("File")); file_menu->set_shortcut_context(main_split); - file_menu->get_popup()->add_item(TTR("New Shader"), FILE_NEW); - file_menu->get_popup()->add_item(TTR("New Shader Include"), FILE_NEW_INCLUDE); + file_menu->get_popup()->add_item(TTR("New Shader..."), FILE_NEW); + file_menu->get_popup()->add_item(TTR("New Shader Include..."), FILE_NEW_INCLUDE); file_menu->get_popup()->add_separator(); - file_menu->get_popup()->add_item(TTR("Load Shader File"), FILE_OPEN); - file_menu->get_popup()->add_item(TTR("Load Shader Include File"), FILE_OPEN_INCLUDE); + file_menu->get_popup()->add_item(TTR("Load Shader File..."), FILE_OPEN); + file_menu->get_popup()->add_item(TTR("Load Shader Include File..."), FILE_OPEN_INCLUDE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("shader_editor/save", TTR("Save File"), KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL | Key::S), FILE_SAVE); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("shader_editor/save_as", TTR("Save File As")), FILE_SAVE_AS); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("shader_editor/save_as", TTR("Save File As...")), FILE_SAVE_AS); file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_item(TTR("Open File in Inspector"), FILE_INSPECT); file_menu->get_popup()->add_separator(); @@ -651,21 +694,23 @@ ShaderEditorPlugin::ShaderEditorPlugin() { file_menu->get_popup()->set_item_disabled(file_menu->get_popup()->get_item_index(i), true); } - if (window_wrapper->is_window_available()) { - Control *padding = memnew(Control); - padding->set_h_size_flags(Control::SIZE_EXPAND_FILL); - menu_hb->add_child(padding); + Control *padding = memnew(Control); + padding->set_h_size_flags(Control::SIZE_EXPAND_FILL); + menu_hb->add_child(padding); - make_floating = memnew(ScreenSelect); - make_floating->set_flat(true); + make_floating = memnew(ScreenSelect); + make_floating->set_flat(true); + make_floating->connect("request_open_in_screen", callable_mp(window_wrapper, &WindowWrapper::enable_window_on_screen).bind(true)); + if (!make_floating->is_disabled()) { + // Override default ScreenSelect tooltip if multi-window support is available. make_floating->set_tooltip_text(TTR("Make the shader editor floating.")); - make_floating->connect("request_open_in_screen", callable_mp(window_wrapper, &WindowWrapper::enable_window_on_screen).bind(true)); - - menu_hb->add_child(make_floating); - window_wrapper->connect("window_visibility_changed", callable_mp(this, &ShaderEditorPlugin::_window_changed)); } + menu_hb->add_child(make_floating); + window_wrapper->connect("window_visibility_changed", callable_mp(this, &ShaderEditorPlugin::_window_changed)); + shader_list = memnew(ItemList); + shader_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); vb->add_child(shader_list); shader_list->connect("item_selected", callable_mp(this, &ShaderEditorPlugin::_shader_selected)); @@ -683,10 +728,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() { empty.instantiate(); shader_tabs->add_theme_style_override("panel", empty); - button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Shader Editor"), window_wrapper); - - // Defer connect because Editor class is not in the binding system yet. - EditorNode::get_singleton()->call_deferred("connect", "resource_saved", callable_mp(this, &ShaderEditorPlugin::_resource_saved), CONNECT_DEFERRED); + button = EditorNode::get_bottom_panel()->add_item(TTR("Shader Editor"), window_wrapper); shader_create_dialog = memnew(ShaderCreateDialog); vb->add_child(shader_create_dialog); |