Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void TestNamedObjectSave()
        {
            EntitySave entitySave = new EntitySave();

            NamedObjectSave nos = new NamedObjectSave();

            string whyNot;

            NameVerifier.IsNamedObjectNameValid("Parent", nos, out whyNot);
            if (string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("Parent should not be  avalid name for a PositionedObject, but Glue allows it");
            }
        }
Ejemplo n.º 4
0
        private static string HandleObjectInFileSelected(NewObjectTypeSelectionControl typeSelectControl)
        {
            string newName;
            var    spaceParen = typeSelectControl.SourceName.IndexOf(" (");

            if (spaceParen != -1)
            {
                newName = typeSelectControl.SourceName.Substring(0, spaceParen);
            }
            else
            {
                newName = typeSelectControl.SourceName;
            }

            // If the user selected "Entire File" we want to make sure the space doesn't show up:
            newName = newName.Replace(" ", "");

            string throwaway;
            bool   isInvalid = NameVerifier.IsNamedObjectNameValid(newName, out throwaway);

            if (!isInvalid)
            {
                // let's get the type:
                var split = typeSelectControl.SourceName.Split('(', ')');

                var last = split.LastOrDefault(item => !string.IsNullOrEmpty(item));

                if (last != null)
                {
                    var lastDot = last.LastIndexOf('.');

                    newName = last.Substring(lastDot + 1, last.Length - (lastDot + 1));
                }
            }

            return(newName);
        }
Ejemplo n.º 5
0
        private void ReactToNamedObjectChangedInstanceName(NamedObjectSave namedObjectSave, object oldValueAsObject)
        {
            string oldValue = (string)oldValueAsObject;

            #region Fail checks

            string whyItIsntValid;

            NameVerifier.IsNamedObjectNameValid(namedObjectSave.InstanceName, out whyItIsntValid);

            if (!string.IsNullOrEmpty(whyItIsntValid))
            {
                GlueGui.ShowMessageBox(whyItIsntValid);
                namedObjectSave.InstanceName = oldValue;
            }
            #endregion

            else
            {
                IElement currentElement = EditorLogic.CurrentElement;

                string baseObject = ((IElement)EditorLogic.CurrentElement).BaseObject;
                // See if the entity has a base and if the base contains this name
                if (!string.IsNullOrEmpty(baseObject))
                {
                    INamedObjectContainer baseNamedObjectContainer = ObjectFinder.Self.GetNamedObjectContainer(baseObject);

                    NamedObjectSave baseNamedObject = baseNamedObjectContainer.GetNamedObjectRecursively(namedObjectSave.InstanceName);

                    if (baseNamedObject != null)
                    {
                        if (baseNamedObject.SetByDerived)
                        {
                            // There is a base element that has an object with the same
                            // name as the derived element.  The derived doesn't have a same-named
                            // object already, and the base is SetByDerived, so let's setup the derived
                            // to use the base and notify the user.
                            namedObjectSave.DefinedByBase = true;
                            MessageBox.Show("This object has the same name as\n\n" + baseNamedObject.ToString() + "\n\nIt is SetByDerived, " +
                                            "so Glue will use this as the base object for the object " + namedObjectSave.InstanceName);
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("A base object already has an object with this name");
                            namedObjectSave.InstanceName = oldValue;
                        }
                    }
                }

                if (currentElement != null)
                {
                    // See if any named objects in this instance use this for tunneling

                    foreach (CustomVariable customVariable in currentElement.CustomVariables)
                    {
                        if (!string.IsNullOrEmpty(customVariable.SourceObject) && customVariable.SourceObject == oldValue)
                        {
                            MessageBox.Show("Changing the variable " + customVariable.Name + " so it uses " + namedObjectSave.InstanceName + " instead of " + (string)oldValue);

                            customVariable.SourceObject = namedObjectSave.InstanceName;
                        }
                    }

                    // See if any events tunnel to this NOS
                    foreach (EventResponseSave eventResponseSave in currentElement.Events)
                    {
                        if (!string.IsNullOrEmpty(eventResponseSave.SourceObject) && eventResponseSave.SourceObject == oldValue)
                        {
                            MessageBox.Show("Chaing the Event " + eventResponseSave.EventName + " so it uses " + namedObjectSave.InstanceName + " instead of " + oldValue);

                            eventResponseSave.SourceObject = namedObjectSave.InstanceName;
                        }
                    }
                }

                // If this is a layer, see if any other NOS's use this as their Layer
                if (namedObjectSave.IsLayer)
                {
                    List <NamedObjectSave> namedObjectList = EditorLogic.CurrentElement.NamedObjects;

                    string oldLayerName = (string)oldValue;

                    foreach (NamedObjectSave nos in namedObjectList)
                    {
                        nos.ReplaceLayerRecursively(oldLayerName, namedObjectSave.InstanceName);
                    }
                }
            }
        }