private static void PerformStandardVariableAssignments(NamedObjectSave instance, TypedMemberBase typedMember, object value, DataGridItem instanceMember, Type memberType) { // If we ignore the next refresh, then AnimationChains won't update when the user // picks an AnimationChainList from a combo box: //RefreshLogic.IgnoreNextRefresh(); GlueCommands.Self.GluxCommands.SetVariableOn( instance, typedMember.MemberName, memberType, value); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); // let's make the UI faster: // Get this on the UI thread, but use it in the async call below var currentElement = GlueState.Self.CurrentElement; TaskManager.Self.AddAsyncTask(() => { GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(currentElement); }, "Saving .glux and regenerating the code for the current element"); }
public static void ReactToValueSet(NamedObjectSave instance, TypedMemberBase typedMember, object value, DataGridItem instanceMember, Type memberType) { instanceMember.IsDefault = false; TryAdjustingValue(instance, typedMember, ref value, instanceMember); PerformStandardVariableAssignments(instance, typedMember, value, instanceMember, memberType); }
private static void TryAdjustingValue(NamedObjectSave instance, TypedMemberBase typedMember, ref object value, DataGridItem instanceMember) { if(typedMember.MemberType == typeof(AnimationChainList)) { if(value is string && ((string)value) == "<NONE>") { value = null; instanceMember.IsDefault = true; // Let's also set the CurrentChainName to null GlueCommands.Self.GluxCommands.SetVariableOn( instance, "CurrentChainName", typeof(string), null); } } }
private static void CreateInstanceMembersForVariables(IElement element, MemberCategory category) { foreach (CustomVariable variable in element.CustomVariables) { Type type = variable.GetRuntimeType(); if (type == null) { type = typeof(string); } string name = variable.Name; //object value = variable.DefaultValue; // todo - do something with converter var instanceMember = new DataGridItem(); instanceMember.CustomGetTypeEvent += (throwaway) => type; string displayName = StringFunctions.InsertSpacesInCamelCaseString(name); instanceMember.DisplayName = displayName; instanceMember.UnmodifiedVariableName = name; TypeConverter converter = variable.GetTypeConverter(element); instanceMember.TypeConverter = converter; instanceMember.CustomSetEvent += (intance, value) => { instanceMember.IsDefault = false; RefreshLogic.IgnoreNextRefresh(); var oldValue = variable.DefaultValue; variable.DefaultValue = value; EditorObjects.IoC.Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue( "DefaultValue", variable, oldValue); GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); }; instanceMember.CustomGetEvent += (instance) => { var foundVariable = element.GetCustomVariableRecursively(name); return(foundVariable?.DefaultValue); }; instanceMember.IsDefaultSet += (owner, args) => { element.GetCustomVariableRecursively(name).DefaultValue = null; GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); }; instanceMember.SetValueError = (newValue) => { if (newValue is string && string.IsNullOrEmpty(newValue as string)) { element.GetCustomVariableRecursively(name).DefaultValue = null; GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); } }; instanceMember.ContextMenuEvents.Add("Variable Properties", (sender, args) => GlueState.Self.CurrentCustomVariable = variable); category.Members.Add(instanceMember); } }
private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container, TypedMemberBase typedMember, AssetTypeInfo ati, VariableDefinition variableDefinition) { bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati); DataGridItem instanceMember = null; if (!shouldBeSkipped) { var typeConverter = PluginManager.GetTypeConverter( container, instance, typedMember); bool isObjectInFile = typeConverter is IObjectsInFileConverter; var memberType = typedMember.MemberType; if (isObjectInFile) { var fileInstanceMember = new FileInstanceMember(); instanceMember = fileInstanceMember; fileInstanceMember.View += () => { var rfs = (typeConverter as IObjectsInFileConverter).ReferencedFileSave; if (rfs != null) { var value = fileInstanceMember.Value as string; GlueCommands.Self.SelectCommands.Select( rfs, value); } }; instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox); } else { instanceMember = new DataGridItem(); } if (variableDefinition?.Name == "RotationZ" && variableDefinition.Type == "float") { instanceMember.PreferredDisplayer = typeof(AngleSelectorDisplay); instanceMember.PropertiesToSetOnDisplayer[nameof(AngleSelectorDisplay.TypeToPushToInstance)] = AngleType.Radians; } instanceMember.FirstGridLength = new System.Windows.GridLength(140); instanceMember.UnmodifiedVariableName = typedMember.MemberName; string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName); instanceMember.DisplayName = displayName; instanceMember.TypeConverter = typeConverter; instanceMember.CustomRefreshOptions += () => { if (typeConverter != null) { instanceMember.CustomOptions.Clear(); var values = typeConverter.GetStandardValues(); foreach (var value in values) { instanceMember.CustomOptions.Add(value); } } }; instanceMember.CustomGetTypeEvent += (throwaway) => memberType; instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null; instanceMember.CustomGetEvent += (throwaway) => { var instruction = instance.GetInstructionFromMember(typedMember.MemberName); if (instruction == null) { if (variableDefinition != null) { var toReturn = variableDefinition.DefaultValue; if (memberType == typeof(bool)) { bool boolToReturn = false; bool.TryParse(variableDefinition.DefaultValue, out boolToReturn); return(boolToReturn); } else { return(toReturn); } } else { return(null); } } else { return(instruction.Value); } }; instanceMember.CustomSetEvent += (owner, value) => { NamedObjectVariableChangeLogic.ReactToValueSet(instance, typedMember, value, instanceMember, memberType); }; instanceMember.IsDefaultSet += (owner, args) => { MakeDefault(instance, typedMember.MemberName); }; instanceMember.SetValueError += (newValue) => { if (newValue is string && string.IsNullOrEmpty(newValue as string)) { MakeDefault(instance, typedMember.MemberName); } }; instanceMember.ContextMenuEvents.Add("Tunnel Variable", (not, used) => { string variableToTunnel = null; if (variableDefinition != null) { variableToTunnel = variableDefinition?.Name; } else if (typedMember != null) { variableToTunnel = typedMember.MemberName; } GlueCommands.Self.DialogCommands.ShowAddNewVariableDialog( FlatRedBall.Glue.Controls.CustomVariableType.Tunneled, instance.InstanceName, variableToTunnel); }); } return(instanceMember); }
private static void CreateInstanceMembersForVariables(IElement element, MemberCategory category) { foreach (CustomVariable variable in element.CustomVariables) { Type type = variable.GetRuntimeType(); if (type == null) { type = typeof(string); } string name = variable.Name; //object value = variable.DefaultValue; // todo - do something with converter var instanceMember = new DataGridItem(); instanceMember.CustomGetTypeEvent += (throwaway) => type; string displayName = StringFunctions.InsertSpacesInCamelCaseString(name); instanceMember.DisplayName = displayName; instanceMember.UnmodifiedVariableName = name; TypeConverter converter = variable.GetTypeConverter(element); instanceMember.TypeConverter = converter; instanceMember.CustomSetEvent += (intance, value) => { instanceMember.IsDefault = false; RefreshLogic.IgnoreNextRefresh(); element.GetCustomVariableRecursively(name).DefaultValue = value; GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); }; instanceMember.CustomGetEvent += (instance) => { return element.GetCustomVariableRecursively(name).DefaultValue; }; instanceMember.IsDefaultSet += (owner, args) => { element.GetCustomVariableRecursively(name).DefaultValue = null; GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); }; instanceMember.SetValueError = (newValue) => { if (newValue is string && string.IsNullOrEmpty(newValue as string)) { element.GetCustomVariableRecursively(name).DefaultValue = null; GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); } }; category.Members.Add(instanceMember); } }
private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container, TypedMemberBase typedMember, AssetTypeInfo ati) { bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati); DataGridItem instanceMember = null; if (!shouldBeSkipped) { var typeConverter = PluginManager.GetTypeConverter( container, instance, typedMember); bool isObjectInFile = typeConverter is IObjectsInFileConverter; var memberType = typedMember.MemberType; VariableDefinition variableDefinition = null; if (ati != null) { variableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == typedMember.MemberName); } if(isObjectInFile) { var fileInstanceMember = new FileInstanceMember(); instanceMember = fileInstanceMember; fileInstanceMember.View += () => { var rfs = (typeConverter as IObjectsInFileConverter).ReferencedFileSave; if (rfs != null) { var value = fileInstanceMember.Value as string; GlueCommands.Self.SelectCommands.Select( rfs, value); } }; instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox); } else { instanceMember = new DataGridItem(); } instanceMember.FirstGridLength = new System.Windows.GridLength(140); instanceMember.UnmodifiedVariableName = typedMember.MemberName; string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName); instanceMember.DisplayName = displayName; instanceMember.TypeConverter = typeConverter; instanceMember.CustomRefreshOptions += () => { if (typeConverter != null) { instanceMember.CustomOptions.Clear(); var values = typeConverter.GetStandardValues(); foreach (var value in values) { instanceMember.CustomOptions.Add(value); } } }; instanceMember.CustomGetTypeEvent += (throwaway) => memberType; instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null; instanceMember.CustomGetEvent += (throwaway) => { var instruction = instance.GetInstructionFromMember(typedMember.MemberName); if (instruction == null) { if (variableDefinition != null) { var toReturn = variableDefinition.DefaultValue; if (memberType == typeof(bool)) { bool boolToReturn = false; bool.TryParse(variableDefinition.DefaultValue, out boolToReturn); return boolToReturn; } else { return toReturn; } } else { return null; } } else { return instruction.Value; } }; instanceMember.CustomSetEvent += (owner, value) => { NamedObjectVariableChangeLogic.ReactToValueSet(instance, typedMember, value, instanceMember, memberType); }; instanceMember.IsDefaultSet += (owner, args) => { MakeDefault(instance, typedMember.MemberName); }; instanceMember.SetValueError += (newValue) => { if (newValue is string && string.IsNullOrEmpty(newValue as string)) { MakeDefault(instance, typedMember.MemberName); } }; } return instanceMember; }
private static MemberCategory CreateNameInstanceMember(NamedObjectSave instance) { var instanceMember = new DataGridItem(); instanceMember.DisplayName = "Name"; instanceMember.UnmodifiedVariableName = "Name"; // This won't actually be the old value after one change, but it's as good as we can get string oldValue = instance.InstanceName; instanceMember.CustomSetEvent += (throwaway, value) => { instanceMember.IsDefault = false; RefreshLogic.IgnoreNextRefresh(); instance.InstanceName = value as string; EditorObjects.IoC.Container.Get<SetVariableLogic>().ReactToPropertyChanged( "InstanceName", oldValue, "InstanceName", null); //GlueCommands.Self.GluxCommands.SetVariableOn( // instance, // "Name", // typeof(string), // value); GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); }; instanceMember.CustomGetEvent += (throwaway) => { return instance.InstanceName; }; instanceMember.CustomGetTypeEvent += (throwaway) => typeof(string); MemberCategory category = new MemberCategory(); category.Name = ""; category.HideHeader = true; category.Members.Add(instanceMember); return category; }
private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container, TypedMemberBase typedMember, AssetTypeInfo ati) { bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati); DataGridItem instanceMember = null; if (!shouldBeSkipped) { var typeConverter = PluginManager.GetTypeConverter( container, instance, typedMember); bool isObjectInFile = typeConverter is IObjectsInFileConverter; var memberType = typedMember.MemberType; VariableDefinition variableDefinition = null; if (ati != null) { variableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == typedMember.MemberName); } if (isObjectInFile) { var fileInstanceMember = new FileInstanceMember(); instanceMember = fileInstanceMember; fileInstanceMember.View += () => { var rfs = (typeConverter as IObjectsInFileConverter).ReferencedFileSave; if (rfs != null) { var value = fileInstanceMember.Value as string; GlueCommands.Self.SelectCommands.Select( rfs, value); } }; instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox); } else { instanceMember = new DataGridItem(); } instanceMember.FirstGridLength = new System.Windows.GridLength(140); instanceMember.UnmodifiedVariableName = typedMember.MemberName; string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName); instanceMember.DisplayName = displayName; instanceMember.TypeConverter = typeConverter; instanceMember.CustomRefreshOptions += () => { if (typeConverter != null) { instanceMember.CustomOptions.Clear(); var values = typeConverter.GetStandardValues(); foreach (var value in values) { instanceMember.CustomOptions.Add(value); } } }; instanceMember.CustomGetTypeEvent += (throwaway) => memberType; instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null; instanceMember.CustomGetEvent += (throwaway) => { var instruction = instance.GetInstructionFromMember(typedMember.MemberName); if (instruction == null) { if (variableDefinition != null) { var toReturn = variableDefinition.DefaultValue; if (memberType == typeof(bool)) { bool boolToReturn = false; bool.TryParse(variableDefinition.DefaultValue, out boolToReturn); return(boolToReturn); } else { return(toReturn); } } else { return(null); } } else { return(instruction.Value); } }; instanceMember.CustomSetEvent += (owner, value) => { NamedObjectVariableChangeLogic.ReactToValueSet(instance, typedMember, value, instanceMember, memberType); }; instanceMember.IsDefaultSet += (owner, args) => { MakeDefault(instance, typedMember.MemberName); }; instanceMember.SetValueError += (newValue) => { if (newValue is string && string.IsNullOrEmpty(newValue as string)) { MakeDefault(instance, typedMember.MemberName); } }; } return(instanceMember); }
private static void PerformStandardVariableAssignments(NamedObjectSave instance, TypedMemberBase typedMember, object value, DataGridItem instanceMember, Type memberType) { // If we ignore the next refresh, then AnimationChains won't update when the user // picks an AnimationChainList from a combo box: //RefreshLogic.IgnoreNextRefresh(); GlueCommands.Self.GluxCommands.SetVariableOn( instance, typedMember.MemberName, memberType, value); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); // let's make the UI faster: // Get this on the UI thread, but use it in the async call below var currentElement = GlueState.Self.CurrentElement; TaskManager.Self.AddAsyncTask(() => { // don't send an entire frefresh command, we'll refresh // just the variables (prevents a full camera reset) bool sendRefreshCommands = false; GlueCommands.Self.GluxCommands.SaveGlux(sendRefreshCommands); GlueCommands.Self.GlueViewCommands.SendRefreshVariablesCommand(); if (currentElement != null) { GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(currentElement); } }, "Saving .glux and regenerating the code for the current element"); }
private static void TryAdjustingValue(NamedObjectSave instance, TypedMemberBase typedMember, ref object value, DataGridItem instanceMember) { if (typedMember.MemberType == typeof(AnimationChainList)) { if (value is string && ((string)value) == "<NONE>") { value = null; instanceMember.IsDefault = true; // Let's also set the CurrentChainName to null GlueCommands.Self.GluxCommands.SetVariableOn( instance, "CurrentChainName", typeof(string), null); } } }
private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container, TypedMemberBase typedMember, AssetTypeInfo ati) { bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati); DataGridItem instanceMember = null; if (!shouldBeSkipped) { var memberType = typedMember.MemberType; VariableDefinition variableDefinition = null; if (ati != null) { variableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == typedMember.MemberName); } instanceMember = new DataGridItem(); instanceMember.FirstGridLength = new System.Windows.GridLength(140); instanceMember.UnmodifiedVariableName = typedMember.MemberName; string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName); instanceMember.DisplayName = displayName; instanceMember.TypeConverter = PluginManager.GetTypeConverter( container, instance, typedMember); instanceMember.CustomGetTypeEvent += (throwaway) => memberType; instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null; instanceMember.CustomGetEvent += (throwaway) => { var instruction = instance.GetInstructionFromMember(typedMember.MemberName); if (instruction == null) { if (variableDefinition != null) { var toReturn = variableDefinition.DefaultValue; if (memberType == typeof(bool)) { bool boolToReturn = false; bool.TryParse(variableDefinition.DefaultValue, out boolToReturn); return boolToReturn; } else { return toReturn; } } else { return null; } } else { return instruction.Value; } }; instanceMember.CustomSetEvent += (owner, value) => { instanceMember.IsDefault = false; RefreshLogic.IgnoreNextRefresh(); GlueCommands.Self.GluxCommands.SetVariableOn( instance, typedMember.MemberName, memberType, value); GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.RefreshCommands.RefreshPropertyGrid(); GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode(); }; instanceMember.IsDefaultSet += (owner, args) => { MakeDefault(instance, typedMember.MemberName); }; instanceMember.SetValueError += (newValue) => { if (newValue is string && string.IsNullOrEmpty(newValue as string)) { MakeDefault(instance, typedMember.MemberName); } }; } return instanceMember; }