Example #1
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);
        }
        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;


                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;


                // November 9, 2020 - Vic asks - why do we set properties here, and ONLY exposed variables? That's weird...
                // It also requires using instanceSave.ParentContainer, and maybe is duplicate setting values which hurts performance
                // andn adds complexity. Not sure what to do here..., but going to try commenting it out to see if it makes a difference
                //var instanceContainerDefaultState = instanceSave.ParentContainer.DefaultState;

                //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);
        }
        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);
        }
Example #4
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);
        }