public void GenerateElementCodeTask(IElement element) { string taskName = nameof(GenerateElementCodeTask) + " " + element.ToString(); TaskManager.Self.Add(() => CodeGeneratorIElement.GenerateElementAndDerivedCode(element), taskName, TaskExecutionPreference.AddOrMoveToEnd); }
public static void GenerateSelectedElementAndDerivedCode() { if (GlueState.Self.CurrentElement != null) { CodeGeneratorIElement.GenerateElementAndDerivedCode(GlueState.Self.CurrentElement); } else if (EditorLogic.CurrentReferencedFile != null) { GlobalContentCodeGenerator.UpdateLoadGlobalContentCode(); // Vic asks - do we have to do anything else here? I don't think so... } }
public static void GenerateSelectedElementAndDerivedCode() { if (EditorLogic.CurrentScreenTreeNode != null) { CodeGeneratorIElement.GenerateElementAndDerivedCode(EditorLogic.CurrentScreenSave); } else if (EditorLogic.CurrentEntityTreeNode != null) { CodeGeneratorIElement.GenerateElementAndDerivedCode(EditorLogic.CurrentEntitySave); } else if (EditorLogic.CurrentReferencedFile != null) { ContentLoadWriter.UpdateLoadGlobalContentCode(); // Vic asks - do we have to do anything else here? I don't think so... } }
private static bool DragDropNosIntoElement(NamedObjectSave movingNos, IElement elementMovingInto) { bool succeeded = true; // moving to another element, so let's copy NamedObjectSave clonedNos = movingNos.Clone(); UpdateNosAfterDragDrop(clonedNos, elementMovingInto); elementMovingInto.NamedObjects.Add(clonedNos); var referenceCheck = ProjectManager.VerifyReferenceGraph(elementMovingInto); if (referenceCheck == ProjectManager.CheckResult.Failed) { succeeded = false; // VerifyReferenceGraph (currently) shows a popup so we don't have to here //MessageBox.Show("This movement would result in a circular reference"); elementMovingInto.NamedObjects.Remove(clonedNos); } if (succeeded) { // If an object which was on a Layer // is moved into another Element, then // the cloned object probably shouldn't // be on a layer. Not sure if we want to // see if there is a Layer with the same-name // but we maybe shouldn't assume that they mean // the same thing. clonedNos.LayerOn = null; BaseElementTreeNode treeNodeForElementMovedInto = GlueState.Self.Find.ElementTreeNode(elementMovingInto); treeNodeForElementMovedInto.UpdateReferencedTreeNodes(); CodeGeneratorIElement.GenerateElementDerivedAndReferenced(elementMovingInto); MessageBox.Show("Copied\n" + movingNos + "\n\nto\n" + clonedNos); } return(succeeded); }
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 }
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 }
public void GenerateElementCode(IElement element) { CodeGeneratorIElement.GenerateElementAndDerivedCode(element); }
public void ReactToPropertyChanged(string variableNameAsDisplayed, object oldValue, string variableName, string parentGridItemName) { var mPropertyGrid = MainGlueWindow.Self.PropertyGrid; bool updateTreeView = true; #region EventResponseSave if (EditorLogic.CurrentEventResponseSave != null) { Container.Get <EventResponseSaveSetVariableLogic>().ReactToChange( variableNameAsDisplayed, oldValue, GlueState.Self.CurrentEventResponseSave, GlueState.Self.CurrentElement); } #endregion #region State else if (EditorLogic.CurrentStateSave != null) { Container.Get <StateSaveSetVariableLogic>().ReactToStateSaveChangedValue( EditorLogic.CurrentStateSave, EditorLogic.CurrentStateSaveCategory, variableNameAsDisplayed, oldValue, EditorLogic.CurrentElement, ref updateTreeView); } #endregion #region StateCategory else if (EditorLogic.CurrentStateSaveCategory != null) { Container.Get <StateSaveCategorySetVariableLogic>().ReactToStateSaveCategoryChangedValue( EditorLogic.CurrentStateSaveCategory, variableNameAsDisplayed, oldValue, EditorLogic.CurrentElement, ref updateTreeView); } #endregion #region NamedObject else if (EditorLogic.CurrentNamedObject != null) { Container.Get <NamedObjectSetVariableLogic>().ReactToNamedObjectChangedValue( variableNameAsDisplayed, parentGridItemName, oldValue); } #endregion #region ReferencedFile else if (EditorLogic.CurrentReferencedFile != null) { Container.Get <ReferencedFileSaveSetVariableLogic>().ReactToChangedReferencedFile( variableNameAsDisplayed, oldValue, ref updateTreeView); } #endregion #region CustomVariable else if (EditorLogic.CurrentCustomVariable != null) { Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue( variableNameAsDisplayed, EditorLogic.CurrentCustomVariable, oldValue); } else if (mPropertyGrid.SelectedObject != null && mPropertyGrid.SelectedObject is PropertyGridDisplayer && EditorLogic.CurrentElement != null && EditorLogic.CurrentElement.GetCustomVariableRecursively(variableName) != null) { Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue( variableName, EditorLogic.CurrentElement.GetCustomVariableRecursively(variableName), oldValue); } #endregion // Check Entities and Screens after checking variables and objects #region Entity else if (EditorLogic.CurrentEntitySave != null) { Container.Get <EntitySaveSetVariableLogic>().ReactToEntityChangedValue(variableNameAsDisplayed, oldValue); } #endregion #region ScreenSave else if (EditorLogic.CurrentScreenSave != null) { Container.Get <ScreenSaveSetVariableLogic>().ReactToScreenChangedValue(variableNameAsDisplayed, oldValue); } #endregion #region Global content container node else if (EditorLogic.CurrentTreeNode.Root().IsGlobalContentContainerNode()) { Container.Get <GlobalContentSetVariableLogic>().ReactToGlobalContentChangedValue( variableNameAsDisplayed, oldValue, ref updateTreeView); } #endregion PluginManager.ReactToChangedProperty(variableNameAsDisplayed, oldValue); if (EditorLogic.CurrentElement != null) { CodeGeneratorIElement.GenerateElementDerivedAndReferenced(EditorLogic.CurrentElement); } else if (EditorLogic.CurrentReferencedFile != null) { ContentLoadWriter.UpdateLoadGlobalContentCode(); } // UpdateCurrentObjectReferencedTreeNodes // kicks off a save by default. Therefore // we don't need to call SaveProjects if UpdateCurrentObjectReferencedTreeNodes // is called. if (updateTreeView) { ElementViewWindow.UpdateCurrentObjectReferencedTreeNodes(); } else { ProjectManager.SaveProjects(); } mPropertyGrid.Refresh(); GluxCommands.Self.SaveGlux(); // Vic says: This was intented to refresh the variables at one point // but this is a messy feature. I think we should just refresh the entire // glux whenever a change is made now that it's async //RemotingManager.RefreshVariables(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 == "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 }
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); }