static void CreateChildrenRecursively(this GraphicalUiElement graphicalElement, ElementSave elementSave, SystemManagers systemManagers) { bool isScreen = elementSave is ScreenSave; foreach (var instance in elementSave.Instances) { var childGue = instance.ToGraphicalUiElement(systemManagers); if (childGue != null) { if (!isScreen) { childGue.Parent = graphicalElement; } childGue.ParentGue = graphicalElement; } } }
public static GraphicalUiElement ToGraphicalUiElement(this InstanceSave instanceSave, SystemManagers systemManagers) { #if DEBUG if (ObjectFinder.Self.GumProjectSave == null) { throw new InvalidOperationException("You need to set the ObjectFinder's GumProjectSave first so it can track references"); } #endif ElementSave instanceElement = ObjectFinder.Self.GetElementSave(instanceSave.BaseType); GraphicalUiElement toReturn = null; if (instanceElement != null) { toReturn = ElementSaveExtensions.CreateGueForElement(instanceElement, true); // If we get here but there's no contained graphical object then that means we don't // have a strongly-typed system (like when a game is running in FRB). Therefore, we'll // just fall back to the regular creation of graphical objects, like is done in the Gum tool: if (toReturn.RenderableComponent == null) { instanceElement.SetGraphicalUiElement(toReturn, systemManagers); } toReturn.Name = instanceSave.Name; toReturn.Tag = instanceSave; var state = instanceSave.ParentContainer.DefaultState; foreach (var variable in state.Variables.Where(item => item.SetsValue && item.SourceObject == instanceSave.Name)) { string propertyOnInstance = variable.Name.Substring(variable.Name.LastIndexOf('.') + 1); if (toReturn.IsExposedVariable(propertyOnInstance)) { toReturn.SetProperty(propertyOnInstance, variable.Value); } } } return(toReturn); }
public static void SetStatesAndCategoriesRecursively(this GraphicalUiElement graphicalElement, ElementSave elementSave) { if (!string.IsNullOrEmpty(elementSave.BaseType)) { var baseElementSave = Gum.Managers.ObjectFinder.Self.GetElementSave(elementSave.BaseType); if (baseElementSave != null) { graphicalElement.SetStatesAndCategoriesRecursively(baseElementSave); } } // We need to set categories and states before calling SetGraphicalUiElement so that the states can be used foreach (var category in elementSave.Categories) { graphicalElement.AddCategory(category); } graphicalElement.AddStates(elementSave.States); }
public static GraphicalUiElement CreateGueForElement(ElementSave elementSave) { GraphicalUiElement toReturn = null; if (mElementToGueTypes.ContainsKey(elementSave.Name)) { var type = mElementToGueTypes[elementSave.Name]; var constructor = type.GetConstructor(new Type[] { typeof(bool) }); bool fullInstantiation = false; toReturn = constructor.Invoke(new object[] { fullInstantiation }) as GraphicalUiElement; } else { toReturn = new GraphicalUiElement(); } toReturn.ElementSave = elementSave; return(toReturn); }
public static void SetVariablesRecursively(this GraphicalUiElement graphicalElement, ElementSave elementSave, Gum.DataTypes.Variables.StateSave stateSave) { if (!string.IsNullOrEmpty(elementSave.BaseType)) { var baseElementSave = Gum.Managers.ObjectFinder.Self.GetElementSave(elementSave.BaseType); if (baseElementSave != null) { graphicalElement.SetVariablesRecursively(baseElementSave, baseElementSave.DefaultState); } } var variablesToSet = stateSave.Variables .Where(item => item.SetsValue && item.Value != null) // States should be applied first, then values may override states (order by sorts false first): .OrderBy(item => !item.IsState(elementSave)) .ToList(); foreach (var variable in variablesToSet) { // See below for explanation on why we don't set Parent here if (variable.GetRootName() != "Parent") { graphicalElement.SetProperty(variable.Name, variable.Value); } } // Now set all parents // The reason for this is // because parents need to // be assigned in the order // of the instances in the .glux. // That way they are drawn in the same // order as they are defined. variablesToSet = variablesToSet.Where(item => item.GetRootName() == "Parent") .OrderBy(item => elementSave.Instances.FindIndex(instance => instance.Name == item.SourceObject)) .ToList(); foreach (var variable in variablesToSet) { graphicalElement.SetProperty(variable.Name, variable.Value); } }
public PositionedObjectGueWrapper(PositionedObject frbObject, GraphicalUiElement gumObject) : base() { var renderable = new InvisibleRenderable(); renderable.Visible = true; GumParent = new GraphicalUiElement(); GumParent.SetContainedObject(renderable); GumParent.XUnits = Gum.Converters.GeneralUnitType.PixelsFromSmall; GumParent.YUnits = Gum.Converters.GeneralUnitType.PixelsFromSmall; GumParent.XOrigin = HorizontalAlignment.Center; GumParent.YOrigin = VerticalAlignment.Center; this.FrbObject = frbObject; this.GumObject = gumObject; gumObject.Parent = GumParent; }
static void AddExposedVariablesRecursively(this GraphicalUiElement graphicalElement, ElementSave elementSave) { if (!string.IsNullOrEmpty(elementSave.BaseType)) { var baseElementSave = Gum.Managers.ObjectFinder.Self.GetElementSave(elementSave.BaseType); if (baseElementSave != null) { graphicalElement.AddExposedVariablesRecursively(baseElementSave); } } if (elementSave != null) { foreach (var variable in elementSave.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName))) { graphicalElement.AddExposedVariable(variable.ExposedAsName, variable.Name); } } }
protected override void ReactToVisualChanged() { textComponent = base.Visual.GetGraphicalUiElementByName("TextInstance"); caretComponent = base.Visual.GetGraphicalUiElementByName("CaretInstance"); // optional: selectionInstance = base.Visual.GetGraphicalUiElementByName("SelectionInstance"); coreTextObject = textComponent.RenderableComponent as RenderingLibrary.Graphics.Text; #if DEBUG if (textComponent == null) { throw new Exception("Gum object must have an object called \"Text\""); } if (coreTextObject == null) { throw new Exception("The Text instance must be of type Text"); } if (caretComponent == null) { throw new Exception("Gum object must have an object called \"Caret\""); } #endif Visual.Click += this.HandleClick; Visual.Push += this.HandlePush; Visual.RollOn += this.HandleRollOn; Visual.RollOver += this.HandleRollOver; Visual.DragOver += this.HandleDrag; Visual.RollOff += this.HandleRollOff; Visual.SizeChanged += HandleVisualSizeChanged; this.textComponent.XUnits = global::Gum.Converters.GeneralUnitType.PixelsFromSmall; base.ReactToVisualChanged(); OffsetTextToKeepCaretInView(); HasFocus = false; }
public static void CreateGraphicalComponent(this GraphicalUiElement graphicalElement, ElementSave elementSave, SystemManagers systemManagers) { IRenderable containedObject = null; bool handled = InstanceSaveExtensionMethods.TryHandleAsBaseType(elementSave.Name, systemManagers, out containedObject); if (handled) { graphicalElement.SetContainedObject(containedObject); } else { if (elementSave != null && elementSave is ComponentSave) { var baseElement = Gum.Managers.ObjectFinder.Self.GetElementSave(elementSave.BaseType); if (baseElement != null) { graphicalElement.CreateGraphicalComponent(baseElement, systemManagers); } } } }
public static GraphicalUiElement CreateGueForElement(ElementSave elementSave, bool fullInstantiation = false) { GraphicalUiElement toReturn = null; if (mElementToGueTypes.ContainsKey(elementSave.Name)) { // This code allows sytems (like games that use Gum) to assign types // to their GraphicalUiElements so that users of the code can work with // strongly-typed Gum objects. var type = mElementToGueTypes[elementSave.Name]; var constructor = type.GetConstructor(new Type[] { typeof(bool), typeof(bool) }); toReturn = constructor.Invoke(new object[] { fullInstantiation, true }) as GraphicalUiElement; } else { toReturn = new GraphicalUiElement(); } toReturn.ElementSave = elementSave; return(toReturn); }
private void CreateRestartButton(ContainerRuntime stackPanel, Texture2D iconSpriteSheet) { var restartButton = new Button(); restartButton.Visual.Parent = stackPanel; restartButton.Visual.WidthUnits = global::Gum.DataTypes.DimensionUnitType.RelativeToChildren; restartButton.Visual.Width = 10; restartButton.Visual.Height = 38; restartButton.X = borderWidth; restartButton.Y = borderWidth; restartButton.Text = ""; restartButton.Push += (not, used) => FlatRedBall.Screens.ScreenManager.CurrentScreen.RestartScreen(reloadContent: true); var internalSprite = new global::RenderingLibrary.Graphics.Sprite(iconSpriteSheet); var restartSprite = new GraphicalUiElement(internalSprite, null); restartSprite.Parent = restartButton.Visual; InitializeIconSprite(restartSprite); restartSprite.TextureLeft = 0; restartSprite.TextureTop = 0; restartSprite.TextureWidth = 30; restartSprite.TextureHeight = 30; }
protected override void ReactToVisualChanged() { // optional var mainListBoxItemVisual = Visual.GetGraphicalUiElementByName("ListBoxItemInstance"); mainListBoxItem = mainListBoxItemVisual?.FormsControlAsObject as ListBoxItem; if (mainListBoxItem != null) { mainListBoxItem.Selected += HandleMainItemSelected; } // optional var expandCollapseButtonVisual = Visual.GetGraphicalUiElementByName("ToggleButtonInstance"); expandCollapseButton = expandCollapseButtonVisual?.FormsControlAsObject as ToggleButton; if (expandCollapseButton != null) { expandCollapseButton.Checked += HandleExpandCollapseButtonCheckChange; expandCollapseButton.Unchecked += HandleExpandCollapseButtonCheckChange; // will start out invisible, will be made visible when items are added expandCollapseButton.IsVisible = false; } // required: innerPanel = Visual.GetGraphicalUiElementByName("InnerPanelInstance"); UpdateInnerPanelCollapsedState(); #if DEBUG if (innerPanel == null) { throw new Exception("Missing InnerPanelInstance"); } #endif treeViewLogic.ContainerTreeViewItemGumType = Visual.GetType(); treeViewLogic.AssignControls(innerPanel); }
static void SetVariablesRecursively(this GraphicalUiElement graphicalElement, ElementSave elementSave) { graphicalElement.SetVariablesRecursively(elementSave, elementSave.DefaultState); }
public void AssignControls(GraphicalUiElement innerPanel) { this.InnerPanel = innerPanel; }
public RadioButton(GraphicalUiElement visual, string groupName = "") : base(visual) { GroupName = groupName; IsChecked = false; }
public ItemsControl(GraphicalUiElement visual) : base(visual) { Items.CollectionChanged += HandleCollectionChanged; }
public TreeViewItem(GraphicalUiElement visual) : base(visual) { InitializeTreeViewLogic(); }
public ComboBox(GraphicalUiElement visual) : base(visual) { }
public void LoadFromFile(string fileName) { var section = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("LoadFromFile " + fileName); { var sectionA = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("GetElement"); 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; string oldFrbDir = FlatRedBall.IO.FileManager.RelativeDirectory; ToolsUtilities.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName); ElementSave elementSave = null; string extension = ToolsUtilities.FileManager.GetExtension(fileName); string strippedName = FlatRedBall.IO.FileManager.RemoveExtension(FlatRedBall.IO.FileManager.RemovePath(fileName)); if (extension == GumProjectSave.ComponentExtension) { elementSave = ObjectFinder.Self.GumProjectSave.Components.FirstOrDefault(item => item.Name.Equals(strippedName, StringComparison.OrdinalIgnoreCase)); } else if (extension == GumProjectSave.ScreenExtension) { elementSave = ObjectFinder.Self.GumProjectSave.Screens.FirstOrDefault(item => item.Name.Equals(strippedName, StringComparison.OrdinalIgnoreCase)); } else if (extension == GumProjectSave.StandardExtension) { elementSave = ObjectFinder.Self.GumProjectSave.StandardElements.FirstOrDefault(item => item.Name.Equals(strippedName, StringComparison.OrdinalIgnoreCase)); } // Set this *after* the deserialization happens. The fileName is relative to FRB's relative directory but // contained file references won't be. FlatRedBall.IO.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName); sectionA.EndTimeAndContext(); var sectionB = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("Set ParentContainer"); // We used to only init the uncategorized states // but every state should be initialized //foreach (var state in elementSave.States) foreach (var state in elementSave.AllStates) { state.Initialize(); state.ParentContainer = elementSave; } foreach (var instance in elementSave.Instances) { instance.ParentContainer = elementSave; } sectionB.EndTimeAndContext(); var sectionC = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("ToGraphicalUiElement"); element = elementSave.ToGraphicalUiElement(mManagers, false); sectionC.EndTimeAndContext(); var sectionD = FlatRedBall.Performance.Measurement.Section.GetAndStartContextAndTime("Wrap up"); element.ExplicitIVisibleParent = this; //Set the relative directory back once we are done ToolsUtilities.FileManager.RelativeDirectory = oldDir; FlatRedBall.IO.FileManager.RelativeDirectory = oldFrbDir; sectionD.EndTimeAndContext(); } section.EndTimeAndContext(); }
public InventoryListBoxItem(GraphicalUiElement visual) : base(visual) { }
public ScrollBar(GraphicalUiElement visual) : base(visual) { }
public StoreListBoxItem(GraphicalUiElement visual) : base(visual) { Selected += HandleSelected; }
/// <summary> /// Reacts to a variable having been set. /// </summary> /// <param name="unqualifiedMember">The variable name without the prefix instance name.</param> /// <param name="oldValue"></param> /// <param name="parentElement"></param> /// <param name="instance"></param> /// <param name="refresh"></param> public void ReactToPropertyValueChanged(string unqualifiedMember, object oldValue, ElementSave parentElement, InstanceSave instance, bool refresh) { if (parentElement != null) { ReactToChangedMember(unqualifiedMember, oldValue, parentElement, instance); string qualifiedName = unqualifiedMember; if (instance != null) { qualifiedName = $"{instance.Name}.{unqualifiedMember}"; } VariableInCategoryPropagationLogic.Self.PropagateVariablesInCategory(qualifiedName); // Need to record undo before refreshing and reselecting the UI Undo.UndoManager.Self.RecordUndo(); if (refresh) { // These properties may require some changes to the grid, so we refresh the tree view // and entire grid. // There's lots of work that can/should be done here: // 1. We should have the plugins that handle excluding variables also // report whether a variable requires refreshing // 2. We could only refresh the grid for some variables like UseCustomFont // 3. We could have only certain variable refresh themselves instead of the entire // grid. var needsToRefreshEntireElement = unqualifiedMember == "Parent" || unqualifiedMember == "Name" || unqualifiedMember == "UseCustomFont" || unqualifiedMember == "Texture Address" || unqualifiedMember == "Base Type" ; if (needsToRefreshEntireElement) { GumCommands.Self.GuiCommands.RefreshElementTreeView(parentElement); GumCommands.Self.GuiCommands.RefreshPropertyGrid(force: true); } } if (refresh) { var value = SelectedState.Self.SelectedStateSave.GetValue(qualifiedName); var areSame = value == null && oldValue == null; if (!areSame && value != null) { areSame = value.Equals(oldValue); } // If the values are the same they may have been set to be the same by a plugin that // didn't allow the assignment, so don't go through the work of saving and refreshing if (!areSame) { GumCommands.Self.FileCommands.TryAutoSaveCurrentElement(); // Inefficient but let's do this for now - we can make it more efficient later // November 19, 2019 // While this is inefficient // at runtime, it is *really* // inefficient for debugging. If // a set value fails, we have to trace // the entire variable assignment and that // can take forever. Therefore, we're going to // migrate towards setting the individual values // here. This can expand over time to just exclude // the RefreshAll call completely....but I don't know // if that will cause problems now, so instead I'm going // to do it one by one: var handledByDirectSet = false; if (PropertiesSupportingIncrementalChange.Contains(unqualifiedMember) && (instance != null || SelectedState.Self.SelectedComponent != null)) { // this assumes that the object having its variable set is the selected instance. If we're setting // an exposed variable, this is not the case - the object having its variable set is actually the instance. //GraphicalUiElement gue = WireframeObjectManager.Self.GetSelectedRepresentation(); GraphicalUiElement gue = null; if (instance != null) { gue = WireframeObjectManager.Self.GetRepresentation(instance); } else { gue = WireframeObjectManager.Self.GetSelectedRepresentation(); } if (gue != null) { gue.SetProperty(unqualifiedMember, value); handledByDirectSet = true; } } if (!handledByDirectSet) { WireframeObjectManager.Self.RefreshAll(true, forceReloadTextures: false); } SelectionManager.Self.Refresh(); } } } }
public TextBox(GraphicalUiElement visual) : base(visual) { }
public RangeBase(GraphicalUiElement visual) : base(visual) { }
public PasswordBox(GraphicalUiElement visual) : base(visual) { }
public void Add(GraphicalUiElement graphicalUiElement) { GraphicalUiElements.Add(graphicalUiElement); }
public void Remove(GraphicalUiElement graphicalUiElement) { GraphicalUiElements.Remove(graphicalUiElement); }
public UserControl(GraphicalUiElement visual) : base(visual) { }
public static float GetTop(this GraphicalUiElement graphicalUiElement) { return(((IRenderableIpso)graphicalUiElement).GetAbsoluteY()); }