summaryrefslogtreecommitdiff
path: root/editor/project_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/project_manager.cpp')
-rw-r--r--editor/project_manager.cpp205
1 files changed, 114 insertions, 91 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 233e07c4c7..da283b16dc 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "project_manager.h"
#include "editor_initialize_ssl.h"
@@ -79,7 +80,7 @@ private:
Label *msg;
LineEdit *project_path;
LineEdit *project_name;
- ToolButton *status_btn;
+ TextureRect *status_rect;
FileDialog *fdialog;
String zip_path;
String zip_title;
@@ -89,33 +90,43 @@ private:
String created_folder_path;
void set_message(const String &p_msg, MessageType p_type = MESSAGE_SUCCESS) {
+
msg->set_text(p_msg);
- if (p_msg == "") {
- status_btn->set_icon(get_icon("StatusSuccess", "EditorIcons"));
- return;
- }
- msg->hide();
+ Ref<Texture> current_icon = status_rect->get_texture();
+ Ref<Texture> new_icon;
+
switch (p_type) {
- case MESSAGE_ERROR:
+
+ case MESSAGE_ERROR: {
+
msg->add_color_override("font_color", get_color("error_color", "Editor"));
- status_btn->set_icon(get_icon("StatusError", "EditorIcons"));
- msg->show();
- break;
- case MESSAGE_WARNING:
+ msg->set_modulate(Color(1, 1, 1, 1));
+ new_icon = get_icon("StatusError", "EditorIcons");
+
+ } break;
+ case MESSAGE_WARNING: {
+
msg->add_color_override("font_color", get_color("warning_color", "Editor"));
- status_btn->set_icon(get_icon("StatusWarning", "EditorIcons"));
- break;
- case MESSAGE_SUCCESS:
- msg->add_color_override("font_color", get_color("success_color", "Editor"));
- status_btn->set_icon(get_icon("StatusSuccess", "EditorIcons"));
- break;
+ msg->set_modulate(Color(1, 1, 1, 1));
+ new_icon = get_icon("StatusWarning", "EditorIcons");
+
+ } break;
+ case MESSAGE_SUCCESS: {
+
+ msg->set_modulate(Color(1, 1, 1, 0));
+ new_icon = get_icon("StatusSuccess", "EditorIcons");
+
+ } break;
}
+
+ if (current_icon != new_icon)
+ status_rect->set_texture(new_icon);
+
+ set_size(Size2(500, 0) * EDSCALE);
}
String _test_path() {
- set_message(" ");
- get_ok()->set_disabled(true);
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
String valid_path;
if (d->change_dir(project_path->get_text()) == OK) {
@@ -127,6 +138,7 @@ private:
if (valid_path == "") {
set_message(TTR("The path does not exist."), MESSAGE_ERROR);
memdelete(d);
+ get_ok()->set_disabled(true);
return "";
}
@@ -136,17 +148,18 @@ private:
set_message(TTR("Please choose a 'project.godot' file."), MESSAGE_ERROR);
memdelete(d);
+ get_ok()->set_disabled(true);
return "";
}
- } else if (mode == MODE_NEW) {
+ } else {
// check if the specified folder is empty, even though this is not an error, it is good to check here
d->list_dir_begin();
bool is_empty = true;
String n = d->get_next();
while (n != String()) {
- if (!n.begins_with(".")) { // i dont know if this is enough to guarantee an empty dir
+ if (!n.begins_with(".")) { // i don't know if this is enough to guarantee an empty dir
is_empty = false;
break;
}
@@ -155,19 +168,15 @@ private:
d->list_dir_end();
if (!is_empty) {
- set_message(TTR("Your project will be created in a non empty folder (you might want to create a new folder)."), MESSAGE_WARNING);
- }
- } else {
-
- if (d->file_exists("project.godot")) {
-
- set_message(TTR("Please choose a folder that does not contain a 'project.godot' file."), MESSAGE_ERROR);
+ set_message(TTR("Please choose an empty folder."), MESSAGE_ERROR);
memdelete(d);
+ get_ok()->set_disabled(true);
return "";
}
}
+ set_message("");
memdelete(d);
get_ok()->set_disabled(false);
return valid_path;
@@ -213,7 +222,6 @@ private:
}
String sp = p.simplify_path();
project_path->set_text(sp);
- set_message(" "); // just so it does not disappear
get_ok()->call_deferred("grab_focus");
}
@@ -242,21 +250,32 @@ private:
void _create_folder() {
- if (project_name->get_text() == "" || created_folder_path != "") {
+ if (project_name->get_text() == "" || created_folder_path != "")
return;
- }
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (d->change_dir(project_path->get_text()) == OK) {
+
if (!d->dir_exists(project_name->get_text())) {
+
if (d->make_dir(project_name->get_text()) == OK) {
+
d->change_dir(project_name->get_text());
project_path->set_text(d->get_current_dir());
created_folder_path = d->get_current_dir();
create_dir->set_disabled(true);
+ } else {
+
+ dialog_error->set_text(TTR("Couldn't create folder."));
+ dialog_error->popup_centered_minsize();
}
+ } else {
+
+ dialog_error->set_text(TTR("There is already a folder in this path with the specified name."));
+ dialog_error->popup_centered_minsize();
}
}
+
memdelete(d);
}
@@ -337,6 +356,7 @@ private:
if (!pkg) {
dialog_error->set_text(TTR("Error opening package file, not in zip format."));
+ dialog_error->popup_centered_minsize();
return;
}
@@ -447,16 +467,21 @@ private:
}
}
- void _toggle_message() {
- msg->set_visible(!msg->is_visible());
- }
-
void cancel_pressed() {
_remove_created_folder();
project_path->clear();
project_name->clear();
+
+ if (status_rect->get_texture() == get_icon("StatusError", "EditorIcons"))
+ msg->show();
+ }
+
+ void _notification(int p_what) {
+
+ if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST)
+ _remove_created_folder();
}
protected:
@@ -468,7 +493,6 @@ protected:
ClassDB::bind_method("_path_text_changed", &ProjectDialog::_path_text_changed);
ClassDB::bind_method("_path_selected", &ProjectDialog::_path_selected);
ClassDB::bind_method("_file_selected", &ProjectDialog::_file_selected);
- ClassDB::bind_method("_toggle_message", &ProjectDialog::_toggle_message);
ADD_SIGNAL(MethodInfo("project_created"));
ADD_SIGNAL(MethodInfo("project_renamed"));
}
@@ -500,11 +524,17 @@ public:
set_title(TTR("Rename Project"));
get_ok()->set_text(TTR("Rename"));
name_container->show();
+ status_rect->hide();
+ msg->hide();
+ get_ok()->set_disabled(false);
ProjectSettings *current = memnew(ProjectSettings);
if (current->setup(project_path->get_text(), "")) {
set_message(TTR("Couldn't get project.godot in the project path."), MESSAGE_ERROR);
+ status_rect->show();
+ msg->show();
+ get_ok()->set_disabled(true);
} else if (current->has_setting("application/config/name")) {
project_name->set_text(current->get("application/config/name"));
}
@@ -512,7 +542,6 @@ public:
project_name->call_deferred("grab_focus");
create_dir->hide();
- status_btn->hide();
} else {
@@ -532,7 +561,8 @@ public:
browse->set_disabled(false);
browse->show();
create_dir->show();
- status_btn->show();
+ status_rect->show();
+ msg->show();
if (mode == MODE_IMPORT) {
set_title(TTR("Import Existing Project"));
@@ -558,7 +588,7 @@ public:
_test_path();
}
- popup_centered(Size2(500, 125) * EDSCALE);
+ popup_centered(Size2(500, 0) * EDSCALE);
}
ProjectDialog() {
@@ -599,10 +629,10 @@ public:
project_path->set_h_size_flags(SIZE_EXPAND_FILL);
pphb->add_child(project_path);
- // status button
- status_btn = memnew(ToolButton);
- status_btn->connect("pressed", this, "_toggle_message");
- pphb->add_child(status_btn);
+ // status icon
+ status_rect = memnew(TextureRect);
+ status_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
+ pphb->add_child(status_rect);
browse = memnew(Button);
browse->set_text(TTR("Browse"));
@@ -610,9 +640,7 @@ public:
pphb->add_child(browse);
msg = memnew(Label);
- msg->set_text(TTR("That's a BINGO!"));
msg->set_align(Label::ALIGN_CENTER);
- msg->hide();
vb->add_child(msg);
fdialog = memnew(FileDialog);
@@ -652,19 +680,20 @@ struct ProjectItem {
void ProjectManager::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
-
- Engine::get_singleton()->set_editor_hint(false);
-
- } else if (p_what == NOTIFICATION_READY) {
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
- if (scroll_childs->get_child_count() == 0) {
- open_templates->popup_centered_minsize();
- }
+ Engine::get_singleton()->set_editor_hint(false);
+ } break;
+ case NOTIFICATION_READY: {
- } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
+ if (scroll_children->get_child_count() == 0)
+ open_templates->popup_centered_minsize();
+ } break;
+ case NOTIFICATION_VISIBILITY_CHANGED: {
- set_process_unhandled_input(is_visible_in_tree());
+ set_process_unhandled_input(is_visible_in_tree());
+ } break;
}
}
@@ -680,9 +709,9 @@ void ProjectManager::_panel_draw(Node *p_hb) {
}
void ProjectManager::_update_project_buttons() {
- for (int i = 0; i < scroll_childs->get_child_count(); i++) {
+ for (int i = 0; i < scroll_children->get_child_count(); i++) {
- CanvasItem *item = Object::cast_to<CanvasItem>(scroll_childs->get_child(i));
+ CanvasItem *item = Object::cast_to<CanvasItem>(scroll_children->get_child(i));
item->update();
}
@@ -704,8 +733,8 @@ void ProjectManager::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
int clicked_id = -1;
int last_clicked_id = -1;
- for (int i = 0; i < scroll_childs->get_child_count(); i++) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ for (int i = 0; i < scroll_children->get_child_count(); i++) {
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
if (!hb) continue;
if (hb->get_meta("name") == clicked) clicked_id = i;
if (hb->get_meta("name") == last_clicked) last_clicked_id = i;
@@ -714,8 +743,8 @@ void ProjectManager::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
if (last_clicked_id != -1 && clicked_id != -1) {
int min = clicked_id < last_clicked_id ? clicked_id : last_clicked_id;
int max = clicked_id > last_clicked_id ? clicked_id : last_clicked_id;
- for (int i = 0; i < scroll_childs->get_child_count(); ++i) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ for (int i = 0; i < scroll_children->get_child_count(); ++i) {
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
if (!hb) continue;
if (i != clicked_id && (i < min || i > max) && !mb->get_control()) {
selected_list.erase(hb->get_meta("name"));
@@ -769,9 +798,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
} break;
case KEY_HOME: {
- for (int i = 0; i < scroll_childs->get_child_count(); i++) {
+ for (int i = 0; i < scroll_children->get_child_count(); i++) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
if (hb) {
selected_list.clear();
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
@@ -784,13 +813,13 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
} break;
case KEY_END: {
- for (int i = scroll_childs->get_child_count() - 1; i >= 0; i--) {
+ for (int i = scroll_children->get_child_count() - 1; i >= 0; i--) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
if (hb) {
selected_list.clear();
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
- scroll->set_v_scroll(scroll_childs->get_size().y);
+ scroll->set_v_scroll(scroll_children->get_size().y);
_update_project_buttons();
break;
}
@@ -806,9 +835,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
bool found = false;
- for (int i = scroll_childs->get_child_count() - 1; i >= 0; i--) {
+ for (int i = scroll_children->get_child_count() - 1; i >= 0; i--) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
if (!hb) continue;
String current = hb->get_meta("name");
@@ -843,9 +872,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
bool found = selected_list.empty();
- for (int i = 0; i < scroll_childs->get_child_count(); i++) {
+ for (int i = 0; i < scroll_children->get_child_count(); i++) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
if (!hb) continue;
String current = hb->get_meta("name");
@@ -909,8 +938,8 @@ void ProjectManager::_load_recent_projects() {
ProjectListFilter::FilterOption filter_option = project_filter->get_filter_option();
String search_term = project_filter->get_search_term();
- while (scroll_childs->get_child_count() > 0) {
- memdelete(scroll_childs->get_child(0));
+ while (scroll_children->get_child_count() > 0) {
+ memdelete(scroll_children->get_child(0));
}
Map<String, String> selected_list_copy = selected_list;
@@ -1039,9 +1068,9 @@ void ProjectManager::_load_recent_projects() {
favorite->set_normal_texture(favorite_icon);
if (!is_favorite)
favorite->set_modulate(Color(1, 1, 1, 0.2));
- favorite->set_v_size_flags(SIZE_EXPAND);
favorite->connect("pressed", this, "_favorite_pressed", varray(hb));
favorite_box->add_child(favorite);
+ favorite_box->set_alignment(BoxContainer::ALIGN_CENTER);
hb->add_child(favorite_box);
TextureRect *tf = memnew(TextureRect);
@@ -1056,6 +1085,7 @@ void ProjectManager::_load_recent_projects() {
hb->add_child(vb);
Control *ec = memnew(Control);
ec->set_custom_minimum_size(Size2(0, 1));
+ ec->set_mouse_filter(MOUSE_FILTER_PASS);
vb->add_child(ec);
Label *title = memnew(Label(project_name));
title->add_font_override("font", gui_base->get_font("title", "EditorFonts"));
@@ -1069,7 +1099,7 @@ void ProjectManager::_load_recent_projects() {
fpath->add_color_override("font_color", font_color);
fpath->set_clip_text(true);
- scroll_childs->add_child(hb);
+ scroll_children->add_child(hb);
}
for (Map<String, String>::Element *E = selected_list_copy.front(); E; E = E->next()) {
@@ -1092,8 +1122,8 @@ void ProjectManager::_on_project_renamed() {
void ProjectManager::_on_project_created(const String &dir) {
bool has_already = false;
- for (int i = 0; i < scroll_childs->get_child_count(); i++) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ for (int i = 0; i < scroll_children->get_child_count(); i++) {
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
Label *fpath = Object::cast_to<Label>(hb->get_node(NodePath("project/path")));
if (fpath->get_text() == dir) {
has_already = true;
@@ -1110,8 +1140,8 @@ void ProjectManager::_on_project_created(const String &dir) {
}
void ProjectManager::_update_scroll_position(const String &dir) {
- for (int i = 0; i < scroll_childs->get_child_count(); i++) {
- HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_childs->get_child(i));
+ for (int i = 0; i < scroll_children->get_child_count(); i++) {
+ HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
Label *fpath = Object::cast_to<Label>(hb->get_node(NodePath("project/path")));
if (fpath->get_text() == dir) {
last_clicked = hb->get_meta("name");
@@ -1214,7 +1244,6 @@ void ProjectManager::_run_project_confirm() {
Error err = OS::get_singleton()->execute(exec, args, false, &pid);
ERR_FAIL_COND(err);
}
- //get_scene()->quit(); do not quit
}
void ProjectManager::_run_project() {
@@ -1552,12 +1581,9 @@ ProjectManager::ProjectManager() {
VBoxContainer *tree_vb = memnew(VBoxContainer);
tree_hb->add_child(tree_vb);
- scroll_childs = memnew(VBoxContainer);
- scroll_childs->set_h_size_flags(SIZE_EXPAND_FILL);
- scroll->add_child(scroll_childs);
-
- //HBoxContainer *hb = memnew( HBoxContainer );
- //vb->add_child(hb);
+ scroll_children = memnew(VBoxContainer);
+ scroll_children->set_h_size_flags(SIZE_EXPAND_FILL);
+ scroll->add_child(scroll_children);
Button *open = memnew(Button);
open->set_text(TTR("Edit"));
@@ -1663,7 +1689,7 @@ ProjectManager::ProjectManager() {
cancel->connect("pressed", this, "_exit_dialog");
vb->add_child(cc);
- //
+ //////////////////////////////////////////////////////////////
language_restart_ask = memnew(ConfirmationDialog);
language_restart_ask->get_ok()->set_text(TTR("Restart Now"));
@@ -1772,12 +1798,9 @@ void ProjectListFilter::_filter_option_selected(int p_idx) {
}
void ProjectListFilter::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_ENTER_TREE: {
- clear_search_button->set_icon(get_icon("Close", "EditorIcons"));
- } break;
- }
+ if (p_what == NOTIFICATION_ENTER_TREE)
+ clear_search_button->set_icon(get_icon("Close", "EditorIcons"));
}
void ProjectListFilter::_bind_methods() {