Exemple #1
0
        // Replaced with ApplyDefaultState
        //static void SetVariablesRecursively(this GraphicalUiElement graphicalElement, ElementSave elementSave)
        //{
        //    graphicalElement.SetVariablesRecursively(elementSave, elementSave.DefaultState);
        //}

        public static void SetVariablesTopLevel(this GraphicalUiElement graphicalElement, ElementSave elementSave, Gum.DataTypes.Variables.StateSave stateSave)
        {
            foreach (var variable in stateSave.Variables.Where(item => item.SetsValue && item.Value != null))
            {
                graphicalElement.SetProperty(variable.Name, variable.Value);
            }
        }
Exemple #2
0
        public static GraphicalUiElement ToGraphicalUiElement(this InstanceSave instanceSave, SystemManagers systemManagers)
        {
            ElementSave instanceElement = ObjectFinder.Self.GetElementSave(instanceSave.BaseType);

            GraphicalUiElement toReturn = null;

            if (instanceElement != null)
            {
                toReturn = ElementSaveExtensions.CreateGueForElement(instanceElement);

                GumRuntime.ElementSaveExtensions.SetGraphicalUiElement(instanceElement, toReturn, systemManagers);

                toReturn.Name = instanceSave.Name;
                toReturn.Tag  = instanceSave;

                var state = instanceSave.ParentContainer.DefaultState;



                foreach (var variable in state.Variables.Where(item => item.SourceObject == instanceSave.Name))
                {
                    string propertyOnInstance = variable.Name.Substring(variable.Name.LastIndexOf('.') + 1);

                    if (toReturn.IsExposedVariable(propertyOnInstance))
                    {
                        toReturn.SetProperty(propertyOnInstance, variable.Value);
                    }
                }
            }

            return(toReturn);
        }
Exemple #3
0
        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 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)
            {
                string genericType = null;

                var instanceContainerDefaultState = instanceSave.ParentContainer.DefaultState;

                if (instanceElement.Name == "Container" && instanceElement is StandardElementSave)
                {
                    genericType = instanceSave.ParentContainer.DefaultState.GetValueOrDefault <string>(instanceSave.Name + "." + "Contained Type");
                }

                toReturn = ElementSaveExtensions.CreateGueForElement(instanceElement, true, genericType);

                // 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;



                foreach (var variable in instanceContainerDefaultState.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);
        }
Exemple #5
0
        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);
                }
            }

            foreach (var variable in stateSave.Variables.Where(item => item.SetsValue && item.Value != null))
            {
                graphicalElement.SetProperty(variable.Name, variable.Value);
            }
        }
Exemple #6
0
        public static GraphicalUiElement ToGraphicalUiElement(this InstanceSave instanceSave, SystemManagers systemManagers)
        {
            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);
        }
Exemple #7
0
        /// <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();
                    }
                }
            }
        }