Combine ClassicubeScreen and MainScreen into one screen.

This commit is contained in:
UnknownShadow200 2015-12-26 23:27:42 +11:00
parent 5fc02e4536
commit 30f9e7aee9
5 changed files with 34 additions and 100 deletions

View File

@ -90,6 +90,7 @@ namespace ClassicalSharp.Renderers {
} }
void RenderClouds( double delta ) { void RenderClouds( double delta ) {
if( game.Map.CloudHeight < -2000 ) return;
double time = game.accumulator; double time = game.accumulator;
float offset = (float)( time / 2048f * 0.6f * map.CloudsSpeed ); float offset = (float)( time / 2048f * 0.6f * map.CloudsSpeed );
graphics.SetMatrixMode( MatrixType.Texture ); graphics.SetMatrixMode( MatrixType.Texture );

View File

@ -119,7 +119,7 @@ namespace Launcher2 {
((LauncherInputWidget)widgets[3]).ClipboardFilter = HashFilter; ((LauncherInputWidget)widgets[3]).ClipboardFilter = HashFilter;
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 MainScreen( 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();

View File

@ -7,14 +7,7 @@ using ClassicalSharp;
namespace Launcher2 { namespace Launcher2 {
public sealed class ClassiCubeScreen : LauncherInputScreen { public sealed partial class MainScreen : LauncherInputScreen {
public ClassiCubeScreen( LauncherWindow game ) : base( game ) {
titleFont = new Font( "Arial", 15, FontStyle.Bold );
inputFont = new Font( "Arial", 15, FontStyle.Regular );
enterIndex = 4;
widgets = new LauncherWidget[7];
}
public override void Init() { public override void Init() {
base.Init(); base.Init();
@ -78,29 +71,18 @@ namespace Launcher2 {
Options.Set( "launcher-cc-password", Secure.Encode( password, user ) ); Options.Set( "launcher-cc-password", Secure.Encode( password, user ) );
Options.Save(); Options.Save();
} }
public override void Resize() {
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
Draw();
}
Dirty = true;
}
void Draw() { void DrawClassicube() {
widgetIndex = 0; MakeLabelAt( "Username", titleFont, Anchor.Centre, Anchor.Centre, -180, -150 );
MakeLabelAt( "Username", titleFont, Anchor.Centre, Anchor.Centre, -180, -100 ); MakeLabelAt( "Password", titleFont, Anchor.Centre, Anchor.Centre, -180, -100 );
MakeLabelAt( "Password", titleFont, Anchor.Centre, Anchor.Centre, -180, -50 );
MakeInput( Get(), 300, Anchor.Centre, false, 30, -100, 32 ); MakeInput( Get(), 280, Anchor.Centre, false, 30, -150, 32 );
MakeInput( Get(), 300, Anchor.Centre, true, 30, -50, 32 ); MakeInput( Get(), 280, Anchor.Centre, true, 30, -100, 32 );
MakeButtonAt( "Sign in", 90, 35, titleFont, Anchor.Centre, MakeButtonAt( "Sign in", buttonWidth / 2, buttonHeight, buttonFont,
-75, 0, StartClient ); Anchor.Centre, Anchor.Centre, 0, -50, LoginAsync );
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre, string text = widgets[5] == null ? "" : widgets[5].Text;
140, 0, (x, y) => game.SetScreen( new MainScreen( game ) ) ); MakeLabelAt( text, inputFont, Anchor.Centre, Anchor.Centre, 0, 0 );
string text = widgets[6] == null ? "" : widgets[6].Text;
MakeLabelAt( text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 );
} }
string lastStatus; string lastStatus;
@ -108,10 +90,10 @@ namespace Launcher2 {
lastStatus = text; lastStatus = text;
using( drawer ) { using( drawer ) {
drawer.SetBitmap( game.Framebuffer ); drawer.SetBitmap( game.Framebuffer );
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[6]; LauncherLabelWidget widget = (LauncherLabelWidget)widgets[5];
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height ); game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 ); widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 0 );
Dirty = true; Dirty = true;
} }
} }
@ -123,7 +105,7 @@ namespace Launcher2 {
} }
bool signingIn; bool signingIn;
void StartClient( int mouseX, int mouseY ) { void LoginAsync( int mouseX, int mouseY ) {
if( String.IsNullOrEmpty( Get( 2 ) ) ) { if( String.IsNullOrEmpty( Get( 2 ) ) ) {
SetStatus( "&ePlease enter a username" ); return; SetStatus( "&ePlease enter a username" ); return;
} }
@ -165,18 +147,12 @@ namespace Launcher2 {
} }
} }
public override void Dispose() {
StoreFields();
base.Dispose();
}
void StoreFields() { void StoreFields() {
Dictionary<string, object> metadata; Dictionary<string, object> metadata;
if( !game.ScreenMetadata.TryGetValue( "screen-CC", out metadata ) ) { if( !game.ScreenMetadata.TryGetValue( "screen-CC", out metadata ) ) {
metadata = new Dictionary<string, object>(); metadata = new Dictionary<string, object>();
game.ScreenMetadata["screen-CC"] = metadata; game.ScreenMetadata["screen-CC"] = metadata;
} }
metadata["user"] = Get( 2 ); metadata["user"] = Get( 2 );
metadata["pass"] = Get( 3 ); metadata["pass"] = Get( 3 );
} }

View File

@ -5,40 +5,14 @@ using OpenTK.Input;
namespace Launcher2 { namespace Launcher2 {
public sealed class MainScreen : LauncherScreen { public sealed partial class MainScreen : LauncherInputScreen {
public MainScreen( LauncherWindow game ) : base( game ) { public MainScreen( LauncherWindow game ) : base( game ) {
textFont = new Font( "Arial", 16, FontStyle.Bold ); titleFont = new Font( "Arial", 15, FontStyle.Bold );
widgets = new LauncherWidget[4]; buttonFont = new Font( "Arial", 16, FontStyle.Bold );
buttonFont = textFont; inputFont = new Font( "Arial", 15, FontStyle.Regular );
} enterIndex = 4;
widgets = new LauncherWidget[10];
void KeyDown( object sender, KeyboardKeyEventArgs e ) {
if( e.Key == Key.Tab ) {
HandleTab();
} else if( e.Key == Key.Enter ) {
LauncherWidget widget = selectedWidget != null ?
selectedWidget : widgets[0];
if( widget.OnClick != null )
widget.OnClick( 0, 0 );
}
}
void KeyUp( object sender, KeyboardKeyEventArgs e ) {
if( e.Key == Key.Tab )
tabDown = false;
}
public override void Init() {
game.Window.Keyboard.KeyDown += KeyDown;
game.Window.Keyboard.KeyUp += KeyUp;
game.Window.Mouse.Move += MouseMove;
game.Window.Mouse.ButtonDown += MouseButtonDown;
Resize();
}
public override void Tick() {
} }
public override void Resize() { public override void Resize() {
@ -49,45 +23,28 @@ namespace Launcher2 {
Dirty = true; Dirty = true;
} }
Font textFont;
void Draw() { void Draw() {
widgetIndex = 0; widgetIndex = 0;
MakeButtonAt( "ClassiCube.net", Anchor.Centre, Anchor.Centre, DrawClassicube();
buttonWidth, buttonHeight, 0, -100,
(x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) );
MakeButtonAt( "Direct connect", Anchor.Centre, Anchor.Centre, MakeButtonAt( "Direct connect", buttonWidth, buttonHeight, buttonFont,
buttonWidth, buttonHeight, 0, -50, Anchor.Centre, Anchor.Centre, 0, 50,
(x, y) => game.SetScreen( new DirectConnectScreen( game ) ) ); (x, y) => game.SetScreen( new DirectConnectScreen( game ) ) );
MakeButtonAt( "Singleplayer", Anchor.Centre, Anchor.Centre, MakeButtonAt( "Singleplayer", buttonWidth, buttonHeight, buttonFont,
buttonWidth, buttonHeight, 0, 0, Anchor.Centre, Anchor.Centre, 0, 100,
(x, y) => Client.Start( "", ref game.ShouldExit ) ); (x, y) => Client.Start( "", ref game.ShouldExit ) );
MakeButtonAt( "Check for updates", Anchor.Centre, Anchor.Centre, MakeButtonAt( "Update check", buttonWidth - 40, buttonHeight, buttonFont,
buttonWidth, buttonHeight, 0, 100, Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -10,
(x, y) => game.SetScreen( new UpdatesScreen( game ) ) ); (x, y) => game.SetScreen( new UpdatesScreen( game ) ) );
} }
const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150; const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150;
void MakeButtonAt( string text, Anchor horAnchor,
Anchor verAnchor, int width, int height, int x, int y, Action<int, int> onClick ) {
LauncherButtonWidget widget = new LauncherButtonWidget( game );
widget.Text = text;
widget.OnClick = onClick;
widget.Active = false;
widget.DrawAt( drawer, text, textFont, horAnchor, verAnchor, width, height, x, y );
widgets[widgetIndex++] = widget;
}
public override void Dispose() { public override void Dispose() {
game.Window.Mouse.Move -= MouseMove; buttonFont.Dispose();
game.Window.Mouse.ButtonDown -= MouseButtonDown; StoreFields();
base.Dispose();
game.Window.Keyboard.KeyDown -= KeyDown;
game.Window.Keyboard.KeyUp -= KeyUp;
textFont.Dispose();
} }
} }
} }

View File

@ -57,11 +57,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Gui\PlatformDrawer.cs" /> <Compile Include="Gui\PlatformDrawer.cs" />
<Compile Include="Gui\Screens\ClassiCubeScreen.cs" />
<Compile Include="Gui\Screens\ClassiCubeServersScreen.cs" /> <Compile Include="Gui\Screens\ClassiCubeServersScreen.cs" />
<Compile Include="Gui\Screens\DirectConnectScreen.cs" /> <Compile Include="Gui\Screens\DirectConnectScreen.cs" />
<Compile Include="Gui\Screens\LauncherInputScreen.cs" /> <Compile Include="Gui\Screens\LauncherInputScreen.cs" />
<Compile Include="Gui\Screens\LauncherScreen.cs" /> <Compile Include="Gui\Screens\LauncherScreen.cs" />
<Compile Include="Gui\Screens\MainScreen.Classicube.cs" />
<Compile Include="Gui\Screens\MainScreen.cs" /> <Compile Include="Gui\Screens\MainScreen.cs" />
<Compile Include="Gui\Screens\ResourcesScreen.cs" /> <Compile Include="Gui\Screens\ResourcesScreen.cs" />
<Compile Include="Gui\Screens\UpdatesScreen.cs" /> <Compile Include="Gui\Screens\UpdatesScreen.cs" />