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; 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); }
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); }