Exemplo n.º 1
0
        private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container,
                                                           TypedMemberBase typedMember, AssetTypeInfo ati, VariableDefinition variableDefinition)
        {
            bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati);

            DataGridItem instanceMember = null;

            if (!shouldBeSkipped)
            {
                var typeConverter = PluginManager.GetTypeConverter(
                    container, instance, typedMember);

                bool isObjectInFile = typeConverter is IObjectsInFileConverter;

                var memberType = typedMember.MemberType;

                if (isObjectInFile)
                {
                    var fileInstanceMember = new FileInstanceMember();
                    instanceMember = fileInstanceMember;


                    fileInstanceMember.View += () =>
                    {
                        var rfs = (typeConverter as IObjectsInFileConverter).ReferencedFileSave;

                        if (rfs != null)
                        {
                            var value = fileInstanceMember.Value as string;

                            GlueCommands.Self.SelectCommands.Select(
                                rfs,
                                value);
                        }
                    };

                    instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox);
                }
                else
                {
                    instanceMember = new DataGridItem();
                }

                if (variableDefinition?.Name == "RotationZ" && variableDefinition.Type == "float")
                {
                    instanceMember.PreferredDisplayer = typeof(AngleSelectorDisplay);
                    instanceMember.PropertiesToSetOnDisplayer[nameof(AngleSelectorDisplay.TypeToPushToInstance)] =
                        AngleType.Radians;
                }

                instanceMember.FirstGridLength = new System.Windows.GridLength(140);

                instanceMember.UnmodifiedVariableName = typedMember.MemberName;
                string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName);
                instanceMember.DisplayName = displayName;

                instanceMember.TypeConverter = typeConverter;

                instanceMember.CustomRefreshOptions += () =>
                {
                    if (typeConverter != null)
                    {
                        instanceMember.CustomOptions.Clear();

                        var values = typeConverter.GetStandardValues();

                        foreach (var value in values)
                        {
                            instanceMember.CustomOptions.Add(value);
                        }
                    }
                };


                instanceMember.CustomGetTypeEvent += (throwaway) => memberType;


                instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null;



                instanceMember.CustomGetEvent += (throwaway) =>
                {
                    var instruction = instance.GetInstructionFromMember(typedMember.MemberName);

                    if (instruction == null)
                    {
                        if (variableDefinition != null)
                        {
                            var toReturn = variableDefinition.DefaultValue;
                            if (memberType == typeof(bool))
                            {
                                bool boolToReturn = false;

                                bool.TryParse(variableDefinition.DefaultValue, out boolToReturn);

                                return(boolToReturn);
                            }
                            else
                            {
                                return(toReturn);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(instruction.Value);
                    }
                };

                instanceMember.CustomSetEvent += (owner, value) =>
                {
                    NamedObjectVariableChangeLogic.ReactToValueSet(instance, typedMember, value, instanceMember, memberType);
                };

                instanceMember.IsDefaultSet += (owner, args) =>
                {
                    MakeDefault(instance, typedMember.MemberName);
                };

                instanceMember.SetValueError += (newValue) =>
                {
                    if (newValue is string && string.IsNullOrEmpty(newValue as string))
                    {
                        MakeDefault(instance, typedMember.MemberName);
                    }
                };

                instanceMember.ContextMenuEvents.Add("Tunnel Variable", (not, used) =>
                {
                    string variableToTunnel = null;
                    if (variableDefinition != null)
                    {
                        variableToTunnel = variableDefinition?.Name;
                    }
                    else if (typedMember != null)
                    {
                        variableToTunnel = typedMember.MemberName;
                    }
                    GlueCommands.Self.DialogCommands.ShowAddNewVariableDialog(
                        FlatRedBall.Glue.Controls.CustomVariableType.Tunneled,
                        instance.InstanceName,
                        variableToTunnel);
                });
            }
            return(instanceMember);
        }
Exemplo n.º 2
0
        private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container, TypedMemberBase typedMember, AssetTypeInfo ati)
        {
            bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati);

            DataGridItem instanceMember = null;

            if (!shouldBeSkipped)
            {
                var typeConverter = PluginManager.GetTypeConverter(
                    container, instance, typedMember);

                bool isObjectInFile = typeConverter is IObjectsInFileConverter;

                var memberType = typedMember.MemberType;

                VariableDefinition variableDefinition = null;

                if (ati != null)
                {
                    variableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == typedMember.MemberName);
                }

                if (isObjectInFile)
                {
                    var fileInstanceMember = new FileInstanceMember();
                    instanceMember = fileInstanceMember;


                    fileInstanceMember.View += () =>
                    {
                        var rfs = (typeConverter as IObjectsInFileConverter).ReferencedFileSave;

                        if (rfs != null)
                        {
                            var value = fileInstanceMember.Value as string;

                            GlueCommands.Self.SelectCommands.Select(
                                rfs,
                                value);
                        }
                    };

                    instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox);
                }
                else
                {
                    instanceMember = new DataGridItem();
                }

                instanceMember.FirstGridLength = new System.Windows.GridLength(140);

                instanceMember.UnmodifiedVariableName = typedMember.MemberName;
                string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName);
                instanceMember.DisplayName = displayName;

                instanceMember.TypeConverter = typeConverter;

                instanceMember.CustomRefreshOptions += () =>
                {
                    if (typeConverter != null)
                    {
                        instanceMember.CustomOptions.Clear();

                        var values = typeConverter.GetStandardValues();

                        foreach (var value in values)
                        {
                            instanceMember.CustomOptions.Add(value);
                        }
                    }
                };


                instanceMember.CustomGetTypeEvent += (throwaway) => memberType;


                instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null;



                instanceMember.CustomGetEvent += (throwaway) =>
                {
                    var instruction = instance.GetInstructionFromMember(typedMember.MemberName);

                    if (instruction == null)
                    {
                        if (variableDefinition != null)
                        {
                            var toReturn = variableDefinition.DefaultValue;
                            if (memberType == typeof(bool))
                            {
                                bool boolToReturn = false;

                                bool.TryParse(variableDefinition.DefaultValue, out boolToReturn);

                                return(boolToReturn);
                            }
                            else
                            {
                                return(toReturn);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(instruction.Value);
                    }
                };

                instanceMember.CustomSetEvent += (owner, value) =>
                {
                    NamedObjectVariableChangeLogic.ReactToValueSet(instance, typedMember, value, instanceMember, memberType);
                };

                instanceMember.IsDefaultSet += (owner, args) =>
                {
                    MakeDefault(instance, typedMember.MemberName);
                };

                instanceMember.SetValueError += (newValue) =>
                {
                    if (newValue is string && string.IsNullOrEmpty(newValue as string))
                    {
                        MakeDefault(instance, typedMember.MemberName);
                    }
                };
            }
            return(instanceMember);
        }