public static object GetValueFromThisOrBase(this InstanceSave instance, List <ElementWithState> elementStack, string variable, bool forceDefault = false) { ElementWithState parentContainer = elementStack.Last(); VariableSave variableSave = instance.GetVariableFromThisOrBase(parentContainer, variable, forceDefault, true); if (variableSave != null) { return(variableSave.Value); } else { VariableListSave variableListSave = parentContainer.Element.DefaultState.GetVariableListSave(instance.Name + "." + variable); if (variableListSave == null) { ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType); if (instanceBase != null) { variableListSave = instanceBase.DefaultState.GetVariableListSave(variable); } } if (variableListSave != null) { return(variableListSave.ValueAsIList); } } // If we get ehre that means there isn't any VariableSave or VariableListSave return(null); }
private void ApplyVertexValues() { var linePolygon = SelectedLinePolygon; if (linePolygon != null) { List <Vector2> vectors = new List <Vector2>(linePolygon.PointCount); for (int i = 0; i < linePolygon.PointCount; i++) { vectors.Add(linePolygon.PointAt(i)); } var variableName = "Points"; if (SelectedState.Self.SelectedInstance != null) { variableName = SelectedState.Self.SelectedInstance.Name + "." + variableName; } var pointsVariableList = SelectedState.Self.SelectedStateSave.VariableLists.FirstOrDefault(item => item.Name == variableName); // This might be null if the points aren't set in this state, but are inherited from a base // state or object if (pointsVariableList == null) { pointsVariableList = new VariableListSave <Vector2>(); pointsVariableList.Name = variableName; SelectedState.Self.SelectedStateSave.VariableLists.Add(pointsVariableList); } pointsVariableList.ValueAsIList = vectors; } }
private static bool GetIfShouldInclude(VariableListSave variableList, ElementSave container, InstanceSave currentInstance, StandardElementSave rootElementSave) { bool toReturn = (string.IsNullOrEmpty(variableList.SourceObject)); if (toReturn) { toReturn = GetShouldIncludeBasedOnBaseType(variableList, container, rootElementSave); } return(toReturn); }
public static bool GetShouldIncludeBasedOnBaseType(VariableListSave variableList, ElementSave container, StandardElementSave rootElementSave) { bool shouldInclude = false; if (string.IsNullOrEmpty(variableList.SourceObject)) { if (container is ScreenSave) { // If it's a Screen, then the answer is "yes" because // Screens don't have a base type that they can switch, // so any variable that's part of the Screen is always part // of the Screen. shouldInclude = true; } else { if (container is ComponentSave) { // See if it's defined in the standards list var foundInstance = StandardElementsManager.Self.GetDefaultStateFor("Component").VariableLists.FirstOrDefault( item => item.Name == variableList.Name); shouldInclude = foundInstance != null; } // If the defaultVariable's // source object is null then // that means that the variable // is being set on "this". However, // variables that are set on "this" may // not actually be valid for the type, but // they may still exist because the object type // was switched. Therefore, we want to make sure // that the variable is valid given the type of object // that "this" currently is by checking the default state // on the rootElementSave if (!shouldInclude && rootElementSave != null) { shouldInclude = rootElementSave.DefaultState.GetVariableListRecursive(variableList.Name) != null; } } } else { shouldInclude = SelectedState.Self.SelectedInstance != null // VariableLists cannot be exposed (currently) //|| !string.IsNullOrEmpty(variableList.ExposedAsName); ; } return(shouldInclude); }
private static bool GetIfShouldInclude(VariableListSave variableList, ElementSave container, InstanceSave currentInstance) { bool toReturn = (string.IsNullOrEmpty(variableList.SourceObject)); if (toReturn) { StandardElementSave rootElementSave = null; if (currentInstance != null) { rootElementSave = ObjectFinder.Self.GetRootStandardElementSave(currentInstance); } else if ((container is ScreenSave) == false) { rootElementSave = ObjectFinder.Self.GetRootStandardElementSave(container); } toReturn = VariableSaveLogic.GetShouldIncludeBasedOnBaseType(variableList, container, rootElementSave); } return(toReturn); }
public static VariableListSave GetVariableListFromThisOrBase(this InstanceSave instance, ElementSave parentContainer, string variable) { ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType); VariableListSave variableListSave = parentContainer.DefaultState.GetVariableListSave(instance.Name + "." + variable); if (variableListSave == null) { variableListSave = instanceBase.DefaultState.GetVariableListSave(variable); } if (variableListSave != null && variableListSave.ValueAsIList == null) { // This can happen if there is a tunneled variable that is null VariableListSave possibleVariable = instanceBase.DefaultState.GetVariableListSave(variable); if (possibleVariable != null && possibleVariable.ValueAsIList != null) { variableListSave = possibleVariable; } } return(variableListSave); }
private static Attribute[] GetAttributesForVariable(VariableListSave variableList) { mListOfAttributes.Clear(); EditorAttribute editorAttribute = new EditorAttribute( //"System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(VariableListConverter), typeof(UITypeEditor)); mListOfAttributes.Add(editorAttribute); if (!string.IsNullOrEmpty(variableList.Category)) { mListOfAttributes.Add(new CategoryAttribute(variableList.Category)); } if (variableList.IsHiddenInPropertyGrid) { mListOfAttributes.Add(new BrowsableAttribute(false)); } return(mListOfAttributes.ToArray()); }
public void RefreshDefaults() { mDefaults = new Dictionary <string, StateSave>(); // Eventually this would get read from somewhere like an XML file // or a CSV file, but for // now we'll just use hard values. { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Text // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave, includeBaseline: true); AddDimensionsVariables(stateSave, 100, 50, DimensionVariableAction.ExcludeFileOptions); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "Hello", Name = "Text", Category = "Text" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "HorizontalAlignment", Value = HorizontalAlignment.Left, Name = "HorizontalAlignment", Category = "Text" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "VerticalAlignment", Value = VerticalAlignment.Top, Name = "VerticalAlignment", Category = "Text" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int?", Value = null, Name = "MaxLettersToShow", Category = "Text" }); // font: stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "UseCustomFont", Category = "Font" }); var fontVariable = new VariableSave { SetsValue = true, Type = "string", Value = "Arial", Name = "Font", IsFont = true, Category = "Font" }; fontVariable.PropertiesToSetOnDisplayer["IsEditable"] = true; stateSave.Variables.Add(fontVariable); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 18, Name = "FontSize", Category = "Font" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "OutlineThickness", Category = "Font" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "IsItalic", Category = "Font" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "UseFontSmoothing", Category = "Font" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "", Name = "CustomFontFile", Category = "Font", IsFile = true }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 1.0f, Name = "Font Scale", Category = "Font" }); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); AddEventVariables(stateSave); AddStateVariable(stateSave); AddColorVariables(stateSave, includeAlpha: true); #if GUM PluginManager.Self.ModifyDefaultStandardState("Text", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Text", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Sprite // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave); AddDimensionsVariables(stateSave, 100, 100, DimensionVariableAction.DefaultToPercentageOfFile); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "", Name = "SourceFile", IsFile = true }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Animation", Name = "Animate" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = null, Category = "Animation", Name = "CurrentChainName" }); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Flip and Rotation", Name = "FlipHorizontal" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Flip and Rotation", Name = "FlipVertical" }); //stateSave.Variables.Add(new VariableSave { Type = "bool", Value = false, Name = "Custom Texture Coordinates", Category="Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "TextureAddress", Value = Gum.Managers.TextureAddress.EntireTexture, Name = "Texture Address", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Left", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Top", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Width", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Height", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 0.0f, Name = "Texture Width Scale", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 0.0f, Name = "Texture Height Scale", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "Wrap", Category = "Source" }); AddColorVariables(stateSave); AddEventVariables(stateSave); AddStateVariable(stateSave); List <string> list = new List <string>(); stateSave.VariableLists.Add(new VariableListSave <string> { Type = "string", Value = list, Category = "Animation", Name = "AnimationFrames" }); #if GUM PluginManager.Self.ModifyDefaultStandardState("Sprite", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Sprite", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Container // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave); AddDimensionsVariables(stateSave, 150, 150, DimensionVariableAction.ExcludeFileOptions); stateSave.Variables.Add(new VariableSave { SetsValue = true, Category = "Children", Type = "string", Value = null, Name = "Contained Type" #if GUM , CustomTypeConverter = new AvailableContainedTypeConverter() #endif }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Category = "Children", Type = "ChildrenLayout", Value = ChildrenLayout.Regular, Name = "Children Layout" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Category = "Children", Type = "bool", Value = false, Name = "Wraps Children" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Category = "Children", Type = "bool", Value = false, Name = "Clips Children" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Flip and Rotation", Name = "FlipHorizontal" }); AddEventVariables(stateSave, defaultHasEvents: true); #if GUM PluginManager.Self.ModifyDefaultStandardState("Container", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Container", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ColoredRectangle // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave); AddDimensionsVariables(stateSave, 50, 50, DimensionVariableAction.ExcludeFileOptions); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); AddColorVariables(stateSave, true); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "Blend", Value = Blend.Normal, Name = "Blend", Category = "Rendering" }); AddEventVariables(stateSave); AddStateVariable(stateSave); #if GUM PluginManager.Self.ModifyDefaultStandardState("ColoredRectangle", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("ColoredRectangle", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Circle // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Radius" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Width", IsHiddenInPropertyGrid = true }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Height", IsHiddenInPropertyGrid = true }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); AddColorVariables(stateSave, true); // Although rotating a circle about its center does nothing we add rotation because you can rotate it about a different origin stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); AddEventVariables(stateSave); AddStateVariable(stateSave); #if GUM PluginManager.Self.ModifyDefaultStandardState("Circle", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Circle", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Rectangle // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave); AddDimensionsVariables(stateSave, 16, 16, DimensionVariableAction.ExcludeFileOptions); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); AddColorVariables(stateSave, true); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); AddEventVariables(stateSave); AddStateVariable(stateSave); #if GUM PluginManager.Self.ModifyDefaultStandardState("Rectangle", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Rectangle", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Polygon // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave, addOriginVariables: false); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); AddColorVariables(stateSave, true); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); var pointsVariable = new VariableListSave <Vector2>() { Name = "Points", Category = "Points" }; pointsVariable.Value.Add(new Vector2(-32, -32)); pointsVariable.Value.Add(new Vector2(32, -32)); pointsVariable.Value.Add(new Vector2(32, 32)); pointsVariable.Value.Add(new Vector2(-32, 32)); // close it: pointsVariable.Value.Add(new Vector2(-32, -32)); stateSave.VariableLists.Add(pointsVariable); AddStateVariable(stateSave); #if GUM PluginManager.Self.ModifyDefaultStandardState("Polygon", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Polygon", stateSave); } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // NineSlice // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; AddPositioningVariables(stateSave); AddDimensionsVariables(stateSave, 64, 64, DimensionVariableAction.ExcludeFileOptions); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "", Name = "SourceFile", IsFile = true }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" }); AddColorVariables(stateSave); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "Blend", Value = Blend.Normal, Name = "Blend", Category = "Rendering" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "TextureAddress", Value = Gum.Managers.TextureAddress.EntireTexture, Name = "Texture Address", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Left", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Top", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Width", Category = "Source" }); stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Height", Category = "Source" }); AddEventVariables(stateSave); AddStateVariable(stateSave); stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" }); #if GUM PluginManager.Self.ModifyDefaultStandardState("NineSlice", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("NineSlice", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Component // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; #if GUM PluginManager.Self.ModifyDefaultStandardState("Component", stateSave); #endif #if GUM // Victor Chelaru // August 21, 2014 // Not sure why we have // this here. Doing so would // create an endless loop... //stateSave.Variables.Add(new VariableSave { Type = "string", Value = "Default", Name = "State", CustomTypeConverter = new AvailableStatesConverter(null)}); // The type used to be "string" but we want to differentiate it from actual strings so we use "State" stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "State", Value = null, Name = "State", CustomTypeConverter = new AvailableStatesConverter(null) }); #endif ApplySortValuesFromOrderInState(stateSave); // Not sure if component needs this - does it get values from container? //AddEventVariables(stateSave); mDefaults.Add("Component", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Screen // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var stateSave = new StateSave(); stateSave.Name = "Default"; #if GUM PluginManager.Self.ModifyDefaultStandardState("Screen", stateSave); #endif ApplySortValuesFromOrderInState(stateSave); mDefaults.Add("Screen", stateSave); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } // We shouldn't do this because states above may explicitly not want to set values - like the variable for state //foreach (var defaultState in mDefaults.Values) //{ // foreach (var variable in defaultState.Variables) // { // variable.SetsValue = true; // } //} }
public static TypeConverter GetTypeConverter(this VariableListSave variableListSave) { return(TypeDescriptor.GetConverter(typeof(List <string>))); //ExpandableObjectConverter eoc = new ExpandableObjectConverter(); //return eoc; }
/// <summary> /// Called when the user clicks the "Make Default" menu item /// </summary> /// <param name="variableName">The variable to make default.</param> private void ResetVariableToDefault(string variableName) { bool shouldReset = false; bool affectsTreeView = false; if (SelectedState.Self.SelectedInstance != null) { affectsTreeView = variableName == "Parent"; variableName = SelectedState.Self.SelectedInstance.Name + "." + variableName; shouldReset = true; } else if (SelectedState.Self.SelectedElement != null) { shouldReset = // Don't let the user reset standard element variables, they have to have some actual value (SelectedState.Self.SelectedElement is StandardElementSave) == false || // ... unless it's not the default SelectedState.Self.SelectedStateSave != SelectedState.Self.SelectedElement.DefaultState; } if (shouldReset) { StateSave state = SelectedState.Self.SelectedStateSave; bool wasChangeMade = false; VariableSave variable = state.GetVariableSave(variableName); if (variable != null) { // Don't remove the variable if it's part of an element - we still want it there // so it can be set, we just don't want it to set a value // Update August 13, 2013 // Actually, we do want to remove it if it's part of an element but not the // default state bool shouldRemove = SelectedState.Self.SelectedInstance != null || SelectedState.Self.SelectedStateSave != SelectedState.Self.SelectedElement.DefaultState; // Also, don't remove it if it's an exposed variable, this un-exposes things shouldRemove = shouldRemove && string.IsNullOrEmpty(variable.ExposedAsName); if (shouldRemove) { state.Variables.Remove(variable); } else { variable.Value = null; variable.SetsValue = false; } wasChangeMade = true; // We need to refresh the property grid and the wireframe display } else { // Maybe this is a variable list? VariableListSave variableList = state.GetVariableListSave(variableName); if (variableList != null) { state.VariableLists.Remove(variableList); // We don't support this yet: // variableList.SetsValue = false; // just to be safe wasChangeMade = true; } } if (wasChangeMade) { RefreshUI(); WireframeObjectManager.Self.RefreshAll(true); SelectionManager.Self.Refresh(); if (affectsTreeView) { GumCommands.Self.GuiCommands.RefreshElementTreeView(SelectedState.Self.SelectedElement); } if (ProjectManager.Self.GeneralSettingsFile.AutoSave) { ProjectManager.Self.SaveElement(SelectedState.Self.SelectedElement); } } } }
private static bool AddAndModifyVariablesAccordingToDefault(ElementSave elementSave, StateSave defaultState) { bool wasModified = false; // Use States and not AllStates because we want to make sure we // have a default state. if (elementSave.States.Count == 0 && defaultState != null) { StateSave stateToAdd = defaultState.Clone(); elementSave.States.Add(stateToAdd); wasModified = true; } else if (elementSave.States.Count != 0 && defaultState != null) { // Replacing the default state: // Update March 16, 2012 // Used to replace but realized // it's better to not replace but // instead add variables that are not // already there. That way when the user // switches types the old information isn't // lost. //elementSave.States[0] = replacement; StateSave stateForNewType = defaultState.Clone(); foreach (VariableSave variableSave in stateForNewType.Variables) { VariableSave existingVariable = elementSave.DefaultState.GetVariableSave(variableSave.Name); if (existingVariable == null) { wasModified = true; elementSave.DefaultState.Variables.Add(variableSave.Clone()); } else { // All of these properties are only relevant to the // editor so we don't want to mark the object as modified // when these properties are set. existingVariable.Category = variableSave.Category; #if !WINDOWS_8 && !UWP existingVariable.CustomTypeConverter = variableSave.CustomTypeConverter; #endif existingVariable.ExcludedValuesForEnum.Clear(); existingVariable.ExcludedValuesForEnum.AddRange(variableSave.ExcludedValuesForEnum); // let's fix any values that may be incorrectly set from types if (existingVariable.Type == "float" && existingVariable.Value != null && (existingVariable.Value is float) == false) { float asFloat = 0.0f; try { asFloat = (float)System.Convert.ChangeType(existingVariable.Value, typeof(float)); } catch { // do nothing, we'll fall back to 0 } existingVariable.Value = asFloat; wasModified = true; } } } // We also need to add any VariableListSaves here foreach (VariableListSave variableList in stateForNewType.VariableLists) { VariableListSave existingList = elementSave.DefaultState.GetVariableListSave(variableList.Name); if (existingList == null) { wasModified = true; // this type doesn't have this list yet, so let's add it elementSave.DefaultState.VariableLists.Add(variableList.Clone()); } else { // See the VariableSave section on why we don't set // wasModified = true here existingList.Category = variableList.Category; } } foreach (var stateSaveCategory in elementSave.Categories) { VariableSave foundVariable = elementSave.DefaultState.Variables.FirstOrDefault(item => item.Name == stateSaveCategory.Name + "State"); if (foundVariable == null) { elementSave.DefaultState.Variables.Add(new VariableSave() { Name = stateSaveCategory.Name + "State", Type = "string", Value = null #if GUM , CustomTypeConverter = new Gum.PropertyGridHelpers.Converters.AvailableStatesConverter(stateSaveCategory.Name) #endif }); } else { #if GUM foundVariable.CustomTypeConverter = new Gum.PropertyGridHelpers.Converters.AvailableStatesConverter(stateSaveCategory.Name); #endif } } VariableSaveSorter vss = new VariableSaveSorter(); vss.ListOrderToMatch = defaultState.Variables; elementSave.DefaultState.Variables.Sort(vss); } else { // Let's give it an empty state so that it doesn't cause runtime problems // Nevermind, this causes problelms in Gum, and it should be okay to pass a null state here //elementSave.States.Add(new StateSave()); } return(wasModified); }
//private void ReactIfChangedMemberIsAnimation(ElementSave parentElement, string changedMember, object oldValue, out bool saveProject) //{ // const string sourceFileString = "SourceFile"; // if (changedMember == sourceFileString) // { // StateSave stateSave = SelectedState.Self.SelectedStateSave; // string value = (string)stateSave.GetValueRecursive(sourceFileString); // if (!FileManager.IsRelative) // { // } // saveProject = true; // } // saveProject = false; //} /// <summary> /// Called when the user clicks the "Make Default" menu item /// </summary> /// <param name="variableName">The variable to make default.</param> private void ResetVariableToDefault(StateReferencingInstanceMember srim) { string variableName = srim.Name; bool shouldReset = false; bool affectsTreeView = false; var selectedElement = SelectedState.Self.SelectedElement; if (SelectedState.Self.SelectedInstance != null) { affectsTreeView = variableName == "Parent"; //variableName = SelectedState.Self.SelectedInstance.Name + "." + variableName; shouldReset = true; } else if (selectedElement != null) { shouldReset = // Don't let the user reset standard element variables, they have to have some actual value (selectedElement is StandardElementSave) == false || // ... unless it's not the default SelectedState.Self.SelectedStateSave != SelectedState.Self.SelectedElement.DefaultState; } // now we reset, but we don't remove the variable: //if(shouldReset) //{ // // If the variable is part of a category, then we don't allow setting the variable to default - they gotta do it through the cateory itself // if (isPartOfCategory) // { // var window = new DeletingVariablesInCategoriesMessageBox(); // window.ShowDialog(); // shouldReset = false; // } //} if (shouldReset) { bool isPartOfCategory = srim.StateSaveCategory != null; StateSave state = SelectedState.Self.SelectedStateSave; bool wasChangeMade = false; VariableSave variable = state.GetVariableSave(variableName); if (variable != null) { // Don't remove the variable if it's part of an element - we still want it there // so it can be set, we just don't want it to set a value // Update August 13, 2013 // Actually, we do want to remove it if it's part of an element but not the // default state // Update October 17, 2017 // Now that components do not // necessarily need to have all // of their variables, we can remove // the variable now. In fact, we should //bool shouldRemove = SelectedState.Self.SelectedInstance != null || // SelectedState.Self.SelectedStateSave != SelectedState.Self.SelectedElement.DefaultState; // Also, don't remove it if it's an exposed variable, this un-exposes things bool shouldRemove = string.IsNullOrEmpty(variable.ExposedAsName) && !isPartOfCategory; // Update October 7, 2019 // Actually, we can remove any variable so long as the current state isn't the "base definition" for it // For elements - no variables are the base variable definitions except for variables that are categorized // state variables for categories defined in this element if (shouldRemove) { var isState = variable.IsState(selectedElement, out ElementSave categoryContainer, out StateSaveCategory categoryForVariable); if (isState) { var isDefinedHere = categoryForVariable != null && categoryContainer == selectedElement; shouldRemove = !isDefinedHere; } } if (shouldRemove) { state.Variables.Remove(variable); } else if (isPartOfCategory) { var variableInDefault = SelectedState.Self.SelectedElement.DefaultState.GetVariableSave(variable.Name); if (variableInDefault != null) { GumCommands.Self.GuiCommands.PrintOutput( $"The variable {variable.Name} is part of the category {srim.StateSaveCategory.Name} so it cannot be removed. Instead, the value has been set to the value in the default state"); variable.Value = variableInDefault.Value; } else { GumCommands.Self.GuiCommands.PrintOutput("Could not set value to default because the default state doesn't set this value"); } } else { variable.Value = null; variable.SetsValue = false; } wasChangeMade = true; // We need to refresh the property grid and the wireframe display } else { // Maybe this is a variable list? VariableListSave variableList = state.GetVariableListSave(variableName); if (variableList != null) { state.VariableLists.Remove(variableList); // We don't support this yet: // variableList.SetsValue = false; // just to be safe wasChangeMade = true; } } if (wasChangeMade) { RefreshUI(force: true); WireframeObjectManager.Self.RefreshAll(true); SelectionManager.Self.Refresh(); if (affectsTreeView) { GumCommands.Self.GuiCommands.RefreshElementTreeView(SelectedState.Self.SelectedElement); } if (ProjectManager.Self.GeneralSettingsFile.AutoSave) { ProjectManager.Self.SaveElement(SelectedState.Self.SelectedElement); } } } else { srim.IsDefault = false; } }
private void AddGumVariables(InstructionSave glueVariable, NamedObjectSave namedObject, GlueElement glueElement, List <VariableSave> gumVariables, List <VariableListSave> gumVariableLists, VariableGroupDictionary variableGroups, bool isInState = false) { string glueVariableName = glueVariable.Member; if (isInState) { // It's a state variable so it references a different variable that we have to find: var variableOnElement = glueElement.GetCustomVariable(glueVariable.Member); if (variableOnElement != null) { glueVariableName = variableOnElement.SourceObjectProperty; } if (!string.IsNullOrEmpty(variableOnElement.SourceObject)) { namedObject = glueElement.AllNamedObjects .FirstOrDefault(item => item.InstanceName == variableOnElement.SourceObject); } } // Let's be explicit instead of expecting the names to match up: switch (glueVariableName) { case "Height": { var variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Height"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value; gumVariables.Add(variableSave); } break; case "Points": { var variableListSave = new VariableListSave <Vector2>(); variableListSave.Name = $"{namedObject.InstanceName}.Points"; var pointsPositiveYUp = glueVariable.Value as List <Vector2>; if (pointsPositiveYUp != null) { foreach (var frbPoint in pointsPositiveYUp) { var newPoint = frbPoint; newPoint.Y *= -1; variableListSave.ValueAsIList.Add(newPoint); } } gumVariableLists.Add(variableListSave); } break; case "Radius": { if (namedObject.SourceType == SourceType.FlatRedBallType && namedObject.SourceClassType == "Circle") { var variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Width"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value * 2.0f; variableSave.IsHiddenInPropertyGrid = true; gumVariables.Add(variableSave); variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Height"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value * 2.0f; variableSave.IsHiddenInPropertyGrid = true; gumVariables.Add(variableSave); variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Radius"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value; gumVariables.Add(variableSave); } } break; case "RotationZ": { var variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Rotation"; variableSave.Type = "float"; var valueRadians = (float)glueVariable.Value; var degrees = 360 * (valueRadians / (2 * Math.PI)); variableSave.Value = (float)degrees; gumVariables.Add(variableSave); } break; case "RightTexturePixel": case "LeftTexturePixel": case "BottomTexturePixel": case "TopTexturePixel": variableGroups.AddVariable(glueVariable, namedObject, glueVariableName, GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory); break; case "Texture": { var variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.SourceFile"; variableSave.Type = "string"; //var referencedFileName = (string)glueVariable.Value; //var nos = glueElement.GetReferencedFileSave(referencedFileName); //if(nos == null) //{ // // todo - need to look in global content; //} // assume the content location is in a monogame DGL location, and the // file is a PNG. Eventually we can make this more intelligent var fileName = $"../Content/{glueElement.Name}/{(string)glueVariable.Value}.png"; variableSave.Value = fileName; variableSave.IsFile = true; gumVariables.Add(variableSave); variableGroups.AddVariable(glueVariable, namedObject, glueVariableName, GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory); } break; case "TextureScale": { var variableSave = new VariableSave(); variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Width"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value * 100; gumVariables.Add(variableSave); variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Height"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value * 100; gumVariables.Add(variableSave); // todo width units? } break; case "X": { VariableSave variableSave = null; variableSave = new VariableSave(); variableSave.Type = "float"; variableSave.Name = $"{namedObject.InstanceName}.X"; variableSave.Value = (float)glueVariable.Value; gumVariables.Add(variableSave); } break; case "Width": { var variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Width"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value; gumVariables.Add(variableSave); } break; case "Y": { var variableSave = new VariableSave(); variableSave.Name = $"{namedObject.InstanceName}.Y"; variableSave.Type = "float"; variableSave.Value = (float)glueVariable.Value; gumVariables.Add(variableSave); } break; default: int m = 3; break; } }
private static void DisplayCurrentElement(List <InstanceSavePropertyDescriptor> pdc, ElementSave elementSave, InstanceSave instanceSave, StateSave defaultState, string prependedVariable, AmountToDisplay amountToDisplay = AmountToDisplay.AllVariables) { bool isDefault = SelectedState.Self.SelectedStateSave == SelectedState.Self.SelectedElement.DefaultState; if (instanceSave?.DefinedByBase == true) { isDefault = false; } if (!string.IsNullOrEmpty(prependedVariable)) { prependedVariable += "."; } bool isCustomType = (elementSave is StandardElementSave) == false; if (isCustomType || instanceSave != null) { AddNameAndBaseTypeProperties(pdc, elementSave, instanceSave, isReadOnly: isDefault == false); } if (instanceSave != null) { mHelper.AddProperty(pdc, "Locked", typeof(bool)).IsReadOnly = !isDefault; } // if component if (instanceSave == null && elementSave as ComponentSave != null) { var variables = StandardElementsManager.Self.GetDefaultStateFor("Component").Variables; foreach (var item in variables) { // Don't add states here, because they're handled below from this object's Default: if (item.IsState(elementSave) == false) { TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, item); } } } // else if screen else if (instanceSave == null && elementSave as ScreenSave != null) { foreach (var item in StandardElementsManager.Self.GetDefaultStateFor("Screen").Variables) { TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, item); } } #region Loop through all variables // We want to use the default state to get all possible // variables because the default state will always set all // variables. We then look at the current state to get the // actual value for (int i = 0; i < defaultState.Variables.Count; i++) { VariableSave defaultVariable = defaultState.Variables[i]; TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, defaultVariable); } #endregion #region Loop through all list variables for (int i = 0; i < defaultState.VariableLists.Count; i++) { VariableListSave variableList = defaultState.VariableLists[i]; bool shouldInclude = GetIfShouldInclude(variableList, elementSave, instanceSave); if (shouldInclude) { TypeConverter typeConverter = variableList.GetTypeConverter(); Attribute[] customAttributes = GetAttributesForVariable(variableList); Type type = typeof(List <string>); mHelper.AddProperty(pdc, variableList.Name, type, typeConverter, // //, customAttributes ); } } #endregion }
//private void ReactIfChangedMemberIsAnimation(ElementSave parentElement, string changedMember, object oldValue, out bool saveProject) //{ // const string sourceFileString = "SourceFile"; // if (changedMember == sourceFileString) // { // StateSave stateSave = SelectedState.Self.SelectedStateSave; // string value = (string)stateSave.GetValueRecursive(sourceFileString); // if (!FileManager.IsRelative) // { // } // saveProject = true; // } // saveProject = false; //} /// <summary> /// Called when the user clicks the "Make Default" menu item /// </summary> /// <param name="variableName">The variable to make default.</param> private void ResetVariableToDefault(StateReferencingInstanceMember srim) { string variableName = srim.Name; bool shouldReset = false; bool affectsTreeView = false; if (SelectedState.Self.SelectedInstance != null) { affectsTreeView = variableName == "Parent"; //variableName = SelectedState.Self.SelectedInstance.Name + "." + variableName; shouldReset = true; } else if (SelectedState.Self.SelectedElement != null) { shouldReset = // Don't let the user reset standard element variables, they have to have some actual value (SelectedState.Self.SelectedElement is StandardElementSave) == false || // ... unless it's not the default SelectedState.Self.SelectedStateSave != SelectedState.Self.SelectedElement.DefaultState; } if (shouldReset) { // If the variable is part of a category, then we don't allow setting the variable to default - they gotta do it through the cateory itself bool isPartOfCategory = srim.StateSaveCategory != null; if (isPartOfCategory) { var window = new DeletingVariablesInCategoriesMessageBox(); window.ShowDialog(); shouldReset = false; } } if (shouldReset) { StateSave state = SelectedState.Self.SelectedStateSave; bool wasChangeMade = false; VariableSave variable = state.GetVariableSave(variableName); if (variable != null) { // Don't remove the variable if it's part of an element - we still want it there // so it can be set, we just don't want it to set a value // Update August 13, 2013 // Actually, we do want to remove it if it's part of an element but not the // default state // Update October 17, 2017 // Now that components do not // necessarily need to have all // of their variables, we can remove // the variable now. In fact, we should //bool shouldRemove = SelectedState.Self.SelectedInstance != null || // SelectedState.Self.SelectedStateSave != SelectedState.Self.SelectedElement.DefaultState; // Also, don't remove it if it's an exposed variable, this un-exposes things bool shouldRemove = string.IsNullOrEmpty(variable.ExposedAsName); if (shouldRemove) { state.Variables.Remove(variable); } else { variable.Value = null; variable.SetsValue = false; } wasChangeMade = true; // We need to refresh the property grid and the wireframe display } else { // Maybe this is a variable list? VariableListSave variableList = state.GetVariableListSave(variableName); if (variableList != null) { state.VariableLists.Remove(variableList); // We don't support this yet: // variableList.SetsValue = false; // just to be safe wasChangeMade = true; } } if (wasChangeMade) { RefreshUI(); WireframeObjectManager.Self.RefreshAll(true); SelectionManager.Self.Refresh(); if (affectsTreeView) { GumCommands.Self.GuiCommands.RefreshElementTreeView(SelectedState.Self.SelectedElement); } if (ProjectManager.Self.GeneralSettingsFile.AutoSave) { ProjectManager.Self.SaveElement(SelectedState.Self.SelectedElement); } } } else { srim.IsDefault = false; } }
public static void PasteInstanceSaves(List <InstanceSave> instancesToCopy, StateSave copiedState, ElementSave targetElement) { Dictionary <string, string> oldNewNameDictionary = new Dictionary <string, string>(); List <InstanceSave> newInstances = new List <InstanceSave>(); foreach (var sourceInstance in instancesToCopy) { ElementSave sourceElement = sourceInstance.ParentContainer; InstanceSave newInstance = sourceInstance.Clone(); // the original may have been defined in a base component. The new instance will not be // derived in the base, so let's get rid of that: newInstance.DefinedByBase = false; newInstances.Add(newInstance); if (targetElement != null) { var oldName = newInstance.Name; newInstance.Name = StringFunctions.MakeStringUnique(newInstance.Name, targetElement.Instances.Select(item => item.Name)); var newName = newInstance.Name; oldNewNameDictionary[oldName] = newName; if (targetElement == sourceElement) { var original = sourceElement.Instances.FirstOrDefault(item => item.Name == sourceInstance.Name); int newIndex = -1; if (original != null) { newIndex = sourceElement.Instances.IndexOf(original); } if (newIndex != -1) { targetElement.Instances.Insert(newIndex + 1, newInstance); } else { targetElement.Instances.Add(newInstance); } } else { targetElement.Instances.Add(newInstance); } } } foreach (var sourceInstance in instancesToCopy) { ElementSave sourceElement = sourceInstance.ParentContainer; var newInstance = newInstances.First(item => item.Name == oldNewNameDictionary[sourceInstance.Name]); if (targetElement != null) { StateSave stateSave = copiedState; StateSave targetState; // We now have to copy over the states if (targetElement != sourceElement) { if (sourceElement.States.Count != 1) { MessageBox.Show("Only the default state variables will be copied since the source and target elements differ."); } targetState = targetElement.DefaultState; } else { targetState = SelectedState.Self.SelectedStateSave ?? SelectedState.Self.SelectedElement.DefaultState; } // why reverse loop? for (int i = stateSave.Variables.Count - 1; i > -1; i--) { // We may have copied over a group of instances. If so // the copied state may have variables for multiple instances. // We only want to apply the variables that work for the selected // object. VariableSave sourceVariable = stateSave.Variables[i]; if (sourceVariable.SourceObject == sourceInstance.Name) { VariableSave copiedVariable = sourceVariable.Clone(); copiedVariable.Name = newInstance.Name + "." + copiedVariable.GetRootName(); var valueAsString = copiedVariable.Value as string; if (copiedVariable.GetRootName() == "Parent" && string.IsNullOrWhiteSpace(valueAsString) == false && oldNewNameDictionary.ContainsKey(valueAsString)) { // this is a parent and it may be attached to a copy, so update the value var newValue = oldNewNameDictionary[valueAsString]; copiedVariable.Value = newValue; } // We don't want to copy exposed variables. // If we did, the user would have 2 variables exposed with the same. copiedVariable.ExposedAsName = null; targetState.Variables.Add(copiedVariable); } } // Copy over the VariableLists too for (int i = stateSave.VariableLists.Count - 1; i > -1; i--) { VariableListSave sourceVariableList = stateSave.VariableLists[i]; if (sourceVariableList.SourceObject == sourceInstance.Name) { VariableListSave copiedList = sourceVariableList.Clone(); copiedList.Name = newInstance.Name + "." + copiedList.GetRootName(); targetState.VariableLists.Add(copiedList); } } // This used to be done here when we paste, but now we're // going to remove it when the cut happens - just like text // editors. Undo will handle this if we mess up. // bool shouldSaveSource = false; //if (mIsCtrlXCut) //{ // if (sourceElement.Instances.Contains(sourceInstance)) // { // // Not sure why we weren't just using // // ElementCommands here - maybe an oversight? // // This should improve things like // //sourceElement.Instances.Remove(sourceInstance); // ElementCommands.Self.RemoveInstance(sourceInstance, sourceElement); // shouldSaveSource = true; // } //} newInstance.ParentContainer = targetElement; // We need to call InstanceAdd before we select the new object - the Undo manager expects it // This includes before other managers refresh PluginManager.Self.InstanceAdd(targetElement, newInstance); } } WireframeObjectManager.Self.RefreshAll(true); GumCommands.Self.GuiCommands.RefreshElementTreeView(targetElement); GumCommands.Self.FileCommands.TryAutoSaveElement(targetElement); SelectedState.Self.SelectedInstances = newInstances; }
private void PastedCopiedInstance(InstanceSave sourceInstance, ElementSave sourceElement, ElementSave targetElement, InstanceSave targetInstance, StateSave copiedState) { targetInstance.Name = StringFunctions.MakeStringUnique(targetInstance.Name, targetElement.Instances.Select(item => item.Name)); targetElement.Instances.Add(targetInstance); StateSave stateSave = copiedState; StateSave targetState; // We now have to copy over the states if (targetElement != sourceElement) { if (sourceElement.States.Count != 1) { MessageBox.Show("Only the default state variables will be copied since the source and target elements differ."); } targetState = targetElement.DefaultState; } else { targetState = SelectedState.Self.SelectedStateSave; } // why reverse loop? for (int i = stateSave.Variables.Count - 1; i > -1; i--) { // We may have copied over a group of instances. If so // the copied state may have variables for multiple instances. // We only want to apply the variables that work for the selected // object. VariableSave sourceVariable = stateSave.Variables[i]; if (sourceVariable.SourceObject == sourceInstance.Name) { VariableSave copiedVariable = sourceVariable.Clone(); copiedVariable.Name = targetInstance.Name + "." + copiedVariable.GetRootName(); // We don't want to copy exposed variables. // If we did, the user would have 2 variables exposed with the same. copiedVariable.ExposedAsName = null; targetState.Variables.Add(copiedVariable); } } // Copy over the VariableLists too for (int i = stateSave.VariableLists.Count - 1; i > -1; i--) { VariableListSave sourceVariableList = stateSave.VariableLists[i]; if (sourceVariableList.SourceObject == sourceInstance.Name) { VariableListSave copiedList = sourceVariableList.Clone(); copiedList.Name = targetInstance.Name + "." + copiedList.GetRootName(); targetState.VariableLists.Add(copiedList); } } // This used to be done here when we paste, but now we're // going to remove it when the cut happens - just like text // editors. Undo will handle this if we mess up. // bool shouldSaveSource = false; //if (mIsCtrlXCut) //{ // if (sourceElement.Instances.Contains(sourceInstance)) // { // // Not sure why we weren't just using // // ElementCommands here - maybe an oversight? // // This should improve things like // //sourceElement.Instances.Remove(sourceInstance); // ElementCommands.Self.RemoveInstance(sourceInstance, sourceElement); // shouldSaveSource = true; // } //} targetInstance.ParentContainer = targetElement; // We need to call InstanceAdd before we select the new object - the Undo manager expects it // This includes before other managers refresh PluginManager.Self.InstanceAdd(targetElement, targetInstance); WireframeObjectManager.Self.RefreshAll(true); GumCommands.Self.GuiCommands.RefreshElementTreeView(targetElement); SelectedState.Self.SelectedInstance = targetInstance; GumCommands.Self.FileCommands.TryAutoSaveElement(targetElement); }
private static PropertyDescriptorCollection DisplayCurrentElement(PropertyDescriptorCollection pdc, ElementSave elementSave, InstanceSave instanceSave, StateSave defaultState, string prependedVariable, AmountToDisplay amountToDisplay = AmountToDisplay.AllVariables) { bool isDefault = SelectedState.Self.SelectedStateSave == SelectedState.Self.SelectedElement.DefaultState; if (!string.IsNullOrEmpty(prependedVariable)) { prependedVariable += "."; } bool isCustomType = (elementSave is StandardElementSave) == false; if (isDefault && (isCustomType || instanceSave != null)) { pdc = AddNameAndBaseTypeProperties(pdc); } if (instanceSave != null) { if (isDefault) { pdc = mHelper.AddProperty(pdc, "Locked", typeof(bool)); } } // if component if (instanceSave == null && elementSave as ComponentSave != null) { foreach (var item in StandardElementsManager.Self.GetDefaultStateFor("Component").Variables) { pdc = TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, null, item); } } // else if screen else if (instanceSave == null && elementSave as ScreenSave != null) { foreach (var item in StandardElementsManager.Self.GetDefaultStateFor("Screen").Variables) { pdc = TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, null, item); } } #region Get the StandardElementSave for the instance/element (depending on what's selected) StandardElementSave ses = null; if (instanceSave != null) { ses = ObjectFinder.Self.GetRootStandardElementSave(instanceSave); } else if ((elementSave is ScreenSave) == false) { ses = ObjectFinder.Self.GetRootStandardElementSave(elementSave); } #endregion #region Loop through all variables // We want to use the default state to get all possible // variables because the default state will always set all // variables. We then look at the current state to get the // actual value for (int i = 0; i < defaultState.Variables.Count; i++) { VariableSave defaultVariable = defaultState.Variables[i]; pdc = TryDisplayVariableSave(pdc, elementSave, instanceSave, amountToDisplay, ses, defaultVariable); } #endregion #region Loop through all list variables for (int i = 0; i < defaultState.VariableLists.Count; i++) { VariableListSave variableList = defaultState.VariableLists[i]; bool shouldInclude = GetIfShouldInclude(variableList, elementSave, instanceSave, null); if (shouldInclude) { TypeConverter typeConverter = variableList.GetTypeConverter(); Attribute[] customAttributes = GetAttributesForVariable(variableList); Type type = typeof(List <string>); pdc = mHelper.AddProperty(pdc, variableList.Name, type, typeConverter, // //, customAttributes ); } } #endregion return(pdc); }