public void TestRegularVisibility()
        {
            CustomVariable visibleVariable = mEntitySave.GetCustomVariable("Visible");

            mElementRuntime.SetCustomVariable(visibleVariable, mElementRuntime.AssociatedIElement, false, false);


            ElementRuntime containedElementRuntime = mElementRuntime.ContainedElements[0] as ElementRuntime;

            Sprite sprite = containedElementRuntime.DirectObjectReference as Sprite;

            if (sprite.AbsoluteVisible)
            {
                throw new Exception("Sprite is visible, but it is part of an element runtime that isn't, so it shouldn't be");
            }


            sprite.Visible = false;
            mElementRuntime.SetCustomVariable(visibleVariable, mElementRuntime.AssociatedIElement, true, false);

            if (sprite.Visible)
            {
                throw new Exception("The Sprite should still have a relative Visibility of true, even though the parent is false");
            }

            sprite.Visible = true;
            if (!sprite.AbsoluteVisible)
            {
                throw new Exception("The Sprite should be visible now!");
            }
        }
        public void ApplyChangeVariables(PositionedObject objectToResize, float cursorXChange, float cursorYChange,
                                         float xChangeCoef, float yChangeCoef)
        {
            //IScalable
            if (objectToResize is IScalable)
            {
                IScalable scalable = (IScalable)objectToResize;
                //Scale
                if (scalable.ScaleX + cursorXChange < 0)
                {
                    scalable.ScaleX = 0;
                    xChangeCoef     = 0;
                }
                else
                {
                    scalable.ScaleX += cursorXChange;
                }

                if (scalable.ScaleY + cursorYChange < 0)
                {
                    scalable.ScaleY = 0;
                    yChangeCoef     = 0;
                }
                else
                {
                    scalable.ScaleY += cursorYChange;
                }
            }
            else if (objectToResize is ElementRuntime &&
                     ((ElementRuntime)objectToResize).AssociatedNamedObjectSave != null &&
                     ((ElementRuntime)objectToResize).AssociatedNamedObjectSave.GetIsScalableEntity())
            {
                ElementRuntime currentElement = objectToResize as ElementRuntime;
                float          scaleX         = (float)currentElement.AssociatedNamedObjectSave.GetEffectiveValue("ScaleX");
                float          scaleY         = (float)currentElement.AssociatedNamedObjectSave.GetEffectiveValue("ScaleY");

                IElement       entitySave = currentElement.AssociatedIElement;
                CustomVariable variable   = entitySave.GetCustomVariable("ScaleX").Clone();

                variable.DefaultValue = scaleX + cursorXChange;
                currentElement.AssociatedNamedObjectSave.GetCustomVariable("ScaleX").Value = scaleX + cursorXChange;
                currentElement.SetCustomVariable(variable);


                variable = entitySave.GetCustomVariable("ScaleY").Clone();
                variable.DefaultValue = scaleY + cursorYChange;
                currentElement.AssociatedNamedObjectSave.GetCustomVariable("ScaleY").Value = variable.DefaultValue;
                currentElement.SetCustomVariable(variable);
            }

            AdjustPositionsAfterScaling(objectToResize, cursorXChange, cursorYChange, xChangeCoef, yChangeCoef);
        }
        void OnPropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            string propertyName = e.ChangedItem.Label;

            CustomVariable customVariable = null;



            if (mCurrentNos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(mCurrentNos.SourceClassType))
            {
                IElement entitySave = ObjectFinder.Self.GetIElement(mCurrentNos.SourceClassType);
                customVariable = entitySave.GetCustomVariable(propertyName).Clone();
            }
            else
            {
                customVariable      = new CustomVariable();
                customVariable.Name = propertyName;
            }
            customVariable.DefaultValue = e.ChangedItem.Value;

            customVariable.Type = mCurrentNos.GetCustomVariable(propertyName).Type;
            mCurrentElementRuntime.SetCustomVariable(customVariable);

            if (mRuntimeOptions.ShouldSave)
            {
                GlueViewCommands.Self.GlueProjectSaveCommands.SaveGlux();
            }
        }
Beispiel #4
0
        private void AssignValue(string newVariableDeclarationType, string leftOfEquals, string rightOfEquals, CodeContext codeContext,
                                 AssignmentOperatorType assignOperator)
        {
            ElementRuntime elementRuntime = codeContext.ContainerInstance as ElementRuntime;
            IElement       element        = null;

            if (elementRuntime != null)
            {
                element = elementRuntime.AssociatedIElement;
            }

            CustomVariable customVariable = CreateCustomVariableFor(newVariableDeclarationType, leftOfEquals, rightOfEquals, elementRuntime, codeContext);

            if (customVariable.Name.CountOf('.') > 1)
            {
                throw new Exception("Script parsing doesn't support setting properties/fields on properties/fields.  In other words, assigning something.X is okay, but not something.Position.x");
            }

            mParserLog.AppendLine("Left side:  " + leftOfEquals + "  RightSide:  " + rightOfEquals + "    Resulting variable:   " + customVariable);

            if (newVariableDeclarationType != null)
            {
                TopOfVariableStack[leftOfEquals] = customVariable.DefaultValue;
                codeContext.VariableStack.Last().Add(leftOfEquals, customVariable.DefaultValue);
            }
            else if (customVariable != null)
            {
                if (codeContext.ContainerInstance != null)
                {
                    ElementRuntime runtime = codeContext.ContainerInstance as ElementRuntime;
                    runtime.SetCustomVariable(customVariable, runtime.AssociatedIElement, customVariable.DefaultValue, true, VariableSettingOptions.LiteralSet);
                }
                else
                {
                    var  reference   = mExpressionParser.EvaluateExpression(leftOfEquals, codeContext, ExpressionParseType.GetReference);
                    bool wasAssigned = false;

                    wasAssigned = TryAssignIAssignableReference(assignOperator, customVariable, reference);

                    if (!wasAssigned)
                    {
                        throw new Exception("Could not assign the value");
                    }
                }
            }
        }
        public void TestSettingVariableCreatedInBAse()
        {
            CustomVariable variable =
                mDerivedElementRuntime.GetCustomVariable("CurrentStateSaveCategoryState");

            ElementRuntime sourceElement;
            string         variableName;

            mDerivedElementRuntime.GetSourceElementAndVariableName(
                variable, out sourceElement, out variableName);

            if (sourceElement != mDerivedElementRuntime)
            {
                throw new Exception("GEtSourceElementAndVariableName should be returning the base ElementRuntime as the containing element but it's not.");
            }



            mDerivedElementRuntime.SetCustomVariable(variable);
        }