public void ScrollToLine(ScriptLineView lineView, bool onlyIfOutOfView = true) { if (scrollView is null) { scrollView = GetFirstAncestorOfType <ScrollView>(); } if (scrollView is null) { return; } while (!ViewRange.Contains(lineView.LineIndex)) { if (lineView.LineIndex < ViewRange.StartIndex) { SelectPreviousPage(); } else { SelectNextPage(); } } if (onlyIfOutOfView && scrollView.worldBound.Contains(lineView.worldBound.min)) { return; } var scroller = scrollView.verticalScroller; scroller.value = Mathf.Lerp(scroller.lowValue, scroller.highValue, linesContainer.IndexOf(lineView) / (float)linesContainer.childCount); }
public void ScrollToLine(ScriptLineView lineView, bool onlyIfOutOfView = true) { var scrollView = GetFirstAncestorOfType <ScrollView>(); if (scrollView != null && (!onlyIfOutOfView || !scrollView.worldBound.Contains(lineView.worldBound.min))) { var scroller = scrollView.verticalScroller; scroller.value = Mathf.Lerp(scroller.lowValue, scroller.highValue, linesContainer.IndexOf(lineView) / (float)linesContainer.childCount); } }
public void HandleLineReordered(ScriptLineView lineView) { var viewIndex = linesContainer.IndexOf(lineView); var insertIndex = ViewToGlobaIndex(viewIndex); Lines.Remove(lineView); Lines.Insert(insertIndex, lineView); SyncLineIndexes(); ScriptModified = true; }
public void RemoveLine(ScriptLineView scriptLineView) { Lines.Remove(scriptLineView); if (linesContainer.Contains(scriptLineView)) { linesContainer.Remove(scriptLineView); ViewRange = new IntRange(ViewRange.StartIndex, ViewRange.EndIndex - 1); UpdatePaginationLabel(); } ScriptModified = true; }
public void FocusLine(ScriptLineView lineView, bool focusFirstField = false) { ScriptLineView.SetFocused(lineView); if (focusFirstField) { EditorApplication.update += FocusFieldDelayed; } void FocusFieldDelayed() // Otherwise editor steals the focus. { lineView?.Q <TextField>()?.Q <VisualElement>(TextInputBaseField <string> .textInputUssName)?.Focus(); EditorApplication.update -= FocusFieldDelayed; } }
public void InsertLine(ScriptLineView lineView, int index, int?viewIndex = default) { if (ViewRange.Contains(index)) { var insertViewIndex = viewIndex ?? index - ViewRange.StartIndex; linesContainer.Insert(insertViewIndex, lineView); ViewRange = new IntRange(ViewRange.StartIndex, ViewRange.EndIndex + 1); HandleLineReordered(lineView); UpdatePaginationLabel(); } else { Lines.Insert(index, lineView); SyncLineIndexes(); ScriptModified = true; } }
private void OpenHelpFor(ScriptLineView line) { var url = @"https://naninovel.com/"; switch (line) { case CommentLineView _: url += "guide/naninovel-scripts.html#comment-lines"; break; case LabelLineView _: url += "guide/naninovel-scripts.html#label-lines"; break; case GenericTextLineView _: url += "guide/naninovel-scripts.html#generic-text-lines"; break; case DefineLineView _: url += "guide/naninovel-scripts.html#define-lines"; break; case CommandLineView commandLine: url += $"api/#{commandLine.CommandId.ToLowerInvariant()}"; break; case ErrorLineView errorLine: url += $"api/#{errorLine.CommandId}"; break; default: url += "guide/naninovel-scripts.html"; break; } Application.OpenURL(url); }
private void ShowSearcher(Vector2 position, int insertIndex, int insertViewIndex) { SearcherWindow.Show(EditorWindow.focusedWindow, searchItems, "Insert Line", item => { if (item is null) { return(true); // Prevent nullref when focus is lost before item is selected. } var lineText = string.Empty; var lineView = default(ScriptLineView); switch (item.Name) { case "Commands": return(false); // Do nothing. case "Comment": lineText = CommentScriptLine.IdentifierLiteral; break; case "Label": lineText = LabelScriptLine.IdentifierLiteral; break; case "Generic Text": var genericTextScriptLine = new GenericTextScriptLine(null, -1, string.Empty, null, true); lineView = new GenericTextLineView(genericTextScriptLine, linesContainer); break; case "Define": lineText = DefineScriptLine.IdentifierLiteral; break; default: lineText = CommandScriptLine.IdentifierLiteral + item.Name; break; } if (lineView is null) { lineView = CreateLineView(lineText, -1, true); } InsertLine(lineView, insertIndex, insertViewIndex); ScriptLineView.SetFocused(lineView); lineView.Q <TextField>().Q <VisualElement>(TextInputBaseField <string> .textInputUssName).Focus(); return(true); }, position); }