internal void HandleGetEventSignatureArgs(FlatRedBall.Glue.SaveClasses.NamedObjectSave namedObject, FlatRedBall.Glue.Events.EventResponseSave eventResponseSave,
                                                  out string type, out string args)
        {
            bool isGumFile = false;

            type = null;
            args = null;

            if (namedObject != null)
            {
                bool   isFromFile = namedObject.SourceType == FlatRedBall.Glue.SaveClasses.SourceType.File;
                string extension  = null;
                if (isFromFile && !string.IsNullOrEmpty(namedObject.SourceFile))
                {
                    extension = FileManager.GetExtension(namedObject.SourceFile);
                }


                isGumFile = extension == "gusx" || extension == "gucx";
            }
            if (isGumFile)
            {
                type = "FlatRedBall.Gui.WindowEvent";
                args = "FlatRedBall.Gui.IWindow window";
            }
        }
        private static void ApplyTextureAddress(List <VariableSave> gumVariables, FlatRedBall.Glue.SaveClasses.NamedObjectSave namedObject, TextureAddress textureAddress)
        {
            VariableSave variableSave = new VariableSave();

            variableSave.Name  = $"{namedObject.InstanceName}.Texture Address";
            variableSave.Type  = nameof(Gum.Managers.TextureAddress);
            variableSave.Value = textureAddress;
            gumVariables.Add(variableSave);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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;
                    }
                }
            }
        }
        private static void ApplyTextureHeight(List <VariableSave> gumVariables, float height, FlatRedBall.Glue.SaveClasses.NamedObjectSave namedObject)
        {
            VariableSave variableSave;

            variableSave       = new VariableSave();
            variableSave.Name  = $"{namedObject.InstanceName}.Texture Height";
            variableSave.Type  = "int";
            variableSave.Value = RenderingLibrary.Math.MathFunctions.RoundToInt(height);
            gumVariables.Add(variableSave);
        }