public void SetCurrentTalkData(TalkData talkData) { _talkData = talkData; if (_textInfo.TextEditor != null) { _textInfo.TextEditor.SelectNone(); //_textInfo.TextEditor.cursorIndex = _textInfo.TextEditor.text.Length; } _textInfo = default; SetTextPageIndex(0, talkData); }
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 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(); } }