/// <summary> /// Displays the interface for editing the words in the language. /// </summary> private void WordEditor() { EditorGUILayout.HelpBox("The json file is automatically updated when editing in this interface.", MessageType.Info); GUILayout.Label("Words"); var list = language.GetAllWords(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUIStyle.none, "verticalScrollbar", GUILayout.Height(Screen.height * .65f)); { EditorGUILayout.BeginVertical(); { var elementRemoved = false; for (var index = 0; index < list.Count; index++) { var pair = list[index]; EditorGUILayout.BeginHorizontal(); { editableList[index].Id = EditorGUILayout.TextField("", editableList[index].Id, GUILayout.Width(Screen.width * .1f)); editableList[index].Word = EditorGUILayout.TextArea(editableList[index].Word, GUILayout.Width(Screen.width * .6f)); EditorGUI.BeginDisabledGroup(string.IsNullOrWhiteSpace(editableList[index].Id) || string.IsNullOrWhiteSpace(editableList[index].Word) || pair.Id != editableList[index].Id && language.ContainsWord(editableList[index].Id) || pair.Id == editableList[index].Id && pair.Word == editableList[index].Word); { if (GUILayout.Button("Save", GUILayout.Width(Screen.width * .1f))) { language.UpdateLanguage(editableList); LanguageJsonHelper.SaveLanguageToJson(language); GetEditableCopy(); EditorUtility.SetDirty(language); } } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Delete", GUILayout.Width(Screen.width * .1f))) { language.RemoveWord(pair.Id); elementRemoved = true; LanguageJsonHelper.SaveLanguageToJson(language); EditorUtility.SetDirty(language); } } EditorGUILayout.EndHorizontal(); WordEditorErrorDisplay(editableList[index].Id, editableList[index].Word, pair.Id); } if (elementRemoved) { GetEditableCopy(); EditorUtility.SetDirty(language); } } EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(); { newId = EditorGUILayout.TextField("", newId, GUILayout.Width(Screen.width * .1f)); newWord = EditorGUILayout.TextArea(newWord, GUILayout.Width(Screen.width * .6f)); EditorGUI.BeginDisabledGroup(string.IsNullOrWhiteSpace(newId) || string.IsNullOrWhiteSpace(newWord) || language.ContainsWord(newId)); { if (GUILayout.Button("Add", GUILayout.Width(Screen.width * .2f))) { language.AddWord(newId, newWord, false); newId = ""; newWord = ""; GetEditableCopy(); LanguageJsonHelper.SaveLanguageToJson(language); EditorUtility.SetDirty(language); } } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndHorizontal(); WordEditorErrorDisplay(newId, newWord); if (!GUILayout.Button("Clear all Words")) { return; } language.Clear(); EditorUtility.SetDirty(language); GetEditableCopy(); }