private GumScreen ToScreen(GlueScreen glueScreen) { var gumScreen = new GumScreen(); gumScreen.States.Add(new Gum.DataTypes.Variables.StateSave() { Name = "Default" }); gumScreen.Name = glueScreen.Name.Substring( "Screens\\".Length); if (!string.IsNullOrEmpty(glueScreen.BaseScreen)) { // This sets the base type, but doesn't populate the instances. // Once the entire project is converted over, we'll loop through all // screens that have base types and have them act as if the value was // just set, causing the inheritance plugin to handle it. var baseScreen = glueScreen.BaseScreen.Substring( "Screens\\".Length); gumScreen.BaseType = baseScreen; } AddInstances(glueScreen, gumScreen); AddStates(glueScreen, gumScreen); return(gumScreen); }
private void HandleNewScreen(FlatRedBall.Glue.SaveClasses.ScreenSave newScreen) { bool createGumScreen = propertiesManager.GetAutoCreateGumScreens(); if (createGumScreen && AppState.Self.GumProjectSave != null) { string gumScreenName = FileManager.RemovePath(newScreen.Name) + "Gum"; bool exists = AppState.Self.GumProjectSave.Screens.Any(item => item.Name == gumScreenName); if (!exists) { Gum.DataTypes.ScreenSave gumScreen = new Gum.DataTypes.ScreenSave(); gumScreen.Initialize(StandardElementsManager.Self.GetDefaultStateFor("Screen")); gumScreen.Name = gumScreenName; string gumProjectFileName = GumProjectManager.Self.GetGumProjectFileName(); AppCommands.Self.AddScreen(gumScreen); AppCommands.Self.SaveGlux(saveAllElements: false); AppCommands.Self.SaveScreen(gumScreen); } // Select the screen to add the file to this GlueState.Self.CurrentScreenSave = newScreen; RightClickManager.Self.AddScreenByName(gumScreenName); } }
public IElement ToGlueIElement(ArrowElementSave arrowElement) { List<string> referencedFiles = new List<string>(); IElement glueElement; if (arrowElement.ElementType == ElementType.Screen) { glueElement = new ScreenSave(); glueElement.Name = "Screens/" + arrowElement.Name; } else { glueElement = new EntitySave(); glueElement.Name = "Entities/" + arrowElement.Name; } AddSpritesToElement(arrowElement, glueElement, referencedFiles); AddCirclesToElement(arrowElement, glueElement); AddRectanglesToElement(arrowElement, glueElement); AddElementInstancesToElement(arrowElement, glueElement); AddReferencedFileSaves(referencedFiles, glueElement); AddCustomVariables(glueElement); return glueElement; }
private ElementReference ToScreenReference(GlueScreen screen) { var elementReference = new ElementReference(); elementReference.ElementType = ElementType.Screen; elementReference.Name = screen.Name.Substring( "Screens\\".Length); return(elementReference); }
private void CreateScreenSaves() { mScreenSave = new ScreenSave(); mScreenSave.Name = "NamedObjectSaveTestsScreen"; ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave); mDerivedNos = new NamedObjectSave(); mDerivedNos.SourceType = SourceType.Entity; mDerivedNos.SourceClassType = mDerivedEntitySave.Name; mScreenSave.NamedObjects.Add(mDerivedNos); }
private void UpdateIncludedAndExcluded(ScreenSave instance) { UpdateIncludedAndExcludedBase(instance); // instance may not be set yet, so we have to use the argument value IncludeMember("BaseScreen", typeof(ScreenSave), new AvailableScreenTypeConverter((ScreenSave)instance)); IncludeMember("NextScreen", typeof(ScreenSave), new AvailableScreenTypeConverter((ScreenSave)instance)); IncludeMember("Name", typeof(string), SetClassName, GetClassName, null, this.CategoryAttribute("\tScreen")); }
private GlueScreenSave ToGlueScreenSave(global::Gum.DataTypes.ScreenSave screen, Dictionary <string, CopiedFileReference> copiedFiles) { GlueScreenSave toReturn = new GlueScreenSave(); toReturn.Name = "Screens\\" + screen.Name; // Make RFS's first so we can rename NOS's if necessary AddReferencedFilesToElement(screen, toReturn, copiedFiles); mInstanceToNos.AddNamedObjectSavesToGlueElement(screen, toReturn, copiedFiles); return(toReturn); }
bool IsLoadingScreen(IElement element, out ScreenSave screenSave) { screenSave = null; if (element is ScreenSave) { ScreenSave asScreenSave = element as ScreenSave; return asScreenSave.IsLoadingScreen; } return false; }
public static void GetAllBaseScreens(this ScreenSave instance, List <ScreenSave> listToFill) { if (!string.IsNullOrEmpty(instance.BaseScreen)) { ScreenSave baseScreen = ObjectFinder.Self.GetScreenSave(instance.BaseScreen); if (baseScreen != null) { listToFill.Add(baseScreen); baseScreen.GetAllBaseScreens(listToFill); } } }
private void CreateScreenSave() { mScreenSave = new ScreenSave(); mScreenSave.Name = "ScreenSaveInVariableSettingTest"; ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.SourceClassType = mEntitySave.Name; nos.UpdateCustomProperties(); nos.InstanceName = "TestObject1"; nos.SetPropertyValue("X", 150); mScreenSave.NamedObjects.Add(nos); }
public static ReferencedFileSave GetReferencedFileSaveRecursively(this ScreenSave instance, string fileName) { ReferencedFileSave rfs = FileReferencerHelper.GetReferencedFileSave(instance, fileName); if (rfs == null && !string.IsNullOrEmpty(instance.BaseScreen)) { IElement baseElement = ObjectFinder.Self.GetIElement(instance.BaseScreen); if (baseElement != null) { rfs = baseElement.GetReferencedFileSaveRecursively(fileName); } } return(rfs); }
public void Initialize() { OverallInitializer.Initialize(); mEntitySave = new EntitySave(); mEntitySave.ImplementsIWindow = true; mEntitySave.Name = "EventTestEntity"; mEntitySave.ImplementsIWindow = true; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mScreenSave = new ScreenSave(); mScreenSave.Name = "EventTestScreen"; ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.SourceClassType = "EventTestEntity"; mScreenSave.NamedObjects.Add(nos); EventResponseSave ers = new EventResponseSave(); ers.SourceObject = "EventTestEntity"; ers.SourceObjectEvent = "Click"; ers.EventName = "EventTestEntityClick"; mScreenSave.Events.Add(ers); EventResponseSave pushErs = new EventResponseSave(); pushErs.SourceObject = "EventTestEntity"; pushErs.SourceObjectEvent = "Push"; pushErs.EventName = "EventTestEntityPush"; mScreenSave.Events.Add(pushErs); // Create a POList so we can expose its event(s) mListNos = new NamedObjectSave(); mListNos.SourceType = SourceType.FlatRedBallType; mListNos.SourceClassType = "PositionedObjectList<T>"; mListNos.SourceClassGenericType = "Sprite"; mScreenSave.NamedObjects.Add(mListNos); mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.Name = "EventTestsDerivedEntity"; mDerivedEntitySave.BaseEntity = mEntitySave.Name; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); }
//public static void CleanUnusedVariablesFromStates(this ScreenSave screenSave) //{ // IElementHelper.CleanUnusedVariablesFromStates(screenSave); //} public static bool InheritsFrom(this ScreenSave instance, string screen) { if (instance.BaseScreen == screen) { return(true); } if (!string.IsNullOrEmpty(instance.BaseScreen)) { EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(instance.BaseScreen); if (baseEntity != null) { return(baseEntity.InheritsFrom(screen)); } } return(false); }
internal IElement ConvertElement(ElementSave element) { if (element is GumScreen) { var glueScreen = new FlatRedBall.Glue.SaveClasses.ScreenSave(); glueScreen.Name = $"Screens\\{element.Name}"; return(glueScreen); } else if (element is ComponentSave) { var glueEntity = new FlatRedBall.Glue.SaveClasses.EntitySave(); glueEntity.Name = $"Entities\\{element.Name}"; // components should have some variables by default: glueEntity.CustomVariables.Add(new CustomVariable() { Name = "X", Type = "float", }); glueEntity.CustomVariables.Add(new CustomVariable() { Name = "Y", Type = "float", }); glueEntity.CustomVariables.Add(new CustomVariable() { Name = "RotationZ", Type = "float", }); return(glueEntity); } else { throw new NotImplementedException(); } }
public static NamedObjectSave GetNamedObjectRecursively(this INamedObjectContainer namedObjectContainer, string namedObjectName) { List <NamedObjectSave> namedObjectList = namedObjectContainer.NamedObjects; NamedObjectSave foundNos = GetNamedObjectInList(namedObjectList, namedObjectName); if (foundNos != null) { return(foundNos); } // These methods need to check if the baseScreen/baseEntity is not null. // They can be null if the user deletes a base Screen/Entity and the tool // managing the Glux doesn't handle the changes. if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject)) { if (namedObjectContainer is EntitySave) { EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject); if (baseEntity != null) { return(GetNamedObjectRecursively(baseEntity, namedObjectName)); } } else if (namedObjectContainer is ScreenSave) { ScreenSave baseScreen = ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject); if (baseScreen != null) { return(GetNamedObjectRecursively(baseScreen, namedObjectName)); } } } return(null); }
protected IEnumerable<string> GetGlueStateNamespaces(ScreenSave entity) { string ns = string.Concat(ProjectManager.ProjectNamespace, ".", entity.Name.Replace("\\", "."), "."); var states = new List<string>() { ns + "VariableState" }; states.AddRange(entity.StateCategoryList .Where(x => !x.SharesVariablesWithOtherCategories) .Select(x => ns + x.Name) .ToArray()); return states; }
public static ScreenSave AddScreen(string screenName) { string fileName = @"Screens\" + screenName + ".cs"; ScreenSave screenSave = new ScreenSave(); screenSave.Name = FileManager.RemoveExtension(fileName); AddScreen(screenSave); return screenSave; }
public void TestExposingStates() { List<string> variables = ExposedVariableManager.GetExposableMembersFor(mEntitySave, false).Select(m=>m.Member).ToList(); if (!variables.Contains("CurrentState")) { throw new Exception("ExposedVariableManager is not properly returning the CurrentState as an exposable variable"); } if (!variables.Contains("CurrentStateCategoryState")) { throw new Exception("ExposedVariableManager is not properly returning categorized states as exposable variables"); } // Let's remove uncategorized state to make sure the categorized state is still recognized: StateSave stateSave = mEntitySave.States[0]; mEntitySave.States.RemoveAt(0); variables = ExposedVariableManager.GetExposableMembersFor(mEntitySave, false).Select(m=>m.Member).ToList(); if (!variables.Contains("CurrentStateCategoryState")) { throw new Exception("ExposedVariableManager is not properly returning categorized states when there are no uncategorized states."); } // Add it back in case it's needed for other tests. mEntitySave.States.Add(stateSave); variables = ExposedVariableManager.GetExposableMembersFor(mEntityWithCategorizedThatShareVariables, false).Select(m => m.Member).ToList(); if (!variables.Contains("CurrentState")) { throw new Exception("Entities that only have states in categories, but those categories share variables with other categories, are not exposing CurrentState and they should!"); } List<string> listOfStates = new List<string>(); AvailableStates availableStates = new AvailableStates(null, mContainerDerivedEntity, mContainerDerivedEntity.CustomVariables[0], null); availableStates.GetListOfStates(listOfStates, "TunneledStateVariable"); if (listOfStates.Count == 0 || !listOfStates.Contains("StateInCategory1")) { throw new Exception("SetByDerived variables that tunnel in to categorized states do not properly return their list through GetListOfStates"); } ScreenSave screenSave = new ScreenSave(); StateSaveCategory category = new StateSaveCategory(); category.Name = "Whatever"; screenSave.StateCategoryList.Add(category); StateSave stateInScreen = new StateSave(); stateInScreen.Name = "First"; category.States.Add(stateInScreen); variables = ExposedVariableManager.GetExposableMembersFor(screenSave, false).Select(item=>item.Member).ToList(); if (variables.Contains("CurrentState") == false) { throw new NotImplementedException("Screens with states that are in categories that share variables are not properly returning the CurrentState as a possible variable"); } }
public static List <StateSave> GetAllStatesReferencingObject(this ScreenSave instance, string objectName) { return(IElementHelper.GetAllStatesReferencingObject(instance, objectName)); }
private void AddTreeNodeFor(ScreenSave screenSave) { string fullName = screenSave.Name; string directory = FileManager.GetDirectory(fullName, RelativeType.Relative); TreeNode directoryNode = GetOrCreateDirectoryNode(directory, AllElementsTreeView.Nodes); TreeNode elementNode = new TreeNode(FileManager.RemovePath(screenSave.Name)); elementNode.Tag = screenSave; directoryNode.Nodes.Add(elementNode); }
public static void RenameElement(this IElement elementToRename, string value) { bool isValid = true; string whyItIsntValid; if (elementToRename is ScreenSave) { isValid = NameVerifier.IsScreenNameValid(value, elementToRename as ScreenSave, out whyItIsntValid); } else { isValid = NameVerifier.IsEntityNameValid(value, elementToRename as EntitySave, out whyItIsntValid); } if (!isValid) { MessageBox.Show(whyItIsntValid); } else { string oldName = elementToRename.Name; string newName = oldName.Substring(0, oldName.Length - elementToRename.ClassName.Length) + value; DialogResult result = ChangeClassNamesInCodeAndFileName(elementToRename, value, oldName, newName); if (result == DialogResult.Yes) { // Set the name first because that's going // to be used by code that follows to modify // inheritance. elementToRename.Name = newName; if (elementToRename is EntitySave) { // Change any Entities that depend on this for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++) { EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i]; if (entitySave.BaseEntity == oldName) { entitySave.BaseEntity = newName; } } // Change any NamedObjects that use this as their type (whether in Entity, or as a generic class) List <NamedObjectSave> namedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(oldName); foreach (NamedObjectSave nos in namedObjects) { if (nos.SourceType == SourceType.Entity && nos.SourceClassType == oldName) { nos.SourceClassType = newName; nos.UpdateCustomProperties(); } else if (nos.SourceType == SourceType.FlatRedBallType && nos.SourceClassGenericType == oldName) { nos.SourceClassGenericType = newName; } } } else { // Change any Screens that depend on this for (int i = 0; i < ProjectManager.GlueProjectSave.Screens.Count; i++) { ScreenSave screenSave = ProjectManager.GlueProjectSave.Screens[i]; if (screenSave.BaseScreen == oldName) { screenSave.BaseScreen = newName; } } if (ProjectManager.StartUpScreen == oldName) { ProjectManager.StartUpScreen = newName; } // Don't do anything with NamedObjects and Screens since they can't (currently) be named objects } ProjectManager.SaveProjects(); GluxCommands.Self.SaveGlux(); TreeNode treeNode = GlueState.Self.Find.ElementTreeNode(elementToRename); if (treeNode is ScreenTreeNode) { ((ScreenTreeNode)treeNode).UpdateReferencedTreeNodes(); } else if (treeNode is EntityTreeNode) { ((EntityTreeNode)treeNode).UpdateReferencedTreeNodes(); } if (elementToRename is EntitySave) { ProjectManager.SortAndUpdateUI(elementToRename as EntitySave); } else if (elementToRename is ScreenSave) { ProjectManager.SortAndUpdateUI(elementToRename as ScreenSave); } } } }
private static int CompareScreenSaves(ScreenSave ss1, ScreenSave ss2) { return ss1.Name.CompareTo(ss2.Name); }
internal static void AddScreen(ScreenSave screenSave, bool suppressAlreadyExistingFileMessage) { string screenName = FileManager.RemovePath(screenSave.Name); string fileName = screenSave.Name + ".cs"; screenSave.Tags.Add("GLUE"); screenSave.Source = "GLUE"; mGlueProjectSave.Screens.Add(screenSave); mGlueProjectSave.Screens.SortByName(); #region Create the Screen code (not the generated version) var item = mProjectBase.AddCodeBuildItem(fileName); string projectNamespace = ProjectNamespace; StringBuilder stringBuilder = new StringBuilder(CodeWriter.ScreenTemplateCode); CodeWriter.SetClassNameAndNamespace( projectNamespace + ".Screens", screenName, stringBuilder); string modifiedTemplate = stringBuilder.ToString(); string fullNonGeneratedFileName = FileManager.RelativeDirectory + fileName; if (FileManager.FileExists(fullNonGeneratedFileName)) { if (!suppressAlreadyExistingFileMessage) { MessageBox.Show("There is already a file named\n\n" + fullNonGeneratedFileName + "\n\nThis file will be used instead of creating a new one just in case you have code that you want to keep there."); } } else { FileManager.SaveText( modifiedTemplate, fullNonGeneratedFileName ); } #endregion #region Create <ScreenName>.Generated.cs string generatedFileName = @"Screens\" + screenName + ".Generated.cs"; CodeProjectHelper.CreateAndAddPartialCodeFile(generatedFileName, true); #endregion // We used to set the // StartUpScreen whenever // the user made a new Screen. // The reason is we assumed that // the user wanted to work on this // Screen, so we set it as the startup // so they could run the game right away. // Now we only want to do it if there are no // other Screens. Otherwise they can just use // GlueView. ScreenTreeNode screenTreeNode = ElementViewWindow.AddScreen(screenSave); if (mGlueProjectSave.Screens.Count == 1) { ElementViewWindow.StartUpScreen = screenTreeNode; } PluginManager.ReactToNewScreenCreated(screenSave); SaveProjects(); GluxCommands.Self.SaveGlux(); }
public static bool DoesMemberNeedToBeSetByContainer(this ScreenSave instance, string memberName) { return(NamedObjectContainerHelper.DoesMemberNeedToBeSetByContainer(instance, memberName)); }
public static void SortAndUpdateUI(ScreenSave screenSave) { mGlueProjectSave.Screens.SortByName(); ElementViewWindow.UpdateNodeToListIndex(screenSave); }
private static void ReactToChangedClassName(object oldValue, ScreenSave screenSave) { }
private static int CompareScreenSaves(ScreenSave ss1, ScreenSave ss2) { return(ss1.Name.CompareTo(ss2.Name)); }
public static List<ExposableEvent> GetExposableEventsFor(ScreenSave screenSave, bool removeAlreadyExposed) { List<ExposableEvent> returnValues = new List<ExposableEvent>(); GetExposableEventsFor(screenSave, returnValues); returnValues.Sort(Sort); if (removeAlreadyExposed) { RemoveAlreadyExposed(screenSave, returnValues); } return returnValues; }
public static string GetMemberTypeForScreen(string memberName, ScreenSave screen) { string toReturn; if (memberName == "CurrentState") { return "VariableState"; } else if (TryGetStateInCategory(memberName, screen, out toReturn)) { return toReturn; } else { throw new InvalidOperationException(); } }
internal static void AddScreen(ScreenSave screenSave) { AddScreen(screenSave, false); }
private GlueScreenSave ToGlueScreenSave(global::Gum.DataTypes.ScreenSave screen, Dictionary<string, CopiedFileReference> copiedFiles) { GlueScreenSave toReturn = new GlueScreenSave(); toReturn.Name = "Screens\\" + screen.Name; // Make RFS's first so we can rename NOS's if necessary AddReferencedFilesToElement(screen, toReturn, copiedFiles); mInstanceToNos.AddNamedObjectSavesToGlueElement(screen, toReturn, copiedFiles); return toReturn; }
public AvailableScreenTypeConverter(ScreenSave currentScreenSave) { CurrentScreenSave = currentScreenSave; }
public static bool IsScreenNameValid(string name, ScreenSave screenSave, out string whyItIsntValid) { whyItIsntValid = ""; CheckForCommonImproperNames(name, ref whyItIsntValid); if (ObjectFinder.Self.GetScreenSave("Screens\\" + name) != null) { whyItIsntValid = "There is already an Screen named " + name; } else if (ObjectFinder.Self.GetReferencedFileSaveFromFile("Screens\\" + name) != null) { whyItIsntValid = "There is already a file named " + name; } else if (mReservedClassNames.Contains(name)) { whyItIsntValid = "The name " + name + " is a reserved class name, so it can't be used for a Screen"; } else if (ObjectFinder.Self.GetEntitySaveUnqualified(name) != null) { whyItIsntValid = "There is already an Entity named " + name + ".\n\n" + "Glue recommends naming the Screen something different than existing Entities because " + "generated code can get confused if you add this same-named Entity in the Screen."; } else if (name == ProjectManager.ProjectNamespace) { whyItIsntValid = "The Screen cannot be named the same as the root namespace (which is usually the same name as the project)"; } return string.IsNullOrEmpty(whyItIsntValid); }
private static List<MemberWithType> GetExposableMembersForScreen(ScreenSave screenSave, bool removeAlreadyExposed, List<MemberWithType> returnValues) { // Currently there's nothing unique to Screens over Entities, so this method does nothing return returnValues; }
public static void RemoveScreen(ScreenSave screenToRemove, List<string> filesThatCouldBeRemoved) { List<ScreenSave> inheritingScreens = ObjectFinder.Self.GetAllScreensThatInheritFrom(screenToRemove); string message = null; if (inheritingScreens.Count != 0) { message = "The Screen " + screenToRemove.ToString() + " is the base for the following Screens:"; for (int i = 0; i < inheritingScreens.Count; i++) { message += "\n" + inheritingScreens[i].ToString(); } } DialogResult result = DialogResult.Yes; if (message != null) { message += "\n\nDo you really want to remove this Screen?"; result = MessageBox.Show(message, "Are you sure?", MessageBoxButtons.YesNo); } if (result == DialogResult.Yes) { // Remove objects before removing files. Otherwise Glue will complain if any objects reference the files. #region Remove the NamedObjectSaves for (int i = screenToRemove.NamedObjects.Count - 1; i > -1; i--) { NamedObjectSave nos = screenToRemove.NamedObjects[i]; ProjectManager.RemoveNamedObject(nos, false, false, null); } #endregion // remove all the files this references first before removing the Screen itself. // For more information see the RemoveEntity function for (int i = screenToRemove.ReferencedFiles.Count - 1; i > -1; i--) { GluxCommands.Self.RemoveReferencedFile(screenToRemove.ReferencedFiles[i], filesThatCouldBeRemoved); } ProjectManager.GlueProjectSave.Screens.Remove(screenToRemove); // If we're going to remove the Screen, we should remove all referenced objects that it references // as well as any ReferencedFiles RemoveUnreferencedFiles(screenToRemove, filesThatCouldBeRemoved); // test this! if (screenToRemove.Name == ProjectManager.GlueProjectSave.StartUpScreen) { ProjectManager.StartUpScreen = ""; } for (int i = 0; i < inheritingScreens.Count; i++) { ScreenSave inheritingScreen = inheritingScreens[i]; DialogResult resetInheritance = MessageBox.Show("Reset the inheritance for " + inheritingScreen.Name + "?", "Reset Inheritance?", MessageBoxButtons.YesNo); if (resetInheritance == DialogResult.Yes) { inheritingScreen.BaseScreen = ""; CodeWriter.GenerateCode(inheritingScreen); } } TaskManager.Self.OnUiThread(() => { ElementViewWindow.RemoveScreen(screenToRemove); }); IElement element = screenToRemove; ProjectManager.RemoveCodeFilesForElement(filesThatCouldBeRemoved, element); ProjectManager.SaveProjects(); GluxCommands.Self.SaveGlux(); } }
public void LoadProject(string projectFileName, InitializationWindow initializationWindow) { TimeManager.Initialize(); var topSection = Section.GetAndStartContextAndTime("All"); ////////////////// EARLY OUT!!!!!!!!! if (!File.Exists(projectFileName)) { GlueGui.ShowException("Could not find the project " + projectFileName + "\n\nOpening Glue without a project.", "Error Loading Project", null); return; } //////////////////// End EARLY OUT//////////////////////////////// FileWatchManager.PerformFlushing = false; bool closeInitWindow = PrepareInitializationWindow(initializationWindow); ClosePreviousProject(projectFileName); SetInitWindowText("Loading code project"); ProjectManager.ProjectBase = ProjectCreator.CreateProject(projectFileName); bool shouldLoad = true; if (ProjectManager.ProjectBase == null) { DialogResult result = MessageBox.Show( "The project\n\n" + projectFileName + "\n\nis an unknown project type. Would you like more " + "info on how to fix this problem?", "Unknown Project Type", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { System.Diagnostics.Process.Start("http://www.flatredball.com/frb/docs/index.php?title=Glue:Reference:Projects:csproj_File"); } shouldLoad = false; } // see if this project references any plugins that aren't installed: var glueFileName = FileManager.RemoveExtension(projectFileName) + ".glux"; if(System.IO.File.Exists(glueFileName)) { try { var tempGlux = GlueProjectSaveExtensions.Load(glueFileName); var requiredPlugins = tempGlux.PluginData.RequiredPlugins; List<string> missingPlugins = new List<string>(); foreach(var requiredPlugin in requiredPlugins) { if(PluginManager.AllPluginContainers.Any(item=>item.Name == requiredPlugin) == false) { missingPlugins.Add(requiredPlugin); } } if(missingPlugins.Count != 0) { var message = $"The project {glueFileName} requires the following plugins:"; foreach(var item in missingPlugins) { message += "\n" + item; } message += "\nWould you like to load the project anyway? It may not run, or may run incorrectly until all plugins are installed."; var result = MessageBox.Show(message, "Missing Plugins", MessageBoxButtons.YesNo); shouldLoad = result == DialogResult.Yes; } } catch(Exception e) { GlueGui.ShowMessageBox($"Could not load .glux file {glueFileName}. Error:\n\n{e.ToString()}"); shouldLoad = false; } } if (shouldLoad) { ProjectManager.ProjectBase.Load(projectFileName); SetInitWindowText("Finding Game class"); FileWatchManager.UpdateToProjectDirectory(); FileManager.RelativeDirectory = FileManager.GetDirectory(projectFileName); // this will make other threads work properly: FileManager.DefaultRelativeDirectory = FileManager.RelativeDirectory; ElementViewWindow.AddDirectoryNodes(); #region Load the GlueProjectSave file if one exists string glueProjectFile = ProjectManager.GlueProjectFileName; bool shouldSaveGlux = false; if (!FileManager.FileExists(glueProjectFile)) { ProjectManager.GlueProjectSave = new GlueProjectSave(); ProjectManager.FindGameClass(); GluxCommands.Self.SaveGlux(); // no need to do this - will do it in PerformLoadGlux: //PluginManager.ReactToLoadedGlux(ProjectManager.GlueProjectSave, glueProjectFile); //shouldSaveGlux = true; //// There's not a lot of code to generate so we can do it on the main thread //// so we get the save to occur after //GlueCommands.Self.GenerateCodeCommands.GenerateAllCodeSync(); //ProjectManager.SaveProjects(); } PerformGluxLoad(projectFileName, glueProjectFile); #endregion SetInitWindowText("Cleaning extra Screens and Entities"); foreach (ScreenTreeNode screenNode in ElementViewWindow.AllScreens) { if (screenNode.ScreenSave == null) { ScreenSave screenSave = new ScreenSave(); screenSave.Name = screenNode.Text; ProjectManager.GlueProjectSave.Screens.Add(screenSave); screenNode.ScreenSave = screenSave; } } foreach (EntityTreeNode entityNode in ElementViewWindow.AllEntities) { if (entityNode.EntitySave == null) { EntitySave entitySave = new EntitySave(); entitySave.Name = entityNode.Text; entitySave.Tags.Add("GLUE"); entitySave.Source = "GLUE"; ProjectManager.GlueProjectSave.Entities.Add(entitySave); entityNode.EntitySave = entitySave; } } UnreferencedFilesManager.Self.RefreshUnreferencedFiles(true); MainGlueWindow.Self.Text = "FlatRedBall Glue - " + projectFileName; MainGlueWindow.Self.SaveRecentProject(projectFileName); if (shouldSaveGlux) { GluxCommands.Self.SaveGlux(); } // saves the projects if dirty GlueCommands.Self.ProjectCommands.SaveProjects(); FileWatchManager.PerformFlushing = true; } if (closeInitWindow) { mCurrentInitWindow.Close(); } Section.EndContextAndTime(); // If we ever want to make things go faster, turn this back on and let's see what's going on. //topSection.Save("Sections.xml"); }
public static ScreenTreeNode AddScreen(ScreenSave screenSave) { string screenFileName = screenSave.Name + ".cs"; string screenFileWithoutExtension = FileManager.RemoveExtension(screenFileName); ScreenTreeNode screenTreeNode = new ScreenTreeNode(FileManager.RemovePath(screenFileWithoutExtension)); screenTreeNode.CodeFile = screenFileName; mScreenNode.Nodes.Add(screenTreeNode); string generatedFile = screenFileWithoutExtension + ".Generated.cs"; bool doesFileExist = FileManager.FileExists(generatedFile); if (!doesFileExist) { CodeWriter.CreateAndAddGeneratedFile(screenSave); } screenTreeNode.GeneratedCodeFile = generatedFile; screenTreeNode.ScreenSave = screenSave; int desiredIndex = ProjectManager.GlueProjectSave.Screens.IndexOf(screenSave); mScreenNode.Nodes.Remove(screenTreeNode); mScreenNode.Nodes.Insert(desiredIndex, screenTreeNode); if (!string.IsNullOrEmpty(screenTreeNode.GeneratedCodeFile)) { CodeWriter.GenerateCode(screenSave); } return screenTreeNode; }
public static void RemoveScreen(ScreenSave screenToRemove) { for (int i = 0; i < mScreenNode.Nodes.Count; i++) { if (((ScreenTreeNode)mScreenNode.Nodes[i]).ScreenSave == screenToRemove) { mScreenNode.Nodes.RemoveAt(i); break; } } }
public static void UpdateNodeToListIndex(ScreenSave screenSave) { ScreenTreeNode screenTreeNode = GlueState.Self.Find.ScreenTreeNode(screenSave); bool wasSelected = MainGlueWindow.Self.ElementTreeView.SelectedNode == screenTreeNode; int desiredIndex = ProjectManager.GlueProjectSave.Screens.IndexOf(screenSave); mScreenNode.Nodes.Remove(screenTreeNode); mScreenNode.Nodes.Insert(desiredIndex, screenTreeNode); if (wasSelected) { MainGlueWindow.Self.ElementTreeView.SelectedNode = screenTreeNode; } }
internal static void AdjustDisplayedScreen(ScreenSave screenSave, ScreenSavePropertyGridDisplayer screenSaveDisplayer) { CallMethodOnPlugin( delegate(PluginBase plugin) { if (plugin.AdjustDisplayedScreen != null) { plugin.AdjustDisplayedScreen(screenSave, screenSaveDisplayer); } }, "AdjustDisplayedScreen"); }
private void HandleAdjustDisplayedScreen(ScreenSave screenSave, ScreenSavePropertyGridDisplayer displayer) { displayer.IncludeCustomPropertyMember(VariableName, typeof(bool)); }
public ScreenTreeNode ScreenTreeNode(ScreenSave screenSave) { for (int i = 0; i < ElementViewWindow.ScreensTreeNode.Nodes.Count; i++) { if (ElementViewWindow.ScreensTreeNode.Nodes[i] is ScreenTreeNode) { ScreenTreeNode asScreenTreeNode = ElementViewWindow.ScreensTreeNode.Nodes[i] as ScreenTreeNode; if (asScreenTreeNode.ScreenSave == screenSave) { return asScreenTreeNode; } } } return null; }
internal static void ReactToNewScreenCreated(ScreenSave screen) { foreach (PluginManager pluginManager in mInstances) { var plugins = pluginManager.ImportedPlugins.Where(x => x.ReactToNewScreenCreated != null); foreach (var plugin in plugins) { var container = pluginManager.mPluginContainers[plugin]; if (container.IsEnabled) { PluginBase plugin1 = plugin; PluginCommand(() => { plugin1.ReactToNewScreenCreated(screen); }, container, "Failed in ReactToNewScreenCreated"); } } } }