private void GetMemberCategoriesForState(ElementSave element, InstanceSave instance, List <MemberCategory> categories, StateSave stateSave, StateSaveCategory stateSaveCategory) { categories.Clear(); var properties = mPropertyGridDisplayer.GetProperties(null); foreach (InstanceSavePropertyDescriptor propertyDescriptor in properties) { // early continue var browsableAttribute = propertyDescriptor.Attributes?.FirstOrDefault(item => item is BrowsableAttribute); var isMarkedAsNotBrowsable = browsableAttribute != null && (browsableAttribute as BrowsableAttribute).Browsable == false; if (isMarkedAsNotBrowsable) { continue; } StateReferencingInstanceMember srim; if (instance != null) { srim = new StateReferencingInstanceMember(propertyDescriptor, stateSave, stateSaveCategory, instance.Name + "." + propertyDescriptor.Name, instance, element); } else { srim = new StateReferencingInstanceMember(propertyDescriptor, stateSave, stateSaveCategory, propertyDescriptor.Name, instance, element); } srim.SetToDefault += (memberName) => ResetVariableToDefault(srim); string category = propertyDescriptor.Category?.Trim(); var categoryToAddTo = categories.FirstOrDefault(item => item.Name == category); if (categoryToAddTo == null) { categoryToAddTo = new MemberCategory(category); categories.Add(categoryToAddTo); } categoryToAddTo.Members.Add(srim); } foreach (var category in categories) { var enumerable = category.Members.OrderBy(item => ((StateReferencingInstanceMember)item).SortValue).ToList(); category.Members.Clear(); foreach (var value in enumerable) { category.Members.Add(value); } } ReorganizeCategories(categories); CustomizeVariables(categories); }
private List <MemberCategory> GetCategories(ElementSave element, StateSave state, InstanceSave instance) { List <MemberCategory> categories = new List <MemberCategory>(); mLastElement = element; mLastState = state; mLastInstance = instance; var stateSave = SelectedState.Self.SelectedStateSave; if (stateSave != null) { categories.Clear(); var properties = mPropertyGridDisplayer.GetProperties(null); foreach (InstanceSavePropertyDescriptor propertyDescriptor in properties) { StateReferencingInstanceMember srim; if (instance != null) { srim = new StateReferencingInstanceMember(propertyDescriptor, stateSave, instance.Name + "." + propertyDescriptor.Name, instance, element); } else { srim = new StateReferencingInstanceMember(propertyDescriptor, stateSave, propertyDescriptor.Name, instance, element); } srim.SetToDefault += ResetVariableToDefault; string category = propertyDescriptor.Category.Trim(); var categoryToAddTo = categories.FirstOrDefault(item => item.Name == category); if (categoryToAddTo == null) { categoryToAddTo = new MemberCategory(category); categories.Add(categoryToAddTo); } categoryToAddTo.Members.Add(srim); } foreach (var category in categories) { var enumerable = category.Members.OrderBy(item => ((StateReferencingInstanceMember)item).SortValue).ToList(); category.Members.Clear(); foreach (var value in enumerable) { category.Members.Add(value); } } MemberCategory categoryToMove = categories.FirstOrDefault(item => item.Name == "Position"); if (categoryToMove != null) { categories.Remove(categoryToMove); categories.Insert(1, categoryToMove); } categoryToMove = categories.FirstOrDefault(item => item.Name == "Dimensions"); if (categoryToMove != null) { categories.Remove(categoryToMove); categories.Insert(2, categoryToMove); } UpdateColorCategory(categories); } return(categories); }
//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 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; } }