From 331f683a5ca813a7805bbf9b89fea49d14ac3f17 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 30 Mar 2016 23:22:44 +1100 Subject: [PATCH] Implement same logic in launchers table widget too. --- .../2D/Screens/BlockSelectScreen.Scrolling.cs | 4 +- .../Gui/Screens/ClassiCubeServersScreen.cs | 2 + .../TableWidget/LauncherTableWidget.Input.cs | 58 +++++++++++-------- .../Gui/TableWidget/LauncherTableWidget.cs | 15 +++-- readme.md | 6 +- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs b/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs index 493309ac8..840f955d7 100644 --- a/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs +++ b/ClassicalSharp/2D/Screens/BlockSelectScreen.Scrolling.cs @@ -22,9 +22,7 @@ namespace ClassicalSharp.Gui { float scale = ScrollbarScale; y = (int)Math.Ceiling( scrollY * scale ); height = (int)Math.Ceiling( maxRows * scale ); - - if( y + height > TableHeight ) - height = TableHeight - y; + height = Math.Min(y + height, TableHeight) - y; } public override bool HandlesMouseScroll( int delta ) { diff --git a/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs b/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs index 4637321fb..dc43276bb 100644 --- a/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs +++ b/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs @@ -24,6 +24,7 @@ namespace Launcher { if( !game.Window.Mouse[MouseButton.Left] ) { table.DraggingColumn = -1; table.DraggingScrollbar = false; + table.mouseOffset = 0; } } @@ -39,6 +40,7 @@ namespace Launcher { LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex]; table.DraggingColumn = -1; table.DraggingScrollbar = false; + table.mouseOffset = 0; } protected override void OnAddedChar() { FilterList(); } diff --git a/Launcher2/Gui/TableWidget/LauncherTableWidget.Input.cs b/Launcher2/Gui/TableWidget/LauncherTableWidget.Input.cs index 21e86a2b8..7ecb117f4 100644 --- a/Launcher2/Gui/TableWidget/LauncherTableWidget.Input.cs +++ b/Launcher2/Gui/TableWidget/LauncherTableWidget.Input.cs @@ -11,23 +11,9 @@ namespace Launcher { PlayersComparer playerComp = new PlayersComparer(); UptimeComparer uptimeComp = new UptimeComparer(); SoftwareComparer softwareComp = new SoftwareComparer(); - public int DraggingColumn = -1; - public bool DraggingScrollbar = false; - - void HandleOnClick( int mouseX, int mouseY ) { - if( mouseX >= Window.Width - 10 ) { - ScrollbarClick( mouseY ); - DraggingScrollbar = true; - lastIndex = -10; return; - } - - if( mouseY >= headerStartY && mouseY < headerEndY ) { - SelectHeader( mouseX, mouseY ); - } else { - GetSelectedServer( mouseX, mouseY ); - } - lastPress = DateTime.UtcNow; - } + internal int DraggingColumn = -1; + internal bool DraggingScrollbar = false; + internal int mouseOffset; void SelectHeader( int mouseX, int mouseY ) { int x = X; @@ -88,27 +74,53 @@ namespace Launcher { } } + void HandleOnClick( int mouseX, int mouseY ) { + if( mouseX >= Window.Width - 10 ) { + ScrollbarClick( mouseY ); + DraggingScrollbar = true; + lastIndex = -10; return; + } + + if( mouseY >= headerStartY && mouseY < headerEndY ) { + SelectHeader( mouseX, mouseY ); + } else { + GetSelectedServer( mouseX, mouseY ); + } + lastPress = DateTime.UtcNow; + } + int lastIndex = -10; DateTime lastPress; public void MouseMove( int x, int y, int deltaX, int deltaY ) { if( DraggingScrollbar ) { - ScrollbarClick( y ); + y -= Y; + float scale = Height / (float)Count; + CurrentIndex = (int)((y - mouseOffset) / scale); + ClampIndex(); } else if( DraggingColumn >= 0 ) { if( x >= Window.Width - 20 ) return; int col = DraggingColumn; ColumnWidths[col] += deltaX; Utils.Clamp( ref ColumnWidths[col], 20, Window.Width - 20 ); - DesiredColumnWidths[col] = ColumnWidths[col]; - NeedRedraw(); + DesiredColumnWidths[col] = ColumnWidths[col]; } + NeedRedraw(); } void ScrollbarClick( int mouseY ) { mouseY -= Y; - float scale = (Window.Height - 10) / (float)Count; + int y, height; + GetScrollbarCoords( out y, out height ); + int delta = (maxIndex - CurrentIndex); - int currentIndex = (int)(mouseY / scale); - CurrentIndex = currentIndex; + if( mouseY < y ) { + CurrentIndex -= delta; + } else if( mouseY >= y + height ) { + CurrentIndex += delta; + } else { + DraggingScrollbar = true; + mouseOffset = mouseY - y; + } ClampIndex(); NeedRedraw(); } diff --git a/Launcher2/Gui/TableWidget/LauncherTableWidget.cs b/Launcher2/Gui/TableWidget/LauncherTableWidget.cs index 71d071f3a..d648a5cd3 100644 --- a/Launcher2/Gui/TableWidget/LauncherTableWidget.cs +++ b/Launcher2/Gui/TableWidget/LauncherTableWidget.cs @@ -170,12 +170,17 @@ namespace Launcher { void DrawScrollbar( IDrawer2D drawer ) { FastColour col = Window.ClassicBackground ? new FastColour( 80, 80, 80 ) : LauncherSkin.ButtonBorderCol; drawer.Clear( col, Window.Width - 10, Y, 10, Height ); + col = Window.ClassicBackground ? new FastColour( 160, 160, 160 ) : LauncherSkin.ButtonForeActiveCol; + int yOffset, height; + GetScrollbarCoords( out yOffset, out height ); + drawer.Clear( col, Window.Width - 10, Y + yOffset, 10, height ); + } + + void GetScrollbarCoords( out int y, out int height ) { float scale = Height / (float)Count; - - col = Window.ClassicBackground ? new FastColour( 160, 160, 160 ) : LauncherSkin.ButtonForeActiveCol; - int y1 = (int)(Y + CurrentIndex * scale); - int height = (int)((maxIndex - CurrentIndex) * scale); - drawer.Clear( col, Window.Width - 10, y1, 10, height + 1 ); + y = (int)Math.Ceiling(CurrentIndex * scale); + height = (int)Math.Ceiling((maxIndex - CurrentIndex) * scale); + height = Math.Min(y + height, Height) - y; } public void SetSelected( int index ) { diff --git a/readme.md b/readme.md index 0d2984b9d..a95e2720b 100644 --- a/readme.md +++ b/readme.md @@ -32,12 +32,12 @@ Run classicalsharp.exe. Run launcher.exe. You can connect to LAN/locally hosted servers, ~~minecraft.net servers,~~ and classicube.net servers through the launcher. ###### *Mono specific* -*You must use either build using the Mono compiler or define `__MonoCS__` when building, otherwise you will get runtime errors when decompressing the map using Mono.* +*If you are using Wine, you need to mark both ClassicalSharp.exe and Launcher.exe as executable, then type this into the terminal: `./Launcher.exe` +If you are using Mono, you just need to type `mono Launcher.exe` into the terminal.* *Also when using older mono versions, you may need to run `mozroots --import --sync` to import trusted root certificates, otherwise you will get an 'Error writing headers' exception.* -*If you are using Wine, you need to mark both ClassicalSharp.exe and Launcher.exe as executable, then type this into the terminal: `./Launcher.exe` -If you are using Mono, you just need to type `mono Launcher.exe` into the terminal.* +*You must use either build using the Mono compiler or define `__MonoCS__` when building, otherwise you will get runtime errors when decompressing the map using Mono.* #### Tips * Press escape (after joining a world) to switch to the pause menu.