Implement scrolling in launcher, fix being able to scroll past through the end of the servers list.

This commit is contained in:
UnknownShadow200 2015-12-10 09:04:44 +11:00
parent 0e331ce01a
commit 4d1026e5a4
4 changed files with 47 additions and 14 deletions

View File

@ -186,7 +186,9 @@ namespace ClassicalSharp {
for( int id = 0; id < 255; id++ ) {
Player player = game.Players[id];
if( player == null ) continue;
if( player.CollisionBounds.Intersects( blockBB ) ) return true;
BoundingBox bounds = player.CollisionBounds;
bounds.Min.Y += 1/32f; // when player is exactly standing on top of ground
if( bounds.Intersects( blockBB ) ) return true;
}
return false;
}

View File

@ -20,7 +20,7 @@ namespace Launcher2 {
public override void Tick() {
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
if( table.DraggingWidth && !game.Window.Mouse[MouseButton.Left] )
table.DraggingWidth = false;
table.DraggingWidth = false;
}
protected override void MouseMove( object sender, MouseMoveEventArgs e ) {
@ -41,11 +41,17 @@ namespace Launcher2 {
protected override void OnRemovedChar() { FilterList(); }
protected override void KeyDown( object sender, KeyboardKeyEventArgs e ) {
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
if( e.Key == Key.Enter ) {
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
if( table.Count == 1 && String.IsNullOrEmpty( Get( 3 ) ) )
widgets[3].Text = table.usedEntries[0].Hash;
ConnectToServer( 0, 0 );
} else if( e.Key == Key.Up ) {
table.SetSelected( table.SelectedIndex - 1 );
table.NeedRedraw();
} else if( e.Key == Key.Down ) {
table.SetSelected( table.SelectedIndex + 1 );
table.NeedRedraw();
} else {
base.KeyDown( sender, e );
}
@ -64,7 +70,7 @@ namespace Launcher2 {
base.RedrawLastInput();
if( lastInput == widgets[3] ) {
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
table.SelectedHash = widgets[3].Text;
table.SetSelected( widgets[3].Text );
Resize();
}
}
@ -76,7 +82,7 @@ namespace Launcher2 {
Resize();
selectedWidget = widgets[1];
InputClick( 0, 0 );
InputClick( 0, 0 );
}
public override void Resize() {
@ -107,7 +113,7 @@ namespace Launcher2 {
MakeButtonAt( "Back", 70, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
-10, 5, (x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) );
MakeButtonAt( "Connect", 100, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
-10, 50, ConnectToServer );
-10, 50, ConnectToServer );
MakeTableWidget();
}

View File

@ -59,9 +59,8 @@ namespace Launcher2 {
Window.ConnectToServer( servers, entry.Hash );
lastPress = DateTime.UtcNow;
}
SelectedChanged( entry.Hash );
SelectedHash = entry.Hash;
SetSelected( i );
NeedRedraw();
lastIndex = i;
break;

View File

@ -13,7 +13,7 @@ namespace Launcher2 {
public Action NeedRedraw;
public Action<string> SelectedChanged;
public string SelectedHash;
public int SelectedIndex = -1;
internal TableEntry[] entries, usedEntries;
internal List<ServerListEntry> servers;
@ -96,9 +96,9 @@ namespace Launcher2 {
for( int i = CurrentIndex; i < Count; i++ ) {
args = new DrawTextArgs( filter( usedEntries[i] ), font, true );
if( usedEntries[i].Hash == SelectedHash ) {
if( i == SelectedIndex )
args.Font = boldFont;
}
if( !DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref usedEntries[i] ) ) {
maxIndex = i;
break;
@ -115,14 +115,14 @@ namespace Launcher2 {
int maxWidth, int x, ref int y, ref TableEntry entry ) {
Size size = drawer.MeasureSize( ref args );
if( y + size.Height > Window.Height ) {
y = Window.Height + 5; return false;
y = Window.Height + 3; return false;
}
size.Width = Math.Min( maxWidth, size.Width );
entry.Y = y; entry.Height = size.Height;
args.SkipPartsCheck = false;
drawer.DrawClippedText( ref args, x, y, maxWidth, 30 );
y += size.Height + 5;
y += size.Height + 3;
return true;
}
@ -135,6 +135,10 @@ namespace Launcher2 {
drawer.DrawRect( foreCol, 0, Y + size.Height + 10, Window.Width, 3 );
headerStartY = Y;
headerEndY = Y + size.Height + 10;
args = new DrawTextArgs( "I", font, true );
size = drawer.MeasureSize( ref args );
numEntries = (Window.Height - headerEndY) / (size.Height + 3);
}
int maxIndex;
@ -147,8 +151,30 @@ namespace Launcher2 {
drawer.DrawRect( scrollCol, Window.Width - 10, y1, 10, height );
}
public void SetSelected( int index ) {
if( index >= maxIndex ) CurrentIndex = index - numEntries;
if( index < CurrentIndex ) CurrentIndex = index;
if( index >= Count ) index = Count - 1;
if( index < 0 ) index = 0;
SelectedIndex = index;
ClampIndex();
if( Count > 0 )
SelectedChanged( entries[index].Hash );
}
public void SetSelected( string hash ) {
SelectedIndex = -1;
for( int i = 0; i < Count; i++ ) {
if( entries[i].Hash == hash ) {
SetSelected( i );
return;
}
}
}
public void ClampIndex() {
if( CurrentIndex >= Count - numEntries )
if( CurrentIndex > Count - numEntries )
CurrentIndex = Count - numEntries;
if( CurrentIndex < 0 )
CurrentIndex = 0;