void CreateContainerElementRuntime() { EntitySave containerEntitySave = new EntitySave { Name = "ContainerVariableSetting" }; ObjectFinder.Self.GlueProject.Entities.Add(containerEntitySave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.InstanceName = mEntitySave.Name + "Instance"; nos.SourceClassType = mEntitySave.Name; containerEntitySave.NamedObjects.Add(nos); nos.UpdateCustomProperties(); nos.SetPropertyValue("CurrentStateSaveCategoryState", "SecondState"); mContainedElementRuntime = new ElementRuntime(containerEntitySave, null, null, null, null); // This thing is attached - we need to check its relativeX //if (mContainedElementRuntime.ContainedElements[0].X != -10.0f) if (mContainedElementRuntime.ContainedElements[0].RelativeX != -10.0f) { throw new Exception("Categorized states on contained NamedObjectSave Elements aren't setting values properly"); } }
private void CreateContainerEntitySave() { mContainerEntitySave = new EntitySave(); mContainerEntitySave.Name = "ContainerCustomVariableEntity"; mBaseNosInContainer = new NamedObjectSave(); mBaseNosInContainer.InstanceName = mEntitySave.Name + "Instance"; mBaseNosInContainer.SourceType = SourceType.Entity; mBaseNosInContainer.SourceClassType = mEntitySave.Name; mContainerEntitySave.NamedObjects.Add(mBaseNosInContainer); CustomVariable customVariable = new CustomVariable(); customVariable.Name = "TunneledCategorizedStateVariable"; customVariable.SourceObject = mBaseNosInContainer.InstanceName; customVariable.SourceObjectProperty = "CurrentStateCategoryState"; customVariable.Type = "StateCategory"; mContainerEntitySave.CustomVariables.Add(customVariable); mDerivedNosInContainer = new NamedObjectSave(); mDerivedNosInContainer.InstanceName = "DerivedNosInContainer"; mDerivedNosInContainer.SourceType = SourceType.Entity; mDerivedNosInContainer.SourceClassType = mDerivedEntitySave.Name; mDerivedNosInContainer.UpdateCustomProperties(); mContainerEntitySave.NamedObjects.Add(mDerivedNosInContainer); ObjectFinder.Self.GlueProject.Entities.Add(mContainerEntitySave); }
public void TestRelativeAbsoluteConversion() { NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.UpdateCustomProperties(); nos.InstanceName = "SpriteObject"; nos.SetPropertyValue("ScaleX", 2.0f); nos.SetPropertyValue("X", 4.0f); nos.SetPropertyValue("RotationZ", 4.0f); nos.SetPropertyValue("RotationZVelocity", 4.0f); mEntitySave.NamedObjects.Add(nos); CustomVariable customVariable = new CustomVariable(); customVariable.SourceObject = nos.InstanceName; customVariable.SourceObjectProperty = "ScaleY"; customVariable.DefaultValue = 8.0f; mEntitySave.CustomVariables.Add(customVariable); ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(mEntitySave, null, null, null, null); Sprite sprite = elementRuntime.ContainedElements[0].DirectObjectReference as Sprite; sprite.ForceUpdateDependencies(); if (elementRuntime.X != 0) { throw new Exception("NOS variables are being applied to the container instead of just to the NOS"); } if (sprite.X != 4.0f) { throw new Exception("Absolute values should get set when setting X on objects even though they're attached"); } if (sprite.RotationZ != 4.0f) { throw new Exception("Absolute values should get set when setting RotationZ on objects even though they're attached"); } if (sprite.RelativeRotationZVelocity != 4.0f) { throw new Exception("Setting RotationZVelocity should set RelativeRotationZVelocity"); } if (sprite.ScaleX != 2.0f) { throw new Exception("Scale values aren't properly showing up on Sprites"); } if (sprite.ScaleY != 8.0f) { throw new Exception("Scale values aren't properly showing up on Sprites"); } }
private void ReactToChangedSourceClassType(NamedObjectSave namedObjectSave, object oldValue) { if (namedObjectSave.SourceClassType == "<NONE>" || namedObjectSave.SourceClassType == null) { namedObjectSave.SourceClassType = (string)oldValue; namedObjectSave.UpdateCustomProperties(); } else { if (namedObjectSave.SourceType == SourceType.Entity) { EntitySave entitySave = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType); #if GLUE // If the EntitySave is null then that probably means that the Entity has been renamed and this hasn't // been pushed to the project yet. if (entitySave != null && ProjectManager.VerifyReferenceGraph(entitySave) == ProjectManager.CheckResult.Failed) { namedObjectSave.SourceClassType = (string)oldValue; } else #endif { namedObjectSave.UpdateCustomProperties(); } } else if (namedObjectSave.SourceType == SaveClasses.SourceType.FlatRedBallType) { namedObjectSave.UpdateCustomProperties(); } } if (namedObjectSave.SourceClassType != (string)oldValue) { ShowPopupsForMissingVariablesInNewType(namedObjectSave, oldValue); if (namedObjectSave.SourceClassType == "Layer") { namedObjectSave.AddToManagers = true; } } // else, we should probably do something here to revert to defaults. What a pain }
private void UpdateDerivedNosFromBase(NamedObjectSave baseNos, NamedObjectSave derivedNos) { if (baseNos.IsList && !string.IsNullOrEmpty(baseNos.SourceClassGenericType)) { derivedNos.SourceType = baseNos.SourceType; derivedNos.SourceClassType = baseNos.SourceClassType; derivedNos.SourceClassGenericType = baseNos.SourceClassGenericType; derivedNos.UpdateCustomProperties(); } }
public void UpdateNosFromArrowInstance(object instance, NamedObjectSave currentNos) { if (currentNos != null) { GeneralSaveConverter converter = mRelationshipManager.ConverterFor(instance); converter.AddVariablesForAllProperties(instance, currentNos); currentNos.UpdateCustomProperties(); } }
public void Show(ElementRuntime elementRuntime, NamedObjectSave nosToShow) { mCurrentElementRuntime = elementRuntime; if (nosToShow != null) { nosToShow.UpdateCustomProperties(); } mCurrentNos = nosToShow; mNosDisplayer.CurrentElement = GlueViewState.Self.CurrentElement; mNosDisplayer.Instance = mCurrentNos; mNosDisplayer.PropertyGrid = mPropertyGrid; }
public void TestVariableReordering() { List <NamedObjectSave> list = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(mEntitySave); if (list.Count == 0) { throw new Exception("Should have found some NamedObjects but didn't"); } CustomVariable variable = new CustomVariable(); variable.Name = "ToBeMoved"; variable.Type = "float"; mEntitySave.CustomVariables.Add(variable); mBaseNosInContainer.UpdateCustomProperties(); // Update November 28, 2012 // It's okay for this to be null // now. What matters is that the // typed members are not null. //if (mBaseNosInContainer.GetCustomVariable("ToBeMoved") == null) //{ // throw new Exception("Could not find the variable ToBeMoved in the base Entity NOS, but it should have it because the derived was given it and then Glue was told to update NOSs accordingly"); //} if (mBaseNosInContainer.TypedMembers.First(member => member.MemberName == "ToBeMoved") == null) { throw new Exception("Could not find the variable ToBeMoved in the base Entity NOS, but it should have it because the derived was given it and then Glue was told to update NOSs accordingly"); } // Now let's reorder by putting ToBeMoved at the very beginning, then make sure the NOS updates: mEntitySave.CustomVariables.Remove(variable); mEntitySave.CustomVariables.Insert(0, variable); mBaseNosInContainer.UpdateCustomProperties(); if (mBaseNosInContainer.TypedMembers[0].MemberName != variable.Name) { throw new Exception("Reordering variables in EntitySaves does not reorder the variables in NOS's that use the EntitySave and it should!"); } }
public void TestUpdateNamedObjectProperties() { mDerivedEntitySave.UpdateFromBaseType(); // Test to make sure this Entity has inherited the Y variable if (mDerivedEntitySave.CustomVariables.Count != 1) { throw new Exception("Derived Entities are not properly inheriting SetByDerived values"); } mDerivedNos.UpdateCustomProperties(); int numberOfProperties = mDerivedNos.TypedMembers.Count; // It turns out it's okay for NOSs to have null InstructionSaves // This makes XML much smaller and makes Glue more efficient in general. //if (numberOfProperties == 0) //{ // throw new Exception("NamedObjectSaves that are not getting their InstructionSaves properly set"); //} if (mDerivedEntitySave.GetTypedMembers().Count != 2) { throw new Exception("There are an invalid number of typed members for NamedObjectSaves which use Entities that have inheritance"); } // Let's switch the derived NOS to the underived, update its properties, then switch it to the derived and see if there are any problems - there shouldn't be mDerivedNos.SourceClassType = mEntitySave.Name; mDerivedNos.UpdateCustomProperties(); mDerivedNos.SourceClassType = mDerivedEntitySave.Name; string message = mDerivedNos.GetMessageWhySwitchMightCauseProblems(mEntitySave.Name); if (!string.IsNullOrEmpty(message)) { throw new Exception("GetMessageWhySwitchMightCauseProblems is incorrectly reporting problems. Reported problems:\n" + message); } }
public static void UpdateShownVariables(DataUiGrid grid, NamedObjectSave instance, IElement container) { grid.Categories.Clear(); List <MemberCategory> categories = new List <MemberCategory>(); var defaultCategory = new MemberCategory("Variables"); defaultCategory.FontSize = 14; categories.Add(defaultCategory); AssetTypeInfo ati = instance.GetAssetTypeInfo(); // not sure if this is needed: if (instance.TypedMembers.Count == 0) { instance.UpdateCustomProperties(); } CreateCategoriesAndVariables(instance, container, categories, ati); if (ati != null) { SortCategoriesAndMembers(ref categories, ati); } if (defaultCategory.Members.Count == 0) { categories.Remove(defaultCategory); } else if (categories.Count != 1) { defaultCategory.Name = "Other Variables"; } if (categories.Count != 0) { // "Name" should be the very first property: var nameCategory = CreateNameInstanceMember(instance); categories.Insert(0, nameCategory); } SetAlternatingColors(grid, categories); foreach (var category in categories) { grid.Categories.Add(category); } grid.Refresh(); }
private void CreateScreenSave() { mScreenSave = new ScreenSave(); mScreenSave.Name = "ScreenSaveInVariableSettingTest"; ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.SourceClassType = mEntitySave.Name; nos.UpdateCustomProperties(); nos.InstanceName = "TestObject1"; nos.SetPropertyValue("X", 150); mScreenSave.NamedObjects.Add(nos); }
private void CreateNamedObjectWithSetVariable() { mNamedObjectWithSetVariable = new NamedObjectSave(); mNamedObjectWithSetVariable.InstanceName = "SpriteObject"; // This will be complicated because it requires FRB to be instantiated! //mNamedObjectWithSetVariable.SourceType = SourceType.File; //mNamedObjectWithSetVariable.SourceFile = "Entities/StateTestEntity/SceneFile.scnx"; //mNamedObjectWithSetVariable.SourceName = "Untextured (Sprite)"; mNamedObjectWithSetVariable.SourceType = SourceType.FlatRedBallType; mNamedObjectWithSetVariable.SourceClassType = "Sprite"; mNamedObjectWithSetVariable.UpdateCustomProperties(); mNamedObjectWithSetVariable.SetPropertyValue("Y", 10.0f); mEntitySave.NamedObjects.Add(mNamedObjectWithSetVariable); }
public void TestSetPropertyValue() { NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.UpdateCustomProperties(); nos.SetPropertyValue("Texture", "redball"); if (nos.InstructionSaves.Count == 0) { throw new Exception("There should be a Texture instruction save"); } if (nos.InstructionSaves.First(instruction => instruction.Member == "Texture").Type != "Texture2D") { throw new Exception("The instruction should be of type Texture2D, but it's not"); } }
void CreateParentElementRuntime() { EntitySave containerEntity = new EntitySave(); ObjectFinder.Self.GlueProject.Entities.Add(containerEntity); containerEntity.Name = "ContainerEntity"; NamedObjectSave first = new NamedObjectSave(); first.SourceType = SourceType.Entity; first.SourceClassType = "ExpressionParserTestEntity"; first.InstanceName = "FirstObject"; first.UpdateCustomProperties(); first.SetPropertyValue("CsvTypeVariable", "CsvValue1"); containerEntity.NamedObjects.Add(first); mParentElementRuntime = new ElementRuntime( containerEntity, null, null, null, null); }
private void ShowPopupsForMissingVariablesInNewType(NamedObjectSave namedObjectSave, object oldValue) { if (namedObjectSave.SourceType == SourceType.Entity) { string oldType = (string)oldValue; string message = namedObjectSave.GetMessageWhySwitchMightCauseProblems(oldType); if (message != null) { message += "\nDo you want to change to " + namedObjectSave.SourceClassType + " anyway?"; DialogResult result = MessageBox.Show(message, "Change anyway?", MessageBoxButtons.YesNo); if (result == DialogResult.No) { namedObjectSave.SourceClassType = (string)oldValue; namedObjectSave.UpdateCustomProperties(); } } } }
private void ReactToSourceClassGenericType(NamedObjectSave namedObjectSave, object oldValue) { namedObjectSave.UpdateCustomProperties(); if (ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassGenericType) != null) { namedObjectSave.AddToManagers = true; } var baseNos = namedObjectSave; var element = EditorLogic.CurrentElement; if (baseNos.SetByDerived) { List <IElement> derivedElements = new List <IElement>(); if (element is EntitySave) { derivedElements.AddRange(ObjectFinder.Self.GetAllEntitiesThatInheritFrom(element as EntitySave)); } else { derivedElements.AddRange(ObjectFinder.Self.GetAllScreensThatInheritFrom(element as ScreenSave)); } foreach (IElement derivedElement in derivedElements) { NamedObjectSave derivedNos = derivedElement.GetNamedObjectRecursively(baseNos.InstanceName); if (derivedNos != baseNos) { UpdateDerivedNosFromBase(baseNos, derivedNos); } } } ProjectManager.UpdateAllDerivedElementFromBaseValues(false, true); }
void CreateElementRuntime(string name) { var entitySave = new EntitySave { Name = name }; ObjectFinder.Self.GlueProject.Entities.Add(entitySave); #region Create CustomVariables var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = 3.0f }; entitySave.CustomVariables.Add(xVariable); var yVariable = new CustomVariable { Name = "Y", Type = "float", DefaultValue = 4.0f }; entitySave.CustomVariables.Add(yVariable); var customVariable = new CustomVariable { Name = "SomeNewVar", Type = "double", DefaultValue = 3.333 }; entitySave.CustomVariables.Add(customVariable); var csvTypeVAriable = new CustomVariable { Name = "CsvTypeVariable", Type = "CsvType.csv", DefaultValue = null }; entitySave.CustomVariables.Add(csvTypeVAriable); var csvTypeVariable2 = new CustomVariable { Name = "EnemyInfoVariable", Type = "EnemyInfo.csv", DefaultValue = "Imp" }; entitySave.CustomVariables.Add(csvTypeVariable2); var scaleXVariable = new CustomVariable { Name = "ScaleX", Type = "float", DefaultValue = 10.0f }; entitySave.CustomVariables.Add(scaleXVariable); #endregion #region Create the NamedObjectsSave NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.InstanceName = "SpriteObject"; nos.UpdateCustomProperties(); nos.SetPropertyValue("ScaleX", 3.0f); entitySave.NamedObjects.Add(nos); #endregion #region Create the ReferencedFileSaves ReferencedFileSave rfs = new ReferencedFileSave(); rfs.Name = "Content/Entities/ReferencedFileSaveTestsBaseEntity/SceneFile.scnx"; entitySave.ReferencedFiles.Add(rfs); rfs = new ReferencedFileSave(); rfs.Name = "Content/EnemyInfo.csv"; rfs.CreatesDictionary = true; entitySave.ReferencedFiles.Add(rfs); #endregion mElementRuntime = new ElementRuntime() { X = (float)xVariable.DefaultValue, Y = (float)yVariable.DefaultValue }; mElementRuntime.Initialize(entitySave, null, null, null, null); #region Create the uncategorized states var leftX = new InstructionSave { Member = "X", Value = -10, Type = "float" }; var rightX = new InstructionSave { Member = "X", Value = 10, Type = "float" }; var someNewVarSetLeft = new InstructionSave { Member = "SomeNewVar", Value = -10.0, Type = "double" }; var someNewVarSetRight = new InstructionSave { Member = "SomeNewVar", Value = 10.0, Type = "double" }; var leftState = new StateSave { Name = "Left" }; leftState.InstructionSaves.Add(leftX); leftState.InstructionSaves.Add(someNewVarSetLeft); var rightState = new StateSave { Name = "Right" }; rightState.InstructionSaves.Add(rightX); rightState.InstructionSaves.Add(someNewVarSetRight); entitySave.States.Add(leftState); entitySave.States.Add(rightState); #endregion #region Create the categorized states StateSaveCategory category = new StateSaveCategory(); category.SharesVariablesWithOtherCategories = false; category.Name = "StateCategory"; var topY = new InstructionSave { Member = "Y", Value = 10, Type = "float" }; var bottomY = new InstructionSave { Member = "Y", Value = 10, Type = "float" }; var topState = new StateSave { Name = "Top" }; topState.InstructionSaves.Add(topY); var bottomState = new StateSave { Name = "Bottom" }; bottomState.InstructionSaves.Add(rightX); category.States.Add(topState); category.States.Add(bottomState); entitySave.StateCategoryList.Add(category); #endregion }
internal static NamedObjectSave CreateNewNamedObjectInElement(IElement elementToCreateIn, EntitySave blueprintEntity, bool createList = false) { if (blueprintEntity == null) { throw new ArgumentNullException($"{nameof(blueprintEntity)} cannot be null"); } if (elementToCreateIn is EntitySave && ((EntitySave)elementToCreateIn).ImplementsIVisible && !blueprintEntity.ImplementsIVisible) { MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = "The Entity\n\n" + blueprintEntity + "\n\nDoes not Implement IVisible, but the Entity it is being dropped in does. " + "What would you like to do?"; mbmb.AddButton("Make " + blueprintEntity.Name + " implement IVisible", DialogResult.OK); mbmb.AddButton("Nothing (your code will not compile until this problem is resolved manually)", DialogResult.Cancel); DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self); if (result == DialogResult.OK) { blueprintEntity.ImplementsIVisible = true; CodeGeneratorIElement.GenerateElementDerivedAndReferenced(blueprintEntity); } } BaseElementTreeNode elementTreeNode = GlueState.Self.Find.ElementTreeNode(elementToCreateIn); //EntityTreeNode entityTreeNode = // ElementViewWindow.GetEntityTreeNode(entityToCreateIn); NamedObjectSave newNamedObject = new NamedObjectSave(); // We'll add "List" or "Instance" below string newName = FileManager.RemovePath(blueprintEntity.Name); #region Set the source type properties for the new NamedObject if (createList) { newName += "List"; newNamedObject.SourceType = SourceType.FlatRedBallType; newNamedObject.SourceClassType = "PositionedObjectList<T>"; newNamedObject.SourceClassGenericType = blueprintEntity.Name; newNamedObject.UpdateCustomProperties(); } else { newName += "Instance"; newNamedObject.SourceType = SourceType.Entity; newNamedObject.SourceClassType = blueprintEntity.Name; newNamedObject.UpdateCustomProperties(); } #endregion #region Set the name for the new NamedObject // get an acceptable name for the new object if (elementToCreateIn.GetNamedObjectRecursively(newName) != null) { newName += "2"; } while (elementToCreateIn.GetNamedObjectRecursively(newName) != null) { newName = StringFunctions.IncrementNumberAtEnd(newName); } newNamedObject.InstanceName = newName; #endregion // We need to add to managers here. Why? Because normally when the type of a NamedObject is changed, // the PropertyGrid handles setting whether it should be added or not. But in this case, we're not changing // the type of the new NamedObject through the PropertyGrid - instead it's being set programatically to be an // Entity. So, we should add to managers programatically since the PropertyGrid won't do it for us. // Update December 11, 2011 // AddToManagers defaults to // true on new NamedObjectSaves // so there's no need to explicitly // set it to true here. //newNamedObject.AddToManagers = true; NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectToElementTreeNode(elementTreeNode, newNamedObject, true); Plugins.PluginManager.ReceiveOutput($"Created {newNamedObject}"); return(newNamedObject); }
public void ReactToNamedObjectChangedValue(string changedMember, string parent, object oldValue) { string combinedMember; if (string.IsNullOrEmpty(parent)) { combinedMember = changedMember; } else { combinedMember = parent + "." + changedMember; } NamedObjectSave namedObjectSave = EditorLogic.CurrentNamedObject; IElement element = EditorLogic.CurrentElement; if (PropertiesToMethods.ContainsKey(changedMember)) { PropertiesToMethods[changedMember](namedObjectSave, oldValue); } #region SourceType changed else if (changedMember == "SourceType") { bool didErrorOccur = false; if (didErrorOccur) { namedObjectSave.SourceType = (SourceType)oldValue; } else { if (namedObjectSave.SourceType == SourceType.Entity) { namedObjectSave.AddToManagers = true; } else if (namedObjectSave.SourceType == SourceType.File && namedObjectSave.GetContainerType() == ContainerType.Screen) { namedObjectSave.AddToManagers = false; } } } #endregion #region SourceClassType changed else if (changedMember == "SourceClassType") { ReactToChangedSourceClassType(namedObjectSave, oldValue); } #endregion #region SourceFile changed else if (changedMember == "SourceFile") { if (namedObjectSave.SourceFile != (string)oldValue) { // See if the current SourceName is valid or not List <string> availableSourceNames = AvailableNameablesStringConverter.GetAvailableNamedObjectSourceNames(namedObjectSave); bool isSourceNameValid = availableSourceNames.Contains(namedObjectSave.SourceName); if (!isSourceNameValid) { namedObjectSave.SourceName = "<NONE>"; } } } #endregion #region SourceName else if (changedMember == "SourceName") { // This needs to happen before we update custom properties ReactToChangedNosSourceName(namedObjectSave, oldValue as string); namedObjectSave.UpdateCustomProperties(); } #endregion #region InstanceName changed else if (changedMember == "InstanceName") { ReactToNamedObjectChangedInstanceName(namedObjectSave, oldValue); } #endregion #region SetByDerived Changed else if (changedMember == "SetByDerived") { if (namedObjectSave.SourceType == SourceType.Entity && !string.IsNullOrEmpty(namedObjectSave.SourceClassType)) { if (ProjectManager.VerifyReferenceGraph(ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType)) == ProjectManager.CheckResult.Failed) { namedObjectSave.SetByDerived = !namedObjectSave.SetByDerived; } } if (namedObjectSave.SetByDerived && namedObjectSave.ExposedInDerived) { // The user has just set SetByDerived to true, but ExposedInDerived means that // the derived expects that the base instantiates. We need to tell the user that // both values can't be true at the same time, and that ExposedInDerived will be set // to false. MessageBox.Show("You have set SetByDerived to true, but ExposedInDerived is also true. Both cannot be true at the same time " + "so Glue will set ExposedInDerived to false."); namedObjectSave.ExposedInDerived = false; } if (namedObjectSave.SourceType == SourceType.FlatRedBallType && namedObjectSave.IsList && namedObjectSave.SetByDerived == true && namedObjectSave.ContainedObjects.Count != 0) { MessageBox.Show("This list is not empty, so it can't be set to \"Set By Derived\". You must first empty the list", "Invalid Setting"); namedObjectSave.SetByDerived = false; } else { ProjectManager.UpdateAllDerivedElementFromBaseValues(false, true); } } #endregion #region ExposedInDerived Changed else if (changedMember == "ExposedInDerived") { if (namedObjectSave.SetByDerived && namedObjectSave.ExposedInDerived) { // See comment in ExposedByDerived block on why this occurs MessageBox.Show("You have set ExposedInDerived to true, but SetByDerived is also true. Both cannot be true at the same time " + "so Glue will set SetByDerived to false."); namedObjectSave.SetByDerived = false; } SetExposedByDerivedRecursively(namedObjectSave, oldValue); ProjectManager.UpdateAllDerivedElementFromBaseValues(false, true); } #endregion #region SourceClassGenericType else if (changedMember == "SourceClassGenericType") { ReactToSourceClassGenericType(namedObjectSave, oldValue); } #endregion #region IsDisabled else if (changedMember == "IsDisabled") { GlueState.Self.Find.ElementTreeNode(EditorLogic.CurrentElement).UpdateReferencedTreeNodes(); } #endregion #region SetByContainer Changed else if (changedMember == "SetByContainer") { if (namedObjectSave.SourceType == SourceType.Entity && !string.IsNullOrEmpty(namedObjectSave.SourceClassType)) { if (ProjectManager.VerifyReferenceGraph(ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType)) == ProjectManager.CheckResult.Failed) { namedObjectSave.SetByContainer = !namedObjectSave.SetByContainer; } } List <IElement> derivedElements = ObjectFinder.Self.GetAllElementsThatInheritFrom( EditorLogic.CurrentElement.Name); foreach (IElement derived in derivedElements) { foreach (NamedObjectSave nos in derived.NamedObjects) { if (nos.InstanceName == namedObjectSave.InstanceName) { nos.SetByContainer = namedObjectSave.SetByContainer; } } } if (EditorLogic.CurrentEntitySave != null) { List <NamedObjectSave> entityNamedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(EditorLogic.CurrentEntitySave.Name); foreach (NamedObjectSave nos in entityNamedObjects) { nos.UpdateCustomProperties(); } } } #endregion #region AddToManagers Changed else if (changedMember == "AddToManagers") { if (namedObjectSave.AddToManagers && namedObjectSave.GetContainerType() == ContainerType.Screen && namedObjectSave.SourceType == SourceType.File) { ScreenSave screenSave = namedObjectSave.GetContainer() as ScreenSave; ReferencedFileSave rfs = screenSave.GetReferencedFileSave(namedObjectSave.SourceFile); if (rfs != null && !rfs.IsSharedStatic) { System.Windows.Forms.MessageBox.Show("This object comes from a file. Files which are part of Screens " + "are automatically added to the engine managers. " + "Adding this object would result in double-membership in the engine which may cause unexpected results. " + "\n\nGlue will now set this value back to false."); namedObjectSave.AddToManagers = false; } } } #endregion #region LayerOn else if (changedMember == "LayerOn") { if (namedObjectSave.IsList) { DialogResult result = DialogResult.No; if (string.IsNullOrEmpty(namedObjectSave.LayerOn)) { result = MessageBox.Show("Do you want to remove every object in the List " + namedObjectSave.InstanceName + " from its Layer?", "Remove all from Layer?", MessageBoxButtons.YesNo); } else { result = MessageBox.Show("Do you want to add every object contained in the List " + namedObjectSave.InstanceName + " to the Layer " + namedObjectSave.LayerOn + "?", "Add all to Layer?", MessageBoxButtons.YesNo); } if (result == DialogResult.Yes) { namedObjectSave.SetLayerRecursively(namedObjectSave.LayerOn); } } } #endregion #region IsContainer else if (changedMember == "IsContainer") { HandleChangedIsContainer(namedObjectSave, element); } #endregion #region AttachToCamera else if (changedMember == "AttachToCamera") { if (namedObjectSave.IsList) { DialogResult result = DialogResult.No; if (namedObjectSave.AttachToCamera) { result = MessageBox.Show("Do you want to attach every object contained in the list " + namedObjectSave.InstanceName + " to the Camera?", "Attach all to Camera?", MessageBoxButtons.YesNo); } else { result = MessageBox.Show("Do you want to detach every object contained in the list " + namedObjectSave.InstanceName + " from the Camera?", "Detach all from the Camera?", MessageBoxButtons.YesNo); } if (result == DialogResult.Yes) { namedObjectSave.SetAttachToCameraRecursively(namedObjectSave.AttachToCamera); } } } #endregion #region DestinationRectangle.Y (for Layers) else if (parent == "DestinationRectangle" && changedMember == "Y") { // If the Y is odd, we should warn the user that it should be even // or else text will draw incorrectly if (namedObjectSave.DestinationRectangle.HasValue && namedObjectSave.DestinationRectangle.Value.Y % 2 == 1) { MessageBox.Show("Setting an odd value to the DestinationRectangle's Y may cause text to render improperly. An " + "even value is recommended"); } } #endregion #region RemoveFromManagersWhenInvisible else if (changedMember == "RemoveFromManagersWhenInvisible") { // is this an Entity instance? if (namedObjectSave.SourceType == SourceType.Entity && namedObjectSave.RemoveFromManagersWhenInvisible) { var entitySave = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType); if (entitySave != null) { // Is this CreatedByOtherEntities? if (!entitySave.CreatedByOtherEntities) { MessageBox.Show("The Entity " + entitySave + " should have its CreatedByOtherEntities set to true to enable " + "visibility-based removal to work properly"); } } } } #endregion else if (namedObjectSave?.GetCustomVariable(changedMember) != null) { // See if this variable is tunneled into in this element. // If so, set that value too. CustomVariableInNamedObject cvino = namedObjectSave.GetCustomVariable(changedMember); object value = cvino.Value; foreach (CustomVariable customVariable in EditorLogic.CurrentElement.CustomVariables) { if (customVariable.SourceObject == namedObjectSave.InstanceName && customVariable.SourceObjectProperty == changedMember) { // The custom variable may have a different type: if (!string.IsNullOrEmpty(customVariable.OverridingPropertyType)) { // it does, so convert Type overridingType = TypeManager.GetTypeFromString(customVariable.OverridingPropertyType); customVariable.DefaultValue = System.Convert.ChangeType(value, overridingType); } else { customVariable.DefaultValue = value; } break; } } } // If we changed BitmapFont and if the NOS is marked as PixelPerfect // and if it's a Text object, then we should set the Scale, Spacing, and // NewLineDistance according to the set BitmapFont // We don't do an else because there could be a CustomVariable by the name // of BitmapFont as well, and we dont' want to eliminate that. if (changedMember == "Font" && namedObjectSave.SourceType == SourceType.FlatRedBallType && namedObjectSave.SourceClassType == "Text" && namedObjectSave.IsPixelPerfect) { ReactToFontSet(namedObjectSave, oldValue); } PropertyGridHelper.UpdateNamedObjectDisplay(); PluginManager.ReactToNamedObjectChangedValue(changedMember, oldValue); }
private void ReactToChangedNosSourceName(NamedObjectSave namedObjectSave, string oldValue) { IElement container = EditorLogic.CurrentElement; if (!string.IsNullOrEmpty(container.BaseElement) && !string.IsNullOrEmpty(namedObjectSave.InstanceType)) { IElement baseElement = ObjectFinder.Self.GetIElement(container.BaseElement); NamedObjectSave namedObjectInBase = baseElement.GetNamedObjectRecursively(namedObjectSave.InstanceName); if (namedObjectInBase == null) { // This is not a valid setup - what do we do here? } else { if (namedObjectInBase.InstanceType != namedObjectSave.InstanceType) { if (string.IsNullOrEmpty(namedObjectInBase.InstanceType)) { string message = "This object has type of " + namedObjectSave.InstanceType + " but the base object in " + baseElement.ToString() + " is untyped. What would you like to do?"; MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = message; mbmb.AddButton("Change " + namedObjectInBase.InstanceName + " to " + namedObjectSave.InstanceType + " in " + baseElement.ToString(), DialogResult.Yes); mbmb.AddButton("Do nothing (your project will likely not compile so you will need to fix this manually)", DialogResult.No); DialogResult result = mbmb.ShowDialog(); if (result == DialogResult.Yes) { switch (namedObjectInBase.SourceType) { case SourceType.File: // The base needs to be a FlatRedBallType namedObjectInBase.SourceType = SourceType.FlatRedBallType; namedObjectInBase.SourceClassType = namedObjectSave.InstanceType; break; case SourceType.FlatRedBallType: namedObjectInBase.SourceType = SourceType.FlatRedBallType; namedObjectInBase.SourceClassType = namedObjectSave.SourceClassType; break; case SourceType.Entity: namedObjectInBase.SourceType = SourceType.Entity; namedObjectInBase.SourceClassType = namedObjectSave.SourceClassType; break; } namedObjectInBase.UpdateCustomProperties(); CodeWriter.GenerateCode(baseElement); } } else { string message = "This object is of type " + namedObjectSave.InstanceType + " but the base " + "object is of type " + namedObjectInBase.InstanceType + ""; MessageBox.Show(message); namedObjectSave.SourceName = oldValue; } } } } }