Added drag and drop to rearrange the autoload order

* Created a new class for autoload settings, in editor_autoload_settings.h
This commit is contained in:
Franklin Sobrinho 2016-07-04 20:22:28 -03:00
parent 576a28470f
commit 3b7b581d63
4 changed files with 719 additions and 405 deletions

View file

@ -100,16 +100,6 @@ void ProjectSettings::_notification(int p_what) {
translation_res_file_open->add_filter("*."+E->get());
translation_res_option_file_open->add_filter("*."+E->get());
}
List<String> afn;
ResourceLoader::get_recognized_extensions_for_type("Script",&afn);
ResourceLoader::get_recognized_extensions_for_type("PackedScene",&afn);
for (List<String>::Element *E=afn.front();E;E=E->next()) {
autoload_file_open->add_filter("*."+E->get());
}
}
}
@ -564,7 +554,7 @@ void ProjectSettings::popup_project_settings() {
popup_centered_ratio();
globals_editor->update_category_list();
_update_translations();
_update_autoload();
autoload_settings->update_autoload();
plugin_settings->update_plugins();
}
@ -811,263 +801,6 @@ void ProjectSettings::_translation_file_open() {
translation_file_open->popup_centered_ratio();
}
void ProjectSettings::_autoload_file_callback(const String& p_path) {
autoload_add_path->set_text(p_path);
//if (autoload_add_name->get_text().strip_edges()==String()) {
autoload_add_name->set_text( p_path.get_file().basename() );
//}
//_translation_add(p_translation);
}
void ProjectSettings::_autoload_file_open() {
autoload_file_open->popup_centered_ratio();
}
void ProjectSettings::_autoload_edited() {
if (updating_autoload)
return;
TreeItem *ti = autoload_list->get_edited();
int column = autoload_list->get_edited_column();
if (!ti || (column != 0 && column != 2))
return;
if (column == 0) {
String name = ti->get_text(0);
String old_name = selected_autoload.substr(selected_autoload.find("/")+1,selected_autoload.length());
if (!name.is_valid_identifier()) {
ti->set_text(0,old_name);
message->set_text(TTR("Invalid name.")+"\n"+TTR("Valid characters:")+" a-z, A-Z, 0-9 or _");
message->popup_centered(Size2(300,100));
return;
}
if (ObjectTypeDB::type_exists(name)) {
ti->set_text(0,old_name);
message->set_text(TTR("Invalid name. Must not collide with an existing engine class name."));
message->popup_centered(Size2(400,100));
return;
}
for(int i=0;i<Variant::VARIANT_MAX;i++) {
if (Variant::get_type_name(Variant::Type(i))==name) {
ti->set_text(0,old_name);
message->set_text(TTR("Invalid name. Must not collide with an existing buit-in type name."));
message->popup_centered(Size2(400,100));
return;
}
}
for(int i=0;i<GlobalConstants::get_global_constant_count();i++) {
if (GlobalConstants::get_global_constant_name(i)==name) {
ti->set_text(0,old_name);
message->set_text(TTR("Invalid name. Must not collide with an existing global constant name."));
message->popup_centered(Size2(400,100));
return;
}
}
if (Globals::get_singleton()->has("autoload/"+name)) {
ti->set_text(0,old_name);
message->set_text(vformat(TTR("Autoload '%s' already exists!"),name));
message->popup_centered(Size2(300,100));
return;
}
updating_autoload = true;
name = "autoload/"+name;
String path = Globals::get_singleton()->get(selected_autoload);
bool is_persisting = Globals::get_singleton()->is_persisting(selected_autoload);
int order = Globals::get_singleton()->get_order(selected_autoload);
undo_redo->create_action(TTR("Rename Autoload"));
undo_redo->add_do_property(Globals::get_singleton(),name,path);
undo_redo->add_do_method(Globals::get_singleton(),"set_persisting",name,is_persisting);
undo_redo->add_do_method(Globals::get_singleton(),"set_order",name,order);
undo_redo->add_do_method(Globals::get_singleton(),"clear",selected_autoload);
undo_redo->add_undo_property(Globals::get_singleton(),selected_autoload,path);
undo_redo->add_undo_method(Globals::get_singleton(),"set_persisting",selected_autoload,is_persisting);
undo_redo->add_undo_method(Globals::get_singleton(),"set_order",selected_autoload,order);
undo_redo->add_undo_method(Globals::get_singleton(),"clear",name);
undo_redo->add_do_method(this,"_update_autoload");
undo_redo->add_undo_method(this,"_update_autoload");
undo_redo->add_do_method(this,"_settings_changed");
undo_redo->add_undo_method(this,"_settings_changed");
undo_redo->commit_action();
selected_autoload = name;
} else if (column == 2) {
updating_autoload = true;
bool checked = ti->is_checked(2);
String base = "autoload/"+ti->get_text(0);
String path = Globals::get_singleton()->get(base);
int order = Globals::get_singleton()->get_order(base);
if (path.begins_with("*"))
path = path.substr(1,path.length());
if (checked)
path = "*" + path;
undo_redo->create_action(TTR("Toggle AutoLoad Globals"));
undo_redo->add_do_property(Globals::get_singleton(),base,path);
undo_redo->add_undo_property(Globals::get_singleton(),base,Globals::get_singleton()->get(base));
undo_redo->add_do_method(Globals::get_singleton(),"set_order",base,order); // keep order, as config order matters for these
undo_redo->add_undo_method(Globals::get_singleton(),"set_order",base,order);
undo_redo->add_do_method(this,"_update_autoload");
undo_redo->add_undo_method(this,"_update_autoload");
undo_redo->add_do_method(this,"_settings_changed");
undo_redo->add_undo_method(this,"_settings_changed");
undo_redo->commit_action();
}
updating_autoload = false;
}
void ProjectSettings::_autoload_add() {
String name = autoload_add_name->get_text();
if (!name.is_valid_identifier()) {
message->set_text(TTR("Invalid name.")+"\n"+TTR("Valid characters:")+" a-z, A-Z, 0-9 or _");
message->popup_centered(Size2(300,100));
return;
}
if (ObjectTypeDB::type_exists(name)) {
message->set_text(TTR("Invalid name. Must not collide with an existing engine class name."));
message->popup_centered(Size2(300,100));
return;
}
for(int i=0;i<Variant::VARIANT_MAX;i++) {
if (Variant::get_type_name(Variant::Type(i))==name) {
message->set_text(TTR("Invalid name. Must not collide with an existing buit-in type name."));
message->popup_centered(Size2(300,100));
return;
}
}
for(int i=0;i<GlobalConstants::get_global_constant_count();i++) {
if (GlobalConstants::get_global_constant_name(i)==name) {
message->set_text(TTR("Invalid name. Must not collide with an existing global constant name."));
message->popup_centered(Size2(300,100));
return;
}
}
String path = autoload_add_path->get_text();
if (!FileAccess::exists(path)) {
message->set_text("Invalid Path.\nFile does not exist.");
message->popup_centered(Size2(300,100));
return;
}
if (!path.begins_with("res://")) {
message->set_text("Invalid Path.\nNot in resource path.");
message->popup_centered(Size2(300,100));
return;
}
undo_redo->create_action(TTR("Add Autoload"));
name = "autoload/"+name;
undo_redo->add_do_property(Globals::get_singleton(),name,"*"+path);
if (Globals::get_singleton()->has(name))
undo_redo->add_undo_property(Globals::get_singleton(),name,Globals::get_singleton()->get(name));
else
undo_redo->add_undo_property(Globals::get_singleton(),name,Variant());
undo_redo->add_do_method(Globals::get_singleton(),"set_persisting",name,true);
undo_redo->add_do_method(this,"_update_autoload");
undo_redo->add_undo_method(this,"_update_autoload");
undo_redo->add_do_method(this,"_settings_changed");
undo_redo->add_undo_method(this,"_settings_changed");
undo_redo->commit_action();
autoload_add_path->set_text("");
autoload_add_name->set_text("");
//autoload_file_open->popup_centered_ratio();
}
void ProjectSettings::_autoload_delete(Object *p_item,int p_column, int p_button) {
TreeItem *ti=p_item->cast_to<TreeItem>();
String name = "autoload/"+ti->get_text(0);
if (p_button==0) {
//delete
int order = Globals::get_singleton()->get_order(name);
undo_redo->create_action(TTR("Remove Autoload"));
undo_redo->add_do_property(Globals::get_singleton(),name,Variant());
undo_redo->add_undo_property(Globals::get_singleton(),name,Globals::get_singleton()->get(name));
undo_redo->add_undo_method(Globals::get_singleton(),"set_persisting",name,true);
undo_redo->add_undo_method(Globals::get_singleton(),"set_order",name,order);
undo_redo->add_do_method(this,"_update_autoload");
undo_redo->add_undo_method(this,"_update_autoload");
undo_redo->add_do_method(this,"_settings_changed");
undo_redo->add_undo_method(this,"_settings_changed");
undo_redo->commit_action();
} else {
TreeItem *swap = NULL;
if (p_button==1) {
swap=ti->get_prev();
} else if (p_button==2) {
swap=ti->get_next();
}
if (!swap)
return;
String swap_name= "autoload/"+swap->get_text(0);
int order = Globals::get_singleton()->get_order(name);
int swap_order = Globals::get_singleton()->get_order(swap_name);
undo_redo->create_action(TTR("Move Autoload"));
undo_redo->add_do_method(Globals::get_singleton(),"set_order",swap_name,order);
undo_redo->add_do_method(Globals::get_singleton(),"set_order",name,swap_order);
undo_redo->add_undo_method(Globals::get_singleton(),"set_order",swap_name,swap_order);
undo_redo->add_undo_method(Globals::get_singleton(),"set_order",name,order);
undo_redo->add_do_method(this,"_update_autoload");
undo_redo->add_undo_method(this,"_update_autoload");
undo_redo->add_do_method(this,"_settings_changed");
undo_redo->add_undo_method(this,"_settings_changed");
undo_redo->commit_action();
}
}
void ProjectSettings::_autoload_selected() {
TreeItem *ti = autoload_list->get_selected();
if (!ti)
return;
selected_autoload = "autoload/"+ti->get_text(0);
}
void ProjectSettings::_translation_delete(Object *p_item,int p_column, int p_button) {
TreeItem *ti = p_item->cast_to<TreeItem>();
@ -1393,55 +1126,6 @@ void ProjectSettings::_update_translations() {
}
void ProjectSettings::_update_autoload() {
if (updating_autoload)
return;
updating_autoload=true;
autoload_list->clear();
TreeItem *root = autoload_list->create_item();
autoload_list->set_hide_root(true);
List<PropertyInfo> props;
Globals::get_singleton()->get_property_list(&props);
for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
const PropertyInfo &pi=E->get();
if (!pi.name.begins_with("autoload/"))
continue;
String name = pi.name.get_slice("/",1);
String path = Globals::get_singleton()->get(pi.name);
if (name=="")
continue;
bool global=false;
if (path.begins_with("*")) {
path=path.substr(1,path.length());
global=true;
}
TreeItem *t = autoload_list->create_item(root);
t->set_text(0,name);
t->set_editable(0,true);
t->set_text(1,path);
t->set_cell_mode(2,TreeItem::CELL_MODE_CHECK);
t->set_editable(2,true);
t->set_text(2,TTR("Enable"));
t->set_checked(2,global);
t->add_button(3,get_icon("MoveUp","EditorIcons"),1);
t->add_button(3,get_icon("MoveDown","EditorIcons"),2);
t->add_button(3,get_icon("Del","EditorIcons"),0);
}
updating_autoload=false;
}
void ProjectSettings::_toggle_search_bar(bool p_pressed) {
globals_editor->get_property_editor()->set_use_filter(p_pressed);
@ -1508,14 +1192,6 @@ void ProjectSettings::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_translation_res_delete"),&ProjectSettings::_translation_res_delete);
ObjectTypeDB::bind_method(_MD("_translation_res_option_delete"),&ProjectSettings::_translation_res_option_delete);
ObjectTypeDB::bind_method(_MD("_autoload_add"),&ProjectSettings::_autoload_add);
ObjectTypeDB::bind_method(_MD("_autoload_file_open"),&ProjectSettings::_autoload_file_open);
ObjectTypeDB::bind_method(_MD("_autoload_file_callback"),&ProjectSettings::_autoload_file_callback);
ObjectTypeDB::bind_method(_MD("_update_autoload"),&ProjectSettings::_update_autoload);
ObjectTypeDB::bind_method(_MD("_autoload_delete"),&ProjectSettings::_autoload_delete);
ObjectTypeDB::bind_method(_MD("_autoload_edited"),&ProjectSettings::_autoload_edited);
ObjectTypeDB::bind_method(_MD("_autoload_selected"),&ProjectSettings::_autoload_selected);
ObjectTypeDB::bind_method(_MD("_clear_search_box"),&ProjectSettings::_clear_search_box);
ObjectTypeDB::bind_method(_MD("_toggle_search_bar"),&ProjectSettings::_toggle_search_bar);
@ -1858,69 +1534,10 @@ ProjectSettings::ProjectSettings(EditorData *p_data) {
{
VBoxContainer *avb = memnew( VBoxContainer );
tab_container->add_child(avb);
avb->set_name(TTR("AutoLoad"));
HBoxContainer *ahb = memnew( HBoxContainer);
avb->add_child(ahb);
VBoxContainer *avb_path = memnew( VBoxContainer );
avb_path->set_h_size_flags(SIZE_EXPAND_FILL);
HBoxContainer *ahb_path = memnew( HBoxContainer );
autoload_add_path = memnew(LineEdit);
autoload_add_path->set_h_size_flags(SIZE_EXPAND_FILL);
ahb_path->add_child(autoload_add_path);
Button *browseaa = memnew( Button("..") );
ahb_path->add_child(browseaa);
browseaa->connect("pressed",this,"_autoload_file_open");
avb_path->add_margin_child(TTR("Path:"),ahb_path);
ahb->add_child(avb_path);
VBoxContainer *avb_name = memnew( VBoxContainer );
avb_name->set_h_size_flags(SIZE_EXPAND_FILL);
HBoxContainer *ahb_name = memnew( HBoxContainer );
autoload_add_name = memnew(LineEdit);
autoload_add_name->set_h_size_flags(SIZE_EXPAND_FILL);
ahb_name->add_child(autoload_add_name);
avb_name->add_margin_child(TTR("Node Name:"),ahb_name);
Button *addaa = memnew( Button(TTR("Add")) );
ahb_name->add_child(addaa);
addaa->connect("pressed",this,"_autoload_add");
ahb->add_child(avb_name);
autoload_list = memnew( Tree );
autoload_list->set_v_size_flags(SIZE_EXPAND_FILL);
avb->add_margin_child(TTR("List:"),autoload_list,true);
autoload_file_open=memnew( EditorFileDialog );
add_child(autoload_file_open);
autoload_file_open->set_mode(EditorFileDialog::MODE_OPEN_FILE);
autoload_file_open->connect("file_selected",this,"_autoload_file_callback");
autoload_list->set_columns(4);
autoload_list->set_column_titles_visible(true);
autoload_list->set_column_title(0,TTR("Name"));
autoload_list->set_column_expand(0,true);
autoload_list->set_column_min_width(0,100);
autoload_list->set_column_title(1,TTR("Path"));
autoload_list->set_column_expand(1,true);
autoload_list->set_column_min_width(1,100);
autoload_list->set_column_title(2,TTR("Singleton"));
autoload_list->set_column_expand(2,false);
autoload_list->set_column_min_width(2,80);
autoload_list->set_column_expand(3,false);
autoload_list->set_column_min_width(3,80);
autoload_list->connect("button_pressed",this,"_autoload_delete");
autoload_list->connect("item_edited",this,"_autoload_edited");
autoload_list->connect("cell_selected", this, "_autoload_selected");
updating_autoload=false;
autoload_settings = memnew( EditorAutoloadSettings );
autoload_settings->set_name(TTR("AutoLoad"));
tab_container->add_child(autoload_settings);
autoload_settings->connect("autoload_changed", this, "_settings_changed");
}
{