Пример #1
0
        internal void SetVariable(ElementSave gumElement, GumInstance gumInstance, string variableName, object oldValue, bool save = true)
        {
            var glueProject = GluePluginState.Self.GlueProject;

            ///////////////////////Early Out///////////////////////
            if (glueProject == null || GluePluginState.Self.InitializationState != InitializationState.Initialized)
            {
                return;
            }
            ////////////////////End Early Out/////////////////////


            var shouldApplyValue = GetIfShouldApplyValue(gumElement, gumInstance, variableName);

            if (shouldApplyValue)
            {
                ApplyChangedVariable(gumElement, gumInstance, variableName, glueProject, save);
            }
            else
            {
                var currentState = SelectedState.Self.SelectedStateSave;

                currentState.SetValue($"{gumInstance.Name}.{variableName}", oldValue, "string");
            }
        }
Пример #2
0
 public static object GetCurrentValueForVariable(string baseVariableName, InstanceSave instanceSave)
 {
     string throwaway;
     object currentValueAsObject;
     GetCurrentValueForVariable(baseVariableName, instanceSave, out throwaway, out currentValueAsObject);
     return currentValueAsObject;
 }
Пример #3
0
        private void CreateTextInScreen()
        {
            mTextInScreen = new InstanceSave();
            mTextInScreen.Name = mElements.Button.Instances[0].Name;
            mTextInScreen.BaseType = "Text";

            mElements.Screen.Instances.Add(mTextInScreen);
        }
Пример #4
0
        public static List<string> GetAvailableStates(InstanceSave instanceSave, string categoryName)
        {
            ElementSave elementSave = ObjectFinder.Self.GetElementSave(instanceSave.BaseType);

            List<string> toReturn = GetAvailableStates(elementSave, categoryName);

            return toReturn;
        }
Пример #5
0
        public bool IsInstanceNameValid(string instanceName, InstanceSave instanceSave, ElementSave elementSave, out string whyNotValid)
        {
            IsNameValidCommon(instanceName, out whyNotValid);

            if (string.IsNullOrEmpty(whyNotValid))
            {
                IsNameAlreadyUsed(instanceName, instanceSave, elementSave, out whyNotValid);
            }
            return string.IsNullOrEmpty(whyNotValid);
        }
        public StateReferencingInstanceMember(InstanceSavePropertyDescriptor ispd, StateSave stateSave, 
            string variableName, InstanceSave instanceSave, ElementSave elementSave)
            : base(variableName, stateSave)
        {
            mInstanceSave = instanceSave;
            mStateSave = stateSave;
            mVariableName = variableName;
            mPropertyDescriptor = ispd;
            mElementSave = elementSave;
            this.CustomGetEvent += GetEvent;
            this.CustomSetEvent += SetEvent;
            this.CustomGetTypeEvent += GetTypeEvent;

            this.SortValue = int.MaxValue;

            if (instanceSave != null)
            {
                this.Instance = instanceSave;
            }
            else
            {
                this.Instance = elementSave;
            }

            DisplayName = RootVariableName;

            TryAddExposeVariableMenuOptions(instanceSave);

            // This could be slow since we have to check it for every variable in an object.
            // Maybe we'll want to pass this in to the function?
            StandardElementSave standardElement = null;
            if (instanceSave != null)
            {
                standardElement = ObjectFinder.Self.GetRootStandardElementSave(instanceSave);
            }
            else
            {
                standardElement = ObjectFinder.Self.GetRootStandardElementSave(elementSave);
            }

            VariableSave standardVariable = null;

            if (standardElement != null)
            {
                standardVariable = standardElement.DefaultState.Variables.FirstOrDefault(item => item.Name == RootVariableName);
            }

            if (standardVariable != null)
            {
                this.SortValue = standardVariable.DesiredOrder;
            }
        }
Пример #7
0
        private bool GetIfShouldApplyValue(ElementSave gumElement, GumInstance gumInstance, string variableName)
        {
            var shouldApply = true;

            if (variableName == "Parent" && gumInstance != null)
            {
                var currentState = SelectedState.Self.SelectedStateSave;

                var newParentName = currentState.GetValueOrDefault <string>($"{gumInstance.Name}.Parent");

                GumInstance newGumParent = null;
                var         glueElement  = GluePluginObjectFinder.Self.GetGlueElementFrom(gumElement);

                var glueInstance = glueElement?.AllNamedObjects.FirstOrDefault(item => item.InstanceName == gumInstance.Name);
                FlatRedBall.Glue.SaveClasses.NamedObjectSave newGlueInstanceParent = null;

                if (!string.IsNullOrEmpty(newParentName))
                {
                    newGumParent = gumElement.GetInstance(newParentName);

                    newGlueInstanceParent =
                        glueElement?.AllNamedObjects.FirstOrDefault(item => item.FieldName == newParentName);
                }

                if (newGumParent != null)
                {
                    if (newGlueInstanceParent?.SourceType == FlatRedBall.Glue.SaveClasses.SourceType.FlatRedBallType &&
                        newGlueInstanceParent.SourceClassType == "ShapeCollection")
                    {
                        var canBeParent = glueInstance?.SourceType == FlatRedBall.Glue.SaveClasses.SourceType.FlatRedBallType &&
                                          (
                            glueInstance.SourceClassType == "Circle" ||
                            glueInstance.SourceClassType == "FlatRedBall.Math.Geometry.Circle" ||
                            glueInstance.SourceClassType == "AxisAlignedRectangle" ||
                            glueInstance.SourceClassType == "FlatRedBall.Math.Geometry.AxisAlignedRectangle" ||
                            glueInstance.SourceClassType == "Polygon" ||
                            glueInstance.SourceClassType == "FlatRedBall.Math.Geometry.Polygon"
                                          );

                        shouldApply = canBeParent;
                    }
                    else
                    {
                        var canNewParentBeParent = newGumParent.BaseType == "Container";

                        shouldApply = canNewParentBeParent;
                    }
                }
            }

            return(shouldApply);
        }
Пример #8
0
        public InstanceSave AddInstance(ElementSave elementToAddTo, string name)
        {
            if (elementToAddTo == null)
            {
                throw new Exception("Could not add instance named " + name + " because no element is selected");
            }

            InstanceSave instanceSave = new InstanceSave();
            instanceSave.Name = name;
            instanceSave.ParentContainer = elementToAddTo;
            instanceSave.BaseType = StandardElementsManager.Self.DefaultType;
            elementToAddTo.Instances.Add(instanceSave);

            return instanceSave;
        }
        private NamedObjectSave CreateNosFor(InstanceSave instance, IElement container)
        {

            NamedObjectSave nos = new NamedObjectSave();

            string name = instance.Name;

            // See if this name is already used by RFS's
            var allRfss = container.GetAllReferencedFileSavesRecursively();
            while (allRfss.Any(item => item.GetInstanceName() == name) || container.ReferencedFiles.Any(item => item.Name == name))
            {
                name = name + instance.BaseType;
            }

            nos.InstanceName = name;
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);
            if (instance.BaseType == "Sprite")
            {
                nos.SourceType = SourceType.FlatRedBallType;
                nos.SourceClassType = "Sprite";

                float width = rvf.GetValue<float>("Width");
                float height = rvf.GetValue<float>("Height");

                if (width == 0 && height == 0)
                {
                    nos.SetPropertyValue("TextureScale", 1.0f);
                }
                else
                {
                    // Eventually handle width/height
                    nos.SetPropertyValue("Width", width);
                    nos.SetPropertyValue("Height", height);
                }

                SetPositionValuesOn(nos, instance);

                string texture = rvf.GetValue<string>("SourceFile");

                string fileInstanceName = FileManager.RemoveExtension(FileManager.RemovePath(texture));

                var added = nos.SetPropertyValue("Texture", fileInstanceName);
                added.Type = "Texture2D";
            }
            return nos;
        }
Пример #10
0
        public EventInstanceMember(ElementSave element, InstanceSave instance, EventSave eventSave)
        {
            mElementSave = element;
            mEventSave = eventSave;
            if (!string.IsNullOrEmpty(eventSave.ExposedAsName))
            {
                this.Name = eventSave.ExposedAsName;
            }
            else
            {
                this.Name = eventSave.Name;
            }

            if (instance != null)
            {
                this.DisplayName = eventSave.GetRootName();
            }

            this.CustomSetEvent += HandlePropertyChanged;
            this.CustomGetEvent += HandlePropertyGet;
            this.CustomGetTypeEvent += HandleGetType;
        }
Пример #11
0
        private static void ApplyChangedVariable(ElementSave gumElement, GumInstance gumInstance, string variableName, FlatRedBall.Glue.SaveClasses.GlueProjectSave glueProject, bool save)
        {
            var glueElement = GluePluginObjectFinder.Self.GetGlueElementFrom(gumElement);


            /////////////////// early out
            if (glueElement == null)
            {
                return;
            }
            ///////////////endn early out

            var fullVariableName = variableName;

            FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos = null;

            if (gumInstance != null)
            {
                fullVariableName = $"{gumInstance.Name}.{variableName}";
                foundNos         = glueElement.AllNamedObjects
                                   .FirstOrDefault(item => item.InstanceName == gumInstance.Name);
            }
            var gumValue = gumElement.GetValueFromThisOrBase(fullVariableName);

            if (foundNos != null)
            {
                var handled = TryHandleAssigningMultipleVariables(gumElement, gumInstance, variableName, glueElement, foundNos, gumValue);

                if (!handled)
                {
                    HandleIndividualVariableAssignment(gumElement, gumInstance, variableName, glueElement, foundNos, gumValue);
                }
            }

            if (save)
            {
                FileManager.XmlSerialize(glueProject, GluePluginState.Self.GlueProjectFilePath.StandardizedCaseSensitive);
            }
        }
Пример #12
0
        private static void HandleIndividualVariableAssignment(ElementSave gumElement, GumInstance gumInstance, string variableName, GlueElement glueElement, FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos, object gumValue)
        {
            var gumToGlueConverter = GumToGlueConverter.Self;
            var glueVariableName   = gumToGlueConverter.ConvertVariableName(variableName, gumInstance);
            var glueValue          = gumToGlueConverter
                                     .ConvertVariableValue(variableName, gumValue, gumInstance);
            var type = gumToGlueConverter.ConvertType(variableName, gumValue, gumInstance);

            var handled = gumToGlueConverter.ApplyGumVariableCustom(gumInstance, gumElement, glueVariableName, glueValue);

            if (!handled)
            {
                var selectedGumState = SelectedState.Self.SelectedStateSave;
                if (selectedGumState == SelectedState.Self.SelectedElement?.DefaultState)
                {
                    var glueVariable = foundNos.SetVariableValue(glueVariableName, glueValue);

                    glueVariable.Type = type;
                }
                else
                {
                    GlueState glueState;

                    glueState = GetOrCreateGlueState(glueElement, selectedGumState);

                    if (gumInstance != null)
                    {
                        // The only way Glue states can set this value is to have a tunneled variable, so we gotta look for that
                        var tunneledVariable = glueElement.CustomVariables
                                               .FirstOrDefault(item => item.SourceObject == gumInstance.Name && item.SourceObjectProperty == glueVariableName);

                        if (tunneledVariable == null)
                        {
                            tunneledVariable                      = new FlatRedBall.Glue.SaveClasses.CustomVariable();
                            tunneledVariable.Name                 = gumInstance.Name + glueVariableName;
                            tunneledVariable.DefaultValue         = null;
                            tunneledVariable.SourceObject         = gumInstance.Name;
                            tunneledVariable.SourceObjectProperty = glueVariableName;
                            tunneledVariable.Type                 = type;

                            glueElement.CustomVariables.Add(tunneledVariable);
                        }

                        var stateVariable = glueState.InstructionSaves.FirstOrDefault(item => item.Member == tunneledVariable.Name);

                        if (stateVariable == null)
                        {
                            stateVariable        = new FlatRedBall.Content.Instructions.InstructionSave();
                            stateVariable.Member = tunneledVariable.Name;
                            glueState.InstructionSaves.Add(stateVariable);
                        }

                        stateVariable.Value = glueValue;
                    }
                    else
                    {
                        var stateVariable = glueState.InstructionSaves.FirstOrDefault(item => item.Member == glueVariableName);

                        if (stateVariable == null)
                        {
                            stateVariable        = new FlatRedBall.Content.Instructions.InstructionSave();
                            stateVariable.Member = glueVariableName;
                            glueState.InstructionSaves.Add(stateVariable);
                        }

                        stateVariable.Value = glueValue;
                    }
                }
            }
        }
Пример #13
0
        public static TypeConverter GetTypeConverter(this VariableSave variableSave, ElementSave container = null)
        {
            ElementSave       categoryContainer;
            StateSaveCategory category;

            if (variableSave.CustomTypeConverter != null)
            {
                return(variableSave.CustomTypeConverter);
            }
            else if (variableSave.IsFont)
            {
                return(new FontTypeConverter());
            }
            else if (variableSave.Name == "Guide")
            {
                AvailableGuidesTypeConverter availableGuidesTypeConverter = new AvailableGuidesTypeConverter();
                availableGuidesTypeConverter.GumProjectSave = ObjectFinder.Self.GumProjectSave;
                availableGuidesTypeConverter.ShowNewGuide   = false;
                return(availableGuidesTypeConverter);
            }
            else if (variableSave.IsState(container, out categoryContainer, out category))
            {
                string categoryName = null;

                if (category != null)
                {
                    categoryName = category.Name;
                }

                AvailableStatesConverter converter = new AvailableStatesConverter(categoryName);
                converter.ElementSave = categoryContainer;
                return(converter);
            }
            else
            {
                // We should see if it's an exposed variable, and if so, let's look to the source object's type converters
                bool foundInRoot = false;
                if (!string.IsNullOrEmpty(variableSave.SourceObject) && container != null)
                {
                    InstanceSave instance = container.GetInstance(variableSave.SourceObject);

                    if (instance != null)
                    {
                        // see if the instance has a variable
                        var foundElementSave = ObjectFinder.Self.GetRootStandardElementSave(instance);

                        if (foundElementSave != null)
                        {
                            VariableSave rootVariableSave = foundElementSave.DefaultState.GetVariableSave(variableSave.GetRootName());

                            if (rootVariableSave != null)
                            {
                                return(rootVariableSave.GetTypeConverter((ElementSave)null));
                            }
                        }
                    }
                }
            }
            Type type = variableSave.GetRuntimeType();

            return(variableSave.GetTypeConverter(type));
        }
        private static VariableSave TryGetVariableFromStatesOnInstance(InstanceSave instance, string variable, ElementSave instanceBase, IEnumerable<StateSave> statesToPullFrom)
        {

            string stateVariableName;
            StateSave fallbackState;
            List<StateSave> statesToLoopThrough;

            VariableSave foundVariableSave = null;

            foreach (var stateCategory in instanceBase.Categories)
            {
                stateVariableName = stateCategory.Name + "State";
                fallbackState = null;
                statesToLoopThrough = stateCategory.States;

                foundVariableSave = TryGetVariableFromStateOnInstance(instance, variable, statesToPullFrom, 
                    stateVariableName, fallbackState, statesToLoopThrough);
            }

            if (foundVariableSave == null)
            {
                stateVariableName = "State";
                fallbackState = instanceBase.DefaultState;
                statesToLoopThrough = instanceBase.States;

                foundVariableSave = TryGetVariableFromStateOnInstance(instance, variable, statesToPullFrom, 
                    stateVariableName, fallbackState, statesToLoopThrough);
            }

            return foundVariableSave;
        }
        private static VariableSave TryGetVariableFromStateOnInstance(InstanceSave instance, string variable, IEnumerable<StateSave> statesToPullFrom, string stateVariableName, StateSave fallbackState, List<StateSave> statesToLoopThrough)
        {
            VariableSave foundVariableSave = null;

            // Let's see if this is in a non-default state
            string thisState = null;
            foreach (var stateToPullFrom in statesToPullFrom)
            {
                var foundStateVariable = stateToPullFrom.GetVariableSave(instance.Name + "." + stateVariableName);
                if (foundStateVariable != null && foundStateVariable.SetsValue)
                {
                    thisState = foundStateVariable.Value as string;
                }
            }
            StateSave instanceStateToPullFrom = fallbackState;

            // if thisState is not null, then the state is being explicitly set, so let's try to get that state
            if (!string.IsNullOrEmpty(thisState) && statesToLoopThrough.Any(item => item.Name == thisState))
            {
                instanceStateToPullFrom = statesToLoopThrough.First(item => item.Name == thisState);
            }

            if (instanceStateToPullFrom != null)
            {
                // Eventually use the instanceBase's current state value
                foundVariableSave = instanceStateToPullFrom.GetVariableRecursive(variable);
            }
            return foundVariableSave;
        }
 public static void Initialize(this InstanceSave instanceSave)
 {
     // nothing to do currently?
 }
        private static void GetStatesToUse(InstanceSave instance, List<ElementWithState> elementStack, bool forceDefault, ElementSave instanceBase, RecursiveVariableFinder rvf, out List<StateSave> statesToPullFrom, out StateSave defaultState)
        {
            statesToPullFrom = null;
            defaultState = null;

#if GUM
            if (SelectedState.Self.SelectedElement != null)
            {
                statesToPullFrom = new List<StateSave> { SelectedState.Self.SelectedElement.DefaultState };
                defaultState = SelectedState.Self.SelectedElement.DefaultState;
            }
#endif

            if (elementStack.Count != 0)
            {
                if (elementStack.Last().Element == null)
                {
                    throw new InvalidOperationException("The ElementStack contains an ElementWithState with no Element");
                }
                statesToPullFrom = elementStack.Last().AllStates.ToList();
                defaultState = elementStack.Last().Element.DefaultState;
            }


#if GUM
            if (elementStack.Count != 0 && elementStack.Last().Element == SelectedState.Self.SelectedElement &&
                SelectedState.Self.SelectedStateSave != null &&
                !forceDefault)
            {
                statesToPullFrom = new List<StateSave> { SelectedState.Self.SelectedStateSave };
            }
#endif

        }
Пример #18
0
 internal void InstanceSelected(ElementSave elementSave, InstanceSave instance)
 {
     CallMethodOnPlugin(
         delegate(PluginBase plugin)
         {
             plugin.CallInstanceSelected(elementSave, instance);
         },
         "InstanceSelected"
     );
 }
        public static bool IsComponent(this InstanceSave instanceSave)
        {
            ComponentSave baseAsComponentSave = ObjectFinder.Self.GetComponent(instanceSave.BaseType);

            return(baseAsComponentSave != null);
        }
 public static VariableSave GetVariableFromThisOrBase(this InstanceSave instance,
                                                      List <ElementWithState> elementStack, string variable)
 {
     return(GetVariableFromThisOrBase(instance, elementStack, new RecursiveVariableFinder(instance, elementStack), variable, false, false));
 }
Пример #21
0
        private static bool TryHandleAssigningMultipleVariables(ElementSave gumElement, GumInstance gumInstance, string variableName, GlueElement glueElement, FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos, object gumValue)
        {
            var isTextureValue = variableName == "Texture Address" ||
                                 variableName == "Texture Left" ||
                                 variableName == "Texture Top" ||
                                 variableName == "Texture Width" ||
                                 variableName == "Texture Height";

            var handled = false;

            if (isTextureValue)
            {
                string variablePrefix = null;
                if (gumInstance != null)
                {
                    variablePrefix = $"{gumInstance.Name}.";
                }
                var state = SelectedState.Self.SelectedStateSave;
                var addressValueGumCurrent       = state.GetValue($"{variablePrefix}Texture Address");
                var textureLeftValueGumCurrent   = state.GetValue($"{variablePrefix}Texture Left");
                var textureWidthValueGumCurrent  = state.GetValue($"{variablePrefix}Texture Width");
                var textureTopValueGumCurrent    = state.GetValue($"{variablePrefix}Texture Top");
                var textureHeightValueGumCurrent = state.GetValue($"{variablePrefix}Texture Height");

                var setsAny = addressValueGumCurrent != null ||
                              textureLeftValueGumCurrent != null ||
                              textureWidthValueGumCurrent != null ||
                              textureTopValueGumCurrent != null ||
                              textureHeightValueGumCurrent != null;

                if (setsAny)
                {
                    var rvf = new RecursiveVariableFinder(state);
                    var addressValueGumRecursive = rvf.GetValue <TextureAddress>($"{variablePrefix}Texture Address");

                    // set them all

                    if (addressValueGumRecursive == TextureAddress.EntireTexture)
                    {
                        // null them out:
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                    }
                    else
                    {
                        // set the values:
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, IntToNullOrFloat(textureLeftValueGumCurrent));
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, IntToNullOrFloat(textureTopValueGumCurrent));

                        // right and bottom depend on left/top plus width/height
                        if (textureLeftValueGumCurrent != null && textureWidthValueGumCurrent != null)
                        {
                            var combined = (int)textureLeftValueGumCurrent + (int)textureWidthValueGumCurrent;
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, (float)combined);
                        }
                        else
                        {
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, IntToNullOrFloat(null));
                        }

                        if (textureTopValueGumCurrent != null && textureHeightValueGumCurrent != null)
                        {
                            var combined = (int)textureTopValueGumCurrent + (int)textureHeightValueGumCurrent;
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, (float)combined);
                        }
                        else
                        {
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                        }
                    }
                }
                else
                {
                    // null them all
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                }



                handled = true;
            }

            return(handled);
        }
Пример #22
0
        public TreeNode GetTreeNodeFor(InstanceSave instanceSave, TreeNode container)
        {
            foreach (TreeNode node in container.Nodes)
            {
                if (node.Tag == instanceSave)
                {
                    return node;
                }

                TreeNode childNode = GetTreeNodeFor(instanceSave, node);
                if (childNode != null)
                {
                    return childNode;
                }
            }

            return null;
        }
Пример #23
0
        public void RemoveInstance(InstanceSave instanceToRemove, ElementSave elementToRemoveFrom)
        {
            if (!elementToRemoveFrom.Instances.Contains(instanceToRemove))
            {
                throw new Exception("Could not find the instance " + instanceToRemove.Name + " in " + elementToRemoveFrom.Name);
            }

            elementToRemoveFrom.Instances.Remove(instanceToRemove);

            foreach (StateSave stateSave in elementToRemoveFrom.AllStates)
            {
                for (int i = stateSave.Variables.Count - 1; i > -1; i--)
                {
                    if (stateSave.Variables[i].SourceObject == instanceToRemove.Name)
                    {
                        stateSave.Variables.RemoveAt(i);
                    }
                }
                for (int i = stateSave.VariableLists.Count - 1; i > -1; i--)
                {
                    if (stateSave.VariableLists[i].SourceObject == instanceToRemove.Name)
                    {
                        stateSave.VariableLists.RemoveAt(i);
                    }
                }
            }

            elementToRemoveFrom.Events.RemoveAll(item => item.GetSourceObject() == instanceToRemove.Name);

            PluginManager.Self.InstanceDelete(elementToRemoveFrom, instanceToRemove);

            if (SelectedState.Self.SelectedInstance == instanceToRemove)
            {
                SelectedState.Self.SelectedInstance = null;
            }
        }
Пример #24
0
        private InstanceSave FindParentInstance(InstanceSave instance)
        {
            ElementSave element = instance.ParentContainer;

            string name = instance.Name + ".Parent";
            VariableSave variable = element.DefaultState.Variables.FirstOrDefault(v => v.Name == name);

            if (variable != null && variable.SetsValue && variable.Value != null)
            {
                string parentName = (string) variable.Value;
                return element.GetInstance(parentName);
            }

            return null;
        }
Пример #25
0
        private TreeNode AddTreeNodeForInstance(InstanceSave instance, TreeNode parentContainerNode, HashSet<InstanceSave> pendingAdditions = null)
        {
            TreeNode treeNode = new TreeNode();

            bool validBaseType = ObjectFinder.Self.GetElementSave(instance.BaseType) != null;

            if (validBaseType)
                treeNode.ImageIndex = InstanceImageIndex;
            else
                treeNode.ImageIndex = ExclamationIndex;

            treeNode.Tag = instance;

            TreeNode parentNode = parentContainerNode;
            InstanceSave parentInstance = FindParentInstance(instance);

            if (parentInstance != null)
            {
                TreeNode parentInstanceNode = GetTreeNodeFor(parentInstance, parentContainerNode);

                // Make sure we are not already trying to add the parent (protects against stack overflow with invalid data)
                if (parentInstanceNode == null && (pendingAdditions == null || !pendingAdditions.Contains(parentInstance)))
                {
                    if (pendingAdditions == null)
                    {
                        pendingAdditions = new HashSet<InstanceSave>();
                    }

                    pendingAdditions.Add(parentInstance);
                    parentInstanceNode = AddTreeNodeForInstance(parentInstance, parentContainerNode, pendingAdditions);
                }

                if (parentInstanceNode != null)
                {
                    parentNode = parentInstanceNode;
                }
            }

            parentNode.Nodes.Add(treeNode);

            return treeNode;
        }
Пример #26
0
        // Discussion about Selection
        // Selection is a rather complicated
        // system in Gum because tree nodes can
        // be selected in a number of ways:
        // 1.  The user can push/release (click)
        // 2.  The user can select an item in the
        //     wireframe window which in turn selects
        //     the appropriate tree node.
        // 3.  The user pushes on a tree node, but then
        //     drags off of it to do a drag+drop somewhere
        //     else.
        // We want the app to refresh what it is displaying
        // in scenario 1 and 2, but not in 3.  Therefore the
        // MultiSelectTreeView class has an event called AfterClickSelect
        // which only fires when the user actually clicks on an item (1) so
        // that #3 doesn't fire off an event.  However, this means that #2 will
        // no longer fire off the event either.  We need to then make sure that #2
        // does still fire off an event, so we'll do this by manually raising the event
        // in the Select methods where a Save object is selected.
        public void Select(InstanceSave instanceSave, ElementSave parent)
        {
            if (instanceSave != null)
            {
                TreeNode parentTreeNode = GetTreeNodeFor(parent);

                // This could be null if the user started a new project or loaded a different project.
                if (parentTreeNode != null)
                {
                    Select(GetTreeNodeFor(instanceSave, parentTreeNode));
                }
            }
            else
            {
                Select((TreeNode)null);
            }
        }
        private GraphicalUiElement CreateRepresentationForInstance(InstanceSave instance, InstanceSave parentInstance, List<ElementWithState> elementStack, GraphicalUiElement container)
        {
            IPositionedSizedObject newIpso = null;

            GraphicalUiElement graphicalElement = newIpso as GraphicalUiElement;
            var baseElement = ObjectFinder.Self.GetElementSave(instance.BaseType);

            string type = instance.BaseType;

            if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle")
            {
                graphicalElement = new GraphicalUiElement(null, container);
                ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
                graphicalElement.CreateGraphicalComponent(instanceBase, null);
                graphicalElement.Tag = instance;
                graphicalElement.Component.Name = instance.Name;
                graphicalElement.Component.Tag = instance;

                if (type == "Text")
                {
                    (graphicalElement.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                }

            }
            else if (instance.IsComponent())
            {
                newIpso = CreateRepresentationsForInstanceFromComponent(instance, elementStack, parentInstance, container, ObjectFinder.Self.GetComponent(instance.BaseType));
            }
            else
            {
                // Make sure the base type is valid.
                // This could be null if a base type changed
                // its name but the derived wasn't updated, or
                // if someone screwed with the XML files.  Who knows...

                if (baseElement != null)
                {
                    graphicalElement = new GraphicalUiElement(null, container);

                    CreateRectangleFor(instance, elementStack, graphicalElement);
                }
            }

            if (newIpso != null && (newIpso is GraphicalUiElement) == false)
            {
                graphicalElement = new GraphicalUiElement(newIpso as IRenderable, container);
            }
            else if (newIpso is GraphicalUiElement)
            {
                graphicalElement = newIpso as GraphicalUiElement;
            }

            if(graphicalElement != null)
            {

                if (baseElement != null)
                {
                    graphicalElement.ElementSave = baseElement;
                    foreach (var exposedVariable in baseElement.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName)))
                    {
                        graphicalElement.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name);
                    }

                }

                var selectedState = SelectedState.Self.SelectedStateSave;
                if (selectedState == null)
                {
                    selectedState = SelectedState.Self.SelectedElement.DefaultState;
                }

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState);

                string guide = rvf.GetValue<string>("Guide");
                string parent = rvf.GetValue<string>(instance.Name + ".Parent");

                SetGuideParent(container, graphicalElement, guide, container == null || parent == AvailableInstancesConverter.ScreenBoundsName);
            }

            if (baseElement != null)
            {
                graphicalElement.SetStatesAndCategoriesRecursively(baseElement);
                graphicalElement.SetVariablesRecursively(baseElement, baseElement.DefaultState);
            }

            return graphicalElement;
        }
Пример #28
0
 public void CallInstanceDelete(ElementSave elementSave, InstanceSave instance)
 {
     if (InstanceDelete != null)
     {
         InstanceDelete(elementSave, instance);
     }
 }
Пример #29
0
        private static void SetInstanceToPosition(float worldX, float worldY, InstanceSave instance)
        {
            float parentX = 0;
            float parentY = 0;
            if (SelectedState.Self.SelectedComponent != null)
            {
                parentX = (float)SelectedState.Self.SelectedStateSave.GetValueRecursive("X");
                parentY = (float)SelectedState.Self.SelectedStateSave.GetValueRecursive("Y");
            }

            // This thing may be left or center aligned so we should account for that

            SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".X", worldX - parentX);
            SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".Y", worldY - parentY);
        }
Пример #30
0
 public void CallVariableSet(ElementSave parentElement, InstanceSave instance, string changedMember, object oldValue)
 {
     if (VariableSet != null)
     {
         VariableSet(parentElement, instance, changedMember, oldValue);
     }
 }
Пример #31
0
 internal void VariableSet(ElementSave parentElement, InstanceSave instance, string changedMember, object oldValue)
 {
     CallMethodOnPlugin(
         delegate(PluginBase plugin)
         {
             plugin.CallVariableSet(parentElement, instance, changedMember, oldValue);
         },
         "GetAttributesFor"
     );
 }
Пример #32
0
        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 IPositionedSizedObject CreateRectangleFor(InstanceSave instance, List<ElementWithState> elementStack, GraphicalUiElement graphicalUiElement)
        {
            ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
            graphicalUiElement.CreateGraphicalComponent(instanceBase, null);
            graphicalUiElement.Tag = instance;
            graphicalUiElement.Component.Name = instance.Name;
            graphicalUiElement.Component.Tag = instance;

            (graphicalUiElement.RenderableComponent as LineRectangle).LocalVisible =
                GraphicalUiElement.ShowLineRectangles;
            return graphicalUiElement;
        }
        public static VariableSave GetVariableFromThisOrBase(this InstanceSave instance,
                                                             List <ElementWithState> elementStack, RecursiveVariableFinder rvf, string variable, bool forceDefault, bool onlyIfSetsValue)
        {
            ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);

            List <StateSave> statesToPullFrom;
            StateSave        defaultState;

            GetStatesToUse(instance, elementStack, forceDefault, instanceBase, rvf, out statesToPullFrom, out defaultState);


            VariableSave variableSave = null;

            // See if the variable is set by the container of the instance:
            foreach (var stateToPullFrom in statesToPullFrom)
            {
                var possibleVariable = stateToPullFrom.GetVariableSave(instance.Name + "." + variable);
                if (possibleVariable != null)
                {
                    variableSave = possibleVariable;
                }
            }
            // non-default states can override the default state, so first
            // let's see if the selected state is non-default and has a value
            // for a given variable.  If not, we'll fall back to the default.
            if ((variableSave == null || (onlyIfSetsValue && variableSave.SetsValue == false)) && !statesToPullFrom.Contains(defaultState))
            {
                variableSave = defaultState.GetVariableSave(instance.Name + "." + variable);
            }

            // Still haven't found a variable yet, so look in the instanceBase if one exists
            if ((variableSave == null ||
                 (onlyIfSetsValue && (variableSave.SetsValue == false || variableSave.Value == null))) && instanceBase != null)
            {
                VariableSave foundVariableSave = TryGetVariableFromStatesOnInstance(instance, variable, instanceBase, statesToPullFrom);

                if (foundVariableSave != null)
                {
                    variableSave = foundVariableSave;
                }
            }

            // I don't think we have to do this because we're going to copy over
            // the variables to all components on load.
            //if (variableSave == null && instanceBase != null && instanceBase is ComponentSave)
            //{
            //    variableSave = StandardElementsManager.Self.DefaultStates["Component"].GetVariableSave(variable);
            //}

            if (variableSave != null && variableSave.Value == null && instanceBase != null && onlyIfSetsValue)
            {
                // This can happen if there is a tunneled variable that is null
                VariableSave possibleVariable = instanceBase.DefaultState.GetVariableSave(variable);
                if (possibleVariable != null && possibleVariable.Value != null && (!onlyIfSetsValue || possibleVariable.SetsValue))
                {
                    variableSave = possibleVariable;
                }
                else if (!string.IsNullOrEmpty(instanceBase.BaseType))
                {
                    ElementSave element = ObjectFinder.Self.GetElementSave(instanceBase.BaseType);

                    if (element != null)
                    {
                        variableSave = element.GetVariableFromThisOrBase(variable, forceDefault);
                    }
                }
            }

            return(variableSave);
        }
        private GraphicalUiElement CreateRepresentationsForInstanceFromComponent(InstanceSave instance, 
            List<ElementWithState> elementStack, InstanceSave parentInstance, GraphicalUiElement parentIpso, 
            ComponentSave baseComponentSave)
        {
            StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(instance);

            GraphicalUiElement rootIpso = null;
            if (ses != null)
            {
                rootIpso = new GraphicalUiElement(null, parentIpso);

                string type = ses.Name;

                if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle")
                {
                    ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
                    rootIpso.CreateGraphicalComponent(instanceBase, null);
                    rootIpso.Tag = instance;
                    rootIpso.Component.Name = instance.Name;
                    rootIpso.Component.Tag = instance;

                    if(type == "Text")
                    {
                        (rootIpso.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                    }

                }
                else
                {
                    CreateRectangleFor(instance, elementStack, rootIpso);
                }

                var selectedState = SelectedState.Self.SelectedStateSave;

                if (selectedState == null)
                {
                    selectedState = SelectedState.Self.SelectedElement.DefaultState;
                }

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState);

                string guide = rvf.GetValue<string>("Guide");
                SetGuideParent(parentIpso, rootIpso, guide, false);

                ElementWithState elementWithState = new ElementWithState(baseComponentSave);
                var tempRvf = new DataTypes.RecursiveVariableFinder(instance, elementStack);
                var state = tempRvf.GetValue("State") as string;
                elementWithState.StateName = state;

                foreach (var category in baseComponentSave.Categories)
                {
                    elementWithState.CategorizedStates.Add(category.Name, tempRvf.GetValue<string>(category.Name + "State"));
                }

                elementWithState.InstanceName = instance.Name;
                elementStack.Add(elementWithState);

                foreach (InstanceSave internalInstance in baseComponentSave.Instances)
                {
                    GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso);

                }

                SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances);

                elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave));
            }

            return rootIpso;
        }
        public static bool GetIsFileFromRoot(this VariableSave variable, InstanceSave instance)
        {
            if (string.IsNullOrEmpty(variable.SourceObject))
            {
                ElementSave root = ObjectFinder.Self.GetRootStandardElementSave(instance);

                var variableInRoot = root.DefaultState.Variables.FirstOrDefault(item => item.Name == variable.GetRootName());

                if (variableInRoot != null)
                {
                    return variableInRoot.IsFile;
                }
            }
            else
            {
                ElementSave elementForInstance = ObjectFinder.Self.GetElementSave(instance.BaseType);

                string rootName = variable.GetRootName();
                VariableSave exposedVariable = elementForInstance.DefaultState.Variables.FirstOrDefault(item => item.ExposedAsName == rootName);

                if (exposedVariable != null)
                {
                    InstanceSave subInstance = elementForInstance.Instances.FirstOrDefault(item => item.Name == exposedVariable.SourceObject);

                    if (subInstance != null)
                    {
                        return exposedVariable.GetIsFileFromRoot(subInstance);
                    }
                }
                else
                {
                    // it's not exposed, so let's just get to the root of it:

                    ElementSave root = ObjectFinder.Self.GetRootStandardElementSave(instance);

                    var variableInRoot = root.DefaultState.Variables.FirstOrDefault(item => item.Name == variable.GetRootName());

                    if (variableInRoot != null)
                    {
                        return variableInRoot.IsFile;
                    }
                }

            }
            return false;
        }
Пример #37
0
 public void CallInstanceSelected(ElementSave elementSave, InstanceSave instance)
 {
     if (InstanceSelected != null)
     {
         InstanceSelected(elementSave, instance);
     }
 }
Пример #38
0
        private static void AskToDeleteInstance(InstanceSave instance)
        {
            DialogResult result =
                MessageBox.Show("Are you sure you'd like to delete " + instance.Name + "?", "Delete instance?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                ElementSave selectedElement = SelectedState.Self.SelectedElement;

                Gum.ToolCommands.ElementCommands.Self.RemoveInstance(instance, selectedElement);

                RefreshAndSaveAfterInstanceRemoval(selectedElement);
            }
        }
Пример #39
0
        public void ReactToRenamed(ElementSave element, InstanceSave instance, string oldName)
        {
            if (instance == null)
            {
                List<ElementReference> listToSearch = null;

                if (element is ScreenSave)
                {
                    listToSearch = ScreenReferences;
                }
                else if (element is ComponentSave)
                {
                    listToSearch = ComponentReferences;
                }
                else if (element is StandardElementSave)
                {
                    listToSearch = StandardElementReferences;
                }

                foreach (ElementReference reference in listToSearch)
                {
                    if (reference.Name == oldName)
                    {
                        reference.Name = element.Name;
                    }
                }
            }
        }
Пример #40
0
        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);

            // 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.");
                }

                StateSave stateSave = copiedState;

                // Why do we reverse loop here?
                for (int i = stateSave.Variables.Count - 1; i > -1; i--)
                {
                    VariableSave sourceVariable = stateSave.Variables[i];

                    VariableSave copiedVariable = sourceVariable.Clone();
                    // Only copy over the variables that apply to the object that was dropped
                    if (sourceVariable.SourceObject == sourceInstance.Name)
                    {
                        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;

                        targetElement.DefaultState.Variables.Add(copiedVariable);
                    }
                }

                for(int i = 0; i < stateSave.VariableLists.Count; i++)
                {
                    var sourceVariableList = stateSave.VariableLists[i];

                    var copiedVariableList = sourceVariableList.Clone();
                    // Only copy over the variables that apply to the object that was dropped
                    if (sourceVariableList.SourceObject == sourceInstance.Name)
                    {
                        copiedVariableList.Name = targetInstance.Name + "." + copiedVariableList.GetRootName();
                        copiedVariableList.SourceObject = targetInstance.Name;
                        targetElement.DefaultState.VariableLists.Add(copiedVariableList);
                    }
                }
            }
            else
            {
                StateSave stateSave = copiedState;

                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;

                        SelectedState.Self.SelectedStateSave.Variables.Add(copiedVariable);
                    }
                }
                // Copy over the VariableLists too
                for (int i = stateSave.VariableLists.Count - 1; i > -1; i--)
                {

                    VariableListSave sourceList = stateSave.VariableLists[i];
                    if (sourceList.SourceObject == sourceInstance.Name)
                    {
                        VariableListSave copiedList = sourceList.Clone();
                        copiedList.Name = targetInstance.Name + "." + copiedList.GetRootName();
                        copiedList.SourceObject = targetInstance.Name;

                        SelectedState.Self.SelectedStateSave.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);
        }