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).SaveObjectAsElement; 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); NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectToElementTreeNode(EditorLogic.CurrentElementTreeNode, movingNos, false); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); IElement elementToRegenerate = targetNode.Parent.Tag as IElement; } } else { succeeded = DragDropNosIntoElement(movingNos, elementMovingInto); } return(succeeded); }
public NamedObjectSave AddNewNamedObjectToSelectedElement(AddObjectViewModel addObjectViewModel) { MembershipInfo membershipInfo = NamedObjectSaveExtensionMethodsGlue.GetMemberMembershipInfo(addObjectViewModel.ObjectName); var newNos = NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectToSelectedElement(addObjectViewModel.ObjectName, membershipInfo, false); if (addObjectViewModel.SourceClassType != NoType && !string.IsNullOrEmpty(addObjectViewModel.SourceClassType)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceClassType = addObjectViewModel.SourceClassType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); } else if (!string.IsNullOrEmpty(addObjectViewModel.SourceFile)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); } newNos.SourceClassGenericType = addObjectViewModel.SourceClassGenericType; var ati = newNos.GetAssetTypeInfo(); if (ati != null && ati.DefaultPublic) { newNos.HasPublicProperty = true; } var currentEntity = GlueState.Self.CurrentElement as EntitySave; if (currentEntity != null && currentEntity.CreatedByOtherEntities && currentEntity.PooledByFactory) { bool wasAnythingAdded = FlatRedBall.Glue.Factories.FactoryManager.AddResetVariablesFor(newNos); if (wasAnythingAdded) { PluginManager.ReceiveOutput("Added reset variables for " + newNos); } } PluginManager.ReactToNewObject(newNos); MainGlueWindow.Self.PropertyGrid.Refresh(); PropertyGridHelper.UpdateNamedObjectDisplay(); ElementViewWindow.GenerateSelectedElementCode(); // it may already be selected, so force select it MainGlueWindow.Self.ElementTreeView.SelectedNode = null; MainGlueWindow.Self.ElementTreeView.SelectedNode = GlueState.Self.Find.NamedObjectTreeNode(newNos); GluxCommands.Self.SaveGlux(); return(newNos); }
public NamedObjectSave AddNewNamedObjectTo(AddObjectViewModel addObjectViewModel, IElement element, NamedObjectSave namedObject) { if (element == null) { throw new ArgumentNullException(nameof(element)); } MembershipInfo membershipInfo = NamedObjectSaveExtensionMethodsGlue.GetMemberMembershipInfo(addObjectViewModel.ObjectName); var newNos = NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectTo(addObjectViewModel.ObjectName, membershipInfo, element, namedObject, false); if (addObjectViewModel.SourceClassType != NoType && !string.IsNullOrEmpty(addObjectViewModel.SourceClassType)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceClassType = addObjectViewModel.SourceClassType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); GlueCommands.Self.RefreshCommands.RefreshUi(element); } else if (!string.IsNullOrEmpty(addObjectViewModel.SourceFile)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); GlueCommands.Self.RefreshCommands.RefreshUi(element); } newNos.SourceClassGenericType = addObjectViewModel.SourceClassGenericType; var ati = newNos.GetAssetTypeInfo(); if (ati != null && ati.DefaultPublic) { newNos.HasPublicProperty = true; } var entity = element as EntitySave; if (entity != null && entity.CreatedByOtherEntities && entity.PooledByFactory) { bool wasAnythingAdded = FlatRedBall.Glue.Factories.FactoryManager.AddResetVariablesFor(newNos); if (wasAnythingAdded) { PluginManager.ReceiveOutput("Added reset variables for " + newNos); } } PluginManager.ReactToNewObject(newNos); MainGlueWindow.Self.PropertyGrid.Refresh(); PropertyGridHelper.UpdateNamedObjectDisplay(); GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(element); GluxCommands.Self.SaveGlux(); return(newNos); }
public TreeNode MoveEntityOn(EntityTreeNode treeNodeMoving, TreeNode targetNode) { TreeNode newTreeNode = null; #region Moving the Entity into (or out of) a directory if (targetNode.IsDirectoryNode() || targetNode.IsRootEntityNode()) { MoveEntityToDirectory(treeNodeMoving, targetNode); } #endregion #region Moving an Entity onto another element to create an instance else if (targetNode.IsEntityNode() || targetNode.IsScreenNode() || targetNode.IsRootNamedObjectNode()) { bool isValidDrop = true; // Make sure that we don't drop an Entity into its own Objects if (targetNode.IsRootNamedObjectNode()) { if (treeNodeMoving == targetNode.GetContainingElementTreeNode()) { isValidDrop = false; } } if (isValidDrop) { newTreeNode = MoveEntityOntoElement(treeNodeMoving, targetNode, newTreeNode); } } #endregion #region Moving an Entity onto a NamedObject (currently supports only Lists) else if (targetNode.IsNamedObjectNode()) { // Allow drop only if it's a list or Layer NamedObjectSave targetNamedObjectSave = targetNode.Tag as NamedObjectSave; if (!targetNamedObjectSave.IsList && !targetNamedObjectSave.IsLayer) { MessageBox.Show("The target is not a List or Layer so we can't add an Object to it.", "Target not valid"); } if (targetNamedObjectSave.IsLayer) { TreeNode parent = targetNode.Parent; newTreeNode = MoveEntityOn(treeNodeMoving, parent); // this created a new NamedObjectSave. Let's put that on the Layer DragDropManager.Self.MoveNamedObject(newTreeNode, targetNode); } else { // Make sure that the two types match string listType = targetNamedObjectSave.SourceClassGenericType; bool isOfTypeOrInherits = listType == treeNodeMoving.EntitySave.Name || treeNodeMoving.EntitySave.InheritsFrom(listType); if (isOfTypeOrInherits == false) { MessageBox.Show("The target list type is of type\n\n" + listType + "\n\nBut the Entity is of type\n\n" + treeNodeMoving.EntitySave.Name + "\n\nCould not add an instance to the list", "Could not add instance"); } else { NamedObjectSave namedObject = new NamedObjectSave(); namedObject.InstanceName = FileManager.RemovePath(treeNodeMoving.EntitySave.Name) + "1"; StringFunctions.MakeNameUnique <NamedObjectSave>( namedObject, targetNamedObjectSave.ContainedObjects); // Not sure if we need to set this or not, but I think // any instance added to a list will not be defined by base namedObject.DefinedByBase = false; NamedObjectSaveExtensionMethodsGlue.AddNamedObjectToCurrentNamedObjectList(namedObject); ElementViewWindow.GenerateSelectedElementCode(); // Don't save the Glux, the caller of this method will take care of it // GluxCommands.Self.SaveGlux(); } } } #endregion else if (targetNode.IsGlobalContentContainerNode()) { AskAndAddAllContainedRfsToGlobalContent(treeNodeMoving.SaveObject); } return(newTreeNode); }
internal static NamedObjectSave CreateNewNamedObjectInElement(IElement elementToCreateIn, EntitySave blueprintEntity, bool createList = false) { if (blueprintEntity == null) { throw new ArgumentNullException($"{nameof(blueprintEntity)} cannot be null"); } if (elementToCreateIn is EntitySave && ((EntitySave)elementToCreateIn).ImplementsIVisible && !blueprintEntity.ImplementsIVisible) { MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = "The Entity\n\n" + blueprintEntity + "\n\nDoes not Implement IVisible, but the Entity it is being dropped in does. " + "What would you like to do?"; mbmb.AddButton("Make " + blueprintEntity.Name + " implement IVisible", DialogResult.OK); mbmb.AddButton("Nothing (your code will not compile until this problem is resolved manually)", DialogResult.Cancel); DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self); if (result == DialogResult.OK) { blueprintEntity.ImplementsIVisible = true; CodeGeneratorIElement.GenerateElementDerivedAndReferenced(blueprintEntity); } } BaseElementTreeNode elementTreeNode = GlueState.Self.Find.ElementTreeNode(elementToCreateIn); //EntityTreeNode entityTreeNode = // ElementViewWindow.GetEntityTreeNode(entityToCreateIn); NamedObjectSave newNamedObject = new NamedObjectSave(); // We'll add "List" or "Instance" below string newName = FileManager.RemovePath(blueprintEntity.Name); #region Set the source type properties for the new NamedObject if (createList) { newName += "List"; newNamedObject.SourceType = SourceType.FlatRedBallType; newNamedObject.SourceClassType = "PositionedObjectList<T>"; newNamedObject.SourceClassGenericType = blueprintEntity.Name; newNamedObject.UpdateCustomProperties(); } else { newName += "Instance"; newNamedObject.SourceType = SourceType.Entity; newNamedObject.SourceClassType = blueprintEntity.Name; newNamedObject.UpdateCustomProperties(); } #endregion #region Set the name for the new NamedObject // get an acceptable name for the new object if (elementToCreateIn.GetNamedObjectRecursively(newName) != null) { newName += "2"; } while (elementToCreateIn.GetNamedObjectRecursively(newName) != null) { newName = StringFunctions.IncrementNumberAtEnd(newName); } newNamedObject.InstanceName = newName; #endregion // We need to add to managers here. Why? Because normally when the type of a NamedObject is changed, // the PropertyGrid handles setting whether it should be added or not. But in this case, we're not changing // the type of the new NamedObject through the PropertyGrid - instead it's being set programatically to be an // Entity. So, we should add to managers programatically since the PropertyGrid won't do it for us. // Update December 11, 2011 // AddToManagers defaults to // true on new NamedObjectSaves // so there's no need to explicitly // set it to true here. //newNamedObject.AddToManagers = true; NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectToElementTreeNode(elementTreeNode, newNamedObject, true); Plugins.PluginManager.ReceiveOutput($"Created {newNamedObject}"); return(newNamedObject); }