コード例 #1
0
        private void CheckForMissingCustomFile(BaseElementTreeNode baseElementTreeNode)
        {
            if (baseElementTreeNode != null)
            {
                IElement element = baseElementTreeNode.SaveObject;

                string fileToSearchFor = FileManager.RelativeDirectory + element.Name + ".cs";

                if (!System.IO.File.Exists(fileToSearchFor))
                {
                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    mbmb.MessageText = "The following file is missing\n\n" + fileToSearchFor +
                                       "\n\nwhich is used by\n\n" + element.ToString() + "\n\nWhat would you like to do?";
                    mbmb.AddButton("Re-create an empty custom code file", DialogResult.OK);
                    mbmb.AddButton("Ignore this problem", DialogResult.Cancel);

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

                    switch (result)
                    {
                    case DialogResult.OK:

                        CodeWriter.GenerateAndAddElementCustomCode(element);

                        break;

                    case DialogResult.Cancel:
                        // Ignore, do nothing
                        break;
                    }
                }
            }
        }
コード例 #2
0
        public static void ShowReadOnlyDialog(string fileName)
        {
            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

            mbmb.StartPosition = FormStartPosition.Manual;

            mbmb.Location = new System.Drawing.Point(MainWindow.MousePosition.X - mbmb.Width / 2,
                                                     MainWindow.MousePosition.Y - mbmb.Height / 2);

            mbmb.MessageText = "Could not save the file\n\n" + fileName + "\n\nbecause it is read-only." +
                               "What would you like to do?";

            mbmb.AddButton("Nothing (file will not save, Gum will continue to work normally)", DialogResult.Cancel);
            mbmb.AddButton("Open folder containing file", DialogResult.OK);

            var dialogResult = mbmb.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                // Let's select the file instead of just opening the folder
                //string folder = FileManager.GetDirectory(fileName);
                //Process.Start(folder);
                Process.Start("explorer.exe", "/select," + fileName);
            }
        }
コード例 #3
0
        private static void ShowErrorMessageBox(ref bool hasUserCancelled, ref string zipToUnpack, string message)
        {
            // todo - eventually make an interface for this, inject it
            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

            mbmb.MessageText = message;
            mbmb.AddButton("Look for the file in the default location", System.Windows.Forms.DialogResult.Yes);
            mbmb.AddButton("Select a .zip file to use", System.Windows.Forms.DialogResult.OK);
            mbmb.AddButton("Nothing - don't create a project", System.Windows.Forms.DialogResult.Cancel);
            var dialogResult = mbmb.ShowDialog();

            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                // do nothing, it'll just look in the default location....
            }
            else if (dialogResult == System.Windows.Forms.DialogResult.OK)
            {
                System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
                fileDialog.InitialDirectory = "c:\\";
                fileDialog.Filter           = "Zipped FRB template (*.zip)|*.zip";
                fileDialog.RestoreDirectory = true;

                if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    zipToUnpack = fileDialog.FileName;
                }
            }
            else if (dialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                hasUserCancelled = true;
            }
        }
コード例 #4
0
ファイル: SetVariableLogic.cs プロジェクト: Kr3m/Gum
        private static bool AskIfShouldCopy(VariableSave variable, string value)
        {
            // Ask the user what to do - make it relative?
            MultiButtonMessageBox mbmb = new
                                         MultiButtonMessageBox();

            mbmb.MessageText = "The file\n" + value + "\nis not relative to the project.  What would you like to do?";
            mbmb.AddButton("Reference the file in its current location", DialogResult.OK);
            mbmb.AddButton("Copy the file relative to the Gum project and reference the copy", DialogResult.Yes);

            var dialogResult = mbmb.ShowDialog();

            bool shouldCopy = false;

            string directory          = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName);
            string targetAbsoluteFile = directory + FileManager.RemovePath(value);

            if (dialogResult == DialogResult.Yes)
            {
                shouldCopy = true;

                // If the destination already exists, we gotta ask the user what they want to do.
                if (System.IO.File.Exists(targetAbsoluteFile))
                {
                    mbmb             = new MultiButtonMessageBox();
                    mbmb.MessageText = "The destination file already exists.  Would you like to overwrite it?";
                    mbmb.AddButton("Yes", DialogResult.Yes);
                    mbmb.AddButton("No, use the original file", DialogResult.No);

                    shouldCopy = mbmb.ShowDialog() == DialogResult.Yes;
                }
            }

            return(shouldCopy);
        }
コード例 #5
0
        private static void CheckForExistingFileOfSameName(string oldName, ReferencedFileSave fileSave, string newFileNameAbsolute, ref bool shouldMove, ref bool shouldContinue)
        {
            if (FileManager.FileExists(newFileNameAbsolute))
            {
                string message = "The new file name already exists.  What would you like to do?";

                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                mbmb.MessageText = message;

                mbmb.AddButton("Use existing file", DialogResult.Yes);
                mbmb.AddButton("Cancel the rename", DialogResult.Cancel);

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


                if (result == DialogResult.Cancel)
                {
                    fileSave.SetNameNoCall(oldName);
                    shouldContinue = false;
                }
                else if (result == DialogResult.Yes)
                {
                    shouldMove = false;
                }
            }
        }
コード例 #6
0
        private void HandleChangedIsContainer(NamedObjectSave nos, IElement element)
        {
            if (nos.IsContainer)
            {
                var existingContainer = element.AllNamedObjects.FirstOrDefault(
                    item => item.IsContainer && item != nos);

                bool succeeded = true;

                if (existingContainer != null)
                {
                    succeeded = false;

                    MessageBox.Show("The object " + existingContainer + " is already marked as IsContainer. " +
                                    "Two objects in the same element cannot be marked as Iscontainer");
                }

                if (succeeded)
                {
                    bool doesBaseMatch = !string.IsNullOrEmpty(element.BaseElement) &&
                                         element.BaseElement == nos.SourceClassType;

                    if (!doesBaseMatch)
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                        string containerType = element.BaseElement;
                        if (string.IsNullOrEmpty(containerType))
                        {
                            containerType = "<NONE>";
                        }


                        mbmb.MessageText = "The object is of type " + nos.SourceClassType + " but the container is of type " + containerType + "\n\n" +
                                           "What would you like to do?";

                        mbmb.AddButton("Set the container's type to " + nos.SourceClassType, DialogResult.Yes);
                        mbmb.AddButton("Nothing - game may not compile until this has been fixed", DialogResult.No);
                        mbmb.AddButton("Set 'IsContainer' back to false", DialogResult.Cancel);

                        var dialogResult = mbmb.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            element.BaseObject = nos.SourceClassType;
                        }
                        else if (dialogResult == DialogResult.Cancel)
                        {
                            succeeded = false;
                        }
                    }
                }

                if (!succeeded)
                {
                    nos.IsContainer = false;
                }
            }
        }
コード例 #7
0
        private static DialogResult AskToReplaceOrRename()
        {
            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

            mbmb.AddButton("Replace original file", DialogResult.Yes);
            mbmb.AddButton("Rename and reference renamed", DialogResult.No);

            mbmb.MessageText = "What would you like to do with the resized file?";

            return(mbmb.ShowDialog());
        }
コード例 #8
0
        void HandleTextureChanged(object sender, MemberChangeArgs memberChangeArgs)
        {
            // Justin has reported a bug here.  I don't know what is going on, so I'm going to spit out the error to a message box
            try
            {
                string fullFileName     = memberChangeArgs.Value as string;
                string emitterDirectory = FileManager.GetDirectory(ProjectManager.Self.FileName);

                if (FileManager.IsRelative(fullFileName))
                {
                    // This file is relative.
                    // This means that the user
                    // typed in a value rather than
                    // using the file window.  We should
                    // assume that the file is relative to
                    // the emitter.
                    fullFileName = emitterDirectory + fullFileName;
                }

                if (!FileManager.IsRelativeTo(fullFileName, emitterDirectory))
                {
                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    mbmb.MessageText = "The selected file:\n\n" + fullFileName + "\n\nis not relative to the Emitter file.  What would you like to do?";

                    mbmb.AddButton("Copy the file to the same folder as the Emitter file", System.Windows.Forms.DialogResult.Yes);
                    mbmb.AddButton("Keep the file where it is (this may limit the portability of the Emitter file)", System.Windows.Forms.DialogResult.No);

                    DialogResult result = mbmb.ShowDialog();

                    if (result == DialogResult.Yes)
                    {
                        string destination = emitterDirectory + FileManager.RemovePath(fullFileName);

                        try
                        {
                            System.IO.File.Copy(fullFileName, destination, true);
                            fullFileName = destination;
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Could not copy the file:\n" + e);
                        }
                    }
                }

                string relativeFileName = FileManager.MakeRelative(fullFileName, emitterDirectory);

                SettingsSaveInstance.Texture = relativeFileName;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
コード例 #9
0
        private bool ResolveDuplicateProjectEntry(bool wasChanged, ProjectItem buildItem)
        {
#if GLUE
            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

            mbmb.MessageText = "The item " + buildItem.UnevaluatedInclude + " is part of " +
                               "the project twice.  Glue does not support double-entries in a project.  What would you like to do?";

            mbmb.AddButton("Remove the duplicate entry and continue", System.Windows.Forms.DialogResult.OK);
            mbmb.AddButton("Remove the duplicate, but show me a list of all contained objects before removal", System.Windows.Forms.DialogResult.No);
            mbmb.AddButton("Cancel loading the project - this will throw an exception", System.Windows.Forms.DialogResult.Cancel);

            DialogResult result;

            if (GlueGui.TryShowDialog(mbmb, out result))
            {
                switch (result)
                {
                case DialogResult.OK:
                    mProject.RemoveItem(buildItem);
                    mProject.ReevaluateIfNecessary();
                    break;

                case DialogResult.No:
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (var item in mProject.AllEvaluatedItems)
                    {
                        stringBuilder.AppendLine(item.ItemType + " " + item.UnevaluatedInclude);
                    }
                    string whereToSave = FileManager.UserApplicationDataForThisApplication + "ProjectFileOutput.txt";
                    FileManager.SaveText(stringBuilder.ToString(), whereToSave);
                    Process.Start(whereToSave);


                    mProject.RemoveItem(buildItem);
                    mProject.ReevaluateIfNecessary();
                    break;

                case DialogResult.Cancel:
                    throw new Exception("Duplicate entries found: " + buildItem.ItemType + " " + buildItem.UnevaluatedInclude);
                }
            }
            else
#endif
            {
                //mProject.EvaluatedItems.RemoveItemAt(i);
                mProject.RemoveItem(buildItem);
                mProject.ReevaluateIfNecessary();
            }
            wasChanged = true;
            return(wasChanged);
        }
コード例 #10
0
        private static DialogResult AskWhatUserWantsToDo()
        {
            MultiButtonMessageBox mbmb;

            mbmb = new MultiButtonMessageBox();
            string message = "What would you like to do?";

            mbmb.MessageText = message;
            mbmb.AddButton("Pad to power of two", System.Windows.Forms.DialogResult.OK);
            mbmb.AddButton("Cancel", System.Windows.Forms.DialogResult.Cancel);

            return(mbmb.ShowDialog());
        }
コード例 #11
0
        public static void LoadActiveSceneFileOk(Window callingWindow)
        {
            MultiButtonMessageBox mbmb = GuiManager.AddMultiButtonMessageBox();

            mbmb.Name = ((FileWindow)callingWindow).Results[0];
            mbmb.Text = "Would you like to load " + ((FileWindow)callingWindow).Results[0] +
                        " as a Blueprint or Blocking Scene?";

            mbmb.AddButton("Blueprint Scene", new GuiMessage(LoadActiveBlueprintScene));
            mbmb.AddButton("Blocking Scene", new GuiMessage(LoadActiveBlockingScene));
            mbmb.AddButton("Cancel", CancelLoadingScene);

            mbmb.ScaleX = 9;
        }
コード例 #12
0
ファイル: ObjectRemover.cs プロジェクト: patridge/Gum
        private bool TryAskForRemovalConfirmation(StateSave stateSave, ElementSave elementSave)
        {
            bool shouldContinue = true;
            // See if the element is used anywhere

            List <InstanceSave> foundInstances = new List <InstanceSave>();

            ObjectFinder.Self.GetElementsReferencing(elementSave, null, foundInstances);

            foreach (var instance in foundInstances)
            {
                // We don't want to go recursively, just top level because
                // I *think* that the lists will include copies of the instances
                // recursively
                ElementSave parent = instance.ParentContainer;

                string variableToLookFor = instance.Name + ".State";

                // loop through all of the states to see if any of the parents' states
                // reference the state that is being removed.
                foreach (var stateInContainer in parent.AllStates)
                {
                    var foundVariable = stateInContainer.Variables.FirstOrDefault(item => item.Name == variableToLookFor);

                    if (foundVariable != null && foundVariable.Value == stateSave.Name)
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                        mbmb.StartPosition = System.Windows.Forms.FormStartPosition.Manual;

                        mbmb.Location = new System.Drawing.Point(MainWindow.MousePosition.X - mbmb.Width / 2,
                                                                 MainWindow.MousePosition.Y - mbmb.Height / 2);

                        mbmb.MessageText = "The state " + stateSave.Name + " is used in the element " +
                                           elementSave + " in its state " + stateInContainer + ".\n  What would you like to do?";

                        mbmb.AddButton("Do nothing - project may be in an invalid state", System.Windows.Forms.DialogResult.No);
                        mbmb.AddButton("Change variable to default", System.Windows.Forms.DialogResult.OK);
                        // eventually will want to add a cancel option

                        if (mbmb.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            foundVariable.Value = "Default";
                        }
                    }
                }
            }

            return(shouldContinue);
        }
コード例 #13
0
        public void SaveSceneClick(string fileName)
        {
            if (!string.IsNullOrEmpty(fileName))
            {
                mLastFileName = fileName;
            }
            List <string> stringArray = new List <string>();

            namesToChange = new SpriteList();
            foreach (Sprite s in GameData.Scene.Sprites)
            {
                if (stringArray.Contains(s.Name))
                {
                    namesToChange.AddOneWay(s);
                }
                else
                {
                    stringArray.Add(s.Name);
                }
            }

            if (AskQuestionsAndDelaySaveIfNecessary(SaveSceneClick))
            {
                if (namesToChange.Count != 0)
                {
                    MultiButtonMessageBox mbmb = GuiManager.AddMultiButtonMessageBox();
                    mbmb.Name = "Duplicate Sprite names found";
                    mbmb.Text = "Duplicate names found in scene.  Duplicate names can alter attachment information.  What would you like to do?";
                    mbmb.AddButton("Leave names as they are and save.", new GuiMessage(OpenFileWindowSaveScene));
                    mbmb.AddButton("Automatically change Sprite names and save.", new GuiMessage(ChangeNamesAndSave));
                    mbmb.AddButton("Cancel save.", null);
                }
                else
                {
                    if (string.IsNullOrEmpty(fileName))
                    {
                        OpenFileWindowSaveScene(null);
                    }
                    else
                    {
                        SaveSceneFileWindowOk(null);
                    }
                }



                ShowWarningsAndMessagesBeforeSaving();
            }
        }
コード例 #14
0
        private void TryHandleFileDropOnComponent(float worldX, float worldY, string[] files, ref bool handled, ref bool shouldUpdate)
        {
            List <ElementWithState> elementStack = new List <ElementWithState>();

            elementStack.Add(new ElementWithState(SelectedState.Self.SelectedElement)
            {
                StateName = SelectedState.Self.SelectedStateSave.Name
            });

            // see if it's over the component:
            IPositionedSizedObject ipsoOver = SelectionManager.Self.GetRepresentationAt(worldX, worldY, false, elementStack);

            if (ipsoOver?.Tag is ComponentSave component && (component.BaseType == "Sprite" || component.BaseType == "NineSlice"))
            {
                string fileName = FileManager.MakeRelative(files[0], FileLocations.Self.ProjectFolder);

                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                mbmb.StartPosition = FormStartPosition.Manual;

                mbmb.Location = new Point(MainWindow.MousePosition.X - mbmb.Width / 2,
                                          MainWindow.MousePosition.Y - mbmb.Height / 2);

                mbmb.MessageText = "What do you want to do with the file " + fileName;

                mbmb.AddButton("Set source file on " + component.Name, DialogResult.OK);
                mbmb.AddButton("Add new Sprite", DialogResult.Yes);
                mbmb.AddButton("Nothing", DialogResult.Cancel);


                var result = mbmb.ShowDialog();

                if (result == DialogResult.OK)
                {
                    var oldValue = SelectedState.Self.SelectedStateSave
                                   .GetValueOrDefault <string>("SourceFile");

                    SelectedState.Self.SelectedStateSave.SetValue("SourceFile", fileName);
                    ProjectState.Self.Selected.SelectedInstance = null;
                    SetVariableLogic.Self.PropertyValueChanged("SourceFile", oldValue);

                    shouldUpdate = true;
                    handled      = true;
                }
                else if (result == DialogResult.Cancel)
                {
                    handled = true;
                }
            }
        }
コード例 #15
0
        private static MultiButtonMessageBox CreateMbmb(string fileName)
        {
            MultiButtonMessageBox newMbmb = new MultiButtonMessageBox(GuiManager.Cursor);

            newMbmb.ScaleX = 20;
            newMbmb.Text   = "Replace or Insert this file?\n\n" + fileName;

            newMbmb.Name = "";

            newMbmb.AddButton("Replace", ReplaceClicked);
            newMbmb.AddButton("Insert", InsertClicked);
            newMbmb.AddButton("Advanced >>", AdvancedClick);
            newMbmb.AddButton("Cancel", null);
            return(newMbmb);
        }
コード例 #16
0
        private static void AskToPreserveVariables(EntitySave entitySave, List<CustomVariable> variablesBefore)
        {
            foreach (CustomVariable oldVariable in variablesBefore)
            {
                if (entitySave.GetCustomVariableRecursively(oldVariable.Name) == null)
                {
                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    string message = "The variable\n\n" + oldVariable.ToString() + "\n\nIs no longer part of the Entity.  What do you want to do?";

                    mbmb.MessageText = message;

                    mbmb.AddButton("Add a new variable with the same name and type to " + entitySave.Name, DialogResult.Yes);
                    mbmb.AddButton("Nothing - the variable will go away", DialogResult.No);

                    DialogResult result = mbmb.ShowDialog();

                    if (result == DialogResult.Yes)
                    {
                        CustomVariable newVariable = new CustomVariable();
                        newVariable.Type = oldVariable.Type;
                        newVariable.Name = oldVariable.Name;
                        newVariable.DefaultValue = oldVariable.DefaultValue;
                        newVariable.SourceObject = oldVariable.SourceObject;
                        newVariable.SourceObjectProperty = oldVariable.SourceObjectProperty;

                        newVariable.Properties = new List<PropertySave>();
                        newVariable.Properties.AddRange(oldVariable.Properties);

                        newVariable.HasAccompanyingVelocityProperty = oldVariable.HasAccompanyingVelocityProperty;
                        newVariable.CreatesEvent = oldVariable.CreatesEvent;
                        newVariable.IsShared = oldVariable.IsShared;

                        if (!string.IsNullOrEmpty(oldVariable.OverridingPropertyType))
                        {
                            newVariable.OverridingPropertyType = oldVariable.OverridingPropertyType;
                            newVariable.TypeConverter = oldVariable.TypeConverter;
                        }

                        newVariable.CreatesEvent = oldVariable.CreatesEvent;

                        entitySave.CustomVariables.Add(newVariable);

                    }

                }
            }
        }
コード例 #17
0
        private void TryHandleFileDropOnInstance(float worldX, float worldY, string[] files, ref bool handled, ref bool shouldUpdate)
        {
            // This only supports drag+drop on an instance, but what if dropping on a component
            // which inherits from Sprite, or perhaps an instance that has an exposed file variable?
            // Not super high priority, but it's worth noting that this currently doesn't work...
            InstanceSave instance = FindInstanceWithSourceFile(worldX, worldY);

            if (instance != null)
            {
                string fileName = FileManager.MakeRelative(files[0], FileLocations.Self.ProjectFolder);

                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                mbmb.StartPosition = FormStartPosition.Manual;

                mbmb.Location = new Point(MainWindow.MousePosition.X - mbmb.Width / 2,
                                          MainWindow.MousePosition.Y - mbmb.Height / 2);

                mbmb.MessageText = "What do you want to do with the file " + fileName;

                mbmb.AddButton("Set source file on " + instance.Name, DialogResult.OK);
                mbmb.AddButton("Add new Sprite", DialogResult.Yes);
                mbmb.AddButton("Nothing", DialogResult.Cancel);

                var result = mbmb.ShowDialog();

                if (result == DialogResult.OK)
                {
                    var oldValue = SelectedState.Self.SelectedStateSave
                                   .GetValueOrDefault <string>(instance.Name + ".SourceFile");

                    SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".SourceFile", fileName, instance);
                    ProjectState.Self.Selected.SelectedInstance = instance;
                    SetVariableLogic.Self.PropertyValueChanged("SourceFile", oldValue);

                    shouldUpdate = true;
                    handled      = true;
                }
                else if (result == DialogResult.Cancel)
                {
                    handled = true;
                }
                // continue for DialogResult.Yes
            }
        }
コード例 #18
0
        public static bool TryAskToMoveFileRelativeToAnimationChainFile(bool copyWithoutAsking, ref string absoluteFileName, out string achxFolder)
        {
            bool shouldProceed = true;

            achxFolder = FileManager.GetDirectory(ProjectManager.Self.FileName);

            if (ShouldAskUserToCopyFile(absoluteFileName))
            {
                DialogResult result = DialogResult.Yes;

                if (!copyWithoutAsking)
                {
                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    mbmb.MessageText = "The selected file:\n\n" + absoluteFileName + "\n\nis not relative to the Animation Chain file.  What would you like to do?";

                    mbmb.AddButton("Copy the file to the same folder as the Animation Chain", System.Windows.Forms.DialogResult.Yes);
                    mbmb.AddButton("Keep the file where it is (this may limit the portability of the Animation Chain file)", System.Windows.Forms.DialogResult.No);

                    result = mbmb.ShowDialog();
                }

                if (result == DialogResult.Yes)
                {
                    string destination = achxFolder + FileManager.RemovePath(absoluteFileName);

                    try
                    {
                        System.IO.File.Copy(absoluteFileName, destination, true);
                        absoluteFileName = destination;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Could not copy the file:\n" + e);
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    shouldProceed = false;
                }
            }

            return(shouldProceed);
        }
コード例 #19
0
        private bool DeserializeGluxXmlInternal(string projectFileName, string glueProjectFile)
        {
            bool succeeded = true;

            try
            {
                ProjectManager.GlueProjectSave = GlueProjectSaveExtensions.Load(glueProjectFile);

                string errors;
                ProjectManager.GlueProjectSave.PostLoadInitialize(out errors);

                if (errors != null)
                {
                    GlueGui.ShowMessageBox(errors);
                }
            }
            catch (Exception e)
            {
                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                mbmb.MessageText = "There was an error loading the .glux file.  What would you like to do?";

                mbmb.AddButton("Nothing - Glue will abort loading the project.", DialogResult.None);
                mbmb.AddButton("See the Exception", DialogResult.OK);
                mbmb.AddButton("Try loading again", DialogResult.Retry);
                mbmb.AddButton("Test for conflicts", DialogResult.Yes);

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

                switch (result)
                {
                case DialogResult.None:
                    // Do nothing;

                    break;

                case DialogResult.OK:
                    MessageBox.Show(e.ToString());
                    break;

                case DialogResult.Retry:
                    LoadProject(projectFileName);
                    break;

                case DialogResult.Yes:
                    string text = FileManager.FromFileText(glueProjectFile);

                    if (text.Contains("<<<"))
                    {
                        MessageBox.Show("There are conflicts in your GLUX file.  You will need to use a merging " +
                                        "tool or text editor to resolve these conflicts.");
                    }
                    else
                    {
                        MessageBox.Show("No Subversion conflicts found in your GLUX.");
                    }
                    break;
                }
                succeeded = false;
            }
            return(succeeded);
        }
コード例 #20
0
        private void CreateEntityTreeNodes()
        {
            //ProjectManager.GlueProjectSave.Entities[78].NamedObjects[9].UpdateCustomProperties();


            // Let's make this faster.
            //foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            // Actually, the contained functions may show popups, and if 2 simultaneous popups
            // are shown, one can cancel the other out and this can cause Glue to freeze. This means
            // we can't parallel foreah it
            //Parallel.ForEach(ProjectManager.GlueProjectSave.Entities, (entity) =>
            foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            {
                entity.UpdateCustomProperties();
                entity.UpdateFromBaseType();
            }

            for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
            {
                EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i];
                // This is so fast that we no longer need to show the
                // user details - and not doing it will make things even faster
                //SetInitWindowText("Creating Entity: " + entitySave.Name);

                EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode(entitySave.Name);

                #region If there is no EntityTreeNode

                if (entityTreeNode == null)
                {
                    // See if the file exists
                    string fileToSearchFor = FileManager.RelativeDirectory + entitySave.Name + ".cs";

                    if (System.IO.File.Exists(fileToSearchFor))
                    {
                        // If we got here that means there's probably not a build item for this file
                        MessageBox.Show("The Glue project has the following Entity:\n" + entitySave.Name + "\n" +
                                        "but this file is not part of Visual Studio.  This file may have been removed manually or " +
                                        "there may have been some saving error.  You should close Glue, manually add this and the Generated file " +
                                        "to Visual Studio, then restart Glue.");
                        MainGlueWindow.Self.HasErrorOccurred = true;
                    }
                    else
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                        mbmb.MessageText = "Could not find the file name\n\n" + fileToSearchFor + "\n\nwhich is used by the entity\n\n" + entitySave.Name + "\n\n" +
                                           "What would you like to do?";


                        mbmb.AddButton("Create a new custom code file", DialogResult.Yes);
                        mbmb.AddButton("Delete this Entity", DialogResult.No);
                        mbmb.AddButton("Do nothing.  The Entity will not show up in Glue until this problem is fixed.", DialogResult.Cancel);

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

                        switch (result)
                        {
                        case DialogResult.Yes:
                            if (entityTreeNode == null)
                            {
                                entityTreeNode = ElementViewWindow.AddEntity(entitySave);
                            }

                            CodeWriter.GenerateAndAddElementCustomCode(entitySave);

                            //entityTreeNode.GenerateCode(ProjectManager.EntityTemplateCode);

                            break;

                        case DialogResult.No:
                            ProjectManager.GlueProjectSave.Entities.RemoveAt(i);
                            i--;
                            continue;

                        //break;
                        case DialogResult.Cancel:
                            // do nothing
                            continue;

                            //break;
                        }

                        System.Windows.Forms.MessageBox.Show("Could not create the EntitySave for " + entitySave.Name +
                                                             " because the following file doesn't exist\n\n" + fileToSearchFor);
                    }
                    //mGlueProjectSave.Entities.RemoveAt(i);
                    //i--;
                }

                #endregion


                entityTreeNode.EntitySave = entitySave;

                CheckForMissingCustomFile(entityTreeNode);


                entityTreeNode.UpdateReferencedTreeNodes();

                // moved above
                //entityTreeNode.EntitySave.UpdateCustomProperties();
                //entityTreeNode.EntitySave.UpdateFromBaseType();
            }
        }
コード例 #21
0
        private void ReactIfChangedMemberIsTexture(ElementSave parentElement, string changedMember, object oldValue)
        {
            VariableSave variable = SelectedState.Self.SelectedVariableSave;

            // Eventually need to handle tunneled variables
            if (variable != null && variable.GetRootName() == "SourceFile")
            {
                string value = variable.Value as string;

                if (!string.IsNullOrEmpty(value))
                {
                    // See if this is relative to the project
                    bool isRelativeToProject = !value.StartsWith("../") && !value.StartsWith("..\\");

                    if (!isRelativeToProject)
                    {
                        // Ask the user what to do - make it relative?
                        MultiButtonMessageBox mbmb = new
                                                     MultiButtonMessageBox();

                        mbmb.MessageText = "The file\n" + value + "\nis not relative to the project.  What would you like to do?";
                        mbmb.AddButton("Reference the file in its current location", DialogResult.OK);
                        mbmb.AddButton("Copy the file relative to the Gum project and reference the copy", DialogResult.Yes);

                        var dialogResult = mbmb.ShowDialog();

                        bool shouldCopy = false;

                        string directory          = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName);
                        string targetAbsoluteFile = directory + FileManager.RemovePath(value);

                        if (dialogResult == DialogResult.Yes)
                        {
                            shouldCopy = true;

                            // If the destination already exists, we gotta ask the user what they want to do.
                            if (System.IO.File.Exists(targetAbsoluteFile))
                            {
                                mbmb             = new MultiButtonMessageBox();
                                mbmb.MessageText = "The destination file already exists.  Would you like to overwrite it?";
                                mbmb.AddButton("Yes", DialogResult.Yes);
                                mbmb.AddButton("No, use the original file", DialogResult.No);

                                shouldCopy = mbmb.ShowDialog() == DialogResult.Yes;
                            }
                        }

                        if (shouldCopy)
                        {
                            try
                            {
                                string sourceAbsoluteFile =
                                    directory + value;
                                sourceAbsoluteFile = FileManager.RemoveDotDotSlash(sourceAbsoluteFile);

                                System.IO.File.Copy(sourceAbsoluteFile, targetAbsoluteFile, overwrite: true);

                                variable.Value = FileManager.RemovePath(value);
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show("Error copying file:\n" + e.ToString());
                            }
                        }
                    }
                }


                StateSave stateSave = SelectedState.Self.SelectedStateSave;

                RecursiveVariableFinder rvf = new RecursiveVariableFinder(stateSave);

                stateSave.SetValue("AnimationFrames", new List <string>());
            }
        }
コード例 #22
0
        public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List <string> additionalFilesToRemove, bool regenerateCode)
        {
            var isContained = GlueState.Self.Find.IfReferencedFileSaveIsReferenced(referencedFileToRemove);

            /////////////////////////Early Out//////////////////////////////
            if (!isContained)
            {
                return;
            }
            ////////////////////////End Early Out/////////////////////////////



            // There are some things that need to happen:
            // 1.  Remove the ReferencedFileSave from the Glue project (GLUX)
            // 2.  Remove the GUI item
            // 3.  Remove the item from the Visual Studio project.
            IElement container = referencedFileToRemove.GetContainer();

            #region Remove the file from the current Screen or Entity if there is a current Screen or Entity

            if (container != null)
            {
                // The referenced file better be a globally referenced file


                if (!container.ReferencedFiles.Contains(referencedFileToRemove))
                {
                    throw new ArgumentException();
                }
                else
                {
                    container.ReferencedFiles.Remove(referencedFileToRemove);
                }
                // Ask about any NamedObjects that reference this file.
                for (int i = container.NamedObjects.Count - 1; i > -1; i--)
                {
                    var nos = container.NamedObjects[i];
                    if (nos.SourceType == SourceType.File && nos.SourceFile == referencedFileToRemove.Name)
                    {
                        MainGlueWindow.Self.Invoke(() =>
                        {
                            // Ask the user what to do here - remove it?  Keep it and not compile?
                            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                            mbmb.MessageText           = "The object\n" + nos.ToString() + "\nreferences the file\n" + referencedFileToRemove.Name +
                                                         "\nWhat would you like to do?";
                            mbmb.AddButton("Remove this object", DialogResult.Yes);
                            mbmb.AddButton("Keep it (object will not be valid until changed)", DialogResult.No);

                            var result = mbmb.ShowDialog();

                            if (result == DialogResult.Yes)
                            {
                                container.NamedObjects.RemoveAt(i);
                            }
                        });
                    }
                    nos.ResetVariablesReferencing(referencedFileToRemove);
                }

                MainGlueWindow.Self.Invoke(() =>
                {
                    if (EditorLogic.CurrentScreenTreeNode != null)
                    {
                        EditorLogic.CurrentScreenTreeNode.UpdateReferencedTreeNodes();
                    }
                    else if (EditorLogic.CurrentEntityTreeNode != null)
                    {
                        EditorLogic.CurrentEntityTreeNode.UpdateReferencedTreeNodes();
                    }
                    if (regenerateCode)
                    {
                        ElementViewWindow.GenerateSelectedElementCode();
                    }
                });
            }
            #endregion

            #region else, the file is likely part of the GlobalContentFile

            else
            {
                ProjectManager.GlueProjectSave.GlobalFiles.Remove(referencedFileToRemove);
                ProjectManager.GlueProjectSave.GlobalContentHasChanged = true;

                // Much faster to just remove the tree node.  This was done
                // to reuse code and make things reactive, but this has gotten
                // slow on bigger projects.
                //ElementViewWindow.UpdateGlobalContentTreeNodes(false); // don't save here because projects will get saved below

                Action refreshUiAction = () =>
                {
                    TreeNode treeNode = GlueState.Self.Find.ReferencedFileSaveTreeNode(referencedFileToRemove);
                    if (treeNode != null)
                    {
                        // treeNode can be null if the user presses delete + enter really really fast, stacking 2 remove
                        // actions
                        if (treeNode.Tag != referencedFileToRemove)
                        {
                            throw new Exception("Error removing the tree node - the selected tree node doesn't reference the file being removed");
                        }

                        treeNode.Parent.Nodes.Remove(treeNode);
                    }
                };

                MainGlueWindow.Self.Invoke((MethodInvoker) delegate
                {
                    refreshUiAction();
                }
                                           );


                GlobalContentCodeGenerator.UpdateLoadGlobalContentCode();

                List <IElement> elements = ObjectFinder.Self.GetAllElementsReferencingFile(referencedFileToRemove.Name);

                foreach (IElement element in elements)
                {
                    if (regenerateCode)
                    {
                        CodeWriter.GenerateCode(element);
                    }
                }
            }

            #endregion


            // November 10, 2015
            // I feel like this may
            // have been old code before
            // we had full dependency tracking
            // in Glue. This file should only be
            // removed from the project if nothing
            // else references it, including no entities.
            // This code does just entities/screens/global
            // content, but doesn't check the full dependency
            // tree. I think we can just remove it and depend on
            // the code below.
            // Actually, removing this seems to cause problems - files
            // that should be removed aren't. So instead we'll chnage the
            // call to use the dependency tree:
            // replace:

            List <string> referencedFiles =
                GlueCommands.Self.FileCommands.GetAllReferencedFileNames().Select(item => item.ToLowerInvariant()).ToList();

            string absoluteToLower   = GlueCommands.Self.GetAbsoluteFileName(referencedFileToRemove).ToLowerInvariant();
            string relativeToProject = FileManager.MakeRelative(absoluteToLower, GlueState.Self.ContentDirectory);

            bool isReferencedByOtherContent = referencedFiles.Contains(relativeToProject);

            if (isReferencedByOtherContent == false)
            {
                additionalFilesToRemove.Add(referencedFileToRemove.GetRelativePath());

                string itemName     = referencedFileToRemove.GetRelativePath();
                string absoluteName = ProjectManager.MakeAbsolute(referencedFileToRemove.Name, true);

                // I don't know why we were removing the file from the ProjectBase - it should
                // be from the Content project
                //ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase, itemName);
                ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase.ContentProject, itemName, performSave: false);

                foreach (ProjectBase syncedProject in ProjectManager.SyncedProjects)
                {
                    ProjectManager.RemoveItemFromProject(syncedProject.ContentProject, absoluteName);
                }
            }



            if (ProjectManager.IsContent(referencedFileToRemove.Name))
            {
                UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false);
                foreach (var file in UnreferencedFilesManager.LastAddedUnreferencedFiles)
                {
                    additionalFilesToRemove.Add(file.FilePath);
                }
            }

            ReactToRemovalIfCsv(referencedFileToRemove, additionalFilesToRemove);

            GluxCommands.Self.SaveGlux();
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        private void ReactToTextureAddressMode(NamedObjectSave namedObjectSave, object oldValue)
        {
            bool isSprite = namedObjectSave.SourceType == SourceType.FlatRedBallType && namedObjectSave.SourceClassType == "Sprite";

            if (isSprite)
            {
                var addressModeVariable = namedObjectSave.GetCustomVariable("TextureAddressMode");

                if (addressModeVariable != null && addressModeVariable.Value != null &&
                    ((TextureAddressMode)(addressModeVariable.Value) == TextureAddressMode.Wrap || (TextureAddressMode)(addressModeVariable.Value) == TextureAddressMode.Mirror))
                {
                    // How big is the texture?
                    var textureVariable = namedObjectSave.GetCustomVariable("Texture");

                    if (textureVariable != null && textureVariable.Value != null)
                    {
                        string value = textureVariable.Value as string;

                        var rfs = namedObjectSave.GetContainer().GetReferencedFileSaveByInstanceName(value);

                        if (rfs != null)
                        {
                            var width = ImageHeader.GetDimensions(
                                ProjectManager.MakeAbsolute(rfs.Name)).Width;
                            var height = ImageHeader.GetDimensions(
                                ProjectManager.MakeAbsolute(rfs.Name)).Height;

                            string whatIsWrong = null;

                            if (FlatRedBall.Math.MathFunctions.IsPowerOfTwo(width) == false)
                            {
                                whatIsWrong = "This Sprite's texture (" + textureVariable.Value + ") has a width of " +
                                              width + " but it should be a power of two to use " + addressModeVariable.Value + " TextureAddressMode";
                            }


                            if (FlatRedBall.Math.MathFunctions.IsPowerOfTwo(height) == false)
                            {
                                whatIsWrong = "This Sprite's texture (" + textureVariable.Value + ") has a height of " +
                                              height + " but it should be a power of two to use " + addressModeVariable.Value + " TextureAddressMode";
                            }

                            if (!string.IsNullOrEmpty(whatIsWrong))
                            {
                                whatIsWrong += "\nWhat would you like to do?";

                                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                                mbmb.MessageText = whatIsWrong;
                                mbmb.AddButton("Undo the change", DialogResult.Cancel);
                                mbmb.AddButton("Keep the change (May cause runtime crashes)", DialogResult.Yes);

                                var result = mbmb.ShowDialog();

                                if (result == DialogResult.Cancel)
                                {
                                    addressModeVariable.Value = oldValue;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #25
0
        public static void RemoveNamedObject(NamedObjectSave namedObjectToRemove, bool performSave, bool updateUi, List <string> additionalFilesToRemove)
        {
            StringBuilder removalInformation = new StringBuilder();

            // The additionalFilesToRemove is included for consistency with other methods.  It may be used later

            // There are the following things that need to happen:
            // 1.  Remove the NamedObject from the Glue project (GLUX)
            // 2.  Remove any variables that use this NamedObject as their source
            // 3.  Remove the named object from the GUI
            // 4.  Update the variables for any NamedObjects that use this element containing this NamedObject
            // 5.  Find any Elements that contain NamedObjects that are DefinedByBase - if so, see if we should remove those or make them not DefinedByBase
            // 6.  Remove any events that tunnel into this.

            IElement element = namedObjectToRemove.GetContainer();

            if (element != null)
            {
                if (!namedObjectToRemove.RemoveSelfFromNamedObjectList(element.NamedObjects))
                {
                    throw new ArgumentException();
                }

                #region Remove all CustomVariables that reference the removed NamedObject
                for (int i = element.CustomVariables.Count - 1; i > -1; i--)
                {
                    CustomVariable variable = element.CustomVariables[i];

                    if (variable.SourceObject == namedObjectToRemove.InstanceName)
                    {
                        removalInformation.AppendLine("Removed variable " + variable.ToString());

                        element.CustomVariables.RemoveAt(i);
                    }
                }
                #endregion

                // Remove any events that use this
                for (int i = element.Events.Count - 1; i > -1; i--)
                {
                    EventResponseSave ers = element.Events[i];
                    if (ers.SourceObject == namedObjectToRemove.InstanceName)
                    {
                        removalInformation.AppendLine("Removed event " + ers.ToString());
                        element.Events.RemoveAt(i);
                    }
                }

                // Remove any objects that use this as a layer
                for (int i = 0; i < element.NamedObjects.Count; i++)
                {
                    if (element.NamedObjects[i].LayerOn == namedObjectToRemove.InstanceName)
                    {
                        removalInformation.AppendLine("Removed the following object from the deleted Layer: " + element.NamedObjects[i].ToString());
                        element.NamedObjects[i].LayerOn = null;
                    }
                }



                element.RefreshStatesToCustomVariables();

                #region Ask the user what to do with all NamedObjects that are DefinedByBase

                List <IElement> derivedElements = new List <IElement>();
                if (element is EntitySave)
                {
                    derivedElements.AddRange(ObjectFinder.Self.GetAllEntitiesThatInheritFrom(element as EntitySave));
                }
                else
                {
                    derivedElements.AddRange(ObjectFinder.Self.GetAllScreensThatInheritFrom(element as ScreenSave));
                }

                foreach (IElement derivedElement in derivedElements)
                {
                    // At this point, namedObjectToRemove is already removed from the current Element, so this will only
                    // return NamedObjects that exist in the derived.
                    NamedObjectSave derivedNamedObject = derivedElement.GetNamedObjectRecursively(namedObjectToRemove.InstanceName);

                    if (derivedNamedObject != null && derivedNamedObject != namedObjectToRemove && derivedNamedObject.DefinedByBase)
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                        mbmb.MessageText = "What would you like to do with the object " + derivedNamedObject.ToString();
                        mbmb.AddButton("Keep it", DialogResult.OK);
                        mbmb.AddButton("Delete it", DialogResult.Cancel);

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

                        if (result == DialogResult.OK)
                        {
                            // Keep it
                            derivedNamedObject.DefinedByBase = false;
                            BaseElementTreeNode treeNode = GlueState.Self.Find.ElementTreeNode(derivedElement);

                            if (updateUi)
                            {
                                treeNode.UpdateReferencedTreeNodes();
                            }
                            CodeWriter.GenerateCode(derivedElement);
                        }
                        else
                        {
                            // Delete it
                            RemoveNamedObject(derivedNamedObject, performSave, updateUi, additionalFilesToRemove);
                        }
                    }
                }
                #endregion


                var elementTreeNode = GlueState.Self.Find.ElementTreeNode(element);

                if (updateUi)
                {
                    elementTreeNode.UpdateReferencedTreeNodes();
                }
                CodeWriter.GenerateCode(element);
                if (element is EntitySave)
                {
                    List <NamedObjectSave> entityNamedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(element.Name);

                    foreach (NamedObjectSave nos in entityNamedObjects)
                    {
                        nos.UpdateCustomProperties();
                    }
                }
            }

            if (performSave)
            {
                GluxCommands.Self.SaveGlux();
            }
        }
コード例 #26
0
        public static bool UpdateNamedObjectsFromBaseType(INamedObjectContainer namedObjectContainer)
        {
            bool haveChangesOccurred = false;

            List <NamedObjectSave> referencedObjectsBeforeUpdate = new List <NamedObjectSave>();

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                if (namedObjectContainer.NamedObjects[i].DefinedByBase)
                {
                    referencedObjectsBeforeUpdate.Add(namedObjectContainer.NamedObjects[i]);
                }
            }

            List <NamedObjectSave> namedObjectsSetByDerived     = new List <NamedObjectSave>();
            List <NamedObjectSave> namedObjectsExposedInDerived = new List <NamedObjectSave>();

            List <INamedObjectContainer> baseElements = new List <INamedObjectContainer>();

            // June 1, 2011:
            // The following code
            // was using AddRange instead
            // of manually looping, but this
            // is only possible in .NET 4.0, and
            // GlueView still uses 3.1.
            // July 24, 2011
            // Before today, this
            // code would loop through
            // all base Entities and search
            // for SetByDerived properties in
            // any NamedObjectSave. This caused
            // bugs.  Basically if you had 3 Elements
            // in an inheritance chain and the one at the
            // very base defined a NOS to be SetByDerived, then
            // anything that inherited directly from the base should
            // be forced to define it.  If it does, then the 3rd Element
            // in the inheritance chain shouldn't have to define it, but before
            // to day it did.  This caused a lot of problems including generated
            // code creating the element twice.
            if (namedObjectContainer is EntitySave)
            {
                if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
                {
                    baseElements.Add(ObjectFinder.Self.GetIElement(namedObjectContainer.BaseObject));
                }
                //List<EntitySave> allBase = ((EntitySave)namedObjectContainer).GetAllBaseEntities();
                //foreach (EntitySave baseEntitySave in allBase)
                //{
                //    baseElements.Add(baseEntitySave);
                //}
            }
            else
            {
                if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
                {
                    baseElements.Add(ObjectFinder.Self.GetIElement(namedObjectContainer.BaseObject));
                }
                //List<ScreenSave> allBase = ((ScreenSave)namedObjectContainer).GetAllBaseScreens();
                //foreach (ScreenSave baseScreenSave in allBase)
                //{
                //    baseElements.Add(baseScreenSave);
                //}
            }


            foreach (INamedObjectContainer baseNamedObjectContainer in baseElements)
            {
                if (baseNamedObjectContainer != null)
                {
                    namedObjectsSetByDerived.AddRange(baseNamedObjectContainer.GetNamedObjectsToBeSetByDerived());
                    namedObjectsExposedInDerived.AddRange(baseNamedObjectContainer.GetNamedObjectsToBeExposedInDerived());
                }
            }

            #region See if there are any objects to be removed from the derived.
            for (int i = referencedObjectsBeforeUpdate.Count - 1; i > -1; i--)
            {
                bool contains = false;

                for (int j = 0; j < namedObjectsSetByDerived.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[i].InstanceName == namedObjectsSetByDerived[j].InstanceName &&
                        referencedObjectsBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                for (int j = 0; j < namedObjectsExposedInDerived.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[i].InstanceName == namedObjectsExposedInDerived[j].InstanceName &&
                        referencedObjectsBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                if (!contains)
                {
                    NamedObjectSave nos = referencedObjectsBeforeUpdate[i];

                    string message = "The following object is marked as \"defined by base\" but it is not contained in " +
                                     "any base elements\n\n" + nos.ToString() + "\n\nWhat would you like to do?";

                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                    mbmb.MessageText = message;

                    mbmb.AddButton("Remove " + nos.ToString(), DialogResult.Yes);
                    mbmb.AddButton("Keep it, make it not \"defined by base\"", DialogResult.No);

                    DialogResult result = mbmb.ShowDialog();

                    if (result == DialogResult.Yes)
                    {
                        // We got a NamedObject we should remove
                        namedObjectContainer.NamedObjects.Remove(nos);
                        referencedObjectsBeforeUpdate.RemoveAt(i);
                    }
                    else
                    {
                        nos.DefinedByBase      = false;
                        nos.InstantiatedByBase = false;
                    }
                    haveChangesOccurred = true;
                }
            }
            #endregion

            #region Next, see if there are any objects to be added
            for (int i = 0; i < namedObjectsSetByDerived.Count; i++)
            {
                NamedObjectSave namedObjectSetByDerived = namedObjectsSetByDerived[i];

                NamedObjectSave matchingDefinedByBase = null;// contains = false;
                for (int j = 0; j < referencedObjectsBeforeUpdate.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[j].InstanceName == namedObjectSetByDerived.InstanceName &&
                        referencedObjectsBeforeUpdate[j].DefinedByBase)
                    {
                        matchingDefinedByBase = referencedObjectsBeforeUpdate[j];
                        break;
                    }
                }

                if (matchingDefinedByBase == null)
                {
                    AddSetByDerivedNos(namedObjectContainer, namedObjectSetByDerived, false);
                }
                else
                {
                    MatchDerivedToBase(namedObjectSetByDerived, matchingDefinedByBase);
                }
            }

            for (int i = 0; i < namedObjectsExposedInDerived.Count; i++)
            {
                NamedObjectSave namedObjectSetByDerived = namedObjectsExposedInDerived[i];

                NamedObjectSave matchingDefinedByBase = null;// contains = false;
                for (int j = 0; j < referencedObjectsBeforeUpdate.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[j].InstanceName == namedObjectSetByDerived.InstanceName &&
                        referencedObjectsBeforeUpdate[j].DefinedByBase)
                    {
                        matchingDefinedByBase = referencedObjectsBeforeUpdate[j];
                        break;
                    }
                }

                if (matchingDefinedByBase == null)
                {
                    AddSetByDerivedNos(namedObjectContainer, namedObjectSetByDerived, true);
                }
                else
                {
                    MatchDerivedToBase(namedObjectSetByDerived, matchingDefinedByBase);
                }
            }

            #endregion

            return(haveChangesOccurred);
        }
コード例 #27
0
ファイル: DragDropManager.cs プロジェクト: jiailiuyan/Gum
        internal void HandleFileDragDrop(object sender, DragEventArgs e)
        {
            if (!CanDrop())
            {
                return;
            }

            float worldX, worldY;

            Renderer.Self.Camera.ScreenToWorld(Cursor.X, Cursor.Y, out worldX, out worldY);

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            // If only one file was dropped, see if we're over an instance that can take a file
            if (files.Length == 1)
            {
                if (!ValidExtension(files[0]))
                {
                    return;
                }

                InstanceSave instance = FindInstanceWithSourceFile(worldX, worldY);
                if (instance != null)
                {
                    string fileName = FileManager.MakeRelative(files[0], FileLocations.Self.ProjectFolder);

                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    mbmb.MessageText = "What do you want to do with the file " + fileName;

                    mbmb.AddButton("Set source file on " + instance.Name, DialogResult.OK);
                    mbmb.AddButton("Add new Sprite", DialogResult.Yes);
                    mbmb.AddButton("Nothing", DialogResult.Cancel);

                    var result = mbmb.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".SourceFile", fileName, instance);
                        SaveAndRefresh();
                        return;
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                    // continue for DialogResult.Yes
                }
            }

            bool shouldUpdate = false;

            foreach (string file in files)
            {
                if (!ValidExtension(file))
                {
                    continue;
                }

                string fileName = FileManager.MakeRelative(file, FileLocations.Self.ProjectFolder);
                AddNewInstanceForDrop(fileName, worldX, worldY);
                shouldUpdate = true;
            }

            if (shouldUpdate)
            {
                SaveAndRefresh();
            }
        }
コード例 #28
0
        private void ReactToChangedNosSourceName(NamedObjectSave namedObjectSave, string oldValue)
        {
            IElement container = EditorLogic.CurrentElement;

            if (!string.IsNullOrEmpty(container.BaseElement) && !string.IsNullOrEmpty(namedObjectSave.InstanceType))
            {
                IElement baseElement = ObjectFinder.Self.GetIElement(container.BaseElement);


                NamedObjectSave namedObjectInBase = baseElement.GetNamedObjectRecursively(namedObjectSave.InstanceName);


                if (namedObjectInBase == null)
                {
                    // This is not a valid setup - what do we do here?
                }
                else
                {
                    if (namedObjectInBase.InstanceType != namedObjectSave.InstanceType)
                    {
                        if (string.IsNullOrEmpty(namedObjectInBase.InstanceType))
                        {
                            string message = "This object has type of " + namedObjectSave.InstanceType +
                                             " but the base object in " + baseElement.ToString() + " is untyped.  What would you like to do?";

                            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                            mbmb.MessageText = message;

                            mbmb.AddButton("Change " + namedObjectInBase.InstanceName + " to " +
                                           namedObjectSave.InstanceType + " in " + baseElement.ToString(), DialogResult.Yes);

                            mbmb.AddButton("Do nothing (your project will likely not compile so you will need to fix this manually)", DialogResult.No);

                            DialogResult result = mbmb.ShowDialog();

                            if (result == DialogResult.Yes)
                            {
                                switch (namedObjectInBase.SourceType)
                                {
                                case SourceType.File:
                                    // The base needs to be a FlatRedBallType
                                    namedObjectInBase.SourceType      = SourceType.FlatRedBallType;
                                    namedObjectInBase.SourceClassType = namedObjectSave.InstanceType;


                                    break;

                                case SourceType.FlatRedBallType:
                                    namedObjectInBase.SourceType      = SourceType.FlatRedBallType;
                                    namedObjectInBase.SourceClassType = namedObjectSave.SourceClassType;
                                    break;

                                case SourceType.Entity:
                                    namedObjectInBase.SourceType      = SourceType.Entity;
                                    namedObjectInBase.SourceClassType = namedObjectSave.SourceClassType;
                                    break;
                                }
                                namedObjectInBase.UpdateCustomProperties();

                                CodeWriter.GenerateCode(baseElement);
                            }
                        }
                        else
                        {
                            string message = "This object is of type " + namedObjectSave.InstanceType + " but the base " +
                                             "object is of type " + namedObjectInBase.InstanceType + "";

                            MessageBox.Show(message);

                            namedObjectSave.SourceName = oldValue;
                        }
                    }
                }
            }
        }
コード例 #29
0
        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
        }
コード例 #30
0
        private static void ResolveElementReferences(IElement newElement)
        {
            #region See if the newly-added IElement has any NamedObjectSaves that reference Entities, and if so try to fix those references

            foreach (NamedObjectSave nos in newElement.AllNamedObjects)
            {
                if (nos.SourceType == SourceType.Entity)
                {
                    //todo:  handle lists too
                    if (!string.IsNullOrEmpty(nos.SourceClassType))
                    {
                        List <IElement> candidates = ObjectFinder.Self.GetElementsUnqualified(FileManager.RemovePath(nos.SourceClassType));

                        if (candidates.Count == 0)
                        {
                            MessageBox.Show(newElement.ToString() + " has an object named " + nos.InstanceName + " which references an Entity " + nos.SourceClassType + "\n\n" +
                                            "Could not find a matching Entity.  Your project may not run properly until this issue is resolved.");
                        }
                        else
                        {
                            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                            mbmb.MessageText = "Glue found possible matches for the object " + nos.InstanceName + " which expects the type " + nos.SourceClassType;

                            foreach (IElement candidate in candidates)
                            {
                                mbmb.AddButton("Use " + candidate.ToString(), DialogResult.OK, candidate);
                            }
                            mbmb.AddButton("Don't do anything", DialogResult.Cancel);

                            DialogResult result = mbmb.ShowDialog();

                            if (result == DialogResult.OK)
                            {
                                IElement referenceToSet = (IElement)mbmb.ClickedTag;

                                nos.SourceClassType = referenceToSet.Name;
                                nos.UpdateCustomProperties();


                                // The nos type has changed, so we should try to resolve enums
                                nos.FixEnumerationTypes();
                            }
                        }
                    }
                }
            }

            #endregion

            #region See if this IElement fixes any existing invalid references

            foreach (IElement element in ProjectManager.GlueProjectSave.Entities)
            {
                if (element != newElement)
                {
                    SeeIfElementSolvesMissingReferences(element, newElement);
                }
            }
            foreach (IElement element in ProjectManager.GlueProjectSave.Screens)
            {
                if (element != newElement)
                {
                    SeeIfElementSolvesMissingReferences(element, newElement);
                }
            }


            #endregion
        }