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 }