private void TryHandleSelectedCollisionRelationship(NamedObjectSave selectedNos) { var shouldShowControl = false; if (selectedNos?.GetAssetTypeInfo() == AssetTypeInfoManager.Self.CollisionRelationshipAti) { RefreshViewModelTo(selectedNos); shouldShowControl = true; } if (shouldShowControl) { if (relationshipControl == null) { relationshipControl = new CollisionRelationshipView(); relationshipPluginTab = this.CreateTab(relationshipControl, "Collision"); this.ShowTab(relationshipPluginTab, TabLocation.Center); relationshipControl.DataContext = relationshipViewModel; } else { this.ShowTab(relationshipPluginTab); } } else { this.RemoveTab(relationshipPluginTab); } }
private void GetEventSignatureAndArgs(NamedObjectSave namedObjectSave, EventResponseSave eventResponseSave, out string type, out string signatureArgs) { if (namedObjectSave == null) { throw new ArgumentNullException(nameof(namedObjectSave)); } if (namedObjectSave.GetAssetTypeInfo() == AssetTypeInfoManager.Self.CollisionRelationshipAti && eventResponseSave.SourceObjectEvent == "CollisionOccurred") { bool firstThrowaway; bool secondThrowaway; var firstType = AssetTypeInfoManager.GetFirstGenericType(namedObjectSave, out firstThrowaway); var secondType = AssetTypeInfoManager.GetSecondGenericType(namedObjectSave, out secondThrowaway); type = $"System.Action<{firstType}, {secondType}>"; signatureArgs = $"{firstType} first, {secondType} second"; } else { type = null; signatureArgs = null; } }
public static CodeBuilder.ICodeBlock AddToPauseIgnoreIfNecessary(CodeBuilder.ICodeBlock codeBlock, IElement element, NamedObjectSave nos) { if (nos.IgnoresPausing) { if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType)) { // it's an Entity codeBlock.Line(nos.InstanceName + ".SetToIgnorePausing();"); } else if (nos.GetAssetTypeInfo() != null && nos.GetAssetTypeInfo().CanIgnorePausing) { codeBlock.Line("FlatRedBall.Instructions.InstructionManager.IgnorePausingFor(" + nos.InstanceName + ");"); } } return(codeBlock); }
private void GenerateVariableActivityFor(ICodeBlock codeBlock, NamedObjectSave namedObject, InstanceManagementValues instanceManagementValues) { var name = namedObject.FieldName; var assetTypeInfo = namedObject.GetAssetTypeInfo(); GenerateActivityFor(codeBlock, instanceManagementValues.SelectedProperties, name, assetTypeInfo); }
private void HandleAddEventsForObject(NamedObjectSave namedObject, List <ExposableEvent> listToAddTo) { if (namedObject.GetAssetTypeInfo() == AssetTypeInfoManager.Self.CollisionRelationshipAti) { var newEvent = new ExposableEvent("CollisionOccurred"); listToAddTo.Add(newEvent); } }
public bool IsTileShapeCollection(NamedObjectSave namedObject) { var isTileShapeCollection = false; if (namedObject != null) { var ati = namedObject.GetAssetTypeInfo(); isTileShapeCollection = ati == AssetTypeInfoAdder.Self.TileShapeCollectionAssetTypeInfo; } return(isTileShapeCollection); }
public static void UpdateShownVariables(DataUiGrid grid, NamedObjectSave instance, IElement container) { grid.Categories.Clear(); List <MemberCategory> categories = new List <MemberCategory>(); var defaultCategory = new MemberCategory("Variables"); defaultCategory.FontSize = 14; categories.Add(defaultCategory); AssetTypeInfo ati = instance.GetAssetTypeInfo(); // not sure if this is needed: if (instance.TypedMembers.Count == 0) { instance.UpdateCustomProperties(); } CreateCategoriesAndVariables(instance, container, categories, ati); if (ati != null) { SortCategoriesAndMembers(ref categories, ati); } if (defaultCategory.Members.Count == 0) { categories.Remove(defaultCategory); } else if (categories.Count != 1) { defaultCategory.Name = "Other Variables"; } if (categories.Count != 0) { // "Name" should be the very first property: var nameCategory = CreateNameInstanceMember(instance); categories.Insert(0, nameCategory); } SetAlternatingColors(grid, categories); foreach (var category in categories) { grid.Categories.Add(category); } grid.Refresh(); }
public bool IsTileShapeCollection(NamedObjectSave namedObject) { var isTileShapeCollection = false; if (namedObject != null) { var ati = namedObject.GetAssetTypeInfo(); isTileShapeCollection = namedObject.SourceType == SourceType.File && !string.IsNullOrEmpty(namedObject.SourceName) && ati == AssetTypeInfoAdder.Self.TileShapeCollectionAssetTypeInfo; } return(isTileShapeCollection); }
private string GetGumElementConstructorFunct(IElement glueContainerElement, NamedObjectSave namedObject, ReferencedFileSave assetTypeInfo) { var fieldName = namedObject.FieldName; var ati = namedObject.GetAssetTypeInfo(); return ("{" + $"var oldLayoutSuspended = global::Gum.Wireframe.GraphicalUiElement.IsAllLayoutSuspended; " + $"global::Gum.Wireframe.GraphicalUiElement.IsAllLayoutSuspended = true; " + $"{fieldName} = new {ati.QualifiedRuntimeTypeName.QualifiedType}();" + $"global::Gum.Wireframe.GraphicalUiElement.IsAllLayoutSuspended = oldLayoutSuspended; " + $"{fieldName}.UpdateLayout();" + "}"); }
private void GenerateVariableUpdateDependenciesFor(ICodeBlock codeBlock, NamedObjectSave namedObject, InstanceManagementValues instanceManagementValues) { var name = namedObject.FieldName; var ati = namedObject.GetAssetTypeInfo(); GeneratePositionedObjectVariableUpdateDependenciesFor(codeBlock, name, instanceManagementValues); if (ati?.RuntimeTypeName == "Text") { GenerateTextVariableUpdateDependenciesFor(codeBlock, name, instanceManagementValues.SelectedProperties); } else if (ati?.RuntimeTypeName == "Sprite") { GenerateSpriteVariableUpdateDependenciesFor(codeBlock, name, instanceManagementValues.SelectedProperties); } }
public static bool GetIfCanBeReferencedByRelationship(NamedObjectSave nos) { if (nos == null) { throw new ArgumentNullException(nameof(nos)); } var nosElement = nos.GetReferencedElement(); var nosAti = nos.GetAssetTypeInfo(); var entity = nosElement as EntitySave; var shouldConsider = false; if (entity?.ImplementsICollidable == true) { shouldConsider = true; } if (!shouldConsider) { // See if it's a list of ICollidables shouldConsider = nos != null && nos.SourceType == SourceType.FlatRedBallType && nos.SourceClassType == "PositionedObjectList<T>" && !string.IsNullOrEmpty(nos.SourceClassGenericType) && ObjectFinder.Self.GetEntitySave(nos.SourceClassGenericType)?.ImplementsICollidable == true; } if (!shouldConsider) { shouldConsider = nosAti?.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.TileCollisions.TileShapeCollection"; } if (!shouldConsider) { shouldConsider = nosAti?.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Math.Geometry.ShapeCollection"; } return(shouldConsider); }
private void ExcludeAndIncludeGlueVariables(NamedObjectSave instance) { bool shouldIncludeSourceClassType = true; bool shouldIncludeSourceFile = true; bool shouldIncludeSourceName = true; bool shouldIncludeSourceClassGenericType = true; bool shouldShowCurrentState = true; bool shouldIncludeIncludeInIVisible = true; bool shouldIncludeIncludeInIClickable = true; bool shouldIncludeIncludeInICollidable = true; bool shouldIncludeIsContainer = true; bool shouldShowIsZBuffered = false; bool shouldIncludeSetByContainer = true; bool shouldShowGenerateTimedEmit = false; bool shouldIncludeIsManuallyUpdated = false; ExcludeMember(nameof(NamedObjectSave.InstructionSaves)); ExcludeMember(nameof(NamedObjectSave.Properties)); ExcludeMember(nameof(NamedObjectSave.FileCreatedBy)); ExcludeMember(nameof(NamedObjectSave.FulfillsRequirement)); ExcludeMember(nameof(NamedObjectSave.IsNodeHidden)); var assetTypeInfo = instance.GetAssetTypeInfo(); shouldIncludeIsManuallyUpdated = !string.IsNullOrEmpty(assetTypeInfo?.AddManuallyUpdatedMethod); if (DisplayMode == DisplayModes.VariablesOnly) { ExcludeAllMembers(); } else { if (DisplayMode != DisplayModes.Debug) { ExcludeMember(nameof(NamedObjectSave.InstantiatedByBase)); } var containerType = instance.GetContainerType(); // Screens can't be IVisible/IClickable so no need to show these properties // in screens shouldIncludeIncludeInIVisible = containerType == ContainerType.Entity; if (assetTypeInfo != null && assetTypeInfo.HasVisibleProperty == false) { shouldIncludeIncludeInIVisible = false; } shouldIncludeIncludeInIClickable = containerType == ContainerType.Entity; if (assetTypeInfo != null && assetTypeInfo.HasCursorIsOn == false) { shouldIncludeIncludeInIClickable = false; } // shapes don't implement ICollidable, but they have collision: bool isShape = assetTypeInfo?.QualifiedRuntimeTypeName.QualifiedType?.StartsWith("FlatRedBall.Math.Geometry") ?? false; if (assetTypeInfo != null && assetTypeInfo.ImplementsICollidable == false && !isShape) { shouldIncludeIncludeInICollidable = false; } bool shouldShowAttachToContainer = containerType == ContainerType.Entity && instance.IsList == false; // Not sure if we want to keep this or not, but currently objects in Entities can't be attached to the Camera bool shouldShowAttachToCamera = instance.GetContainerType() == ContainerType.Screen; if (!shouldShowAttachToContainer) { this.ExcludeMember(nameof(NamedObjectSave.AttachToContainer)); } if (!shouldShowAttachToCamera) { ExcludeMember(nameof(NamedObjectSave.AttachToCamera)); } if (instance.SourceType == SaveClasses.SourceType.FlatRedBallType && instance.SourceClassType == "Layer") { } // We used to not show the AddToManagers property for objects inside Entities, but as I worked on SteamBirds // I found myself needing it. //else if (ContainerType == ContainerType.Entity) //{ // ExcludeMember("AddToManagers"); //} if (instance.SetByDerived) { ExcludeMember(nameof(NamedObjectSave.AttachToContainer)); } if (instance.InstantiatedByBase) { ExcludeMember(nameof(NamedObjectSave.SourceType)); shouldIncludeSourceClassType = false; shouldIncludeSourceClassGenericType = false; ExcludeMember(nameof(NamedObjectSave.InstanceName)); ExcludeMember(nameof(NamedObjectSave.CallActivity)); ExcludeMember(nameof(NamedObjectSave.IgnoresPausing)); ExcludeMember(nameof(NamedObjectSave.HasPublicProperty)); ExcludeMember(nameof(NamedObjectSave.ExposedInDerived)); ExcludeMember(nameof(NamedObjectSave.SetByDerived)); ExcludeMember(nameof(NamedObjectSave.SetByContainer)); } bool shouldIncludeAddToManagers = !instance.InstantiatedByBase && !instance.IsList; if (!shouldIncludeAddToManagers) { ExcludeMember("AddToManagers"); } UpdateLayerIncludeAndExclude(instance); if (containerType != ContainerType.Entity) { shouldIncludeIsContainer = false; shouldIncludeSetByContainer = false; } #region Camera-related properties if (instance.SourceType != SaveClasses.SourceType.FlatRedBallType || instance.SourceClassType != "Camera") { ExcludeMember(nameof(NamedObjectSave.IsNewCamera)); } #endregion #region Text-related properties if (instance.SourceType != SaveClasses.SourceType.FlatRedBallType || instance.SourceClassType != "Text") { ExcludeMember(nameof(NamedObjectSave.IsPixelPerfect)); } #endregion // we don't show this on files because Sprites from file will be put on the z buffer according to the // file. shouldShowIsZBuffered = instance.SourceType == SourceType.FlatRedBallType && (instance.SourceClassType != "Sprite" || instance.SourceClassType != "SpriteFrame"); shouldShowGenerateTimedEmit = (instance.SourceType == SourceType.FlatRedBallType && instance.SourceClassType == "Emitter") || (instance.SourceType == SourceType.File && instance.ClassType == "Emitter"); #region Remove based off of SourceType if (instance.SourceType == SourceType.FlatRedBallType) { shouldShowCurrentState = false; shouldIncludeSourceFile = false; shouldIncludeSourceName = false; if (!instance.IsGenericType) { shouldIncludeSourceClassGenericType = false; } } else if (instance.SourceType == SourceType.File) { shouldShowCurrentState = false; shouldIncludeSourceClassType = false; shouldIncludeSourceClassGenericType = false; } else if (instance.SourceType == SourceType.Entity) { shouldIncludeSourceFile = false; shouldIncludeSourceName = false; shouldIncludeSourceClassGenericType = false; shouldShowCurrentState = DetermineIfShouldShowStates(instance); } #endregion if (shouldIncludeSourceClassType) { IncludeMember(nameof(NamedObjectSave.SourceClassType), typeof(NamedObjectSave), new AvailableClassTypeConverter(instance)); } else { ExcludeMember(nameof(NamedObjectSave.SourceClassType)); } if (shouldIncludeSourceFile) { IncludeMember(nameof(NamedObjectSave.SourceFile), typeof(NamedObjectSave), new AvailableFileStringConverter(CurrentElement)); } else { ExcludeMember(nameof(NamedObjectSave.SourceFile)); } if (shouldShowGenerateTimedEmit) { IncludeMember(nameof(instance.GenerateTimedEmit), typeof(NamedObjectSave)); } else { ExcludeMember(nameof(instance.GenerateTimedEmit)); } if (shouldIncludeSourceName) { IncludeMember(nameof(NamedObjectSave.SourceName), typeof(NamedObjectSave), new AvailableNameablesStringConverter(instance, null)); } else { ExcludeMember(nameof(NamedObjectSave.SourceName)); } if (shouldIncludeSourceClassGenericType) { IncludeMember(nameof(NamedObjectSave.SourceClassGenericType), typeof(NamedObjectSave), new AvailableClassGenericTypeConverter()); } else { ExcludeMember(nameof(NamedObjectSave.SourceClassGenericType)); } if (shouldShowCurrentState) { IncludeMember(nameof(NamedObjectSave.CurrentState), typeof(NamedObjectSave), new AvailableStates(CurrentNamedObject, CurrentElement, CurrentCustomVariable, CurrentStateSave)); } else { ExcludeMember(nameof(NamedObjectSave.CurrentState)); } if (!shouldIncludeIncludeInIClickable) { ExcludeMember(nameof(NamedObjectSave.IncludeInIClickable)); } if (!shouldIncludeIncludeInIVisible) { ExcludeMember(nameof(NamedObjectSave.IncludeInIVisible)); } if (!shouldIncludeIncludeInICollidable) { ExcludeMember(nameof(NamedObjectSave.IncludeInICollidable)); } if (!shouldShowIsZBuffered) { ExcludeMember(nameof(NamedObjectSave.IsZBuffered)); } if (!shouldIncludeSetByContainer) { ExcludeMember(nameof(NamedObjectSave.SetByContainer)); } if (shouldIncludeIsManuallyUpdated == false) { ExcludeMember(nameof(NamedObjectSave.IsManuallyUpdated)); } } }
private static void AddCodeForIsOn(ICodeBlock codeBlock, NamedObjectSave nos) { string condition = null; AssetTypeInfo ati = nos.GetAssetTypeInfo(); if (ati != null && ati.HasCursorIsOn) { bool shouldConsiderVisible = ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Sprite" || ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.ManagedSpriteGroups.SpriteFrame" || ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Text"; bool shouldConsiderAlpha = ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Sprite" || ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.ManagedSpriteGroups.SpriteFrame" || ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Text"; string whatToFormat; if (shouldConsiderVisible) { whatToFormat = "{0}.AbsoluteVisible && cursor.IsOn3D({0}, LayerProvidedByContainer)"; } else if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Scene") { whatToFormat = "cursor.IsOn3D({0}, LayerProvidedByContainer, false)"; } else { whatToFormat = "cursor.IsOn3D({0}, LayerProvidedByContainer)"; } if (shouldConsiderAlpha) { whatToFormat = "{0}.Alpha != 0 && " + whatToFormat; } condition = string.Format(whatToFormat, nos.InstanceName); } else if (nos.SourceType == SourceType.Entity) { EntitySave entitySave = ObjectFinder.Self.GetEntitySave(nos.SourceClassType); if (entitySave != null) { // This happens if: // The user has an Entity which is IWindow // The user adds a new object // The user sets the object to Entity - this will cause a code regeneration and this will be null; if (entitySave.ImplementsIWindow || entitySave.ImplementsIClickable) { condition = string.Format("{0}.HasCursorOver(cursor)", nos.InstanceName); } } } if (condition != null) { codeBlock.If(condition) .Line("return true;"); } }
public static List <MemberWithType> GetExposableMembersFor(NamedObjectSave namedObjectSave) { List <MemberWithType> returnValue = new List <MemberWithType>(); if (namedObjectSave != null) { switch (namedObjectSave.SourceType) { case SourceType.Entity: EntitySave entitySave = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType); if (entitySave == null) { return(returnValue); } else { return(GetTunnelableMembersFor(entitySave, false)); } //break; case SourceType.File: Type type = null; string typeAsString = namedObjectSave.InstanceType; type = TypeManager.GetTypeFromString( typeAsString); if (type != null) { FillListWithAvailableVariablesInType(type, returnValue); } var assetTypeInfo = namedObjectSave.GetAssetTypeInfo(); if (assetTypeInfo != null) { FillFromVariableDefinitions(returnValue, assetTypeInfo); } break; case SourceType.FlatRedBallType: FillWithExposableMembersForFlatRedBallType(namedObjectSave, returnValue); break; } } AssetTypeInfo ati = namedObjectSave.GetAssetTypeInfo(); if (ati != null) { // we convert from a string member to a typed member, only to go back to a string member. // That means we lose type info on any member that is of type not understood by Glue. // Not sure why the code does this, but we could just directly add the member from CachedExtraVariables //List<TypedMemberBase> typedMembers = null; //typedMembers = ati.GetTypedMembers(); foreach (var member in ati.CachedExtraVariables) { if (!returnValue.Any(item => item.Member == member.Member)) { returnValue.Add(member); } } } return(returnValue); }
public static List <ExposableEvent> GetExposableEventsFor(NamedObjectSave namedObjectSave, IElement parent) { List <ExposableEvent> returnValues = new List <ExposableEvent>(); if (namedObjectSave != null) { switch (namedObjectSave.SourceType) { case SourceType.Entity: EntitySave entitySave = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType); if (entitySave == null) { // do nothing //return returnValues; } else { returnValues = GetExposableEventsFor(entitySave, false); } break; case SourceType.FlatRedBallType: if (namedObjectSave.SourceClassType == "PositionedObjectList<T>") { returnValues.Add(new ExposableEvent("CollectionChanged")); } break; case SourceType.File: var ati = namedObjectSave.GetAssetTypeInfo(); if (ati != null && ati.ImplementsIWindow) { AddIWindowEvents(returnValues); } break; } #if GLUE PluginManager.AddEventsForObject(namedObjectSave, returnValues); #endif } if (parent != null) { for (int i = returnValues.Count - 1; i > -1; i--) { bool found = false; foreach (EventResponseSave ers in parent.Events) { if (ers.SourceObject == namedObjectSave.InstanceName && ers.SourceObjectEvent == returnValues[i].Name) { found = true; break; } } if (found) { returnValues.RemoveAt(i); } } } return(returnValues); }
public static string GetMemberTypeForNamedObject(NamedObjectSave namedObject, string variableName) { Type typeOfNamedObject = null; string foundType = null; var ati = namedObject.GetAssetTypeInfo(); switch (namedObject.SourceType) { case SourceType.Entity: EntitySave entitySave = ObjectFinder.Self.GetEntitySave(namedObject.SourceClassType); typeOfNamedObject = typeof(PositionedObject); if (entitySave != null) { CustomVariable customVariable = entitySave.GetCustomVariable(variableName); if (customVariable == null) { if (variableName.StartsWith("Current") && variableName.EndsWith("State")) { if (variableName == "CurrentState") { foundType = "VariableState"; } else { foundType = variableName.Substring("Current".Length, variableName.Length - ("Current".Length + "State".Length)); } } else if (variableName == "Visible" && // Should this check recursively? (entitySave.ImplementsIVisible || entitySave.InheritsFromFrbType())) { foundType = "bool"; } else if (variableName == "Enabled" && entitySave.ImplementsIWindow) { foundType = "bool"; } } else if (entitySave.ContainsCustomVariable(variableName)) { CustomVariable foundVariable = entitySave.GetCustomVariable(variableName); if (!string.IsNullOrEmpty(foundVariable.OverridingPropertyType)) { foundType = foundVariable.OverridingPropertyType; } else { foundType = foundVariable.Type; } } } break; case SourceType.File: { if (ati != null && ati.CachedExtraVariables.Any(item => item.Member == variableName)) { foundType = ati.CachedExtraVariables.First(item => item.Member == variableName).Type; } else if (ati != null && ati.VariableDefinitions.Any(item => item.Name == variableName)) { foundType = ati.VariableDefinitions.First(item => item.Name == variableName).Type; } else { string typeAsString = namedObject.InstanceType; typeOfNamedObject = TypeManager.GetTypeFromString( typeAsString); } } break; case SourceType.FlatRedBallType: if (variableName == "SourceFile") { return(namedObject.ClassType); } else if (ati != null && ati.CachedExtraVariables.Any(item => item.Member == variableName)) { foundType = ati.CachedExtraVariables.First(item => item.Member == variableName).Type; } else if (ati != null && !string.IsNullOrEmpty(ati.QualifiedRuntimeTypeName.QualifiedType)) { typeOfNamedObject = TypeManager.GetTypeFromString(ati.QualifiedRuntimeTypeName.QualifiedType); } else if (namedObject.IsList && variableName == "Visible") { foundType = "bool"; } break; } if (!string.IsNullOrEmpty(foundType)) { return(foundType); } else { Type type = GetTypeForMemberInType(typeOfNamedObject, variableName); if (type == null) { type = typeof(string); } string toReturn = type.Name; if (type.IsGenericType) { var split = type.Name.Split('`'); string firstPart = split[0]; int numberOfParams = int.Parse(split[1]); if (numberOfParams > 1) { // need to add support //throw new Exception(); } else { var result = type.GetGenericArguments(); toReturn = firstPart + "<" + result[0].Name + ">"; } } return(toReturn); } }
private void HandleChangedIsContainer(NamedObjectSave nos, IElement element) { if (nos.IsContainer) { var existingContainer = element.AllNamedObjects.FirstOrDefault( item => item.IsContainer && item != nos); bool succeeded = true; if (existingContainer != null) { succeeded = false; MessageBox.Show("The object " + existingContainer + " is already marked as IsContainer. " + "Two objects in the same element cannot be marked as Iscontainer"); } if (succeeded) { string nosType = nos.GetAssetTypeInfo()?.QualifiedRuntimeTypeName.QualifiedType; if (string.IsNullOrEmpty(nosType)) { nosType = nos.SourceClassType; } bool doesBaseMatch = !string.IsNullOrEmpty(element.BaseElement) && element.BaseElement == nosType; if (!doesBaseMatch) { MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); string containerType = element.BaseElement; if (string.IsNullOrEmpty(containerType)) { containerType = "<NONE>"; } mbmb.MessageText = "The object is of type " + nosType + " but the container is of type " + containerType + "\n\n" + "What would you like to do?"; mbmb.AddButton("Set the container's type to " + nosType, DialogResult.Yes); mbmb.AddButton("Nothing - game may not compile until this has been fixed", DialogResult.No); mbmb.AddButton("Set 'IsContainer' back to false", DialogResult.Cancel); var dialogResult = mbmb.ShowDialog(); if (dialogResult == DialogResult.Yes) { element.BaseObject = nosType; } else if (dialogResult == DialogResult.Cancel) { succeeded = false; } } } if (!succeeded) { nos.IsContainer = false; } } }
private static void FillWithExposableMembersForFlatRedBallType(NamedObjectSave namedObjectSave, List <MemberWithType> returnValue) { AssetTypeInfo assetTypeInfo = namedObjectSave.GetAssetTypeInfo(); if (assetTypeInfo != null && !string.IsNullOrEmpty(assetTypeInfo.Extension)) { returnValue.Add(new MemberWithType { Member = "SourceFile", Type = "string" }); } // slowly move away from reflection: // To do this, the CSV has to include // types for variables. Until it does, we // are going to continue to rely on reflection. if (assetTypeInfo != null && (assetTypeInfo.FriendlyName == "Sprite" || assetTypeInfo.FriendlyName == "AxisAlignedRectangle" || assetTypeInfo.FriendlyName == "Circle" || assetTypeInfo.FriendlyName == "Polygon" || assetTypeInfo.FriendlyName == "Layer" )) { if (assetTypeInfo.VariableDefinitions.Any(definition => string.IsNullOrEmpty(definition.Type))) { throw new InvalidOperationException("The type " + assetTypeInfo.FriendlyName + " has variables without a type"); } var toAdd = assetTypeInfo.VariableDefinitions .Select(definition => new MemberWithType { Member = definition.Name, Type = definition.Type }); returnValue.AddRange(toAdd); } else if (assetTypeInfo != null && !string.IsNullOrEmpty(assetTypeInfo.QualifiedRuntimeTypeName.QualifiedType)) { var type = TypeManager.GetTypeFromString(assetTypeInfo.QualifiedRuntimeTypeName.QualifiedType); // We'll fall back to reflection, but eventually I'd like to see this go away if (type != null) { FillListWithAvailableVariablesInType(type, returnValue); AddSpecialCasePropertiesFor(type, returnValue); } FillFromVariableDefinitions(returnValue, assetTypeInfo); } else if (namedObjectSave.IsList && !string.IsNullOrEmpty(namedObjectSave.SourceClassGenericType)) { // special case - if the list is of IVisibles, then // let's allow the user to set visibility on the whole // list. EntitySave entityTypeInList = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassGenericType); if (entityTypeInList != null && entityTypeInList.ImplementsIVisible) { returnValue.Add(new MemberWithType { Member = "Visible", Type = "bool" }); } } // June 23, 2013 // I don't think we // want to sort here // because the properties // will already be sorted in // a particular way from the function // FillListWithAvailableVariablesInType. // I'm going to comment this out to see if // it causes any problems. //returnValue.Sort(); }
private void ReactToChangedNosSourceName(NamedObjectSave namedObjectSave, string oldValue) { IElement container = EditorLogic.CurrentElement; if (!string.IsNullOrEmpty(container.BaseElement) && !string.IsNullOrEmpty(namedObjectSave.InstanceType)) { IElement baseElement = ObjectFinder.Self.GetIElement(container.BaseElement); NamedObjectSave namedObjectInBase = baseElement.GetNamedObjectRecursively(namedObjectSave.InstanceName); if (namedObjectInBase == null) { // This is not a valid setup - what do we do here? } else { // We'll rely on the instance type, which is the "old" informal way... var doDiffer = namedObjectInBase.InstanceType != namedObjectSave.InstanceType && // and the new AssetTypeInfo which will resolve issues like unqualified vs qualified types namedObjectInBase.GetAssetTypeInfo() != null && namedObjectInBase.GetAssetTypeInfo() != namedObjectSave.GetAssetTypeInfo(); if (doDiffer) { if (string.IsNullOrEmpty(namedObjectInBase.InstanceType)) { string message = "This object has type of " + namedObjectSave.InstanceType + " but the base object in " + baseElement.ToString() + " is untyped. What would you like to do?"; MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = message; mbmb.AddButton("Change " + namedObjectInBase.InstanceName + " to " + namedObjectSave.InstanceType + " in " + baseElement.ToString(), DialogResult.Yes); mbmb.AddButton("Do nothing (your project will likely not compile so you will need to fix this manually)", DialogResult.No); DialogResult result = mbmb.ShowDialog(); if (result == DialogResult.Yes) { switch (namedObjectInBase.SourceType) { case SourceType.File: // The base needs to be a FlatRedBallType namedObjectInBase.SourceType = SourceType.FlatRedBallType; namedObjectInBase.SourceClassType = namedObjectSave.InstanceType; break; case SourceType.FlatRedBallType: namedObjectInBase.SourceType = SourceType.FlatRedBallType; namedObjectInBase.SourceClassType = namedObjectSave.SourceClassType; break; case SourceType.Entity: namedObjectInBase.SourceType = SourceType.Entity; namedObjectInBase.SourceClassType = namedObjectSave.SourceClassType; break; } namedObjectInBase.UpdateCustomProperties(); CodeWriter.GenerateCode(baseElement); } } else { string message = "This object is of type " + namedObjectSave.InstanceType + " but the base " + "object is of type " + namedObjectInBase.InstanceType + ""; MessageBox.Show(message); namedObjectSave.SourceName = oldValue; } } } } }