Beispiel #1
0
        public static void AddNamedObjectToCurrentNamedObjectList(NamedObjectSave namedObject)
        {
            namedObject.AddToManagers = true;

            NamedObjectSave parentNamedObject = EditorLogic.CurrentNamedObject;

            parentNamedObject.ContainedObjects.Add(namedObject);

            EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();

            // Since it's part of a list we know its type
            string typeOfNewObject = parentNamedObject.SourceClassGenericType;

            if (ObjectFinder.Self.GetEntitySave(typeOfNewObject) != null)
            {
                namedObject.SourceType = SourceType.Entity;

                namedObject.SourceClassType = typeOfNewObject;
                namedObject.UpdateCustomProperties();
            }
            else if (AvailableClassTypeConverter.IsFlatRedBallType(typeOfNewObject))
            {
                namedObject.SourceType      = SourceType.FlatRedBallType;
                namedObject.SourceClassType = typeOfNewObject;
                namedObject.UpdateCustomProperties();
            }

            // Highlight the newly created object
            TreeNode newNode = GlueState.Self.Find.NamedObjectTreeNode(namedObject);

            if (newNode != null)
            {
                MainGlueWindow.Self.ElementTreeView.SelectedNode = newNode;
            }
        }
        private void PopulateFlatRedBallAndCustomTypes()
        {
            List <string> addedTypes = new List <string>();

            addedTypes.AddRange(AvailableClassTypeConverter.GetAvailableTypes(false, SourceType.FlatRedBallType));
            addedTypes.Sort();

            IEnumerable <string> availableTypes = addedTypes;

            if (!string.IsNullOrEmpty(this.SearchTextBox.Text))
            {
                availableTypes = availableTypes.Where(item => item.ToLower().Contains(SearchTextBox.Text.ToLower()));
            }

            FlatRedBallTypesTreeView.Nodes.Clear();

            foreach (var available in availableTypes)
            {
                FlatRedBallTypesTreeView.Nodes.Add(available);
            }
        }
Beispiel #3
0
        private static AddObjectViewModel CreateAndShowAddNamedObjectWindow(AddObjectViewModel addObjectViewModel = null)
        {
            TextInputWindow tiw = new TextInputWindow();

            tiw.Message = "Enter the new object's name";
            tiw.Text    = "New Object";
            // If windows is zoomed, the text may not wrap properly, so increase it:
            tiw.Width = 450;

            var currentObject = GlueState.Self.CurrentNamedObjectSave;

            bool isTypePredetermined = currentObject != null && currentObject.IsList;

            if (addObjectViewModel == null)
            {
                addObjectViewModel = new AddObjectViewModel();
            }

            var toAdd = AvailableClassTypeConverter.GetAvailableTypes(false, SourceType.FlatRedBallType)
                        .ToList();

            toAdd.Sort();

            foreach (var item in toAdd)
            {
                addObjectViewModel.FlatRedBallAndCustomTypes.Add(item);
            }

            NewObjectTypeSelectionControl typeSelectControl = null;

            if (!isTypePredetermined)
            {
                tiw.Width = 400;

                typeSelectControl       = new NewObjectTypeSelectionControl(addObjectViewModel);
                typeSelectControl.Width = tiw.Width - 22;

                typeSelectControl.AfterStrongSelect += delegate
                {
                    tiw.ClickOk();
                };

                typeSelectControl.AfterSelect += delegate(object sender, EventArgs args)
                {
                    string result = tiw.Result;

                    bool isDefault = string.IsNullOrEmpty(result);

                    // Victor Chelaru November 3, 2012
                    // I don't know if we want to only re-assign when default.
                    // The downside is that the user may have already entered a
                    // name, an then changed the type.  This would result in the
                    // user-entered name being overwritten.  However, if we don't
                    // change the name, then an old name that the user entered which
                    // is specific to the type may not get reset.  I'm leaning towards
                    // always changing the name to help prevent misnaming, and it's also
                    // less programatically complex.
                    //if (isDefault)
                    {
                        string newName;

                        if (!string.IsNullOrEmpty(typeSelectControl.SourceFile) && !string.IsNullOrEmpty(typeSelectControl.SourceName))
                        {
                            newName = HandleObjectInFileSelected(typeSelectControl);
                        }
                        else if (string.IsNullOrEmpty(typeSelectControl.SourceClassType))
                        {
                            newName = "ObjectInstance";
                        }
                        else
                        {
                            var classType = typeSelectControl.SourceClassType;
                            if (classType?.Contains(".") == true)
                            {
                                // un-qualify if it's something like "FlatRedBall.Sprite"
                                var lastIndex = classType.LastIndexOf(".");
                                classType = classType.Substring(lastIndex + 1);
                            }
                            string textToAssign = classType + "Instance";
                            if (textToAssign.Contains("/") || textToAssign.Contains("\\"))
                            {
                                textToAssign = FileManager.RemovePath(textToAssign);
                            }

                            newName = textToAssign.Replace("<T>", "");
                        }

                        // We need to make sure this is a unique name.
                        newName    = StringFunctions.MakeStringUnique(newName, EditorLogic.CurrentElement.AllNamedObjects);
                        tiw.Result = newName;
                    }
                };

                if (addObjectViewModel != null)
                {
                    typeSelectControl.SourceType = addObjectViewModel.SourceType;
                    typeSelectControl.SourceFile = addObjectViewModel.SourceFile;
                }


                tiw.AddControl(typeSelectControl, AboveOrBelow.Above);
            }


            addObjectViewModel.DialogResult = tiw.ShowDialog();

            addObjectViewModel.SourceType             = SourceType.FlatRedBallType;
            addObjectViewModel.SourceClassType        = null;
            addObjectViewModel.SourceFile             = null;
            addObjectViewModel.SourceNameInFile       = null;
            addObjectViewModel.SourceClassGenericType = null;
            addObjectViewModel.ObjectName             = tiw.Result;

            if (isTypePredetermined)
            {
                var parentList = GlueState.Self.CurrentNamedObjectSave;

                var genericType = parentList.SourceClassGenericType;

                if (!string.IsNullOrEmpty(genericType))
                {
                    addObjectViewModel.SourceClassType = genericType;

                    // the generic type will be fully qualified (like FlatRedBall.Sprite)
                    // but object types for FRB primitives are not qualified, so we need to remove
                    // any dots

                    if (addObjectViewModel.SourceClassType.Contains("."))
                    {
                        int lastDot = addObjectViewModel.SourceClassType.LastIndexOf('.');

                        addObjectViewModel.SourceClassType = addObjectViewModel.SourceClassType.Substring(lastDot + 1);
                    }

                    if (ObjectFinder.Self.GetEntitySave(genericType) != null)
                    {
                        addObjectViewModel.SourceType = SourceType.Entity;
                    }
                    else
                    {
                        addObjectViewModel.SourceType = SourceType.FlatRedBallType;
                    }
                }
            }

            if (typeSelectControl != null)
            {
                if (!string.IsNullOrEmpty(typeSelectControl.SourceClassType) || typeSelectControl.SourceType == SourceType.File)
                {
                    addObjectViewModel.SourceType = typeSelectControl.SourceType;
                }
                addObjectViewModel.SourceFile       = typeSelectControl.SourceFile;
                addObjectViewModel.SourceNameInFile = typeSelectControl.SourceName;

                addObjectViewModel.SourceClassType        = typeSelectControl.SourceClassType;
                addObjectViewModel.SourceClassGenericType = typeSelectControl.SourceClassGenericType;
            }

            return(addObjectViewModel);
        }