Skip to content

Commit

Permalink
Implemented dedicated shader editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosus committed Jan 14, 2021
1 parent 8d4698d commit 8d1afef
Show file tree
Hide file tree
Showing 10 changed files with 587 additions and 57 deletions.
4 changes: 2 additions & 2 deletions doc/classes/EditorPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
</return>
<description>
Override this method in your plugin to return a [Texture2D] in order to give it an icon.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", and "AssetLib" buttons.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", "Shader", and "AssetLib" buttons.
Ideally, the plugin icon should be white with a transparent background and 16x16 pixels in size.
[codeblocks]
[gdscript]
Expand All @@ -425,7 +425,7 @@
</return>
<description>
Override this method in your plugin to provide the name of the plugin when displayed in the Godot editor.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", and "AssetLib" buttons.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", "Shader", and "AssetLib" buttons.
</description>
</method>
<method name="get_script_create_dialog">
Expand Down
32 changes: 25 additions & 7 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/os/keyboard.h"
#include "core/string/string_builder.h"
#include "editor/editor_scale.h"
#include "editor/plugins/shader_editor_plugin.h"
#include "editor_node.h"
#include "editor_settings.h"
#include "scene/gui/margin_container.h"
Expand Down Expand Up @@ -1563,10 +1564,18 @@ void CodeTextEditor::_set_show_warnings_panel(bool p_show) {
}

void CodeTextEditor::_toggle_scripts_pressed() {
if (is_layout_rtl()) {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
if (_is_shader_editor()) {
if (is_layout_rtl()) {
toggle_scripts_button->set_icon(ShaderEditor::get_singleton()->toggle_shaders_panel() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
} else {
toggle_scripts_button->set_icon(ShaderEditor::get_singleton()->toggle_shaders_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
}
} else {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
if (is_layout_rtl()) {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
} else {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
}
}
}

Expand Down Expand Up @@ -1688,12 +1697,21 @@ void CodeTextEditor::show_toggle_scripts_button() {
}

void CodeTextEditor::update_toggle_scripts_button() {
if (is_layout_rtl()) {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
if (_is_shader_editor()) {
if (is_layout_rtl()) {
toggle_scripts_button->set_icon(ShaderEditor::get_singleton()->is_shaders_panel_toggled() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
} else {
toggle_scripts_button->set_icon(ShaderEditor::get_singleton()->is_shaders_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
}
toggle_scripts_button->set_tooltip(TTR("Toggle Shaders Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")");
} else {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
if (is_layout_rtl()) {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons"));
} else {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons"));
}
toggle_scripts_button->set_tooltip(TTR("Toggle Scripts Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")");
}
toggle_scripts_button->set_tooltip(TTR("Toggle Scripts Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")");
}

CodeTextEditor::CodeTextEditor() {
Expand Down
1 change: 1 addition & 0 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class CodeTextEditor : public VBoxContainer {
void _line_col_changed();
void _notification(int);
static void _bind_methods();
virtual bool _is_shader_editor() const { return false; }

bool is_warnings_panel_opened;

Expand Down
46 changes: 32 additions & 14 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {
_editor_select(EDITOR_3D);
} else if (ED_IS_SHORTCUT("editor/editor_script", p_event)) {
_editor_select(EDITOR_SCRIPT);
} else if (ED_IS_SHORTCUT("editor/editor_shader", p_event)) {
_editor_select(EDITOR_SHADER);
} else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) {
emit_signal("request_help_search", "");
} else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event) && StreamPeerSSL::is_available()) {
Expand Down Expand Up @@ -1941,6 +1943,10 @@ void EditorNode::_edit_current() {
inspector_dock->update(nullptr);
EditorNode::get_singleton()->get_import_dock()->set_edit_path(current_res->get_path());

if (current_res->get_class_name() == "Shader") {
main_editor_buttons[EDITOR_SHADER]->set_visible(true);
}

int subr_idx = current_res->get_path().find("::");
if (subr_idx != -1) {
String base_path = current_res->get_path().substr(0, subr_idx);
Expand Down Expand Up @@ -2040,14 +2046,17 @@ void EditorNode::_edit_current() {
}

if (main_plugin) {
bool script_editor_disabled = !ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus();
bool shader_editor_disabled = !ShaderEditor::get_singleton() || !ShaderEditor::get_singleton()->is_visible_in_tree();

// special case if use of external editor is true
if (main_plugin->get_name() == "Script" && current_obj->get_class_name() != StringName("VisualScript") && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) {
if ((main_plugin->get_name() == "Script" || main_plugin->get_name() == "Shader") && current_obj->get_class_name() != StringName("VisualScript") && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) {
if (!changing_scene) {
main_plugin->edit(current_obj);
}
}

else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) {
else if (main_plugin != editor_plugin_screen && script_editor_disabled && shader_editor_disabled) {
// update screen main_plugin

if (!changing_scene) {
Expand Down Expand Up @@ -2908,6 +2917,10 @@ void EditorNode::_editor_select(int p_which) {

if (editor_plugin_screen) {
editor_plugin_screen->make_visible(false);

if (p_which != EDITOR_SHADER) {
main_editor_buttons[EDITOR_SHADER]->set_visible(false);
}
}

editor_plugin_screen = new_editor;
Expand All @@ -2920,7 +2933,7 @@ void EditorNode::_editor_select(int p_which) {
}

if (EditorSettings::get_singleton()->get("interface/editor/separate_distraction_mode")) {
if (p_which == EDITOR_SCRIPT) {
if (p_which == EDITOR_SCRIPT || p_which == EDITOR_SHADER) {
set_distraction_free_mode(script_distraction);
} else {
set_distraction_free_mode(scene_distraction);
Expand Down Expand Up @@ -2975,7 +2988,11 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan
for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
if (p_editor->get_name() == singleton->main_editor_buttons[i]->get_text()) {
if (singleton->main_editor_buttons[i]->is_pressed()) {
singleton->_editor_select(EDITOR_SCRIPT);
if (i == EDITOR_SCRIPT) {
singleton->_editor_select(EDITOR_SCRIPT);
} else if (i == EDITOR_SHADER) {
singleton->_editor_select(EDITOR_SHADER);
}
}

memdelete(singleton->main_editor_buttons[i]);
Expand Down Expand Up @@ -4701,9 +4718,7 @@ void EditorNode::_scene_tab_closed(int p_tab, int option) {
return;
}

bool unsaved = (p_tab == editor_data.get_edited_scene()) ?
saved_version != editor_data.get_undo_redo().get_version() :
editor_data.get_scene_version(p_tab) != 0;
bool unsaved = (p_tab == editor_data.get_edited_scene()) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(p_tab) != 0;
if (unsaved) {
save_confirmation->get_ok_button()->set_text(TTR("Save & Close"));
save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene->get_filename() != "" ? scene->get_filename() : "unsaved scene"));
Expand Down Expand Up @@ -4953,7 +4968,7 @@ void EditorNode::_toggle_distraction_free_mode() {
}
}

if (screen == EDITOR_SCRIPT) {
if (screen == EDITOR_SCRIPT || screen == EDITOR_SHADER) {
script_distraction = !script_distraction;
set_distraction_free_mode(script_distraction);
} else {
Expand Down Expand Up @@ -6604,11 +6619,14 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(Node3DEditorPlugin(this)));
add_editor_plugin(memnew(ScriptEditorPlugin(this)));

EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor();

ScriptTextEditor::register_editor(); //register one for text scripts
TextEditor::register_editor();

add_editor_plugin(memnew(ShaderEditorPlugin(this)));
main_editor_buttons[EDITOR_SHADER]->set_visible(false); // hide by default

EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor();

if (StreamPeerSSL::is_available()) {
add_editor_plugin(memnew(AssetLibraryEditorPlugin(this)));
} else {
Expand All @@ -6624,10 +6642,8 @@ EditorNode::EditorNode() {
raise_bottom_panel_item(AnimationPlayerEditor::singleton);

add_editor_plugin(VersionControlEditorPlugin::get_singleton());
add_editor_plugin(memnew(ShaderEditorPlugin(this)));
add_editor_plugin(memnew(ShaderFileEditorPlugin(this)));
add_editor_plugin(memnew(VisualShaderEditorPlugin(this)));

add_editor_plugin(memnew(Camera3DEditorPlugin(this)));
add_editor_plugin(memnew(ThemeEditorPlugin(this)));
add_editor_plugin(memnew(MultiMeshEditorPlugin(this)));
Expand Down Expand Up @@ -6827,14 +6843,16 @@ EditorNode::EditorNode() {
ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_MASK_ALT | KEY_1);
ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_ALT | KEY_2);
ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_ALT | KEY_3);
ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_ALT | KEY_4);
ED_SHORTCUT("editor/editor_shader", TTR("Open Shader Editor"), KEY_MASK_ALT | KEY_4);
ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_ALT | KEY_5);
ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_MASK_ALT | KEY_SPACE);
#else
// Use the Ctrl modifier so F2 can be used to rename nodes in the scene tree dock.
ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_MASK_CTRL | KEY_F1);
ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_CTRL | KEY_F2);
ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_CTRL | KEY_F3);
ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_CTRL | KEY_F4);
ED_SHORTCUT("editor/editor_shader", TTR("Open Shader Editor"), KEY_MASK_CTRL | KEY_F4);
ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_CTRL | KEY_F5);
ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_F1);
#endif
ED_SHORTCUT("editor/editor_next", TTR("Open the next Editor"));
Expand Down
3 changes: 2 additions & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ class EditorNode : public Node {
EDITOR_2D = 0,
EDITOR_3D,
EDITOR_SCRIPT,
EDITOR_ASSETLIB
EDITOR_SHADER,
EDITOR_ASSETLIB,
};

void set_visible_editor(EditorTable p_table) { _editor_select(p_table); }
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3673,7 +3673,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
String type = open_in_new.get_slicec(',', i).strip_edges();
for (int j = 0; j < p_hint_text.get_slice_count(","); j++) {
String inherits = p_hint_text.get_slicec(',', j);
if (ClassDB::is_parent_class(inherits, type)) {
if (ClassDB::is_parent_class(inherits, type) || inherits == "Shader") {
editor->set_use_sub_inspector(false);
}
}
Expand Down
24 changes: 13 additions & 11 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2570,19 +2570,21 @@ void Node3DEditorViewport::_notification(int p_what) {
}
}

if (p_what == NOTIFICATION_ENTER_TREE) {
surface->connect("draw", callable_mp(this, &Node3DEditorViewport::_draw));
surface->connect("gui_input", callable_mp(this, &Node3DEditorViewport::_sinput));
surface->connect("mouse_entered", callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter));
surface->connect("mouse_exited", callable_mp(this, &Node3DEditorViewport::_surface_mouse_exit));
surface->connect("focus_entered", callable_mp(this, &Node3DEditorViewport::_surface_focus_enter));
surface->connect("focus_exited", callable_mp(this, &Node3DEditorViewport::_surface_focus_exit));
if (!reattaching) {
if (p_what == NOTIFICATION_ENTER_TREE) {
surface->connect("draw", callable_mp(this, &Node3DEditorViewport::_draw));
surface->connect("gui_input", callable_mp(this, &Node3DEditorViewport::_sinput));
surface->connect("mouse_entered", callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter));
surface->connect("mouse_exited", callable_mp(this, &Node3DEditorViewport::_surface_mouse_exit));
surface->connect("focus_entered", callable_mp(this, &Node3DEditorViewport::_surface_focus_enter));
surface->connect("focus_exited", callable_mp(this, &Node3DEditorViewport::_surface_focus_exit));

_init_gizmo_instance(index);
}
_init_gizmo_instance(index);
}

if (p_what == NOTIFICATION_EXIT_TREE) {
_finish_gizmo_instances();
if (p_what == NOTIFICATION_EXIT_TREE) {
_finish_gizmo_instances();
}
}

if (p_what == NOTIFICATION_THEME_CHANGED) {
Expand Down
23 changes: 22 additions & 1 deletion editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class Node3DEditorViewport : public Control {
AABB *preview_bounds;
Vector<String> selected_files;
AcceptDialog *accept;
bool reattaching = false;

Node *target_node;
Point2 drop_pos;
Expand Down Expand Up @@ -463,6 +464,13 @@ class Node3DEditorViewport : public Control {
static void _bind_methods();

public:
void set_reattaching(bool p_reattaching) {
reattaching = p_reattaching;
}
bool is_reattaching() const {
return reattaching;
}

void update_surface() { surface->update(); }
void update_transform_gizmo_view();

Expand Down Expand Up @@ -581,6 +589,7 @@ class Node3DEditor : public VBoxContainer {
Node3DEditorViewport *viewports[VIEWPORTS_COUNT];
VSplitContainer *shader_split;
HSplitContainer *palette_split;
bool reattaching = false;

/////

Expand Down Expand Up @@ -797,12 +806,24 @@ class Node3DEditor : public VBoxContainer {
void set_over_gizmo_handle(int idx) { over_gizmo_handle = idx; }

void set_can_preview(Camera3D *p_preview);

Node3DEditorViewportContainer *get_editor_viewport_base() const {
return viewport_base;
}
Node3DEditorViewport *get_editor_viewport(int p_idx) {
ERR_FAIL_INDEX_V(p_idx, static_cast<int>(VIEWPORTS_COUNT), nullptr);
return viewports[p_idx];
}

void set_viewports_reattaching(bool p_reattaching) {
for (int i = 0; i < static_cast<int>(VIEWPORTS_COUNT); i++) {
viewports[i]->set_reattaching(p_reattaching);
}
reattaching = p_reattaching;
}
bool is_viewports_reattaching() const {
return reattaching;
}

void add_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin);
void remove_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin);

Expand Down
Loading

0 comments on commit 8d1afef

Please sign in to comment.