コード例 #1
0
        private void RefreshToNamedObject(NamedObjectSave namedObjectSave)
        {
            bool shouldShow = namedObjectSave != null;

            if (shouldShow)
            {
                shouldShow =
                    namedObjectSave.SourceClassType == "Polygon" ||
                    namedObjectSave.SourceClassType == "FlatRedBall.Math.Geometry.Polygon";
            }

            if (shouldShow)
            {
                var instructions = namedObjectSave.GetInstructionFromMember("Points");

                if (instructions == null)
                {
                    instructions        = new CustomVariableInNamedObject();
                    instructions.Member = "Points";
                    instructions.Value  = new List <Vector2>();

                    namedObjectSave.InstructionSaves.Add(instructions);
                }

                mPointEditWindow.Data = instructions.Value as List <Vector2>;

                ShowTab();
            }
            else
            {
                HideTab();
            }
        }
        private static AnimationChainListSave GetReferencedAclsThroughSetVariables(IElement element, NamedObjectSave referencedNos, StateSave stateSave)
        {
            AnimationChainListSave foundAcls = null;

            // Give states the priority
            if (stateSave != null)
            {
                foreach (var item in stateSave.InstructionSaves)
                {
                    var customVariable = element.CustomVariables.FirstOrDefault(variable => variable.Name == item.Member);

                    if (customVariable != null && customVariable.SourceObject == referencedNos.InstanceName && customVariable.SourceObjectProperty == "AnimationChains")
                    {
                        string value = (string)item.Value;

                        foundAcls = LoadAnimationChainListSave(element, value);
                    }
                }
            }

            if (foundAcls == null)
            {
                // Does this have a set AnimationChainList?
                foreach (CustomVariable customVariable in element.CustomVariables)
                {
                    if (customVariable.SourceObject == referencedNos.InstanceName && customVariable.SourceObjectProperty == "AnimationChains")
                    {
                        string value = (string)customVariable.DefaultValue;

                        foundAcls = LoadAnimationChainListSave(element, value);
                    }
                }
            }

            // If the acls is null that means that it hasn't been set by custom variables, but the NOS itself may have a value set right on the Sprite for the current AnimationChain
            if (foundAcls == null)
            {
                var instruction = referencedNos.GetInstructionFromMember("AnimationChains");
                if (instruction != null)
                {
                    foundAcls = LoadAnimationChainListSave(element, (string)instruction.Value);
                }
            }


            return(foundAcls);
        }
コード例 #3
0
        public void SetVariableOn(NamedObjectSave nos, string memberName, Type memberType, object value)
        {
            object oldValue = null;

            var instruction = nos.GetInstructionFromMember(memberName);

            if (instruction != null)
            {
                oldValue = instruction.Value;
            }
            NamedObjectPropertyGridDisplayer.SetVariableOn(nos, memberName, memberType, value);

            EditorObjects.IoC.Container.Get <NamedObjectSetVariableLogic>().ReactToNamedObjectChangedValue(
                memberName, nos.InstanceName, oldValue);


            PluginManager.ReactToChangedProperty(memberName, oldValue);
        }
コード例 #4
0
        private float GetTextureScale()
        {
            float           textureScale = 0;
            NamedObjectSave nos          = Instance as NamedObjectSave;

            var instruction = nos.GetInstructionFromMember("TextureScale");

            if (instruction != null && instruction.Value != null)
            {
                if (instruction.Value is int)
                {
                    textureScale = (float)((int)instruction.Value);
                }
                else
                {
                    textureScale = (float)instruction.Value;
                }
            }
            return(textureScale);
        }
コード例 #5
0
        public static CustomVariable GetCustomVariableFromNosOrElement(ElementRuntime elementRuntime, string variableName)
        {
            CustomVariable variable = elementRuntime.AssociatedIElement.GetCustomVariableRecursively(variableName);



            if (variable != null)
            {
                // The NOS may be overwriting the value from the element, so we need to set that if so:
                if (elementRuntime.AssociatedNamedObjectSave != null)
                {
                    NamedObjectSave nos = elementRuntime.AssociatedNamedObjectSave;

                    InstructionSave instruction = nos.GetInstructionFromMember(variable.Name);

                    if (instruction != null && instruction.Value != null)
                    {
                        variable = variable.Clone();
                        variable.DefaultValue = instruction.Value;
                    }
                }
            }
            return(variable);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }