public static void ShowWindow(ulong startingCode) { UnicodeBrowser window = GetWindow <UnicodeBrowser>(); window.SetStartingUnicode(startingCode); window.Show(); }
private void OnGUI() { if (language != null && foldoutStatus.Count != language.Alpha.Count) { Dictionary <Letter, bool> newStatus = new Dictionary <Letter, bool>(); for (int i = 0; i < language.Alpha.Count; i++) { if (foldoutStatus.ContainsKey(language.Alpha[i])) { newStatus.Add(language.Alpha[i], foldoutStatus[language.Alpha[i]]); } else { newStatus.Add(language.Alpha[i], false); } } foldoutStatus = newStatus; } titleContent = new GUIContent("Language Builder"); // toolbar at top EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("New", EditorStyles.toolbarButton)) { // ask for new language string path = EditorUtility.SaveFilePanel("New Language File", langDirPath, "english.lang", "lang"); if (path != "") { language = GenerateEnglishLanguage(); File.WriteAllText(path, language.GenerateConfig()); langFilePath = path; langDirPath = Path.GetDirectoryName(langFilePath); } } if (GUILayout.Button("Load", EditorStyles.toolbarButton)) { // ask for loaded language string path = EditorUtility.OpenFilePanel("Open Language File", langDirPath, "lang"); if (path != "") { language = Language.ParseConfig(File.ReadAllText(path)); langFilePath = path; langDirPath = Path.GetDirectoryName(langFilePath); } } GUILayout.FlexibleSpace(); if (language != null && GUILayout.Button("Save", EditorStyles.toolbarButton)) { // save the language to config string path = EditorUtility.SaveFilePanel("Save Language File", langDirPath, Path.GetFileName(langFilePath), "lang"); if (path != "") { File.WriteAllText(path, language.GenerateConfig()); langFilePath = path; langDirPath = Path.GetDirectoryName(langFilePath); } } EditorGUILayout.EndHorizontal(); // end toolbar if (language == null) { EditorGUILayout.HelpBox("Create a new language with the \"New\" button above", MessageType.Info); return; } EditorGUILayout.LabelField("Language loaded at " + langFilePath + "\nin " + langDirPath, EditorStyles.helpBox, GUILayout.ExpandWidth(true)); language.Name = EditorGUILayout.TextField("Language Name:", language.Name); language.TextOrder = (Language.TextOrdering)EditorGUILayout.EnumPopup("Text Direction: ", language.TextOrder); // letters toolbar EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Add", EditorStyles.toolbarButton)) { language.Alpha.Add(new Letter("New Letter", 'A')); } GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("Letters"); GUILayout.FlexibleSpace(); if (GUILayout.Button("Sort", EditorStyles.toolbarButton)) { language.SortLetters(); } if (selectedLetter != null && GUILayout.Button("Remove Selected", EditorStyles.toolbarButton)) { language.Alpha.Remove(selectedLetter); selectedLetter = null; } EditorGUILayout.EndHorizontal(); // end letters toolbar // display warnings on letters here // duplicate name warning List <string> letterNames = new List <string>(); List <string> duplicateNames = new List <string>(); foreach (Letter l in language.Alpha) { if (letterNames.Contains(l.Name)) { duplicateNames.Add(l.Name); } else { letterNames.Add(l.Name); } } if (duplicateNames.Count != 0) { string names = ""; foreach (string name in duplicateNames) { names += "\t" + name + "\n"; } EditorGUILayout.HelpBox("There are multiple letters with the same name(s):\n" + names, MessageType.Warning); } // duplicate isolated warning List <char> letters = new List <char>(); List <char> duplicateLetters = new List <char>(); foreach (Letter l in language.Alpha) { if (letters.Contains(l.Isolated)) { duplicateLetters.Add(l.Isolated); } else { letters.Add(l.Isolated); } } if (duplicateLetters.Count != 0) { string chars = ""; foreach (char c in duplicateLetters) { chars += "\t(0x" + ((ulong)c).ToString("X") + ") " + c + "\n"; } EditorGUILayout.HelpBox("There are multiple letters with the same isolated character.\nThese should be unique.\n" + chars, MessageType.Warning); } // each letter gui letterScrollPos = EditorGUILayout.BeginScrollView(letterScrollPos); GUIStyle charLabelStyle = new GUIStyle(EditorStyles.label); charLabelStyle.alignment = TextAnchor.MiddleRight; Color defaultColor = GUI.backgroundColor; foreach (Letter letter in language.Alpha) { GUI.backgroundColor = (letter == selectedLetter) ? Color.cyan : defaultColor; // overall box outline EditorGUILayout.BeginVertical(GUI.skin.GetStyle("Box"), GUILayout.ExpandWidth(true)); // ensure letter is at least in the list if (!foldoutStatus.ContainsKey(letter)) { foldoutStatus.Add(letter, false); } // only continue if the foldoutstatus for this letter is true, toggled by the foldout method if (!(foldoutStatus[letter] = EditorGUILayout.Foldout(foldoutStatus[letter], letter.Name, true))) { EditorGUILayout.EndVertical(); continue; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Name", GUILayout.MaxWidth(40f)); letter.Name = EditorGUILayout.TextField(letter.Name); EditorGUILayout.EndHorizontal(); // character fields (setable by Unicode Browser) try { // combination settings if (letter.Combination != null) { bool remove = false; // used to prevent null errors EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Combination Settings"); if (GUILayout.Button("Remove")) { remove = true; } EditorGUILayout.EndHorizontal(); // first letter EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("First Letter", GUILayout.MaxWidth(100f)); EditorGUILayout.LabelField("0x", charLabelStyle, GUILayout.MaxWidth(20f)); letter.Combination.FirstLetter = (char)Convert.ToUInt64(EditorGUILayout.TextField("0x" + ((ulong)letter.Combination.FirstLetter).ToString("X"), GUILayout.ExpandWidth(true)), 16); EditorGUILayout.LabelField("Char", charLabelStyle, GUILayout.MaxWidth(40f)); letter.Combination.FirstLetter = EditorGUILayout.TextField(letter.Combination.FirstLetter + "", GUILayout.ExpandWidth(true))[0]; if (GUILayout.Button("Pull from UB")) { GUI.FocusControl(null); letter.Combination.FirstLetter = (char)UnicodeBrowser.GetSelectedChar(); } EditorGUILayout.EndHorizontal(); // second EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Second Letter", GUILayout.MaxWidth(100f)); EditorGUILayout.LabelField("0x", charLabelStyle, GUILayout.MaxWidth(20f)); letter.Combination.SecondLetter = (char)Convert.ToUInt64(EditorGUILayout.TextField("0x" + ((ulong)letter.Combination.SecondLetter).ToString("X"), GUILayout.ExpandWidth(true)), 16); EditorGUILayout.LabelField("Char", charLabelStyle, GUILayout.MaxWidth(40f)); letter.Combination.SecondLetter = EditorGUILayout.TextField(letter.Combination.SecondLetter + "", GUILayout.ExpandWidth(true))[0]; if (GUILayout.Button("Pull from UB")) { GUI.FocusControl(null); letter.Combination.SecondLetter = (char)UnicodeBrowser.GetSelectedChar(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (remove) { letter.Combination = null; } } else { if (GUILayout.Button("Add Combination")) { letter.Combination = new Combination('A', 'B'); } } // isolated chars EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Isolated", GUILayout.MaxWidth(100f)); EditorGUILayout.LabelField("0x", charLabelStyle, GUILayout.MaxWidth(20f)); letter.Isolated = (char)Convert.ToUInt64(EditorGUILayout.TextField("0x" + ((ulong)letter.Isolated).ToString("X"), GUILayout.ExpandWidth(true)), 16); EditorGUILayout.LabelField("Char", charLabelStyle, GUILayout.MaxWidth(40f)); letter.Isolated = EditorGUILayout.TextField(letter.Isolated + "", GUILayout.ExpandWidth(true))[0]; if (GUILayout.Button("Pull from UB")) { GUI.FocusControl(null); letter.Isolated = (char)UnicodeBrowser.GetSelectedChar(); } EditorGUILayout.EndHorizontal(); // initial chars EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Initial", GUILayout.MaxWidth(100f)); EditorGUILayout.LabelField("0x", charLabelStyle, GUILayout.MaxWidth(20f)); letter.Initial = (char)Convert.ToUInt64(EditorGUILayout.TextField("0x" + ((ulong)letter.Initial).ToString("X")), 16); EditorGUILayout.LabelField("Char", charLabelStyle, GUILayout.MaxWidth(40f)); letter.Initial = EditorGUILayout.TextField(letter.Initial + "", GUILayout.ExpandWidth(true))[0]; if (GUILayout.Button("Pull from UB")) { GUI.FocusControl(null); letter.Initial = (char)UnicodeBrowser.GetSelectedChar(); } EditorGUILayout.EndHorizontal(); // medial EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Medial", GUILayout.MaxWidth(100f)); EditorGUILayout.LabelField("0x", charLabelStyle, GUILayout.MaxWidth(20f)); letter.Medial = (char)Convert.ToUInt64(EditorGUILayout.TextField("0x" + ((ulong)letter.Medial).ToString("X")), 16); EditorGUILayout.LabelField("Char", charLabelStyle, GUILayout.MaxWidth(40f)); letter.Medial = EditorGUILayout.TextField(letter.Medial + "", GUILayout.ExpandWidth(true))[0]; if (GUILayout.Button("Pull from UB")) { GUI.FocusControl(null); letter.Medial = (char)UnicodeBrowser.GetSelectedChar(); } EditorGUILayout.EndHorizontal(); // final EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Final", GUILayout.MaxWidth(100f)); EditorGUILayout.LabelField("0x", charLabelStyle, GUILayout.MaxWidth(20f)); letter.Final = (char)Convert.ToUInt64(EditorGUILayout.TextField("0x" + ((ulong)letter.Final).ToString("X")), 16); EditorGUILayout.LabelField("Char", charLabelStyle, GUILayout.MaxWidth(40f)); letter.Final = EditorGUILayout.TextField(letter.Final + "", GUILayout.ExpandWidth(true))[0]; if (GUILayout.Button("Pull from UB")) { GUI.FocusControl(null); letter.Final = (char)UnicodeBrowser.GetSelectedChar(); } EditorGUILayout.EndHorizontal(); } catch (OverflowException ofe) { EditorGUILayout.HelpBox("Character fields must be in hexidecimal (0xFFFF) format.", MessageType.Error); } catch (FormatException fe) { EditorGUILayout.HelpBox("Character fields must be in hexidecimal (0xFFFF) format.", MessageType.Error); } catch (ArgumentOutOfRangeException aofre) { // do nothing, this is when the field is blank, it's fine } catch (IndexOutOfRangeException ioore) { // do nothing, this happens when character text fields are empty } EditorGUILayout.EndVertical(); if (Event.current.isMouse && Event.current.button == 0 && Event.current.type == EventType.MouseUp && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) { // this box was clicked if (selectedLetter == letter) { // deselect selectedLetter = null; } else { selectedLetter = letter; } GUI.FocusControl(null); Repaint(); Event.current.Use(); } } EditorGUILayout.EndScrollView(); }