mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Implement scrolling in launcher, fix being able to scroll past through the end of the servers list.
This commit is contained in:
parent
0e331ce01a
commit
4d1026e5a4
@ -186,7 +186,9 @@ namespace ClassicalSharp {
|
|||||||
for( int id = 0; id < 255; id++ ) {
|
for( int id = 0; id < 255; id++ ) {
|
||||||
Player player = game.Players[id];
|
Player player = game.Players[id];
|
||||||
if( player == null ) continue;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace Launcher2 {
|
|||||||
public override void Tick() {
|
public override void Tick() {
|
||||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||||
if( table.DraggingWidth && !game.Window.Mouse[MouseButton.Left] )
|
if( table.DraggingWidth && !game.Window.Mouse[MouseButton.Left] )
|
||||||
table.DraggingWidth = false;
|
table.DraggingWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void MouseMove( object sender, MouseMoveEventArgs e ) {
|
protected override void MouseMove( object sender, MouseMoveEventArgs e ) {
|
||||||
@ -41,11 +41,17 @@ namespace Launcher2 {
|
|||||||
protected override void OnRemovedChar() { FilterList(); }
|
protected override void OnRemovedChar() { FilterList(); }
|
||||||
|
|
||||||
protected override void KeyDown( object sender, KeyboardKeyEventArgs e ) {
|
protected override void KeyDown( object sender, KeyboardKeyEventArgs e ) {
|
||||||
|
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||||
if( e.Key == Key.Enter ) {
|
if( e.Key == Key.Enter ) {
|
||||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
|
||||||
if( table.Count == 1 && String.IsNullOrEmpty( Get( 3 ) ) )
|
if( table.Count == 1 && String.IsNullOrEmpty( Get( 3 ) ) )
|
||||||
widgets[3].Text = table.usedEntries[0].Hash;
|
widgets[3].Text = table.usedEntries[0].Hash;
|
||||||
ConnectToServer( 0, 0 );
|
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 {
|
} else {
|
||||||
base.KeyDown( sender, e );
|
base.KeyDown( sender, e );
|
||||||
}
|
}
|
||||||
@ -64,7 +70,7 @@ namespace Launcher2 {
|
|||||||
base.RedrawLastInput();
|
base.RedrawLastInput();
|
||||||
if( lastInput == widgets[3] ) {
|
if( lastInput == widgets[3] ) {
|
||||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||||
table.SelectedHash = widgets[3].Text;
|
table.SetSelected( widgets[3].Text );
|
||||||
Resize();
|
Resize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +82,7 @@ namespace Launcher2 {
|
|||||||
|
|
||||||
Resize();
|
Resize();
|
||||||
selectedWidget = widgets[1];
|
selectedWidget = widgets[1];
|
||||||
InputClick( 0, 0 );
|
InputClick( 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Resize() {
|
public override void Resize() {
|
||||||
@ -107,7 +113,7 @@ namespace Launcher2 {
|
|||||||
MakeButtonAt( "Back", 70, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
|
MakeButtonAt( "Back", 70, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
|
||||||
-10, 5, (x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) );
|
-10, 5, (x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) );
|
||||||
MakeButtonAt( "Connect", 100, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
|
MakeButtonAt( "Connect", 100, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
|
||||||
-10, 50, ConnectToServer );
|
-10, 50, ConnectToServer );
|
||||||
MakeTableWidget();
|
MakeTableWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +59,8 @@ namespace Launcher2 {
|
|||||||
Window.ConnectToServer( servers, entry.Hash );
|
Window.ConnectToServer( servers, entry.Hash );
|
||||||
lastPress = DateTime.UtcNow;
|
lastPress = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
SelectedChanged( entry.Hash );
|
|
||||||
SelectedHash = entry.Hash;
|
|
||||||
|
|
||||||
|
SetSelected( i );
|
||||||
NeedRedraw();
|
NeedRedraw();
|
||||||
lastIndex = i;
|
lastIndex = i;
|
||||||
break;
|
break;
|
||||||
|
@ -13,7 +13,7 @@ namespace Launcher2 {
|
|||||||
|
|
||||||
public Action NeedRedraw;
|
public Action NeedRedraw;
|
||||||
public Action<string> SelectedChanged;
|
public Action<string> SelectedChanged;
|
||||||
public string SelectedHash;
|
public int SelectedIndex = -1;
|
||||||
|
|
||||||
internal TableEntry[] entries, usedEntries;
|
internal TableEntry[] entries, usedEntries;
|
||||||
internal List<ServerListEntry> servers;
|
internal List<ServerListEntry> servers;
|
||||||
@ -96,9 +96,9 @@ namespace Launcher2 {
|
|||||||
|
|
||||||
for( int i = CurrentIndex; i < Count; i++ ) {
|
for( int i = CurrentIndex; i < Count; i++ ) {
|
||||||
args = new DrawTextArgs( filter( usedEntries[i] ), font, true );
|
args = new DrawTextArgs( filter( usedEntries[i] ), font, true );
|
||||||
if( usedEntries[i].Hash == SelectedHash ) {
|
if( i == SelectedIndex )
|
||||||
args.Font = boldFont;
|
args.Font = boldFont;
|
||||||
}
|
|
||||||
if( !DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref usedEntries[i] ) ) {
|
if( !DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref usedEntries[i] ) ) {
|
||||||
maxIndex = i;
|
maxIndex = i;
|
||||||
break;
|
break;
|
||||||
@ -115,14 +115,14 @@ namespace Launcher2 {
|
|||||||
int maxWidth, int x, ref int y, ref TableEntry entry ) {
|
int maxWidth, int x, ref int y, ref TableEntry entry ) {
|
||||||
Size size = drawer.MeasureSize( ref args );
|
Size size = drawer.MeasureSize( ref args );
|
||||||
if( y + size.Height > Window.Height ) {
|
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 );
|
size.Width = Math.Min( maxWidth, size.Width );
|
||||||
entry.Y = y; entry.Height = size.Height;
|
entry.Y = y; entry.Height = size.Height;
|
||||||
|
|
||||||
args.SkipPartsCheck = false;
|
args.SkipPartsCheck = false;
|
||||||
drawer.DrawClippedText( ref args, x, y, maxWidth, 30 );
|
drawer.DrawClippedText( ref args, x, y, maxWidth, 30 );
|
||||||
y += size.Height + 5;
|
y += size.Height + 3;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +135,10 @@ namespace Launcher2 {
|
|||||||
drawer.DrawRect( foreCol, 0, Y + size.Height + 10, Window.Width, 3 );
|
drawer.DrawRect( foreCol, 0, Y + size.Height + 10, Window.Width, 3 );
|
||||||
headerStartY = Y;
|
headerStartY = Y;
|
||||||
headerEndY = Y + size.Height + 10;
|
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;
|
int maxIndex;
|
||||||
@ -147,8 +151,30 @@ namespace Launcher2 {
|
|||||||
drawer.DrawRect( scrollCol, Window.Width - 10, y1, 10, height );
|
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() {
|
public void ClampIndex() {
|
||||||
if( CurrentIndex >= Count - numEntries )
|
if( CurrentIndex > Count - numEntries )
|
||||||
CurrentIndex = Count - numEntries;
|
CurrentIndex = Count - numEntries;
|
||||||
if( CurrentIndex < 0 )
|
if( CurrentIndex < 0 )
|
||||||
CurrentIndex = 0;
|
CurrentIndex = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user