private string GetWhySharesVariableChangeIsntAllowed(StateSaveCategory category, IElement element) { string toReturn = null; if (category.SharesVariablesWithOtherCategories) { // Shares, which means we need to go through all uncategorized and all other categories that share to see if there's any matches foreach (var state in category.States) { if (element.States.Exists(item => item.Name == state.Name)) { toReturn = "There is already an uncategorized state named " + state.Name + " which would conflict with the state in " + category.Name; break; } foreach (var otherCategory in element.StateCategoryList.Where(item=>item.SharesVariablesWithOtherCategories && item != category)) { if (otherCategory.States.Exists(item => item.Name == state.Name)) { toReturn = "There is already a state in the category " + otherCategory.Name + " with the name " + state.Name; break; } } } } return toReturn; }
public void Initialize() { Container.Set(new StateSaveCategorySetVariableLogic()); mEntitySave = new EntitySave(); mCategory = new StateSaveCategory(); mCategory.Name = "Category1"; mCategory.SharesVariablesWithOtherCategories = true; mEntitySave.StateCategoryList.Add(mCategory); mCategory2 = new StateSaveCategory(); mCategory2.Name = "Category2"; mCategory2.SharesVariablesWithOtherCategories = true; mEntitySave.StateCategoryList.Add(mCategory); StateSave state1 = new StateSave(); state1.Name = "State1"; mCategory.States.Add(state1); StateSave stateInCategory2 = new StateSave(); stateInCategory2.Name = "State1InCategory2"; mCategory2.States.Add(stateInCategory2); mCustomVariable = new CustomVariable(); mCustomVariable.Name = "CurrentState"; mCustomVariable.Type = "VariableState"; mCustomVariable.DefaultValue = "State1"; mEntitySave.CustomVariables.Add(mCustomVariable); //need to test the case where a variable shouldn't be changed because it's not part of the category that got changed. //Also, need to handle a case where the variable becomes an uncategorized variable, but there alread is one...do we allow it? }
public void ReactToStateSaveCategoryChangedValue(StateSaveCategory stateSaveCategory, string changedMember, object oldValue, IElement element, ref bool updateTreeView) { if(changedMember == "SharesVariablesWithOtherCategories") { string oldType; string newType; if ((bool)oldValue == true) { oldType = "VariableState"; newType = stateSaveCategory.Name; } else { oldType = stateSaveCategory.Name; newType = "VariableState"; } string whyIsntAllowed = GetWhySharesVariableChangeIsntAllowed(stateSaveCategory, element); if (!string.IsNullOrEmpty(whyIsntAllowed)) { MessageBox.Show(whyIsntAllowed); stateSaveCategory.SharesVariablesWithOtherCategories = false; } else { // See if any variables are using this. If so, let's change them // We need to see if any variables are already tunneling in to this // new type. If so, then notify the user that the variable will be removed. // Otherwise, notify the user that the variable type is changing. foreach (CustomVariable customVariable in element.CustomVariables) { if (customVariable.Type == oldType && !string.IsNullOrEmpty(customVariable.DefaultValue as string) && stateSaveCategory.GetState(customVariable.DefaultValue as string) != null) { // We need to do something here... bool shouldChange = false; #if !UNIT_TESTS var dialogResult = System.Windows.Forms.MessageBox.Show("Change variable " + customVariable.Name + " to be of type " + newType + " ? Selecting 'No' will introduce compile errors.", "Change variable type?", System.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { shouldChange = true; } #else shouldChange = true; #endif if (shouldChange) { customVariable.Type = newType; } } } } } }
TreeNode GetTreeNodeFor(StateSaveCategory category) { foreach (TreeNode treeNode in this.Nodes) { if (treeNode.Tag == category) { return treeNode; } } return null; }
public void ReactToStateSaveChangedValue(StateSave stateSave, StateSaveCategory category, string changedMember, object oldValue, IElement parentObject, ref bool updateTreeView) { if (changedMember != "Name") { updateTreeView = false; } // See if this is an Unmodified object // We don't support NamedObjectPropertyOverrides anymore //NamedObjectPropertyOverride propertyOverride = parentObject as NamedObjectPropertyOverride; //if (propertyOverride != null) //{ // if (stateSave.NamedObjectPropertyOverrides.Contains(propertyOverride)) // { // if (changedMember == "SourceFile" && propertyOverride.SourceFile == AvailableFileStringConverter.UseDefaultString) // { // propertyOverride.SourceFile = null; // } // if (propertyOverride.IsNulledOut) // { // stateSave.NamedObjectPropertyOverrides.Remove(propertyOverride); // } // } // else // { // switch (changedMember) // { // case "SourceFile": // propertyOverride.SourceFile = NamedObjectPropertyOverride.SourceFileBuffer; // break; // } // stateSave.NamedObjectPropertyOverrides.Add(propertyOverride); // } //} if (changedMember == "Name") { string whyItIsntValid; if (!NameVerifier.IsStateNameValid(stateSave.Name, EditorLogic.CurrentElement, EditorLogic.CurrentStateSaveCategory, EditorLogic.CurrentStateSave, out whyItIsntValid)) { stateSave.Name = (string)oldValue; updateTreeView = false; AutomatedGlue.GlueGui.ShowMessageBox(whyItIsntValid); } else { ReactToStateNameChange(oldValue, stateSave, category, parentObject); } } }
private GumStateCategory ToGumStateCategory(GlueStateCategory glueStateCategory, GlueElement glueElement) { var gumStateCategory = new GumStateCategory(); gumStateCategory.Name = glueStateCategory.Name; foreach (var glueState in glueStateCategory.States) { var gumState = ToGumState(glueState, glueElement); gumStateCategory.States.Add(gumState); } return(gumStateCategory); }
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 StateSaveCategory GetStateCategoryRecursively(this IElement element, string stateCategoryName) { // start at the top-down StateSaveCategory category = element.GetStateCategory(stateCategoryName); if (category == null && !string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = GlueState.CurrentGlueProject.GetElement(element.BaseElement); if (baseElement != null) { return(baseElement.GetStateCategoryRecursively(stateCategoryName)); } } return(category); }
private void CreateEntitySaves() { mEntitySave = new EntitySave(); mEntitySave.Name = "NamedObjectSaveTestsEntity"; mEntitySave.ImplementsIVisible = true; mEntitySave.ImplementsIWindow = true; CustomVariable customVariable = new CustomVariable(); customVariable.Type = "float"; customVariable.Name = "X"; mEntitySave.CustomVariables.Add(customVariable); customVariable = new CustomVariable(); customVariable.Type = "float"; customVariable.Name = "Y"; customVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(customVariable); StateSave stateSave = new StateSave(); stateSave.Name = "TestState"; mEntitySave.States.Add(stateSave); StateSaveCategory stateSaveCategory = new StateSaveCategory(); stateSaveCategory.Name = "TestCategory"; mEntitySave.StateCategoryList.Add(stateSaveCategory); StateSave categorizedState = new StateSave(); categorizedState.Name = "CategorizedState"; stateSaveCategory.States.Add(categorizedState); ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.BaseEntity = mEntitySave.Name; mDerivedEntitySave.Name = "NamedObjectSaveTestDerivedEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); }
public void TestStateVariables() { EntitySave entitySave = new EntitySave(); entitySave.Name = "CustomVariableTestStateVariableEntity"; ObjectFinder.Self.GlueProject.Entities.Add(entitySave); StateSaveCategory category1 = new StateSaveCategory(); category1.Name = "Category1"; category1.SharesVariablesWithOtherCategories = false; StateSave stateSave = new StateSave(); stateSave.Name = "Disabled"; category1.States.Add(stateSave); StateSaveCategory category2 = new StateSaveCategory(); category2.Name = "Category2"; category2.SharesVariablesWithOtherCategories = false; stateSave = new StateSave(); stateSave.Name = "Disabled"; category2.States.Add(stateSave); entitySave.StateCategoryList.Add(category1); entitySave.StateCategoryList.Add(category2); CustomVariable customVariable = new CustomVariable(); customVariable.Type = "Category2"; customVariable.DefaultValue = "Disabled"; customVariable.Name = "CurrentCategory2State"; entitySave.CustomVariables.Add(customVariable); ElementRuntime elementRuntime = new ElementRuntime(entitySave, null, null, null, null); StateSave foundStateSave = elementRuntime.GetStateSaveFromCustomVariableValue(customVariable, customVariable.DefaultValue); if (foundStateSave != category2.States[0]) { throw new Exception("States in categories are not being found properly when referenced through custom variables"); } }
public static bool IsStateNameValid(string name, IElement element, StateSaveCategory category, StateSave currentStateSave, out string whyItIsntValid) { whyItIsntValid = null; CheckForCommonImproperNames(name, ref whyItIsntValid); if (!string.IsNullOrEmpty(whyItIsntValid)) { return(false); } //Check if shared if (element != null) { if (category == null || category.SharesVariablesWithOtherCategories) { //Check states not in category if (element.States.Any(otherState => otherState.Name == name && otherState != currentStateSave)) { whyItIsntValid = "Conflicts with existing state"; return(false); } //Check categories that have sharing on foreach (var stateSaveCategory in from stateSaveCategory in element.StateCategoryList where stateSaveCategory.SharesVariablesWithOtherCategories from stateSave in stateSaveCategory.States where name == stateSave.Name && stateSave != currentStateSave select stateSaveCategory) { whyItIsntValid = "Conflicts with existing state in category " + stateSaveCategory.Name; return(false); } } else if (category != null) { if (category.States.Any(state => state.Name == name && state != currentStateSave)) { whyItIsntValid = "The name " + name + " is already being used in the category " + category.Name; return(false); } } } if (!string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement); if (baseElement != null) { string categoryName = null; if (category != null && category.SharesVariablesWithOtherCategories == false) { categoryName = category.Name; } if (baseElement.GetState(name, categoryName) != null) { string screenOrEntity = "screen"; if (baseElement is EntitySave) { screenOrEntity = "entity"; } whyItIsntValid = "This state name \"" + name + "\" is already used in a base " + screenOrEntity; } } } return(string.IsNullOrEmpty(whyItIsntValid)); }
private void AddComboBoxIfStatesExist(StateSaveCategory category) { AddComboBoxIfStatesExist(category.Name, category.States); }
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"); } }
static void AddStateCategoryClick(object sender, EventArgs e) { // add category, addcategory, add state category TextInputWindow tiw = new TextInputWindow(); tiw.DisplayText = "Enter a name for the new category"; tiw.Text = "New Category"; DialogResult result = tiw.ShowDialog(MainGlueWindow.Self); if (result == DialogResult.OK) { string whyItIsntValid; if(!NameVerifier.IsStateCategoryNameValid(tiw.Result, out whyItIsntValid)) { GlueGui.ShowMessageBox(whyItIsntValid); } else { IElement element = EditorLogic.CurrentElement; StateSaveCategory newCategory = new StateSaveCategory(); newCategory.Name = tiw.Result; newCategory.SharesVariablesWithOtherCategories = false; element.StateCategoryList.Add(newCategory); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); ElementViewWindow.GenerateSelectedElementCode(); GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); } } }
public static bool IsStateNameValid(string name, IElement element, StateSaveCategory category, StateSave currentStateSave, out string whyItIsntValid) { whyItIsntValid = null; CheckForCommonImproperNames(name, ref whyItIsntValid); if(!string.IsNullOrEmpty(whyItIsntValid)) return false; //Check if shared if (element != null) { if (category == null || category.SharesVariablesWithOtherCategories) { //Check states not in category if (element.States.Any(otherState => otherState.Name == name && otherState != currentStateSave)) { whyItIsntValid = "Conflicts with existing state"; return false; } //Check categories that have sharing on foreach (var stateSaveCategory in from stateSaveCategory in element.StateCategoryList where stateSaveCategory.SharesVariablesWithOtherCategories from stateSave in stateSaveCategory.States where name == stateSave.Name && stateSave != currentStateSave select stateSaveCategory) { whyItIsntValid = "Conflicts with existing state in category " + stateSaveCategory.Name; return false; } } else if (category != null) { if (category.States.Any(state => state.Name == name && state != currentStateSave)) { whyItIsntValid = "The name " + name + " is already being used in the category " + category.Name; return false; } } } if (!string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement); if (baseElement != null) { string categoryName = null; if (category != null && category.SharesVariablesWithOtherCategories == false) { categoryName = category.Name; } if (baseElement.GetState(name, categoryName) != null) { string screenOrEntity = "screen"; if(baseElement is EntitySave) { screenOrEntity = "entity"; } whyItIsntValid = "This state name \"" + name + "\" is already used in a base " + screenOrEntity; } } } return string.IsNullOrEmpty(whyItIsntValid); }
void CreateElementRuntime(string name) { var entitySave = new EntitySave {Name = name}; ObjectFinder.Self.GlueProject.Entities.Add(entitySave); #region Create CustomVariables var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = 3.0f }; entitySave.CustomVariables.Add(xVariable); var yVariable = new CustomVariable { Name = "Y", Type = "float", DefaultValue = 4.0f }; entitySave.CustomVariables.Add(yVariable); var customVariable = new CustomVariable { Name = "SomeNewVar", Type = "double", DefaultValue = 3.333 }; entitySave.CustomVariables.Add(customVariable); var csvTypeVAriable = new CustomVariable { Name = "CsvTypeVariable", Type = "CsvType.csv", DefaultValue = null }; entitySave.CustomVariables.Add(csvTypeVAriable); var csvTypeVariable2 = new CustomVariable { Name = "EnemyInfoVariable", Type = "EnemyInfo.csv", DefaultValue = "Imp" }; entitySave.CustomVariables.Add(csvTypeVariable2); var scaleXVariable = new CustomVariable { Name = "ScaleX", Type = "float", DefaultValue = 10.0f }; entitySave.CustomVariables.Add(scaleXVariable); #endregion #region Create the NamedObjectsSave NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.InstanceName = "SpriteObject"; nos.UpdateCustomProperties(); nos.SetPropertyValue("ScaleX", 3.0f); entitySave.NamedObjects.Add(nos); #endregion #region Create the ReferencedFileSaves ReferencedFileSave rfs = new ReferencedFileSave(); rfs.Name = "Content/Entities/ReferencedFileSaveTestsBaseEntity/SceneFile.scnx"; entitySave.ReferencedFiles.Add(rfs); rfs = new ReferencedFileSave(); rfs.Name = "Content/EnemyInfo.csv"; rfs.CreatesDictionary = true; entitySave.ReferencedFiles.Add(rfs); #endregion mElementRuntime = new ElementRuntime(entitySave, null, null, null, null) { X = (float) xVariable.DefaultValue, Y = (float) yVariable.DefaultValue }; #region Create the uncategorized states var leftX = new InstructionSave { Member = "X", Value = -10, Type = "float" }; var rightX = new InstructionSave { Member = "X", Value = 10, Type = "float" }; var someNewVarSetLeft = new InstructionSave { Member = "SomeNewVar", Value = -10.0, Type = "double" }; var someNewVarSetRight = new InstructionSave { Member = "SomeNewVar", Value = 10.0, Type = "double" }; var leftState = new StateSave {Name = "Left"}; leftState.InstructionSaves.Add(leftX); leftState.InstructionSaves.Add(someNewVarSetLeft); var rightState = new StateSave {Name = "Right"}; rightState.InstructionSaves.Add(rightX); rightState.InstructionSaves.Add(someNewVarSetRight); entitySave.States.Add(leftState); entitySave.States.Add(rightState); #endregion #region Create the categorized states StateSaveCategory category = new StateSaveCategory(); category.SharesVariablesWithOtherCategories = false; category.Name = "StateCategory"; var topY = new InstructionSave { Member = "Y", Value = 10, Type = "float" }; var bottomY = new InstructionSave { Member = "Y", Value = 10, Type = "float" }; var topState = new StateSave { Name = "Top" }; topState.InstructionSaves.Add(topY); var bottomState = new StateSave { Name = "Bottom" }; bottomState.InstructionSaves.Add(rightX); category.States.Add(topState); category.States.Add(bottomState); entitySave.StateCategoryList.Add(category); #endregion }
public static EntitySave CreateEntitySaveWithStates(string name) { EntitySave entitySave = new EntitySave(); entitySave.Name = name; StateSaveCategory category = new StateSaveCategory(); category.Name = "StateCategory"; StateSave stateSave = new StateSave(); stateSave.Name = "StateInCategory1"; category.SharesVariablesWithOtherCategories = false; category.States.Add(stateSave); entitySave.StateCategoryList.Add(category); StateSave uncategoried = new StateSave(); uncategoried.Name = "Uncategorized"; entitySave.States.Add(uncategoried); return entitySave; }
public void Add(string containerName, StateSaveCategory stateSaveCategory) { throw new NotImplementedException(); }
public static void GetAdditionsNeededForChangingType(string oldType, string newType, List <PropertyValuePair> valuesToBeSet, List <CustomVariable> neededVariables, List <StateSave> neededStates, List <StateSaveCategory> neededCategories) { IElement oldElement = ObjectFinder.Self.GetIElement(oldType); IElement newElement = ObjectFinder.Self.GetIElement(newType); if (oldElement != null && newElement != null) { #region Compare CustomVariables foreach (CustomVariable customVariable in oldElement.CustomVariables) { string name = customVariable.Name; string type = customVariable.Type; // Is there a custom variable in the type to change to? // We used to only call GetCustomVariable, but this needs // to be recursive, because the object will get variables from // the immediate type as well as all base types. //CustomVariable customVariableInNewType = newElement.GetCustomVariable(name); CustomVariable customVariableInNewType = newElement.GetCustomVariableRecursively(name); if (customVariableInNewType == null || customVariableInNewType.Type != type) { neededVariables.Add(customVariable); } } #endregion #region Compare interfaces like IClickable if (oldElement is EntitySave && newElement is EntitySave) { EntitySave oldEntity = oldElement as EntitySave; EntitySave newEntity = newElement as EntitySave; if (oldEntity.GetImplementsIClickableRecursively() && !newEntity.GetImplementsIClickableRecursively()) { valuesToBeSet.Add(new PropertyValuePair("ImplementsIClickable", true)); } if (oldEntity.GetImplementsIVisibleRecursively() && !newEntity.GetImplementsIVisibleRecursively()) { valuesToBeSet.Add(new PropertyValuePair("ImplementsIVisible", true)); } if (oldEntity.GetImplementsIWindowRecursively() && !newEntity.GetImplementsIWindowRecursively()) { valuesToBeSet.Add(new PropertyValuePair("ImplementsIWindow", true)); } } #endregion #region Compare States // Don't use AllStates because we want // states that belong to categories to be // identified as being in categories. foreach (StateSave state in oldElement.States) { if (newElement.GetUncategorizedStateRecursively(state.Name) == null) { neededStates.Add(state); } } #endregion #region Compare Categories foreach (StateSaveCategory category in oldElement.StateCategoryList) { StateSaveCategory cloneOfCategory = null; StateSaveCategory categoryInNew = newElement.GetStateCategoryRecursively(category.Name); if (categoryInNew == null) { cloneOfCategory = new StateSaveCategory { Name = category.Name }; neededCategories.Add(cloneOfCategory); } List <StateSave> statesMissingInNewCategory = new List <StateSave>(); foreach (StateSave state in category.States) { if (categoryInNew == null || categoryInNew.GetState(state.Name) == null) { if (cloneOfCategory == null) { cloneOfCategory = new StateSaveCategory { Name = category.Name }; } cloneOfCategory.States.Add(state); } } if (cloneOfCategory != null) { neededCategories.Add(cloneOfCategory); } } #endregion } }
public static void GetAdditionsNeededForChangingType(string oldType, string newType, List<PropertyValuePair> valuesToBeSet, List<CustomVariable> neededVariables, List<StateSave> neededStates, List<StateSaveCategory> neededCategories) { IElement oldElement = ObjectFinder.Self.GetIElement(oldType); IElement newElement = ObjectFinder.Self.GetIElement(newType); if (oldElement != null && newElement != null) { #region Compare CustomVariables foreach (CustomVariable customVariable in oldElement.CustomVariables) { string name = customVariable.Name; string type = customVariable.Type; // Is there a custom variable in the type to change to? // We used to only call GetCustomVariable, but this needs // to be recursive, because the object will get variables from // the immediate type as well as all base types. //CustomVariable customVariableInNewType = newElement.GetCustomVariable(name); CustomVariable customVariableInNewType = newElement.GetCustomVariableRecursively(name); if (customVariableInNewType == null || customVariableInNewType.Type != type) { neededVariables.Add(customVariable); } } #endregion #region Compare interfaces like IClickable if (oldElement is EntitySave && newElement is EntitySave) { EntitySave oldEntity = oldElement as EntitySave; EntitySave newEntity = newElement as EntitySave; if (oldEntity.GetImplementsIClickableRecursively() && !newEntity.GetImplementsIClickableRecursively()) { valuesToBeSet.Add(new PropertyValuePair("ImplementsIClickable", true)); } if (oldEntity.GetImplementsIVisibleRecursively() && !newEntity.GetImplementsIVisibleRecursively()) { valuesToBeSet.Add(new PropertyValuePair("ImplementsIVisible", true)); } if (oldEntity.GetImplementsIWindowRecursively() && !newEntity.GetImplementsIWindowRecursively()) { valuesToBeSet.Add(new PropertyValuePair("ImplementsIWindow", true)); } } #endregion #region Compare States // Don't use AllStates because we want // states that belong to categories to be // identified as being in categories. foreach (StateSave state in oldElement.States) { if (newElement.GetUncategorizedStateRecursively(state.Name) == null) { neededStates.Add(state); } } #endregion #region Compare Categories foreach (StateSaveCategory category in oldElement.StateCategoryList) { StateSaveCategory cloneOfCategory = null; StateSaveCategory categoryInNew = newElement.GetStateCategoryRecursively(category.Name); if (categoryInNew == null) { cloneOfCategory = new StateSaveCategory { Name = category.Name }; neededCategories.Add(cloneOfCategory); } List<StateSave> statesMissingInNewCategory = new List<StateSave>(); foreach (StateSave state in category.States) { if (categoryInNew == null || categoryInNew.GetState(state.Name) == null) { if (cloneOfCategory == null) { cloneOfCategory = new StateSaveCategory { Name = category.Name }; } cloneOfCategory.States.Add(state); } } if (cloneOfCategory != null) { neededCategories.Add(cloneOfCategory); } } #endregion } }
private static object TryToGetStateCategoryFromElement(string memberName, IElement element) { object foundObject = null; StateSaveCategory existingCategory = element.GetStateCategoryRecursively(memberName); bool isUncategorizedCategory = memberName == "VariableState"; if (!isUncategorizedCategory) { if (existingCategory != null) { if (existingCategory.SharesVariablesWithOtherCategories == false) { foundObject = existingCategory; } else { isUncategorizedCategory = true; } } } if (isUncategorizedCategory) { StateSaveCategory stateSaveCategory = new StateSaveCategory(); foreach (StateSave stateSave in element.States) { stateSaveCategory.States.Add(stateSave); } foundObject = stateSaveCategory; } return foundObject; }
private static void ReactToStateNameChange(object oldValue, StateSave stateSave, StateSaveCategory category, IElement parentObject) { PluginManager.ReactToStateNameChange(parentObject as IElement, (string)oldValue, stateSave.Name); IElement parentAsElement = parentObject as IElement; string name = parentObject.Name; string typeToMatch = "VariableState"; if (category != null && category.SharesVariablesWithOtherCategories == false) { typeToMatch = "Current" + category.Name + "State"; } var matchingVariables = from variable in parentAsElement.CustomVariables where variable.DefaultValue == oldValue && variable.Type == typeToMatch select variable; foreach (CustomVariable variable in matchingVariables) { variable.DefaultValue = stateSave.Name; } string variableName = stateSave.GetExposedVariableName(parentObject); string variableType = stateSave.GetEnumTypeName(parentObject); // Find any NOSs that use the ParentObject as their type foreach (ScreenSave screenSave in ObjectFinder.Self.GlueProject.Screens) { var customQuery = from nos in screenSave.AllNamedObjects where nos.SourceType == SourceType.Entity && nos.SourceClassType == name select nos; foreach (var nos in customQuery) { if (nos.CurrentState == (oldValue as string)) { nos.CurrentState = stateSave.Name; } foreach (var variable in nos.InstructionSaves.Where(item => item.Member == variableName && (item.Value as string) == (oldValue as string))) { variable.Value = stateSave.Name; } } } foreach (EntitySave entitySave in ObjectFinder.Self.GlueProject.Entities) { var customQuery = from nos in entitySave.AllNamedObjects where nos.SourceType == SourceType.Entity && nos.SourceClassType == name select nos; foreach (var nos in customQuery) { if (nos.CurrentState == (oldValue as string)) { nos.CurrentState = stateSave.Name; } foreach (var variable in nos.InstructionSaves.Where(item => item.Member == variableName && (item.Value as string) == (oldValue as string))) { variable.Value = stateSave.Name; } } } }
private void UpdateIncludedAndExcluded(StateSaveCategory category) { ExcludeMember("States"); }
public void Update(string containerName, StateSaveCategory stateSaveCategory) { var container = ObjectFinder.Self.GetIElement(containerName); var currentNos = container.GetStateCategory(stateSaveCategory.Name); CopyObject(stateSaveCategory, currentNos); RefreshElement(container); //GlueCommand.GluxCommands.SaveGlux(); }
void CreateElementRuntime() { mEntitySave = new EntitySave { Name = "VariableSettingEntity" }; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = 0 }; mEntitySave.CustomVariables.Add(xVariable); // Needs the Z variable exposed so that the uncategorized state below can use it: var zVariable = new CustomVariable { Name = "Z", Type = "float", DefaultValue = 0 }; mEntitySave.CustomVariables.Add(zVariable); CustomVariable stateVariable = new CustomVariable { Name = "CurrentStateSaveCategoryState", Type = "StateSaveCategory", DefaultValue = "FirstState" }; stateVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(stateVariable); CustomVariable uncategorizedStateVariable = new CustomVariable { Name = "CurrentState", Type = "VariableState", //DefaultValue = "Uncategorized", // Don't set a default value - the derived will do this SetByDerived = true }; mEntitySave.CustomVariables.Add(uncategorizedStateVariable); StateSave uncategorized = new StateSave(); uncategorized.Name = "Uncategorized"; InstructionSave instruction = new InstructionSave(); instruction.Member = "Z"; instruction.Value = 8.0f; uncategorized.InstructionSaves.Add(instruction); mEntitySave.States.Add(uncategorized); StateSave stateSave = new StateSave(); stateSave.Name = "FirstState"; instruction = new InstructionSave(); instruction.Member = "X"; instruction.Value = 10; stateSave.InstructionSaves.Add(instruction); StateSave secondStateSave = new StateSave(); secondStateSave.Name = "SecondState"; instruction = new InstructionSave(); instruction.Member = "X"; instruction.Value = -10; secondStateSave.InstructionSaves.Add(instruction); StateSaveCategory category = new StateSaveCategory(); category.Name = "StateSaveCategory"; category.States.Add(stateSave); category.States.Add(secondStateSave); mEntitySave.StateCategoryList.Add(category); mElementRuntime = new ElementRuntime(mEntitySave, null, null, null, null); mElementRuntime.AfterVariableApply += AfterVariableSet; }
public TreeNode StateCategoryTreeNode(StateSaveCategory category) { TreeNode treeNode = TreeNodeByTagIn(category, ElementViewWindow.ScreensTreeNode.Nodes); if (treeNode == null) { treeNode = TreeNodeByTagIn(category, ElementViewWindow.EntitiesTreeNode.Nodes); } return treeNode; }
private void CreateEntitySave() { mEntitySave = ExposedVariableTests.CreateEntitySaveWithStates("StateEntity"); ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mExposedStateVariable = new CustomVariable(); mExposedStateVariable.Name = "CurrentState"; mExposedStateVariable.Type = "VariableState"; mExposedStateVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(mExposedStateVariable); mExposedStateInCategoryVariable = new CustomVariable(); mExposedStateInCategoryVariable.Name = "CurrentStateCategoryState"; mExposedStateInCategoryVariable.Type = "StateCategory"; mExposedStateInCategoryVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(mExposedStateInCategoryVariable); mRenamedExposedUncategorizedStateVariable = new CustomVariable(); mRenamedExposedUncategorizedStateVariable.Name = "RenamedVariable"; mRenamedExposedUncategorizedStateVariable.Type = "VariableState"; mRenamedExposedUncategorizedStateVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(mRenamedExposedUncategorizedStateVariable); mRenamedExposedCategorizedStateVariable = new CustomVariable(); mRenamedExposedCategorizedStateVariable.Name = "RenamedCategorizedVariable"; mRenamedExposedCategorizedStateVariable.Type = "StateCategory"; mEntitySave.CustomVariables.Add(mRenamedExposedCategorizedStateVariable); // Let's add some states now StateSave stateSave = new StateSave(); stateSave.Name = "FirstState"; mEntitySave.States.Add(stateSave); stateSave = new StateSave(); stateSave.Name = "SecondState"; mEntitySave.States.Add(stateSave); StateSaveCategory category = new StateSaveCategory(); category.Name = "SharedVariableCategory"; mEntitySave.StateCategoryList.Add(category); stateSave = new StateSave(); stateSave.Name = "SharedStateSave"; category.States.Add(stateSave); }