public StateSave AddState(ElementSave elementToAddTo, StateSaveCategory category, string name) { if (elementToAddTo == null) { throw new Exception("Could not add state named " + name + " because no element is selected"); } StateSave stateSave = new StateSave(); stateSave.Name = name; AddState(elementToAddTo, category, stateSave); return stateSave; }
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 StateSaveCategory Clone() { var toReturn = new StateSaveCategory(); toReturn.Name = this.Name; foreach (var state in this.States) { var clone = state.Clone(); toReturn.States.Add(clone); } return(toReturn); }
public StateSaveCategory AddCategory(ElementSave elementToAddTo, string name) { if (elementToAddTo == null) { throw new Exception("Could not add category " + name + " because no element is selected"); } StateSaveCategory category = new StateSaveCategory(); category.Name = name; elementToAddTo.Categories.Add(category); string categoryName = category.Name + "State"; elementToAddTo.DefaultState.Variables.Add(new VariableSave() { Name = categoryName, Type = categoryName, Value = null #if GUM , CustomTypeConverter = new Gum.PropertyGridHelpers.Converters.AvailableStatesConverter(category.Name) #endif }); elementToAddTo.DefaultState.Variables.Sort((first, second) => first.Name.CompareTo(second.Name)); return category; }
public static bool IsState(this VariableSave variableSave, ElementSave container, out ElementSave categoryContainer, out StateSaveCategory category, bool recursive = true) { category = null; categoryContainer = null; var variableName = variableSave.GetRootName(); ///////////////Early Out if(variableName.EndsWith("State") == false && string.IsNullOrEmpty(variableSave.SourceObject )) { return false; } /////////////End early out // what about uncategorized string categoryName = null; if (variableName.EndsWith("State")) { categoryName = variableName.Substring(0, variableName.Length - "State".Length); } if(string.IsNullOrEmpty( variableSave.SourceObject) == false) { var instanceSave = container.GetInstance(variableSave.SourceObject); if(instanceSave != null) { var element = ObjectFinder.Self.GetElementSave(instanceSave.BaseType); if(element != null) { // let's try going recursively: var subVariable = element.DefaultState.Variables.FirstOrDefault(item => item.ExposedAsName == variableSave.GetRootName()); if (subVariable != null && recursive) { return subVariable.IsState(element, out categoryContainer, out category); } else { if (variableName == "State") { categoryContainer = element; category = null; return true; } else { category = element.GetStateSaveCategoryRecursively(categoryName, out categoryContainer); return category != null; } } } } } else { if (variableName == "State") { return true; } else { category = container.GetStateSaveCategoryRecursively(categoryName, out categoryContainer); return category != null; } } return false; }
public void AddState(ElementSave elementToAddTo, StateSaveCategory category, StateSave stateSave) { stateSave.ParentContainer = elementToAddTo; if (category == null) { elementToAddTo.States.Add(stateSave); } else { category.States.Add(stateSave); } }
public void RemoveStateCategory(StateSaveCategory category, ElementSave elementToRemoveFrom) { elementToRemoveFrom.Categories.Remove(category); GumCommands.Self.FileCommands.TryAutoSaveCurrentElement(); }
public void Select(StateSaveCategory stateSaveCategory) { TreeNode treeNode = GetTreeNodeForTag(stateSaveCategory); Select(treeNode); }
private static void UpdateTextStateCategory() { var textStandard = AppState.Self.GumProjectSave.StandardElements .FirstOrDefault(item => item.Name == "Text"); if (textStandard != null) { var added = false; var category = textStandard .Categories.FirstOrDefault(item => item.Name == "ColorCategory"); if (category == null) { category = new Gum.DataTypes.Variables.StateSaveCategory(); category.Name = "ColorCategory"; textStandard.Categories.Add(category); added = true; } var grayState = category.States .FirstOrDefault(item => item.Name == "Gray"); if (grayState == null) { grayState = new Gum.DataTypes.Variables.StateSave(); grayState.Name = "Gray"; category.States.Add(grayState); grayState.Variables.Add(new Gum.DataTypes.Variables.VariableSave { Type = "int", Name = "Blue", Value = 208, Category = "Rendering", SetsValue = true }); grayState.Variables.Add(new Gum.DataTypes.Variables.VariableSave { Type = "int", Name = "Green", Value = 208, Category = "Rendering", SetsValue = true }); grayState.Variables.Add(new Gum.DataTypes.Variables.VariableSave { Type = "int", Name = "Red", Value = 208, Category = "Rendering", SetsValue = true }); grayState.Initialize(); added = true; } var blackState = category.States .FirstOrDefault(item => item.Name == "Black"); if (blackState == null) { blackState = new Gum.DataTypes.Variables.StateSave(); blackState.Name = "Black"; category.States.Add(blackState); blackState.Variables.Add(new Gum.DataTypes.Variables.VariableSave { Type = "int", Name = "Blue", Value = 49, Category = "Rendering", SetsValue = true }); blackState.Variables.Add(new Gum.DataTypes.Variables.VariableSave { Type = "int", Name = "Green", Value = 49, Category = "Rendering", SetsValue = true }); blackState.Variables.Add(new Gum.DataTypes.Variables.VariableSave { Type = "int", Name = "Red", Value = 49, Category = "Rendering", SetsValue = true }); blackState.Initialize(); added = true; } if (added) { AppCommands.Self.SaveStandardElement(textStandard); } } }