private void AdjustCircle(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("Radius", 16f); } }
private void AdjustSpriteFrame(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("PixelSize", .5f); } }
void AdjustNewNamedObject(NamedObjectSave nos) { IElement element = EditorLogic.CurrentElement; if (element != null) { if (nos.SourceType == SourceType.FlatRedBallType) { switch (nos.SourceClassType) { case "Sprite": AdjustSprite(nos, element); break; case "Circle": AdjustCircle(nos, element); break; case "SpriteFrame": AdjustSpriteFrame(nos, element); break; case "AxisAlignedRectangle": AdjustAxisAlignedRectangle(nos, element); break; case "Layer": AdjustLayer(nos, element); break; } } } }
private void AdjustLayer(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.Is2D = true; } }
private static bool CheckForMissingTunnelReferences(IElement asIElement) { bool errorFound = false; foreach (CustomVariable variable in asIElement.CustomVariables) { if (!string.IsNullOrEmpty(variable.SourceObject)) { NamedObjectSave nos = asIElement.GetNamedObjectRecursively(variable.SourceObject); if (nos == null) { errorFound = true; MessageBox.Show("The variable " + variable.Name + " references " + variable.SourceObject + " but " + "this object doesn't exist."); } else { List <string> availableMembers = ExposedVariableManager.GetExposableMembersFor(nos).Select(item => item.Member).ToList(); if (!availableMembers.Contains(variable.SourceObjectProperty)) { errorFound = true; MessageBox.Show("The variable " + variable.Name + " references the property " + variable.SourceObjectProperty + "in " + asIElement.ToString() + " which does not exist."); } } } } return(errorFound); }
private static void AddSpriteValues(NamedObjectSave newNos, bool is2D) { // whatToAdd = new AxisAlignedRectangle(); CustomVariableInNamedObject scaleX = GetOrCreateInstruction(newNos, "ScaleX"); scaleX.Type = "Single"; CustomVariableInNamedObject scaleY = GetOrCreateInstruction(newNos, "ScaleY"); scaleY.Type = "Single"; if (is2D) { scaleX.Value = 16.0f; scaleY.Value = 16.0f; CustomVariableInNamedObject pixelSize = GetOrCreateInstruction(newNos, "PixelSize"); pixelSize.Type = "Single"; } else { scaleX.Value = 1.0f; scaleY.Value = 1.0f; } }
private void CreateEntitySaves() { mEntitySave = new EntitySave(); mEntitySave.Name = "StateTestEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); CreateNamedObjectWithSetVariable(); CreateEntityVariables(); CreateEntitySaveState(); mContainer = new EntitySave(); mContainer.Name = "StateTestContainerEntity"; NamedObjectSave nos = new NamedObjectSave(); nos.InstanceName = mEntitySave.Name + "Instance"; nos.SourceType = SourceType.Entity; nos.SourceClassType = mEntitySave.Name; mContainer.NamedObjects.Add(nos); CustomVariable stateTunnel = new CustomVariable(); stateTunnel.SourceObject = nos.InstanceName; stateTunnel.SourceObjectProperty = "CurrentState"; stateTunnel.Type = "VariableState"; stateTunnel.Name = "StateTunnelVariable"; mContainer.CustomVariables.Add(stateTunnel); CreateContainerEntityState(); }
internal string GetAddToManagersFunc(IElement glueElement, NamedObjectSave namedObjectSave, ReferencedFileSave referencedFileSave, string layerName) { var stringBuilder = new StringBuilder(); var namedObjectName = namedObjectSave.FieldName; string layerCode = "null"; if (!string.IsNullOrEmpty(layerName)) { layerCode = $"System.Linq.Enumerable.FirstOrDefault(FlatRedBall.Gum.GumIdb.AllGumLayersOnFrbLayer({layerName}))"; } if (glueElement is EntitySave) { stringBuilder.AppendLine("{"); stringBuilder.AppendLine($"{namedObjectName}.AddToManagers(RenderingLibrary.SystemManagers.Default, {layerCode});"); var shouldGenerateWrapper = namedObjectSave.AttachToContainer; if (shouldGenerateWrapper) { stringBuilder.AppendLine($"var wrapperForAttachment = new GumCoreShared.FlatRedBall.Embedded.PositionedObjectGueWrapper(this, {namedObjectName});"); stringBuilder.AppendLine("FlatRedBall.SpriteManager.AddPositionedObject(wrapperForAttachment);"); stringBuilder.AppendLine("gumAttachmentWrappers.Add(wrapperForAttachment);"); } stringBuilder.AppendLine("}"); } else { stringBuilder.AppendLine($"{namedObjectName}.AddToManagers(RenderingLibrary.SystemManagers.Default, {layerCode});"); } return(stringBuilder.ToString()); }
private void CreateEntitySave() { mEntitySave = ExposedVariableTests.CreateEntitySaveWithStates("CustomVariableEntity"); mExposedStateInCategoryVariable = new CustomVariable(); mExposedStateInCategoryVariable.Name = "CurrentStateCategoryState"; mExposedStateInCategoryVariable.Type = "StateCategory"; mExposedStateInCategoryVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(mExposedStateInCategoryVariable); mSetByDerivedVariable = new CustomVariable(); mSetByDerivedVariable.Type = "float"; mSetByDerivedVariable.Name = "SomeVariable"; mSetByDerivedVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(mSetByDerivedVariable); mTextInBase = new NamedObjectSave(); mTextInBase.InstanceName = "TextObject"; mTextInBase.SourceType = SourceType.FlatRedBallType; mTextInBase.SourceClassType = "Text"; mEntitySave.NamedObjects.Add(mTextInBase); CustomVariable customVariable = new CustomVariable(); customVariable.Name = "TunneledDisplayText"; customVariable.SourceObject = mTextInBase.InstanceName; customVariable.SourceObjectProperty = "DisplayText"; customVariable.Type = "string"; customVariable.OverridingPropertyType = "int"; mEntitySave.CustomVariables.Add(customVariable); ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); }
private void CreateContainerEntitySave() { mContainerEntitySave = new EntitySave(); mContainerEntitySave.Name = "ContainerCustomVariableEntity"; mBaseNosInContainer = new NamedObjectSave(); mBaseNosInContainer.InstanceName = mEntitySave.Name + "Instance"; mBaseNosInContainer.SourceType = SourceType.Entity; mBaseNosInContainer.SourceClassType = mEntitySave.Name; mContainerEntitySave.NamedObjects.Add(mBaseNosInContainer); CustomVariable customVariable = new CustomVariable(); customVariable.Name = "TunneledCategorizedStateVariable"; customVariable.SourceObject = mBaseNosInContainer.InstanceName; customVariable.SourceObjectProperty = "CurrentStateCategoryState"; customVariable.Type = "StateCategory"; mContainerEntitySave.CustomVariables.Add(customVariable); mDerivedNosInContainer = new NamedObjectSave(); mDerivedNosInContainer.InstanceName = "DerivedNosInContainer"; mDerivedNosInContainer.SourceType = SourceType.Entity; mDerivedNosInContainer.SourceClassType = mDerivedEntitySave.Name; mDerivedNosInContainer.UpdateCustomProperties(); mContainerEntitySave.NamedObjects.Add(mDerivedNosInContainer); ObjectFinder.Self.GlueProject.Entities.Add(mContainerEntitySave); }
private void ReactToFontSet(NamedObjectSave namedObjectSave, object oldValue) { string value = namedObjectSave.GetCustomVariable("Font").Value as string; if (!string.IsNullOrEmpty(value)) { IElement element = EditorLogic.CurrentElement; ReferencedFileSave referencedFileSave = element.GetReferencedFileSaveByInstanceNameRecursively(value); if (referencedFileSave != null) { string file = referencedFileSave.GetRelativePath(); file = ProjectManager.MakeAbsolute(file, true); string contents = FileManager.FromFileText(file); int size = StringFunctions.GetIntAfter( "size=", contents); float lineHeightInPixels = StringFunctions.GetIntAfter( "lineHeight=", contents); lineHeightInPixels /= 2.0f; namedObjectSave.SetPropertyValue("Scale", (float)lineHeightInPixels); namedObjectSave.SetPropertyValue("Spacing", (float)lineHeightInPixels); namedObjectSave.SetPropertyValue("NewLineDistance", (float)(lineHeightInPixels * 1.5f)); } } }
public void ReactToNewFile(ReferencedFileSave newFile) { if (FileManager.GetExtension(newFile.Name) == "scnx") { DialogResult result = MessageBox.Show("Make an object for " + "the entire scene?", "Make object?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { NamedObjectSave namedObjectSave = new NamedObjectSave(); namedObjectSave.InstanceName = "EntireSceneInstance"; namedObjectSave.AddToManagers = true; namedObjectSave.SourceType = SourceType.File; namedObjectSave.SourceFile = newFile.Name; namedObjectSave.SourceName = "Entire File (Scene)"; EditorLogic.CurrentElement.NamedObjects.Add(namedObjectSave); GlueCommands.RefreshCommands.RefreshUiForSelectedElement(); GlueCommands.GluxCommands.SaveGlux(); } } }
void CreateContainerElementRuntime() { EntitySave containerEntitySave = new EntitySave { Name = "ContainerVariableSetting" }; ObjectFinder.Self.GlueProject.Entities.Add(containerEntitySave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.InstanceName = mEntitySave.Name + "Instance"; nos.SourceClassType = mEntitySave.Name; containerEntitySave.NamedObjects.Add(nos); nos.UpdateCustomProperties(); nos.SetPropertyValue("CurrentStateSaveCategoryState", "SecondState"); mContainedElementRuntime = new ElementRuntime(containerEntitySave, null, null, null, null); // This thing is attached - we need to check its relativeX //if (mContainedElementRuntime.ContainedElements[0].X != -10.0f) if (mContainedElementRuntime.ContainedElements[0].RelativeX != -10.0f) { throw new Exception("Categorized states on contained NamedObjectSave Elements aren't setting values properly"); } }
private void AdjustSprite(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("TextureScale", 1.0f); } }
private static NamedObjectSave HandleAddShape(string message, string sourceClassType) { NamedObjectSave toReturn = null; var tiw = new TextInputWindow(); tiw.Message = message; var dialogResult = tiw.ShowDialog(); if (dialogResult == DialogResult.OK) { string whyItIsntValid; NameVerifier.IsNamedObjectNameValid(tiw.Result, out whyItIsntValid); if (!string.IsNullOrEmpty(whyItIsntValid)) { GlueCommands.Self.DialogCommands.ShowMessageBox(whyItIsntValid); } else { var viewModel = new AddObjectViewModel(); viewModel.ObjectName = tiw.Result; viewModel.SourceType = SaveClasses.SourceType.FlatRedBallType; viewModel.SourceClassType = sourceClassType; toReturn = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement(viewModel); GlueState.Self.CurrentNamedObjectSave = toReturn; } } return(toReturn); }
public NamedObjectSave ShowAddNewObjectDialog(AddObjectViewModel addObjectViewModel = null) { NamedObjectSave newNamedObject = null; // add named object, add object, addnamedobject, add new object, addnewobject, createobject, addobject addObjectViewModel = CreateAndShowAddNamedObjectWindow(addObjectViewModel); if (addObjectViewModel.DialogResult == DialogResult.OK) { string whyItIsntValid = null; bool isValid = NameVerifier.IsNamedObjectNameValid(addObjectViewModel.ObjectName, out whyItIsntValid); if (isValid) { if (addObjectViewModel.SourceType == SourceType.Entity && !RecursionManager.Self.CanContainInstanceOf(GlueState.Self.CurrentElement, addObjectViewModel.SourceClassType)) { isValid = false; whyItIsntValid = "This type would result in infinite recursion"; } } if (isValid) { newNamedObject = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentNamedObjectSave = newNamedObject; } else { GlueGui.ShowMessageBox(whyItIsntValid); } } return(newNamedObject); }
public static void SetVariableOn(NamedObjectSave nos, string memberName, Type memberType, object value) { bool shouldConvertValue = false; if (memberType != null && value is string && memberType != typeof(Microsoft.Xna.Framework.Color) && !CustomVariableExtensionMethods.GetIsFile(memberType) && // If it's a file, we just want to set the string value and have the underlying system do the loading !CustomVariableExtensionMethods.GetIsObjectType(memberType.FullName) ) { bool isCsv = NamedObjectPropertyGridDisplayer.GetIfIsCsv(nos, memberName); shouldConvertValue = !isCsv && memberType != typeof(object) && // variable could be an object memberType != typeof(PositionedObject); // If the MemberType is object, then it's something we can't convert to - it's likely a state } if (shouldConvertValue) { value = PropertyValuePair.ConvertStringToType((string)value, memberType); } nos.SetPropertyValue(memberName, value); }
private bool DetermineIfShouldShowStates(NamedObjectSave instance) { IElement referencedEntitySave = instance.GetReferencedElement(); bool shouldRemove = referencedEntitySave == null; if (referencedEntitySave != null) { shouldRemove = true; IElement element = referencedEntitySave; while (element != null) { if (element.States.Count != 0) { shouldRemove = false; break; } else { element = ObjectFinder.Self.GetIElement(element.BaseElement); } } } return(!shouldRemove); }
private NamedObjectSave CreateCollisionNamedObject(bool isCircle, bool isRectangle) { NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; if (isCircle) { nos.SourceClassType = "Circle"; nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "Radius", Value = TileWidth / 2.0f }); } else if (isRectangle) { nos.SourceClassType = "AxisAlignedRectangle"; nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "Width", Value = (float)TileWidth }); nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "Height", Value = (float)TileHeight }); } nos.InstanceName = "Collision"; nos.HasPublicProperty = true; return(nos); }
private void CreateContainerEntitySave() { mEntitySaveInstance = new NamedObjectSave(); mEntitySaveInstance.InstanceName = "StateEntityInstance"; mEntitySaveInstance.SourceType = SourceType.Entity; mEntitySaveInstance.SourceClassType = mEntitySave.Name; mDerivedSaveInstance = new NamedObjectSave(); mDerivedSaveInstance.InstanceName = "StateDerivedEntityInstance"; mDerivedSaveInstance.SourceType = SourceType.Entity; mDerivedSaveInstance.SourceClassType = mDerivedEntitySave.Name; mContainerEntitySave = new EntitySave(); mContainerEntitySave.Name = "StateEntityContainer"; mContainerEntitySave.NamedObjects.Add(mEntitySaveInstance); mContainerEntitySave.NamedObjects.Add(mDerivedSaveInstance); mTunneledUncategorizedStateInContainer = new CustomVariable(); mTunneledUncategorizedStateInContainer.Name = "TunneledUncategorizedStateVariable"; mTunneledUncategorizedStateInContainer.SourceObject = mEntitySaveInstance.InstanceName; mTunneledUncategorizedStateInContainer.SourceObjectProperty = mRenamedExposedUncategorizedStateVariable.Name; mContainerEntitySave.CustomVariables.Add(mTunneledUncategorizedStateInContainer); ObjectFinder.Self.GlueProject.Entities.Add(mContainerEntitySave); }
private object CreateObjectBasedOnExtension(NamedObjectSave objectToLoad, IElement elementSave, Layer layerToPutOn, PositionedObjectList <ElementRuntime> listToPopulate, string extension) { object returnObject = null; switch (extension) { case "scnx": returnObject = NamedObjectManager.LoadObjectForNos <Scene>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this); break; case "shcx": returnObject = NamedObjectManager.LoadObjectForNos <ShapeCollection>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this); break; case "nntx": //returnObject = NamedObjectManager.LoadNodeNetworkObject(objectToLoad, elementSave, layerToPutOn, listToPopulate, entireFileOnly); break; case "emix": returnObject = NamedObjectManager.LoadObjectForNos <EmitterList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this); break; case "splx": returnObject = NamedObjectManager.LoadObjectForNos <SplineList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this); break; } return(returnObject); }
private Graphics.Layer GetLayerForNos(Layer layerProvidedByContainer, NamedObjectSave n) { Layer layerToPutOn = layerProvidedByContainer; // If the NOS specifies its own Layer, handle that: if (!string.IsNullOrEmpty(n.LayerOn)) { if (n.LayerOn == "Under Everything (Engine Layer)") { layerToPutOn = SpriteManager.UnderAllDrawnLayer; } else if (n.LayerOn == "Top Layer (Engine Layer)") { layerToPutOn = SpriteManager.TopLayer; } else { ElementRuntime layerContainer = GetContainedElementRuntime(n.LayerOn); if (layerContainer != null) { layerToPutOn = ((Layer)layerContainer.mDirectObjectReference); } } } return(layerToPutOn); }
private static void AddExistingNamedObjectToElement(IElement element, NamedObjectSave newNamedObject) { element.NamedObjects.Add(newNamedObject); GlueCommands.Self.RefreshCommands.RefreshUi(element); PluginManager.ReactToNewObject(newNamedObject); GlueCommands.Self.GenerateCodeCommands.GenerateElementCodeTask(element); }
public static string GetSecondGenericType(NamedObjectSave collisionRelationship, out bool isList) { var secondName = collisionRelationship.Properties.GetValue <string>(nameof(CollisionRelationshipViewModel.SecondCollisionName)); var container = collisionRelationship.GetContainer(); string secondType = null; isList = false; if (container != null) { var secondObject = container.GetNamedObject(secondName); isList = secondObject?.IsList == true; if (secondObject != null) { if (secondObject.IsList) { secondType = secondObject.SourceClassGenericType?.Replace("\\", "."); } else { secondType = NamedObjectSaveCodeGenerator.GetQualifiedTypeName(secondObject); } } } return(secondType); }
private bool HandleDropOnShapeCollection(TreeNode treeNodeMoving, TreeNode targetNode, NamedObjectSave targetNos, NamedObjectSave movingNos) { bool succeeded = true; if (movingNos.CanBeInShapeCollection() == false) { MessageBox.Show("The Object you are moving is of type " + movingNos.SourceClassType + " which cannot be contained in a ShapeCollection"); } else { succeeded = true; TreeNode parentTreeNode = treeNodeMoving.Parent; if (parentTreeNode.IsNamedObjectNode()) { NamedObjectSave parentNos = parentTreeNode.Tag as NamedObjectSave; parentNos.ContainedObjects.Remove(movingNos); } else { EditorLogic.CurrentElement.NamedObjects.Remove(movingNos); } parentTreeNode.Nodes.Remove(treeNodeMoving); targetNode.Nodes.Add(treeNodeMoving); targetNos.ContainedObjects.Add(movingNos); } return(succeeded); }
private TreeNode MoveEntityOntoElement(EntityTreeNode treeNodeMoving, TreeNode targetNode, TreeNode newTreeNode) { EntitySave entitySaveMoved = treeNodeMoving.EntitySave; #region Get the IElement elementToCreateIn IElement elementToCreateIn = null; if (targetNode.IsRootNamedObjectNode()) { BaseElementTreeNode baseElementTreeNode = targetNode.Parent as BaseElementTreeNode; elementToCreateIn = baseElementTreeNode.SaveObject; } else { elementToCreateIn = ((BaseElementTreeNode)targetNode).SaveObject; } #endregion // We used to ask the user if they're sure, but this isn't a destructive action so just do it: //DialogResult result = // MessageBox.Show("Create a new Object in\n\n" + elementToCreateIn.Name + "\n\nusing\n\n\t" + entitySaveMoved.Name + "?", "Create new Object?", MessageBoxButtons.YesNo); NamedObjectSave newNamedObject = CreateNewNamedObjectInElement(elementToCreateIn, entitySaveMoved); newTreeNode = GlueState.Self.Find.NamedObjectTreeNode(newNamedObject); GlueState.Self.CurrentNamedObjectSave = newNamedObject; return(newTreeNode); }
private static bool MoveObjectOnObjectsRoot(TreeNode treeNodeMoving, TreeNode targetNode, NamedObjectSave movingNos, bool succeeded) { // Dropped it on the "Objects" tree node // Let's see if it's the Objects that contains node or another one IElement parentOfMovingNos = movingNos.GetContainer(); IElement elementMovingInto = ((BaseElementTreeNode)targetNode.Parent).SaveObject; if (parentOfMovingNos == elementMovingInto) { if (treeNodeMoving.Parent.IsNamedObjectNode()) { succeeded = true; // removing from a list NamedObjectSave container = treeNodeMoving.Parent.Tag as NamedObjectSave; IElement elementToAddTo = movingNos.GetContainer(); container.ContainedObjects.Remove(movingNos); AddExistingNamedObjectToElement( GlueState.Self.CurrentElement, movingNos); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); IElement elementToRegenerate = targetNode.Parent.Tag as IElement; } } else { succeeded = DragDropNosIntoElement(movingNos, elementMovingInto); } return(succeeded); }
public AvailableStates(NamedObjectSave currentNamedObject, IElement currentElement, CustomVariable currentCustomVariable, StateSave currentStateSave) : base() { CurrentNamedObject = currentNamedObject; CurrentElement = currentElement; CurrentCustomVariable = currentCustomVariable; CurrentStateSave = currentStateSave; }
public static IElement GetElementIfCustomVariableIsVariableState(CustomVariable customVariable, IElement saveObject) { if (customVariable.GetIsVariableState() && string.IsNullOrEmpty(customVariable.SourceObject)) { return(saveObject); } else { NamedObjectSave sourceNamedObjectSave = saveObject.GetNamedObjectRecursively(customVariable.SourceObject); if (sourceNamedObjectSave != null) { EntitySave sourceEntitySave = ObjectFinder.Self.GetEntitySave(sourceNamedObjectSave.SourceClassType); if (sourceEntitySave != null && ((sourceEntitySave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState") || sourceEntitySave.StateCategoryList.ContainsCategoryName(customVariable.Type)) ) { return(sourceEntitySave); } else if (sourceEntitySave == null) { ScreenSave sourceScreenSave = ObjectFinder.Self.GetScreenSave(sourceNamedObjectSave.SourceClassType); if (sourceScreenSave != null && sourceScreenSave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState") { return(sourceScreenSave); } } } return(null); } }
int Compare(ElementRuntime first, ElementRuntime second) { ElementRuntime currentElement = GluxManager.CurrentElement; NamedObjectSave mFirstNos = first.AssociatedNamedObjectSave; NamedObjectSave mSecondNos = second.AssociatedNamedObjectSave; string firstLayer = mFirstNos.LayerOn; string secondLayer = mSecondNos.LayerOn; if (string.IsNullOrEmpty(firstLayer) && !string.IsNullOrEmpty(secondLayer)) { // second is not on a layer, so that should come first return(1); } else if (!string.IsNullOrEmpty(firstLayer) && string.IsNullOrEmpty(secondLayer)) { return(-1); } else if (string.IsNullOrEmpty(firstLayer)) { // they both are, so compare their Z return(-first.Z.CompareTo(second.Z)); } else { // they're on separate layers, so compare the layer indexes IElement element = currentElement.AssociatedIElement; NamedObjectSave firstLayerNos = element.GetNamedObjectRecursively(firstLayer); NamedObjectSave secondLayerNos = element.GetNamedObjectRecursively(secondLayer); return(-Compare(firstLayerNos, secondLayerNos)); } }
private static object GetDefaultValueFor(NamedObjectSave nos, string property, string overridingType) { if (!string.IsNullOrEmpty(overridingType)) { Type overridingTypeAsType = TypeManager.GetTypeFromString(overridingType); string valueAsString = TypeManager.GetDefaultForType(overridingType); return PropertyValuePair.ConvertStringToType(valueAsString, overridingTypeAsType); } switch (nos.SourceType) { case SourceType.File: if (!string.IsNullOrEmpty(nos.SourceFile) && !string.IsNullOrEmpty(nos.SourceNameWithoutParenthesis)) { string absoluteFileName = ProjectManager.MakeAbsolute(nos.SourceFile, true); return ContentParser.GetValueForProperty(absoluteFileName, nos.SourceNameWithoutParenthesis, property); } break; case SourceType.Entity: if (!string.IsNullOrEmpty(nos.SourceClassType)) { IElement element = ObjectFinder.Self.GetIElement(nos.SourceClassType); if (element != null) { CustomVariable customVariable = element.GetCustomVariable(property); if (customVariable != null) { return GetDefaultValueFor(customVariable, element); } else if (property == "Visible" && element is EntitySave && ((EntitySave)element).ImplementsIVisible) { return true; } else if (property == "Enabled" && element is EntitySave && ((EntitySave)element).ImplementsIWindow) { return true; } } } break; case SourceType.FlatRedBallType: if (!string.IsNullOrEmpty(nos.SourceClassType)) { // See if there is a variable set for this already - there may be // now that we allow users to specify values right on FlatRedBall-type // NamedObjectSaves InstructionSave instructionSave = nos.GetCustomVariable(property); if (instructionSave != null && instructionSave.Value != null) { return instructionSave.Value; } else { object value = GetExceptionForFlatRedBallTypeDefaultValue(nos, property); if (value != null) { return value; } else { string classType = nos.SourceClassType; value = GetDefaultValueForPropertyInType(property, classType); return value; } } } break; } return null; }
private static object GetExceptionForFlatRedBallTypeDefaultValue(NamedObjectSave nos, string property) { if (property == "Visible" || property == "Enabled") { return true; } return null; }