This commit is contained in:
excitedneon 2017-05-11 20:55:38 +03:00
parent 6eb2948e11
commit c5c9f662f1

View File

@ -41,21 +41,17 @@ namespace Cyber.Console {
public int RowLength = 80; public int RowLength = 80;
/// <summary> /// <summary>
/// The linecount threshold when the <see cref="TextField"/> is cleaned /// How many lines are included in the <see cref="TextField"/> when
/// up so it has <see cref="LineCountSavedFromCleanup"/> lines left. /// the total amount of lines exceeds this.
/// </summary> /// </summary>
public int MaxLinesUntilCleanup = 48; public int LinesRendered = 15;
/// <summary>
/// See <see cref="MaxLinesUntilCleanup"/>.
/// </summary>
public int LineCountSavedFromCleanup = 24;
private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>(); private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
private List<string> Lines = new List<string>(); private List<string> Lines = new List<string>();
private List<string> Commands = new List<string>(); private List<string> Commands = new List<string>();
private int LastCommandIndex = 0; private int LastCommandIndex = 0;
private string LastUnexecutedCommand = ""; private string LastUnexecutedCommand = "";
private int ScrollOffset = 1;
/// <summary> /// <summary>
/// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton. /// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton.
@ -128,7 +124,6 @@ namespace Cyber.Console {
/// </remarks> /// </remarks>
/// <param name="text">Text.</param> /// <param name="text">Text.</param>
public void Print(string text) { public void Print(string text) {
// Wrap lines and log them to Lines // Wrap lines and log them to Lines
int Index = 0; int Index = 0;
int EscapeIndex = 0; int EscapeIndex = 0;
@ -143,17 +138,20 @@ namespace Cyber.Console {
TextField.text += Line + "\n"; TextField.text += Line + "\n";
EscapeIndex++; EscapeIndex++;
} while (Index < text.Length && EscapeIndex < 10); } while (Index < text.Length && EscapeIndex < 10);
if (Lines.Count > MaxLinesUntilCleanup) { UpdateTextField();
// The print history is too long, clear up until there are only }
// a small amount left (so the user doesn't notice the cleanup)
private void UpdateTextField() {
string NewLog = ""; string NewLog = "";
Lines.RemoveRange(0, Lines.Count - LineCountSavedFromCleanup); int LineAmt = Mathf.Min(LinesRendered, Lines.Count);
foreach (string Line in Lines) { for (int i = 0; i < LineAmt; i++) {
NewLog += Line + "\n"; int Index = Lines.Count - (i + ScrollOffset);
if (Index >= 0 && Index < Lines.Count) {
NewLog += Lines[i] + "\n";
}
} }
TextField.text = NewLog; TextField.text = NewLog;
} }
}
private void Start() { private void Start() {
AddCommand("help", "Lists all commands.", (args) => { AddCommand("help", "Lists all commands.", (args) => {
@ -229,6 +227,14 @@ namespace Cyber.Console {
InputField.text = LastUnexecutedCommand; InputField.text = LastUnexecutedCommand;
} }
} }
if (Input.GetAxis("Mouse ScrollWheel") > 0 && ScrollOffset + 1 <= Lines.Count) {
ScrollOffset++;
UpdateTextField();
}
if (Input.GetAxis("Mouse ScrollWheel") < 0 && ScrollOffset - 1 > 1) {
ScrollOffset--;
UpdateTextField();
}
// Slide up/down animation // Slide up/down animation
RectTransform Rect = Panel.GetComponent<RectTransform>(); RectTransform Rect = Panel.GetComponent<RectTransform>();