Re-organize UI in the shader editor

This commit is contained in:
Chaosus
2024-12-11 20:32:11 +03:00
parent 4b36c0491e
commit b983a05806
7 changed files with 153 additions and 18 deletions

View File

@ -34,6 +34,7 @@
#include "core/io/resource_loader.h"
#include "core/math/math_defs.h"
#include "core/os/keyboard.h"
#include "core/version_generated.gen.h"
#include "editor/editor_node.h"
#include "editor/editor_properties.h"
#include "editor/editor_properties_vector.h"
@ -1572,6 +1573,10 @@ void VisualShaderEditor::validate_script() {
}
}
Control *VisualShaderEditor::get_top_bar() {
return toolbar;
}
void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
if (plugins.has(p_plugin)) {
return;
@ -2463,6 +2468,13 @@ Size2 VisualShaderEditor::get_minimum_size() const {
return Size2(10, 200);
}
void VisualShaderEditor::update_toggle_scripts_button() {
ERR_FAIL_NULL(toggle_scripts_list);
bool forward = toggle_scripts_list->is_visible() == is_layout_rtl();
toggle_scripts_button->set_button_icon(get_editor_theme_icon(forward ? SNAME("Forward") : SNAME("Back")));
toggle_scripts_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text()));
}
void VisualShaderEditor::_draw_color_over_button(Object *p_obj, Color p_color) {
Button *button = Object::cast_to<Button>(p_obj);
if (!button) {
@ -5147,6 +5159,10 @@ void VisualShaderEditor::_param_unselected() {
_clear_preview_param();
}
void VisualShaderEditor::_help_open() {
OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/visual_shaders.html", GODOT_VERSION_DOCS_URL));
}
void VisualShaderEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
@ -5188,6 +5204,7 @@ void VisualShaderEditor::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
site_search->set_button_icon(get_editor_theme_icon(SNAME("ExternalLink")));
highend_label->set_modulate(get_theme_color(SNAME("highend_color"), EditorStringName(Editor)));
param_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
@ -5251,6 +5268,11 @@ void VisualShaderEditor::_notification(int p_what) {
if (is_visible_in_tree()) {
_update_graph();
}
update_toggle_scripts_button();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
update_toggle_scripts_button();
} break;
case NOTIFICATION_DRAG_BEGIN: {
@ -6354,6 +6376,16 @@ void VisualShaderEditor::_show_shader_preview() {
}
}
void VisualShaderEditor::set_toggle_list_control(Control *p_control) {
toggle_scripts_list = p_control;
}
void VisualShaderEditor::_toggle_scripts_pressed() {
ERR_FAIL_NULL(toggle_scripts_list);
toggle_scripts_list->set_visible(!toggle_scripts_list->is_visible());
update_toggle_scripts_button();
}
void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes);
ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
@ -6490,7 +6522,7 @@ VisualShaderEditor::VisualShaderEditor() {
toolbar_panel->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE, PRESET_MODE_MINSIZE, 10);
toolbar_panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
HFlowContainer *toolbar = memnew(HFlowContainer);
toolbar = memnew(HFlowContainer);
{
LocalVector<Node *> nodes;
for (int i = 0; i < graph->get_menu_hbox()->get_child_count(); i++) {
@ -6589,6 +6621,32 @@ VisualShaderEditor::VisualShaderEditor() {
toolbar->add_child(shader_preview_button);
shader_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_shader_preview));
Control *spacer = memnew(Control);
spacer->set_h_size_flags(Control::SIZE_EXPAND);
toolbar->add_child(spacer);
site_search = memnew(Button);
site_search->set_flat(true);
site_search->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_help_open));
site_search->set_text(TTR("Online Docs"));
site_search->set_tooltip_text(TTR("Open Godot online documentation."));
toolbar->add_child(site_search);
toolbar->add_child(memnew(VSeparator));
VSeparator *separator = memnew(VSeparator);
toolbar->add_child(separator);
toolbar->move_child(separator, 0);
separator = memnew(VSeparator);
toolbar->add_child(separator);
toolbar->move_child(separator, 0);
toggle_scripts_button = memnew(Button);
toggle_scripts_button->set_flat(true);
toggle_scripts_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_toggle_scripts_pressed));
toolbar->add_child(toggle_scripts_button);
toolbar->move_child(toggle_scripts_button, 0);
///////////////////////////////////////
// CODE PREVIEW
///////////////////////////////////////