From a5d91ca5cb14a70796366d077313b644b94f7153 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 22 Dec 2015 19:10:54 +1100 Subject: [PATCH] Fix using scroll wheel on last column past last valid item crashing the client. (Thanks nyxzimus) --- .../2D/Screens/BlockSelectScreen.Scrolling.cs | 25 ++++++++++--------- .../2D/Screens/BlockSelectScreen.cs | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs b/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs index 7af6a823a..61d2f8e33 100644 --- a/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs +++ b/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs @@ -8,7 +8,7 @@ namespace ClassicalSharp { static FastColour scrollCol = new FastColour( 10, 10, 10, 220 ); static FastColour scrollUsedCol = new FastColour( 100, 100, 100, 220 ); void DrawScrollbar() { - graphicsApi.Draw2DQuad( TableX, TableY, scrollbarWidth, + graphicsApi.Draw2DQuad( TableX, TableY, scrollbarWidth, TableHeight, scrollCol ); float scale = TableHeight / (float)rows; int yOffset = (int)Math.Ceiling(scrollY * scale); @@ -16,26 +16,27 @@ namespace ClassicalSharp { if( yOffset + height > TableHeight ) height = TableHeight - yOffset; - graphicsApi.Draw2DQuad( TableX, TableY + yOffset, scrollbarWidth, + graphicsApi.Draw2DQuad( TableX, TableY + yOffset, scrollbarWidth, height, scrollUsedCol ); } public override bool HandlesMouseScroll( int delta ) { bool bounds = Contains( TableX, TableY, TableWidth, TableHeight, game.Mouse.X, game.Mouse.Y ); - if( !bounds ) return false; + if( !bounds || selIndex == -1 ) return false; + delta = -delta; int startScrollY = scrollY; - scrollY -= delta; - ClampScrollY(); + selIndex += delta * blocksPerRow; - int diffY = scrollY - startScrollY; - if( selIndex >= 0 ) { - selIndex += diffY * blocksPerRow; - RecreateBlockInfoTexture(); - } + if( selIndex >= blocksTable.Length || selIndex < 0 ) + selIndex -= delta * blocksPerRow; + Utils.Clamp( ref selIndex, 0, blocksTable.Length - 1 ); + int endScrollY = selIndex / blocksPerRow; + + UpdateSelectedState(); return true; } - int scrollY; + int scrollY; void UpdateScrollY() { scrollY = selIndex / blocksPerRow; @@ -51,7 +52,7 @@ namespace ClassicalSharp { void ScrollbarClick( int mouseY ) { mouseY -= TableY; - float scale = TableHeight / (float)rows; + float scale = TableHeight / (float)rows; scrollY = (int)(mouseY / scale); ClampScrollY(); } diff --git a/ClassicalSharp/2D/Screens/BlockSelectScreen.cs b/ClassicalSharp/2D/Screens/BlockSelectScreen.cs index cb06624dd..5ae27ae16 100644 --- a/ClassicalSharp/2D/Screens/BlockSelectScreen.cs +++ b/ClassicalSharp/2D/Screens/BlockSelectScreen.cs @@ -174,7 +174,7 @@ namespace ClassicalSharp { lastCreatedIndex = selIndex; graphicsApi.DeleteTexture( ref blockInfoTexture ); - if( selIndex == -1 || selIndex >= blocksTable.Length ) return; + if( selIndex == -1 ) return; Block block = blocksTable[selIndex]; UpdateBlockInfoString( block );