public static VariableSave GetVariableFromThisOrBase(this InstanceSave instance, ElementWithState parent, string variable, bool forceDefault) { var elementStack = new List<ElementWithState> { parent }; return GetVariableFromThisOrBase(instance, elementStack, new RecursiveVariableFinder(instance, elementStack), variable, forceDefault, false); }
public bool ShouldSkipDraggingMovementOn(InstanceSave instanceSave) { ElementWithState element = new ElementWithState(SelectedState.Self.SelectedElement); List <ElementWithState> stack = new List <ElementWithState>() { element }; var selectedInstances = SelectedState.Self.SelectedInstances; bool shouldSkip = false; // Make sure this isn't attached to another instance var representation = WireframeObjectManager.Self.GetRepresentation(instanceSave, stack); if (representation != null && representation.Parent != null) { var parentRepresentation = representation.Parent; if (parentRepresentation != null) { var parentInstance = WireframeObjectManager.Self.GetInstance(parentRepresentation, InstanceFetchType.InstanceInCurrentElement, stack); if (selectedInstances.Contains(parentInstance)) { shouldSkip = true; } } } return(shouldSkip); }
private static bool TryAddToElementStack(InstanceSave instanceSave, List <ElementWithState> elementStack, out ElementSave selectedElement) { bool toReturn = false; if (instanceSave == null) { selectedElement = elementStack.Last().Element; } else { selectedElement = ObjectFinder.Self.GetElementSave(instanceSave.BaseType); if (elementStack.Count == 0 || elementStack.Last().Element != selectedElement) { ElementWithState elementWithState = new ElementWithState(selectedElement); var state = new DataTypes.RecursiveVariableFinder(instanceSave, elementStack).GetValue("State") as string; elementWithState.StateName = state; elementStack.Add(elementWithState); toReturn = true; } } return(toReturn); }
public InstanceSave GetInstance(IRenderableIpso representation, ElementSave instanceContainer, string prefix, InstanceFetchType fetchType, List <ElementWithState> elementStack) { if (instanceContainer == null) { return(null); } InstanceSave toReturn = null; string qualifiedName = representation.GetAttachmentQualifiedName(elementStack); // strip off the guide name if it starts with a guide qualifiedName = StripGuideOrParentNameIfNecessaryName(qualifiedName, representation); foreach (InstanceSave instanceSave in instanceContainer.Instances) { if (prefix + instanceSave.Name == qualifiedName) { toReturn = instanceSave; break; } } if (toReturn == null) { foreach (InstanceSave instanceSave in instanceContainer.Instances) { ElementSave instanceElement = instanceSave.GetBaseElementSave(); bool alreadyInStack = elementStack.Any(item => item.Element == instanceElement); if (!alreadyInStack) { var elementWithState = new ElementWithState(instanceElement); elementStack.Add(elementWithState); toReturn = GetInstance(representation, instanceElement, prefix + instanceSave.Name + ".", fetchType, elementStack); if (toReturn != null) { if (fetchType == InstanceFetchType.DeepInstance) { // toReturn will be toReturn, no need to do anything } else // fetchType == InstanceInCurrentElement { toReturn = instanceSave; } break; } elementStack.Remove(elementWithState); } } } return(toReturn); }
private GraphicalUiElement CreateIpsoForElement(ElementSave elementSave) { GraphicalUiElement rootIpso = null; bool isScreen = elementSave is ScreenSave; rootIpso = new GraphicalUiElement(); rootIpso.Tag = elementSave; mGraphicalElements.Add(rootIpso); rootIpso.ElementSave = elementSave; if (isScreen == false) { // We used to not add the IPSO for the root element to the list of graphical elements // and this prevented selection. I'm not sure if this was intentionally left out or not // but I think it should be here mGraphicalElements.Add(rootIpso); rootIpso.CreateGraphicalComponent(elementSave, null); rootIpso.Component.Name = elementSave.Name; rootIpso.Component.Tag = elementSave; RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(SelectedState.Self.SelectedStateSaveOrDefault); string guide = rvf.GetValue<string>("Guide"); SetGuideParent(null, rootIpso, guide, true); } foreach(var exposedVariable in elementSave.DefaultState.Variables.Where(item=> !string.IsNullOrEmpty(item.ExposedAsName) )) { rootIpso.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name); } List<GraphicalUiElement> newlyAdded = new List<GraphicalUiElement>(); List<ElementWithState> elementStack = new List<ElementWithState>(); ElementWithState elementWithState = new ElementWithState(elementSave); if (elementSave == SelectedState.Self.SelectedElement) { if (SelectedState.Self.SelectedStateSave != null) { elementWithState.StateName = SelectedState.Self.SelectedStateSave.Name; } else { elementWithState.StateName = "Default"; } } elementStack.Add(elementWithState); // parallel screws up the ordering of objects, so we'll do it on the primary thread for now // and parallelize it later: //Parallel.ForEach(elementSave.Instances, instance => foreach (var instance in elementSave.Instances) { GraphicalUiElement child = CreateRepresentationForInstance(instance, null, elementStack, rootIpso); if (child == null) { // This can occur // if an instance references // a component that doesn't exist. // I don't think we need to do anything // here. } else { newlyAdded.Add(child); mGraphicalElements.Add(child); } } SetUpParentRelationship(newlyAdded, elementStack, elementSave.Instances); //); elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == elementSave)); rootIpso.SetStatesAndCategoriesRecursively(elementSave); // First we need to the default state (and do so recursively) rootIpso.SetVariablesRecursively(elementSave, elementSave.DefaultState); // then we override it with the current state if one is set: if (SelectedState.Self.SelectedStateSave != elementSave.DefaultState && SelectedState.Self.SelectedStateSave != null) { var state = SelectedState.Self.SelectedStateSave; rootIpso.SetVariablesTopLevel(elementSave, state); } // I think this has to be *after* we set varaibles because that's where clipping gets set if (rootIpso != null) { rootIpso.AddToManagers(); if (rootIpso.ElementSave is ScreenSave) { // If it's a screen and it hasn't been added yet, we need to add it. foreach (var item in rootIpso.ContainedElements.Where(candidate=>candidate.Managers == null)) { item.AddToManagers(); } } } return rootIpso; }
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; 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 { 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, false); 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; elementStack.Add(elementWithState); foreach (InstanceSave internalInstance in baseComponentSave.Instances) { GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso); } SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances); elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave)); } return rootIpso; }
private GraphicalUiElement CreateIpsoForElement(ElementSave elementSave) { GraphicalUiElement rootIpso = null; bool isScreen = elementSave is ScreenSave; rootIpso = new GraphicalUiElement(); // If we don't turn off layouts, layouts can be called tens of thousands of times for // complex elements. We'll turn off layouts, then turn them back on at the end and manually // layout: GraphicalUiElement.IsAllLayoutSuspended = true; { rootIpso.Tag = elementSave; mGraphicalElements.Add(rootIpso); rootIpso.ElementSave = elementSave; if (isScreen == false) { // We used to not add the IPSO for the root element to the list of graphical elements // and this prevented selection. I'm not sure if this was intentionally left out or not // but I think it should be here mGraphicalElements.Add(rootIpso); rootIpso.CreateGraphicalComponent(elementSave, null); // can be null if the element save references a bad file if (rootIpso.Component != null) { rootIpso.Component.Name = elementSave.Name; rootIpso.Component.Tag = elementSave; } RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(SelectedState.Self.SelectedStateSaveOrDefault); string guide = rvf.GetValue <string>("Guide"); SetGuideParent(null, rootIpso, guide); } var exposedVariables = elementSave .DefaultState .Variables .Where(item => !string.IsNullOrEmpty(item.ExposedAsName) && string.IsNullOrEmpty(item.SourceObject)) .ToArray(); foreach (var exposedVariable in exposedVariables) { rootIpso.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name); } List <GraphicalUiElement> newlyAdded = new List <GraphicalUiElement>(); List <ElementWithState> elementStack = new List <ElementWithState>(); ElementWithState elementWithState = new ElementWithState(elementSave); if (elementSave == SelectedState.Self.SelectedElement) { if (SelectedState.Self.SelectedStateSave != null) { elementWithState.StateName = SelectedState.Self.SelectedStateSave.Name; } else { elementWithState.StateName = "Default"; } } elementStack.Add(elementWithState); // parallel screws up the ordering of objects, so we'll do it on the primary thread for now // and parallelize it later: //Parallel.ForEach(elementSave.Instances, instance => foreach (var instance in elementSave.Instances) { GraphicalUiElement child = CreateRepresentationForInstance(instance, null, elementStack, rootIpso); if (child == null) { // This can occur // if an instance references // a component that doesn't exist. // I don't think we need to do anything // here. } else { newlyAdded.Add(child); mGraphicalElements.Add(child); } } SetUpParentRelationship(newlyAdded, elementStack, elementSave.Instances); elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == elementSave)); rootIpso.SetStatesAndCategoriesRecursively(elementSave); // First we need to the default state (and do so recursively) try { rootIpso.SetVariablesRecursively(elementSave, elementSave.DefaultState); } catch (Exception e) { // this barfed, but we don't want to crash the tool GumCommands.Self.GuiCommands.PrintOutput($"Error loading {elementSave}:\n{e.ToString()}"); } // then we override it with the current state if one is set: if (SelectedState.Self.SelectedStateSave != elementSave.DefaultState && SelectedState.Self.SelectedStateSave != null) { var state = SelectedState.Self.SelectedStateSave; rootIpso.ApplyState(state); } if (elementSave is StandardElementSave && elementSave.Name == "Text") { // We created a new Text object, so let's try generating fonts for it: FontManager.Self.ReactToFontValueSet(null); } // I think this has to be *after* we set varaibles because that's where clipping gets set if (rootIpso != null) { gueManager.Add(rootIpso); rootIpso.AddToManagers(); } } GraphicalUiElement.IsAllLayoutSuspended = false; // There is a bug that currently requires layout to be performed twice. // Update Nov 19, 2019 - I don't know when this was written, but layout has // been continually improving, even as recently as today. I'm going to remove // the 2nd call to make things faster and to see if I can spot other issues that // remain after a single UpdateLayout call: //rootIpso.UpdateLayout(); rootIpso.UpdateLayout(); return(rootIpso); }
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 GraphicalUiElement CreateIpsoForElement(ElementSave elementSave) { GraphicalUiElement rootIpso = null; bool isScreen = elementSave is ScreenSave; rootIpso = new GraphicalUiElement(); rootIpso.Tag = elementSave; mGraphicalElements.Add(rootIpso); rootIpso.ElementSave = elementSave; if (isScreen == false) { // We used to not add the IPSO for the root element to the list of graphical elements // and this prevented selection. I'm not sure if this was intentionally left out or not // but I think it should be here mGraphicalElements.Add(rootIpso); rootIpso.CreateGraphicalComponent(elementSave, null); rootIpso.Component.Name = elementSave.Name; rootIpso.Component.Tag = elementSave; RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(SelectedState.Self.SelectedStateSaveOrDefault); string guide = rvf.GetValue <string>("Guide"); SetGuideParent(null, rootIpso, guide, true); } foreach (var exposedVariable in elementSave.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName))) { rootIpso.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name); } List <GraphicalUiElement> newlyAdded = new List <GraphicalUiElement>(); List <ElementWithState> elementStack = new List <ElementWithState>(); ElementWithState elementWithState = new ElementWithState(elementSave); if (elementSave == SelectedState.Self.SelectedElement) { if (SelectedState.Self.SelectedStateSave != null) { elementWithState.StateName = SelectedState.Self.SelectedStateSave.Name; } else { elementWithState.StateName = "Default"; } } elementStack.Add(elementWithState); // parallel screws up the ordering of objects, so we'll do it on the primary thread for now // and parallelize it later: //Parallel.ForEach(elementSave.Instances, instance => foreach (var instance in elementSave.Instances) { GraphicalUiElement child = CreateRepresentationForInstance(instance, null, elementStack, rootIpso); if (child == null) { // This can occur // if an instance references // a component that doesn't exist. // I don't think we need to do anything // here. } else { newlyAdded.Add(child); mGraphicalElements.Add(child); } } SetUpParentRelationship(newlyAdded, elementStack, elementSave.Instances); //); elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == elementSave)); rootIpso.SetStatesAndCategoriesRecursively(elementSave); // First we need to the default state (and do so recursively) rootIpso.SetVariablesRecursively(elementSave, elementSave.DefaultState); // then we override it with the current state if one is set: if (SelectedState.Self.SelectedStateSave != elementSave.DefaultState && SelectedState.Self.SelectedStateSave != null) { var state = SelectedState.Self.SelectedStateSave; rootIpso.SetVariablesTopLevel(elementSave, state); } // I think this has to be *after* we set varaibles because that's where clipping gets set if (rootIpso != null) { rootIpso.AddToManagers(); if (rootIpso.ElementSave is ScreenSave) { // If it's a screen and it hasn't been added yet, we need to add it. foreach (var item in rootIpso.ContainedElements.Where(candidate => candidate.Managers == null)) { item.AddToManagers(); } } } return(rootIpso); }
public List<ElementWithState> GetTopLevelElementStack() { List<ElementWithState> toReturn = new List<ElementWithState>(); if (SelectedElement != null) { ElementWithState item = new ElementWithState(SelectedElement); if (this.SelectedStateSave != null) { item.StateName = this.SelectedStateSave.Name; } toReturn.Add(item); } return toReturn; }
private bool ShouldSkipDraggingMovementOn(InstanceSave instanceSave) { ElementWithState element = new ElementWithState(SelectedState.Self.SelectedElement); List<ElementWithState> stack = new List<ElementWithState>() { element }; var selectedInstances = SelectedState.Self.SelectedInstances; bool shouldSkip = false; // Make sure this isn't attached to another instance var representation = WireframeObjectManager.Self.GetRepresentation(instanceSave, stack); if (representation != null && representation.Parent != null) { var parentRepresentation = representation.Parent; if (parentRepresentation != null) { var parentInstance = WireframeObjectManager.Self.GetInstance(parentRepresentation, InstanceFetchType.InstanceInCurrentElement, stack); if (selectedInstances.Contains(parentInstance)) { shouldSkip = true; } } } return shouldSkip; }