예제 #1
0
        /// <summary>Add a new phrase to this localization, or return the current one.</summary>
        public LeanPhrase AddPhrase(string phraseName)
        {
            if (Phrases == null)
            {
                Phrases = new List <LeanPhrase>();
            }

            var phrase = Phrases.Find(p => p.Name == phraseName);

            if (phrase == null)
            {
                phrase = new LeanPhrase();

                phrase.Name = phraseName;

                Phrases.Add(phrase);
            }

            return(phrase);
        }
        private void DrawTranslations(LeanLocalization localization, LeanPhrase phrase)
        {
            existingLanguages.Clear();

            for (var i = 0; i < phrase.Translations.Count; i++)
            {
                var labelA      = Reserve();
                var valueA      = Reserve(ref labelA, 20.0f);
                var translation = phrase.Translations[i];

                if (translationIndex == i)
                {
                    BeginModifications();
                    {
                        translation.Language = EditorGUI.TextField(labelA, "", translation.Language);
                    }
                    EndModifications();

                    if (GUI.Button(valueA, "X") == true)
                    {
                        MarkAsModified();

                        phrase.Translations.RemoveAt(i); translationIndex = -1;
                    }
                }

                if (EditorGUI.Foldout(labelA, translationIndex == i, translationIndex == i ? "" : translation.Language) == true)
                {
                    translationIndex = i;

                    EditorGUI.indentLevel += 1;
                    {
                        DrawTranslation(translation);
                    }
                    EditorGUI.indentLevel -= 1;

                    EditorGUILayout.Separator();
                }
                else if (translationIndex == i)
                {
                    translationIndex = -1;
                }

                if (existingLanguages.Contains(translation.Language) == true)
                {
                    EditorGUILayout.HelpBox("This phrase has already been translated to this language!", MessageType.Warning);
                }
                else
                {
                    existingLanguages.Add(translation.Language);
                }

                if (localization.Languages.Contains(translation.Language) == false)
                {
                    EditorGUILayout.HelpBox("This translation uses a language that hasn't been set in the localization!", MessageType.Warning);
                }
            }

            for (var i = 0; i < localization.Languages.Count; i++)
            {
                var language = localization.Languages[i];

                if (phrase.Translations.Exists(t => t.Language == language) == false)
                {
                    var labelA = Reserve();
                    var valueA = Reserve(ref labelA, 120.0f);

                    EditorGUI.LabelField(labelA, language);

                    if (GUI.Button(valueA, "Create Translation") == true)
                    {
                        MarkAsModified();

                        var newTranslation = new LeanTranslation();

                        newTranslation.Language = language;
                        newTranslation.Text     = phrase.Name;

                        translationIndex = phrase.Translations.Count;

                        phrase.Translations.Add(newTranslation);
                    }
                }
            }
        }