From 5e5cd2495d8ec8bc0685dbf3b98dc251c3c7bddb Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Fri, 4 Jun 2021 12:24:08 +0300 Subject: Added editor dialog for easily creating shaders. --- editor/editor_properties.cpp | 4 + editor/editor_resource_picker.cpp | 41 ++ editor/editor_resource_picker.h | 19 + editor/plugins/visual_shader_editor_plugin.cpp | 1 + editor/scene_tree_dock.cpp | 59 +++ editor/scene_tree_dock.h | 9 + editor/shader_create_dialog.cpp | 643 +++++++++++++++++++++++++ editor/shader_create_dialog.h | 115 +++++ 8 files changed, 891 insertions(+) create mode 100644 editor/shader_create_dialog.cpp create mode 100644 editor/shader_create_dialog.h (limited to 'editor') diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index fa03d281f2..789cabea9a 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2854,6 +2854,10 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const EditorScriptPicker *script_picker = memnew(EditorScriptPicker); script_picker->set_script_owner(Object::cast_to(p_object)); resource_picker = script_picker; + } else if (p_path == "shader" && p_base_type == "Shader" && Object::cast_to(p_object)) { + EditorShaderPicker *shader_picker = memnew(EditorShaderPicker); + shader_picker->set_edited_material(Object::cast_to(p_object)); + resource_picker = shader_picker; } else { resource_picker = memnew(EditorResourcePicker); } diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index f3965fe7de..a4ab749db4 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -847,6 +847,8 @@ EditorResourcePicker::EditorResourcePicker() { edit_button->connect("gui_input", callable_mp(this, &EditorResourcePicker::_button_input)); } +// EditorScriptPicker + void EditorScriptPicker::set_create_options(Object *p_menu_node) { PopupMenu *menu_node = Object::cast_to(p_menu_node); if (!menu_node) { @@ -895,3 +897,42 @@ void EditorScriptPicker::_bind_methods() { EditorScriptPicker::EditorScriptPicker() { } + +// EditorShaderPicker + +void EditorShaderPicker::set_create_options(Object *p_menu_node) { + PopupMenu *menu_node = Object::cast_to(p_menu_node); + if (!menu_node) { + return; + } + + menu_node->add_icon_item(get_theme_icon("Shader", "EditorIcons"), TTR("New Shader"), OBJ_MENU_NEW_SHADER); + menu_node->add_separator(); +} + +bool EditorShaderPicker::handle_menu_selected(int p_which) { + Ref material = Ref(get_edited_material()); + + switch (p_which) { + case OBJ_MENU_NEW_SHADER: { + if (material.is_valid()) { + EditorNode::get_singleton()->get_scene_tree_dock()->open_shader_dialog(material); + return true; + } + } break; + default: + break; + } + return false; +} + +void EditorShaderPicker::set_edited_material(ShaderMaterial *p_material) { + edited_material = p_material; +} + +ShaderMaterial *EditorShaderPicker::get_edited_material() const { + return edited_material; +} + +EditorShaderPicker::EditorShaderPicker() { +} diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h index a4c3006c02..d77c31f831 100644 --- a/editor/editor_resource_picker.h +++ b/editor/editor_resource_picker.h @@ -144,4 +144,23 @@ public: EditorScriptPicker(); }; +class EditorShaderPicker : public EditorResourcePicker { + GDCLASS(EditorShaderPicker, EditorResourcePicker); + + enum ExtraMenuOption { + OBJ_MENU_NEW_SHADER = 10, + }; + + ShaderMaterial *edited_material = nullptr; + +public: + virtual void set_create_options(Object *p_menu_node) override; + virtual bool handle_menu_selected(int p_which) override; + + void set_edited_material(ShaderMaterial *p_material); + ShaderMaterial *get_edited_material() const; + + EditorShaderPicker(); +}; + #endif // EDITOR_RESOURCE_PICKER_H diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 452ad126b3..9a41a100bd 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1007,6 +1007,7 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { const Dictionary vs_version = visual_shader->get_engine_version(); if (!vs_version.has_all(components)) { visual_shader->update_engine_version(engine_version); + print_line(vformat(TTR("The shader (\"%s\") has been updated to correspond Godot %s.%s version."), visual_shader->get_path(), engine_version["major"], engine_version["minor"])); } else { for (int i = 0; i < components.size(); i++) { if (vs_version[components[i]] != engine_version[components[i]]) { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index c4d47c7594..8994adf112 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -45,6 +45,7 @@ #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/shader_create_dialog.h" #include "scene/main/window.h" #include "scene/resources/packed_scene.h" #include "servers/display_server.h" @@ -1939,12 +1940,31 @@ void SceneTreeDock::_script_created(Ref