コード例 #1
0
        public static bool GetIsListCsv(this CustomVariable customVariable)
        {
            if (customVariable.GetIsCsv())
            {
                string             fullFileName = FacadeContainer.Self.ProjectValues.ContentDirectory + customVariable.Type;
                ReferencedFileSave foundRfs     = ObjectFinder.Self.GetReferencedFileSaveFromFile(fullFileName);

                if (foundRfs != null)
                {
                    return(foundRfs.CreatesDictionary == false);
                }
            }

            return(false);
        }
コード例 #2
0
        private static void HandleIsSharedVariableSet(CustomVariable customVariable, object oldValue)
        {
            // July 11, 2011
            // We used to loop
            // through all derived
            // elements and set all
            // variables with the same
            // name to be IsShared as well,
            // however, this is bad because now
            // we discourage same-named variables
            // that are not SetByDerived. 
            //if (EditorLogic.CurrentEntitySave != null)
            //{
            //    List<EntitySave> derivedEntities = ObjectFinder.Self.GetAllEntitiesThatInheritFrom(
            //        EditorLogic.CurrentEntitySave.Name);
            //    foreach (EntitySave entity in derivedEntities)
            //    {
            //        foreach (CustomVariable cv in entity.CustomVariables)
            //        {
            //            if (cv.Name == customVariable.Name)
            //            {
            //                cv.IsShared = customVariable.IsShared;
            //            }
            //        }
            //    }
            //}
            bool didErrorOccur = false;
            if (customVariable.SetByDerived && customVariable.IsShared)
            {
                MessageBox.Show("Variables which are SetByDerived cannot be IsShared");
                didErrorOccur = true;
            }

            if (didErrorOccur)
            {
                customVariable.IsShared = (bool)oldValue;
            }

            if (!didErrorOccur)
            {

                if (customVariable.IsShared && customVariable.GetIsCsv())
                {
                    MessageBox.Show("Shared CSV variables are not assigned until either an instance of this object is created, or until LoadStaticContent is called.  Until then, the variable will equal null");

                }
            }
        }
コード例 #3
0
        private void DefaultValueIncludeActivity(CustomVariable instance)
        {

            bool handled = false;

            if (instance.GetIsCsv())
            {
                if (instance.GetIsListCsv())
                {
                    handled = true;
                    var member = IncludeMember("Set CreatesDictionary to true to assign value", typeof(string),
                        (object sender, MemberChangeArgs args) => { },
                        () => { return null; },


                        null,
                        // Let's put this in the variables list
                        new Attribute[] { new CategoryAttribute("\t") });
                    member.IsReadOnly = true;
                }
            }


            if (!handled)
            {
                Type typeToPass = instance.GetRuntimeType();
                if (typeToPass == null)
                {
                    typeToPass = typeof(string);
                }

                var typeConverter =
                    instance.GetTypeConverter(CurrentElement);

                IncludeMember(
                    "DefaultValue",
                    typeToPass,
                    OnMemberChanged,
                    instance.GetValue,
                    typeConverter,
                    new Attribute[] { new CategoryAttribute("\t") });
            }
            else
            {
                ExcludeMember("DefaultValue");
            }
        }
コード例 #4
0
        /// <summary>
        /// This method populates the mCustomVariables list with default valued variables.  These can later get set in SetCustomVariable, but they need to exist so that 
        /// plugins like the script parser know whether something is a custom variable or not.
        /// </summary>
        /// <param name="cv">The variable to evaluate and add if it is a custom variable.</param>
        private void CreateCustomVariableContainer(CustomVariable cv)
        {
            bool isCustomVariable = true;

            if(!string.IsNullOrEmpty(cv.SourceObject))
            {
                isCustomVariable = false;
            }

            if (isCustomVariable)
            {

                Type positionedObjectType = typeof(PositionedObject);

                PropertyInfo property = positionedObjectType.GetProperty(cv.Name);
                FieldInfo field = positionedObjectType.GetField(cv.Name);
                if (property != null || field != null)
                {
                    isCustomVariable = false;
                }
            }

            if (isCustomVariable)
            {
                EntitySave baseEntitySave = ObjectFinder.Self.GetEntitySave(this.AssociatedIElement.BaseElement);

                if (baseEntitySave != null && baseEntitySave.GetCustomVariable(cv.Name) != null)
                {
                    isCustomVariable = false;
                }
            }

            if (isCustomVariable)
            {
                object defaultValue = null;
                if (cv.GetIsFile())
                {
                    defaultValue = null;
                }
                    
                else if (cv.GetIsCsv())
                {
                    defaultValue = null;
                }
                else if (cv.GetIsVariableState())
                {
                    defaultValue = null;
                }
                else
                {
                    try
                    {
                        defaultValue = TypeManager.GetDefaultForTypeAsType(cv.Type);
                    }
                    catch
                    {
                        throw new Exception("Could not get the default value for variable " + cv);
                    }
                }

                mCustomVariables.Add(new PropertyValuePair(cv.Name, defaultValue));

            }
        }
コード例 #5
0
        public static TypeConverter GetTypeConverter(this CustomVariable customVariable, IElement containingElement, StateSave stateSave, FlatRedBall.Glue.Plugins.ExportedInterfaces.IGlueState glueState)
        {
            TypeConverter typeConverter = null;

            if (customVariable.GetIsVariableState())
            {
                typeConverter = new AvailableStates(
                    FacadeContainer.Self.GlueState.CurrentNamedObjectSave,
                    FacadeContainer.Self.GlueState.CurrentElement,
                    FacadeContainer.Self.GlueState.CurrentCustomVariable,
                    FacadeContainer.Self.GlueState.CurrentStateSave
                    );
            }
            else
            {
                Type runtimeType = customVariable.GetRuntimeType();

                if (runtimeType != null)
                {
                    if (runtimeType.IsEnum)
                    {
                        typeConverter = new EnumConverter(runtimeType);
                    }
                    else if (runtimeType == typeof(Color))
                    {
                        return(new AvailableColorTypeConverter());
                    }

                    else if ((runtimeType == typeof(string) || runtimeType == typeof(AnimationChainList)) &&
                             customVariable.SourceObjectProperty == "CurrentChainName")
                    {
                        typeConverter = new AvailableAnimationChainsStringConverter(customVariable, stateSave);
                    }
                    else if (customVariable.GetIsFile())
                    {
                        AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement);
                        converter.QualifiedRuntimeTypeName = runtimeType.FullName;
                        converter.ShowNewFileOption        = false;
                        converter.RemovePathAndExtension   = true;
                        typeConverter = converter;
                    }
                }
                else if (customVariable.GetIsCsv())
                {
                    if (FacadeContainer.Self.ProjectValues == null)
                    {
                        throw new NullReferenceException("The ProjectValues property in FAcadeContainer.Self.ProjectValues must be set before trying to get the CSV type converter for the variable " + customVariable.ToString());
                    }

                    ReferencedFileSave rfs = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item =>
                                                                                                      item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == customVariable.Type);

                    AvailableSpreadsheetValueTypeConverter converter = null;
                    if (rfs != null)
                    {
                        converter = new AvailableSpreadsheetValueTypeConverter(
                            FacadeContainer.Self.ProjectValues.ContentDirectory + rfs.Name, containingElement);
                    }
                    else
                    {
                        converter = new AvailableSpreadsheetValueTypeConverter(
                            FacadeContainer.Self.ProjectValues.ContentDirectory + customVariable.Type, containingElement);
                    }
                    converter.ShouldAppendFileName = true;

                    typeConverter = converter;
                }
                else if (customVariable.GetIsFile())
                {
                    // If we got here, that means that the
                    // CustomVariable is a file, but it doesn't
                    // have a System.Type, so it only knows its runtime
                    // type;
                    AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement);
                    converter.UnqualifiedRuntimeTypeName = customVariable.Type;
                    converter.ShowNewFileOption          = false;
                    converter.RemovePathAndExtension     = true;
                    typeConverter = converter;
                }
            }


            return(typeConverter);
        }
コード例 #6
0
        public static ICodeBlock AppendAssignmentForCustomVariableInElement(ICodeBlock codeBlock, CustomVariable customVariable, IElement saveObject)
        {
            bool hasBase = !string.IsNullOrEmpty(((INamedObjectContainer)saveObject).BaseObject);

            // Victor Chelaru
            // December 17, 2014
            // We used to not go into
            // this if statement if SetByDerived
            // was true, but actually since variables
            // are set bottom-up, there's really no reason
            // to set it only on the derived, because the base
            // will always get assigned first, then the derived
            // can override it.
            //if (!customVariable.SetByDerived && 
            if (customVariable.DefaultValue != null && // if it's null the user doesn't want to change what is set in the file or in the source object
                !customVariable.IsShared && // no need to handle statics here because they're always defined in class scope
                !IsVariableTunnelingToDisabledObject(customVariable, saveObject)
                )
            {


                string variableToAssign = "";

                CustomVariable variableConsideringDefinedByBase = customVariable.GetDefiningCustomVariable();

                IElement containerOfState = null;

                // This can be null
                // if the user takes
                // an Element that inherits
                // from another and has variables
                // from it, then changes the Element
                // to no longer inherit.

                if (variableConsideringDefinedByBase != null)
                {

                    containerOfState = BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(variableConsideringDefinedByBase, saveObject);

                    if (containerOfState == null)
                    {
                        variableToAssign =
                            CodeParser.ParseObjectValue(customVariable.DefaultValue);
                        NamedObjectSave namedObject = saveObject.GetNamedObject(customVariable.SourceObject);


                        if (customVariable.GetIsFile())
                        {
                            variableToAssign = variableToAssign.Replace("\"", "").Replace("-", "_");

                            if (variableToAssign == "<NONE>")
                            {
                                variableToAssign = "null";
                            }
                        }
                        else if (customVariable != null && customVariable.GetIsCsv())
                        {
                            if (ShouldAssignToCsv(customVariable, variableToAssign))
                            {
                                variableToAssign = GetAssignmentToCsvItem(customVariable, saveObject, variableToAssign);
                            }
                            else
                            {
                                variableToAssign = null;
                            }
                        }
                        else if (customVariable.Type == "Color")
                        {
                            variableToAssign = "Color." + variableToAssign.Replace("\"", "");

                        }
                        else if (customVariable.Type != "string" && variableToAssign == "\"\"")
                        {
                            variableToAssign = null;
                        }
                        else
                        {

                            //Not sure why this wasn't localizing variables but it caused a problem with 
                            //variables that tunnel in to a Text's DisplayText not being localized
                            //finish here

                            // Special Case:
                            // We don't want to
                            // set Visible on NOS's
                            // which are added/removed
                            // when Visible is set on them:
                            // Update March 7, 2014 
                            // We do want to set it because if we don't,
                            // then the checks inside the Visible property
                            // don't properly detect that they've been changed.
                            // Therefore, we're going to set it on the underlying
                            // object 
                            bool shouldSetUnderlyingValue = namedObject != null && namedObject.RemoveFromManagersWhenInvisible &&
                                customVariable.SourceObjectProperty == "Visible";

                            if (shouldSetUnderlyingValue)
                            {
                                // Don't change the variable to assign
                            }
                            else
                            {
                                variableToAssign = CodeWriter.MakeLocalizedIfNecessary(namedObject, customVariable.SourceObjectProperty,
                                    customVariable.DefaultValue, variableToAssign, null);
                                variableToAssign = variableToAssign.Replace("+", ".");
                            }
                        }
                    }
                    else
                    {
                        string valueAsString = (string)customVariable.DefaultValue;

                        if (!string.IsNullOrEmpty(valueAsString))
                        {
                            variableToAssign = StateCodeGenerator.FullyQualifyStateValue(containerOfState, (string)customVariable.DefaultValue, customVariable.Type);
                        }
                    }

                    if (!string.IsNullOrEmpty(variableToAssign))
                    {
                        string relativeVersionOfProperty = InstructionManager.GetRelativeForAbsolute(customVariable.Name);
                        if (!string.IsNullOrEmpty(relativeVersionOfProperty))
                        {
                            codeBlock = codeBlock.If("Parent == null");
                        }

                        NamedObjectSave namedObject = saveObject.GetNamedObject(customVariable.SourceObject);

                        bool shouldSetUnderlyingValue = namedObject != null && namedObject.RemoveFromManagersWhenInvisible &&
                            customVariable.SourceObjectProperty == "Visible";

                        if (namedObject != null)
                        {
                            NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, namedObject);
                        }

                        if (shouldSetUnderlyingValue)
                        {
                            codeBlock.Line(StringHelper.SpaceStrings(namedObject.InstanceName + "." + customVariable.SourceObjectProperty + " = ", variableToAssign + ";"));

                        }
                        else
                        {
                            codeBlock.Line(StringHelper.SpaceStrings(customVariable.Name, "=", variableToAssign + ";"));

                        }


                        if (!string.IsNullOrEmpty(relativeVersionOfProperty))
                        {
                            if (customVariable.Name == "Z")
                            {
                                codeBlock = codeBlock.End().ElseIf("Parent is FlatRedBall.Camera");
                                codeBlock.Line(relativeVersionOfProperty + " = " + variableToAssign + " - 40.0f;");
                            }
                            codeBlock = codeBlock.End().Else();
                            codeBlock.Line(relativeVersionOfProperty + " = " + variableToAssign + ";");
                            codeBlock = codeBlock.End();
                        }
                        

                        if (namedObject != null)
                        {
                            NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, namedObject);
                        }




                    }
                }
            }

            return codeBlock;
        }
コード例 #7
0
        static bool ReferencesCsvFromGlobalContent(CustomVariable customVariable)
        {
            if (customVariable.GetIsCsv() == false)
            {
                return false;
            }
            else
            {

                return customVariable.Type.StartsWith("GlobalContent/");
            }
        }