private static StandardElementSave GetRootElement() { StandardElementSave rootElement = null; if (SelectedState.Self.SelectedInstance != null) { rootElement = ObjectFinder.Self.GetRootStandardElementSave(SelectedState.Self.SelectedInstance); } else if (SelectedState.Self.SelectedElement != null) { rootElement = ObjectFinder.Self.GetRootStandardElementSave(SelectedState.Self.SelectedElement); } return(rootElement); }
private static bool GetIfShouldInclude(VariableListSave variableList, ElementSave container, InstanceSave currentInstance) { bool toReturn = (string.IsNullOrEmpty(variableList.SourceObject)); if (toReturn) { StandardElementSave rootElementSave = null; if (currentInstance != null) { rootElementSave = ObjectFinder.Self.GetRootStandardElementSave(currentInstance); } else if ((container is ScreenSave) == false) { rootElementSave = ObjectFinder.Self.GetRootStandardElementSave(container); } toReturn = VariableSaveLogic.GetShouldIncludeBasedOnBaseType(variableList, container, rootElementSave); } return(toReturn); }
public StateReferencingInstanceMember(InstanceSavePropertyDescriptor ispd, StateSave stateSave, StateSaveCategory stateSaveCategory, string variableName, InstanceSave instanceSave, ElementSave elementSave) : base(variableName, stateSave) { StateSaveCategory = stateSaveCategory; mInstanceSave = instanceSave; mStateSave = stateSave; mVariableName = variableName; mPropertyDescriptor = ispd; mElementSave = elementSave; if (ispd.IsReadOnly) { // don't assign it (can't null it) //this.CustomSetEvent = null; } else { this.CustomSetEvent += HandleCustomSet; } this.CustomGetEvent += HandleCustomGet; this.CustomGetTypeEvent += HandleCustomGetType; this.SortValue = int.MaxValue; if (instanceSave != null) { this.Instance = instanceSave; } else { this.Instance = elementSave; } var alreadyHasSpaces = RootVariableName?.Contains(" "); if (alreadyHasSpaces == false) { DisplayName = ToolsUtilities.StringFunctions.InsertSpacesInCamelCaseString(RootVariableName); } else { DisplayName = RootVariableName; } TryAddExposeVariableMenuOptions(instanceSave); // This could be slow since we have to check it for every variable in an object. // Maybe we'll want to pass this in to the function? StandardElementSave standardElement = null; if (instanceSave != null) { standardElement = ObjectFinder.Self.GetRootStandardElementSave(instanceSave); } else { standardElement = ObjectFinder.Self.GetRootStandardElementSave(elementSave); } VariableSave standardVariable = null; if (standardElement != null) { standardVariable = standardElement.DefaultState.Variables.FirstOrDefault(item => item.Name == RootVariableName); } if (standardVariable != null) { this.SortValue = standardVariable.DesiredOrder; } }
private void AddAndRemoveScreensComponentsAndStandards(TreeNode folderTreeNode) { if (ProjectManager.Self.GumProjectSave == null) { return; } // Save off old selected stuff InstanceSave selectedInstance = SelectedState.Self.SelectedInstance; ElementSave selectedElement = SelectedState.Self.SelectedElement; BehaviorSave selectedBehavior = SelectedState.Self.SelectedBehavior; if (!string.IsNullOrEmpty(ProjectManager.Self.GumProjectSave.FullFileName)) { string currentDirectory = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName); if (folderTreeNode != null) { currentDirectory = folderTreeNode.GetFullFilePath(); } } #region Add nodes that haven't been added yet foreach (ScreenSave screenSave in ProjectManager.Self.GumProjectSave.Screens) { if (GetTreeNodeFor(screenSave) == null) { string fullPath = FileLocations.Self.ScreensFolder + FileManager.GetDirectory(screenSave.Name); TreeNode parentNode = GetTreeNodeFor(fullPath); AddTreeNodeForElement(screenSave, parentNode, ScreenImageIndex); } } foreach (ComponentSave componentSave in ProjectManager.Self.GumProjectSave.Components) { if (GetTreeNodeFor(componentSave) == null) { string fullPath = FileLocations.Self.ComponentsFolder + FileManager.GetDirectory(componentSave.Name); TreeNode parentNode = GetTreeNodeFor(fullPath); if (parentNode == null) { throw new Exception($"Error trying to get parent node for component {fullPath}"); } AddTreeNodeForElement(componentSave, parentNode, ComponentImageIndex); } } foreach (StandardElementSave standardSave in ProjectManager.Self.GumProjectSave.StandardElements) { if (standardSave.Name != "Component") { if (GetTreeNodeFor(standardSave) == null) { AddTreeNodeForElement(standardSave, mStandardElementsTreeNode, StandardElementImageIndex); } } } foreach (BehaviorSave behaviorSave in ProjectManager.Self.GumProjectSave.Behaviors) { if (GetTreeNodeFor(behaviorSave) == null) { string fullPath = FileLocations.Self.BehaviorsFolder + FileManager.GetDirectory(behaviorSave.Name); TreeNode parentNode = GetTreeNodeFor(fullPath); AddTreeNodeForBehavior(behaviorSave, parentNode, BehaviorImageIndex); } } #endregion #region Remove nodes that are no longer needed for (int i = mScreensTreeNode.Nodes.Count - 1; i > -1; i--) { ScreenSave screen = mScreensTreeNode.Nodes[i].Tag as ScreenSave; // If the screen is null, that means that it's a folder TreeNode, so we don't want to remove it if (screen != null) { if (!ProjectManager.Self.GumProjectSave.Screens.Contains(screen)) { mScreensTreeNode.Nodes.RemoveAt(i); } } } for (int i = mComponentsTreeNode.Nodes.Count - 1; i > -1; i--) { ComponentSave component = mComponentsTreeNode.Nodes[i].Tag as ComponentSave; // If the component is null, that means that it's a folder TreeNode, so we don't want to remove it if (component != null) { if (!ProjectManager.Self.GumProjectSave.Components.Contains(component)) { mComponentsTreeNode.Nodes.RemoveAt(i); } } } for (int i = mStandardElementsTreeNode.Nodes.Count - 1; i > -1; i--) { // Do we want to support folders here? StandardElementSave standardElement = mStandardElementsTreeNode.Nodes[i].Tag as StandardElementSave; if (!ProjectManager.Self.GumProjectSave.StandardElements.Contains(standardElement)) { mStandardElementsTreeNode.Nodes.RemoveAt(i); } } for (int i = mBehaviorsTreeNode.Nodes.Count - 1; i > -1; i--) { BehaviorSave behavior = mBehaviorsTreeNode.Nodes[i].Tag as BehaviorSave; if (behavior != null) { if (!ProjectManager.Self.GumProjectSave.Behaviors.Contains(behavior)) { mBehaviorsTreeNode.Nodes.RemoveAt(i); } } } #endregion #region Update the nodes foreach (TreeNode treeNode in mScreensTreeNode.Nodes) { RefreshUi(treeNode); } foreach (TreeNode treeNode in mComponentsTreeNode.Nodes) { RefreshUi(treeNode); } foreach (TreeNode treeNode in mStandardElementsTreeNode.Nodes) { RefreshUi(treeNode); } foreach (TreeNode treeNode in mBehaviorsTreeNode.Nodes) { RefreshUi(treeNode); } #endregion #region Sort everything mScreensTreeNode.Nodes.SortByName(recursive: true); mComponentsTreeNode.Nodes.SortByName(recursive: true); mStandardElementsTreeNode.Nodes.SortByName(recursive: true); mBehaviorsTreeNode.Nodes.SortByName(recursive: true); #endregion #region Re-select whatever was selected before if (selectedInstance != null) { SelectedState.Self.SelectedInstance = selectedInstance; } if (selectedBehavior != null) { SelectedState.Self.SelectedBehavior = selectedBehavior; } #endregion }
public TreeNode GetTreeNodeFor(StandardElementSave standardElementSave) { return(GetTreeNodeForTag(standardElementSave, RootStandardElementsTreeNode)); }
private static bool GetShouldIncludeBasedOnBaseType(VariableSave defaultVariable, ElementSave container, InstanceSave instanceSave, StandardElementSave rootElementSave) { bool shouldInclude = false; if (string.IsNullOrEmpty(defaultVariable.SourceObject)) { if (container is ScreenSave) { // If it's a Screen, then the answer is "yes" because // Screens don't have a base type that they can switch, // so any variable that's part of the Screen is always part // of the Screen. // do nothing to shouldInclude shouldInclude = true; } else { if (container is ComponentSave) { // See if it's defined in the standards list var foundInstance = StandardElementsManager.Self.GetDefaultStateFor("Component").Variables.FirstOrDefault( item => item.Name == defaultVariable.Name); shouldInclude = foundInstance != null; } // If the defaultVariable's // source object is null then // that means that the variable // is being set on "this". However, // variables that are set on "this" may // not actually be valid for the type, but // they may still exist because the object type // was switched. Therefore, we want to make sure // that the variable is valid given the type of object // that "this" currently is by checking the default state // on the rootElementSave if (!shouldInclude && rootElementSave != null) { shouldInclude = rootElementSave.DefaultState.GetVariableSave(defaultVariable.Name) != null; } string nameWithoutState = null; if (!shouldInclude && defaultVariable.Name.EndsWith("State") && instanceSave != null) { nameWithoutState = defaultVariable.Name.Substring(0, defaultVariable.Name.Length - "State".Length); var instanceElement = ObjectFinder.Self.GetElementSave(instanceSave.BaseType); // See if this is a category: if (!string.IsNullOrEmpty(nameWithoutState) && instanceElement != null && instanceElement.Categories.Any(item => item.Name == nameWithoutState)) { shouldInclude = true; } } if (!shouldInclude && instanceSave == null && defaultVariable.IsState(container)) { return(true); } } } else { shouldInclude = SelectedState.Self.SelectedInstance != null || !string.IsNullOrEmpty(defaultVariable.ExposedAsName); } return(shouldInclude); }
public static bool GetShouldIncludeBasedOnBaseType(VariableListSave variableList, ElementSave container, StandardElementSave rootElementSave) { bool shouldInclude = false; if (string.IsNullOrEmpty(variableList.SourceObject)) { if (container is ScreenSave) { // If it's a Screen, then the answer is "yes" because // Screens don't have a base type that they can switch, // so any variable that's part of the Screen is always part // of the Screen. shouldInclude = true; } else { if (container is ComponentSave) { // See if it's defined in the standards list var foundInstance = StandardElementsManager.Self.GetDefaultStateFor("Component").VariableLists.FirstOrDefault( item => item.Name == variableList.Name); shouldInclude = foundInstance != null; } // If the defaultVariable's // source object is null then // that means that the variable // is being set on "this". However, // variables that are set on "this" may // not actually be valid for the type, but // they may still exist because the object type // was switched. Therefore, we want to make sure // that the variable is valid given the type of object // that "this" currently is by checking the default state // on the rootElementSave if (!shouldInclude && rootElementSave != null) { shouldInclude = rootElementSave.DefaultState.GetVariableListRecursive(variableList.Name) != null; } } } else { shouldInclude = SelectedState.Self.SelectedInstance != null // VariableLists cannot be exposed (currently) //|| !string.IsNullOrEmpty(variableList.ExposedAsName); ; } return(shouldInclude); }
private static PropertyDescriptorCollection DisplayCurrentElement(PropertyDescriptorCollection pdc, ElementSave elementSave, InstanceSave instanceSave, StateSave defaultState, string prependedVariable, AmountToDisplay amountToDisplay = AmountToDisplay.AllVariables) { bool isDefault = SelectedState.Self.SelectedStateSave == SelectedState.Self.SelectedElement.DefaultState; if (!string.IsNullOrEmpty(prependedVariable)) { prependedVariable += "."; } bool isCustomType = (elementSave is StandardElementSave) == false; if (isDefault && (isCustomType || instanceSave != null)) { pdc = AddNameAndBaseTypeProperties(pdc); } if (instanceSave != null) { if (isDefault) { pdc = mHelper.AddProperty(pdc, "Locked", typeof(bool)); } } // if component if (instanceSave == null && elementSave as ComponentSave != null) { foreach (var item in StandardElementsManager.Self.GetDefaultStateFor("Component").Variables) { pdc = TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, null, item); } } // else if screen else if (instanceSave == null && elementSave as ScreenSave != null) { foreach (var item in StandardElementsManager.Self.GetDefaultStateFor("Screen").Variables) { pdc = TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, null, item); } } #region Get the StandardElementSave for the instance/element (depending on what's selected) StandardElementSave ses = null; if (instanceSave != null) { ses = ObjectFinder.Self.GetRootStandardElementSave(instanceSave); } else if ((elementSave is ScreenSave) == false) { ses = ObjectFinder.Self.GetRootStandardElementSave(elementSave); } #endregion #region Loop through all variables // We want to use the default state to get all possible // variables because the default state will always set all // variables. We then look at the current state to get the // actual value for (int i = 0; i < defaultState.Variables.Count; i++) { VariableSave defaultVariable = defaultState.Variables[i]; pdc = TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, ses, defaultVariable); } #endregion #region Loop through all list variables for (int i = 0; i < defaultState.VariableLists.Count; i++) { VariableListSave variableList = defaultState.VariableLists[i]; bool shouldInclude = GetIfShouldInclude(variableList, elementSave, instanceSave, null); if (shouldInclude) { TypeConverter typeConverter = variableList.GetTypeConverter(); Attribute[] customAttributes = GetAttributesForVariable(variableList); Type type = typeof(List <string>); pdc = mHelper.AddProperty(pdc, variableList.Name, type, typeConverter, // //, customAttributes ); } } #endregion return(pdc); }
private static bool GetIfShouldInclude(VariableSave defaultVariable, ElementSave container, InstanceSave currentInstance, StandardElementSave rootElementSave) { bool shouldInclude = GetIfShouldIncludeAccordingToDefaultState(defaultVariable, container, currentInstance); if (shouldInclude) { shouldInclude = GetShouldIncludeBasedOnAttachments(defaultVariable, container, currentInstance); } if (shouldInclude) { shouldInclude = GetShouldIncludeBasedOnBaseType(defaultVariable, container, currentInstance, rootElementSave); } if (shouldInclude) { RecursiveVariableFinder rvf; if (currentInstance != null) { rvf = new RecursiveVariableFinder(currentInstance, container); } else { rvf = new RecursiveVariableFinder(container.DefaultState); } shouldInclude = !PluginManager.Self.ShouldExclude(defaultVariable, rvf); } return(shouldInclude); }
private static bool GetIfShouldInclude(VariableListSave variableList, ElementSave container, InstanceSave currentInstance, StandardElementSave rootElementSave) { bool toReturn = (string.IsNullOrEmpty(variableList.SourceObject)); if (toReturn) { toReturn = GetShouldIncludeBasedOnBaseType(variableList, container, rootElementSave); } return(toReturn); }
private static PropertyDescriptorCollection TryDisplayVariableSave(PropertyDescriptorCollection pdc, ElementSave elementSave, InstanceSave instanceSave, AmountToDisplay amountToDisplay, StandardElementSave ses, VariableSave defaultVariable) { ElementSave container = elementSave; if (instanceSave != null) { container = instanceSave.ParentContainer; } // Not sure why we were passing elementSave to this function: // I added a container object //bool shouldInclude = GetIfShouldInclude(defaultVariable, elementSave, instanceSave, ses); bool shouldInclude = GetIfShouldInclude(defaultVariable, container, instanceSave, ses); shouldInclude &= ( string.IsNullOrEmpty(defaultVariable.SourceObject) || amountToDisplay == AmountToDisplay.AllVariables || !string.IsNullOrEmpty(defaultVariable.ExposedAsName)); if (shouldInclude) { TypeConverter typeConverter = defaultVariable.GetTypeConverter(elementSave); Attribute[] customAttributes = GetAttributesForVariable(defaultVariable); //Type type = typeof(string); Type type = Gum.Reflection.TypeManager.Self.GetTypeFromString(defaultVariable.Type); string name = defaultVariable.Name; if (!string.IsNullOrEmpty(defaultVariable.ExposedAsName)) { name = defaultVariable.ExposedAsName; } pdc = mHelper.AddProperty(pdc, name, type, typeConverter, //, customAttributes ); } return(pdc); }
private void GenerateStates(StandardElementSave standardElementSave, ICodeBlock currentBlock) { StateCodeGenerator.Self.GenerateEverythingFor(standardElementSave, currentBlock); }
private GraphicalUiElement CreateRepresentationsForInstanceFromComponent(InstanceSave instance, List <ElementWithState> elementStack, InstanceSave parentInstance, GraphicalUiElement parentIpso, ComponentSave baseComponentSave) { StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(instance); GraphicalUiElement rootIpso = null; if (ses != null) { rootIpso = new GraphicalUiElement(null, parentIpso); string type = ses.Name; var renderable = PluginManager.Self.CreateRenderableForType(type); if (renderable != null) { rootIpso.SetContainedObject(renderable); rootIpso.Tag = instance; rootIpso.Component.Name = instance.Name; rootIpso.Component.Tag = instance; } else if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle") { ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType); rootIpso.CreateGraphicalComponent(instanceBase, null); rootIpso.Tag = instance; rootIpso.Component.Name = instance.Name; rootIpso.Component.Tag = instance; if (type == "Text") { (rootIpso.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines; } } else { // give the plugin manager a shot at it: CreateRectangleFor(instance, elementStack, rootIpso); } var selectedState = SelectedState.Self.SelectedStateSave; if (selectedState == null) { selectedState = SelectedState.Self.SelectedElement.DefaultState; } RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState); string guide = rvf.GetValue <string>("Guide"); SetGuideParent(parentIpso, rootIpso, guide); ElementWithState elementWithState = new ElementWithState(baseComponentSave); var tempRvf = new DataTypes.RecursiveVariableFinder(instance, elementStack); var state = tempRvf.GetValue("State") as string; elementWithState.StateName = state; foreach (var category in baseComponentSave.Categories) { elementWithState.CategorizedStates.Add(category.Name, tempRvf.GetValue <string>(category.Name + "State")); } elementWithState.InstanceName = instance.Name; // Does this element already exist? bool alreadyExists = elementStack.Any(item => item.Element == elementWithState.Element); if (!alreadyExists) { elementStack.Add(elementWithState); foreach (InstanceSave internalInstance in baseComponentSave.Instances) { // let's make sure we don't recursively create the same instance causing a stack overflow: GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso); } } SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances); elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave)); } return(rootIpso); }
private GeneralResponse GetReferencesInProjectOrDisk(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, ProjectOrDisk projectOrDisk) { GeneralResponse generalResponse = GeneralResponse.SuccessfulResponse; if (CanTrackDependenciesOn(fileName)) { string extension = FileManager.GetExtension(fileName); string oldRelative = FileManager.RelativeDirectory; string gumxFile = null; FileManager.RelativeDirectory = GetGumxDirectory(fileName); LoadGumxIfNecessaryFromDirectory(FileManager.RelativeDirectory); string absoluteFileName = fileName; if (FileManager.IsRelative(absoluteFileName)) { absoluteFileName = FileManager.RelativeDirectory + absoluteFileName; } string errors = null; if (System.IO.File.Exists(absoluteFileName)) { switch (extension) { case "gumx": { try { LoadGumxIfNecessaryFromDirectory(FileManager.RelativeDirectory, force: true); GetFilesReferencedBy(Gum.Managers.ObjectFinder.Self.GumProjectSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; case "gucx": { ComponentSave gumComponentSave = null; try { gumComponentSave = FileManager.XmlDeserialize <ComponentSave>(absoluteFileName); gumComponentSave.FileName = absoluteFileName; // See an explanation for this in LoadGumxIfNecessaryFromDirectory gumComponentSave.Initialize(gumComponentSave.DefaultState); GetFilesReferencedBy(gumComponentSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; case "gusx": { ScreenSave gumScreenSave = null; try { gumScreenSave = FileManager.XmlDeserialize <ScreenSave>(absoluteFileName); gumScreenSave.FileName = absoluteFileName; // See an explanation for this in LoadGumxIfNecessaryFromDirectory gumScreenSave.Initialize(gumScreenSave.DefaultState); GetFilesReferencedBy(gumScreenSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; case "gutx": { StandardElementSave standardElementSave = null; try { standardElementSave = FileManager.XmlDeserialize <StandardElementSave>(absoluteFileName); standardElementSave.FileName = absoluteFileName; // See an explanation for this in LoadGumxIfNecessaryFromDirectory standardElementSave.Initialize(standardElementSave.DefaultState); GetFilesReferencedBy(standardElementSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; } } if (errors != null) { generalResponse = new GeneralResponse { Succeeded = false, Message = errors }; } FileManager.RelativeDirectory = oldRelative; } return(generalResponse); }