private static bool DragDropNosIntoElement(NamedObjectSave movingNos, IElement elementMovingInto)
        {
            bool succeeded = true;

            // moving to another element, so let's copy
            NamedObjectSave clonedNos = movingNos.Clone();

            UpdateNosAfterDragDrop(clonedNos, elementMovingInto);

            elementMovingInto.NamedObjects.Add(clonedNos);

            var referenceCheck = ProjectManager.VerifyReferenceGraph(elementMovingInto);

            if (referenceCheck == ProjectManager.CheckResult.Failed)
            {
                succeeded = false;
                // VerifyReferenceGraph (currently) shows a popup so we don't have to here
                //MessageBox.Show("This movement would result in a circular reference");

                elementMovingInto.NamedObjects.Remove(clonedNos);
            }

            if (succeeded)
            {
                // If an object which was on a Layer
                // is moved into another Element, then
                // the cloned object probably shouldn't
                // be on a layer.  Not sure if we want to
                // see if there is a Layer with the same-name
                // but we maybe shouldn't assume that they mean
                // the same thing.
                clonedNos.LayerOn = null;

                BaseElementTreeNode treeNodeForElementMovedInto = GlueState.Self.Find.ElementTreeNode(elementMovingInto);
                treeNodeForElementMovedInto.UpdateReferencedTreeNodes();
                CodeGeneratorIElement.GenerateElementDerivedAndReferenced(elementMovingInto);

                MessageBox.Show("Copied\n" + movingNos + "\n\nto\n" + clonedNos);
            }
            return(succeeded);
        }
        private static void ReactToChangedImplementsIVisible(object oldValue, EntitySave entitySave)
        {
            #region If the user turned IVisible off, see if there is a "Visible" Exposed Variable
            if (((bool)oldValue) == true)
            {
                CustomVariable variableToRemove = entitySave.GetCustomVariable("Visible");
                if (variableToRemove != null)
                {
                    List<string> throwawayList = new List<string>();

                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    mbmb.MessageText = "This entity has a \"Visible\" variable exposed.  This variable is no longer valid.  What would you like to do?";
                    mbmb.AddButton("Remove this variable", DialogResult.Yes);
                    mbmb.AddButton("Keep this as a non-functional Variable (it will no longer control the object's visibility)", DialogResult.No);

                    DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self);

                    if (result == DialogResult.Yes)
                    {
                        ProjectManager.RemoveCustomVariable(variableToRemove, throwawayList);
                    }
                    else
                    {
                        // No need to do anything
                    }
                }
            }
            #endregion

            #region If the user turned IVisible on, see if there are any NamedObjectSaves that reference Elements that are not IVisible

            if (entitySave.ImplementsIVisible)
            {
                foreach (NamedObjectSave nos in entitySave.AllNamedObjects)
                {
                    if (nos.SourceType == SourceType.Entity || nos.IsList)
                    {

                        EntitySave nosEntitySave = null;

                        if (nos.SourceType == SourceType.Entity)
                        {
                            nosEntitySave = ObjectFinder.Self.GetEntitySave(nos.SourceClassType);
                        }
                        else
                        {
                            nosEntitySave = ObjectFinder.Self.GetEntitySave(nos.SourceClassGenericType);
                        }

                        if (nosEntitySave != null && nosEntitySave.ImplementsIVisible == false)
                        {
                            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                            mbmb.MessageText = entitySave + " implements IVisible, but its object " + nos + " does not.  Would would you like to do?";

                            mbmb.AddButton("Make " + nosEntitySave + " implement IVisible", DialogResult.Yes);
                            mbmb.AddButton("Ignore " + nos + " when setting Visible on " + entitySave, DialogResult.No);
                            mbmb.AddButton("Do nothing - this will likely cause compile errors so this must be fixed manually", DialogResult.Cancel);

                            DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self);

                            if (result == DialogResult.Yes)
                            {
                                nosEntitySave.ImplementsIVisible = true;

                                CodeGeneratorIElement.GenerateElementDerivedAndReferenced(nosEntitySave);
                            }
                            else if (result == DialogResult.No)
                            {
                                nos.IncludeInIVisible = false;
                            }
                            else if (result == DialogResult.Cancel)
                            {
                                // do nothing - the user better fix this!
                            }
                        }
                    }
                }
            }
            #endregion

            #region If it's a ScrollableEntityList, then the item it's using must also be an IVisible

            if (entitySave.ImplementsIVisible && entitySave.IsScrollableEntityList && !string.IsNullOrEmpty(entitySave.ItemType))
            {
                EntitySave itemTypeAsEntity = ObjectFinder.Self.GetEntitySave(entitySave.ItemType);

                if (itemTypeAsEntity != null && itemTypeAsEntity.ImplementsIVisible == false)
                {
                    MessageBox.Show("The item type " + itemTypeAsEntity.ToString() + " must also implement IVisible.  Glue will do this now");

                    itemTypeAsEntity.ImplementsIVisible = true;

                    // Gotta regen this thing
                    var entityForItem = ObjectFinder.Self.GetIElement(entitySave.ItemType);
                    CodeWriter.GenerateCode(entityForItem);
                }
            }

            #endregion
        }
예제 #3
0
        public void ReactToPropertyChanged(string variableNameAsDisplayed, object oldValue, string variableName, string parentGridItemName)
        {
            var mPropertyGrid = MainGlueWindow.Self.PropertyGrid;


            bool updateTreeView = true;

            #region EventResponseSave
            if (EditorLogic.CurrentEventResponseSave != null)
            {
                Container.Get <EventResponseSaveSetVariableLogic>().ReactToChange(
                    variableNameAsDisplayed, oldValue, GlueState.Self.CurrentEventResponseSave, GlueState.Self.CurrentElement);
            }

            #endregion

            #region State

            else if (EditorLogic.CurrentStateSave != null)
            {
                Container.Get <StateSaveSetVariableLogic>().ReactToStateSaveChangedValue(
                    EditorLogic.CurrentStateSave, EditorLogic.CurrentStateSaveCategory, variableNameAsDisplayed, oldValue, EditorLogic.CurrentElement, ref updateTreeView);
            }

            #endregion

            #region StateCategory

            else if (EditorLogic.CurrentStateSaveCategory != null)
            {
                Container.Get <StateSaveCategorySetVariableLogic>().ReactToStateSaveCategoryChangedValue(
                    EditorLogic.CurrentStateSaveCategory, variableNameAsDisplayed, oldValue, EditorLogic.CurrentElement, ref updateTreeView);
            }

            #endregion

            #region NamedObject

            else if (EditorLogic.CurrentNamedObject != null)
            {
                Container.Get <NamedObjectSetVariableLogic>().ReactToNamedObjectChangedValue(
                    variableNameAsDisplayed, parentGridItemName, oldValue);
            }

            #endregion

            #region ReferencedFile

            else if (EditorLogic.CurrentReferencedFile != null)
            {
                Container.Get <ReferencedFileSaveSetVariableLogic>().ReactToChangedReferencedFile(
                    variableNameAsDisplayed, oldValue, ref updateTreeView);
            }

            #endregion

            #region CustomVariable

            else if (EditorLogic.CurrentCustomVariable != null)
            {
                Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue(
                    variableNameAsDisplayed, EditorLogic.CurrentCustomVariable, oldValue);
            }
            else if (mPropertyGrid.SelectedObject != null && mPropertyGrid.SelectedObject is PropertyGridDisplayer &&
                     EditorLogic.CurrentElement != null && EditorLogic.CurrentElement.GetCustomVariableRecursively(variableName) != null)
            {
                Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue(
                    variableName, EditorLogic.CurrentElement.GetCustomVariableRecursively(variableName), oldValue);
            }
            #endregion

            // Check Entities and Screens after checking variables and objects
            #region Entity
            else if (EditorLogic.CurrentEntitySave != null)
            {
                Container.Get <EntitySaveSetVariableLogic>().ReactToEntityChangedValue(variableNameAsDisplayed, oldValue);
            }

            #endregion

            #region ScreenSave

            else if (EditorLogic.CurrentScreenSave != null)
            {
                Container.Get <ScreenSaveSetVariableLogic>().ReactToScreenChangedValue(variableNameAsDisplayed, oldValue);
            }

            #endregion

            #region Global content container node

            else if (EditorLogic.CurrentTreeNode.Root().IsGlobalContentContainerNode())
            {
                Container.Get <GlobalContentSetVariableLogic>().ReactToGlobalContentChangedValue(
                    variableNameAsDisplayed, oldValue, ref updateTreeView);
            }

            #endregion


            PluginManager.ReactToChangedProperty(variableNameAsDisplayed, oldValue);

            if (EditorLogic.CurrentElement != null)
            {
                CodeGeneratorIElement.GenerateElementDerivedAndReferenced(EditorLogic.CurrentElement);
            }
            else if (EditorLogic.CurrentReferencedFile != null)
            {
                ContentLoadWriter.UpdateLoadGlobalContentCode();
            }

            // UpdateCurrentObjectReferencedTreeNodes
            // kicks off a save by default.  Therefore
            // we don't need to call SaveProjects if UpdateCurrentObjectReferencedTreeNodes
            // is called.
            if (updateTreeView)
            {
                ElementViewWindow.UpdateCurrentObjectReferencedTreeNodes();
            }
            else
            {
                ProjectManager.SaveProjects();
            }

            mPropertyGrid.Refresh();

            GluxCommands.Self.SaveGlux();

            // Vic says:  This was intented to refresh the variables at one point
            // but this is a messy feature.  I think we should just refresh the entire
            // glux whenever a change is made now that it's async
            //RemotingManager.RefreshVariables(false);
        }
        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);
        }