Ejemplo n.º 1
0
        string DrawKeys(bool useList, string currentKey)
        {
            string newKey = currentKey;

            if (useList)
            {
                string[] keyArray = LEStringTableEditor.GetLangKeys().ToArray();

                // Just make an array with the current value
                // LE Manager probably isn't loaded
                // That's ok
                if (keyArray.Length == 0)
                {
                    keyArray = new string[] { currentKey }
                }
                ;

                int currentIndex = Array.IndexOf(keyArray, currentKey);

                int newIndex = EditorGUILayout.Popup(LEConstants.KeyLbl, currentIndex, keyArray);
                if (currentIndex != newIndex && keyArray.IsValidIndex(newIndex))
                {
                    newKey = keyArray[newIndex];
                }
            }
            else
            {
                newKey = EditorGUILayout.TextField(LEConstants.KeyLbl, currentKey);
            }

            return(newKey);
        }
    }
Ejemplo n.º 2
0
        public static void GenStaticKeysClass(List <string> keys)
        {
            Debug.Log(LEConstants.GeneratingLbl + " " + LECodeGenConstants.StaticKeysFilePath);
            StringBuilder sb = new StringBuilder();

            sb.Append(LECodeGenConstants.AutoGenMsg);
            sb.Append("\n");
            sb.Append(LECodeGenConstants.StaticKeyClassHeader);

            foreach (var key in keys)
            {
                string visKey = LEStringTableEditor.Logical2Visual(key);

                sb.Append("\n");
                sb.Append("".PadLeft(LECodeGenConstants.IndentLevel2));
                sb.AppendFormat(LECodeGenConstants.StaticKeyFormat, visKey);
            }

            sb.Append("\n");
            sb.Append("}".PadLeft(LECodeGenConstants.IndentLevel1 + 1));
            sb.Append("\n");
            sb.Append("}");
            sb.Append("\n");

            File.WriteAllText(Path.Combine(LESettings.FullRootDir, LECodeGenConstants.StaticKeysFilePath), sb.ToString());
            Debug.Log(LEConstants.DoneGeneratingLbl + " " + LECodeGenConstants.StaticKeysFilePath);
            AssetDatabase.Refresh();
        }
        static string FormatCultureDisplay(LECulture culture)
        {
            string nativeName = culture.NativeName;

            if (culture.IsRightToLeft)
            {
                nativeName = LEStringTableEditor.Logical2Visual(nativeName);
            }

            return(culture.Name + " - " + nativeName +
                   (!culture.NativeName.Equals(culture.DisplayName) ? " - " + culture.DisplayName : string.Empty));
        }
Ejemplo n.º 4
0
        void DrawAddNewKey(LELocalize leLocalize)
        {
            newKey = EditorGUILayout.TextField(LEConstants.KeyLbl, newKey);
            if (!string.IsNullOrEmpty(newKey) && GUILayout.Button(LEConstants.AddStringBtn))
            {
                LEStringTableEditor.AddNewString(newKey, leLocalize.Text);
                LEStringTableEditor.Save();

                leLocalize.localized_string_key = newKey;
                nextState = LELocalizeState.Initialized;
            }
        }
        void DrawNewLocStringField()
        {
            if (isRTL)
            {
                DrawVisualPresentation(newLocKey.Equals(LEConstants.NewKeyLbl)?string.Empty:newLocKey,
                                       newLocValue.Equals(LEConstants.NewValueLbl)?string.Empty:newLocValue);
            }

            // Key label position
            newLocKey = string.IsNullOrEmpty(newLocKey) ? LEConstants.NewKeyLbl : newLocKey;
            Rect labelPosition = GetResizableTextBoxPosition(newLocKey, boxWidth, keyStyle);

            // Key box
            GUI.Box(labelPosition, string.Empty);

            // Key label
            newLocKey = DrawResizableTextBox(newLocKey, labelPosition, keyStyle);

            // Value label position
            newLocValue = string.IsNullOrEmpty(newLocValue)? LEConstants.NewValueLbl : newLocValue;
            Rect valuePosition = GetResizableTextBoxPosition(newLocValue, boxWidth, valueStyle);

            // Value box
            GUI.Box(valuePosition, string.Empty);

            // Value label
            newLocValue = DrawResizableTextBox(newLocValue, valuePosition, valueStyle);

            // Add String Button
            content.text = LEConstants.AddStringBtn;
            size         = GUI.skin.button.CalcSize(content);
            if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content) && !string.IsNullOrEmpty(newLocKey) && !string.IsNullOrEmpty(newLocValue))
            {
                try
                {
                    LEStringTableEditor.AddNewString(newLocKey, newLocValue);

                    newLocKey   = string.Empty;
                    newLocValue = string.Empty;

                    GUI.FocusControl(string.Empty);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }

            float height = Math.Max(labelPosition.height, valuePosition.height);

            drawHelper.NewLine(height / drawHelper.LineHeight - 1);
        }
        void DrawVisualPresentation(string logicalKey, string logicalValue)
        {
            Rect  labelPosition;
            Rect  valuePosition;
            float height;

            // Draw the visual representation section
            content.text = LEConstants.VisualPresentation;
            drawHelper.TryGetCachedSize(LEConstants.SizeVisualPresentationKey, content, labelStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
            drawHelper.NewLine();

            // Key label position
            string visKey = LEStringTableEditor.GetPresentationFromCache(logicalKey);

            labelPosition = GetResizableTextBoxPosition(visKey, boxWidth, keyStyle);

            // Key box
            GUI.Box(labelPosition, string.Empty);

            // Key label
            EditorGUI.SelectableLabel(labelPosition, visKey, keyStyle);
            drawHelper.CurrentLinePosition += (labelPosition.width + 2);

            // Value label position
            string visValue = LEStringTableEditor.GetPresentationFromCache(logicalValue);

            valuePosition = GetResizableTextBoxPosition(visValue, boxWidth, valueStyle);

            // Value box
            GUI.Box(valuePosition, string.Empty);

            // Value label
            EditorGUI.SelectableLabel(valuePosition, visValue, valueStyle);

            height = Math.Max(labelPosition.height, valuePosition.height);
            drawHelper.NewLine(height / drawHelper.LineHeight + .2f);

            content.text = LEConstants.LogicalPresentation;
            drawHelper.TryGetCachedSize(LEConstants.SizeLogicalPresentationKey, content, labelStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
            drawHelper.NewLine();
        }
        void Load()
        {
            LEStringTableEditor.Load();
            SetCurrentLanguageInManager();

            editingFields.Clear();
            editFieldTextDict.Clear();
            groupHeightCollection.Clear();

            LESettings.Instance.WarningCache.Clear();
            LESettings.Instance.Save();

            langIndex    = 0;
            newLangIndex = 0;

            LoadNewLanguagesDisplay();
            LoadLanguagesDisplay();

            GUI.FocusControl(string.Empty);
        }
Ejemplo n.º 8
0
        static bool ProcessGameObject(GameObject go, string value)
        {
            bool result = false;

            // Determine if this component already has a LELocalize attached
            if (go.GetComponent <LELocalize>() == null)
            {
                // Add LELocalize
                LELocalize leLocalize = go.AddComponent <LELocalize>();

                string key = LEConstants.AutoIndexPrefix + LESettings.Instance.AutoIndex++;
                LEStringTableEditor.AddNewString(key, value);

                leLocalize.State = LELocalizeState.Initialized;
                leLocalize.localized_string_key = key;

                result = true;
            }

            return(result);
        }
        void DrawReadOnlyLocString(LELangDict langDict, KeyValuePair <string, string> locStringEntry)
        {
            // Draw read only loc section
            string visKey   = LEStringTableEditor.GetPresentationFromCache(locStringEntry.Key);
            string visValue = LEStringTableEditor.GetPresentationValue(locStringEntry.Key);

            // Key label position
            Rect labelPosition = GetResizableTextBoxPosition(locStringEntry.Key, boxWidth, keyStyle);

            // Key box
            GUI.Box(labelPosition, string.Empty);

            // Key label
            if (GUI.Button(labelPosition, visKey, keyStyle))
            {
                SetLocStringToEditMode(locStringEntry);
            }
            drawHelper.CurrentLinePosition += labelPosition.width + 2f;

            // Value label position
            Rect valuePosition = GetResizableTextBoxPosition(visValue, boxWidth, valueStyle);

            // Value box
            GUI.Box(valuePosition, string.Empty);

            // Value label
            if (GUI.Button(valuePosition, visValue, valueStyle))
            {
                SetLocStringToEditMode(locStringEntry);
            }
            drawHelper.CurrentLinePosition += valuePosition.width + 2f;

            float height = Math.Max(labelPosition.height, valuePosition.height);

            drawHelper.NewLine(height / drawHelper.LineHeight - 1);
        }
        void DrawAddNewSection()
        {
            // Check the new cultures array
            if (newCulturesDisplay == null || newCulturesDisplay.Length == 0)
            {
                LoadNewLanguagesDisplay();
            }

            // New language popup
            newLangIndex = EditorGUI.Popup(new Rect(drawHelper.CurrentLinePosition, drawHelper.PopupTop(), LEConstants.NewLangPopupWidth, comboBoxStyle.fixedHeight),
                                           newLangIndex, newCulturesDisplay, comboBoxStyle);
            drawHelper.CurrentLinePosition += LEConstants.NewLangPopupWidth + 2f;

            // Custom name textbox (only shows up if Custom is selected)
            if (newCulturesDisplay.IsValidIndex(newLangIndex) && newCulturesDisplay[newLangIndex].Equals(LEConstants.CustomLbl))
            {
                content.text = LEConstants.NewCustomLangLbl;
                drawHelper.TryGetCachedSize(LEConstants.SizeNewCustomLangLblKey, content, valueStyle, out size);
                newLangCode = EditorGUI.TextField(new Rect(drawHelper.CurrentLinePosition, drawHelper.PopupTop(), size.x, size.y), newLangCode);
                drawHelper.CurrentLinePosition += size.x + 2f;

                // Add language button
                content.text = LEConstants.AddLanguageLbl;
                drawHelper.TryGetCachedSize(LEConstants.SizeNewLangBtnKey, content, GUI.skin.button, out size);
                if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
                {
                    LEStringTableEditor.AddNewLanguage(newLangCode);
                    LEStringTableEditor.CurrentLanguage = newLangCode;

                    SetCurrentLanguageInManager();
                    groupHeightCollection.Clear();

                    LoadLanguagesDisplay();

                    newLangCode = LEConstants.NewCustomLangLbl;

                    GUI.FocusControl(string.Empty);
                }
            }
            else
            {
                // Add language button
                content.text = LEConstants.AddLanguageLbl;
                drawHelper.TryGetCachedSize(LEConstants.SizeNewLangBtnKey, content, GUI.skin.button, out size);
                if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
                {
                    string newLangCode = newCultures[newLangIndex].Name;
                    LEStringTableEditor.AddNewLanguage(newLangCode);
                    LEStringTableEditor.CurrentLanguage = newLangCode;

                    SetCurrentLanguageInManager();
                    groupHeightCollection.Clear();

                    LoadLanguagesDisplay();
                    LoadNewLanguagesDisplay();

                    SelectLanguage(langIndex);
                }
            }

            drawHelper.NewLine(1.75f);
        }
        void OnGUI()
        {
            SetStyles();

            size = Vector2.zero;

            drawHelper.ResetToTop();

            Color     currentColor         = headerColor;
            Texture2D currentAltBackground = altBackground;
            Texture2D normalBackground     = GUI.skin.textArea.normal.background;

            drawHelper.DrawMainHeaderLabel(LEConstants.MainHeaderLbl, currentColor, LEConstants.SizeMainHeaderKey);
            DrawHeader();

            drawHelper.DrawSubHeader(LEConstants.AddNewHeaderLbl, currentColor, LEConstants.SizeAddNewHeaderKey);
            DrawAddNewSection();

            drawHelper.DrawSectionSeparator();

            drawHelper.DrawSubHeader(LEConstants.LocStringSectionHeader, currentColor, LEConstants.SizeLocStringHeaderKey);

            languageWidth = CalcMinWithForArray(languages, comboBoxStyle);

            if (LEStringTableEditor.AllLangsLogical.Count == 0)
            {
                content.text = LEConstants.AddNewLanguageMsg;
                drawHelper.TryGetCachedSize(LEConstants.SizeAddNewLanguageMsgKey, content, labelStyle, out size);
                EditorGUI.LabelField(new Rect(drawHelper.HorizontalMiddleOfLine() - size.x / 2f, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);

                return;
            }

            // Check if the new languages and code have been loaded
            // If not, load them now (fix for Windows)
            if (languages == null || languageCodes == null)
            {
                LoadLanguagesDisplay();
                LoadNewLanguagesDisplay();
            }


            // Select the next available language if the current one is invalid
            if (!languageCodes.Contains(LEStringTableEditor.CurrentLanguage))
            {
                if (languageCodes.IsValidIndex(langIndex - 1))
                {
                    SelectLanguage(langIndex - 1);
                }
                else
                {
                    SelectLanguage(0);
                }
            }

            // Draw language drop down
            content.text = LEConstants.LanguageLbl;
            size         = labelStyle.CalcSize(content);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
            drawHelper.CurrentLinePosition += size.x + 5;

            int newIndex = EditorGUI.Popup(new Rect(drawHelper.CurrentLinePosition, drawHelper.PopupTop(), languageWidth, comboBoxStyle.fixedHeight), langIndex, languages, comboBoxStyle);

            if (languageCodes.IsValidIndex(newIndex) && newIndex != langIndex)
            {
                SelectLanguage(newIndex);
            }
            drawHelper.CurrentLinePosition += languageWidth + 2f;

            // Draw Delete Language Button
            content.text = LEConstants.DeleteBtn;
            drawHelper.TryGetCachedSize(LEConstants.SizeDeleteBtnKey, content, GUI.skin.button, out size);
            if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.PopupTop(), size.x, size.y), content))
            {
                languagesToRemove.Add(languageCodes[langIndex]);

                if (languageCodes.IsValidIndex(langIndex - 1))
                {
                    SelectLanguage(langIndex - 1);
                }
                else
                {
                    SelectLanguage(0);
                }
            }

            // Set the alignment for the current culture selected
            if (languageCodes.IsValidIndex(langIndex) && currentCulture != null && currentCulture.IsRightToLeft)
            {
                keyStyle.alignment   = TextAnchor.MiddleRight;
                valueStyle.alignment = TextAnchor.MiddleRight;
                isRTL = true;
            }
            else
            {
                keyStyle.alignment   = TextAnchor.MiddleLeft;
                valueStyle.alignment = TextAnchor.MiddleLeft;
                isRTL = false;
            }

            drawHelper.NewLine(2);

            DrawNewLocStringField();
            drawHelper.NewLine(2);

            // Draw the string table labels
            content.text = LEConstants.KeysLbl;
            size         = labelStyle.CalcSize(content);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
            drawHelper.CurrentLinePosition += boxWidth;

            content.text = LEConstants.ValuesLbl;
            size         = labelStyle.CalcSize(content);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);

            drawHelper.NewLine();

            // Draw each loc string, one on each line
            if (!languageCodes.IsValidIndex(langIndex) || !LEStringTableEditor.AllLangsVisual.ContainsKey(languageCodes[langIndex]))
            {
                return;
            }

            if (!groupHeightCollection.TryGetValue(LEStringTableEditor.CurrentLanguage, out groupHeights))
            {
                groupHeights = new Dictionary <string, float>();
            }

            float currentGroupHeightTotal = CalculateGroupHeightsTotal();

            scrollViewHeight          = drawHelper.HeightToBottomOfWindow();
            scrollViewY               = drawHelper.TopOfLine();
            verticalScrollbarPosition = GUI.BeginScrollView(new Rect(drawHelper.CurrentLinePosition, scrollViewY, drawHelper.FullWindowWidth(), scrollViewHeight),
                                                            verticalScrollbarPosition,
                                                            new Rect(drawHelper.CurrentLinePosition, scrollViewY, drawHelper.ScrollViewWidth(), currentGroupHeightTotal));
            int   count = 0;
            float currentGroupHeight = 0;
            float beginningHeight    = 0;
            var   string_table       = LEStringTableEditor.AllLangsLogical[languageCodes[langIndex]];

            foreach (var loc_string in string_table)
            {
                if (count % 2 != 0)
                {
                    valueStyle.normal.background = currentAltBackground;
                    keyStyle.normal.background   = currentAltBackground;
                }
                else
                {
                    valueStyle.normal.background = normalBackground;
                    keyStyle.normal.background   = normalBackground;
                }

                groupHeights.TryGetValue(loc_string.Key, out currentGroupHeight);
                if (currentGroupHeight == 0f || currentGroupHeight.NearlyEqual(drawHelper.LineHeight))
                {
                    currentGroupHeight = drawHelper.LineHeight;
                }

                if (drawHelper.IsGroupVisible(currentGroupHeight, verticalScrollbarPosition, scrollViewHeight, scrollViewY) ||
                    (count == string_table.Count - 1 && verticalScrollbarPosition.y.NearlyEqual(currentGroupHeightTotal - drawHelper.LineHeight)))
                {
                    beginningHeight = drawHelper.CurrentHeight();

                    DrawLocString(string_table, loc_string);
                    drawHelper.NewLine(1.1f);

                    currentGroupHeight = drawHelper.CurrentHeight() - beginningHeight;
                }
                else
                {
                    drawHelper.NewLine(currentGroupHeight / drawHelper.LineHeight);
                }

                groupHeights.TryAddOrUpdateValue(loc_string.Key, currentGroupHeight);
                groupHeightCollection.TryAddOrUpdateValue(LEStringTableEditor.CurrentLanguage, groupHeights);
                count++;
            }
            GUI.EndScrollView();

            // Remove keys from all langs
            keysToRemove.ForEach(key => {
                LEStringTableEditor.RemoveString(key);
            });
            keysToRemove.Clear();

            // Rename any keys in other languages
            foreach (var pair in renamedKeys)
            {
                LEStringTableEditor.UpdateKey(pair.Key, pair.Value);
            }

            // Send out the renamed key event
            if (renamedKeys.Count > 0)
            {
                LEManager.KeysRenamed(renamedKeys);
            }

            renamedKeys.Clear();

            // Update any values in current lang
            foreach (var pair in updatedStringsForCurrent)
            {
                LEStringTableEditor.UpdateString(LEStringTableEditor.CurrentLanguage, pair.Key, pair.Value);
            }

            if (updatedStringsForCurrent.Count > 0)
            {
                LEManager.LocStringChanged(updatedStringsForCurrent.Keys.ToList());
            }

            updatedStringsForCurrent.Clear();

            // Delete any languages that were deleted
            bool shouldRebuildLanguageLists = languagesToRemove.Count > 0;

            languagesToRemove.ForEach(lang => {
                LEStringTableEditor.RemoveLanguage(lang);
            });
            languagesToRemove.Clear();

            if (shouldRebuildLanguageLists)
            {
                LoadLanguagesDisplay();
                LoadNewLanguagesDisplay();
                AssetDatabase.Refresh();
            }
        }
 void Save()
 {
     LEStringTableEditor.Save();
 }
Ejemplo n.º 13
0
        public static void ProcessScene()
        {
            try
            {
                // Force autoindex to start at 1
                if (LESettings.Instance.AutoIndex < 1)
                {
                    LESettings.Instance.AutoIndex = 1;
                }

                int totalConfigured = 0;
                int totalComponents = 0;

                        #if !UNITY_4_3 && !UNITY_4_5
                // Text components
                Text[] textComponents = GameObject.FindObjectsOfType <Text>();
                totalComponents += textComponents.Length;
                for (int i = 0; i < textComponents.Length; i++)
                {
                    if (ProcessGameObject(textComponents[i].gameObject, textComponents[i].text))
                    {
                        totalConfigured++;
                    }
                }
                #endif

                // GUIText components
                GUIText[] guiTextComponents = GameObject.FindObjectsOfType <GUIText>();
                totalComponents += guiTextComponents.Length;
                for (int i = 0; i < guiTextComponents.Length; i++)
                {
                    if (ProcessGameObject(guiTextComponents[i].gameObject, guiTextComponents[i].text))
                    {
                        totalConfigured++;
                    }
                }

                // TextMesh components
                TextMesh[] textMeshComponents = GameObject.FindObjectsOfType <TextMesh>();
                totalComponents += textMeshComponents.Length;
                for (int i = 0; i < textMeshComponents.Length; i++)
                {
                    if (ProcessGameObject(textMeshComponents[i].gameObject, textMeshComponents[i].text))
                    {
                        totalConfigured++;
                    }
                }

                // At the end of the process, save LE Editor
                LEStringTableEditor.Save();
                LESettings.Instance.Save();

                EditorUtility.DisplayDialog(LEConstants.ProcessSceneMsgTitle,
                                            string.Format(LEConstants.ProcessSceneCompleteMsg, totalComponents, totalConfigured, totalComponents - totalConfigured),
                                            LEConstants.OkLbl);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }