1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Proper function/property selection in visual script editing for property.

This one has an ordered list, built-in description, search, etc.
This commit is contained in:
Juan Linietsky
2016-08-23 19:29:07 -03:00
parent 965fcf5996
commit ad8f208bdb
17 changed files with 949 additions and 676 deletions

View File

@@ -46,6 +46,7 @@
#include "scene/main/viewport.h"
#include "editor_file_system.h"
#include "create_dialog.h"
#include "property_selector.h"
void CustomPropertyEditor::_notification(int p_what) {
@@ -438,6 +439,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty
} else if (hint==PROPERTY_HINT_TYPE_STRING) {
if (!create_dialog) {
create_dialog = memnew( CreateDialog );
create_dialog->connect("create",this,"_create_dialog_callback");
@@ -452,6 +454,112 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty
create_dialog->popup(false);
hide();
updating=false;
return false;
} else if (hint==PROPERTY_HINT_METHOD_OF_VARIANT_TYPE) {
#define MAKE_PROPSELECT if (!property_select) { property_select = memnew(PropertySelector); property_select->connect("selected",this,"_create_selected_property"); add_child(property_select); } hide();
MAKE_PROPSELECT;
Variant::Type type=Variant::NIL;
for(int i=0;i<Variant::VARIANT_MAX;i++) {
if (hint_text==Variant::get_type_name(Variant::Type(i))) {
type=Variant::Type(i);
}
}
if (type)
property_select->select_method_from_basic_type(type,v);
updating=false;
return false;
} else if (hint==PROPERTY_HINT_METHOD_OF_BASE_TYPE) {
MAKE_PROPSELECT
property_select->select_method_from_base_type(hint_text,v);
updating=false;
return false;
} else if (hint==PROPERTY_HINT_METHOD_OF_INSTANCE) {
MAKE_PROPSELECT
Object *instance = ObjectDB::get_instance(hint_text.to_int64());
if (instance)
property_select->select_method_from_instance(instance,v);
updating=false;
return false;
} else if (hint==PROPERTY_HINT_METHOD_OF_SCRIPT) {
MAKE_PROPSELECT
Object *obj = ObjectDB::get_instance(hint_text.to_int64());
if (obj && obj->cast_to<Script>()) {
property_select->select_method_from_script(obj->cast_to<Script>(),v);
}
updating=false;
return false;
} else if (hint==PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE) {
MAKE_PROPSELECT
Variant::Type type=Variant::NIL;
String tname=hint_text;
if (tname.find(".")!=-1)
tname=tname.get_slice(".",0);
for(int i=0;i<Variant::VARIANT_MAX;i++) {
if (tname==Variant::get_type_name(Variant::Type(i))) {
type=Variant::Type(Variant::Type(i));
}
}
InputEvent::Type iet = InputEvent::NONE;
if (hint_text.find(".")!=-1) {
iet=InputEvent::Type(int(hint_text.get_slice(".",1).to_int()));
}
if (type)
property_select->select_property_from_basic_type(type,iet,v);
updating=false;
return false;
} else if (hint==PROPERTY_HINT_PROPERTY_OF_BASE_TYPE) {
MAKE_PROPSELECT
property_select->select_property_from_base_type(hint_text,v);
updating=false;
return false;
} else if (hint==PROPERTY_HINT_PROPERTY_OF_INSTANCE) {
Object *instance = ObjectDB::get_instance(hint_text.to_int64());
if (instance)
property_select->select_property_from_instance(instance,v);
updating=false;
return false;
} else if (hint==PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
MAKE_PROPSELECT
Object *obj = ObjectDB::get_instance(hint_text.to_int64());
if (obj && obj->cast_to<Script>()) {
property_select->select_property_from_script(obj->cast_to<Script>(),v);
}
updating=false;
return false;
} else if (hint==PROPERTY_HINT_TYPE_STRING) {
if (!create_dialog) {
create_dialog = memnew( CreateDialog );
create_dialog->connect("create",this,"_create_dialog_callback");
add_child(create_dialog);
}
} else {
List<String> names;
@@ -1360,6 +1468,13 @@ void CustomPropertyEditor::_create_dialog_callback() {
emit_signal("variant_changed");
}
void CustomPropertyEditor::_create_selected_property(const String& p_prop) {
v=p_prop;
emit_signal("variant_changed");
}
void CustomPropertyEditor::_modified(String p_string) {
if (updating)
@@ -1753,6 +1868,7 @@ void CustomPropertyEditor::_bind_methods() {
ObjectTypeDB::bind_method( "_text_edit_changed",&CustomPropertyEditor::_text_edit_changed);
ObjectTypeDB::bind_method( "_menu_option",&CustomPropertyEditor::_menu_option);
ObjectTypeDB::bind_method( "_create_dialog_callback",&CustomPropertyEditor::_create_dialog_callback);
ObjectTypeDB::bind_method( "_create_selected_property",&CustomPropertyEditor::_create_selected_property);
@@ -1877,6 +1993,7 @@ CustomPropertyEditor::CustomPropertyEditor() {
slider->connect("value_changed",this,"_range_modified");
create_dialog = NULL;
property_select = NULL;
}
bool PropertyEditor::_might_be_in_instance() {
@@ -2150,6 +2267,19 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p
p_item->set_text(1,obj->get(p_name));
}
if ( p_hint==PROPERTY_HINT_METHOD_OF_VARIANT_TYPE ||
p_hint==PROPERTY_HINT_METHOD_OF_BASE_TYPE ||
p_hint==PROPERTY_HINT_METHOD_OF_INSTANCE ||
p_hint==PROPERTY_HINT_METHOD_OF_SCRIPT ||
p_hint==PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE ||
p_hint==PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ||
p_hint==PROPERTY_HINT_PROPERTY_OF_INSTANCE ||
p_hint==PROPERTY_HINT_PROPERTY_OF_SCRIPT ) {
p_item->set_text(1,obj->get(p_name));
}
if (p_hint==PROPERTY_HINT_ENUM) {
Vector<String> strings = p_hint_text.split(",");
@@ -3172,6 +3302,13 @@ void PropertyEditor::update_tree() {
} break;
case PROPERTY_HINT_METHOD_OF_BASE_TYPE: ///< a method of a base type
case PROPERTY_HINT_METHOD_OF_INSTANCE: ///< a method of an instance
case PROPERTY_HINT_METHOD_OF_SCRIPT: ///< a method of a script & base
case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE: ///< a property of a type
case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE: ///< a property of a base type
case PROPERTY_HINT_PROPERTY_OF_INSTANCE: ///< a property of an instance
case PROPERTY_HINT_PROPERTY_OF_SCRIPT: ///< a property of a script & base
case PROPERTY_HINT_TYPE_STRING: {
item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM);
@@ -3181,6 +3318,7 @@ void PropertyEditor::update_tree() {
item->set_text(1,obj->get(p.name));
} break;
default: {
item->set_cell_mode( 1, TreeItem::CELL_MODE_STRING );