Beispiel #1
0
        public static GumProjectSave Load(string fileName, out string errors)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                errors = "Passed null file name, could not load GumProjectSave";
                return(null);
            }

            GumProjectSave gps = null;

                        #if ANDROID
            gps = LoadFromTitleStorage(fileName, out errors);
            #else
            if (System.IO.File.Exists(fileName))
            {
                gps = FileManager.XmlDeserialize <GumProjectSave>(fileName);
            }
            else
            {
                errors = "The Gum project file does not exist";
            }
            #endif

            string projectRootDirectory = FileManager.GetDirectory(fileName);

            gps.PopulateElementSavesFromReferences(projectRootDirectory, out errors);
            gps.FullFileName = fileName;

            return(gps);
        }
Beispiel #2
0
 /// <summary>
 /// Adds any Standard Elements that have been created since the project was last saved.  This should be called
 /// when the project is first loaded.
 /// </summary>
 /// <param name="gumProjectSave">The gum project to add to</param>
 public static void AddNewStandardElementTypes(this GumProjectSave gumProjectSave)
 {
     foreach (string typeName in StandardElementsManager.Self.DefaultTypes)
     {
         if (typeName != "Screen" && !gumProjectSave.StandardElements.ContainsName(typeName))
         {
             StandardElementsManager.Self.AddStandardElementSaveInstance(
                 gumProjectSave, typeName);
         }
     }
 }
Beispiel #3
0
        static GumProjectSave LoadFromTitleStorage(string fileName, LinkLoadingPreference linkLoadingPreference, GumLoadResult result)
        {
            using (System.IO.Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(fileName))
            {
                GumProjectSave gps = FileManager.XmlDeserializeFromStream <GumProjectSave>(stream);

                gps.FullFileName = fileName;

                return(gps);
            }
        }
Beispiel #4
0
        static GumProjectSave LoadFromTitleStorage(string fileName, GumLoadResult result)
        {
            using (System.IO.Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(fileName))
            {
                GumProjectSave gps = FileManager.XmlDeserializeFromStream <GumProjectSave>(stream);

                string projectRootDirectory = FileManager.GetDirectory(fileName);

                gps.PopulateElementSavesFromReferences(projectRootDirectory, result);

                gps.FullFileName = fileName;

                return(gps);
            }
        }
Beispiel #5
0
        public static void FixStandardVariables(this GumProjectSave gumProjectSave)
        {
            foreach (var element in gumProjectSave.StandardElements)
            {
                var defaultState = StandardElementsManager.Self.GetDefaultStateFor(element.Name);

                foreach (var variable in defaultState.Variables)
                {
                    var variableInLoadedElement = element.DefaultState.GetVariableSave(variable.Name);

                    variableInLoadedElement.CanOnlyBeSetInDefaultState = variable.CanOnlyBeSetInDefaultState;
                    variableInLoadedElement.DesiredOrder = variable.DesiredOrder;
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Adds any Standard Elements that have been created since the project was last saved.  This should be called
        /// when the project is first loaded.
        /// </summary>
        /// <param name="gumProjectSave">The gum project to add to</param>
        public static bool AddNewStandardElementTypes(this GumProjectSave gumProjectSave)
        {
            bool modified = false;

            foreach (string typeName in StandardElementsManager.Self.DefaultTypes)
            {
                if (typeName != "Screen" && !gumProjectSave.StandardElements.ContainsName(typeName))
                {
                    StandardElementsManager.Self.AddStandardElementSaveInstance(
                        gumProjectSave, typeName);
                    modified = true;
                }
            }
            return(modified);
        }
        public GlueProjectSave ToGlueProjectSave(GumProjectSave gumProjectSave, string gluxFolder)
        {
            mGluxFolder = gluxFolder;
            mGumProjectSave = gumProjectSave;
            mInstanceToNos.GumProjectSave = mGumProjectSave;

            GlueProjectSave toReturn = new GlueProjectSave();
            mGlueProjectSave = toReturn;

            var copiedFiles = CopyExternalFilesToProjects();

            AddScreensAndEntities(copiedFiles);

            return toReturn;
        }
Beispiel #8
0
 public static void RemoveDuplicateVariables(this GumProjectSave gumProjectSave)
 {
     foreach (var component in gumProjectSave.Components)
     {
         RemoveDuplicateVariables(component);
     }
     foreach (var screen in gumProjectSave.Screens)
     {
         RemoveDuplicateVariables(screen);
     }
     foreach (var element in gumProjectSave.StandardElements)
     {
         RemoveDuplicateVariables(element);
     }
 }
Beispiel #9
0
        public static GumProjectSave Load(string fileName, out GumLoadResult result)
        {
            result = new GumLoadResult();
            if (string.IsNullOrEmpty(fileName))
            {
                result.ErrorMessage = "Passed null file name, could not load GumProjectSave";
                return(null);
            }

            if (FileManager.IsRelative(fileName))
            {
                fileName = FileManager.MakeAbsolute(fileName);
            }

            GumProjectSave gps = null;

#if ANDROID || IOS || WINDOWS_8
            gps = LoadFromTitleStorage(fileName, result);
#else
            try
            {
                gps = FileManager.XmlDeserialize <GumProjectSave>(fileName);
            }
            catch (FileNotFoundException)
            {
                result.MissingFiles.Add(fileName);
                return(null);
            }
            catch (IOException ex)
            {
                result.ErrorMessage = ex.Message;
                return(null);
            }
#endif

            string projectRootDirectory = FileManager.GetDirectory(fileName);

            gps.PopulateElementSavesFromReferences(projectRootDirectory, result);
            gps.FullFileName = fileName.Replace('\\', '/');

            return(gps);
        }
Beispiel #10
0
        internal void ProjectSave(GumProjectSave savedProject)
        {
            foreach (var plugin in this.Plugins)
            {
                PluginContainer container = this.PluginContainers[plugin];

                if (container.IsEnabled)
                {
                    try
                    {
                        plugin.CallProjectSave(savedProject);
                    }
                    catch (Exception e)
                    {
            #if DEBUG
                        MessageBox.Show("Error in plugin " + plugin.FriendlyName + ":\n\n" + e.ToString());
            #endif
                        container.Fail(e, "Failed in ProjectSave");
                    }
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Initializes the GumProjectSave for editing in Gum.  This means
        /// adding any variables that are necessary, fixing enumerations, and
        /// checking for other errors.
        /// </summary>
        /// <param name="gumProjectSave">The GumProjectSave</param>
        public static bool Initialize(this GumProjectSave gumProjectSave)
        {
            bool wasModified = false;

            gumProjectSave.ScreenReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.StandardElementReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.BehaviorReferences.Sort((first, second) =>
            {
                if (first.Name == null)
                {
                    return(0);
                }
                else
                {
                    return(first.Name.CompareTo(second.Name));
                }
            });

            gumProjectSave.Screens.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.Components.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.StandardElements.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.Behaviors.Sort((first, second) => first.Name?.CompareTo(second.Name) ?? 0);

            // Do StandardElements first
            // because the values here are
            // used by components to set their
            // ignored enum values.
            foreach (StandardElementSave standardElementSave in gumProjectSave.StandardElements)
            {
                StateSave stateSave = StandardElementsManager.Self.GetDefaultStateFor(standardElementSave.Name);
                // this will result in extra variables being
                // added
                wasModified = standardElementSave.Initialize(stateSave) || wasModified;

                stateSave.ParentContainer = standardElementSave;
            }

            foreach (ScreenSave screenSave in gumProjectSave.Screens)
            {
                var stateSave = StandardElementsManager.Self.GetDefaultStateFor("Screen");
                wasModified = screenSave.Initialize(stateSave) || wasModified;
            }



            foreach (ComponentSave componentSave in gumProjectSave.Components)
            {
                // June 27, 2012
                // We used to pass
                // null here because
                // passing a non-null
                // variable meant replacing
                // the existing StateSave with
                // the argument StateSave.  However,
                // now when the type of a Component is
                // changed, old values are not removed, but
                // are rather preserved so that changing the
                // type doesn't wipe out old values.
                //componentSave.Initialize(null);

                // October 17, 2017
                // We used to pass in
                // the base StandardElementSave
                // to copy the variables to the Component.
                // This is redundant. It adds data, makes things
                // slower...I just don't think we need it. It's especially
                // bad at runtime in games that are redundantly setting variables
                // which may result in reflection.
                //StateSave defaultStateSave = null;
                //StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(componentSave);
                //if (ses != null)
                //{
                //    defaultStateSave = ses.DefaultState;
                //}

                if (componentSave.Initialize(new StateSave {
                    Name = "Default"
                }))
                {
                    wasModified = true;
                }

                if (componentSave.Initialize(StandardElementsManager.Self.GetDefaultStateFor("Component")))
                {
                    wasModified = true;
                }
            }

            foreach (var behavior in gumProjectSave.Behaviors)
            {
                if (behavior.Initialize())
                {
                    wasModified = true;
                }
            }

            if (gumProjectSave.Version < 1)
            {
                // This means that all default variables have SetValue = false
                // We need to fix that
                foreach (StandardElementSave standardElementSave in gumProjectSave.StandardElements)
                {
                    var defaultState = standardElementSave.DefaultState;

                    foreach (var variable in defaultState.Variables)
                    {
                        if (variable.IsState(standardElementSave) == false)
                        {
                            variable.SetsValue = true;
                        }
                    }
                }

                foreach (var component in gumProjectSave.Components)
                {
                    // We only want to do this on components that don't inherit from other components:
                    var baseComponent = ObjectFinder.Self.GetComponent(component.BaseType);

                    if (baseComponent == null)
                    {
                        var defaultState = component.DefaultState;


                        foreach (var variable in defaultState.Variables)
                        {
                            if (variable.IsState(component) == false)
                            {
                                variable.SetsValue = true;
                            }
                        }
                    }
                }
                gumProjectSave.Version = 1;
                wasModified            = true;
            }

            return(wasModified);
        }
        public StandardElementSave AddStandardElementSaveInstance(GumProjectSave gumProjectSave, string type)
        {
            StandardElementSave elementSave = new StandardElementSave();
            elementSave.Initialize(mDefaults[type]);
            elementSave.Name = type;

            
            gumProjectSave.StandardElementReferences.Add( new ElementReference { Name = type, ElementType = ElementType.Standard});
            gumProjectSave.StandardElements.Add( elementSave);

            return elementSave;
        }
Beispiel #13
0
        public void CreateNewProject()
        {
            mGumProjectSave = new GumProjectSave();
            ObjectFinder.Self.GumProjectSave = mGumProjectSave;

            StandardElementsManager.Self.PopulateProjectWithDefaultStandards(mGumProjectSave);
            // Now that a new project is created, refresh the UI!
            GumCommands.Self.GuiCommands.RefreshElementTreeView();

            PluginManager.Self.ProjectLoad(mGumProjectSave);
        }
Beispiel #14
0
 public void CallProjectSave(GumProjectSave savedProject)
 {
     if (AfterProjectSave != null)
     {
         AfterProjectSave(savedProject);
     }
 }
Beispiel #15
0
 public void CallBeforeProjectSave(GumProjectSave savedProject)
 {
     if (BeforeProjectSave != null)
     {
         BeforeProjectSave(savedProject);
     }
 }
 public void VerifyComponentsAreInTreeView(GumProjectSave gumProject)
 {
     foreach (ComponentSave component in gumProject.Components)
     {
         if (GetTreeNodeFor(component) == null)
         {
             throw new Exception();
         }
     }
 }
Beispiel #17
0
        /// <summary>
        /// Initializes the GumProjectSave for editing in Gum.  This means
        /// adding any variables that are necessary, fixing enumerations, and
        /// checking for other errors.
        /// </summary>
        /// <param name="gumProjectSave">The GumProjectSave</param>
        public static bool Initialize(this GumProjectSave gumProjectSave)
        {
            bool wasModified = false;

            gumProjectSave.ScreenReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.StandardElementReferences.Sort((first, second) => first.Name.CompareTo(second.Name));

            gumProjectSave.Screens.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.Components.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.StandardElements.Sort((first, second) => first.Name.CompareTo(second.Name));


            // Do StandardElements first
            // because the values here are
            // used by components to set their
            // ignored enum values.
            foreach (StandardElementSave standardElementSave in gumProjectSave.StandardElements)
            {
                StateSave stateSave = StandardElementsManager.Self.GetDefaultStateFor(standardElementSave.Name);
                // this will result in extra variables being
                // added
                wasModified = standardElementSave.Initialize(stateSave) || wasModified;

                stateSave.ParentContainer = standardElementSave;
            }

            foreach (ScreenSave screenSave in gumProjectSave.Screens)
            {
                screenSave.Initialize(null);
            }



            foreach (ComponentSave componentSave in gumProjectSave.Components)
            {
                // June 27, 2012
                // We used to pass
                // null here because
                // passing a non-null
                // variable meant replacing
                // the existing StateSave with
                // the argument StateSave.  However,
                // now when the type of a Component is
                // changed, old values are not removed, but
                // are rather preserved so that changing the
                // type doesn't wipe out old values.
                //componentSave.Initialize(null);

                StateSave           defaultStateSave = null;
                StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(componentSave);
                if (ses != null)
                {
                    defaultStateSave = ses.DefaultState;
                }

                if (componentSave.Initialize(defaultStateSave))
                {
                    wasModified = true;
                }

                if (componentSave.Initialize(StandardElementsManager.Self.DefaultStates["Component"]))
                {
                    wasModified = true;
                }
            }

            if (gumProjectSave.Version < 1)
            {
                // This means that all default variables have SetValue = false
                // We need to fix that
                foreach (StandardElementSave standardElementSave in gumProjectSave.StandardElements)
                {
                    var defaultState = standardElementSave.DefaultState;

                    foreach (var variable in defaultState.Variables)
                    {
                        if (variable.IsState(standardElementSave) == false)
                        {
                            variable.SetsValue = true;
                        }
                    }
                }

                foreach (var component in gumProjectSave.Components)
                {
                    // We only want to do this on components that don't inherit from other components:
                    var baseComponent = ObjectFinder.Self.GetComponent(component.BaseType);

                    if (baseComponent == null)
                    {
                        var defaultState = component.DefaultState;


                        foreach (var variable in defaultState.Variables)
                        {
                            if (variable.IsState(component) == false)
                            {
                                variable.SetsValue = true;
                            }
                        }
                    }
                }

                wasModified = true;
            }

            return(wasModified);
        }
Beispiel #18
0
        // made public so that File commands can access this function
        public void LoadProject(string fileName)
        {
            GumLoadResult result;

            mGumProjectSave = GumProjectSave.Load(fileName, out result);

            string errors = result.ErrorMessage;

            if (!string.IsNullOrEmpty(errors))
            {
                MessageBox.Show("Errors loading " + fileName + "\n\n" + errors);

                // If the file doesn't exist, that's okay we will let the user still work - it's not like they can overwrite a file that doesn't exist
                // But if it does exist, we want to be careful and not allow overwriting because they could be wiping out good data
                if (FileManager.FileExists(fileName))
                {
                    mHaveErrorsOccurred = true;
                }

                // We used to not load the project, but maybe we still should, just disable autosaving
                //
                //mGumProjectSave = new GumProjectSave();
            }
            else
            {
                mHaveErrorsOccurred = false;
            }

            ObjectFinder.Self.GumProjectSave = mGumProjectSave;

            if (mGumProjectSave != null)
            {
                bool wasModified = mGumProjectSave.Initialize();

                RecreateMissingStandardElements();

                mGumProjectSave.AddNewStandardElementTypes();
                mGumProjectSave.FixStandardVariables();

                FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);
                mGumProjectSave.RemoveDuplicateVariables();

                GraphicalUiElement.ShowLineRectangles = mGumProjectSave.ShowOutlines;
                EditingManager.Self.RestrictToUnitValues = mGumProjectSave.RestrictToUnitValues;

                PluginManager.Self.ProjectLoad(mGumProjectSave);

                if (wasModified)
                {
                    ProjectManager.Self.SaveProject(forceSaveContainedElements:true);
                }

                GraphicalUiElement.CanvasWidth = mGumProjectSave.DefaultCanvasWidth;
                GraphicalUiElement.CanvasHeight = mGumProjectSave.DefaultCanvasHeight;
            }
            else
            {
                PluginManager.Self.ProjectLoad(mGumProjectSave);
            }

            // Now that a new project is loaded, refresh the UI!
            GumCommands.Self.GuiCommands.RefreshElementTreeView();
            // And the guides
            WireframeObjectManager.Self.UpdateGuides();

            GeneralSettingsFile.AddToRecentFilesIfNew(fileName);

            if (GeneralSettingsFile.LastProject != fileName)
            {
                GeneralSettingsFile.LastProject = fileName;
                GeneralSettingsFile.Save();
            }

            if (RecentFilesUpdated != null)
            {
                RecentFilesUpdated();
            }
        }
Beispiel #19
0
 public void CallProjectLoad(GumProjectSave newlyLoadedProject)
 {
     if (ProjectLoad != null)
     {
         ProjectLoad(newlyLoadedProject);
     }
 }
        public void PopulateProjectWithDefaultStandards(GumProjectSave gumProjectSave)
        {
            if (mDefaults == null)
            {
                throw new Exception("You must first call Initialize on this StandardElementsManager");
            }


            foreach (KeyValuePair<string, StateSave> kvp in mDefaults)
            {

                string type = kvp.Key;

                if (type != "Screen")
                {
                    AddStandardElementSaveInstance(gumProjectSave, type);
                }
            }
        }
Beispiel #21
0
 void OnProjectLoad(GumProjectSave obj)
 {
     GuiCommands.Self.UpdateWireframeToProject();
 }
Beispiel #22
0
        public void SetFrom(GumProjectSave gumProjectSave, ReferencedFileSave referencedFileSave)
        {
            shouldRaiseEvents = false;
            {
                backingGumProject = gumProjectSave;
                backingRfs = referencedFileSave;

                UseAtlases = backingRfs.Properties.GetValue<bool>(nameof(UseAtlases));
                AutoCreateGumScreens = backingRfs.Properties.GetValue<bool>(nameof(AutoCreateGumScreens));
                ShowDottedOutlines = backingRfs.Properties.GetValue<bool>(nameof(ShowDottedOutlines));
            }
            shouldRaiseEvents = true;
        }