コード例 #1
0
        // This method paints a graphical representation of the
        // selected value of the LightShpae property.
        public override void PaintValue(PaintValueEventArgs e)
        {
            if (e.Bounds.Left == 1 && e.Bounds.Top == 1)
            {
                if (e.Context.Instance is StateSavePropertyGridDisplayer)
                {
                    FlatRedBall.Glue.SaveClasses.StateSave stateSave =
                        ((StateSavePropertyGridDisplayer)e.Context.Instance).Instance as StateSave;

                    PropertyInfo[] properties = e.Context.GetType().GetProperties();

                    PropertyInfo info = e.Context.GetType().GetProperty("PropertyName");



                    string variableName = (string)info.GetValue(e.Context, null);

                    CustomVariable variable = GlueState.Self.CurrentElement.GetCustomVariable(variableName);
                    if (variable != null)
                    {
                        InterpolationCharacteristic interpolationCharacteristic =
                            CustomVariableHelper.GetInterpolationCharacteristic(variable, GlueState.Self.CurrentElement);

                        Image bitmap = null;
                        if (interpolationCharacteristic == InterpolationCharacteristic.CanInterpolate ||
                            (interpolationCharacteristic == InterpolationCharacteristic.NeedsVelocityVariable && variable.HasAccompanyingVelocityProperty))
                        {
                            bitmap = mCanInterpolate;
                        }
                        else if (interpolationCharacteristic == InterpolationCharacteristic.NeedsVelocityVariable)
                        {
                            bitmap = mNeedsVelocityVariable;
                        }
                        else
                        {
                            bitmap = mCantInterpolate;
                        }

                        e.Graphics.DrawImage(bitmap, e.Bounds.Left, e.Bounds.Top, bitmap.Width, bitmap.Height);
                    }
                }
            }
            else
            {
                //e.Graphics.DrawEllipse(Pens.Yellow, e.Bounds);
            }
        }
コード例 #2
0
        public void TestStateVariables()
        {
            bool result = CustomVariableHelper.IsStateMissingFor(mExposedStateInCategoryVariable, mEntitySave);

            if (result)
            {
                throw new Exception("This variable does have a state associated with it, so this shouldn't be true");
            }

            // Make a dummy state that should have its state missing
            CustomVariable variable = new CustomVariable();

            variable.Name = "CurrentCategoryThatDoesntExistState";
            variable.Type = "CategoryThatDoesntExist";
            result        = CustomVariableHelper.IsStateMissingFor(variable, mEntitySave);
            if (!result)
            {
                throw new Exception("This variable does not have an associated category");
            }
        }
コード例 #3
0
        private static void ReactToChangedHasAccompanyingVelocityProperty(CustomVariable customVariable)
        {
            if (customVariable.HasAccompanyingVelocityProperty)
            {
                // The user just
                // set this to true,
                // but we should check
                // if this is a good idea
                // or not - there may already
                // be a velocity variable for this.
                if (string.IsNullOrEmpty(customVariable.SourceObject))
                {
                    // todo:  fill this in
                }
                else
                {
                    // We want to set the accompanying to false before checking this, then back to true.
                    customVariable.HasAccompanyingVelocityProperty = false;
                    InterpolationCharacteristic characteristic =
                        CustomVariableHelper.GetInterpolationCharacteristic(customVariable, EditorLogic.CurrentElement);
                    customVariable.HasAccompanyingVelocityProperty = true;

                    if (characteristic == InterpolationCharacteristic.CantInterpolate)
                    {
                        MessageBox.Show("The variable " + customVariable.SourceObjectProperty + " cannot be interpolated.");
                        customVariable.HasAccompanyingVelocityProperty = false;
                    }
                    else if (characteristic == InterpolationCharacteristic.CanInterpolate)
                    {
                        string velocityMember =
                            FlatRedBall.Instructions.InstructionManager.GetVelocityForState(customVariable.SourceObjectProperty);
                        MessageBox.Show("The variable " + customVariable.SourceObjectProperty + " already has a built-in " +
                                        "velocity member named " + velocityMember + "\n\nThere is no need to set an accompanying velocity property. " +
                                        "Glue will undo this change now.");

                        customVariable.HasAccompanyingVelocityProperty = false;
                    }
                }
            }
        }
コード例 #4
0
        public void TestInterpolationCharacteristics()
        {
            CustomVariable variable = new CustomVariable();

            variable.Name = "Whatever";
            variable.Type = "int";

            if (CustomVariableHelper.GetInterpolationCharacteristic(variable, null) !=
                InterpolationCharacteristic.NeedsVelocityVariable)
            {
                throw new Exception("int varaibles should be interpolatable if given a velocity variable, but this one says it can't.");
            }

            variable.Name = "X";
            var characteristic = CustomVariableHelper.GetInterpolationCharacteristic(variable, new EntitySave());

            if (characteristic != InterpolationCharacteristic.CanInterpolate)
            {
                throw new Exception("int varaibles should be able to interpolate, but this one says it can't.");
            }

            variable.Name = "Whatever";
            variable.Type = "string";

            if (CustomVariableHelper.GetInterpolationCharacteristic(variable, null) !=
                InterpolationCharacteristic.CantInterpolate)
            {
                throw new Exception("string varaibles should not be able to interpolate, but this one says it can (or might be able to).");
            }



            variable.OverridingPropertyType = "int";

            if (CustomVariableHelper.GetInterpolationCharacteristic(variable, null) ==
                InterpolationCharacteristic.CantInterpolate)
            {
                throw new Exception("OverridingPropertyType variables are not properly setting whether they can interpolate or not");
            }
        }
コード例 #5
0
        private static void CreateStartingValueVariables(IElement element, List <StateSave> states, ICodeBlock curBlock, Dictionary <InstructionSave, InterpolationCharacteristic> interpolationCharacteristics)
        {
            foreach (StateSave state in states)
            {
                foreach (InstructionSave instructionSave in state.InstructionSaves)
                {
                    string member = instructionSave.Member;

                    if (!ContainsKey(interpolationCharacteristics, member))
                    {
                        CustomVariable customVariable = element.GetCustomVariable(member);

                        NamedObjectSave nos = null;

                        if (customVariable != null)
                        {
                            nos = element.GetNamedObjectRecursively(customVariable.SourceObject);
                        }

                        if (nos == null || nos.IsDisabled == false)
                        {
                            InterpolationCharacteristic interpolationCharacteristic =
                                CustomVariableHelper.GetInterpolationCharacteristic(customVariable, element);

                            interpolationCharacteristics.Add(instructionSave, interpolationCharacteristic);

                            if (interpolationCharacteristic != InterpolationCharacteristic.CantInterpolate)
                            {
                                curBlock.Line("bool set" + instructionSave.Member + " = true;");

                                string defaultStartingValue = "";


                                try
                                {
                                    if (customVariable.GetIsVariableState())
                                    {
                                        IElement stateContainingEntity = null;

                                        if (nos != null)
                                        {
                                            stateContainingEntity = ObjectFinder.Self.GetIElement(nos.SourceClassType);
                                        }
                                        else if (string.IsNullOrEmpty(customVariable.SourceObject))
                                        {
                                            stateContainingEntity = element;
                                        }


                                        if (stateContainingEntity != null)
                                        {
                                            string stateType = "VariableState";
                                            if (customVariable != null && customVariable.Type.ToLower() != "string")
                                            {
                                                stateType = customVariable.Type;
                                            }

                                            defaultStartingValue = StateCodeGenerator.FullyQualifiedDefaultStateValue(stateContainingEntity, stateType);
                                        }
                                    }
                                    else
                                    {
                                        defaultStartingValue = TypeManager.GetDefaultForType(instructionSave.Type);
                                    }
                                }
                                catch
                                {
                                    throw new Exception("Could not get a default value for " + instructionSave.Member + " of type " + instructionSave.Type);
                                }


                                string type = CustomVariableCodeGenerator.GetMemberTypeFor(customVariable, element);

                                curBlock.Line(type + " " + member + FirstValue + "= " + defaultStartingValue + ";");
                                curBlock.Line(type + " " + member + SecondValue + "= " + defaultStartingValue + ";");
                            }
                        }
                    }
                }
            }
        }