private static void AskToCreateEntity(out TextInputWindow tiw, out ControlForAddingCollision collisionControl, out DialogResult result)
        {
            tiw             = new TextInputWindow();
            tiw.DisplayText = "Enter entity name:";

            collisionControl = new ControlForAddingCollision();

            tiw.AddControl(collisionControl);

            result = tiw.ShowDialog();
        }
Example #2
0
        internal void ElementInstance()
        {
            if (ArrowState.Self.CurrentArrowElementSave != null)
            {
                //Show a text input window for the name, but add a combo box so the user can select the type
                TextInputWindow tiw = new TextInputWindow();

                TreeView treeView = new TreeView();
                treeView.HorizontalAlignment = HorizontalAlignment.Stretch;
                treeView.VerticalAlignment   = VerticalAlignment.Top;
                treeView.Height = 80;
                treeView.Margin = new Thickness(3);

                List <ArrowElementSave> toAddToTreeView = new List <ArrowElementSave>();

                foreach (var elementSave in ArrowState.Self.CurrentArrowProject.Elements)
                {
                    if (elementSave != null && elementSave != ArrowState.Self.CurrentArrowElementSave)
                    {
                        toAddToTreeView.Add(elementSave);
                    }
                }

                treeView.ItemsSource = toAddToTreeView;

                tiw.AddControl(treeView);



                bool?result = tiw.ShowDialog();

                if (result.HasValue && result.Value)
                {
                    ArrowElementSave typeToAdd = treeView.SelectedItem as ArrowElementSave;

                    string name = tiw.Result;

                    ElementInstance(name, typeToAdd);
                }
                //tiw.AddControl
            }
        }
Example #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;

            NewObjectTypeSelectionControl typeSelectControl = null;

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

                typeSelectControl       = new NewObjectTypeSelectionControl();
                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);
            }

            if (addObjectViewModel == null)
            {
                addObjectViewModel = new AddObjectViewModel();
            }
            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);
        }