Exemple #1
0
        public static bool GetIsScalableEntity(this NamedObjectSave instance)
        {
            if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType))
            {
                EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                return(entitySave.GetCustomVariableRecursively("ScaleX") != null && entitySave.GetCustomVariableRecursively("ScaleY") != null);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Returns the value of a variable either set in the NamedObjectSave (if it is set there) or in the underlying Entity if not
        /// </summary>
        /// <param name="instance">The NamedObjectSave to get the variable from.</param>
        /// <param name="variableName">The name of the variable, such as "ScaleX"</param>
        /// <returns>The value of the variable in either the NamedObjectSave or underlying Entity.  Returns null if varible isn't found.</returns>
        public static object GetEffectiveValue(this NamedObjectSave instance, string variableName)
        {
            CustomVariableInNamedObject cvino = instance.GetCustomVariable(variableName);

            if (cvino == null || cvino.Value == null)
            {
                if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType))
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                    if (entitySave != null)
                    {
                        CustomVariable variable = entitySave.GetCustomVariableRecursively(variableName);

                        if (variable != null)
                        {
                            return(variable.DefaultValue);
                        }
                    }
                }
            }
            else
            {
                return(cvino.Value);
            }
            return(null);
        }
        private static void AskToPreserveVariables(EntitySave entitySave, List<CustomVariable> variablesBefore)
        {
            foreach (CustomVariable oldVariable in variablesBefore)
            {
                if (entitySave.GetCustomVariableRecursively(oldVariable.Name) == null)
                {
                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    string message = "The variable\n\n" + oldVariable.ToString() + "\n\nIs no longer part of the Entity.  What do you want to do?";

                    mbmb.MessageText = message;

                    mbmb.AddButton("Add a new variable with the same name and type to " + entitySave.Name, DialogResult.Yes);
                    mbmb.AddButton("Nothing - the variable will go away", DialogResult.No);

                    DialogResult result = mbmb.ShowDialog();

                    if (result == DialogResult.Yes)
                    {
                        CustomVariable newVariable = new CustomVariable();
                        newVariable.Type = oldVariable.Type;
                        newVariable.Name = oldVariable.Name;
                        newVariable.DefaultValue = oldVariable.DefaultValue;
                        newVariable.SourceObject = oldVariable.SourceObject;
                        newVariable.SourceObjectProperty = oldVariable.SourceObjectProperty;

                        newVariable.Properties = new List<PropertySave>();
                        newVariable.Properties.AddRange(oldVariable.Properties);

                        newVariable.HasAccompanyingVelocityProperty = oldVariable.HasAccompanyingVelocityProperty;
                        newVariable.CreatesEvent = oldVariable.CreatesEvent;
                        newVariable.IsShared = oldVariable.IsShared;

                        if (!string.IsNullOrEmpty(oldVariable.OverridingPropertyType))
                        {
                            newVariable.OverridingPropertyType = oldVariable.OverridingPropertyType;
                            newVariable.TypeConverter = oldVariable.TypeConverter;
                        }

                        newVariable.CreatesEvent = oldVariable.CreatesEvent;

                        entitySave.CustomVariables.Add(newVariable);

                    }

                }
            }
        }