private void HandleAddLinkedComponentClick(object sender, EventArgs e) { ////////////////Early Out///////////////////////// if (ObjectFinder.Self.GumProjectSave == null || string.IsNullOrEmpty(ProjectManager.Self.GumProjectSave.FullFileName)) { MessageBox.Show("You must first save the project before adding a new component"); return; } //////////////End Early Out//////////////////////// OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.Filter = "Gum Component (*.gucx)|*.gucx"; /////////////////Another Early Out//////////////////////// if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } ///////////End Another Early Out////////////////////////// ComponentSave lastImportedComponent = null; for (int i = 0; i < openFileDialog.FileNames.Length; ++i) { FilePath componentFilePath = openFileDialog.FileNames[i]; var gumProject = ObjectFinder.Self.GumProjectSave; var gumProjectDirectory = new FilePath(gumProject.FullFileName).GetDirectoryContainingThis(); var relative = FileManager.MakeRelative(componentFilePath.FullPath, gumProjectDirectory.FullPath); var componentSave = FileManager.XmlDeserialize <ComponentSave>(componentFilePath.FullPath); var reference = new ElementReference(); reference.Name = componentSave.Name; reference.Link = relative; reference.LinkType = LinkType.CopyLocally; // This is what FRB needs, so we'll make it the default. Eventually...we can change this? Make it optional? reference.ElementType = ElementType.Component; gumProject.ComponentReferences.Add(reference); gumProject.ComponentReferences.Sort(); var components = ProjectManager.Self.GumProjectSave.Components; components.Add(componentSave); components.Sort((first, second) => first.Name.CompareTo(second.Name)); componentSave.InitializeDefaultAndComponentVariables(); lastImportedComponent = componentSave; } if (lastImportedComponent != null) { GumCommands.Self.GuiCommands.RefreshElementTreeView(); SelectedState.Self.SelectedComponent = lastImportedComponent; GumCommands.Self.FileCommands.TryAutoSaveProject(); } }
private void PrepareNewComponentSave(ComponentSave componentSave, string componentName) { componentSave.Name = componentName; componentSave.BaseType = "Container"; componentSave.InitializeDefaultAndComponentVariables(); // components shouldn't set their positions to 0 by default, so if the // default state sets those values, we should null them out: var xVariable = componentSave.DefaultState.GetVariableSave("X"); var yVariable = componentSave.DefaultState.GetVariableSave("Y"); if (xVariable != null) { xVariable.Value = null; xVariable.SetsValue = false; } if (yVariable != null) { yVariable.Value = null; yVariable.SetsValue = false; } var hasEventsVariable = componentSave.DefaultState.GetVariableSave("HasEvents"); if (hasEventsVariable != null) { hasEventsVariable.Value = true; } }
private void AddCategoriesFromBehavior(BehaviorSave behaviorSave, ComponentSave component) { foreach (var behaviorCategory in behaviorSave.Categories) { StateSaveCategory matchingComponentCategory = component.Categories.FirstOrDefault(item => item.Name == behaviorCategory.Name); if (matchingComponentCategory == null) { //category doesn't exist, so let's add a clone of it: matchingComponentCategory = new StateSaveCategory(); matchingComponentCategory.Name = behaviorCategory.Name; component.Categories.Add(matchingComponentCategory); } foreach (var behaviorState in behaviorCategory.States) { var matchingComponentState = matchingComponentCategory.States.FirstOrDefault(item => item.Name == behaviorState.Name); if (matchingComponentState == null) { // state doesn't exist, so add it: var newState = new StateSave(); newState.Name = behaviorState.Name; newState.ParentContainer = component; matchingComponentCategory.States.Add(newState); } } } }
/// <summary> /// Returns the ElementSave (Screen, Component, or Standard Element) for the argument elementName /// </summary> /// <param name="elementName">The name of the ElementSave to search for</param> /// <returns>The matching ElementSave, or null if none is found</returns> public ElementSave GetElementSave(string elementName) { if (cachedDictionary != null) { var nameInvariant = elementName?.ToLowerInvariant(); if (nameInvariant != null && cachedDictionary.ContainsKey(nameInvariant)) { return(cachedDictionary[nameInvariant]); } } else { ScreenSave screenSave = GetScreen(elementName); if (screenSave != null) { return(screenSave); } ComponentSave componentSave = GetComponent(elementName); if (componentSave != null) { return(componentSave); } StandardElementSave standardElementSave = GetStandardElement(elementName); if (standardElementSave != null) { return(standardElementSave); } } // If we got here there's nothing by the argument name return(null); }
private List <ErrorViewModel> GetBehaviorErrorsFor(ComponentSave component, GumProjectSave project) { List <ErrorViewModel> toReturn = new List <ErrorViewModel>(); if (component != null) { foreach (var behaviorReference in component.Behaviors) { var behavior = project.Behaviors.FirstOrDefault(item => item.Name == behaviorReference.BehaviorName); if (behavior == null) { toReturn.Add(new ErrorViewModel { Message = $"Missing reference to behavior {behaviorReference.BehaviorName}" }); } else { AddBehaviorErrors(component, toReturn, behavior); } } } return(toReturn); }
public ElementSave GetElementSave(string elementName) { ScreenSave screenSave = GetScreen(elementName); if (screenSave != null) { return(screenSave); } ComponentSave componentSave = GetComponent(elementName); if (componentSave != null) { return(componentSave); } StandardElementSave standardElementSave = GetStandardElement(elementName); if (standardElementSave != null) { return(standardElementSave); } // If we got here there's nothing by the argument name return(null); }
public void AssertIsPartOfProject(ComponentSave componentSave) { if (!ObjectFinder.Self.GumProjectSave.Components.Contains(componentSave)) { throw new Exception("Could not find Component " + componentSave + " in the project"); } }
public void LoadFromFile(string fileName) { if (mProjectFileName == null || ObjectFinder.Self.GumProjectSave == null) { throw new Exception("The GumIDB must be initialized with a project file before loading any components/screens. Make sure you have a .gumx project file in your global content, or call StaticInitialize in code first."); } string oldDir = ToolsUtilities.FileManager.RelativeDirectory; ToolsUtilities.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName); ComponentSave elementSave = FlatRedBall.IO.FileManager.XmlDeserialize <ComponentSave>(fileName); foreach (var state in elementSave.States) { state.Initialize(); state.ParentContainer = elementSave; } foreach (var instance in elementSave.Instances) { instance.ParentContainer = elementSave; } element = elementSave.ToGraphicalUiElement(mManagers, false); //Set the relative directory back once we are done ToolsUtilities.FileManager.RelativeDirectory = oldDir; }
private ComponentSave ToComponent(EntitySave entitySave) { ComponentSave component = new ComponentSave(); component.BaseType = "Container"; component.States.Add(new Gum.DataTypes.Variables.StateSave() { Name = "Default" }); component.Name = entitySave.Name.Substring( "Entities\\".Length); component.DefaultState.SetValue("Width", 0.0f, "float"); component.DefaultState.SetValue("Height", 0.0f, "float"); component.DefaultState.SetValue("Width Units", DimensionUnitType.RelativeToChildren, nameof(DimensionUnitType)); component.DefaultState.SetValue("Height Units", DimensionUnitType.RelativeToChildren, nameof(DimensionUnitType)); AddInstances(entitySave, component); AddStates(entitySave, component); return(component); }
private static InstanceSave HandleDroppedElementInElement(ElementSave draggedAsElementSave, ElementSave target, out bool handled) { InstanceSave newInstance = null; handled = false; if (target == null) { MessageBox.Show("No Screen or Component selected"); } else if (target is StandardElementSave) { MessageBox.Show("Standard types can't contain objects"); } else if (draggedAsElementSave is ScreenSave) { MessageBox.Show("Screens can't be dropped into other Screens or Components"); } else { bool canAdd = true; if (draggedAsElementSave is ComponentSave && target is ComponentSave) { ComponentSave targetAsComponentSave = target as ComponentSave; if (!targetAsComponentSave.CanContainInstanceOfType(draggedAsElementSave.Name)) { MessageBox.Show("Can't add instance of " + draggedAsElementSave.Name + " in " + targetAsComponentSave.Name); canAdd = false; } } if (target.IsSourceFileMissing) { MessageBox.Show("The source file for " + target.Name + " is missing, so it cannot be edited"); canAdd = false; } if (canAdd) { #if DEBUG if (draggedAsElementSave == null) { throw new Exception("DraggedAsElementSave is null and it shouldn't be. For vic - try to put this exception earlier to see what's up."); } #endif string name = GetUniqueNameForNewInstance(draggedAsElementSave, target); // First we want to re-select the target so that it is highlighted in the tree view and not // the object we dragged off. This is so that plugins can properly use the SelectedElement. ElementTreeViewManager.Self.Select(target); newInstance = ElementTreeViewManager.Self.AddInstance(name, draggedAsElementSave.Name, target); handled = true; } } return(newInstance); }
private static void AddBehaviorErrors(ComponentSave component, List <ErrorViewModel> toReturn, DataTypes.Behaviors.BehaviorSave behavior) { foreach (var behaviorInstance in behavior.RequiredInstances) { var candidateInstances = component.Instances.Where(item => item.Name == behaviorInstance.Name).ToList(); if (!string.IsNullOrEmpty(behaviorInstance.BaseType)) { candidateInstances = candidateInstances.Where(item => item.IsOfType(behaviorInstance.BaseType)).ToList(); } if (behaviorInstance.Behaviors.Any()) { var requiredBehaviorNames = behaviorInstance.Behaviors.Select(item => item.Name); candidateInstances = candidateInstances.Where(item => { bool fulfillsRequirements = false; var element = ObjectFinder.Self.GetComponent(item.BaseType); if (element != null) { var implementedBehaviorNames = element.Behaviors.Select(implementedBehavior => implementedBehavior.BehaviorName); fulfillsRequirements = requiredBehaviorNames.All(required => implementedBehaviorNames.Contains(required)); } return(fulfillsRequirements); }).ToList(); } if (!candidateInstances.Any()) { string message = $"Missing instance with name {behaviorInstance.Name}"; if (!string.IsNullOrEmpty(behaviorInstance.BaseType)) { message += $" of type {behaviorInstance.BaseType}"; } if (behaviorInstance.Behaviors.Any()) { if (behaviorInstance.Behaviors.Count == 1) { message += " with behavior type"; } else { message += " with behavior types"; } var behaviorsJoined = string.Join(", ", behaviorInstance.Behaviors.Select(item => item.Name).ToArray()); message += behaviorsJoined; } message += $" needed by behavior {behavior.Name}"; toReturn.Add(new ErrorViewModel { Message = message }); } } }
public void AddComponentClick(object sender, EventArgs e) { if (ObjectFinder.Self.GumProjectSave == null || string.IsNullOrEmpty(ProjectManager.Self.GumProjectSave.FullFileName)) { MessageBox.Show("You must first save the project before adding a new component"); } else { TextInputWindow tiw = new TextInputWindow(); tiw.Message = "Enter new Component name:"; if (tiw.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string name = tiw.Result; string whyNotValid; if (!NameVerifier.Self.IsComponentNameValid(name, null, out whyNotValid)) { MessageBox.Show(whyNotValid); } else { TreeNode nodeToAddTo = ElementTreeViewManager.Self.SelectedNode; while (nodeToAddTo != null && nodeToAddTo.Tag is ComponentSave && nodeToAddTo.Parent != null) { nodeToAddTo = nodeToAddTo.Parent; } if (nodeToAddTo == null || !nodeToAddTo.IsPartOfComponentsFolderStructure()) { nodeToAddTo = RootComponentsTreeNode; } string path = nodeToAddTo.GetFullFilePath(); string relativeToComponents = FileManager.MakeRelative(path, FileLocations.Self.ComponentsFolder); ComponentSave componentSave = ProjectCommands.Self.AddComponent(relativeToComponents + name); GumCommands.Self.GuiCommands.RefreshElementTreeView(); SelectedState.Self.SelectedComponent = componentSave; GumCommands.Self.FileCommands.TryAutoSaveProject(); GumCommands.Self.FileCommands.TryAutoSaveElement(componentSave); } } } }
public void createOverlay(ComponentSave myComp, List <GameObject> tiles, List <GameObject> floorTiles) { GameObject prefab = Instantiate(compOverlayPrefab, overlayFather.transform); prefab.transform.position = placer.transform.position; ComponentOverlay overlay = prefab.transform.GetChild(0).GetComponent <ComponentOverlay>(); overlay.setParams(myComp, tiles, floorTiles); overlays.Add(prefab); }
public bool IsComponentNameValid(string componentName, ComponentSave component, out string whyNotValid) { IsNameValidCommon(componentName, out whyNotValid); if (string.IsNullOrEmpty(whyNotValid)) { IsNameAnExistingElement(componentName, component, out whyNotValid); } return(string.IsNullOrEmpty(whyNotValid)); }
internal void RemoveComponent(ComponentSave asComponentSave) { GumProjectSave gps = ProjectManager.Self.GumProjectSave; string name = asComponentSave.Name; List <ElementReference> references = gps.ComponentReferences; RemoveElementReferencesFromList(name, references); gps.Components.Remove(asComponentSave); }
private EntitySave ToGlueEntitySave(ComponentSave component, Dictionary <string, CopiedFileReference> copiedFiles) { EntitySave toReturn = new EntitySave(); toReturn.Name = "Entities\\" + component.Name; // Make RFS's first so we can rename NOS's if necessary AddReferencedFilesToElement(component, toReturn, copiedFiles); mInstanceToNos.AddNamedObjectSavesToGlueElement(component, toReturn, copiedFiles); return(toReturn); }
private void CreateButtonContainerComponent() { ButtonContainer = new ComponentSave(); ButtonContainer.Name = "ButtonContainer"; ButtonContainer.BaseType = "Container"; ButtonContainer.Initialize(StandardElementsManager.Self.GetDefaultStateFor("Container")); InstanceSave buttonInContainer = new InstanceSave(); buttonInContainer.Name = "ButtonInstance"; buttonInContainer.BaseType = "Button"; ButtonContainer.Instances.Add(buttonInContainer); }
internal void AddComponentToGumProject(ComponentSave gumComponent) { AppState.Self.GumProjectSave.Components.Add(gumComponent); var elementReference = new ElementReference { ElementType = ElementType.Component, Name = gumComponent.Name }; AppState.Self.GumProjectSave.ComponentReferences.Add(elementReference); AppState.Self.GumProjectSave.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name)); FlatRedBall.Glue.Plugins.PluginManager.ReceiveOutput("Added Gum component " + gumComponent.Name); }
private static void createFile(ComponentSave save) { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } Debug.Log("Comp: Creating new file..."); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(savePath + save.name + postfix); bf.Serialize(file, save); file.Close(); }
public static bool removeSave(ComponentSave save) { if (savedComponents.Contains(save)) { Debug.Log("Removing comp save..."); savedComponents.Remove(save); if (File.Exists(savePath + save.name + postfix)) { File.Delete(savePath + save.name + postfix); return(true); } return(true); } return(false); }
public bool IsComponentNameValid(string componentName, string folderName, ComponentSave component, out string whyNotValid) { IsNameValidCommon(componentName, out whyNotValid); //if (string.IsNullOrEmpty(whyNotValid)) //{ // IsNameValidVariable(componentName, out whyNotValid); //} if (string.IsNullOrEmpty(whyNotValid)) { IsNameAnExistingElement(componentName, folderName, component, out whyNotValid); } return(string.IsNullOrEmpty(whyNotValid)); }
public void setParams(ComponentSave myComp, List <GameObject> tiles, List <GameObject> floorTiles) { this.myComp = myComp; this.tiles = tiles; //TileHub hub = GameObject.Find("Manager").GetComponent<TileHub>(); //float x = //floorTiles[0].transform.position.x - (myComp.length / 2.0f); //float y = //floorTiles[0].transform.position.y + (myComp.height / 2.0f); //print("x/y: " + x + "/" + y); List <GameObject> overlayTiles = new List <GameObject>(); //Create overlaytiles foreach (GameObject go in floorTiles) { GameObject prefab = Instantiate(overlayTilePrefab, pop.transform); prefab.transform.position = go.transform.position + new Vector3(0, 0, -2); prefab.GetComponent <OverlayTile>().myTile = go; prefab.GetComponent <OverlayTile>().pop = pop; prefab.GetComponent <OverlayTile>().myOverlay = this; overlayTiles.Add(prefab); } float x = (overlayTiles[0].transform.localPosition.x + overlayTiles[myComp.length - 1].transform.localPosition.x) / 2; //floorTiles[0].transform.position.x - (myComp.length / 2.0f); //float x = overlayTiles[floorTiles.Count - 1].transform.position.x + dx; float y = (overlayTiles[floorTiles.Count - myComp.length].transform.localPosition.y - overlayTiles[0].transform.localPosition.y) / 2; //floorTiles[0].transform.position.y + (myComp.height / 2.0f); //float y = overlayTiles[floorTiles.Count - myComp.length].transform.position.y + dy; //print(x +"/"+ y); transform.localPosition = new Vector3(x, y, -2); transform.localScale = new Vector3(myComp.length * 1.6f, myComp.height * 1.6f, 1); foreach (GameObject go in tiles) { if (go != null) { go.GetComponent <TileController>().myCompOverlay = transform.parent.gameObject; } } nameMesh.text = myComp.name; nameMesh.transform.localPosition = new Vector3(x, y, -2); }
public static void SaveComp(ComponentSave save) { //Debug.Log("Save: " + save.gameName); if (savedComponents.Contains(save)) { Debug.Log("Overwriting..."); int index = savedComponents.IndexOf(save); savedComponents.RemoveAt(index); savedComponents.Insert(index, save); } else { Debug.Log("Adding new comp to savedComponents!"); savedComponents.Add(save); } createFile(save); }
public void loadComp(ComponentSave comp, Vector3 pos) { if (placer == null) { GameObject prefab = Instantiate(componentPlacerPrefab, Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, 10)), Quaternion.identity); prefab.GetComponent <ComponentPlacerController>().myComp = comp; prefab.GetComponent <ComponentPlacerController>().GC = GC; prefab.GetComponent <ComponentPlacerController>().CUI = this; prefab.GetComponent <ComponentPlacerController>().UC = UC; placer = prefab; } else { placer.GetComponent <ComponentPlacerController>().myComp = comp; placer.GetComponent <ComponentPlacerController>().setBackdrop(); } GC.audioMixer.playButtonSFX(); }
public ComponentSave AddComponent(string componentName, string folder) { string whyNotValid; if (!NameVerifier.Self.IsComponentNameValid(componentName, folder, null, out whyNotValid)) { MessageBox.Show(whyNotValid); return(null); } else { ComponentSave componentSave = new ComponentSave(); PrepareNewComponentSave(componentSave, folder + componentName); AddComponent(componentSave); return(componentSave); } }
public void AddComponent(ComponentSave componentSave) { var gumProject = ProjectState.Self.GumProjectSave; gumProject.ComponentReferences.Add(new ElementReference { Name = componentSave.Name, ElementType = ElementType.Component }); gumProject.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name)); gumProject.Components.Add(componentSave); GumCommands.Self.GuiCommands.RefreshElementTreeView(); SelectedState.Self.SelectedComponent = componentSave; GumCommands.Self.FileCommands.TryAutoSaveProject(); GumCommands.Self.FileCommands.TryAutoSaveElement(componentSave); Plugins.PluginManager.Self.ElementAdd(componentSave); }
private void CreateButtonComponent() { Button = new ComponentSave(); Button.Name = "VariableTestButton"; Button.BaseType = "Sprite"; Button.Initialize(StandardElementsManager.Self.GetDefaultStateFor("Sprite")); InstanceSave instance = new InstanceSave(); instance.Name = "TextInstance"; instance.BaseType = "Text"; Button.Instances.Add(instance); // Set the varlue for the Text's Text property Button.DefaultState.SetValue(instance.Name + "." + "Text", "Hello"); VariableSave variableSave = Button.DefaultState.GetVariableSave(instance.Name + "." + "Text"); variableSave.ExposedAsName = "ButtonText"; }
private void UpdateViewModelTo(ComponentSave asComponent) { viewModel.AddedBehaviors.Clear(); foreach (var behavior in asComponent.Behaviors) { viewModel.AddedBehaviors.Add(behavior.BehaviorName); } viewModel.AllBehaviors.Clear(); foreach (var behavior in ProjectManager.Self.GumProjectSave.Behaviors) { var newItem = new CheckListBehaviorItem(); newItem.Name = behavior.Name; newItem.IsChecked = viewModel.AddedBehaviors.Contains(behavior.Name); viewModel.AllBehaviors.Add(newItem); } }
private void RemoveElement(ElementSave elementToRemove) { ScreenSave asScreenSave = elementToRemove as ScreenSave; ComponentSave asComponentSave = elementToRemove as ComponentSave; if (asScreenSave != null) { ProjectCommands.Self.RemoveScreen(asScreenSave); } else if (asComponentSave != null) { ProjectCommands.Self.RemoveComponent(asComponentSave); } GumCommands.Self.GuiCommands.RefreshElementTreeView(); StateTreeViewManager.Self.RefreshUI(null); PropertyGridManager.Self.RefreshUI(); Wireframe.WireframeObjectManager.Self.RefreshAll(true); GumCommands.Self.FileCommands.TryAutoSaveProject(); }
private static string GetErrorMessage(ElementSave draggedAsElementSave, ElementSave target, string errorMessage) { if (target == null) { errorMessage = "No Screen or Component selected"; } if (errorMessage == null && target is StandardElementSave) { // do nothing, it's annoying: errorMessage = "Standard types can't contain objects"; } if (errorMessage == null && draggedAsElementSave is ScreenSave) { errorMessage = "Screens can't be dropped into other Screens or Components"; } if (errorMessage == null) { if (draggedAsElementSave is ComponentSave && target is ComponentSave) { ComponentSave targetAsComponentSave = target as ComponentSave; if (!targetAsComponentSave.CanContainInstanceOfType(draggedAsElementSave.Name)) { errorMessage = "Can't add instance of " + draggedAsElementSave.Name + " in " + targetAsComponentSave.Name; } } } if (errorMessage == null && target.IsSourceFileMissing) { errorMessage = "The source file for " + target.Name + " is missing, so it cannot be edited"; } return(errorMessage); }