Implement same logic in launchers table widget too.

This commit is contained in:
UnknownShadow200 2016-03-30 23:22:44 +11:00
parent 32697c43ca
commit 331f683a5c
5 changed files with 51 additions and 34 deletions

View File

@ -22,9 +22,7 @@ namespace ClassicalSharp.Gui {
float scale = ScrollbarScale; float scale = ScrollbarScale;
y = (int)Math.Ceiling( scrollY * scale ); y = (int)Math.Ceiling( scrollY * scale );
height = (int)Math.Ceiling( maxRows * scale ); height = (int)Math.Ceiling( maxRows * scale );
height = Math.Min(y + height, TableHeight) - y;
if( y + height > TableHeight )
height = TableHeight - y;
} }
public override bool HandlesMouseScroll( int delta ) { public override bool HandlesMouseScroll( int delta ) {

View File

@ -24,6 +24,7 @@ namespace Launcher {
if( !game.Window.Mouse[MouseButton.Left] ) { if( !game.Window.Mouse[MouseButton.Left] ) {
table.DraggingColumn = -1; table.DraggingColumn = -1;
table.DraggingScrollbar = false; table.DraggingScrollbar = false;
table.mouseOffset = 0;
} }
} }
@ -39,6 +40,7 @@ namespace Launcher {
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex]; LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
table.DraggingColumn = -1; table.DraggingColumn = -1;
table.DraggingScrollbar = false; table.DraggingScrollbar = false;
table.mouseOffset = 0;
} }
protected override void OnAddedChar() { FilterList(); } protected override void OnAddedChar() { FilterList(); }

View File

@ -11,23 +11,9 @@ namespace Launcher {
PlayersComparer playerComp = new PlayersComparer(); PlayersComparer playerComp = new PlayersComparer();
UptimeComparer uptimeComp = new UptimeComparer(); UptimeComparer uptimeComp = new UptimeComparer();
SoftwareComparer softwareComp = new SoftwareComparer(); SoftwareComparer softwareComp = new SoftwareComparer();
public int DraggingColumn = -1; internal int DraggingColumn = -1;
public bool DraggingScrollbar = false; internal bool DraggingScrollbar = false;
internal int mouseOffset;
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;
}
void SelectHeader( int mouseX, int mouseY ) { void SelectHeader( int mouseX, int mouseY ) {
int x = X; 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; int lastIndex = -10;
DateTime lastPress; DateTime lastPress;
public void MouseMove( int x, int y, int deltaX, int deltaY ) { public void MouseMove( int x, int y, int deltaX, int deltaY ) {
if( DraggingScrollbar ) { if( DraggingScrollbar ) {
ScrollbarClick( y ); y -= Y;
float scale = Height / (float)Count;
CurrentIndex = (int)((y - mouseOffset) / scale);
ClampIndex();
} else if( DraggingColumn >= 0 ) { } else if( DraggingColumn >= 0 ) {
if( x >= Window.Width - 20 ) return; if( x >= Window.Width - 20 ) return;
int col = DraggingColumn; int col = DraggingColumn;
ColumnWidths[col] += deltaX; ColumnWidths[col] += deltaX;
Utils.Clamp( ref ColumnWidths[col], 20, Window.Width - 20 ); Utils.Clamp( ref ColumnWidths[col], 20, Window.Width - 20 );
DesiredColumnWidths[col] = ColumnWidths[col]; DesiredColumnWidths[col] = ColumnWidths[col];
NeedRedraw();
} }
NeedRedraw();
} }
void ScrollbarClick( int mouseY ) { void ScrollbarClick( int mouseY ) {
mouseY -= Y; 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); if( mouseY < y ) {
CurrentIndex = currentIndex; CurrentIndex -= delta;
} else if( mouseY >= y + height ) {
CurrentIndex += delta;
} else {
DraggingScrollbar = true;
mouseOffset = mouseY - y;
}
ClampIndex(); ClampIndex();
NeedRedraw(); NeedRedraw();
} }

View File

@ -170,12 +170,17 @@ namespace Launcher {
void DrawScrollbar( IDrawer2D drawer ) { void DrawScrollbar( IDrawer2D drawer ) {
FastColour col = Window.ClassicBackground ? new FastColour( 80, 80, 80 ) : LauncherSkin.ButtonBorderCol; FastColour col = Window.ClassicBackground ? new FastColour( 80, 80, 80 ) : LauncherSkin.ButtonBorderCol;
drawer.Clear( col, Window.Width - 10, Y, 10, Height ); drawer.Clear( col, Window.Width - 10, Y, 10, Height );
float scale = Height / (float)Count;
col = Window.ClassicBackground ? new FastColour( 160, 160, 160 ) : LauncherSkin.ButtonForeActiveCol; col = Window.ClassicBackground ? new FastColour( 160, 160, 160 ) : LauncherSkin.ButtonForeActiveCol;
int y1 = (int)(Y + CurrentIndex * scale); int yOffset, height;
int height = (int)((maxIndex - CurrentIndex) * scale); GetScrollbarCoords( out yOffset, out height );
drawer.Clear( col, Window.Width - 10, y1, 10, height + 1 ); drawer.Clear( col, Window.Width - 10, Y + yOffset, 10, height );
}
void GetScrollbarCoords( out int y, out int height ) {
float scale = Height / (float)Count;
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 ) { public void SetSelected( int index ) {

View File

@ -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. Run launcher.exe. You can connect to LAN/locally hosted servers, ~~minecraft.net servers,~~ and classicube.net servers through the launcher.
###### *Mono specific* ###### *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.* *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` *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 Mono, you just need to type `mono Launcher.exe` into the terminal.*
#### Tips #### Tips
* Press escape (after joining a world) to switch to the pause menu. * Press escape (after joining a world) to switch to the pause menu.