private void FilterKeys() { if (statusToDisplay == LocalizationStatus.All) { keysWithCorrectLocalizationStatus = keys.ToList(); } else { keysWithCorrectLocalizationStatus = new List <string>(); foreach (var key in keys) { var isLocalized = !Localizator.GetLocalizationStatusOfKey(key).Contains(false); if (statusToDisplay == LocalizationStatus.Localized && isLocalized || statusToDisplay == LocalizationStatus.NotLocalized && !isLocalized) { keysWithCorrectLocalizationStatus.Add(key); } } } Search("", ignoreRepetition: true); }
private void OnGUI() { // Styles var languageDisplayerStyle = new GUIStyle { richText = true, fixedHeight = ELEMENT_HEIGHT, fontStyle = FontStyle.Bold, fontSize = 12, padding = new RectOffset(10, 10, 5, 5) }; var keyButtonStyle = new GUIStyle(EditorStyles.miniButton) { fixedHeight = ELEMENT_HEIGHT, fixedWidth = ELEMENT_WIDTH, fontSize = 12, padding = new RectOffset(10, 10, 5, 5) }; var keyButtonStyleBold = new GUIStyle(GUI.skin.button) { fixedHeight = ELEMENT_HEIGHT, fixedWidth = ELEMENT_WIDTH, fontSize = 12, fontStyle = FontStyle.BoldAndItalic, padding = new RectOffset(10, 10, 5, 5) }; if (GUILayout.Button("Refresh", GUILayout.Height(BUTTON_HEIGHT)) || !keysInit) { Refresh(); } GUILayout.Space(10); var searchStyle = new GUIStyle(EditorStyles.textField) { fixedWidth = position.width * .99f, fixedHeight = 23f, alignment = TextAnchor.MiddleCenter, fontSize = 12 }; search = GUILayout.TextField(search, searchStyle); search = search.Replace(' ', '_').ToLower(); Search(search); // Search Options SetLocalizationStatus((LocalizationStatus)EditorGUILayout.EnumPopup(statusToDisplay)); GUILayout.Space(10); EditorScriptingUtils.HorizontalLine(3); var rectPos = EditorGUILayout.GetControlRect(); var rectBox = new Rect(rectPos.x, rectPos.y, rectPos.width, position.height - 110); var viewRect = new Rect(rectPos.x, rectPos.y, currentLanguages.Length * LANGUAGE_NAME_DISPLAYER_WIDTH + ELEMENT_WIDTH, searchedKeys.Count * ELEMENT_HEIGHT); scrollPos = GUI.BeginScrollView(rectBox, scrollPos, viewRect, false, true); var viewCount = Mathf.FloorToInt((position.height - 110) / ELEMENT_HEIGHT); var firstIndex = Mathf.FloorToInt(scrollPos.y / ELEMENT_HEIGHT); var contentPos = new Rect(rectBox.x, firstIndex * ELEMENT_HEIGHT + 80f, rectBox.width, ELEMENT_HEIGHT); Localizator.UpdateKeyFile(); for (var i = firstIndex; i < Mathf.Min(firstIndex + viewCount, searchedKeys.Count); i++) { contentPos.y += ELEMENT_HEIGHT; var localizationStatus = Localizator.GetLocalizationStatusOfKey(searchedKeys[i]); // Displaying EditorGUILayout.BeginHorizontal(); var currentKey = searchedKeys[i]; if (GUI.Button(contentPos, currentKey, currentKey == "lng_name" || currentKey == "lng_error" ? keyButtonStyleBold : keyButtonStyle)) { KeyEditor.key = currentKey; var window = (KeyEditor)GetWindow(typeof(KeyEditor), false, "Key Editor", true); window.Show(); FocusWindowIfItsOpen(typeof(KeyEditor)); } GUILayout.FlexibleSpace(); for (var j = 0; j < currentLanguages.Length; j++) { var language = currentLanguages[j]; var xOffset = ELEMENT_WIDTH + j * LANGUAGE_NAME_DISPLAYER_WIDTH; var offsetedContentPos = new Rect(contentPos.x + xOffset, contentPos.y, contentPos.width, ELEMENT_HEIGHT); GUI.Label(offsetedContentPos, localizationStatus[j] ? $"<color=green>{language.ToString()}</color>" : $"<color=red>{language.ToString()}</color>", languageDisplayerStyle); } EditorGUILayout.EndHorizontal(); } GUI.EndScrollView(); }