Example #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);
            }
        }
        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;
                    }
                }
            }
        }
Example #3
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 + ";");
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        private void CreateStartingValueVariables(ElementSave element, IEnumerable <StateSave> states, ICodeBlock curBlock, Dictionary <VariableSave, InterpolationCharacteristic> interpolationCharacteristics)
        {
            foreach (StateSave state in states)
            {
                var variables = state.Variables.Where(item => GetIfShouldGenerateStateVariable(item, element)).ToList();

                foreach (VariableSave variableSave in variables)
                {
                    string member = variableSave.MemberNameInCode(element, VariableNamesToReplaceForStates);

                    if (!ContainsKey(interpolationCharacteristics, member, element))
                    {
                        InterpolationCharacteristic interpolationCharacteristic =
                            GetInterpolationCharacteristic(variableSave, element);

                        interpolationCharacteristics.Add(variableSave, interpolationCharacteristic);

                        if (interpolationCharacteristic != InterpolationCharacteristic.CantInterpolate)
                        {
                            string stringSuffix = variableSave.MemberNameInCode(element, VariableNamesToReplaceForStates).Replace(".", "");
                            curBlock.Line("bool set" + stringSuffix + FirstValue + " = false;");
                            curBlock.Line("bool set" + stringSuffix + SecondValue + " = false;");

                            string defaultStartingValue = "";

                            string type = variableSave.Type;

                            try
                            {
                                ElementSave       categoryContainer;
                                StateSaveCategory stateSaveCategory;
                                if (variableSave.IsState(element, out categoryContainer, out stateSaveCategory, recursive:false))
                                {
                                    type = categoryContainer.MemberTypeInCode() + "Runtime.VariableState";
                                    string defaultValue = "Default";
                                    if (stateSaveCategory != null)
                                    {
                                        type         = categoryContainer.MemberTypeInCode() + "Runtime." + stateSaveCategory.Name;
                                        defaultValue = stateSaveCategory.States.First().MemberNameInCode();
                                    }

                                    defaultStartingValue = FlatRedBall.IO.FileManager.RemovePath(type) + "." + defaultValue;
                                }
                                else
                                {
                                    defaultStartingValue = FlatRedBall.Glue.Parsing.TypeManager.GetDefaultForType(variableSave.Type);
                                }
                            }
                            catch
                            {
                                throw new Exception("Could not get a default value for " + variableSave.GetRootName() + " of type " + variableSave.Type);
                            }



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