private void PageOptions() { var configIcon = EditorGUIUtility.IconContent("d__Popup"); configIcon.text = "Page Options"; GUILayout.Label(configIcon); GUILayout.BeginVertical(EditorStyles.helpBox); var talkerName = EditorGUILayout.TextField("Talker Name", _data._currentTextPage.TalkerName); EditorGUILayout.Separator(); var writeIcon = EditorGUIUtility.IconContent("d_editicon.sml"); writeIcon.text = "Write Type"; var writerType = (WriteType)EditorGUILayout.EnumPopup(writeIcon, _data._currentTextPage.WriteType); switch (writerType) { case WriteType.Instant: if (_data._currentTextPage.CharByCharInfo != default) { UTalkEditorWindow.RecordToUndo("char by char default"); _data._currentTextPage.CharByCharInfo = default; } InstantInfoPageOpt(); break; case WriteType.CharByChar: if (_data._currentTextPage.InstantInfo != default) { UTalkEditorWindow.RecordToUndo("set instant default"); _data._currentTextPage.InstantInfo = default; } CharByCharPageOpt(); break; } if (_data._currentTextPage.WriteType != writerType) { UTalkEditorWindow.RecordToUndo("writer name"); _data._currentTextPage.WriteType = writerType; } if (_data._currentTextPage.TalkerName != talkerName) { UTalkEditorWindow.RecordToUndo("Talker name " + talkerName); _data._currentTextPage.TalkerName = talkerName; } EditorGUILayout.Separator(); SpritesOption(); GUILayout.EndVertical(); }
public void OnGUI() { if (_data._pageIndex >= 0) { GUILayout.Space(5); _pageScroll = EditorGUILayout.BeginScrollView(_pageScroll); var hightligted = HighlightText(_data._currentTextPage); AddRemovePageToolbar(); var oldText = _data._currentTextPage.Text.ToString(); var text = oldText.ToString(); GUI.SetNextControlName("Text Area"); _textInfo = GUIUtils.SmartTextArea(ref text, SetToClipboard, GUILayout.MinHeight(100)); EditorGUILayout.Separator(); TextPreview(hightligted); if (_data._currentTextPage.Text != text) { UTalkEditorWindow.RecordToUndo("Text changed"); _data._currentTextPage.Text = text; } if (_textInfo.TextLengthChanged) { OnTextChanged(oldText, _textInfo.Text, _textInfo.AddedChars, _textInfo.CursorIndex); } UpdateHighlight(_textInfo); GUILayout.Space(5); PagesToolBar(); GUILayout.Space(5); PageOptions(); EditorGUILayout.EndScrollView(); } }
private void SpritesOption() { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); var spriteIcon = EditorGUIUtility.IconContent("d_Sprite Icon"); spriteIcon.text = "Sprites"; EditorGUILayout.LabelField(spriteIcon, GUILayout.MaxWidth(135)); GUILayout.Space(10); if (GUILayout.Button("Add")) { UTalkEditorWindow.RecordToUndo("add sprite"); _pageScroll = Vector2.up * 10000; _data._currentTextPage.Sprites.Add(default);
private void PagesToolBar() { GUILayout.BeginHorizontal(EditorStyles.helpBox); var nextSkin = _data._pageIndex + 1 < _talkData.PagesCount ? _prevNextButtons : _prevNextButtonsDisabled; var prevSkin = _data._pageIndex > 0 ? _prevNextButtons : _prevNextButtonsDisabled; var prev = EditorGUIUtility.IconContent("tab_prev"); GUI.SetNextControlName("Prev"); if (GUILayout.Button(prev, prevSkin) && _data._pageIndex > 0) { UTalkEditorWindow.RecordToUndo("go prev page"); GUI.FocusControl("Prev"); _data._pageIndex--; _textInfo.TextEditor.ClearSelectedText(); _data._currentTextPage = _talkData.GetPage(_data._pageIndex); } GUILayout.Label((_data._pageIndex + 1).ToString() + "/" + _talkData.PagesCount, _centeredLabel, GUILayout.Width(40)); var next = EditorGUIUtility.IconContent("tab_next"); GUI.SetNextControlName("Next"); if (GUILayout.Button(next, nextSkin) && _data._pageIndex + 1 < _talkData.PagesCount) { UTalkEditorWindow.RecordToUndo("advance next page"); GUI.FocusControl("Next"); _data._pageIndex++; _textInfo.TextEditor.ClearSelectedText(); _data._currentTextPage = _talkData.GetPage(_data._pageIndex); } GUILayout.EndHorizontal(); }
private void AddRemovePageToolbar() { GUILayout.BeginHorizontal(EditorStyles.helpBox); var addIcon = EditorGUIUtility.IconContent("CreateAddNew"); //addIcon.text = "Add"; if (GUILayout.Button(addIcon)) { UTalkEditorWindow.RecordToUndo("PageAdded"); _talkData.CreateEmptyPageWithLastPageOptions(); _data._pageIndex = _talkData.PagesCount - 1; _data._currentTextPage = _talkData.GetPage(_data._pageIndex); } var buttonSkin = _talkData.PagesCount > 1 ? GUI.skin.button : _disabledButton; var deleteIcon = EditorGUIUtility.IconContent("TreeEditor.Trash"); //deleteIcon.text = "Delete"; if (GUILayout.Button(deleteIcon, buttonSkin)) { if (_talkData.PagesCount > 1) { UTalkEditorWindow.RecordToUndo("DeletedPage"); _talkData.DeletePage(_data._pageIndex); if (_data._pageIndex - 1 > -1) { _data._pageIndex--; } _data._currentTextPage = _talkData.GetPage(_data._pageIndex); } } GUILayout.EndHorizontal(); }
private void Groups() { GUILayout.Space(4); _groupsScroll = GUILayout.BeginScrollView(_groupsScroll); var index = 0; for (int i = 0; i < _groupsTextGrid.Length; i++) { GUILayout.BeginHorizontal(); for (int j = 0; j < _groupsPerRow; j++) { if (GUILayout.Button(_groupsTextGrid[index], _groupGridButtons)) { TalksPage(_groupsTextGrid[index].text); } index++; if (index == _groupsTextGrid.Length) { i = _groupsTextGrid.Length; break; } } GUILayout.EndHorizontal(); } if (_deleteGroup) { var selectedGroup = 0; for (int i = 0; i < Mathf.CeilToInt((float)_groupsTextGrid.Length / 2); i++) { for (int j = 0; j < 2; j++) { if (_groupsTextGrid.Length > selectedGroup) { _deleteToggles[selectedGroup] = GUI.Toggle(new Rect(15 + j * (Screen.width / 2 - 16), i * 110 + 10, 20, 20), _deleteToggles[selectedGroup], ""); } selectedGroup++; } } if (_deleteToggles.Any(x => x)) { if (GUI.Button(new Rect(0, Screen.height - 123, Screen.width, 20), $"Delete ({_deleteToggles.Count(x => x)})")) { //Context.Delete(UTalkEditorWindow.Position, "Group", "Selected", "groups", DeleteGroup); //void DeleteGroup() { UTalkEditorWindow.RecordToUndo("Delete group"); for (int i = 0; i < _deleteToggles.Count; i++) { if (_deleteToggles[i]) { _dataContainer.DeleteGroup(_groupsTextGrid[i].text, _dataContainer.Language); } } SetGroups(); _deleteGroup = false; } return; } } } GUILayout.EndScrollView(); }
private void UpdateHighlight(GUIUtils.TextEditorInfo textInfo) { //does the TextArea have text? if (!string.IsNullOrWhiteSpace(textInfo.SelectedText)) { var selectedWords = Utils.GetSelectedWords(textInfo.StartSelectIndex, textInfo.SelectedText, textInfo.Text); var wordsToHighlight = ""; for (int i = 0; i < selectedWords.Count; i++) { if (!_data._currentTextPage.Highlight.ContainsKey(selectedWords[i].WordIndex)) { wordsToHighlight += selectedWords[i].Word + (i + 1 == selectedWords.Count ? null : " | "); } } if (!string.IsNullOrEmpty(wordsToHighlight) && GUILayout.Button($"Add Hightlight to: {wordsToHighlight}", _buttonWrapStyle)) { UTalkEditorWindow.RecordToUndo("add highlight"); for (int i = 0; i < selectedWords.Count; i++) { if (!_data._currentTextPage.Highlight.ContainsKey(selectedWords[i].WordIndex)) { var word = selectedWords[i].Word; var wordIndex = selectedWords[i].WordIndex; var globalStartingChar = selectedWords[i].GlobalCharIndex; var localStartCharIndex = Utils.ToLocalStartChar(globalStartingChar, textInfo.Text, word); var highlightLength = textInfo.SelectedText.Length; var highlight = new Highlight(wordIndex, localStartCharIndex, highlightLength, Color.white); _data._currentTextPage.Highlight.Add(wordIndex, highlight); } } } GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Space(4); //GUILayout.HorizontalSlider(5, 0, 10, GUI.skin.horizontalScrollbar, GUI.skin.button); _scrollView = GUILayout.BeginScrollView(_scrollView, GUILayout.MinHeight(135), GUILayout.ExpandHeight(true)); GUILayout.BeginHorizontal(); for (int i = 0; i < selectedWords.Count; i++) { var word = selectedWords[i].Word; var wordIndex = selectedWords[i].WordIndex; var globalStartingChar = selectedWords[i].GlobalCharIndex; var containsKey = _data._currentTextPage.Highlight.ContainsKey(wordIndex); //Debug.Log("Starting char created: " + startingChar); var localStartCharIndex = Utils.ToLocalStartChar(globalStartingChar, textInfo.Text, word); var highlightLength = textInfo.SelectedText.Length; //Debug.Log("startChar: " + startingChar + ", local start: " + startCharIndex + ", length " + highlightLength); if (containsKey) { GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(150)); GUILayout.Space(1); GUILayout.BeginHorizontal(); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { UTalkEditorWindow.RecordToUndo("HRemoved"); _data._currentTextPage.Highlight.Remove(wordIndex); GUILayout.EndHorizontal(); GUILayout.EndVertical(); return; } GUILayout.Label($"{word}", _labelStyle); GUILayout.EndHorizontal(); var highlight = _data._currentTextPage.Highlight[wordIndex]; if (highlight != default) { GUILayout.BeginHorizontal(); GUILayout.Label("Color", GUILayout.MaxWidth(70)); var color = EditorGUILayout.ColorField(highlight.Color); color.a = 1; GUILayout.EndHorizontal(); if (highlight.Color != color) { UTalkEditorWindow.RecordToUndo("HColor"); } GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.Label("Anim", GUILayout.MaxWidth(70)); var type = (TextAnimation)EditorGUILayout.EnumPopup(highlight.Type); GUILayout.EndHorizontal(); if (highlight.Type != type) { UTalkEditorWindow.RecordToUndo("HAnim"); } GUILayout.BeginHorizontal(); GUILayout.Label("Write Speed", GUILayout.MaxWidth(80)); var writeSpeedType = (Highlight.HighlightWriteSpeed)EditorGUILayout.EnumPopup(highlight.WriteSpeedType); GUILayout.EndHorizontal(); if (highlight.WriteSpeedType != writeSpeedType) { UTalkEditorWindow.RecordToUndo("HwriteSpeedType"); } var normalWriteSpeed = 0f; if (writeSpeedType == Highlight.HighlightWriteSpeed.Custom) { GUILayout.BeginHorizontal(); GUILayout.Label("Speed", GUILayout.MaxWidth(70)); normalWriteSpeed = EditorGUILayout.FloatField(highlight.NormalWriteSpeed); GUILayout.EndHorizontal(); } if (highlight.NormalWriteSpeed != normalWriteSpeed) { UTalkEditorWindow.RecordToUndo("HNWriteSpeed"); } highlight = new Highlight(wordIndex, localStartCharIndex, highlightLength, color, type, writeSpeedType, normalWriteSpeed); _data._currentTextPage.Highlight[wordIndex] = highlight; } GUILayout.EndVertical(); //GUILayout.Space(4); } } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); GUILayout.EndVertical(); } }
private void ShowTalks() { _scroll = GUILayout.BeginScrollView(_scroll); for (int i = 0; i < _talkData.SubGroups.Count; i++) { var key = _talkData.SubGroups.Keys.ElementAt(i); var talksOfSubGroup = _talkData.SubGroups[key]; if (_subGroupsList.Contains(key)) { GUILayout.Space(5); var c = GUI.color; GUI.color = Color.gray; GUILayout.BeginVertical(EditorStyles.helpBox); GUI.color = c; GUILayout.BeginHorizontal(); var deleteIcon = EditorGUIUtility.IconContent("TreeEditor.Trash"); if (GUILayout.Button(deleteIcon, _deleteSubGroupStyle, GUILayout.Width(22), GUILayout.MaxHeight(22))) { //Context.Delete(UTalkEditorWindow.Position, "Delete", key, "Sub-Group and all it's data", DeleteGroup); //void DeleteGroup() { UTalkEditorWindow.RecordToUndo("Delete subGroup"); _talkData.SubGroups.Remove(key); } return; } GUILayout.Label(key); GUILayout.EndHorizontal(); GUILayout.Space(3); } if (talksOfSubGroup.Talks.Count == 0) { GUILayout.Label("Empty", _centeredLabel); GUILayout.Space(2); } else { for (int j = 0; j < talksOfSubGroup.Talks.Count; j++) { //GUILayout.Space(7); GUILayout.BeginHorizontal(); //GUILayout.Space(10); var talk = talksOfSubGroup.Talks[j]; var pageIcon = EditorGUIUtility.IconContent("UnityEditor.ConsoleWindow@2x"); pageIcon.text = talk.TalkInfo.TalkName /*+ " | Pages: " + talk.PagesCount*/; if (GUILayout.Button(pageIcon, _groupButtonStyle, GUILayout.MinHeight(40))) { var info = talksOfSubGroup.Talks[j].TalkInfo; _navigator.PushEditPage(info.SubGroupName, info.TalkName); } var deletePage = EditorGUIUtility.IconContent("TreeEditor.Trash"); if (GUILayout.Button(deletePage, GUILayout.Width(40), GUILayout.MinHeight(40))) { //Context.Delete(UTalkEditorWindow.Position, "Delete Talk", talk.TalkInfo.TalkName, "Talk", RemoveTalk); //void RemoveTalk() { UTalkEditorWindow.RecordToUndo("Remove talk"); talksOfSubGroup.Talks.RemoveAt(j); } return; } GUILayout.EndHorizontal(); if (j + 1 < talksOfSubGroup.Talks.Count) { GUILayout.Space(3); } } } if (string.IsNullOrEmpty(key)) { key = _default; } if (_subGroupsList.Contains(key)) { GUILayout.Space(3); GUILayout.EndVertical(); } } GUILayout.EndScrollView(); }