feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -146,12 +146,13 @@ void ShaderEditorPlugin::edit(Object *p_object) {
if (edited_shaders[i].shader_inc.ptr() == si) {
shader_tabs->set_current_tab(i);
shader_list->select(i);
_switch_to_editor(edited_shaders[i].shader_editor);
return;
}
}
es.shader_inc = Ref<ShaderInclude>(si);
TextShaderEditor *text_shader = memnew(TextShaderEditor);
text_shader->get_code_editor()->set_toggle_list_control(left_panel);
text_shader->get_code_editor()->set_toggle_list_control(shader_list);
es.shader_editor = text_shader;
es.shader_editor->edit_shader_include(si);
shader_tabs->add_child(es.shader_editor);
@ -161,16 +162,19 @@ void ShaderEditorPlugin::edit(Object *p_object) {
if (edited_shaders[i].shader.ptr() == s) {
shader_tabs->set_current_tab(i);
shader_list->select(i);
_switch_to_editor(edited_shaders[i].shader_editor);
return;
}
}
es.shader = Ref<Shader>(s);
Ref<VisualShader> vs = es.shader;
if (vs.is_valid()) {
es.shader_editor = memnew(VisualShaderEditor);
VisualShaderEditor *vs_editor = memnew(VisualShaderEditor);
vs_editor->set_toggle_list_control(shader_list);
es.shader_editor = vs_editor;
} else {
TextShaderEditor *text_shader = memnew(TextShaderEditor);
text_shader->get_code_editor()->set_toggle_list_control(left_panel);
text_shader->get_code_editor()->set_toggle_list_control(shader_list);
es.shader_editor = text_shader;
}
shader_tabs->add_child(es.shader_editor);
@ -185,11 +189,18 @@ void ShaderEditorPlugin::edit(Object *p_object) {
cte->set_zoom_factor(text_shader_zoom_factor);
cte->connect("zoomed", callable_mp(this, &ShaderEditorPlugin::_set_text_shader_zoom_factor));
}
if (text_shader_editor->get_top_bar()) {
text_shader_editor->get_top_bar()->set_h_size_flags(Control::SIZE_EXPAND_FILL);
menu_hb->add_child(text_shader_editor->get_top_bar());
menu_hb->move_child(text_shader_editor->get_top_bar(), 1);
}
}
shader_tabs->set_current_tab(shader_tabs->get_tab_count() - 1);
edited_shaders.push_back(es);
_update_shader_list();
_switch_to_editor(es.shader_editor);
}
bool ShaderEditorPlugin::handles(Object *p_object) const {
@ -250,7 +261,7 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
}
if (p_layout->has_section_key("ShaderEditor", "split_offset")) {
main_split->set_split_offset(p_layout->get_value("ShaderEditor", "split_offset"));
files_split->set_split_offset(p_layout->get_value("ShaderEditor", "split_offset"));
}
_update_shader_list();
@ -300,7 +311,7 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
}
}
p_layout->set_value("ShaderEditor", "open_shaders", shaders);
p_layout->set_value("ShaderEditor", "split_offset", main_split->get_split_offset());
p_layout->set_value("ShaderEditor", "split_offset", files_split->get_split_offset());
p_layout->set_value("ShaderEditor", "selected_shader", selected_shader);
p_layout->set_value("ShaderEditor", "text_shader_zoom_factor", text_shader_zoom_factor);
}
@ -343,7 +354,7 @@ String ShaderEditorPlugin::get_unsaved_status(const String &p_for_scene) const {
void ShaderEditorPlugin::save_external_data() {
for (EditedShader &edited_shader : edited_shaders) {
if (edited_shader.shader_editor) {
if (edited_shader.shader_editor && edited_shader.shader_editor->is_unsaved()) {
edited_shader.shader_editor->save_external_data();
}
}
@ -364,6 +375,7 @@ void ShaderEditorPlugin::_shader_selected(int p_index) {
}
if (edited_shaders[p_index].shader_editor) {
_switch_to_editor(edited_shaders[p_index].shader_editor);
edited_shaders[p_index].shader_editor->validate_script();
}
@ -400,6 +412,8 @@ void ShaderEditorPlugin::_setup_popup_menu(PopupMenuType p_type, PopupMenu *p_me
p_menu->add_item(TTR("Inspect Native Shader Code..."), FILE_INSPECT_NATIVE_SHADER_CODE);
p_menu->add_separator();
p_menu->add_shortcut(ED_SHORTCUT("shader_editor/close_file", TTRC("Close File"), KeyModifierMask::CMD_OR_CTRL | Key::W), FILE_CLOSE);
p_menu->add_separator();
p_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/toggle_files_panel"), TOGGLE_FILES_PANEL);
} else {
p_menu->add_shortcut(ED_SHORTCUT("shader_editor/close_file", TTRC("Close File"), KeyModifierMask::CMD_OR_CTRL | Key::W), FILE_CLOSE);
p_menu->add_item(TTR("Close All"), CLOSE_ALL);
@ -428,21 +442,37 @@ void ShaderEditorPlugin::_make_script_list_context_menu() {
context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_ALL), shader_tabs->get_tab_count() <= 0);
context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_OTHER_TABS), shader_tabs->get_tab_count() <= 1);
context_menu->set_position(main_split->get_screen_position() + main_split->get_local_mouse_position());
context_menu->set_position(files_split->get_screen_position() + files_split->get_local_mouse_position());
context_menu->reset_size();
context_menu->popup();
}
void ShaderEditorPlugin::_close_shader(int p_index) {
ERR_FAIL_INDEX(p_index, shader_tabs->get_tab_count());
Control *c = shader_tabs->get_tab_control(p_index);
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(c);
if (vs_editor) {
file_menu->get_parent()->remove_child(file_menu);
menu_hb->add_child(file_menu);
menu_hb->move_child(file_menu, 0);
make_floating->get_parent()->remove_child(make_floating);
menu_hb->add_child(make_floating);
} else {
memdelete(edited_shaders[p_index].shader_editor->get_top_bar());
}
memdelete(c);
edited_shaders.remove_at(p_index);
_update_shader_list();
EditorUndoRedoManager::get_singleton()->clear_history(); // To prevent undo on deleted graphs.
if (shader_tabs->get_tab_count() == 0) {
left_panel->show(); // Make sure the panel is visible, because it can't be toggled without open shaders.
shader_list->show(); // Make sure the panel is visible, because it can't be toggled without open shaders.
menu_spacer->show();
} else {
_switch_to_editor(edited_shaders[shader_tabs->get_current_tab()].shader_editor);
}
}
@ -590,6 +620,21 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) {
Ref<Resource> shader = _get_current_shader();
DisplayServer::get_singleton()->clipboard_set(shader->get_path());
} break;
case TOGGLE_FILES_PANEL: {
shader_list->set_visible(!shader_list->is_visible());
int index = shader_tabs->get_current_tab();
ERR_FAIL_INDEX(index, shader_tabs->get_tab_count());
TextShaderEditor *editor = Object::cast_to<TextShaderEditor>(edited_shaders[index].shader_editor);
if (editor) {
editor->get_code_editor()->update_toggle_files_button();
} else {
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(edited_shaders[index].shader_editor);
if (vs_editor) {
vs_editor->update_toggle_files_button();
}
}
} break;
}
}
@ -606,7 +651,14 @@ Variant ShaderEditorPlugin::get_drag_data_fw(const Point2 &p_point, Control *p_f
return Variant();
}
int idx = shader_list->get_item_at_position(p_point);
int idx = 0;
if (p_point == Vector2(Math::INF, Math::INF)) {
if (shader_list->is_anything_selected()) {
idx = shader_list->get_selected_items()[0];
}
} else {
idx = shader_list->get_item_at_position(p_point);
}
if (idx < 0) {
return Variant();
}
@ -624,7 +676,7 @@ Variant ShaderEditorPlugin::get_drag_data_fw(const Point2 &p_point, Control *p_f
Label *label = memnew(Label(preview_name));
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate script names.
drag_preview->add_child(label);
main_split->set_drag_preview(drag_preview);
files_split->set_drag_preview(drag_preview);
Dictionary drag_data;
drag_data["type"] = "shader_list_element";
@ -646,7 +698,7 @@ bool ShaderEditorPlugin::can_drop_data_fw(const Point2 &p_point, const Variant &
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
if (files.size() == 0) {
if (files.is_empty()) {
return false;
}
@ -683,7 +735,14 @@ void ShaderEditorPlugin::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (String(d["type"]) == "shader_list_element") {
int idx = d["shader_list_element"];
int new_idx = shader_list->get_item_at_position(p_point);
int new_idx = 0;
if (p_point == Vector2(Math::INF, Math::INF)) {
if (shader_list->is_anything_selected()) {
new_idx = shader_list->get_selected_items()[0];
}
} else {
new_idx = shader_list->get_item_at_position(p_point);
}
_move_shader_tab(idx, new_idx);
return;
}
@ -723,6 +782,45 @@ void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) {
}
}
void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) {
Control *bar = p_editor->get_top_bar();
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(p_editor);
if (vs_editor) {
file_menu->get_parent()->remove_child(file_menu);
bar->add_child(file_menu);
bar->move_child(file_menu, 2); // Toggle Files Panel button + separator.
make_floating->get_parent()->remove_child(make_floating);
bar->add_child(make_floating);
} else {
if (menu_spacer->is_visible()) {
menu_spacer->hide();
}
// Just swapped from a visual shader editor.
if (file_menu->get_parent() != menu_hb) {
file_menu->get_parent()->remove_child(file_menu);
menu_hb->add_child(file_menu);
menu_hb->move_child(file_menu, 0);
make_floating->get_parent()->remove_child(make_floating);
menu_hb->add_child(make_floating);
}
}
for (int i = 0; i < shader_tabs->get_tab_count(); i++) {
ShaderEditor *se = Object::cast_to<ShaderEditor>(shader_tabs->get_tab_control(i));
if (se && se->get_top_bar()) {
if (se == p_editor) {
se->get_top_bar()->show();
} else {
se->get_top_bar()->hide();
}
}
}
}
void ShaderEditorPlugin::_file_removed(const String &p_removed_file) {
for (uint32_t i = 0; i < edited_shaders.size(); i++) {
if (edited_shaders[i].path == p_removed_file) {
@ -782,18 +880,19 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
window_wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("Shader Editor")));
window_wrapper->set_margins_enabled(true);
main_split = memnew(HSplitContainer);
main_split->set_split_offset(200 * EDSCALE);
main_container = memnew(VBoxContainer);
Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("shader_editor/make_floating", TTRC("Make Floating"));
window_wrapper->set_wrapped_control(main_split, make_floating_shortcut);
window_wrapper->set_wrapped_control(main_container, make_floating_shortcut);
left_panel = memnew(VBoxContainer);
files_split = memnew(HSplitContainer);
files_split->set_split_offset(200 * EDSCALE);
files_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
HBoxContainer *menu_hb = memnew(HBoxContainer);
left_panel->add_child(menu_hb);
menu_hb = memnew(HBoxContainer);
main_container->add_child(menu_hb);
file_menu = memnew(MenuButton);
file_menu->set_text(TTR("File"));
file_menu->set_shortcut_context(main_split);
file_menu->set_shortcut_context(files_split);
_setup_popup_menu(FILE, file_menu->get_popup());
file_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed));
menu_hb->add_child(file_menu);
@ -804,16 +903,14 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
add_child(context_menu);
context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed));
Control *padding = memnew(Control);
padding->set_h_size_flags(Control::SIZE_EXPAND_FILL);
menu_hb->add_child(padding);
menu_spacer = menu_hb->add_spacer();
make_floating = memnew(ScreenSelect);
make_floating->set_flat(true);
make_floating->connect("request_open_in_screen", callable_mp(window_wrapper, &WindowWrapper::enable_window_on_screen).bind(true));
if (!make_floating->is_disabled()) {
// Override default ScreenSelect tooltip if multi-window support is available.
make_floating->set_tooltip_text(TTR("Make the shader editor floating.\nRight-click to open the screen selector."));
make_floating->set_tooltip_text(TTR("Make the shader editor floating.") + "\n" + TTR("Right-click to open the screen selector."));
}
menu_hb->add_child(make_floating);
@ -823,20 +920,20 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
shader_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
shader_list->set_theme_type_variation("ItemListSecondary");
left_panel->add_child(shader_list);
files_split->add_child(shader_list);
shader_list->connect(SceneStringName(item_selected), callable_mp(this, &ShaderEditorPlugin::_shader_selected));
shader_list->connect("item_clicked", callable_mp(this, &ShaderEditorPlugin::_shader_list_clicked));
shader_list->set_allow_rmb_select(true);
SET_DRAG_FORWARDING_GCD(shader_list, ShaderEditorPlugin);
main_split->add_child(left_panel);
left_panel->set_custom_minimum_size(Size2(100, 300) * EDSCALE);
main_container->add_child(files_split);
main_container->set_custom_minimum_size(Size2(100, 300) * EDSCALE);
shader_tabs = memnew(TabContainer);
shader_tabs->set_custom_minimum_size(Size2(460, 300) * EDSCALE);
shader_tabs->set_tabs_visible(false);
shader_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_split->add_child(shader_tabs);
files_split->add_child(shader_tabs);
Ref<StyleBoxEmpty> empty;
empty.instantiate();
shader_tabs->add_theme_style_override(SceneStringName(panel), empty);
@ -844,10 +941,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
button = EditorNode::get_bottom_panel()->add_item(TTR("Shader Editor"), window_wrapper, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_shader_editor_bottom_panel", TTRC("Toggle Shader Editor Bottom Panel"), KeyModifierMask::ALT | Key::S));
shader_create_dialog = memnew(ShaderCreateDialog);
main_split->add_child(shader_create_dialog);
files_split->add_child(shader_create_dialog);
shader_create_dialog->connect("shader_created", callable_mp(this, &ShaderEditorPlugin::_shader_created));
shader_create_dialog->connect("shader_include_created", callable_mp(this, &ShaderEditorPlugin::_shader_include_created));
}
ShaderEditorPlugin::~ShaderEditorPlugin() {
}