public override object GetValue(object component)
        {
            UrhoBackend.Serializable wrapper = component as UrhoBackend.Serializable;
            PropertyGridTypeHandler  handler = component as PropertyGridTypeHandler;

            if (handler != null && wrapper == null)
            {
                wrapper = handler.wrapper;
            }

            if (wrapper != null)
            {
                UrhoBackend.Variant var = wrapper.GetAttribute(attrName_);

                /*if (type_ == typeof(UrhoBackend.ResourceRefList))
                 *  return var.GetResourceRefList().ToList();
                 * else */if (attrInfo_.EnumNames != null && attrInfo_.EnumNames.Count > 0)
                {
                    return(attrInfo_.EnumNames[var.GetInt()]);
                }
                else if (type_ == typeof(UrhoBackend.Quaternion))
                {
                    return(var.GetQuaternion().ToEulerAngles());
                }
                else if (type_ == typeof(UrhoBackend.VariantMap))
                {
                    if (!source_.Equals(wrapper) || lastReturn_ == null)
                    {
                        source_     = wrapper;
                        lastReturn_ = VariantMapRecord.Get(wrapper, this, var.GetVariantMap());;
                        return(lastReturn_);
                    }
                    return(lastReturn_);
                }
                else if (type_ == typeof(UrhoBackend.VariantVector))
                {
                    return(VariantVectorRecord.From(var.GetVariantVector()));
                }
                return(VariantTranslate.ExtractFromVariant(var));
            }
            return(null);
        }
Esempio n. 2
0
        public static VariantMapList Get(object src, PropertyDescriptor desc, VariantMap map)
        {
            Scene scene = src as Scene;

            if (scene == null)
            {
                Node nd = src as Node;
                if (nd == null)
                {
                    UrhoBackend.Component cp = src as UrhoBackend.Component;
                    scene = cp.GetScene();
                }
                else
                {
                    scene = nd.GetScene();
                }
            }

            VariantMapList    keys     = new VariantMapList(desc, src);
            List <string>     varNames = new List <string>(Enum.GetNames(typeof(VariantType)));
            List <StringHash> hashes   = map.Keys();

            foreach (StringHash sh in hashes)
            {
                Variant          v     = map.Get(sh);
                string           value = v.ToString();
                VariantType      vt    = (VariantType)varNames.IndexOf(v.GetVarType());
                VariantMapRecord rec   = new VariantMapRecord(keys)
                {
                    ExplicitKey = sh, Type = (VariantType)v.GetVarTypeID(), Value = v.ToString()
                };
                if (scene != null)
                {
                    rec.Key = VariableUtils.GetVariableName(scene, rec.ExplicitKey);
                }
                rec.Enabled = true;
                keys.Add(rec);
            }
            return(keys);
        }
        public override object GetEditor(Type editorBaseType)
        {
            if (attrInfo_.EnumNames != null && attrInfo_.EnumNames.Count > 0)
            {
                List <int> enumValues = new List <int>();
                for (int i = 0; i < attrInfo_.EnumNames.Count; ++i)
                {
                    enumValues.Add(i);
                }
                return(new EditorCore.Controls.PropertyGrid.NamedEnumEditor(attrInfo_.EnumNames.ToArray()));
            }
            if (attrInfo_.Name.EndsWith("Mask"))
            {
                return(new EditorCore.Controls.PropertyGrid.MaskEditor());
            }
            if (type_ == typeof(bool))
            {
                return(new Sce.Atf.Controls.PropertyEditing.BoolEditor());
            }
            else if (type_ == typeof(int))
            {
                return(new Sce.Atf.Controls.PropertyEditing.NumericEditor(typeof(int)));
            }
            else if (type_ == typeof(float))
            {
                return(new Sce.Atf.Controls.PropertyEditing.NumericEditor(typeof(float)));
            }
            else if (type_ == typeof(UrhoBackend.Vector3))
            {
                return(new EditorCore.Controls.PropertyGrid.VectorEditor(typeof(UrhoBackend.Vector3), new[] { "X", "Y", "Z" }));
            }
            else if (type_ == typeof(UrhoBackend.Vector2))
            {
                return(new EditorCore.Controls.PropertyGrid.VectorEditor(typeof(UrhoBackend.Vector2), new[] { "X", "Y", "Z" }));
            }
            else if (type_ == typeof(UrhoBackend.Vector4))
            {
                return(new EditorCore.Controls.PropertyGrid.VectorEditor(typeof(UrhoBackend.Vector4), new[] { "X", "Y", "Z", "W" }));
            }
            else if (type_ == typeof(UrhoBackend.Color))
            {
                return new Sce.Atf.Controls.PropertyEditing.ColorPickerEditor {
                           EnableAlpha = true
                }
            }
            ;
            else if (type_ == typeof(UrhoBackend.ResourceRef))
            {
                return(new Sce.Atf.Controls.PropertyEditing.FileUriEditor(EditorCore.Interop.UrhoConstants.GetFilters(source_.GetAttributeDefault(attrName_).GetResourceRef())));
            }
            else if (type_ == typeof(UrhoBackend.VariantVector))
            {
            }
            else if (type_ == typeof(UrhoBackend.ResourceRefList))
            {
                return(new EditorCore.Controls.PropertyGrid.ResourceRefListEditor());
            }
            else if (type_ == typeof(UrhoBackend.VariantMap))
            {
                Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor editor = new Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor();
                editor.GetItemInsertersFunc = (context) =>
                {
                    Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor.ItemInserter inserter = new Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor.ItemInserter("Record", () =>
                    {
                        AttributePropertyDescriptor desc = context.Descriptor as AttributePropertyDescriptor;
                        VariantMapList list = desc.lastReturn_ as VariantMapList;
                        if (list == null)
                        {
                            return(null);
                        }
                        VariantMapRecord rec = new VariantMapRecord(list);
                        list.Add(rec);
                        rec.Enabled = true;
                        return(rec);
                    });
                    List <Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor.ItemInserter> ret = new List <Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor.ItemInserter>();
                    ret.Add(inserter);
                    return(ret);
                };

                editor.RemoveItemFunc = (context, obj) =>
                {
                    AttributePropertyDescriptor desc = context.Descriptor as AttributePropertyDescriptor;
                    VariantMapList list = desc.lastReturn_ as VariantMapList;
                    if (list == null)
                    {
                        return;
                    }
                    list.Remove(obj as VariantMapRecord);
                    UrhoBackend.VariantMap map = new UrhoBackend.VariantMap();
                    VariantMapRecord.Fill(map, list);
                    SetValue(context.LastSelectedObject, map);
                };

                return(editor);
            }
            else if (type_ == typeof(UrhoBackend.VariantVector))
            {
                Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor editor = new Sce.Atf.Controls.PropertyEditing.EmbeddedCollectionEditor();
                return(editor);
            }
            else if (type_ == typeof(UrhoBackend.Quaternion))
            {
                return(new EditorCore.Controls.PropertyGrid.VectorEditor(typeof(UrhoBackend.Vector3), new[] { "X", "Y", "Z" }));
            }
            return(base.GetEditor(editorBaseType));
        }
        public override void SetValue(object component, object value)
        {
            UrhoBackend.Serializable wrapper = component as UrhoBackend.Serializable;
            PropertyGridTypeHandler  handler = component as PropertyGridTypeHandler;

            if (handler != null && wrapper == null)
            {
                wrapper = handler.wrapper;
            }

            if (wrapper != null)
            {
                if (type_ == typeof(UrhoBackend.ResourceRef))
                {
                    UrhoBackend.ResourceRef newRef  = value as UrhoBackend.ResourceRef;
                    UrhoBackend.ResourceRef baseRef = wrapper.GetAttributeDefault(attrName_).GetResourceRef();
                    baseRef.SetResourceName(newRef.GetName());
                    wrapper.SetAttribute(attrName_, VariantTranslate.VariantFromObject(baseRef));
                }
                //else if (type_ == typeof(UrhoBackend.ResourceRefList))
                //{
                //    List<string> list = value as List<string>;
                //    if (list != null)
                //    {
                //        UrhoBackend.ResourceRefList baseList = wrapper.GetAttributeDefault(attrName_).GetResourceRefList();
                //        baseList.FromList(list);
                //        wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(baseList));
                //    }
                //}
                else if (attrInfo_.EnumNames != null && attrInfo_.EnumNames.Count > 0)
                {
                    int index = attrInfo_.EnumNames.IndexOf(value.ToString());
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(index));
                }
                else if (type_ == typeof(UrhoBackend.Quaternion))
                {
                    UrhoBackend.Vector3    vec3 = value as UrhoBackend.Vector3;
                    UrhoBackend.Quaternion quat = new UrhoBackend.Quaternion();
                    quat.FromEulerAngles(vec3.x, vec3.y, vec3.z);
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(quat));
                }
                else if (type_ == typeof(UrhoBackend.VariantMap))
                {
                    VariantMapList         records = lastReturn_ as VariantMapList; // value as VariantMapList;
                    UrhoBackend.VariantMap newMap  = new UrhoBackend.VariantMap();
                    VariantMapRecord.Fill(newMap, records);
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(newMap));
                    VariableUtils.SetVariableNames(wrapper, records);
                }
                else if (type_ == typeof(UrhoBackend.VariantVector))
                {
                    List <VariantVectorRecord> records = value as List <VariantVectorRecord>;
                    UrhoBackend.VariantVector  newVec  = new UrhoBackend.VariantVector();
                    VariantVectorRecord.To(newVec, records);
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(newVec));
                }
                else
                {
                    wrapper.SetAttribute(attrName_, VariantTranslate.VariantFromObject(value));
                }
            }
            //\todo
        }