Fix chat not scrolling back properly when many empty lines. (Thanks Good)

This commit is contained in:
UnknownShadow200 2016-03-02 12:53:02 +11:00
parent 2d4e6a7394
commit 32f6ba8563
2 changed files with 49 additions and 40 deletions

View File

@ -150,7 +150,9 @@ namespace ClassicalSharp {
static FastColour backColour = new FastColour( 60, 60, 60, 180 ); static FastColour backColour = new FastColour( 60, 60, 60, 180 );
public void RenderBackground() { public void RenderBackground() {
int height = normalChat.GetUsedHeight(); int minIndex = Math.Min( 0, game.Chat.Log.Count - chatLines );
int height = chatIndex == minIndex ? normalChat.GetUsedHeight() : normalChat.Height;
int y = normalChat.Y + normalChat.Height - height - 5; int y = normalChat.Y + normalChat.Height - height - 5;
int x = normalChat.X - 5; int x = normalChat.X - 5;
int width = Math.Max( clientStatus.Width, normalChat.Width ) + 10; int width = Math.Max( clientStatus.Width, normalChat.Width ) + 10;
@ -160,7 +162,7 @@ namespace ClassicalSharp {
graphicsApi.Draw2DQuad( x, y, width, boxHeight + 10, backColour ); graphicsApi.Draw2DQuad( x, y, width, boxHeight + 10, backColour );
} }
int inputOldHeight = -1, oldStatusOffset = -1; int inputOldHeight = -1;
void UpdateChatYOffset( bool force ) { void UpdateChatYOffset( bool force ) {
int height = textInput.RealHeight; int height = textInput.RealHeight;
if( force || height != inputOldHeight ) { if( force || height != inputOldHeight ) {
@ -313,13 +315,13 @@ namespace ClassicalSharp {
textInput.SendTextInBufferAndReset(); textInput.SendTextInBufferAndReset();
chatIndex = game.Chat.Log.Count - chatLines; chatIndex = game.Chat.Log.Count - chatLines;
ResetIndex(); ScrollHistory();
} else if( key == Key.PageUp ) { } else if( key == Key.PageUp ) {
chatIndex -= chatLines; chatIndex -= chatLines;
ResetIndex(); ScrollHistory();
} else if( key == Key.PageDown ) { } else if( key == Key.PageDown ) {
chatIndex += chatLines; chatIndex += chatLines;
ResetIndex(); ScrollHistory();
} else { } else {
textInput.HandlesKeyDown( key ); textInput.HandlesKeyDown( key );
} }
@ -339,16 +341,23 @@ namespace ClassicalSharp {
public override bool HandlesMouseScroll( int delta ) { public override bool HandlesMouseScroll( int delta ) {
if( !HandlesAllInput ) return false; if( !HandlesAllInput ) return false;
chatIndex -= delta; chatIndex -= delta;
ResetIndex(); ScrollHistory();
return true; return true;
} }
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) { public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
if( !HandlesAllInput || game.HideGui ) return false; if( !HandlesAllInput || game.HideGui ) return false;
if( normalChat.Bounds.Contains( mouseX, mouseY ) ) { if( !normalChat.Bounds.Contains( mouseX, mouseY ) )
return textInput.HandlesMouseClick( mouseX, mouseY, button );
int height = normalChat.GetUsedHeight(); int height = normalChat.GetUsedHeight();
int y = normalChat.Y + normalChat.Height - height; int y = normalChat.Y + normalChat.Height - height;
if( new Rectangle( normalChat.X, y, normalChat.Width, height ).Contains( mouseX, mouseY ) ) { if( new Rectangle( normalChat.X, y, normalChat.Width, height ).Contains( mouseX, mouseY ) )
return HandlesChatClick( mouseX, mouseY );
return false;
}
bool HandlesChatClick( int mouseX, int mouseY ) {
string text = normalChat.GetSelected( mouseX, mouseY ); string text = normalChat.GetSelected( mouseX, mouseY );
if( text == null ) return false; if( text == null ) return false;
@ -370,10 +379,6 @@ namespace ClassicalSharp {
} }
return true; return true;
} }
return false;
}
return textInput.HandlesMouseClick( mouseX, mouseY, button );
}
void OpenUrl( WarningScreen screen ) { void OpenUrl( WarningScreen screen ) {
try { try {
@ -388,7 +393,7 @@ namespace ClassicalSharp {
textInput.AppendText( (string)screen.Metadata ); textInput.AppendText( (string)screen.Metadata );
} }
void ResetIndex() { void ScrollHistory() {
int maxIndex = game.Chat.Log.Count - chatLines; int maxIndex = game.Chat.Log.Count - chatLines;
int minIndex = Math.Min( 0, maxIndex ); int minIndex = Math.Min( 0, maxIndex );
Utils.Clamp( ref chatIndex, minIndex, maxIndex ); Utils.Clamp( ref chatIndex, minIndex, maxIndex );

View File

@ -86,11 +86,15 @@ namespace ClassicalSharp {
} }
public int GetUsedHeight() { public int GetUsedHeight() {
int sum = 0; int sum = 0, max = Textures.Length;
for( int i = 0; i < Textures.Length; i++ ) { for( int i = 0; i < Textures.Length; i++ ) {
if( Textures[i].IsValid ) if( Textures[i].IsValid ) {
sum += Textures[i].Height; max = i; break;
} }
}
for( int i = max; i < Textures.Length; i++ )
sum += Textures[i].Height;
return sum; return sum;
} }