private static void HandleCreatedByOtherEntitiesSet(EntitySave entitySave) { if (entitySave.CreatedByOtherEntities == true) { FactoryCodeGenerator.AddGeneratedPerformanceTypes(); FactoryCodeGenerator.UpdateFactoryClass(entitySave); ProjectManager.SaveProjects(); } else { FactoryCodeGenerator.RemoveFactory(entitySave); ProjectManager.SaveProjects(); } List<EntitySave> entitiesToRefresh = ObjectFinder.Self.GetAllEntitiesThatInheritFrom(entitySave); entitiesToRefresh.AddRange(entitySave.GetAllBaseEntities()); entitiesToRefresh.Add(entitySave); // We need to re-generate all objects that use this Entity foreach (EntitySave entityToRefresh in entitiesToRefresh) { List<NamedObjectSave> namedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(entityToRefresh.Name); foreach (NamedObjectSave nos in namedObjects) { IElement namedObjectContainer = nos.GetContainer(); if (namedObjectContainer != null) { CodeWriter.GenerateCode(namedObjectContainer); } } } PropertyGridHelper.UpdateDisplayedPropertyGridProperties(); }
private void PerformGluxLoad(string projectFileName, string glueProjectFile) { SetInitWindowText("Loading .glux"); bool succeeded = true; succeeded = DeserializeGluxXmlInternal(projectFileName, glueProjectFile); if (succeeded) { // This seems to take some time (like 1 second). Can we possibly // make it faster by having it chek Game1.cs first? Why is this so slow? ProjectManager.FindGameClass(); AvailableAssetTypes.Self.AdditionalExtensionsToTreatAsAssets.Clear(); IdentifyAdditionalAssetTypes(); SetInitWindowText("Finding and fixing .glux errors"); ProjectManager.GlueProjectSave.FixErrors(true); ProjectManager.GlueProjectSave.RemoveInvalidStatesFromNamedObjects(true); FixProjectErrors(); SetUnsetValues(); ProjectManager.LoadOrCreateProjectSpecificSettings(FileManager.GetDirectory(projectFileName)); SetInitWindowText("Notifying plugins of project..."); // The project specific settings are needed before the plugins do their thing... PluginManager.ReactToLoadedGluxEarly(ProjectManager.GlueProjectSave); // and after that's done we can validate that the build tools are there BuildToolAssociationManager.Self.ProjectSpecificBuildTools.ValidateBuildTools(FileManager.GetDirectory(projectFileName)); ProjectManager.GlueProjectSave.UpdateIfTranslationIsUsed(); Section.GetAndStartContextAndTime("Add items"); SetInitWindowText("Creating project view..."); AddEmptyTreeItems(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("RefreshSourceFileCache"); // This has to be done before the tree nodes are created. The reason is because a user // may create a ReferencedFileSave using a source type, but not check in the built file. // Glue depends on the built file being there, so we gotta build to make sure that file gets // generated. // Update on May 4, 2011: This should be done AFTER BuildAllOutOfDateFiles because Refreshing // source file cache requires looking at all referenced files, and this requires the files existing // so that dependencies can be tracked. // Update May 4, 2011 Part 2: The SourceFileCache is used when building files. So instead, the refreshing // of the source file cache will also build a file if it encounters a missing file. This should greatly reduce // popup count. SetInitWindowText("Refreshing Source File Cache..."); RefreshSourceFileCache(); SetInitWindowText("Checking for additional missing files..."); SetInitWindowText("Building out of date external files..."); BuildAllOutOfDateFiles(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("RefreshGlobalContentDirectory"); SetInitWindowText("Refreshing global content dictionary..."); ReferencedFileSaveCodeGenerator.RefreshGlobalContentDictionary(); GlobalContentCodeGenerator.SuppressGlobalContentDictionaryRefresh = true; Section.EndContextAndTime(); Section.GetAndStartContextAndTime("Screens"); SetInitWindowText("Creating tree nodes..."); CreateScreenTreeNodes(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("Entities"); CreateEntityTreeNodes(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("SortEntities"); ElementViewWindow.SortEntities(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("PrepareSyncedProjects"); PrepareSyncedProjects(projectFileName); mLastLoadedFilename = projectFileName; Section.EndContextAndTime(); Section.GetAndStartContextAndTime("MakeGeneratedItemsNested"); // This should happen after loading synced projects SetInitWindowText("Nesting generated items"); GlueCommands.Self.ProjectCommands.MakeGeneratedCodeItemsNested(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("GlobalContent"); #region Update GlobalContent UI and code SetInitWindowText("Updating global content"); ElementViewWindow.UpdateGlobalContentTreeNodes(false); // Screens and Entities have the membership of their files // automatically updated when the tree nodes are created. This // is bad. GlobalContent does this better by requiring the call // to be explicitly made: UpdateGlobalContentFileProjectMembership(); // I think this is handled automatically when regenerating all code... // Yes, down in GenerateAllCodeTask //GlobalContentCodeGenerator.UpdateLoadGlobalContentCode(); #endregion Section.EndContextAndTime(); Section.GetAndStartContextAndTime("Startup"); SetInitWindowText("Setting StartUp Screen"); #region Set the Startup Screen if (!string.IsNullOrEmpty(ProjectManager.GlueProjectSave.StartUpScreen)) { TreeNode startUpTreeNode = GlueState.Self.Find.ScreenTreeNode(ProjectManager.GlueProjectSave.StartUpScreen); ElementViewWindow.StartUpScreen = startUpTreeNode; if (startUpTreeNode == null) { ProjectManager.GlueProjectSave.StartUpScreen = ""; } } #endregion Section.EndContextAndTime(); Section.GetAndStartContextAndTime("Performance code"); FactoryCodeGenerator.AddGeneratedPerformanceTypes(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("CSV generation"); CsvCodeGenerator.RegenerateAllCsvs(); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("PluginManager Init"); PluginManager.Initialize(false); SetInitWindowText("Notifying Plugins of startup"); PluginManager.ReactToLoadedGlux(ProjectManager.GlueProjectSave, glueProjectFile, SetInitWindowText); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("GenerateAllCode"); SetInitWindowText("Generating all code"); GlueCommands.Self.GenerateCodeCommands.GenerateAllCodeTask(); Section.EndContextAndTime(); GlobalContentCodeGenerator.SuppressGlobalContentDictionaryRefresh = false; } }
internal void ReactToEntityChangedValue(string changedMember, object oldValue) { EntitySave entitySave = EditorLogic.CurrentEntitySave; #region BaseEntity changed if (changedMember == "BaseEntity") { // Not sure why we want to return here. Maybe the user used // to have this set to something but now is undoing it //if (string.IsNullOrEmpty(entitySave.BaseEntity)) //{ // return; //} ReactToChangedBaseEntity(oldValue, entitySave); } #endregion #region CreatedByOtherEntities changed else if (changedMember == "CreatedByOtherEntities") { HandleCreatedByOtherEntitiesSet(entitySave); } #endregion #region PooledByFactory else if (changedMember == nameof(entitySave.PooledByFactory) && (bool)oldValue != entitySave.PooledByFactory) { if (entitySave.PooledByFactory) { // We should ask the user // if Glue should set the reset // variables for all contained objects string message = "Would you like to add reset variables for all contained objects (recommended)"; DialogResult result = MessageBox.Show(message, "Add reset variables?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { FactoryManager.Self.SetResetVariablesForEntitySave(entitySave); } } else // user set it to false { var hasResetVariables = entitySave.AllNamedObjects.Any(item => item.VariablesToReset?.Any() == true); if(hasResetVariables) { string message = "Would you like to remove reset variables for all contained objects? Select 'Yes' if you added reset variables earlier for pooling"; var dialogResult = MessageBox.Show(message, "Remove reset variables?", MessageBoxButtons.YesNo); if(dialogResult == DialogResult.Yes) { FactoryManager.Self.RemoveResetVariablesForEntitySave(entitySave); } } } FactoryCodeGenerator.AddGeneratedPerformanceTypes(); FactoryCodeGenerator.UpdateFactoryClass(entitySave); } #endregion #region Click Broadcast // Vic says: I don't think we need this anymore else if (changedMember == "ClickBroadcast") { if (string.IsNullOrEmpty((string)oldValue) && !entitySave.ImplementsIClickable ) { // Let the user know that this won't do anything unless the entity implements IClickable string message = "The Click Broadcast message will not be broadcasted unless this " + "Entity is made IClickable. Would you like to make it IClickable?"; DialogResult result = MessageBox.Show(message, "Make IClickable?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { entitySave.ImplementsIClickable = true; } } } #endregion #region ImplementsIWindow else if (changedMember == "ImplementsIWindow") { if (entitySave.ImplementsIWindow && !entitySave.ImplementsIVisible) { MessageBox.Show("IWindows must also be IVisible. Automatically setting Implements IVisible to true"); entitySave.ImplementsIVisible = true; } RegenerateAllContainersForNamedObjectsThatUseCurrentEntity(); } #endregion #region ImplementsIVisible else if (changedMember == "ImplementsIVisible") { ReactToChangedImplementsIVisible(oldValue, entitySave); } #endregion #region ImplementsIClickable else if (changedMember == "ImplementsIClickable") { RegenerateAllContainersForNamedObjectsThatUseCurrentEntity(); } #endregion #region ItemType else if (changedMember == "ItemType") { EntitySave itemTypeEntity = ObjectFinder.Self.GetEntitySave(entitySave.ItemType); if (itemTypeEntity != null) { if (!itemTypeEntity.CreatedByOtherEntities) { MessageBox.Show("The Entity " + entitySave.ItemType + " must be \"Created By Other Entities\" to be used as an Item Type"); entitySave.ItemType = null; } } } #endregion #region ClassName else if (changedMember == "ClassName") { List<NamedObjectSave> allNamedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseElement(EditorLogic.CurrentElement); List<IElement> containers = new List<IElement>(); foreach (NamedObjectSave nos in allNamedObjects) { IElement element = nos.GetContainer(); if (!containers.Contains(element)) { containers.Add(element); } } foreach (IElement element in containers) { CodeGeneratorIElement.GenerateElement(element); } } #endregion }
internal void ReactToEntityChangedValue(string changedMember, object oldValue) { EntitySave entitySave = EditorLogic.CurrentEntitySave; #region BaseEntity changed if (changedMember == "BaseEntity") { // Not sure why we want to return here. Maybe the user used // to have this set to something but now is undoing it //if (string.IsNullOrEmpty(entitySave.BaseEntity)) //{ // return; //} ReactToChangedBaseEntity(oldValue, entitySave); } #endregion #region CreatedByOtherEntities changed else if (changedMember == "CreatedByOtherEntities") { HandleCreatedByOtherEntitiesSet(entitySave); } #endregion #region PooledByFactory else if (changedMember == "PooledByFactory") { if ((bool)oldValue == false && entitySave.PooledByFactory) { // We should ask the user // if Glue should set the reset // variables for all contained objects string message = "Would you like to add reset variables for all contained objects (recommended)"; DialogResult result = MessageBox.Show(message, "Add reset variables?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { FactoryManager.Self.SetResetVariablesForEntitySave(entitySave); // See if there are any base entities that have objects which are not exposed. // If so, those aren't going to get reset variables, so we need to warn the user // about that. // Actually it seems like glue does actually reset base entity variables, so... // we don't need this //var baseElements = ObjectFinder.Self.GetAllBaseElementsRecursively(entitySave); //string inheritanceErrorMessage = ""; //foreach (var element in baseElements) //{ // foreach (var nos in element.AllNamedObjects.Where(item => item.ExposedInDerived == false)) // { // if (string.IsNullOrEmpty(inheritanceErrorMessage)) // { // inheritanceErrorMessage = "The following Objects have their SetByDerived set to false, so they cannot be properly reset:"; // } // inheritanceErrorMessage += "\n" + nos.ToString(); // } //} } } FactoryCodeGenerator.AddGeneratedPerformanceTypes(); FactoryCodeGenerator.UpdateFactoryClass(entitySave); } #endregion #region Click Broadcast // Vic says: I don't think we need this anymore else if (changedMember == "ClickBroadcast") { if (string.IsNullOrEmpty((string)oldValue) && !entitySave.ImplementsIClickable ) { // Let the user know that this won't do anything unless the entity implements IClickable string message = "The Click Broadcast message will not be broadcasted unless this " + "Entity is made IClickable. Would you like to make it IClickable?"; DialogResult result = MessageBox.Show(message, "Make IClickable?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { entitySave.ImplementsIClickable = true; } } } #endregion #region ImplementsIWindow else if (changedMember == "ImplementsIWindow") { if (entitySave.ImplementsIWindow && !entitySave.ImplementsIVisible) { MessageBox.Show("IWindows must also be IVisible. Automatically setting Implements IVisible to true"); entitySave.ImplementsIVisible = true; } RegenerateAllContainersForNamedObjectsThatUseCurrentEntity(); } #endregion #region ImplementsIVisible else if (changedMember == "ImplementsIVisible") { ReactToChangedImplementsIVisible(oldValue, entitySave); } #endregion #region ImplementsIClickable else if (changedMember == "ImplementsIClickable") { RegenerateAllContainersForNamedObjectsThatUseCurrentEntity(); } #endregion #region ItemType else if (changedMember == "ItemType") { EntitySave itemTypeEntity = ObjectFinder.Self.GetEntitySave(entitySave.ItemType); if (itemTypeEntity != null) { if (!itemTypeEntity.CreatedByOtherEntities) { MessageBox.Show("The Entity " + entitySave.ItemType + " must be \"Created By Other Entities\" to be used as an Item Type"); entitySave.ItemType = null; } } } #endregion #region ClassName else if (changedMember == "ClassName") { List <NamedObjectSave> allNamedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseElement(EditorLogic.CurrentElement); List <IElement> containers = new List <IElement>(); foreach (NamedObjectSave nos in allNamedObjects) { IElement element = nos.GetContainer(); if (!containers.Contains(element)) { containers.Add(element); } } foreach (IElement element in containers) { CodeGeneratorIElement.GenerateElement(element); } } #endregion }