Make some gui touchups to launcher, default to 640x480.

This commit is contained in:
UnknownShadow200 2015-12-09 15:41:28 +11:00
parent ac42cf3bc8
commit 55db094c0b
8 changed files with 44 additions and 40 deletions

View File

@ -22,6 +22,7 @@ namespace ClassicalSharp {
Socket socket; Socket socket;
Game game; Game game;
bool receivedFirstPosition; bool receivedFirstPosition;
DateTime lastPacket;
public override void Connect( IPAddress address, int port ) { public override void Connect( IPAddress address, int port ) {
socket = new Socket( address.AddressFamily, SocketType.Stream, ProtocolType.Tcp ); socket = new Socket( address.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
@ -41,9 +42,9 @@ namespace ClassicalSharp {
gzippedMap = new FixedBufferStream( reader.buffer ); gzippedMap = new FixedBufferStream( reader.buffer );
MakeLoginPacket( game.Username, game.Mppass ); MakeLoginPacket( game.Username, game.Mppass );
SendPacket(); SendPacket();
lastPacket = DateTime.UtcNow;
} }
public override void Dispose() { public override void Dispose() {
socket.Close(); socket.Close();
Disconnected = true; Disconnected = true;

View File

@ -13,7 +13,7 @@ namespace Launcher2 {
titleFont = new Font( "Arial", 15, FontStyle.Bold ); titleFont = new Font( "Arial", 15, FontStyle.Bold );
inputFont = new Font( "Arial", 15, FontStyle.Regular ); inputFont = new Font( "Arial", 15, FontStyle.Regular );
enterIndex = 4; enterIndex = 4;
widgets = new LauncherWidget[8]; widgets = new LauncherWidget[7];
} }
public override void Init() { public override void Init() {
@ -101,10 +101,6 @@ namespace Launcher2 {
140, 0, (x, y) => game.SetScreen( new MainScreen( game ) ) ); 140, 0, (x, y) => game.SetScreen( new MainScreen( game ) ) );
string text = widgets[6] == null ? "" : widgets[6].Text; string text = widgets[6] == null ? "" : widgets[6].Text;
MakeLabelAt( text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 ); MakeLabelAt( text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 );
if( HasServers && !signingIn )
MakeButtonAt( "Servers", 90, 35, titleFont, Anchor.Centre,
35, 0, ShowServers );
} }
string lastStatus; string lastStatus;
@ -143,11 +139,6 @@ namespace Launcher2 {
SetStatus( "&eSigning in.." ); SetStatus( "&eSigning in.." );
signingIn = true; signingIn = true;
} }
void ShowServers( int mouseX, int mouseY ) {
if( signingIn || !HasServers ) return;
game.SetScreen( new ClassiCubeServersScreen( game ) );
}
void DisplayWebException( WebException ex, string action ) { void DisplayWebException( WebException ex, string action ) {
ErrorHandler.LogError( action, ex ); ErrorHandler.LogError( action, ex );

View File

@ -97,17 +97,17 @@ namespace Launcher2 {
void Draw() { void Draw() {
widgetIndex = 0; widgetIndex = 0;
MakeLabelAt( "Search", titleFont, Anchor.Centre, Anchor.LeftOrTop, -190, 10 ); MakeLabelAt( "Search servers:", inputFont, Anchor.LeftOrTop, Anchor.LeftOrTop, 5, 10 );
MakeInput( Get(), 270, Anchor.LeftOrTop, false, -5, 5, 32 ); MakeInput( Get(), 330, Anchor.LeftOrTop, Anchor.LeftOrTop, false, 135, 5, 32 );
MakeLabelAt( "/play/", inputFont, Anchor.Centre, Anchor.LeftOrTop, -215, 55 ); MakeLabelAt( "../server/play/", inputFont, Anchor.LeftOrTop, Anchor.LeftOrTop, 5, 55 );
MakeInput( Get(), 310, Anchor.LeftOrTop, false, -35, 50, 32 ); MakeInput( Get(), 330, Anchor.LeftOrTop, Anchor.LeftOrTop, false, 135, 50, 32 );
((LauncherInputWidget)widgets[3]).ClipboardFilter = HashFilter; ((LauncherInputWidget)widgets[3]).ClipboardFilter = HashFilter;
MakeButtonAt( "Back", 70, 30, titleFont, Anchor.LeftOrTop, MakeButtonAt( "Back", 70, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
195, 5, (x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) ); -10, 5, (x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) );
MakeButtonAt( "Connect", 100, 30, titleFont, Anchor.LeftOrTop, MakeButtonAt( "Connect", 100, 30, titleFont, Anchor.BottomOrRight, Anchor.LeftOrTop,
180, 50, ConnectToServer ); -10, 50, ConnectToServer );
MakeTableWidget(); MakeTableWidget();
} }

View File

@ -128,6 +128,24 @@ namespace Launcher2 {
widgets[widgetIndex++] = widget; widgets[widgetIndex++] = widget;
} }
protected void MakeInput( string text, int width, Anchor horAnchor, Anchor verAnchor,
bool password, int x, int y, int maxChars ) {
if( widgets[widgetIndex] != null ) {
LauncherInputWidget input = (LauncherInputWidget)widgets[widgetIndex];
input.DrawAt( drawer, text, inputFont, horAnchor, verAnchor, width, 30, x, y );
widgetIndex++;
return;
}
LauncherInputWidget widget = new LauncherInputWidget( game );
widget.OnClick = InputClick;
widget.Password = password;
widget.MaxTextLength = maxChars;
widget.DrawAt( drawer, text, inputFont, horAnchor, verAnchor, width, 30, x, y );
widgets[widgetIndex++] = widget;
}
public override void Dispose() { public override void Dispose() {
game.Window.Mouse.Move -= MouseMove; game.Window.Mouse.Move -= MouseMove;
game.Window.Mouse.ButtonDown -= MouseButtonDown; game.Window.Mouse.ButtonDown -= MouseButtonDown;

View File

@ -124,10 +124,15 @@ namespace Launcher2 {
protected void MakeButtonAt( string text, int width, int height, Font font, protected void MakeButtonAt( string text, int width, int height, Font font,
Anchor verAnchor, int x, int y, Action<int, int> onClick ) { Anchor verAnchor, int x, int y, Action<int, int> onClick ) {
MakeButtonAt( text, width, height, font, Anchor.Centre, verAnchor, x, y, onClick );
}
protected void MakeButtonAt( string text, int width, int height, Font font, Anchor horAnchor,
Anchor verAnchor, int x, int y, Action<int, int> onClick ) {
if( widgets[widgetIndex] != null ) { if( widgets[widgetIndex] != null ) {
LauncherButtonWidget input = (LauncherButtonWidget)widgets[widgetIndex]; LauncherButtonWidget button = (LauncherButtonWidget)widgets[widgetIndex];
input.Active = false; button.Active = false;
input.DrawAt( drawer, text, font, Anchor.Centre, verAnchor, width, height, x, y ); button.DrawAt( drawer, text, font, horAnchor, verAnchor, width, height, x, y );
widgetIndex++; widgetIndex++;
return; return;
} }
@ -137,7 +142,7 @@ namespace Launcher2 {
widget.OnClick = onClick; widget.OnClick = onClick;
widget.Active = false; widget.Active = false;
widget.DrawAt( drawer, text, font, Anchor.Centre, verAnchor, width, height, x, y ); widget.DrawAt( drawer, text, font, horAnchor, verAnchor, width, height, x, y );
widgets[widgetIndex++] = widget; widgets[widgetIndex++] = widget;
} }

View File

@ -85,6 +85,7 @@ namespace Launcher2 {
int currentIndex = (int)(mouseY / scale); int currentIndex = (int)(mouseY / scale);
CurrentIndex = currentIndex; CurrentIndex = currentIndex;
ClampIndex();
NeedRedraw(); NeedRedraw();
} }
} }

View File

@ -53,8 +53,8 @@ namespace Launcher2 {
} }
public int CurrentIndex, Count; public int CurrentIndex, Count;
public int[] ColumnWidths = { 280, 80, 80 }; public int[] ColumnWidths = { 360, 80, 80 };
public int[] DesiredColumnWidths = { 280, 80, 80 }; public int[] DesiredColumnWidths = { 360, 80, 80 };
internal struct TableEntry { internal struct TableEntry {
public string Hash, Name, Players, Uptime; public string Hash, Name, Players, Uptime;
@ -107,7 +107,7 @@ namespace Launcher2 {
Height = Window.Height - Y; Height = Window.Height - Y;
if( separator ) if( separator )
drawer.DrawRect( foreCol, x + maxWidth + 2, Y + 2, 3, Height ); drawer.DrawRect( foreCol, x + maxWidth + 2, Y + 2, 2, Height );
return maxWidth + 5; return maxWidth + 5;
} }
@ -135,24 +135,12 @@ 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 );
int y = Y + size.Height + 10;
size = drawer.MeasureSize( ref args );
numEntries = 0;
for( ; ; ) {
if( y + size.Height > Window.Height ) break;
numEntries++;
drawer.DrawRect( foreCol, 0, y, Window.Width, 1 );
y += size.Height + 5;
}
} }
int maxIndex; int maxIndex;
void DrawScrollbar( IDrawer2D drawer ) { void DrawScrollbar( IDrawer2D drawer ) {
drawer.DrawRect( backCol, Window.Width - 10, Y, 10, Window.Height - Y ); drawer.DrawRect( backCol, Window.Width - 10, Y, 10, Window.Height - Y );
float scale = (Window.Height - 10 - Y) / (float)Count; float scale = (Window.Height - Y) / (float)Count;
int y1 = (int)(Y + CurrentIndex * scale); int y1 = (int)(Y + CurrentIndex * scale);
int height = (int)((maxIndex - CurrentIndex) * scale); int height = (int)((maxIndex - CurrentIndex) * scale);

View File

@ -117,7 +117,7 @@ namespace Launcher2 {
} }
public void Run() { public void Run() {
Window = new NativeWindow( 480, 480, Program.AppName, 0, Window = new NativeWindow( 640, 480, Program.AppName, 0,
GraphicsMode.Default, DisplayDevice.Default ); GraphicsMode.Default, DisplayDevice.Default );
Window.Visible = true; Window.Visible = true;
Drawer = new GdiPlusDrawer2D( null ); Drawer = new GdiPlusDrawer2D( null );