diff options
Diffstat (limited to 'tools/editor/property_editor.cpp')
-rw-r--r-- | tools/editor/property_editor.cpp | 392 |
1 files changed, 352 insertions, 40 deletions
diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 3258bc6d74..2ea28e26ad 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -45,6 +45,8 @@ #include "scene/resources/packed_scene.h" #include "scene/main/viewport.h" #include "editor_file_system.h" +#include "create_dialog.h" +#include "property_selector.h" void CustomPropertyEditor::_notification(int p_what) { @@ -82,6 +84,20 @@ void CustomPropertyEditor::_menu_option(int p_which) { v=val; emit_signal("variant_changed"); + } else if (hint==PROPERTY_HINT_ENUM) { + + v=p_which; + emit_signal("variant_changed"); + + } + } break; + case Variant::STRING: { + + if (hint==PROPERTY_HINT_ENUM) { + + v=hint_text.get_slice(",",p_which); + emit_signal("variant_changed"); + } } break; case Variant::OBJECT: { @@ -210,6 +226,10 @@ void CustomPropertyEditor::_menu_option(int p_which) { ERR_BREAK( !obj ); Resource *res=obj->cast_to<Resource>(); ERR_BREAK( !res ); + if (owner && hint==PROPERTY_HINT_RESOURCE_TYPE && hint_text=="Script") { + //make visual script the right type + res->call("set_instance_base_type",owner->get_type()); + } v=Ref<Resource>(res).get_ref_ptr(); emit_signal("variant_changed"); @@ -247,7 +267,8 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty hint=p_hint; hint_text=p_hint_text; type_button->hide(); - color_picker->hide(); + if (color_picker) + color_picker->hide(); texture_preview->hide(); inheritors_array.clear(); text_edit->hide(); @@ -276,6 +297,16 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty switch(type) { + case Variant::BOOL: { + + CheckBox *c=checks20[0]; + c->set_text("True"); + c->set_pos(Vector2(4,4)); + c->set_pressed(v); + c->show(); + set_size(checks20[0]->get_pos()+checks20[0]->get_size()+Vector2(4,4)*EDSCALE); + + } break; case Variant::INT: case Variant::REAL: { @@ -316,9 +347,24 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty set_size(Size2(70,35)*EDSCALE); } + } else if (hint==PROPERTY_HINT_ENUM) { + + menu->clear(); + Vector<String> options = hint_text.split(","); + for(int i=0;i<options.size();i++) { + menu->add_item(options[i],i); + } + menu->set_pos(get_pos()); + menu->popup(); + hide(); + updating=false; + return false; + } else if (hint==PROPERTY_HINT_ALL_FLAGS) { + checks20[0]->set_text(""); + uint32_t flgs = v; for(int i=0;i<2;i++) { @@ -388,7 +434,6 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty List<String> names; names.push_back("value:"); config_value_editors(1,1,50,names); - Vector3 vec=v; value_editor[0]->set_text( String::num(v) ); } @@ -410,7 +455,16 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty config_action_buttons(names); } else if (hint==PROPERTY_HINT_ENUM) { - + menu->clear(); + Vector<String> options = hint_text.split(","); + for(int i=0;i<options.size();i++) { + menu->add_item(options[i],i); + } + menu->set_pos(get_pos()); + menu->popup(); + hide(); + updating=false; + return false; } else if (hint==PROPERTY_HINT_MULTILINE_TEXT) { @@ -431,11 +485,134 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty action_buttons[0]->set_text(TTR("Close")); action_buttons[0]->show(); + } 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); + } + + if (hint_text!=String()) { + create_dialog->set_base_type(hint_text); + } else { + create_dialog->set_base_type("Object"); + } + + 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; names.push_back("string:"); config_value_editors(1,1,50,names); - Vector3 vec=v; value_editor[0]->set_text( v ); } @@ -596,11 +773,22 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::COLOR: { + if (!color_picker) { + //late init for performance + color_picker = memnew( ColorPicker ); + add_child(color_picker); + color_picker->hide(); + color_picker->set_area_as_parent_rect(); + for(int i=0;i<4;i++) + color_picker->set_margin((Margin)i,5); + color_picker->connect("color_changed",this,"_color_changed"); + } color_picker->show(); color_picker->set_edit_alpha(hint!=PROPERTY_HINT_COLOR_NO_ALPHA); color_picker->set_color(v); set_size( Size2(300*EDSCALE, color_picker->get_combined_minimum_size().height+10*EDSCALE)); + color_picker->set_focus_on_line_edit(); /* int ofs=80; int m=10; @@ -930,11 +1118,23 @@ void CustomPropertyEditor::_color_changed(const Color& p_color) { void CustomPropertyEditor::_node_path_selected(NodePath p_path) { - if (owner) { + + if (hint==PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && hint_text!=String()) { + + Node* node=get_node(hint_text); + if (node) { + + Node *tonode=node->get_node(p_path); + if (tonode) { + p_path=node->get_path_to(tonode); + } + } + + } else if (owner) { Node *node=NULL; - if (owner->is_type("Node")) + if (owner->is_type("Node")) node = owner->cast_to<Node>(); else if (owner->is_type("ArrayPropertyEdit")) node = owner->cast_to<ArrayPropertyEdit>()->get_node(); @@ -965,6 +1165,10 @@ void CustomPropertyEditor::_action_pressed(int p_which) { return; switch(type) { + case Variant::BOOL: { + v=checks20[0]->is_pressed(); + emit_signal("variant_changed"); + } break; case Variant::INT: { if (hint==PROPERTY_HINT_ALL_FLAGS) { @@ -999,6 +1203,7 @@ void CustomPropertyEditor::_action_pressed(int p_which) { file->clear_filters(); + if (hint_text!="") { Vector<String> extensions=hint_text.split(","); for(int i=0;i<extensions.size();i++) { @@ -1309,17 +1514,41 @@ void CustomPropertyEditor::_text_edit_changed() { } +void CustomPropertyEditor::_create_dialog_callback() { + + + v=create_dialog->get_selected_type(); + 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) return; updating=true; switch(type) { + case Variant::INT: { + + if (evaluator) + v=evaluator->eval(value_editor[0]->get_text()); + else + v=value_editor[0]->get_text().to_int(); + emit_signal("variant_changed"); + + + } break; case Variant::REAL: { if (hint!=PROPERTY_HINT_EXP_EASING) { if (evaluator) - evaluator->eval(value_editor[0]->get_text()); + v=evaluator->eval(value_editor[0]->get_text()); else v=value_editor[0]->get_text().to_double(); emit_signal("variant_changed"); @@ -1523,7 +1752,8 @@ void CustomPropertyEditor::_modified(String p_string) { } break; case Variant::NODE_PATH: { - + v=NodePath(value_editor[0]->get_text()); + emit_signal("variant_changed"); } break; case Variant::INPUT_EVENT: { @@ -1690,6 +1920,8 @@ void CustomPropertyEditor::_bind_methods() { ObjectTypeDB::bind_method("_drag_easing",&CustomPropertyEditor::_drag_easing); 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); @@ -1757,13 +1989,9 @@ CustomPropertyEditor::CustomPropertyEditor() { action_buttons[i]->connect("pressed", this,"_action_pressed",binds); } - color_picker = memnew( ColorPicker ); - add_child(color_picker); - color_picker->hide(); - color_picker->set_area_as_parent_rect(); - for(int i=0;i<4;i++) - color_picker->set_margin((Margin)i,5); - color_picker->connect("color_changed",this,"_color_changed"); + color_picker=NULL; + + set_as_toplevel(true); file = memnew ( EditorFileDialog ); @@ -1816,6 +2044,9 @@ CustomPropertyEditor::CustomPropertyEditor() { add_child(slider); slider->set_area_as_parent_rect(5); slider->connect("value_changed",this,"_range_modified"); + + create_dialog = NULL; + property_select = NULL; } bool PropertyEditor::_might_be_in_instance() { @@ -1956,6 +2187,13 @@ bool PropertyEditor::_is_property_different(const Variant& p_current, const Vari return false; } + if (p_current.get_type()==Variant::REAL && p_orig.get_type()==Variant::REAL) { + float a = p_current; + float b = p_orig; + + return Math::abs(a-b)>CMP_EPSILON; //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error + } + return bool(Variant::evaluate(Variant::OP_NOT_EQUAL,p_current,p_orig)); } @@ -2076,6 +2314,25 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p } break; case Variant::STRING: + + if (p_hint==PROPERTY_HINT_TYPE_STRING) { + + 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(","); @@ -2128,6 +2385,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p if (obj->get( p_name ).get_type() == Variant::NIL || obj->get( p_name ).operator RefPtr().is_null()) { p_item->set_text(1,"<null>"); + p_item->set_icon(1,Ref<Texture>()); Dictionary d = p_item->get_metadata(0); int hint=d.has("hint")?d["hint"].operator int():-1; @@ -2225,6 +2483,7 @@ void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) { if (_get_instanced_node_original_property(p_name,vorig) || usage) { Variant v = obj->get(p_name); + bool changed = _is_property_different(v,vorig,usage); //if ((found!=-1 && !is_disabled)!=changed) { @@ -2340,15 +2599,27 @@ Variant PropertyEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) if (!item) return Variant(); - int col = tree->get_column_at_pos(p_point); - if (col!=1) - return Variant(); - - Dictionary d = item->get_metadata(0); if (!d.has("name")) return Variant(); + int col = tree->get_column_at_pos(p_point); + if (col==0) { + + Dictionary dp; + dp["type"]="obj_property"; + dp["object"]=obj; + dp["property"]=d["name"]; + dp["value"]=obj->get(d["name"]); + + Label *label =memnew( Label ); + label->set_text(d["name"]); + set_drag_preview(label); + return dp; + } + + + Variant val = obj->get(d["name"]); if (val.get_type()==Variant::OBJECT) { @@ -2797,7 +3068,7 @@ void PropertyEditor::update_tree() { if (capitalize_paths) cat = cat.capitalize(); - if (cat.findn(filter)==-1 && name.findn(filter)==-1) + if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name)) continue; } @@ -2964,10 +3235,8 @@ void PropertyEditor::update_tree() { else item->set_cell_mode( 1, TreeItem::CELL_MODE_RANGE_EXPRESSION ); - if (p.hint==PROPERTY_HINT_SPRITE_FRAME) { - item->set_range_config(1,0,99999,1); - } else if (p.hint==PROPERTY_HINT_RANGE || p.hint==PROPERTY_HINT_EXP_RANGE) { + if (p.hint==PROPERTY_HINT_SPRITE_FRAME || p.hint==PROPERTY_HINT_RANGE || p.hint==PROPERTY_HINT_EXP_RANGE) { int c = p.hint_string.get_slice_count(","); float min=0,max=100,step=1; @@ -3026,10 +3295,10 @@ void PropertyEditor::update_tree() { } else { if (p.type == Variant::REAL) { - item->set_range_config(1, -65536, 65535, 0.001); + item->set_range_config(1, -16777216, 16777216, 0.001); } else { - item->set_range_config(1, -65536, 65535, 1); + item->set_range_config(1, -2147483647, 2147483647, 1); } }; @@ -3086,6 +3355,24 @@ void PropertyEditor::update_tree() { } break; + case PROPERTY_HINT_METHOD_OF_VARIANT_TYPE: ///< a property of a type + 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); + item->set_editable(1,!read_only); + if (show_type_icons) + item->set_icon( 0, get_icon("String","EditorIcons") ); + item->set_text(1,obj->get(p.name)); + + } break; + default: { item->set_cell_mode( 1, TreeItem::CELL_MODE_STRING ); @@ -3330,10 +3617,10 @@ void PropertyEditor::update_tree() { String type; if (p.hint==PROPERTY_HINT_RESOURCE_TYPE) type=p.hint_string; - bool notnil=false; if (obj->get( p.name ).get_type() == Variant::NIL || obj->get( p.name ).operator RefPtr().is_null()) { item->set_text(1,"<null>"); + item->set_icon(1,Ref<Texture>()); } else { RES res = obj->get( p.name ).operator RefPtr(); @@ -3352,8 +3639,7 @@ void PropertyEditor::update_tree() { } else { item->set_text(1,"<"+res->get_type()+">"); - }; - notnil=true; + } if (has_icon(res->get_type(),"EditorIcons")) { type=res->get_type(); @@ -3470,7 +3756,7 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { } else { - undo_redo->create_action(TTR("Set")+" "+p_name,true); + undo_redo->create_action(TTR("Set")+" "+p_name,UndoRedo::MERGE_ENDS); undo_redo->add_do_property(obj,p_name,p_value); undo_redo->add_undo_property(obj,p_name,obj->get(p_name)); undo_redo->add_do_method(this,"_changed_callback",obj,p_name); @@ -3919,6 +4205,7 @@ void PropertyEditor::_bind_methods() { ObjectTypeDB::bind_method( "_filter_changed",&PropertyEditor::_filter_changed); ObjectTypeDB::bind_method( "update_tree",&PropertyEditor::update_tree); ObjectTypeDB::bind_method( "_resource_preview_done",&PropertyEditor::_resource_preview_done); + ObjectTypeDB::bind_method( "refresh",&PropertyEditor::refresh); ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &PropertyEditor::get_drag_data_fw); ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &PropertyEditor::can_drop_data_fw); @@ -4174,6 +4461,8 @@ public: void SectionedPropertyEditor::_bind_methods() { ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected); + + ObjectTypeDB::bind_method("update_category_list", &SectionedPropertyEditor::update_category_list); } void SectionedPropertyEditor::_section_selected(int p_which) { @@ -4217,19 +4506,32 @@ String SectionedPropertyEditor::get_full_item_path(const String& p_item) { void SectionedPropertyEditor::edit(Object* p_object) { - if (p_object) { - obj=p_object->get_instance_ID(); - update_category_list(); - } else { + if (!p_object) { + obj = -1; sections->clear(); + + filter->set_edited(NULL); + editor->edit(NULL); + + return; } - filter->set_edited(p_object); - editor->edit(filter); + ObjectID id = p_object->get_instance_ID(); + + if (obj != id) { + + obj = id; + update_category_list(); + + filter->set_edited(p_object); + editor->edit(filter); - sections->select(0); - _section_selected(0); + sections->select(0); + _section_selected(0); + } else { + update_category_list(); + } } void SectionedPropertyEditor::update_category_list() { @@ -4285,6 +4587,8 @@ PropertyEditor *SectionedPropertyEditor::get_property_editor() { SectionedPropertyEditor::SectionedPropertyEditor() { + obj = -1; + VBoxContainer *left_vb = memnew( VBoxContainer); left_vb->set_custom_minimum_size(Size2(160,0)*EDSCALE); add_child(left_vb); @@ -4319,7 +4623,7 @@ SectionedPropertyEditor::~SectionedPropertyEditor() { double PropertyValueEvaluator::eval(const String& p_text) { - if (!obj) + if (!obj || !script_language) return _default_eval(p_text); Ref<Script> script= Ref<Script>(script_language ->create_script()); @@ -4331,6 +4635,8 @@ double PropertyValueEvaluator::eval(const String& p_text) { } ScriptInstance *script_instance = script->instance_create(this); + if (!script_instance) + return _default_eval(p_text); Variant::CallError call_err; script_instance->call("set_this",obj); @@ -4358,7 +4664,13 @@ String PropertyValueEvaluator::_build_script(const String& p_text) { } PropertyValueEvaluator::PropertyValueEvaluator() { - script_language = ScriptServer::get_language(0); // todo: get script language from editor setting + script_language=NULL; + + for(int i=0;i<ScriptServer::get_language_count();i++) { + if (ScriptServer::get_language(i)->get_name()=="GDScript") { + script_language=ScriptServer::get_language(i); + } + } } PropertyValueEvaluator::~PropertyValueEvaluator() { |