summaryrefslogtreecommitdiffstats
path: root/tools/editor/array_property_edit.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-01-11 14:46:38 +0100
committerGitHub <noreply@github.com>2017-01-11 14:46:38 +0100
commit42802ab9dc4c688f0300c51859cae1fe3c18017d (patch)
treeb2022cf7ad646ae9130b8f6d0146de81968d7b1b /tools/editor/array_property_edit.cpp
parent34c33648f236b50eb9a68b7a11ee811f979caa3f (diff)
parent713f1451b95c7dd29079496186fb157ac0a11b40 (diff)
downloadredot-engine-42802ab9dc4c688f0300c51859cae1fe3c18017d.tar.gz
Merge pull request #6930 from bojidar-bg/gdscript-export-array-hint
Allow typing hints for Array class (in GDScript and Inspector)
Diffstat (limited to 'tools/editor/array_property_edit.cpp')
-rw-r--r--tools/editor/array_property_edit.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/tools/editor/array_property_edit.cpp b/tools/editor/array_property_edit.cpp
index d7e980980c..b587c4f830 100644
--- a/tools/editor/array_property_edit.cpp
+++ b/tools/editor/array_property_edit.cpp
@@ -100,13 +100,19 @@ bool ArrayPropertyEdit::_set(const StringName& p_name, const Variant& p_value){
ur->add_undo_method(this,"_set_value",i,arr.get(i));
}
- } else if (newsize>size && size) {
+ } else if (newsize>size) {
Variant init;
Variant::CallError ce;
- init = Variant::construct(arr.get(size-1).get_type(),NULL,0,ce);
- for(int i=size;i<newsize;i++) {
- ur->add_do_method(this,"_set_value",i,init);
+ Variant::Type new_type = subtype;
+ if(new_type==Variant::NIL && size) {
+ new_type = arr.get(size-1).get_type();
+ }
+ if(new_type!=Variant::NIL) {
+ init = Variant::construct(new_type,NULL,0,ce);
+ for(int i=size;i<newsize;i++) {
+ ur->add_do_method(this,"_set_value",i,init);
+ }
}
}
@@ -223,28 +229,52 @@ void ArrayPropertyEdit::_get_property_list( List<PropertyInfo> *p_list) const{
for(int i=0;i<items;i++) {
Variant v=arr.get(i+offset);
- if (arr.get_type()==Variant::ARRAY) {
+ bool is_typed = arr.get_type()!=Variant::ARRAY || subtype!=Variant::NIL;
+
+ if (!is_typed) {
p_list->push_back(PropertyInfo(Variant::INT,"indices/"+itos(i+offset)+"_type",PROPERTY_HINT_ENUM,vtypes));
}
- if (arr.get_type()!=Variant::ARRAY || v.get_type()!=Variant::NIL) {
+
+ if (is_typed || v.get_type()!=Variant::NIL ) {
PropertyInfo pi(v.get_type(),"indices/"+itos(i+offset));
- if (v.get_type()==Variant::OBJECT) {
+ if(subtype!=Variant::NIL) {
+ pi.type = Variant::Type(subtype);
+ pi.hint = PropertyHint(subtype_hint);
+ pi.hint_string = subtype_hint_string;
+ } else if (v.get_type()==Variant::OBJECT) {
pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
pi.hint_string="Resource";
}
+
p_list->push_back(pi);
}
}
}
-void ArrayPropertyEdit::edit(Object* p_obj,const StringName& p_prop,Variant::Type p_deftype) {
+void ArrayPropertyEdit::edit(Object* p_obj,const StringName& p_prop,const String& p_hint_string,Variant::Type p_deftype) {
page=0;
property=p_prop;
obj=p_obj->get_instance_ID();
default_type=p_deftype;
+ if(!p_hint_string.empty()) {
+ int hint_subtype_seperator = p_hint_string.find(":");
+ if(hint_subtype_seperator >= 0) {
+ String subtype_string = p_hint_string.substr(0,hint_subtype_seperator);
+
+ int slash_pos = subtype_string.find("/");
+ if(slash_pos >= 0) {
+ subtype_hint = PropertyHint(subtype_string.substr(slash_pos+1, subtype_string.size()-slash_pos-1).to_int());
+ subtype_string = subtype_string.substr(0,slash_pos);
+ }
+
+ subtype_hint_string = p_hint_string.substr(hint_subtype_seperator+1, p_hint_string.size() - hint_subtype_seperator-1);
+ subtype=Variant::Type(subtype_string.to_int());
+ }
+ }
+
}
Node *ArrayPropertyEdit::get_node() {
@@ -274,5 +304,7 @@ ArrayPropertyEdit::ArrayPropertyEdit()
vtypes+=Variant::get_type_name( Variant::Type(i) );
}
default_type=Variant::NIL;
-
+ subtype=Variant::NIL;
+ subtype_hint=PROPERTY_HINT_NONE;
+ subtype_hint_string="";
}