shader_editor_plugin.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*************************************************************************/
  2. /* shader_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "shader_editor_plugin.h"
  30. #include "editor/editor_node.h"
  31. #include "editor/editor_settings.h"
  32. #include "editor/property_editor.h"
  33. #include "io/resource_loader.h"
  34. #include "io/resource_saver.h"
  35. #include "os/keyboard.h"
  36. #include "os/os.h"
  37. #include "scene/resources/shader_graph.h"
  38. #include "servers/visual/shader_types.h"
  39. #include "spatial_editor_plugin.h"
  40. /*** SETTINGS EDITOR ****/
  41. /*** SCRIPT EDITOR ****/
  42. Ref<Shader> ShaderTextEditor::get_edited_shader() const {
  43. return shader;
  44. }
  45. void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) {
  46. shader = p_shader;
  47. _load_theme_settings();
  48. get_text_edit()->set_text(p_shader->get_code());
  49. _line_col_changed();
  50. }
  51. void ShaderTextEditor::_load_theme_settings() {
  52. get_text_edit()->clear_colors();
  53. /* keyword color */
  54. get_text_edit()->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0)));
  55. get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0)));
  56. get_text_edit()->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244")));
  57. get_text_edit()->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf")));
  58. get_text_edit()->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/highlighting/completion_scroll_color", Color::html("ffffff")));
  59. get_text_edit()->add_color_override("completion_font_color", EDITOR_DEF("text_editor/highlighting/completion_font_color", Color::html("aaaaaa")));
  60. get_text_edit()->add_color_override("font_color", EDITOR_DEF("text_editor/highlighting/text_color", Color(0, 0, 0)));
  61. get_text_edit()->add_color_override("line_number_color", EDITOR_DEF("text_editor/highlighting/line_number_color", Color(0, 0, 0)));
  62. get_text_edit()->add_color_override("caret_color", EDITOR_DEF("text_editor/highlighting/caret_color", Color(0, 0, 0)));
  63. get_text_edit()->add_color_override("caret_background_color", EDITOR_DEF("text_editor/highlighting/caret_background_color", Color(0, 0, 0)));
  64. get_text_edit()->add_color_override("font_selected_color", EDITOR_DEF("text_editor/highlighting/text_selected_color", Color(1, 1, 1)));
  65. get_text_edit()->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1)));
  66. get_text_edit()->add_color_override("brace_mismatch_color", EDITOR_DEF("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2)));
  67. 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)));
  68. 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)));
  69. get_text_edit()->add_color_override("number_color", EDITOR_DEF("text_editor/highlighting/number_color", Color(0.9, 0.6, 0.0, 2)));
  70. get_text_edit()->add_color_override("function_color", EDITOR_DEF("text_editor/highlighting/function_color", Color(0.4, 0.6, 0.8)));
  71. get_text_edit()->add_color_override("member_variable_color", EDITOR_DEF("text_editor/highlighting/member_variable_color", Color(0.9, 0.3, 0.3)));
  72. get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4)));
  73. get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2)));
  74. 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)));
  75. 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)));
  76. get_text_edit()->add_color_override("symbol_color", EDITOR_DEF("text_editor/highlighting/symbol_color", Color::hex(0x005291ff)));
  77. Color keyword_color = EDITOR_DEF("text_editor/highlighting/keyword_color", Color(0.5, 0.0, 0.2));
  78. List<String> keywords;
  79. ShaderLanguage::get_keyword_list(&keywords);
  80. if (shader.is_valid()) {
  81. 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()) {
  82. for (const Map<StringName, ShaderLanguage::DataType>::Element *F = E->get().front(); F; F = F->next()) {
  83. keywords.push_back(F->key());
  84. }
  85. }
  86. for (const Set<String>::Element *E = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
  87. keywords.push_back(E->get());
  88. }
  89. }
  90. for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
  91. get_text_edit()->add_keyword_color(E->get(), keyword_color);
  92. }
  93. //colorize core types
  94. //Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));
  95. //colorize comments
  96. Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color", Color::hex(0x797e7eff));
  97. get_text_edit()->add_color_region("/*", "*/", comment_color, false);
  98. get_text_edit()->add_color_region("//", "", comment_color, false);
  99. /*//colorize strings
  100. Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
  101. List<String> strings;
  102. shader->get_shader_mode()->get_string_delimiters(&strings);
  103. for (List<String>::Element *E=strings.front();E;E=E->next()) {
  104. String string = E->get();
  105. String beg = string.get_slice(" ",0);
  106. String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String();
  107. get_text_edit()->add_color_region(beg,end,string_color,end=="");
  108. }*/
  109. }
  110. void ShaderTextEditor::_check_shader_mode() {
  111. String type = ShaderLanguage::get_shader_type(get_text_edit()->get_text());
  112. print_line("type is: " + type);
  113. Shader::Mode mode;
  114. if (type == "canvas_item") {
  115. mode = Shader::MODE_CANVAS_ITEM;
  116. } else if (type == "particles") {
  117. mode = Shader::MODE_PARTICLES;
  118. } else {
  119. mode = Shader::MODE_SPATIAL;
  120. }
  121. if (shader->get_mode() != mode) {
  122. shader->set_code(get_text_edit()->get_text());
  123. _load_theme_settings();
  124. }
  125. }
  126. void ShaderTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) {
  127. _check_shader_mode();
  128. ShaderLanguage sl;
  129. String calltip;
  130. 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())), ShaderTypes::get_singleton()->get_types(), r_options, calltip);
  131. if (calltip != "") {
  132. get_text_edit()->set_code_hint(calltip);
  133. }
  134. }
  135. void ShaderTextEditor::_validate_script() {
  136. _check_shader_mode();
  137. String code = get_text_edit()->get_text();
  138. //List<StringName> params;
  139. //shader->get_param_list(&params);
  140. ShaderLanguage sl;
  141. 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())), ShaderTypes::get_singleton()->get_types());
  142. if (err != OK) {
  143. String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
  144. set_error(error_text);
  145. get_text_edit()->set_line_as_marked(sl.get_error_line(), true);
  146. } else {
  147. for (int i = 0; i < get_text_edit()->get_line_count(); i++)
  148. get_text_edit()->set_line_as_marked(i, false);
  149. set_error("");
  150. }
  151. emit_signal("script_changed");
  152. }
  153. void ShaderTextEditor::_bind_methods() {
  154. //ADD_SIGNAL( MethodInfo("script_changed") );
  155. }
  156. ShaderTextEditor::ShaderTextEditor() {
  157. }
  158. /*** SCRIPT EDITOR ******/
  159. void ShaderEditor::_menu_option(int p_option) {
  160. ShaderTextEditor *current = shader_editor;
  161. switch (p_option) {
  162. case EDIT_UNDO: {
  163. current->get_text_edit()->undo();
  164. } break;
  165. case EDIT_REDO: {
  166. current->get_text_edit()->redo();
  167. } break;
  168. case EDIT_CUT: {
  169. current->get_text_edit()->cut();
  170. } break;
  171. case EDIT_COPY: {
  172. current->get_text_edit()->copy();
  173. } break;
  174. case EDIT_PASTE: {
  175. current->get_text_edit()->paste();
  176. } break;
  177. case EDIT_SELECT_ALL: {
  178. current->get_text_edit()->select_all();
  179. } break;
  180. case SEARCH_FIND: {
  181. current->get_find_replace_bar()->popup_search();
  182. } break;
  183. case SEARCH_FIND_NEXT: {
  184. current->get_find_replace_bar()->search_next();
  185. } break;
  186. case SEARCH_FIND_PREV: {
  187. current->get_find_replace_bar()->search_prev();
  188. } break;
  189. case SEARCH_REPLACE: {
  190. current->get_find_replace_bar()->popup_replace();
  191. } break;
  192. //case SEARCH_LOCATE_SYMBOL: {
  193. //} break;
  194. case SEARCH_GOTO_LINE: {
  195. goto_line_dialog->popup_find_line(current->get_text_edit());
  196. } break;
  197. }
  198. }
  199. void ShaderEditor::_notification(int p_what) {
  200. if (p_what == NOTIFICATION_ENTER_TREE) {
  201. }
  202. if (p_what == NOTIFICATION_DRAW) {
  203. RID ci = get_canvas_item();
  204. Ref<StyleBox> style = get_stylebox("panel", "Panel");
  205. style->draw(ci, Rect2(Point2(), get_size()));
  206. }
  207. }
  208. Dictionary ShaderEditor::get_state() const {
  209. #if 0
  210. apply_shaders();
  211. Dictionary state;
  212. Array paths;
  213. int open=-1;
  214. for(int i=0;i<tab_container->get_child_count();i++) {
  215. ShaderTextEditor *ste = tab_container->get_child(i)->cast_to<ShaderTextEditor>();
  216. if (!ste)
  217. continue;
  218. Ref<Shader> shader = ste->get_edited_shader();
  219. if (shader->get_path()!="" && shader->get_path().find("local://")==-1 && shader->get_path().find("::")==-1) {
  220. paths.push_back(shader->get_path());
  221. } else {
  222. const Node *owner = _find_node_with_shader(get_root_node(),shader.get_ref_ptr());
  223. if (owner)
  224. paths.push_back(owner->get_path());
  225. }
  226. if (i==tab_container->get_current_tab())
  227. open=i;
  228. }
  229. if (paths.size())
  230. state["sources"]=paths;
  231. if (open!=-1)
  232. state["current"]=open;
  233. return state;
  234. #endif
  235. return Dictionary();
  236. }
  237. void ShaderEditor::set_state(const Dictionary &p_state) {
  238. #if 0
  239. print_line("setting state..");
  240. if (!p_state.has("sources"))
  241. return; //bleh
  242. Array sources = p_state["sources"];
  243. for(int i=0;i<sources.size();i++) {
  244. Variant source=sources[i];
  245. Ref<Shader> shader;
  246. if (source.get_type()==Variant::NODE_PATH) {
  247. print_line("cain find owner at path "+String(source));
  248. Node *owner=get_root_node()->get_node(source);
  249. if (!owner)
  250. continue;
  251. shader = owner->get_shader();
  252. } else if (source.get_type()==Variant::STRING) {
  253. print_line("loading at path "+String(source));
  254. shader = ResourceLoader::load(source,"Shader");
  255. }
  256. print_line("found shader at "+String(source)+"? - "+itos(shader.is_null()));
  257. if (shader.is_null()) //ah well..
  258. continue;
  259. get_scene()->get_root_node()->call("_resource_selected",shader);
  260. }
  261. if (p_state.has("current"))
  262. tab_container->set_current_tab(p_state["current"]);
  263. #endif
  264. }
  265. void ShaderEditor::clear() {
  266. }
  267. void ShaderEditor::_params_changed() {
  268. shader_editor->_validate_script();
  269. }
  270. void ShaderEditor::_editor_settings_changed() {
  271. shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
  272. shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
  273. shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size"));
  274. shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs"));
  275. shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers"));
  276. shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
  277. shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences"));
  278. shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
  279. shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
  280. shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing"));
  281. shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
  282. }
  283. void ShaderEditor::_bind_methods() {
  284. ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed);
  285. ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option);
  286. ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed);
  287. ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders);
  288. //ClassDB::bind_method("_close_current_tab",&ShaderEditor::_close_current_tab);
  289. }
  290. void ShaderEditor::ensure_select_current() {
  291. /*
  292. if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) {
  293. ShaderTextEditor *ste = tab_container->get_child(tab_container->get_current_tab())->cast_to<ShaderTextEditor>();
  294. if (!ste)
  295. return;
  296. Ref<Shader> shader = ste->get_edited_shader();
  297. get_scene()->get_root_node()->call("_resource_selected",shader);
  298. }*/
  299. }
  300. void ShaderEditor::edit(const Ref<Shader> &p_shader) {
  301. if (p_shader.is_null())
  302. return;
  303. shader = p_shader;
  304. shader_editor->set_edited_shader(p_shader);
  305. //vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
  306. // see if already has it
  307. }
  308. void ShaderEditor::save_external_data() {
  309. if (shader.is_null())
  310. return;
  311. apply_shaders();
  312. if (shader->get_path() != "" && shader->get_path().find("local://") == -1 && shader->get_path().find("::") == -1) {
  313. //external shader, save it
  314. ResourceSaver::save(shader->get_path(), shader);
  315. }
  316. }
  317. void ShaderEditor::apply_shaders() {
  318. if (shader.is_valid()) {
  319. shader->set_code(shader_editor->get_text_edit()->get_text());
  320. shader->set_edited(true);
  321. }
  322. }
  323. ShaderEditor::ShaderEditor() {
  324. HBoxContainer *hbc = memnew(HBoxContainer);
  325. add_child(hbc);
  326. edit_menu = memnew(MenuButton);
  327. hbc->add_child(edit_menu);
  328. edit_menu->set_pos(Point2(5, -1));
  329. edit_menu->set_text(TTR("Edit"));
  330. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z), EDIT_UNDO);
  331. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y), EDIT_REDO);
  332. edit_menu->get_popup()->add_separator();
  333. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X), EDIT_CUT);
  334. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C), EDIT_COPY);
  335. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V), EDIT_PASTE);
  336. edit_menu->get_popup()->add_separator();
  337. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A), EDIT_SELECT_ALL);
  338. edit_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  339. search_menu = memnew(MenuButton);
  340. hbc->add_child(search_menu);
  341. search_menu->set_pos(Point2(38, -1));
  342. search_menu->set_text(TTR("Search"));
  343. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), SEARCH_FIND);
  344. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT);
  345. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), SEARCH_FIND_PREV);
  346. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R), SEARCH_REPLACE);
  347. search_menu->get_popup()->add_separator();
  348. //search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K);
  349. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L), SEARCH_GOTO_LINE);
  350. search_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  351. goto_line_dialog = memnew(GotoLineDialog);
  352. add_child(goto_line_dialog);
  353. shader_editor = memnew(ShaderTextEditor);
  354. add_child(shader_editor);
  355. shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  356. shader_editor->connect("script_changed", this, "apply_shaders");
  357. EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
  358. _editor_settings_changed();
  359. }
  360. void ShaderEditorPlugin::edit(Object *p_object) {
  361. Shader *s = p_object->cast_to<Shader>();
  362. shader_editor->edit(s);
  363. }
  364. bool ShaderEditorPlugin::handles(Object *p_object) const {
  365. bool handles = true;
  366. Shader *shader = p_object->cast_to<Shader>();
  367. /*
  368. if (!shader || shader->cast_to<ShaderGraph>()) // Don't handle ShaderGraph's
  369. handles = false;
  370. */
  371. return shader != NULL;
  372. }
  373. void ShaderEditorPlugin::make_visible(bool p_visible) {
  374. if (p_visible) {
  375. button->show();
  376. editor->make_bottom_panel_item_visible(shader_editor);
  377. } else {
  378. button->hide();
  379. if (shader_editor->is_visible_in_tree())
  380. editor->hide_bottom_panel();
  381. shader_editor->apply_shaders();
  382. }
  383. }
  384. void ShaderEditorPlugin::selected_notify() {
  385. shader_editor->ensure_select_current();
  386. }
  387. Dictionary ShaderEditorPlugin::get_state() const {
  388. return shader_editor->get_state();
  389. }
  390. void ShaderEditorPlugin::set_state(const Dictionary &p_state) {
  391. shader_editor->set_state(p_state);
  392. }
  393. void ShaderEditorPlugin::clear() {
  394. shader_editor->clear();
  395. }
  396. void ShaderEditorPlugin::save_external_data() {
  397. shader_editor->save_external_data();
  398. }
  399. void ShaderEditorPlugin::apply_changes() {
  400. shader_editor->apply_shaders();
  401. }
  402. ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
  403. editor = p_node;
  404. shader_editor = memnew(ShaderEditor);
  405. shader_editor->set_custom_minimum_size(Size2(0, 300));
  406. button = editor->add_bottom_panel_item("Shader", shader_editor);
  407. }
  408. ShaderEditorPlugin::~ShaderEditorPlugin() {
  409. }