Esempio n. 1
0
        public static string MakeLocalizedIfNecessary(NamedObjectSave namedObject, string variableName, object valueAsObject, string valueAsString, CustomVariable customVariable)
        {
            // This code will convert something like
            //      someVariable = "Hello";
            // to
            //      someVariable = LocalizationManager.Translate("Hello");

            // This code gets called on states.
            // If it's a state, then we find the 
            // custom variable that the state represents
            // and pass it as the last argument in the method.
            // We can look at that custom variable to see if it's
            // an AnimationChain

            if (ObjectFinder.Self.GlueProject != null && 
                ObjectFinder.Self.GlueProject.UsesTranslation && valueAsObject is string && (customVariable == null || customVariable.Type != "Color"))//&& !namedObject.IsAnimationChain)
            {
                if (customVariable != null && customVariable.GetIsAnimationChain())
                {
                    // do nothing
                }
                else if (namedObject != null && namedObject.SourceType == SourceType.File)
                {
                    if (variableName != "CurrentChain" // CurrentChain is used by some FRB types
                        && variableName != "CurrentChainName" // and CurrentChainName is used by others....sucky.
                        )
                    {
                        valueAsString = "FlatRedBall.Localization.LocalizationManager.Translate(" + valueAsString + ")";
                    }
                }
                else if (namedObject != null && namedObject.SourceType == SourceType.Entity)
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(namedObject.SourceClassType);

                    if (entitySave != null)
                    {
                        CustomVariable variableInEntity = entitySave.GetCustomVariable(variableName);

                        if (variableInEntity == null || variableInEntity.GetIsAnimationChain() == false)
                        {
                            valueAsString = "FlatRedBall.Localization.LocalizationManager.Translate(" + valueAsString + ")";
                        }
                    }
                }
                else if (namedObject != null && namedObject.SourceType == SourceType.FlatRedBallType)
                {
                    if (namedObject.SourceClassType == "Text" && variableName == "DisplayText")
                    {
                        valueAsString = "FlatRedBall.Localization.LocalizationManager.Translate(" + valueAsString + ")";
                    }
                }
            }
            return valueAsString;
        }
Esempio n. 2
0
        private object CastAndTranslateValueToSet(CustomVariable cv, object valueToSetTo)
        {
            if (cv.Type == "Color")
            {
                if (valueToSetTo == null || string.IsNullOrEmpty(valueToSetTo as string))
                {

                }
                Type colorType = typeof(Color);
                PropertyInfo propertyInfo = colorType.GetProperty((string)valueToSetTo, BindingFlags.Public | BindingFlags.Static);

                Color colorToSet = (Color)(propertyInfo.GetValue(null, null));
                return colorToSet;
            }
            else if (cv.Type == "string" && valueToSetTo is string)
            {
                if (cv.GetIsFile())
                {
                    // do noting
                }
                else if (cv != null && cv.GetIsAnimationChain())
                {
                    // do nothing
                }
                else if (LocalizationManager.HasDatabase)
                {
                    valueToSetTo = LocalizationManager.Translate((string)valueToSetTo);
                }
                //else if (namedObject.SourceType == SourceType.File)
                //{
                //    if (instructionSave.Member != "CurrentChain")
                //    {
                //        value = "LocalizationManager.Translate(" + value + ")";
                //    }
                //}
                //else if (namedObject.SourceType == SourceType.Entity)
                //{
                //    EntitySave entitySave = ObjectFinder.GetEntitySave(namedObject.SourceClassType);

                //    if (entitySave != null)
                //    {
                //        CustomVariable variableInEntity = entitySave.GetCustomVariable(instructionSave.Member);

                //        if (variableInEntity == null || variableInEntity.IsAnimationChain == false)
                //        {
                //            value = "LocalizationManager.Translate(" + value + ")";
                //        }
                //    }
                //}





                return valueToSetTo;
            }
            else
            {
                return valueToSetTo;
            }
        }