Inheritance: PositionedObject, IVisible, IClickable
Esempio n. 1
0
        private Graphics.Layer GetLayerForNos(Layer layerProvidedByContainer, NamedObjectSave n)
        {
            Layer layerToPutOn = layerProvidedByContainer;

            // If the NOS specifies its own Layer, handle that:

            if (!string.IsNullOrEmpty(n.LayerOn))
            {
                if (n.LayerOn == "Under Everything (Engine Layer)")
                {
                    layerToPutOn = SpriteManager.UnderAllDrawnLayer;
                }
                else if (n.LayerOn == "Top Layer (Engine Layer)")
                {
                    layerToPutOn = SpriteManager.TopLayer;
                }

                else
                {
                    ElementRuntime layerContainer = GetContainedElementRuntime(n.LayerOn);
                    if (layerContainer != null)
                    {
                        layerToPutOn = ((Layer)layerContainer.mDirectObjectReference);
                    }
                }
            }
            return(layerToPutOn);
        }
Esempio n. 2
0
        static void LoadNextElementActivity()
        {
            if (mNextElement != null)
            {
                IElement elementToShow = ObjectFinder.GetIElement(mNextElement);
                mNextElement = null;

                RemoveCurrentElement();

                ContentManagerName = StringFunctions.IncrementNumberAtEnd(ContentManagerName);

                try
                {
                    if (BeforeElementLoaded != null)
                    {
                        BeforeElementLoaded(elementToShow);
                    }


                    CurrentElement = new ElementRuntime(elementToShow, null, null, OnBeforeVariableSet, OnAfterVariableSet);

                    if (AfterElementLoaded != null)
                    {
                        SpriteManager.AddPositionedObject(CurrentElement);
                        AfterElementLoaded(CurrentElement.AssociatedIElement);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error loading element " + elementToShow + ":\n\n" + e.ToString());
                }
            }
        }
Esempio n. 3
0
        int Compare(ElementRuntime first, ElementRuntime second)
        {
            ElementRuntime currentElement = GluxManager.CurrentElement;

            NamedObjectSave mFirstNos = first.AssociatedNamedObjectSave;
            NamedObjectSave mSecondNos = second.AssociatedNamedObjectSave;

            string firstLayer = mFirstNos.LayerOn;
            string secondLayer = mSecondNos.LayerOn;

            if (string.IsNullOrEmpty(firstLayer) && !string.IsNullOrEmpty(secondLayer))
            {
                // second is not on a layer, so that should come first
                return 1;
            }
            else if (!string.IsNullOrEmpty(firstLayer) && string.IsNullOrEmpty(secondLayer))
            {
                return -1;
            }
            else if (string.IsNullOrEmpty(firstLayer))
            {
                // they both are, so compare their Z
                return -first.Z.CompareTo(second.Z);
            }
            else
            {
                // they're on separate layers, so compare the layer indexes
                IElement element = currentElement.AssociatedIElement;

                NamedObjectSave firstLayerNos = element.GetNamedObjectRecursively(firstLayer);
                NamedObjectSave secondLayerNos = element.GetNamedObjectRecursively(secondLayer);

                return -Compare(firstLayerNos, secondLayerNos);
            }
        }
 public void UpdateIElementVariables(ElementRuntime elementRuntime, List<string> variables)
 {
     foreach (string variable in variables)
     {
         UpdateIElementVariable(elementRuntime, variable);
     }
 }
Esempio n. 5
0
        static void RefreshHighlightActivity()
        {
            if (mShouldRefreshHighlight)
            {
                if (mNextElementToHighlight == null)
                {
                    if (mCurrentElementHighlight.CurrentElement != null)
                    {
                        mCurrentElementHighlight.CurrentElement = null;
                    }
                }
                else if (mCurrentElement != null)
                {
                    ElementRuntime nextElement = mCurrentElement.GetContainedElementRuntime(mNextElementToHighlight);
                    mCurrentElementHighlight.CurrentElement = nextElement;

                    mCurrentElementHighlight.Color =
                        mCurrentElementHighlight.GetColorVisibleAgainst(SpriteManager.Camera.BackgroundColor);
                }

                if (ElementHighlighted != null)
                {
                    ElementHighlighted(mCurrentElementHighlight.CurrentElement);
                }

                mShouldRefreshHighlight = false;
            }

            // We want to refresh every frame because elements may change due to plugins, interpolation, script, etc.
            // This is a little inefficient but it might be okay since we're on a PC.  Review this if we have performance
            // problems (I don't expect we will)
            mCurrentElementHighlight.CurrentElement = mCurrentElementHighlight.CurrentElement;
        }
Esempio n. 6
0
        public void Initialize()
        {
            OverallInitializer.Initialize();

            mBaseEntity = new EntitySave();
            mBaseEntity.Name = "BaseEntityInheritanceTests";
            ObjectFinder.Self.GlueProject.Entities.Add(mBaseEntity);

            NamedObjectSave nos = new NamedObjectSave();
            nos.InstanceName = "SpriteInstance";
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.SetByDerived = true;
            mBaseEntity.NamedObjects.Add(nos);

            nos = new NamedObjectSave();
            nos.InstanceName = "RectInstance";
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "AxisAlignedRectangle";
            nos.ExposedInDerived = true;
            mBaseEntity.NamedObjects.Add(nos);

            mDerivedEntity = new EntitySave();
            mDerivedEntity.Name = "DerivedentityInheritanceTests";
            mDerivedEntity.BaseEntity = mBaseEntity.Name;
            mDerivedEntity.UpdateFromBaseType();
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntity);

            mDerivedElementRuntime = new ElementRuntime(mDerivedEntity, null, null, null, null);
        }
Esempio n. 7
0
        public void TestLayerOrthoValues()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "LayerTestTestLayerOrthoValuesEntity";

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Layer";
            nos.InstanceName = "Layer1";
            nos.IndependentOfCamera = true;
            nos.Is2D = true;
            nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel;
            nos.LayerCoordinateType = LayerCoordinateType.MatchCamera;
            entitySave.NamedObjects.Add(nos);

            nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Layer";
            nos.InstanceName = "Layer2";
            nos.IndependentOfCamera = true;
            nos.Is2D = true;
            nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel;
            nos.LayerCoordinateType = LayerCoordinateType.MatchCamera;
            nos.DestinationRectangle = new FloatRectangle(0, 0, 80, 64);
            entitySave.NamedObjects.Add(nos);

            SpriteManager.Camera.Orthogonal = true;
            SpriteManager.Camera.OrthogonalWidth = 800;
            SpriteManager.Camera.OrthogonalHeight = 640;


            ElementRuntime elementRuntime = new ElementRuntime(entitySave,
                null,
                null,
                null,
                null);

            Layer layer = (elementRuntime.ContainedElements[0].DirectObjectReference as Layer);

            if (layer.LayerCameraSettings.OrthogonalWidth != 800 ||
                layer.LayerCameraSettings.OrthogonalHeight != 640)
            {
                throw new Exception("A Layer using MatchCamera coordinate types is not matching the Camera's ortho values");
            }


            layer = (elementRuntime.ContainedElements[1].DirectObjectReference as Layer);

            if (layer.LayerCameraSettings.OrthogonalWidth != 80 ||
                layer.LayerCameraSettings.OrthogonalHeight != 64)
            {
                throw new Exception("A Layer using MatchCamera with a destination rectangle does not have proper coordinates");
            }
        }
 public void Show(ElementRuntime elementRuntime, NamedObjectSave nosToShow)
 {
     mCurrentElementRuntime = elementRuntime;
     if (nosToShow != null)
     {
         nosToShow.UpdateCustomProperties();
     }
     mCurrentNos = nosToShow;
     mNosDisplayer.CurrentElement = GlueViewState.Self.CurrentElement;
     mNosDisplayer.Instance = mCurrentNos;
     mNosDisplayer.PropertyGrid = mPropertyGrid;
 }
        public void TestRelativeAbsoluteConversion()
        {
            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.UpdateCustomProperties();
            nos.InstanceName = "SpriteObject";
            nos.SetPropertyValue("ScaleX", 2.0f);
            nos.SetPropertyValue("X", 4.0f);
            nos.SetPropertyValue("RotationZ", 4.0f);
            nos.SetPropertyValue("RotationZVelocity", 4.0f);

            mEntitySave.NamedObjects.Add(nos);

            CustomVariable customVariable = new CustomVariable();
            customVariable.SourceObject = nos.InstanceName;
            customVariable.SourceObjectProperty = "ScaleY";
            customVariable.DefaultValue = 8.0f;

            mEntitySave.CustomVariables.Add(customVariable);

            ElementRuntime elementRuntime = new ElementRuntime(mEntitySave, null, null, null, null);

            Sprite sprite = elementRuntime.ContainedElements[0].DirectObjectReference as Sprite;
            sprite.ForceUpdateDependencies();

            if (elementRuntime.X != 0)
            {
                throw new Exception("NOS variables are being applied to the container instead of just to the NOS");
            }

            if (sprite.X != 4.0f)
            {
                throw new Exception("Absolute values should get set when setting X on objects even though they're attached");
            }

            if (sprite.RotationZ != 4.0f)
            {
                throw new Exception("Absolute values should get set when setting RotationZ on objects even though they're attached");
            }
            if (sprite.RelativeRotationZVelocity != 4.0f)
            {
                throw new Exception("Setting RotationZVelocity should set RelativeRotationZVelocity");
            }
            if (sprite.ScaleX != 2.0f)
            {
                throw new Exception("Scale values aren't properly showing up on Sprites");
            }
            if (sprite.ScaleY != 8.0f)
            {
                throw new Exception("Scale values aren't properly showing up on Sprites");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="element">The ElementRuntime that is selected</param>
        public EntityControlControls(ElementRuntime element, RuntimeOptions runtimeOptions)
        {
            mRuntimeOptions = runtimeOptions;
            InitializeComponent();

            TypeOfAction = ActionType.None;
            unselectedButtonColor = noneButton.BackColor;
            noneButton.BackColor = Color.Red;

            currentElementRuntime = element;

            mPropertyGridManager = new PropertyGridManager(propertyGrid1, runtimeOptions);
        }
Esempio n. 11
0
        private void CreateDerivedElementRuntime()
        {
            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.Name = "DerivedVariableSettingEntity";
            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);
            mDerivedEntitySave.UpdateFromBaseType();
            mDerivedEntitySave.GetCustomVariable("CurrentState").DefaultValue = "Uncategorized";


            mDerivedElementRuntime = new ElementRuntime(mDerivedEntitySave, null, null, null, null);


        }
		/// <summary>
		/// Saves the variables to the glux file.
		/// If a variable does not exist, it will be created
		/// Tells GlueView to ignore the next Glue Save
		/// </summary>
		public void SaveElement(ElementRuntime elementRuntime, List<string> variables)
		{
			if (elementRuntime != null)
			{
				foreach (string s in variables)
				{
					UpdateIElementVariable(elementRuntime, s);
				}

				//Save
				SaveGlux();

			}
		}
Esempio n. 13
0
        private void SetInstanceVariablesOnNamedObjects()
        {
            for (int i = 0; i < mContainedElements.Count; i++)
            {
                ElementRuntime elementRuntime = mContainedElements[i];

                SetVariablesOnElementRuntime(elementRuntime);
            }

            for (int i = 0; i < this.mElementsInList.Count; i++)
            {
                ElementRuntime elementRuntime = mElementsInList[i];
                SetVariablesOnElementRuntime(elementRuntime);
            }
        }
 public bool IsElementRuntimeScalable(ElementRuntime elementRuntime)
 {
     if (elementRuntime != null)
     {
         if (elementRuntime.DirectObjectReference != null)
         {
             return elementRuntime.DirectObjectReference is IScalable ||
                 elementRuntime.DirectObjectReference is Circle;
         }
         else if (elementRuntime.AssociatedNamedObjectSave != null && elementRuntime.AssociatedNamedObjectSave.GetIsScalableEntity())
         {
             // Does this thing have ScaleX and ScaleY values?
             return true;
         }
     }
     return false;
 }
        protected override void CreatePolygonsForElement(ElementRuntime element)
        {
            //element.AssociatedNamedObjectSave.GetIsScalableEntity();

            //Positioned Objects
            if (element.DirectObjectReference != null && element.DirectObjectReference is PositionedObject)
            {
                //Sprite
                //CreateRotationHandleForPositionedObject((PositionedObject)element.DirectObjectReference);
                //Text

            }
            //Entities
            else if (element.AssociatedIElement != null)
            {
                //CreateRotationHandleForPositionedObject((PositionedObject)element);
            }
        }
Esempio n. 16
0
        public void TestStateVariables()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "CustomVariableTestStateVariableEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(entitySave);

            StateSaveCategory category1 = new StateSaveCategory();
            category1.Name = "Category1";
            category1.SharesVariablesWithOtherCategories = false;
            StateSave stateSave = new StateSave();
            stateSave.Name = "Disabled";
            category1.States.Add(stateSave);

            StateSaveCategory category2 = new StateSaveCategory();
            category2.Name = "Category2";
            category2.SharesVariablesWithOtherCategories = false;
            stateSave = new StateSave();
            stateSave.Name = "Disabled";
            category2.States.Add(stateSave);

            entitySave.StateCategoryList.Add(category1);
            entitySave.StateCategoryList.Add(category2);

            CustomVariable customVariable = new CustomVariable();
            customVariable.Type = "Category2";
            customVariable.DefaultValue = "Disabled";
            customVariable.Name = "CurrentCategory2State";
            entitySave.CustomVariables.Add(customVariable);

            

            ElementRuntime elementRuntime = new ElementRuntime(entitySave, null, null, null, null);

            StateSave foundStateSave = 
                elementRuntime.GetStateSaveFromCustomVariableValue(customVariable, customVariable.DefaultValue);

            if (foundStateSave != category2.States[0])
            {
                throw new Exception("States in categories are not being found properly when referenced through custom variables");
            }

        }
Esempio n. 17
0
        private void SetVariablesOnElementRuntime(ElementRuntime elementRuntime)
        {
            object objectToSet = elementRuntime.mDirectObjectReference;

            if (objectToSet == null)
            {
                objectToSet = elementRuntime;
            }

            // If the IElement
            // that contains the
            // elementRuntime has
            // a base IElement, then
            // the elementRuntime's NamedObjectSave
            // may be defined in a base object, and the
            // derived classes may provide a chain of overriden
            // variables.
            string name = elementRuntime.mAssociatedNamedObjectSave.InstanceName;

            IElement element = this.AssociatedIElement;
            List <NamedObjectSave> nosList = new List <NamedObjectSave>();

            do
            {
                NamedObjectSave nos = element.GetNamedObject(name);

                if (nos != null && (nos.DefinedByBase || nos == elementRuntime.mAssociatedNamedObjectSave))
                {
                    nosList.Add(nos);
                }

                element = ObjectFinder.Self.GetIElement(element.BaseElement);
            } while (element != null);


            // Start with the most derived, so do a reverse for loop
            for (int i = nosList.Count - 1; i > -1; i--)
            {
                SetVariablesForNamedObject(objectToSet, nosList[i]);
            }
        }
Esempio n. 18
0
        public CustomVariable CreateCustomVariableFor(string newVariableDeclarationType, string leftOfEquals, string rightOfEquals, ElementRuntime elementRuntime, CodeContext codeContext)
        {
            IElement element = null;
            CustomVariable toReturn = null;
            if (elementRuntime != null)
            {
                element = elementRuntime.AssociatedIElement;
                toReturn = element.GetCustomVariableRecursively(leftOfEquals);
            }
            // See if there is already a CustomVariable for this:

            if (toReturn != null)
            {
                toReturn = toReturn.Clone();
            }

            if (toReturn == null)
            {
                // If there's no event, we gotta create one
                toReturn = new CustomVariable();
                toReturn.Name = leftOfEquals;

                // If the left side has a period, that means the user is setting a variable on a contained object (because this. will already have been stripped)
                if (leftOfEquals.Contains('.'))
                {
                    int indexOfDot = leftOfEquals.IndexOf('.');
                    toReturn.SourceObject = leftOfEquals.Substring(0, indexOfDot);
                    toReturn.SourceObjectProperty = leftOfEquals.Substring(indexOfDot + 1, leftOfEquals.Length - (indexOfDot + 1));
                }


                if (newVariableDeclarationType == null)
                {
                    Type throwaway = null;
                    toReturn.Type = GetTypeStringForValue(leftOfEquals, elementRuntime, codeContext, out throwaway);
                }
                else
                {
                    toReturn.Type = newVariableDeclarationType;
                }

            }

            object valueToAssign = null;

            if (!string.IsNullOrEmpty(rightOfEquals))
            {
                valueToAssign = mExpressionParser.EvaluateExpression(rightOfEquals, codeContext);
            }

            if (toReturn.Type == null && valueToAssign != null)
            {
                toReturn.Type = valueToAssign.GetType().FullName;
            }

            if (toReturn.Type != null)
            {


                if (toReturn.GetRuntimeType() == typeof(float))
                {
                    if (valueToAssign is double)
                    {
                        valueToAssign = (float)((double)valueToAssign);
                    }
                    else if (valueToAssign is int)
                    {
                        valueToAssign = (float)((int)valueToAssign);
                    }
                }


                if (valueToAssign is float && float.IsNaN( (float)valueToAssign ))
                {
                    int m = 3;
                }

                toReturn.DefaultValue = valueToAssign;
            }

            return toReturn;
        }
Esempio n. 19
0
        private object CreateFlatRedBallTypeNos(NamedObjectSave namedObjectSave,
                                                PositionedObjectList <ElementRuntime> listToPopulate, Layer layerToPutOn)
        {
            object returnObject = null;

            ElementRuntime newElementRuntime = null;

            switch (namedObjectSave.SourceClassType)
            {
            case "Layer":
            case "FlatRedBall.Graphics.Layer":
                returnObject = CreateLayerObject(namedObjectSave, returnObject);
                break;

            case "AxisAlignedRectangle":
            case "FlatRedBall.Math.Geometry.AxisAlignedRectangle":
                AxisAlignedRectangle aaRectangle = ShapeManager.AddAxisAlignedRectangle();
                if (layerToPutOn != null)
                {
                    ShapeManager.AddToLayer(aaRectangle, layerToPutOn);
                }
                aaRectangle.Name = namedObjectSave.InstanceName;
                returnObject     = aaRectangle;
                break;

            case "Camera":
            case "FlatRedBall.Camera":
                if (namedObjectSave.IsNewCamera)
                {
                    returnObject = null;
                }
                else
                {
                    returnObject = SpriteManager.Camera;
                }
                break;

            case "Circle":
            case "FlatRedBall.Math.Geometry.Circle":
                Circle circle = ShapeManager.AddCircle();
                circle.Name = namedObjectSave.InstanceName;
                if (layerToPutOn != null)
                {
                    ShapeManager.AddToLayer(circle, layerToPutOn);
                }
                returnObject = circle;

                break;

            case "Polygon":
            case "FlatRedBall.Math.Geometry.Polygon":
                Polygon polygon = ShapeManager.AddPolygon();
                polygon.Name = namedObjectSave.InstanceName;

                if (layerToPutOn != null)
                {
                    ShapeManager.AddToLayer(polygon, layerToPutOn);
                }
                returnObject = polygon;

                break;

            case "Sprite":
            case "FlatRedBall.Sprite":
                Sprite sprite = SpriteManager.AddSprite((Texture2D)null);
                if (layerToPutOn != null)
                {
                    SpriteManager.AddToLayer(sprite, layerToPutOn);
                }
                sprite.Name  = namedObjectSave.InstanceName;
                returnObject = sprite;
                break;

            case "SpriteFrame":
            case "FlatRedBall.ManagedSpriteGroups.SpriteFrame":
                SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All);
                if (layerToPutOn != null)
                {
                    SpriteManager.AddToLayer(spriteFrame, layerToPutOn);
                }
                spriteFrame.Name = namedObjectSave.InstanceName;
                returnObject     = spriteFrame;
                break;

            case "Text":
            case "FlatRedBall.Graphics.Text":
                Text text = TextManager.AddText("");
                if (layerToPutOn != null)
                {
                    TextManager.AddToLayer(text, layerToPutOn);
                    text.SetPixelPerfectScale(layerToPutOn);
                }
                text.Name    = namedObjectSave.InstanceName;
                returnObject = text;
                break;

            case "Scene":
            case "FlatRedBall.Scene":
                Scene scene = new Scene();

                scene.Name   = namedObjectSave.InstanceName;
                returnObject = scene;
                break;

            default:
                // do nothing - need to add more types?
                break;
            }

            if (returnObject != null)
            {
                if (returnObject is IScalable)
                {
                    newElementRuntime = new ScalableElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                else
                {
                    newElementRuntime = new ElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                newElementRuntime.mDirectObjectReference = returnObject;

                if (returnObject is Camera && !namedObjectSave.IsNewCamera)
                {
                    SpriteManager.Camera.AttachTo(newElementRuntime, false);
                    SpriteManager.Camera.RelativePosition = Vector3.Zero;
                    newElementRuntime.Z    = 40;
                    newElementRuntime.Name = namedObjectSave.InstanceName;
                }
                else if (returnObject is FlatRedBall.Utilities.INameable)
                {
                    newElementRuntime.Name = ((FlatRedBall.Utilities.INameable)returnObject).Name;
                }
                else
                {
                    object nameValueAsObject;
                    if (LateBinder.TryGetValueStatic(returnObject, "Name", out nameValueAsObject))
                    {
                        newElementRuntime.Name = (string)nameValueAsObject;
                    }
                }

                listToPopulate.Add(newElementRuntime);
            }

            return(returnObject);
        }
        private void SetVariablesOnElementRuntime(ElementRuntime elementRuntime)
        {
            object objectToSet = elementRuntime.mDirectObjectReference;

            if (objectToSet == null)
            {
                objectToSet = elementRuntime;
            }

            // If the IElement
            // that contains the
            // elementRuntime has
            // a base IElement, then
            // the elementRuntime's NamedObjectSave
            // may be defined in a base object, and the
            // derived classes may provide a chain of overriden
            // variables.
            string name = elementRuntime.mAssociatedNamedObjectSave.InstanceName;

            IElement element = this.AssociatedIElement;
            List<NamedObjectSave> nosList = new List<NamedObjectSave>();
            do
            {
                NamedObjectSave nos = element.GetNamedObject(name);

                if (nos != null && (nos.DefinedByBase || nos == elementRuntime.mAssociatedNamedObjectSave))
                {
                    nosList.Add(nos);
                }

                element = ObjectFinder.Self.GetIElement(element.BaseElement);

            } while (element != null);


            // Start with the most derived, so do a reverse for loop
            for (int i = nosList.Count - 1; i > -1; i--)
            {
                SetVariablesForNamedObject(objectToSet, nosList[i]);
            }
        }
        protected override void CreatePolygonForScalableEntity(ElementRuntime element)
        {
            base.CreatePolygonForScalableEntity(element);

            float scaleX = (float)element.AssociatedNamedObjectSave.GetEffectiveValue("ScaleX");
            float scaleY = (float)element.AssociatedNamedObjectSave.GetEffectiveValue("ScaleY");

            CreateHandles(element, scaleX, scaleY);
        }
Esempio n. 22
0
 private void GetEvaluated(ElementRuntime elementRuntime, FunctionArgs args, List<Dictionary<string, object>> localVariableStack, List<object> dotOperatorStack, out object firstEvaluated, out object secondEvaluated)
 {
     firstEvaluated = args.Parameters[0].Evaluate();
     secondEvaluated = args.Parameters[1].Evaluate();
 }
        void OnElementLoaded(object sender, EventArgs e)
        {
            //Parses the layers out of the currently selected element in Glue
            setUpLayerComboBox();

            if (mCurrentSelectedElementRuntime != null && mCurrentSelectedElementRuntime.AssociatedNamedObjectSave != null)
            {
                ElementRuntime newElementRuntime = GluxManager.CurrentElement;
                if (newElementRuntime.Name != mCurrentSelectedElementRuntime.Name)
                {
                    newElementRuntime = newElementRuntime.GetContainedElementRuntime(mCurrentSelectedElementRuntime.Name);
                }
                mCurrentSelectedElementRuntime = newElementRuntime;

                if (mCurrentSelectedElementRuntime != null)
                {
                    // The element has been reloaded which means the NamedObjectSaves and ElementRuntimes have been recreated.
                    // We need to update to that:
                    entityControlControls.SetCurrentNamedObject(
                        mCurrentSelectedElementRuntime,
                        mCurrentSelectedElementRuntime.AssociatedNamedObjectSave);
                }
            }
        }
        private void SelectElement(ElementRuntime elementRuntimeOver)
        {
            mCurrentSelectedElementRuntime = elementRuntimeOver;

            if (mCurrentSelectedElementRuntime != null && mCurrentSelectedElementRuntime.AssociatedNamedObjectSave != null)
            {
                entityControlControls.SetCurrentNamedObject(
                    mCurrentSelectedElementRuntime,
                    mCurrentSelectedElementRuntime.AssociatedNamedObjectSave);
            }

            if (mScalingHandles.IsElementRuntimeScalable(mCurrentSelectedElementRuntime))
            {
                mScalingHandles.CurrentElement = mCurrentSelectedElementRuntime;
            }
            else
            {
                mScalingHandles.CurrentElement = null;
            }

            mRotationHandles.CurrentElement = mCurrentSelectedElementRuntime;

            if (mCurrentSelectedElementRuntime == null)
            {
                mCurrentAction = ActionType.None;
            }
            else
            {
                mCurrentAction = ActionType.Move;
            }
        }
Esempio n. 25
0
        public string GetTypeStringForValue(string leftOfEquals, ElementRuntime elementRuntime, CodeContext codeContext, out Type runtimeType)
        {
            // try using the new method:
            var leftReference = mExpressionParser.EvaluateExpression(leftOfEquals, codeContext, ExpressionParseType.GetReference);

            if (leftReference != null)
            {
                if (leftReference is IAssignableReference)
                {
                    Type type = ((IAssignableReference)leftReference).TypeOfReference;
                    runtimeType = type;
                    string toReturn = null;
                    if (runtimeType != null)
                    {
                        toReturn = runtimeType.FullName;
                    }
                    return toReturn;
                }
                else
                {
                    runtimeType = null;
                    return null;
                }

            }
            else
            {


                string leftSideRaw = leftOfEquals;
                string leftSideContainer = null;
                if (leftOfEquals.Contains('.'))
                {
                    // That means the user is setting a value on a contained object, so let's see what the raw variable is
                    int lastDot = leftOfEquals.LastIndexOf('.');

                    leftSideRaw = leftOfEquals.Substring(lastDot + 1, leftSideRaw.Length - (lastDot + 1));
                    leftSideContainer = leftOfEquals.Substring(0, lastDot);
                }

                if (leftSideContainer == null)
                {
                    if (elementRuntime != null)
                    {

                        if (IsStateVariable(leftSideRaw, elementRuntime))
                        {
                            runtimeType = typeof(string);
                            return "String";
                        }
                    }

                    FieldInfo fieldInfo = mAllFields.GetFieldByName(leftSideRaw);
                    if (fieldInfo != null)
                    {
                        runtimeType = fieldInfo.FieldType;
                        return fieldInfo.FieldType.ToString();
                    }

                    PropertyInfo propertyInfo = mAllProperties.GetPropertyByName(leftSideRaw);
                    if (propertyInfo != null)
                    {
                        runtimeType = propertyInfo.PropertyType;
                        return propertyInfo.PropertyType.ToString();
                    }
                }
                // reverse loop so we get the inner-most variables first
                for (int i = mCallStackVariables.Count - 1; i > -1; i--)
                {
                    Dictionary<string, object> variableDictionary = mCallStackVariables[i];


                    if (variableDictionary.ContainsKey(leftSideRaw))
                    {
                        runtimeType = variableDictionary[leftSideRaw].GetType();
                        return runtimeType.ToString();
                    }

                }

                if (leftSideContainer != null)
                {
                    ElementRuntime containerElementRuntime = elementRuntime.GetContainedElementRuntime(leftSideContainer);

                    if (containerElementRuntime != null)
                    {
                        return GetTypeStringForValue(leftSideRaw, containerElementRuntime, codeContext, out runtimeType);
                    }
                }

                // If we got this far we should try to get the type through reflection
                GetTypeFromReflection(leftOfEquals, out runtimeType, null);

                if (runtimeType != null)
                {
                    return runtimeType.ToString();
                }
                else
                {
                    return null;
                }
            }
        }
Esempio n. 26
0
        private void CreateElementRuntime()
        {
            mElementRuntime = new ElementRuntime(mEntitySave, null, null, null, null);

            mContainerElementRuntime = new ElementRuntime(mContainer, null, null, null, null);
        }
Esempio n. 27
0
 static void OnElementHighlighted(ElementRuntime elementRuntime)
 {
     PluginManager.ReactToElementHighlight();
 }
Esempio n. 28
0
        private void SetVariablesForNamedObject(object newlyCreatedElementRuntime, NamedObjectSave n)
        {
            if (newlyCreatedElementRuntime != null)
            {
                ElementRuntime containedElementRuntime = GetContainedElementRuntime(n);

                Type typeOfNewObject = newlyCreatedElementRuntime.GetType();

                // As of June 24, 2012
                // States are set before
                // CustomVariables:
                if (!string.IsNullOrEmpty(n.CurrentState))
                {
                    containedElementRuntime.SetState(n.CurrentState, false);
                }


                // If it's null, this means it's a default value so don't set anything
                foreach (CustomVariableInNamedObject cvino in n.InstructionSaves.Where(cvino => cvino.Value != null))
                {
                    // If there isn't a TypedMember for the variable, that means Glue won't generate code for it, so we shouln't be applying it.
                    if (!ShouldApplyVariableOnRuntime(cvino, n))
                    {
                        continue;
                    }

                    try
                    {
                        // We used to execute
                        // the Instructions right
                        // on the element runtime itself
                        // but I think it's best if we use
                        // the CustomVariable code so that we
                        // get all the benefit of CustomVariables
                        // like loading of files, and calling events.
                        //cvino.ToInstruction(newlyCreatedElementRuntime).Execute();

                        // Update May 25, 2012
                        // We used to get the ElementRuntime
                        // for the NamedObjectSave and have it
                        // set the CustomVariable - however this
                        // doesn't work because it tries to access
                        // files within its own scope, instead of files
                        // that belong to "this".
                        //CustomVariable customVariable = new CustomVariable();
                        //customVariable.Type = cvino.Type;
                        ////customVariable.SourceObject = n.InstanceName;
                        ////customVariable.SourceObjectProperty = cvino.Member;
                        //customVariable.DefaultValue = cvino.Value;
                        //customVariable.Name = cvino.Member;
                        //containedElementRuntime.SetCustomVariable(customVariable, customVariable.DefaultValue, false);

                        CustomVariable customVariable = new CustomVariable();
                        customVariable.Type                 = cvino.Type;
                        customVariable.SourceObject         = n.InstanceName;
                        customVariable.SourceObjectProperty = cvino.Member;
                        customVariable.DefaultValue         = cvino.Value;
                        customVariable.Name                 = cvino.Member;
                        if (cvino.Value is string && customVariable.GetIsFile())
                        {
                            // We want to load the file at this level and pass the result down:
                            ReferencedFileSave rfs         = GetReferencedFileFromName(cvino.Value);
                            object             fileRuntime = null;

                            if (rfs == null)
                            {
                                fileRuntime = null;
                            }
                            else
                            {
                                fileRuntime = LoadReferencedFileSave(rfs, true, this.AssociatedIElement);
                            }

                            customVariable.DefaultValue = fileRuntime;
                        }
                        if (customVariable.DefaultValue is float && customVariable.SourceObjectProperty == "Z" &&
                            newlyCreatedElementRuntime is PositionedObject && ((PositionedObject)newlyCreatedElementRuntime).Parent == Camera.Main)
                        {
                            float value = (float)customVariable.DefaultValue - 40;

                            customVariable.DefaultValue = value;
                        }
                        SetCustomVariable(customVariable, mAssociatedIElement, customVariable.DefaultValue, false);
                    }
                    catch (Exception e)
                    {
                        int m = 3;
                        m++;
                        // for now, do nothing
                    }
                }
            }
        }
Esempio n. 29
0
        public static CustomVariable GetCustomVariableFromNosOrElement(ElementRuntime elementRuntime, string variableName)
        {
            CustomVariable variable = elementRuntime.AssociatedIElement.GetCustomVariableRecursively(variableName);



            if (variable != null)
            {

                // The NOS may be overwriting the value from the element, so we need to set that if so:
                if (elementRuntime.AssociatedNamedObjectSave != null)
                {
                    NamedObjectSave nos = elementRuntime.AssociatedNamedObjectSave;

                    InstructionSave instruction = nos.GetInstructionFromMember(variable.Name);

                    if (instruction != null && instruction.Value != null)
                    {
                        variable = variable.Clone();
                        variable.DefaultValue = instruction.Value;
                    }
                }
            }
            return variable;
        }
Esempio n. 30
0
        private void ApplyEventResponseSave(ElementRuntime elementRuntime, EventResponseSave ers)
        {
            IElement element = elementRuntime.AssociatedIElement;
            string projectDirectory = FileManager.GetDirectory(GlueViewState.Self.CurrentGlueProjectFile);
            string[] lines = GetMethodLines(element, ers, projectDirectory);
            string fileName = EventResponseSave.GetSharedCodeFullFileName(element, projectDirectory);

            CodeContext codeContext = new CodeContext(elementRuntime);
            ApplyLinesInternal(lines, 0, lines.Length, element, codeContext, fileName);
        }
Esempio n. 31
0
        private bool GetFloatValue(ElementRuntime elementRuntime, FunctionArgs args, string variableName)
        {
            float valueToSet = float.NaN;
            bool wasSet = false;
            switch (variableName)
            {
                case "PositiveInfinity":
                    valueToSet = float.PositiveInfinity;
                    wasSet = true;
                    break;
                case "NegativeInfinity":
                    valueToSet = float.NegativeInfinity;
                    wasSet = true;
                    break;
                case "MaxValue":
                    valueToSet = float.MaxValue;
                    wasSet = true;
                    break;
                case "MinValue":
                    valueToSet = float.MinValue;
                    wasSet = true;
                    break;
            }

            if (wasSet)
            {
                args.Result = valueToSet;
            }

            return wasSet;
        }
 public void SetCurrentNamedObject(ElementRuntime elementRuntime, NamedObjectSave nos)
 {
     mPropertyGridManager.Show(elementRuntime, nos);
 }
Esempio n. 33
0
        private void EvaluateFunctionGetStaticMember(ElementRuntime elementRuntime, FunctionArgs args, CodeContext codeContext)
        {

            string argument = (string)args.Parameters[0].ParsedExpression.ToString();

            string value = (string) mExpressionParser.EvaluateExpression(argument, codeContext);

            ReferencedFileSave rfs = elementRuntime.AssociatedIElement.GetReferencedFileSaveByInstanceNameRecursively(value);

            args.Result = elementRuntime.LoadReferencedFileSave(rfs, true, elementRuntime.AssociatedIElement);
        }
Esempio n. 34
0
        public void TestSceneTypes()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "NosSceneTest";

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.InstanceName = "NamedScene";
            nos.SourceClassType = "Scene";
            entitySave.NamedObjects.Add(nos);

            ElementRuntime elementRuntime = new ElementRuntime(entitySave, null, null, null, null);

            if (elementRuntime.ContainedElements.Count == 0)
            {
                throw new Exception("ElementRuntimes with Scene NOS's should create ElementRuntimes for the Scene NOS");
            }

            if (elementRuntime.ContainedElements[0].DirectObjectReference is Scene == false)
            {
                throw new Exception("Scene NOS's should create Scenes");
            }

            if (((Scene)elementRuntime.ContainedElements[0].DirectObjectReference).Name != nos.InstanceName)
            {
                throw new Exception("Name on Scenes are not being set from NOS's");
            }

        }
Esempio n. 35
0
        public static void InterpolateBetween(ElementRuntime elementRuntime, object firstStateSaveAsObject, object secondStateSaveAsObject, object interpolationValueAsObject,
            StringBuilder logStringBuilder = null)
        {
            StateSave firstStateSave = firstStateSaveAsObject as StateSave;
            StateSave secondStateSave = secondStateSaveAsObject as StateSave;
            float interpolationValue = 0;

            if (interpolationValueAsObject is float)
            {
                interpolationValue = (float)interpolationValueAsObject;
            }
            if (interpolationValueAsObject is double)
            {
                interpolationValue = (float)((double)interpolationValueAsObject);
            }
            else if (interpolationValueAsObject is int)
            {
                interpolationValue = (int)interpolationValueAsObject;
            }

            if (float.IsNaN(interpolationValue))
            {
                throw new Exception("InterpolationValue is NaN");
            }

            StateSave resultingStateSave = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstStateSave, secondStateSave, interpolationValue);
            string nameOfObject = "unnamed object";
            if (elementRuntime.AssociatedNamedObjectSave != null)
            {
                nameOfObject = elementRuntime.AssociatedNamedObjectSave.ToString();
            }
            else if (elementRuntime.AssociatedIElement != null)
            {
                nameOfObject = elementRuntime.AssociatedIElement.ToString();
            }
            if (logStringBuilder != null)
            {
                logStringBuilder.AppendLine("Interpolating " + nameOfObject + " between " + firstStateSave + " and " + secondStateSave + " with value " + interpolationValue);

                foreach (InstructionSave instruction in resultingStateSave.InstructionSaves)
                {
                    logStringBuilder.AppendLine("\t" + instruction);
                }
            }

            try
            {
                elementRuntime.SetState(resultingStateSave, elementRuntime.AssociatedIElement);
            }
            catch (Exception e)
            {
                throw new StateSettingException("Error in script trying to interpolate " + nameOfObject + " between " + firstStateSave + " and " + secondStateSave + " with value " + interpolationValue);
            }
        }
        /// <summary>
        /// Checks to see if the elemenetRuntime is owned by another file
        /// </summary>
        /// <param name="elementRuntimeOver">The ElementRuntime to check</param>
        /// <returns>Whether the elementRuntime is owned by a file</returns>
        private bool CheckForSourceFile(ElementRuntime elementRuntimeOver)
        {
            if (elementRuntimeOver == null)
            {
                return false;
            }
            else if (elementRuntimeOver.AssociatedNamedObjectSave == null)
            {
                return false;
            }
            else if (elementRuntimeOver.AssociatedNamedObjectSave.SourceFile == null)
            {
                return false;
            }

            return true;
        }
        private object CreateFlatRedBallTypeNos(NamedObjectSave namedObjectSave, 
            PositionedObjectList<ElementRuntime> listToPopulate, Layer layerToPutOn)
        {
            object returnObject = null;

            ElementRuntime newElementRuntime = null;

            switch (namedObjectSave.SourceClassType)
            {
                case "Layer":
                case "FlatRedBall.Graphics.Layer":
                    returnObject = CreateLayerObject(namedObjectSave, returnObject);
                    break;
                case "AxisAlignedRectangle":
                case "FlatRedBall.Math.Geometry.AxisAlignedRectangle":
                    AxisAlignedRectangle aaRectangle = ShapeManager.AddAxisAlignedRectangle();
                    if (layerToPutOn != null)
                    {
                        ShapeManager.AddToLayer(aaRectangle, layerToPutOn);
                    }
                    aaRectangle.Name = namedObjectSave.InstanceName;
                    returnObject = aaRectangle;
                    break;
                case "Camera":
                case "FlatRedBall.Camera":
                    if (namedObjectSave.IsNewCamera)
                    {
                        returnObject = null;
                    }
                    else
                    {
                        returnObject = SpriteManager.Camera;
                    }
                    break;
                case "Circle":
                case "FlatRedBall.Math.Geometry.Circle":
                    Circle circle = ShapeManager.AddCircle();
                    circle.Name = namedObjectSave.InstanceName;
                    if (layerToPutOn != null)
                    {
                        ShapeManager.AddToLayer(circle, layerToPutOn);
                    }
                    returnObject = circle;

                    break;
                case "Polygon":
                case "FlatRedBall.Math.Geometry.Polygon":
                    Polygon polygon = ShapeManager.AddPolygon();
                    polygon.Name = namedObjectSave.InstanceName;

                    if(layerToPutOn != null)
                    {
                        ShapeManager.AddToLayer(polygon, layerToPutOn);
                    }
                    returnObject = polygon;

                    break;
                case "Sprite":
                case "FlatRedBall.Sprite":
                    Sprite sprite = SpriteManager.AddSprite((Texture2D)null);
                    if (layerToPutOn != null)
                    {
                        SpriteManager.AddToLayer(sprite, layerToPutOn);
                    }
                    sprite.Name = namedObjectSave.InstanceName;
                    returnObject = sprite;
                    break;
                case "SpriteFrame":
                case "FlatRedBall.ManagedSpriteGroups.SpriteFrame":
                    SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All);
                    if (layerToPutOn != null)
                    {
                        SpriteManager.AddToLayer(spriteFrame, layerToPutOn);
                    }
                    spriteFrame.Name = namedObjectSave.InstanceName;
                    returnObject = spriteFrame;
                    break;
                case "Text":
                case "FlatRedBall.Graphics.Text":
                    Text text = TextManager.AddText("");
                    if (layerToPutOn != null)
                    {
                        TextManager.AddToLayer(text, layerToPutOn);
                        text.SetPixelPerfectScale(layerToPutOn);
                    }
                    text.Name = namedObjectSave.InstanceName;
                    returnObject = text;
                    break;
                case "Scene":
                case "FlatRedBall.Scene":
                    Scene scene = new Scene();

                    scene.Name = namedObjectSave.InstanceName;
                    returnObject = scene;
                    break;
                default:
                    // do nothing - need to add more types?
                    break;
            }

            if (returnObject != null)
            {
                if (returnObject is IScalable)
                {
                    newElementRuntime = new ScalableElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                else
                {
                    newElementRuntime = new ElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                newElementRuntime.mDirectObjectReference = returnObject;

                if (returnObject is Camera && !namedObjectSave.IsNewCamera)
                {
                    SpriteManager.Camera.AttachTo(newElementRuntime, false);
                    SpriteManager.Camera.RelativePosition = Vector3.Zero;
                    newElementRuntime.Z = 40;
                    newElementRuntime.Name = namedObjectSave.InstanceName;
                }
                else if (returnObject is FlatRedBall.Utilities.INameable)
                {
                    newElementRuntime.Name = ((FlatRedBall.Utilities.INameable)returnObject).Name;
                }
                else
                {
                    object nameValueAsObject;
                    if (LateBinder.TryGetValueStatic(returnObject, "Name", out nameValueAsObject))
                    {

                        newElementRuntime.Name = (string)nameValueAsObject;

                    }
                }

                listToPopulate.Add(newElementRuntime);
            }

            return returnObject;
        }