mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Fix chat not scrolling back properly when many empty lines. (Thanks Good)
This commit is contained in:
parent
2d4e6a7394
commit
32f6ba8563
@ -150,7 +150,9 @@ namespace ClassicalSharp {
|
||||
|
||||
static FastColour backColour = new FastColour( 60, 60, 60, 180 );
|
||||
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 x = normalChat.X - 5;
|
||||
int width = Math.Max( clientStatus.Width, normalChat.Width ) + 10;
|
||||
@ -160,7 +162,7 @@ namespace ClassicalSharp {
|
||||
graphicsApi.Draw2DQuad( x, y, width, boxHeight + 10, backColour );
|
||||
}
|
||||
|
||||
int inputOldHeight = -1, oldStatusOffset = -1;
|
||||
int inputOldHeight = -1;
|
||||
void UpdateChatYOffset( bool force ) {
|
||||
int height = textInput.RealHeight;
|
||||
if( force || height != inputOldHeight ) {
|
||||
@ -313,13 +315,13 @@ namespace ClassicalSharp {
|
||||
textInput.SendTextInBufferAndReset();
|
||||
|
||||
chatIndex = game.Chat.Log.Count - chatLines;
|
||||
ResetIndex();
|
||||
ScrollHistory();
|
||||
} else if( key == Key.PageUp ) {
|
||||
chatIndex -= chatLines;
|
||||
ResetIndex();
|
||||
ScrollHistory();
|
||||
} else if( key == Key.PageDown ) {
|
||||
chatIndex += chatLines;
|
||||
ResetIndex();
|
||||
ScrollHistory();
|
||||
} else {
|
||||
textInput.HandlesKeyDown( key );
|
||||
}
|
||||
@ -339,16 +341,23 @@ namespace ClassicalSharp {
|
||||
public override bool HandlesMouseScroll( int delta ) {
|
||||
if( !HandlesAllInput ) return false;
|
||||
chatIndex -= delta;
|
||||
ResetIndex();
|
||||
ScrollHistory();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
||||
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 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 );
|
||||
if( text == null ) return false;
|
||||
|
||||
@ -370,10 +379,6 @@ namespace ClassicalSharp {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return textInput.HandlesMouseClick( mouseX, mouseY, button );
|
||||
}
|
||||
|
||||
void OpenUrl( WarningScreen screen ) {
|
||||
try {
|
||||
@ -388,7 +393,7 @@ namespace ClassicalSharp {
|
||||
textInput.AppendText( (string)screen.Metadata );
|
||||
}
|
||||
|
||||
void ResetIndex() {
|
||||
void ScrollHistory() {
|
||||
int maxIndex = game.Chat.Log.Count - chatLines;
|
||||
int minIndex = Math.Min( 0, maxIndex );
|
||||
Utils.Clamp( ref chatIndex, minIndex, maxIndex );
|
||||
|
@ -86,11 +86,15 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public int GetUsedHeight() {
|
||||
int sum = 0;
|
||||
int sum = 0, max = Textures.Length;
|
||||
for( int i = 0; i < Textures.Length; i++ ) {
|
||||
if( Textures[i].IsValid )
|
||||
sum += Textures[i].Height;
|
||||
if( Textures[i].IsValid ) {
|
||||
max = i; break;
|
||||
}
|
||||
}
|
||||
|
||||
for( int i = max; i < Textures.Length; i++ )
|
||||
sum += Textures[i].Height;
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user