2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* shader_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "shader_editor_plugin.h"
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "core/io/resource_loader.h"
|
|
|
|
#include "core/io/resource_saver.h"
|
|
|
|
#include "core/os/keyboard.h"
|
|
|
|
#include "core/os/os.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor/editor_node.h"
|
2020-01-12 07:24:15 +00:00
|
|
|
#include "editor/editor_scale.h"
|
2017-03-05 13:21:25 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor/property_editor.h"
|
2020-03-03 13:36:29 +00:00
|
|
|
#include "servers/display_server.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering/shader_types.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-26 15:46:49 +00:00
|
|
|
/*** SHADER SCRIPT EDITOR ****/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Ref<Shader> ShaderTextEditor::get_edited_shader() const {
|
|
|
|
return shader;
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) {
|
2019-03-04 22:37:05 +00:00
|
|
|
if (shader == p_shader) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
shader = p_shader;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_load_theme_settings();
|
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
get_text_editor()->set_text(p_shader->get_code());
|
|
|
|
get_text_editor()->clear_undo_history();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-02-23 20:52:49 +00:00
|
|
|
_validate_script();
|
2014-02-10 01:10:30 +00:00
|
|
|
_line_col_changed();
|
|
|
|
}
|
|
|
|
|
2018-10-08 19:26:45 +00:00
|
|
|
void ShaderTextEditor::reload_text() {
|
|
|
|
ERR_FAIL_COND(shader.is_null());
|
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
CodeEdit *te = get_text_editor();
|
2018-10-08 19:26:45 +00:00
|
|
|
int column = te->cursor_get_column();
|
|
|
|
int row = te->cursor_get_line();
|
|
|
|
int h = te->get_h_scroll();
|
|
|
|
int v = te->get_v_scroll();
|
|
|
|
|
|
|
|
te->set_text(shader->get_code());
|
|
|
|
te->cursor_set_line(row);
|
|
|
|
te->cursor_set_column(column);
|
|
|
|
te->set_h_scroll(h);
|
|
|
|
te->set_v_scroll(v);
|
|
|
|
|
|
|
|
te->tag_saved_version();
|
|
|
|
|
|
|
|
update_line_and_column();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ShaderTextEditor::_load_theme_settings() {
|
2017-12-26 19:41:08 +00:00
|
|
|
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
|
|
|
|
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
|
|
|
|
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
|
|
|
|
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
|
|
|
|
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
|
|
|
|
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
|
|
|
|
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
|
|
|
|
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
|
|
|
|
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
|
|
|
|
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
|
|
|
|
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
|
|
|
|
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
|
|
|
|
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
|
|
|
|
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
|
|
|
|
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
|
|
|
|
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
|
|
|
|
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
|
2019-04-19 23:51:25 +00:00
|
|
|
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
|
2017-12-26 19:41:08 +00:00
|
|
|
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
|
2019-04-22 16:20:27 +00:00
|
|
|
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
|
2017-12-26 19:41:08 +00:00
|
|
|
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
|
|
|
|
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
|
|
|
|
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
|
2017-09-15 01:02:05 +00:00
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
get_text_editor()->add_theme_color_override("background_color", background_color);
|
|
|
|
get_text_editor()->add_theme_color_override("completion_background_color", completion_background_color);
|
|
|
|
get_text_editor()->add_theme_color_override("completion_selected_color", completion_selected_color);
|
|
|
|
get_text_editor()->add_theme_color_override("completion_existing_color", completion_existing_color);
|
|
|
|
get_text_editor()->add_theme_color_override("completion_scroll_color", completion_scroll_color);
|
|
|
|
get_text_editor()->add_theme_color_override("completion_font_color", completion_font_color);
|
|
|
|
get_text_editor()->add_theme_color_override("font_color", text_color);
|
|
|
|
get_text_editor()->add_theme_color_override("line_number_color", line_number_color);
|
|
|
|
get_text_editor()->add_theme_color_override("caret_color", caret_color);
|
|
|
|
get_text_editor()->add_theme_color_override("caret_background_color", caret_background_color);
|
2020-12-08 13:11:45 +00:00
|
|
|
get_text_editor()->add_theme_color_override("font_selected_color", text_selected_color);
|
2020-07-24 14:50:35 +00:00
|
|
|
get_text_editor()->add_theme_color_override("selection_color", selection_color);
|
|
|
|
get_text_editor()->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
|
|
|
|
get_text_editor()->add_theme_color_override("current_line_color", current_line_color);
|
|
|
|
get_text_editor()->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
|
|
|
|
get_text_editor()->add_theme_color_override("word_highlighted_color", word_highlighted_color);
|
|
|
|
get_text_editor()->add_theme_color_override("mark_color", mark_color);
|
|
|
|
get_text_editor()->add_theme_color_override("bookmark_color", bookmark_color);
|
|
|
|
get_text_editor()->add_theme_color_override("breakpoint_color", breakpoint_color);
|
|
|
|
get_text_editor()->add_theme_color_override("executing_line_color", executing_line_color);
|
|
|
|
get_text_editor()->add_theme_color_override("code_folding_color", code_folding_color);
|
|
|
|
get_text_editor()->add_theme_color_override("search_result_color", search_result_color);
|
|
|
|
get_text_editor()->add_theme_color_override("search_result_border_color", search_result_border_color);
|
2020-05-03 16:08:15 +00:00
|
|
|
|
|
|
|
syntax_highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color"));
|
|
|
|
syntax_highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color"));
|
|
|
|
syntax_highlighter->set_function_color(EDITOR_GET("text_editor/highlighting/function_color"));
|
|
|
|
syntax_highlighter->set_member_variable_color(EDITOR_GET("text_editor/highlighting/member_variable_color"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-11-11 19:28:25 +00:00
|
|
|
syntax_highlighter->clear_keyword_colors();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> keywords;
|
2016-10-07 14:31:18 +00:00
|
|
|
ShaderLanguage::get_keyword_list(&keywords);
|
2019-11-11 19:28:25 +00:00
|
|
|
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
|
|
|
|
|
|
|
|
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
|
|
|
|
syntax_highlighter->add_keyword_color(E->get(), keyword_color);
|
|
|
|
}
|
2016-10-07 14:31:18 +00:00
|
|
|
|
2019-11-11 19:28:25 +00:00
|
|
|
// Colorize built-ins like `COLOR` differently to make them easier
|
|
|
|
// to distinguish from keywords at a quick glance.
|
|
|
|
|
|
|
|
List<String> built_ins;
|
2016-10-07 14:31:18 +00:00
|
|
|
if (shader.is_valid()) {
|
2020-03-27 18:21:27 +00:00
|
|
|
for (const Map<StringName, ShaderLanguage::FunctionInfo>::Element *E = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
|
2017-12-15 21:23:16 +00:00
|
|
|
for (const Map<StringName, ShaderLanguage::BuiltInInfo>::Element *F = E->get().built_ins.front(); F; F = F->next()) {
|
2019-11-11 19:28:25 +00:00
|
|
|
built_ins.push_back(F->key());
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode())).size(); i++) {
|
2019-11-11 19:28:25 +00:00
|
|
|
built_ins.push_back(ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode()))[i]);
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-11-11 19:28:25 +00:00
|
|
|
const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
|
|
|
|
|
|
|
|
for (List<String>::Element *E = built_ins.front(); E; E = E->next()) {
|
|
|
|
syntax_highlighter->add_keyword_color(E->get(), member_variable_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-11 19:28:25 +00:00
|
|
|
// Colorize comments.
|
2020-05-03 16:08:15 +00:00
|
|
|
const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
|
|
|
|
syntax_highlighter->clear_color_regions();
|
|
|
|
syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
|
2020-07-28 19:16:24 +00:00
|
|
|
syntax_highlighter->add_color_region("//", "", comment_color, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void ShaderTextEditor::_check_shader_mode() {
|
2020-07-24 14:50:35 +00:00
|
|
|
String type = ShaderLanguage::get_shader_type(get_text_editor()->get_text());
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
Shader::Mode mode;
|
|
|
|
|
|
|
|
if (type == "canvas_item") {
|
|
|
|
mode = Shader::MODE_CANVAS_ITEM;
|
|
|
|
} else if (type == "particles") {
|
|
|
|
mode = Shader::MODE_PARTICLES;
|
|
|
|
} else {
|
|
|
|
mode = Shader::MODE_SPATIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shader->get_mode() != mode) {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader->set_code(get_text_editor()->get_text());
|
2017-04-07 02:36:37 +00:00
|
|
|
_load_theme_settings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) {
|
|
|
|
RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable);
|
|
|
|
return RS::global_variable_type_get_shader_datatype(gvt);
|
|
|
|
}
|
|
|
|
|
2019-07-06 04:03:17 +00:00
|
|
|
void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options) {
|
2017-04-07 02:36:37 +00:00
|
|
|
_check_shader_mode();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
ShaderLanguage sl;
|
|
|
|
String calltip;
|
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
sl.complete(p_code, ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_types(), _get_global_variable_type, r_options, calltip);
|
2016-10-07 14:31:18 +00:00
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
get_text_editor()->set_code_hint(calltip);
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
void ShaderTextEditor::_validate_script() {
|
2017-04-07 02:36:37 +00:00
|
|
|
_check_shader_mode();
|
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
String code = get_text_editor()->get_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
//List<StringName> params;
|
|
|
|
//shader->get_param_list(¶ms);
|
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
ShaderLanguage sl;
|
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_types(), _get_global_variable_type);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (err != OK) {
|
|
|
|
String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
set_error(error_text);
|
2018-11-21 10:56:02 +00:00
|
|
|
set_error_pos(sl.get_error_line() - 1, 0);
|
2020-07-24 14:50:35 +00:00
|
|
|
for (int i = 0; i < get_text_editor()->get_line_count(); i++) {
|
|
|
|
get_text_editor()->set_line_as_marked(i, false);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-07-24 14:50:35 +00:00
|
|
|
get_text_editor()->set_line_as_marked(sl.get_error_line() - 1, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
2020-07-24 14:50:35 +00:00
|
|
|
for (int i = 0; i < get_text_editor()->get_line_count(); i++) {
|
|
|
|
get_text_editor()->set_line_as_marked(i, false);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
set_error("");
|
|
|
|
}
|
|
|
|
|
|
|
|
emit_signal("script_changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderTextEditor::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderTextEditor::ShaderTextEditor() {
|
2020-05-03 16:08:15 +00:00
|
|
|
syntax_highlighter.instance();
|
2020-07-24 14:50:35 +00:00
|
|
|
get_text_editor()->set_syntax_highlighter(syntax_highlighter);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** SCRIPT EDITOR ******/
|
|
|
|
|
|
|
|
void ShaderEditor::_menu_option(int p_option) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_option) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case EDIT_UNDO: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->undo();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_REDO: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->redo();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_CUT: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->cut();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_COPY: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->copy();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_PASTE: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->paste();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_SELECT_ALL: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->select_all();
|
2017-11-11 04:07:41 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_MOVE_LINE_UP: {
|
2018-05-25 22:49:35 +00:00
|
|
|
shader_editor->move_lines_up();
|
2017-11-11 04:07:41 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_MOVE_LINE_DOWN: {
|
2018-05-25 22:49:35 +00:00
|
|
|
shader_editor->move_lines_down();
|
2017-11-11 04:07:41 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_INDENT_LEFT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (shader.is_null()) {
|
2017-11-11 04:07:41 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-11-11 04:07:41 +00:00
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
CodeEdit *tx = shader_editor->get_text_editor();
|
2017-12-14 09:10:53 +00:00
|
|
|
tx->indent_left();
|
2017-11-11 04:07:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case EDIT_INDENT_RIGHT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (shader.is_null()) {
|
2017-11-11 04:07:41 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-11-11 04:07:41 +00:00
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
CodeEdit *tx = shader_editor->get_text_editor();
|
2017-12-14 09:10:53 +00:00
|
|
|
tx->indent_right();
|
2017-11-11 04:07:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case EDIT_DELETE_LINE: {
|
2018-05-25 22:49:35 +00:00
|
|
|
shader_editor->delete_lines();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-11-11 04:07:41 +00:00
|
|
|
case EDIT_CLONE_DOWN: {
|
2018-11-04 18:26:08 +00:00
|
|
|
shader_editor->clone_lines_down();
|
2017-11-11 04:07:41 +00:00
|
|
|
} break;
|
|
|
|
case EDIT_TOGGLE_COMMENT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (shader.is_null()) {
|
2017-11-11 04:07:41 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-11-11 04:07:41 +00:00
|
|
|
|
2019-02-04 19:17:44 +00:00
|
|
|
shader_editor->toggle_inline_comment("//");
|
2017-11-11 04:07:41 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case EDIT_COMPLETE: {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->query_code_comple();
|
2017-11-11 04:07:41 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case SEARCH_FIND: {
|
2017-11-11 04:07:41 +00:00
|
|
|
shader_editor->get_find_replace_bar()->popup_search();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case SEARCH_FIND_NEXT: {
|
2017-11-11 04:07:41 +00:00
|
|
|
shader_editor->get_find_replace_bar()->search_next();
|
2016-05-28 16:25:45 +00:00
|
|
|
} break;
|
|
|
|
case SEARCH_FIND_PREV: {
|
2017-11-11 04:07:41 +00:00
|
|
|
shader_editor->get_find_replace_bar()->search_prev();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case SEARCH_REPLACE: {
|
2017-11-11 04:07:41 +00:00
|
|
|
shader_editor->get_find_replace_bar()->popup_replace();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case SEARCH_GOTO_LINE: {
|
2020-07-24 14:50:35 +00:00
|
|
|
goto_line_dialog->popup_find_line(shader_editor->get_text_editor());
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2019-04-19 23:51:25 +00:00
|
|
|
case BOOKMARK_TOGGLE: {
|
|
|
|
shader_editor->toggle_bookmark();
|
|
|
|
} break;
|
|
|
|
case BOOKMARK_GOTO_NEXT: {
|
|
|
|
shader_editor->goto_next_bookmark();
|
|
|
|
} break;
|
|
|
|
case BOOKMARK_GOTO_PREV: {
|
|
|
|
shader_editor->goto_prev_bookmark();
|
|
|
|
} break;
|
|
|
|
case BOOKMARK_REMOVE_ALL: {
|
|
|
|
shader_editor->remove_all_bookmarks();
|
|
|
|
} break;
|
2019-08-02 14:03:45 +00:00
|
|
|
case HELP_DOCS: {
|
2021-01-03 16:32:55 +00:00
|
|
|
OS::get_singleton()->shell_open("https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/index.html");
|
2019-08-02 14:03:45 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-11-11 04:07:41 +00:00
|
|
|
if (p_option != SEARCH_FIND && p_option != SEARCH_REPLACE && p_option != SEARCH_GOTO_LINE) {
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->call_deferred("grab_focus");
|
2017-11-11 04:07:41 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditor::_notification(int p_what) {
|
2020-06-29 23:47:18 +00:00
|
|
|
if (p_what == NOTIFICATION_WM_WINDOW_FOCUS_IN) {
|
2018-10-08 19:26:45 +00:00
|
|
|
_check_for_external_edit();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditor::_params_changed() {
|
2016-10-07 14:31:18 +00:00
|
|
|
shader_editor->_validate_script();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 11:39:04 +00:00
|
|
|
void ShaderEditor::_editor_settings_changed() {
|
2020-07-30 11:22:09 +00:00
|
|
|
shader_editor->update_editor_settings();
|
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->add_theme_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing"));
|
2020-07-26 14:57:23 +00:00
|
|
|
shader_editor->get_text_editor()->set_draw_breakpoints_gutter(false);
|
2020-07-30 11:22:09 +00:00
|
|
|
shader_editor->get_text_editor()->set_draw_executing_lines_gutter(false);
|
2016-04-29 11:39:04 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void ShaderEditor::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditor::ensure_select_current() {
|
2017-03-05 15:44:50 +00:00
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) {
|
2017-08-24 20:58:51 +00:00
|
|
|
ShaderTextEditor *ste = Object::cast_to<ShaderTextEditor>(tab_container->get_child(tab_container->get_current_tab()));
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!ste)
|
|
|
|
return;
|
|
|
|
Ref<Shader> shader = ste->get_edited_shader();
|
|
|
|
get_scene()->get_root_node()->call("_resource_selected",shader);
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2018-10-27 15:24:41 +00:00
|
|
|
void ShaderEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
|
|
|
|
shader_editor->goto_line_selection(p_line, p_begin, p_end);
|
|
|
|
}
|
|
|
|
|
2018-10-08 19:26:45 +00:00
|
|
|
void ShaderEditor::_check_for_external_edit() {
|
|
|
|
if (shader.is_null() || !shader.is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// internal shader.
|
|
|
|
if (shader->get_path() == "" || shader->get_path().find("local://") != -1 || shader->get_path().find("::") != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool use_autoreload = bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", false));
|
|
|
|
if (shader->get_last_modified_time() != FileAccess::get_modified_time(shader->get_path())) {
|
|
|
|
if (use_autoreload) {
|
|
|
|
_reload_shader_from_disk();
|
|
|
|
} else {
|
|
|
|
disk_changed->call_deferred("popup_centered");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditor::_reload_shader_from_disk() {
|
|
|
|
Ref<Shader> rel_shader = ResourceLoader::load(shader->get_path(), shader->get_class(), true);
|
|
|
|
ERR_FAIL_COND(!rel_shader.is_valid());
|
|
|
|
|
|
|
|
shader->set_code(rel_shader->get_code());
|
|
|
|
shader->set_last_modified_time(rel_shader->get_last_modified_time());
|
|
|
|
shader_editor->reload_text();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ShaderEditor::edit(const Ref<Shader> &p_shader) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_shader.is_null() || !p_shader->is_text_shader()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (shader == p_shader) {
|
2019-03-04 22:37:05 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-03-04 22:37:05 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shader = p_shader;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
shader_editor->set_edited_shader(p_shader);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-01-21 03:57:37 +00:00
|
|
|
//vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
|
2014-02-10 01:10:30 +00:00
|
|
|
// see if already has it
|
|
|
|
}
|
|
|
|
|
2018-10-08 19:26:45 +00:00
|
|
|
void ShaderEditor::save_external_data(const String &p_str) {
|
|
|
|
if (shader.is_null()) {
|
|
|
|
disk_changed->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2018-10-08 19:26:45 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-10-08 19:26:45 +00:00
|
|
|
apply_shaders();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (shader->get_path() != "" && shader->get_path().find("local://") == -1 && shader->get_path().find("::") == -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//external shader, save it
|
2017-03-05 15:44:50 +00:00
|
|
|
ResourceSaver::save(shader->get_path(), shader);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2018-10-08 19:26:45 +00:00
|
|
|
|
|
|
|
disk_changed->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ShaderEditor::apply_shaders() {
|
2014-08-14 13:31:38 +00:00
|
|
|
if (shader.is_valid()) {
|
2019-03-04 22:37:05 +00:00
|
|
|
String shader_code = shader->get_code();
|
2020-07-24 14:50:35 +00:00
|
|
|
String editor_code = shader_editor->get_text_editor()->get_text();
|
2019-03-04 22:37:05 +00:00
|
|
|
if (shader_code != editor_code) {
|
|
|
|
shader->set_code(editor_code);
|
|
|
|
shader->set_edited(true);
|
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:07:41 +00:00
|
|
|
void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
|
|
|
Ref<InputEventMouseButton> mb = ev;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-11 04:07:41 +00:00
|
|
|
if (mb.is_valid()) {
|
2018-01-02 07:10:49 +00:00
|
|
|
if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
|
2017-11-11 04:07:41 +00:00
|
|
|
int col, row;
|
2020-07-24 14:50:35 +00:00
|
|
|
CodeEdit *tx = shader_editor->get_text_editor();
|
2017-11-11 04:07:41 +00:00
|
|
|
tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
|
2017-12-20 01:36:47 +00:00
|
|
|
tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
|
|
|
|
|
|
|
|
if (tx->is_right_click_moving_caret()) {
|
|
|
|
if (tx->is_selection_active()) {
|
|
|
|
int from_line = tx->get_selection_from_line();
|
|
|
|
int to_line = tx->get_selection_to_line();
|
|
|
|
int from_column = tx->get_selection_from_column();
|
|
|
|
int to_column = tx->get_selection_to_column();
|
|
|
|
|
|
|
|
if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
|
2018-09-13 01:38:39 +00:00
|
|
|
// Right click is outside the selected text
|
2017-12-20 01:36:47 +00:00
|
|
|
tx->deselect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!tx->is_selection_active()) {
|
|
|
|
tx->cursor_set_line(row, true, false);
|
|
|
|
tx->cursor_set_column(col);
|
|
|
|
}
|
|
|
|
}
|
2019-06-22 18:22:52 +00:00
|
|
|
_make_context_menu(tx->is_selection_active(), get_local_mouse_position());
|
2017-11-11 04:07:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-22 18:22:52 +00:00
|
|
|
|
|
|
|
Ref<InputEventKey> k = ev;
|
2018-04-05 17:59:35 +00:00
|
|
|
if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_MENU) {
|
2020-07-24 14:50:35 +00:00
|
|
|
CodeEdit *tx = shader_editor->get_text_editor();
|
2019-06-22 18:22:52 +00:00
|
|
|
_make_context_menu(tx->is_selection_active(), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos()));
|
|
|
|
context_menu->grab_focus();
|
|
|
|
}
|
2017-11-11 04:07:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 08:07:48 +00:00
|
|
|
void ShaderEditor::_update_bookmark_list() {
|
2019-08-09 01:36:51 +00:00
|
|
|
bookmarks_menu->clear();
|
2019-05-21 08:07:48 +00:00
|
|
|
|
2019-08-09 01:36:51 +00:00
|
|
|
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
|
|
|
|
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
|
|
|
|
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
|
|
|
|
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
|
2019-05-21 08:07:48 +00:00
|
|
|
|
2020-07-26 14:57:23 +00:00
|
|
|
Array bookmark_list = shader_editor->get_text_editor()->get_bookmarked_lines();
|
2019-05-21 08:07:48 +00:00
|
|
|
if (bookmark_list.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-09 01:36:51 +00:00
|
|
|
bookmarks_menu->add_separator();
|
2019-05-21 08:07:48 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < bookmark_list.size(); i++) {
|
2020-07-24 14:50:35 +00:00
|
|
|
String line = shader_editor->get_text_editor()->get_line(bookmark_list[i]).strip_edges();
|
2019-05-21 08:07:48 +00:00
|
|
|
// Limit the size of the line if too big.
|
|
|
|
if (line.length() > 50) {
|
|
|
|
line = line.substr(0, 50);
|
|
|
|
}
|
|
|
|
|
2019-08-09 01:36:51 +00:00
|
|
|
bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\"");
|
|
|
|
bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]);
|
2019-05-21 08:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditor::_bookmark_item_pressed(int p_idx) {
|
|
|
|
if (p_idx < 4) { // Any item before the separator.
|
2019-08-09 01:36:51 +00:00
|
|
|
_menu_option(bookmarks_menu->get_item_id(p_idx));
|
2019-05-21 08:07:48 +00:00
|
|
|
} else {
|
2019-08-09 01:36:51 +00:00
|
|
|
shader_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx));
|
2019-05-21 08:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-22 18:22:52 +00:00
|
|
|
void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) {
|
2017-11-11 04:07:41 +00:00
|
|
|
context_menu->clear();
|
|
|
|
if (p_selection) {
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
|
|
|
}
|
|
|
|
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
|
|
|
context_menu->add_separator();
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
|
|
|
|
|
|
|
context_menu->add_separator();
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
|
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
2019-05-21 08:07:48 +00:00
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
|
2017-11-11 04:07:41 +00:00
|
|
|
|
2019-06-22 18:22:52 +00:00
|
|
|
context_menu->set_position(get_global_transform().xform(p_position));
|
2017-11-11 04:07:41 +00:00
|
|
|
context_menu->set_size(Vector2(1, 1));
|
|
|
|
context_menu->popup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderEditor::ShaderEditor(EditorNode *p_node) {
|
|
|
|
shader_editor = memnew(ShaderTextEditor);
|
|
|
|
shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
|
2020-03-12 12:37:40 +00:00
|
|
|
shader_editor->add_theme_constant_override("separation", 0);
|
2020-12-22 16:24:29 +00:00
|
|
|
shader_editor->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
|
2017-11-11 04:07:41 +00:00
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
shader_editor->connect("script_changed", callable_mp(this, &ShaderEditor::apply_shaders));
|
|
|
|
EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &ShaderEditor::_editor_settings_changed));
|
2017-11-11 04:07:41 +00:00
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->set_callhint_settings(
|
2017-11-11 04:07:41 +00:00
|
|
|
EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"),
|
|
|
|
EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset"));
|
|
|
|
|
2020-07-24 14:50:35 +00:00
|
|
|
shader_editor->get_text_editor()->set_select_identifiers_on_hover(true);
|
|
|
|
shader_editor->get_text_editor()->set_context_menu_enabled(false);
|
|
|
|
shader_editor->get_text_editor()->connect("gui_input", callable_mp(this, &ShaderEditor::_text_edit_gui_input));
|
2017-11-11 04:07:41 +00:00
|
|
|
|
|
|
|
shader_editor->update_editor_settings();
|
|
|
|
|
|
|
|
context_menu = memnew(PopupMenu);
|
|
|
|
add_child(context_menu);
|
2020-02-21 17:28:45 +00:00
|
|
|
context_menu->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
|
2017-11-11 04:07:41 +00:00
|
|
|
|
|
|
|
VBoxContainer *main_container = memnew(VBoxContainer);
|
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_menu = memnew(MenuButton);
|
2020-09-17 01:40:00 +00:00
|
|
|
edit_menu->set_shortcut_context(this);
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_menu->set_text(TTR("Edit"));
|
2018-07-29 22:26:43 +00:00
|
|
|
edit_menu->set_switch_on_hover(true);
|
2020-03-12 12:37:40 +00:00
|
|
|
|
2017-11-11 04:07:41 +00:00
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
|
|
|
edit_menu->get_popup()->add_separator();
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
|
|
|
edit_menu->get_popup()->add_separator();
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_menu->get_popup()->add_separator();
|
2017-11-11 04:07:41 +00:00
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_menu->get_popup()->add_separator();
|
2017-11-11 04:07:41 +00:00
|
|
|
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
|
2020-02-21 17:28:45 +00:00
|
|
|
edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
search_menu = memnew(MenuButton);
|
2020-09-17 01:40:00 +00:00
|
|
|
search_menu->set_shortcut_context(this);
|
2016-05-04 01:25:37 +00:00
|
|
|
search_menu->set_text(TTR("Search"));
|
2018-07-29 22:26:43 +00:00
|
|
|
search_menu->set_switch_on_hover(true);
|
2020-03-12 12:37:40 +00:00
|
|
|
|
2017-11-11 04:07:41 +00:00
|
|
|
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
|
|
|
|
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
|
|
|
|
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
|
|
|
|
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
|
2020-02-21 17:28:45 +00:00
|
|
|
search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-08-09 01:36:51 +00:00
|
|
|
MenuButton *goto_menu = memnew(MenuButton);
|
2020-09-17 01:40:00 +00:00
|
|
|
goto_menu->set_shortcut_context(this);
|
2019-08-09 01:36:51 +00:00
|
|
|
goto_menu->set_text(TTR("Go To"));
|
|
|
|
goto_menu->set_switch_on_hover(true);
|
2020-02-21 17:28:45 +00:00
|
|
|
goto_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
|
2019-08-09 01:36:51 +00:00
|
|
|
|
|
|
|
goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
|
|
|
|
goto_menu->get_popup()->add_separator();
|
|
|
|
|
|
|
|
bookmarks_menu = memnew(PopupMenu);
|
|
|
|
bookmarks_menu->set_name("Bookmarks");
|
|
|
|
goto_menu->get_popup()->add_child(bookmarks_menu);
|
|
|
|
goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks");
|
2019-05-21 08:07:48 +00:00
|
|
|
_update_bookmark_list();
|
2020-03-12 12:37:40 +00:00
|
|
|
bookmarks_menu->connect("about_to_popup", callable_mp(this, &ShaderEditor::_update_bookmark_list));
|
2020-02-21 17:28:45 +00:00
|
|
|
bookmarks_menu->connect("index_pressed", callable_mp(this, &ShaderEditor::_bookmark_item_pressed));
|
2019-04-19 23:51:25 +00:00
|
|
|
|
2019-08-02 14:03:45 +00:00
|
|
|
help_menu = memnew(MenuButton);
|
|
|
|
help_menu->set_text(TTR("Help"));
|
|
|
|
help_menu->set_switch_on_hover(true);
|
2020-03-12 12:37:40 +00:00
|
|
|
help_menu->get_popup()->add_icon_item(p_node->get_gui_base()->get_theme_icon("Instance", "EditorIcons"), TTR("Online Docs"), HELP_DOCS);
|
2020-02-21 17:28:45 +00:00
|
|
|
help_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
|
2019-08-02 14:03:45 +00:00
|
|
|
|
2017-11-11 04:07:41 +00:00
|
|
|
add_child(main_container);
|
|
|
|
main_container->add_child(hbc);
|
|
|
|
hbc->add_child(search_menu);
|
|
|
|
hbc->add_child(edit_menu);
|
2019-08-09 01:36:51 +00:00
|
|
|
hbc->add_child(goto_menu);
|
2019-08-02 14:03:45 +00:00
|
|
|
hbc->add_child(help_menu);
|
2020-03-12 12:37:40 +00:00
|
|
|
hbc->add_theme_style_override("panel", p_node->get_gui_base()->get_theme_stylebox("ScriptEditorPanel", "EditorStyles"));
|
2017-11-11 04:07:41 +00:00
|
|
|
main_container->add_child(shader_editor);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
goto_line_dialog = memnew(GotoLineDialog);
|
|
|
|
add_child(goto_line_dialog);
|
|
|
|
|
2018-10-08 19:26:45 +00:00
|
|
|
disk_changed = memnew(ConfirmationDialog);
|
|
|
|
|
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
|
|
|
disk_changed->add_child(vbc);
|
|
|
|
|
|
|
|
Label *dl = memnew(Label);
|
|
|
|
dl->set_text(TTR("This shader has been modified on on disk.\nWhat action should be taken?"));
|
|
|
|
vbc->add_child(dl);
|
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
disk_changed->connect("confirmed", callable_mp(this, &ShaderEditor::_reload_shader_from_disk));
|
2020-12-14 18:37:30 +00:00
|
|
|
disk_changed->get_ok_button()->set_text(TTR("Reload"));
|
2018-10-08 19:26:45 +00:00
|
|
|
|
2020-07-08 23:02:38 +00:00
|
|
|
disk_changed->add_button(TTR("Resave"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "resave");
|
2020-02-21 17:28:45 +00:00
|
|
|
disk_changed->connect("custom_action", callable_mp(this, &ShaderEditor::save_external_data));
|
2018-10-08 19:26:45 +00:00
|
|
|
|
|
|
|
add_child(disk_changed);
|
|
|
|
|
2016-04-29 11:39:04 +00:00
|
|
|
_editor_settings_changed();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditorPlugin::edit(Object *p_object) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Shader *s = Object::cast_to<Shader>(p_object);
|
2016-10-07 14:31:18 +00:00
|
|
|
shader_editor->edit(s);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderEditorPlugin::handles(Object *p_object) const {
|
2017-08-24 20:58:51 +00:00
|
|
|
Shader *shader = Object::cast_to<Shader>(p_object);
|
2020-04-01 23:20:12 +00:00
|
|
|
return shader != nullptr && shader->is_text_shader();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
if (p_visible) {
|
2016-10-07 14:31:18 +00:00
|
|
|
button->show();
|
|
|
|
editor->make_bottom_panel_item_visible(shader_editor);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2016-10-07 14:31:18 +00:00
|
|
|
button->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (shader_editor->is_visible_in_tree()) {
|
2016-10-07 14:31:18 +00:00
|
|
|
editor->hide_bottom_panel();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
shader_editor->apply_shaders();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditorPlugin::selected_notify() {
|
|
|
|
shader_editor->ensure_select_current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditorPlugin::save_external_data() {
|
|
|
|
shader_editor->save_external_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderEditorPlugin::apply_changes() {
|
|
|
|
shader_editor->apply_shaders();
|
|
|
|
}
|
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
|
2017-03-05 15:44:50 +00:00
|
|
|
editor = p_node;
|
2017-11-11 04:07:41 +00:00
|
|
|
shader_editor = memnew(ShaderEditor(p_node));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-01-12 07:24:15 +00:00
|
|
|
shader_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
|
2017-06-12 22:23:37 +00:00
|
|
|
button = editor->add_bottom_panel_item(TTR("Shader"), shader_editor);
|
|
|
|
button->hide();
|
2020-11-24 09:12:55 +00:00
|
|
|
|
|
|
|
_2d = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderEditorPlugin::~ShaderEditorPlugin() {
|
|
|
|
}
|