You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
@@ -28,113 +28,99 @@
|
||||
/*************************************************************************/
|
||||
#include "shader_editor_plugin.h"
|
||||
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "spatial_editor_plugin.h"
|
||||
#include "scene/resources/shader_graph.h"
|
||||
#include "editor/property_editor.h"
|
||||
#include "io/resource_loader.h"
|
||||
#include "io/resource_saver.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/property_editor.h"
|
||||
#include "os/os.h"
|
||||
#include "scene/resources/shader_graph.h"
|
||||
#include "servers/visual/shader_types.h"
|
||||
#include "spatial_editor_plugin.h"
|
||||
|
||||
/*** SETTINGS EDITOR ****/
|
||||
|
||||
|
||||
|
||||
|
||||
/*** SCRIPT EDITOR ****/
|
||||
|
||||
|
||||
Ref<Shader> ShaderTextEditor::get_edited_shader() const {
|
||||
|
||||
return shader;
|
||||
}
|
||||
void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader) {
|
||||
|
||||
shader=p_shader;
|
||||
void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) {
|
||||
|
||||
shader = p_shader;
|
||||
|
||||
_load_theme_settings();
|
||||
|
||||
get_text_edit()->set_text(p_shader->get_code());
|
||||
|
||||
_line_col_changed();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ShaderTextEditor::_load_theme_settings() {
|
||||
|
||||
get_text_edit()->clear_colors();
|
||||
|
||||
/* keyword color */
|
||||
|
||||
get_text_edit()->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color",Color(0,0,0,0)));
|
||||
get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0,0,0,0)));
|
||||
get_text_edit()->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0)));
|
||||
get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0)));
|
||||
get_text_edit()->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244")));
|
||||
get_text_edit()->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf")));
|
||||
get_text_edit()->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/highlighting/completion_scroll_color", Color::html("ffffff")));
|
||||
get_text_edit()->add_color_override("completion_font_color", EDITOR_DEF("text_editor/highlighting/completion_font_color", Color::html("aaaaaa")));
|
||||
get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/highlighting/text_color",Color(0,0,0)));
|
||||
get_text_edit()->add_color_override("line_number_color",EDITOR_DEF("text_editor/highlighting/line_number_color",Color(0,0,0)));
|
||||
get_text_edit()->add_color_override("caret_color",EDITOR_DEF("text_editor/highlighting/caret_color",Color(0,0,0)));
|
||||
get_text_edit()->add_color_override("caret_background_color",EDITOR_DEF("text_editor/highlighting/caret_background_color",Color(0,0,0)));
|
||||
get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/highlighting/text_selected_color",Color(1,1,1)));
|
||||
get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/highlighting/selection_color",Color(0.2,0.2,1)));
|
||||
get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/highlighting/brace_mismatch_color",Color(1,0.2,0.2)));
|
||||
get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/highlighting/current_line_color",Color(0.3,0.5,0.8,0.15)));
|
||||
get_text_edit()->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/highlighting/word_highlighted_color",Color(0.8,0.9,0.9,0.15)));
|
||||
get_text_edit()->add_color_override("number_color",EDITOR_DEF("text_editor/highlighting/number_color",Color(0.9,0.6,0.0,2)));
|
||||
get_text_edit()->add_color_override("function_color",EDITOR_DEF("text_editor/highlighting/function_color",Color(0.4,0.6,0.8)));
|
||||
get_text_edit()->add_color_override("member_variable_color",EDITOR_DEF("text_editor/highlighting/member_variable_color",Color(0.9,0.3,0.3)));
|
||||
get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0,0.4,0.4,0.4)));
|
||||
get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8,0.8,0.4,0.2)));
|
||||
get_text_edit()->add_color_override("search_result_color",EDITOR_DEF("text_editor/highlighting/search_result_color",Color(0.05,0.25,0.05,1)));
|
||||
get_text_edit()->add_color_override("search_result_border_color",EDITOR_DEF("text_editor/highlighting/search_result_border_color",Color(0.1,0.45,0.1,1)));
|
||||
get_text_edit()->add_color_override("symbol_color",EDITOR_DEF("text_editor/highlighting/symbol_color",Color::hex(0x005291ff)));
|
||||
|
||||
Color keyword_color= EDITOR_DEF("text_editor/highlighting/keyword_color",Color(0.5,0.0,0.2));
|
||||
get_text_edit()->add_color_override("font_color", EDITOR_DEF("text_editor/highlighting/text_color", Color(0, 0, 0)));
|
||||
get_text_edit()->add_color_override("line_number_color", EDITOR_DEF("text_editor/highlighting/line_number_color", Color(0, 0, 0)));
|
||||
get_text_edit()->add_color_override("caret_color", EDITOR_DEF("text_editor/highlighting/caret_color", Color(0, 0, 0)));
|
||||
get_text_edit()->add_color_override("caret_background_color", EDITOR_DEF("text_editor/highlighting/caret_background_color", Color(0, 0, 0)));
|
||||
get_text_edit()->add_color_override("font_selected_color", EDITOR_DEF("text_editor/highlighting/text_selected_color", Color(1, 1, 1)));
|
||||
get_text_edit()->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1)));
|
||||
get_text_edit()->add_color_override("brace_mismatch_color", EDITOR_DEF("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2)));
|
||||
get_text_edit()->add_color_override("current_line_color", EDITOR_DEF("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15)));
|
||||
get_text_edit()->add_color_override("word_highlighted_color", EDITOR_DEF("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15)));
|
||||
get_text_edit()->add_color_override("number_color", EDITOR_DEF("text_editor/highlighting/number_color", Color(0.9, 0.6, 0.0, 2)));
|
||||
get_text_edit()->add_color_override("function_color", EDITOR_DEF("text_editor/highlighting/function_color", Color(0.4, 0.6, 0.8)));
|
||||
get_text_edit()->add_color_override("member_variable_color", EDITOR_DEF("text_editor/highlighting/member_variable_color", Color(0.9, 0.3, 0.3)));
|
||||
get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4)));
|
||||
get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2)));
|
||||
get_text_edit()->add_color_override("search_result_color", EDITOR_DEF("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1)));
|
||||
get_text_edit()->add_color_override("search_result_border_color", EDITOR_DEF("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1)));
|
||||
get_text_edit()->add_color_override("symbol_color", EDITOR_DEF("text_editor/highlighting/symbol_color", Color::hex(0x005291ff)));
|
||||
|
||||
Color keyword_color = EDITOR_DEF("text_editor/highlighting/keyword_color", Color(0.5, 0.0, 0.2));
|
||||
|
||||
List<String> keywords;
|
||||
ShaderLanguage::get_keyword_list(&keywords);
|
||||
|
||||
if (shader.is_valid()) {
|
||||
|
||||
for (const Map<StringName, Map<StringName, ShaderLanguage::DataType> >::Element *E = ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
|
||||
|
||||
for(const Map< StringName, Map<StringName,ShaderLanguage::DataType> >::Element *E=ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front();E;E=E->next()) {
|
||||
|
||||
for (const Map<StringName,ShaderLanguage::DataType>::Element *F=E->get().front();F;F=F->next()) {
|
||||
for (const Map<StringName, ShaderLanguage::DataType>::Element *F = E->get().front(); F; F = F->next()) {
|
||||
keywords.push_back(F->key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(const Set<String>::Element *E =ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front();E;E=E->next()) {
|
||||
for (const Set<String>::Element *E = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
|
||||
|
||||
keywords.push_back(E->get());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
|
||||
|
||||
for(List<String>::Element *E=keywords.front();E;E=E->next()) {
|
||||
|
||||
get_text_edit()->add_keyword_color(E->get(),keyword_color);
|
||||
get_text_edit()->add_keyword_color(E->get(), keyword_color);
|
||||
}
|
||||
|
||||
//colorize core types
|
||||
//Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));
|
||||
|
||||
|
||||
//colorize comments
|
||||
Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color",Color::hex(0x797e7eff));
|
||||
Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color", Color::hex(0x797e7eff));
|
||||
|
||||
get_text_edit()->add_color_region("/*","*/",comment_color,false);
|
||||
get_text_edit()->add_color_region("//","",comment_color,false);
|
||||
get_text_edit()->add_color_region("/*", "*/", comment_color, false);
|
||||
get_text_edit()->add_color_region("//", "", comment_color, false);
|
||||
|
||||
/*//colorize strings
|
||||
Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
|
||||
@@ -151,38 +137,38 @@ void ShaderTextEditor::_load_theme_settings() {
|
||||
}*/
|
||||
}
|
||||
|
||||
void ShaderTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) {
|
||||
void ShaderTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) {
|
||||
|
||||
print_line("code complete");
|
||||
|
||||
ShaderLanguage sl;
|
||||
String calltip;
|
||||
|
||||
Error err = sl.complete(p_code,ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())),ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())),r_options,calltip);
|
||||
Error err = sl.complete(p_code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())), r_options, calltip);
|
||||
|
||||
if (calltip!="") {
|
||||
if (calltip != "") {
|
||||
get_text_edit()->set_code_hint(calltip);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderTextEditor::_validate_script() {
|
||||
|
||||
String code=get_text_edit()->get_text();
|
||||
String code = get_text_edit()->get_text();
|
||||
//List<StringName> params;
|
||||
//shader->get_param_list(¶ms);
|
||||
|
||||
ShaderLanguage sl;
|
||||
|
||||
Error err = sl.compile(code,ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())),ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())));
|
||||
Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())));
|
||||
|
||||
if (err!=OK) {
|
||||
String error_text="error("+itos(sl.get_error_line())+"): "+sl.get_error_text();
|
||||
if (err != OK) {
|
||||
String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
|
||||
set_error(error_text);
|
||||
get_text_edit()->set_line_as_marked(sl.get_error_line(),true);
|
||||
get_text_edit()->set_line_as_marked(sl.get_error_line(), true);
|
||||
|
||||
} else {
|
||||
for(int i=0;i<get_text_edit()->get_line_count();i++)
|
||||
get_text_edit()->set_line_as_marked(i,false);
|
||||
for (int i = 0; i < get_text_edit()->get_line_count(); i++)
|
||||
get_text_edit()->set_line_as_marked(i, false);
|
||||
set_error("");
|
||||
}
|
||||
|
||||
@@ -191,29 +177,21 @@ void ShaderTextEditor::_validate_script() {
|
||||
|
||||
void ShaderTextEditor::_bind_methods() {
|
||||
|
||||
|
||||
//ADD_SIGNAL( MethodInfo("script_changed") );
|
||||
|
||||
}
|
||||
|
||||
ShaderTextEditor::ShaderTextEditor() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*** SCRIPT EDITOR ******/
|
||||
|
||||
|
||||
|
||||
void ShaderEditor::_menu_option(int p_option) {
|
||||
|
||||
|
||||
ShaderTextEditor *current = shader_editor;
|
||||
|
||||
switch(p_option) {
|
||||
switch (p_option) {
|
||||
case EDIT_UNDO: {
|
||||
|
||||
|
||||
current->get_text_edit()->undo();
|
||||
} break;
|
||||
case EDIT_REDO: {
|
||||
@@ -260,29 +238,21 @@ void ShaderEditor::_menu_option(int p_option) {
|
||||
|
||||
goto_line_dialog->popup_find_line(current->get_text_edit());
|
||||
} break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShaderEditor::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
}
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Ref<StyleBox> style = get_stylebox("panel","Panel");
|
||||
style->draw( ci, Rect2( Point2(), get_size() ) );
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("panel", "Panel");
|
||||
style->draw(ci, Rect2(Point2(), get_size()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Dictionary ShaderEditor::get_state() const {
|
||||
#if 0
|
||||
apply_shaders();
|
||||
@@ -326,7 +296,7 @@ Dictionary ShaderEditor::get_state() const {
|
||||
#endif
|
||||
return Dictionary();
|
||||
}
|
||||
void ShaderEditor::set_state(const Dictionary& p_state) {
|
||||
void ShaderEditor::set_state(const Dictionary &p_state) {
|
||||
#if 0
|
||||
print_line("setting state..");
|
||||
if (!p_state.has("sources"))
|
||||
@@ -365,43 +335,41 @@ void ShaderEditor::set_state(const Dictionary& p_state) {
|
||||
#endif
|
||||
}
|
||||
void ShaderEditor::clear() {
|
||||
|
||||
}
|
||||
|
||||
void ShaderEditor::_params_changed() {
|
||||
|
||||
|
||||
shader_editor->_validate_script();
|
||||
}
|
||||
|
||||
void ShaderEditor::_editor_settings_changed() {
|
||||
|
||||
shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
|
||||
shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
|
||||
shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size"));
|
||||
shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs"));
|
||||
shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers"));
|
||||
shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
|
||||
shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences"));
|
||||
shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
|
||||
shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
|
||||
shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing"));
|
||||
shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
|
||||
shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
|
||||
shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
|
||||
shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size"));
|
||||
shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs"));
|
||||
shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers"));
|
||||
shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
|
||||
shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences"));
|
||||
shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
|
||||
shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
|
||||
shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing"));
|
||||
shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
|
||||
}
|
||||
|
||||
void ShaderEditor::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method("_editor_settings_changed",&ShaderEditor::_editor_settings_changed);
|
||||
ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed);
|
||||
|
||||
ClassDB::bind_method("_menu_option",&ShaderEditor::_menu_option);
|
||||
ClassDB::bind_method("_params_changed",&ShaderEditor::_params_changed);
|
||||
ClassDB::bind_method("apply_shaders",&ShaderEditor::apply_shaders);
|
||||
ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option);
|
||||
ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed);
|
||||
ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders);
|
||||
//ClassDB::bind_method("_close_current_tab",&ShaderEditor::_close_current_tab);
|
||||
}
|
||||
|
||||
void ShaderEditor::ensure_select_current() {
|
||||
|
||||
/*
|
||||
/*
|
||||
if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) {
|
||||
|
||||
ShaderTextEditor *ste = tab_container->get_child(tab_container->get_current_tab())->cast_to<ShaderTextEditor>();
|
||||
@@ -412,20 +380,17 @@ void ShaderEditor::ensure_select_current() {
|
||||
}*/
|
||||
}
|
||||
|
||||
void ShaderEditor::edit(const Ref<Shader>& p_shader) {
|
||||
void ShaderEditor::edit(const Ref<Shader> &p_shader) {
|
||||
|
||||
if (p_shader.is_null())
|
||||
return;
|
||||
|
||||
|
||||
shader=p_shader;
|
||||
shader = p_shader;
|
||||
|
||||
shader_editor->set_edited_shader(p_shader);
|
||||
|
||||
//vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
|
||||
// see if already has it
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ShaderEditor::save_external_data() {
|
||||
@@ -434,14 +399,13 @@ void ShaderEditor::save_external_data() {
|
||||
return;
|
||||
apply_shaders();
|
||||
|
||||
if (shader->get_path()!="" && shader->get_path().find("local://")==-1 &&shader->get_path().find("::")==-1) {
|
||||
if (shader->get_path() != "" && shader->get_path().find("local://") == -1 && shader->get_path().find("::") == -1) {
|
||||
//external shader, save it
|
||||
ResourceSaver::save(shader->get_path(),shader);
|
||||
ResourceSaver::save(shader->get_path(), shader);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderEditor::apply_shaders() {
|
||||
|
||||
void ShaderEditor::apply_shaders() {
|
||||
|
||||
if (shader.is_valid()) {
|
||||
shader->set_code(shader_editor->get_text_edit()->get_text());
|
||||
@@ -449,75 +413,68 @@ void ShaderEditor::apply_shaders() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ShaderEditor::ShaderEditor() {
|
||||
|
||||
|
||||
HBoxContainer *hbc = memnew( HBoxContainer);
|
||||
HBoxContainer *hbc = memnew(HBoxContainer);
|
||||
|
||||
add_child(hbc);
|
||||
|
||||
edit_menu = memnew( MenuButton );
|
||||
edit_menu = memnew(MenuButton);
|
||||
hbc->add_child(edit_menu);
|
||||
edit_menu->set_pos(Point2(5,-1));
|
||||
edit_menu->set_pos(Point2(5, -1));
|
||||
edit_menu->set_text(TTR("Edit"));
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD|KEY_Z), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD|KEY_Y), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD|KEY_X), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD|KEY_C), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD|KEY_V), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD|KEY_A), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->connect("id_pressed", this,"_menu_option");
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->connect("id_pressed", this, "_menu_option");
|
||||
|
||||
|
||||
search_menu = memnew( MenuButton );
|
||||
search_menu = memnew(MenuButton);
|
||||
hbc->add_child(search_menu);
|
||||
search_menu->set_pos(Point2(38,-1));
|
||||
search_menu->set_pos(Point2(38, -1));
|
||||
search_menu->set_text(TTR("Search"));
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F), SEARCH_FIND);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), SEARCH_FIND);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT|KEY_F3), SEARCH_FIND_PREV);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD|KEY_R), SEARCH_REPLACE);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), SEARCH_FIND_PREV);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R), SEARCH_REPLACE);
|
||||
search_menu->get_popup()->add_separator();
|
||||
//search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K);
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD|KEY_L), SEARCH_GOTO_LINE);
|
||||
search_menu->get_popup()->connect("id_pressed", this,"_menu_option");
|
||||
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L), SEARCH_GOTO_LINE);
|
||||
search_menu->get_popup()->connect("id_pressed", this, "_menu_option");
|
||||
|
||||
goto_line_dialog = memnew(GotoLineDialog);
|
||||
add_child(goto_line_dialog);
|
||||
|
||||
shader_editor = memnew( ShaderTextEditor );
|
||||
shader_editor = memnew(ShaderTextEditor);
|
||||
add_child(shader_editor);
|
||||
shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
|
||||
shader_editor->connect("script_changed", this,"apply_shaders");
|
||||
EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
|
||||
shader_editor->connect("script_changed", this, "apply_shaders");
|
||||
EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
|
||||
|
||||
_editor_settings_changed();
|
||||
}
|
||||
|
||||
|
||||
void ShaderEditorPlugin::edit(Object *p_object) {
|
||||
|
||||
Shader* s = p_object->cast_to<Shader>();
|
||||
Shader *s = p_object->cast_to<Shader>();
|
||||
shader_editor->edit(s);
|
||||
|
||||
}
|
||||
|
||||
bool ShaderEditorPlugin::handles(Object *p_object) const {
|
||||
|
||||
bool handles = true;
|
||||
Shader *shader=p_object->cast_to<Shader>();
|
||||
Shader *shader = p_object->cast_to<Shader>();
|
||||
/*
|
||||
if (!shader || shader->cast_to<ShaderGraph>()) // Dont handle ShaderGraph's
|
||||
handles = false;
|
||||
*/
|
||||
|
||||
return shader!=NULL;
|
||||
return shader != NULL;
|
||||
}
|
||||
|
||||
void ShaderEditorPlugin::make_visible(bool p_visible) {
|
||||
@@ -532,9 +489,7 @@ void ShaderEditorPlugin::make_visible(bool p_visible) {
|
||||
if (shader_editor->is_visible_in_tree())
|
||||
editor->hide_bottom_panel();
|
||||
shader_editor->apply_shaders();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ShaderEditorPlugin::selected_notify() {
|
||||
@@ -547,7 +502,7 @@ Dictionary ShaderEditorPlugin::get_state() const {
|
||||
return shader_editor->get_state();
|
||||
}
|
||||
|
||||
void ShaderEditorPlugin::set_state(const Dictionary& p_state) {
|
||||
void ShaderEditorPlugin::set_state(const Dictionary &p_state) {
|
||||
|
||||
shader_editor->set_state(p_state);
|
||||
}
|
||||
@@ -568,17 +523,12 @@ void ShaderEditorPlugin::apply_changes() {
|
||||
|
||||
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
|
||||
|
||||
editor = p_node;
|
||||
shader_editor = memnew(ShaderEditor);
|
||||
|
||||
editor=p_node;
|
||||
shader_editor = memnew( ShaderEditor );
|
||||
|
||||
shader_editor->set_custom_minimum_size(Size2(0,300));
|
||||
button=editor->add_bottom_panel_item("Shader",shader_editor);
|
||||
|
||||
shader_editor->set_custom_minimum_size(Size2(0, 300));
|
||||
button = editor->add_bottom_panel_item("Shader", shader_editor);
|
||||
}
|
||||
|
||||
|
||||
ShaderEditorPlugin::~ShaderEditorPlugin() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user