private void CreateDerivedElementRuntime() { mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.Name = "DerivedVariableSettingEntity"; mDerivedEntitySave.BaseEntity = mEntitySave.Name; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mDerivedEntitySave.UpdateFromBaseType(); mDerivedEntitySave.GetCustomVariable("CurrentState").DefaultValue = "Uncategorized"; mDerivedElementRuntime = new ElementRuntime(mDerivedEntitySave, null, null, null, null); }
public void Initialize() { OverallInitializer.Initialize(); ExposedVariableManager.Initialize(); mEntitySave = CreateEntitySaveWithStates("ExposedVariableEntity"); mEntitySave.ImplementsIVisible = true; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.BaseEntity = mEntitySave.Name; mDerivedEntitySave.Name = "DerivedExposedVariableEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mEntityWithCategorizedThatShareVariables = new EntitySave(); mEntityWithCategorizedThatShareVariables.Name = "ExposedVariableTestEntityWithCategorizedThatShareVariables"; ObjectFinder.Self.GlueProject.Entities.Add(mEntityWithCategorizedThatShareVariables); StateSaveCategory category = new StateSaveCategory(); category.SharesVariablesWithOtherCategories = true; // this is important - it means that it won't make a new enum or property, so it is just the "CurrentState" variable category.Name = "Category1"; mEntityWithCategorizedThatShareVariables.StateCategoryList.Add(category); StateSave stateSave = new StateSave(); stateSave.Name = "CategorizedState1"; category.States.Add(stateSave); mContainerBaseEntity = new EntitySave(); mContainerBaseEntity.Name = "ExposedVariableTestContainerBaseEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mContainerBaseEntity); NamedObjectSave namedObjectSave = new NamedObjectSave(); namedObjectSave.InstanceName = mEntitySave.Name + "Instance"; namedObjectSave.SourceType = SourceType.Entity; namedObjectSave.SourceClassType = mEntitySave.Name; mContainerBaseEntity.NamedObjects.Add(namedObjectSave); CustomVariable tunneledVariable = new CustomVariable(); tunneledVariable.Name = "TunneledStateVariable"; tunneledVariable.SourceObject = namedObjectSave.InstanceName; tunneledVariable.SourceObjectProperty = "Current" + mEntitySave.StateCategoryList[0].Name + "State"; tunneledVariable.Type = mEntitySave.StateCategoryList[0].Name; tunneledVariable.SetByDerived = true; mContainerBaseEntity.CustomVariables.Add(tunneledVariable); mContainerDerivedEntity = new EntitySave(); mContainerDerivedEntity.Name = "ExposedVariableTestContainerDerivedEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mContainerDerivedEntity); mContainerDerivedEntity.BaseEntity = mContainerBaseEntity.Name; mContainerDerivedEntity.UpdateFromBaseType(); mContainerDerivedEntity.GetCustomVariable(tunneledVariable.Name).DefaultValue = mEntitySave.StateCategoryList[0].States[0].Name; CreateCsvContainerEntitySave(); }
public static bool HasAccompanyingVelocityConsideringTunneling(this CustomVariable variable, IElement container, int maxDepth = 0) { if (variable.HasAccompanyingVelocityProperty) { return(true); } else if (!string.IsNullOrEmpty(variable.SourceObject) && !string.IsNullOrEmpty(variable.SourceObjectProperty) && maxDepth > 0) { NamedObjectSave nos = container.GetNamedObjectRecursively(variable.SourceObject); if (nos != null) { // If it's a FRB if (nos.SourceType == SourceType.FlatRedBallType || nos.SourceType == SourceType.File) { return(!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variable.SourceObjectProperty))); } else if (nos.SourceType == SourceType.Entity) { EntitySave entity = GlueState.CurrentGlueProject.GetEntitySave(nos.SourceClassType); if (entity != null) { CustomVariable variableInEntity = entity.GetCustomVariable(variable.SourceObjectProperty); if (variableInEntity != null) { if (!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variableInEntity.Name))) { return(true); } else { return(variableInEntity.HasAccompanyingVelocityConsideringTunneling(entity, maxDepth - 1)); } } else { // There's no variable for this, so let's see if it's a variable that has velocity in FRB return(!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variable.SourceObjectProperty))); } } } } } return(false); }
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 }