Fix the scrolling bug

This commit is contained in:
excitedneon 2017-05-11 23:15:05 +03:00
parent 7abde0d4cf
commit 498fa4ff85
2 changed files with 9 additions and 10 deletions

View File

@ -1987,8 +1987,7 @@ MonoBehaviour:
TextField: {fileID: 1815899005} TextField: {fileID: 1815899005}
Visible: 1 Visible: 1
RowLength: 80 RowLength: 80
MaxLinesUntilCleanup: 30 LinesRendered: 15
LineCountSavedFromCleanup: 15
--- !u!4 &1463006272 --- !u!4 &1463006272
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2320,9 +2319,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: 'Use the "help" command for a list of commands. m_Text:
'
--- !u!222 &1815899006 --- !u!222 &1815899006
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -51,7 +51,7 @@ namespace Cyber.Console {
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; private int ScrollOffset = 0;
/// <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.
@ -144,10 +144,10 @@ namespace Cyber.Console {
private void UpdateTextField() { private void UpdateTextField() {
string NewLog = ""; string NewLog = "";
int LineAmt = Mathf.Min(LinesRendered, Lines.Count); int LineAmt = Mathf.Min(LinesRendered, Lines.Count);
for (int i = 0; i < LineAmt; i++) { for (int i = LineAmt; i > 0; i--) {
int Index = Lines.Count - (i + ScrollOffset); int Index = Lines.Count - (i + ScrollOffset);
if (Index >= 0 && Index < Lines.Count) { if (Index >= 0 && Index < Lines.Count) {
NewLog += Lines[i] + "\n"; NewLog += Lines[Index] + "\n";
} }
} }
TextField.text = NewLog; TextField.text = NewLog;
@ -188,6 +188,8 @@ namespace Cyber.Console {
Application.Quit(); Application.Quit();
}); });
Println("Use the \"help\" command for a list of commands.");
// Set an accurate row length (if the panel is set) // Set an accurate row length (if the panel is set)
if (Panel != null && Panel.GetComponent<RectTransform>() != null) { if (Panel != null && Panel.GetComponent<RectTransform>() != null) {
CharacterInfo CharInfo; CharacterInfo CharInfo;
@ -227,11 +229,11 @@ namespace Cyber.Console {
InputField.text = LastUnexecutedCommand; InputField.text = LastUnexecutedCommand;
} }
} }
if (Input.GetAxis("Mouse ScrollWheel") > 0 && ScrollOffset + 1 <= Lines.Count) { if (Input.GetAxis("Mouse ScrollWheel") > 0 && ScrollOffset + 1 < Lines.Count) {
ScrollOffset++; ScrollOffset++;
UpdateTextField(); UpdateTextField();
} }
if (Input.GetAxis("Mouse ScrollWheel") < 0 && ScrollOffset - 1 > 1) { if (Input.GetAxis("Mouse ScrollWheel") < 0 && ScrollOffset - 1 >= 0) {
ScrollOffset--; ScrollOffset--;
UpdateTextField(); UpdateTextField();
} }