Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework scene creation dialog #61954

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,13 @@ void CreateDialog::select_type(const String &p_type, bool p_center_on_item) {
get_ok_button()->set_disabled(false);
}

void CreateDialog::select_base() {
if (search_options_types.is_empty()) {
_update_search();
}
select_type(base_type, false);
}

String CreateDialog::get_selected_type() {
TreeItem *selected = search_options->get_selected();
if (!selected) {
Expand Down
1 change: 1 addition & 0 deletions editor/create_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class CreateDialog : public ConfirmationDialog {

void set_base_type(const String &p_base) { base_type = p_base; }
String get_base_type() const { return base_type; }
void select_base();

void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
String get_preferred_search_result_type() { return preferred_search_result_type; }
Expand Down
60 changes: 12 additions & 48 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/import_dock.h"
#include "editor/scene_create_dialog.h"
#include "editor/scene_tree_dock.h"
#include "editor/shader_create_dialog.h"
#include "scene/gui/label.h"
Expand Down Expand Up @@ -1469,44 +1470,12 @@ void FileSystemDock::_make_dir_confirm() {
}

void FileSystemDock::_make_scene_confirm() {
String scene_name = make_scene_dialog_text->get_text().strip_edges();

if (scene_name.length() == 0) {
EditorNode::get_singleton()->show_warning(TTR("No name provided."));
return;
}

String directory = path;
if (!directory.ends_with("/")) {
directory = directory.get_base_dir();
}

String extension = scene_name.get_extension();
List<String> extensions;
Ref<PackedScene> sd = memnew(PackedScene);
ResourceSaver::get_recognized_extensions(sd, &extensions);

bool extension_correct = false;
for (const String &E : extensions) {
if (E == extension) {
extension_correct = true;
break;
}
}
if (!extension_correct) {
scene_name = scene_name.get_basename() + ".tscn";
}

scene_name = directory.plus_file(scene_name);

Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (da->file_exists(scene_name)) {
EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
return;
}
const String scene_path = make_scene_dialog->get_scene_path();

int idx = EditorNode::get_singleton()->new_scene();
EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_name);
EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_path);
EditorNode::get_singleton()->set_edited_scene(make_scene_dialog->create_scene_root());
EditorNode::get_singleton()->save_scene_list({ scene_path });
}

void FileSystemDock::_file_removed(String p_file) {
Expand Down Expand Up @@ -2003,10 +1972,12 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
} break;

case FILE_NEW_SCENE: {
make_scene_dialog_text->set_text("new scene");
make_scene_dialog_text->select_all();
make_scene_dialog->popup_centered(Size2(250, 80) * EDSCALE);
make_scene_dialog_text->grab_focus();
String directory = path;
if (!directory.ends_with("/")) {
directory = directory.get_base_dir();
}
make_scene_dialog->config(directory);
make_scene_dialog->popup_centered();
} break;

case FILE_NEW_SCRIPT: {
Expand Down Expand Up @@ -3216,15 +3187,8 @@ FileSystemDock::FileSystemDock() {
make_dir_dialog->register_text_enter(make_dir_dialog_text);
make_dir_dialog->connect("confirmed", callable_mp(this, &FileSystemDock::_make_dir_confirm));

make_scene_dialog = memnew(ConfirmationDialog);
make_scene_dialog->set_title(TTR("Create Scene"));
VBoxContainer *make_scene_dialog_vb = memnew(VBoxContainer);
make_scene_dialog->add_child(make_scene_dialog_vb);

make_scene_dialog_text = memnew(LineEdit);
make_scene_dialog_vb->add_margin_child(TTR("Name:"), make_scene_dialog_text);
make_scene_dialog = memnew(SceneCreateDialog);
add_child(make_scene_dialog);
make_scene_dialog->register_text_enter(make_scene_dialog_text);
make_scene_dialog->connect("confirmed", callable_mp(this, &FileSystemDock::_make_scene_confirm));

make_script_dialog = memnew(ScriptCreateDialog);
Expand Down
4 changes: 2 additions & 2 deletions editor/filesystem_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"

class SceneCreateDialog;
class ShaderCreateDialog;

class FileSystemDock : public VBoxContainer {
Expand Down Expand Up @@ -148,9 +149,8 @@ class FileSystemDock : public VBoxContainer {
LineEdit *duplicate_dialog_text = nullptr;
ConfirmationDialog *make_dir_dialog = nullptr;
LineEdit *make_dir_dialog_text = nullptr;
ConfirmationDialog *make_scene_dialog = nullptr;
LineEdit *make_scene_dialog_text = nullptr;
ConfirmationDialog *overwrite_dialog = nullptr;
SceneCreateDialog *make_scene_dialog = nullptr;
ScriptCreateDialog *make_script_dialog = nullptr;
ShaderCreateDialog *make_shader_dialog = nullptr;
CreateDialog *new_resource_dialog = nullptr;
Expand Down
Loading