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;
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 ) {

View file

@ -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(); }

View file

@ -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();
}

View file

@ -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 ) {

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.
###### *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.