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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Rework scene creation dialog #62746

Merged
merged 1 commit into from
Aug 25, 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 @@ -492,6 +492,13 @@ String CreateDialog::get_base_type() const {
return base_type;
}

void CreateDialog::select_base() {
if (search_options_types.empty()) {
_update_search();
}
select_type(base_type);
}

void CreateDialog::set_preferred_search_result_type(const String &p_preferred_type) {
preferred_search_result_type = p_preferred_type;
}
Expand Down
1 change: 1 addition & 0 deletions editor/create_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class CreateDialog : public ConfirmationDialog {

void set_base_type(const String &p_base);
String get_base_type() const;
void select_base();

void set_preferred_search_result_type(const String &p_preferred_type);
String get_preferred_search_result_type();
Expand Down
64 changes: 14 additions & 50 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "editor/scene_create_dialog.h"
#include "editor_feature_profile.h"
#include "editor_node.h"
#include "editor_resource_preview.h"
Expand Down Expand Up @@ -1376,46 +1377,14 @@ 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 (List<String>::Element *E = extensions.front(); E; E = E->next()) {
if (E->get() == extension) {
extension_correct = true;
break;
}
}
if (!extension_correct) {
scene_name = scene_name.get_basename() + ".tscn";
}

scene_name = directory.plus_file(scene_name);

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."));
memdelete(da);
return;
}
memdelete(da);
const String scene_path = make_scene_dialog->get_scene_path();

int idx = editor->new_scene();
editor->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());
Vector<String> scenes;
scenes.push_back(scene_path);
EditorNode::get_singleton()->save_scene_list(scenes);
}

void FileSystemDock::_file_removed(String p_file) {
Expand Down Expand Up @@ -1916,10 +1885,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_minsize(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 @@ -3000,15 +2971,8 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
make_dir_dialog->register_text_enter(make_dir_dialog_text);
make_dir_dialog->connect("confirmed", this, "_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", this, "_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 @@ -55,6 +55,7 @@
#include "script_create_dialog.h"

class EditorNode;
class SceneCreateDialog;

class FileSystemDock : public VBoxContainer {
GDCLASS(FileSystemDock, VBoxContainer);
Expand Down Expand Up @@ -154,9 +155,8 @@ class FileSystemDock : public VBoxContainer {
LineEdit *duplicate_dialog_text;
ConfirmationDialog *make_dir_dialog;
LineEdit *make_dir_dialog_text;
ConfirmationDialog *make_scene_dialog;
LineEdit *make_scene_dialog_text;
ConfirmationDialog *overwrite_dialog;
SceneCreateDialog *make_scene_dialog = nullptr;
ScriptCreateDialog *make_script_dialog;
CreateDialog *new_resource_dialog;

Expand Down
Loading