private void FilesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.SourceNameComboBox.Items.Clear();

            //AvailableNameablesStringConverter availabl
            List <string> availableObjects = new List <string>();

            AvailableNameablesStringConverter.FillListWithAvailableObjects(FilesTreeView.SelectedNode.Text, availableObjects);

            SourceNameComboBox.Items.AddRange(availableObjects.ToArray());

            if (AfterSelect != null)
            {
                AfterSelect(this, e);
            }
        }
Esempio n. 2
0
        private static InstanceMember CreateInstanceMemberForSourceName(NamedObjectSave instance)
        {
            var instanceMember = new FileInstanceMember();

            instanceMember.View += () =>
            {
                var element = GlueState.Self.CurrentElement;
                var rfs     = element.ReferencedFiles.FirstOrDefault(item => item.Name == instance.SourceFile);

                if (rfs != null)
                {
                    GlueCommands.Self.SelectCommands.Select(
                        rfs,
                        instance.SourceNameWithoutParenthesis);
                }
            };

            instanceMember.FirstGridLength = new System.Windows.GridLength(140);

            instanceMember.UnmodifiedVariableName = "SourceName";
            string fileName = FlatRedBall.IO.FileManager.RemovePath(instance.SourceFile);

            instanceMember.DisplayName = $"Object in {fileName}:";

            // todo: get the type converter from the file
            var typeConverter = new AvailableNameablesStringConverter(instance);

            instanceMember.TypeConverter = typeConverter;

            instanceMember.CustomGetTypeEvent += (throwaway) => typeof(string);

            instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox);

            instanceMember.IsDefault = instance.SourceName == null;

            instanceMember.CustomGetEvent += (throwaway) =>
            {
                return(instance.SourceName);
            };

            instanceMember.CustomSetEvent += (owner, value) =>
            {
                instanceMember.IsDefault = false;
                RefreshLogic.IgnoreNextRefresh();

                instance.SourceName = value as string;

                GlueCommands.Self.GluxCommands.SaveGlux();

                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
            };

            instanceMember.IsDefaultSet += (owner, args) =>
            {
                instance.SourceName = null;
            };

            instanceMember.SetValueError += (newValue) =>
            {
                if (newValue is string && string.IsNullOrEmpty(newValue as string))
                {
                    MakeDefault(instance, "SourceName");
                }
            };

            return(instanceMember);
        }
Esempio n. 3
0
        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);
        }