Enter in main screen should switch to classicube.net screen, option to auto close launcher, fix crashing when username or password is invalid.

This commit is contained in:
UnknownShadow200 2015-11-22 12:16:34 +11:00
parent 75fce33012
commit 1a8ae3e8f8
7 changed files with 43 additions and 15 deletions

View File

@ -21,6 +21,7 @@ namespace ClassicalSharp {
g.Players.ShowHoveredNames = v == "yes";
Options.Set( OptionsKey.ShowHoveredNames, v == "yes" );
}),
Make( -140, -50, "Speed multiplier", Anchor.Centre, OnWidgetClick,
g => g.LocalPlayer.SpeedMultiplier.ToString(),
(g, v) => { g.LocalPlayer.SpeedMultiplier = Single.Parse( v );
@ -37,12 +38,17 @@ namespace ClassicalSharp {
// Column 2
!network.IsSinglePlayer ? null :
Make( 140, -50, "Singleplayer physics", Anchor.Centre, OnWidgetClick,
Make( 140, -100, "Singleplayer physics", Anchor.Centre, OnWidgetClick,
g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no",
(g, v) => {
((SinglePlayerServer)network).physics.Enabled = v == "yes";
Options.Set( OptionsKey.SingleplayerPhysics, v == "yes" );
}),
Make( 140, -50, "Auto close launcher", Anchor.Centre, OnWidgetClick,
g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no",
(g, v) => Options.Set( OptionsKey.AutoCloseLauncher, v == "yes" ) ),
Make( 140, 0, "Pushback block placing", Anchor.Centre, OnWidgetClick,
g => g.LocalPlayer.PushbackBlockPlacing
&& g.LocalPlayer.CanPushbackBlocks ? "yes" : "no",
@ -50,10 +56,12 @@ namespace ClassicalSharp {
if( g.LocalPlayer.CanPushbackBlocks)
g.LocalPlayer.PushbackBlockPlacing = v == "yes";
}),
Make( 140, 50, "Mouse sensitivity", Anchor.Centre, OnWidgetClick,
g => g.MouseSensitivity.ToString(),
(g, v) => { g.MouseSensitivity = Int32.Parse( v );
Options.Set( OptionsKey.Sensitivity, v ); } ),
Make( 0, 5, "Back to menu", Anchor.BottomOrRight,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ), null, null ),
null,

View File

@ -22,6 +22,7 @@ namespace ClassicalSharp {
public const string MouseMiddle = "mousemiddle";
public const string MouseRight = "mouseright";
public const string VSync = "vsync";
public const string AutoCloseLauncher = "autocloselauncher";
}
// TODO: implement this

View File

@ -146,7 +146,7 @@ namespace Launcher2 {
if( String.IsNullOrEmpty( mppass ) ) mppass = "(none)";
ClientStartData data = new ClientStartData( Get( 3 ), mppass, ipPart, portPart );
bool ccSkins = ((LauncherBooleanWidget)widgets[10]).Value;
Client.Start( data, ccSkins );
Client.Start( data, ccSkins, ref game.ShouldExit );
}
public override void Dispose() {

View File

@ -29,6 +29,8 @@ namespace Launcher2 {
void KeyDown( object sender, KeyboardKeyEventArgs e ) {
if( e.Key == Key.Tab )
HandleTab();
else if( e.Key == Key.Enter )
widgets[0].OnClick( 0, 0 );
}
void KeyUp( object sender, KeyboardKeyEventArgs e ) {
@ -69,7 +71,7 @@ namespace Launcher2 {
MakeButtonAt( "Singleplayer", Anchor.Centre, Anchor.Centre,
buttonWidth, buttonHeight, 0, 0,
(x, y) => Client.Start( "" ) );
(x, y) => Client.Start( "", ref game.ShouldExit ) );
MakeButtonAt( "Check for updates", Anchor.Centre, Anchor.Centre,
buttonWidth, buttonHeight, 0, 100,

View File

@ -40,6 +40,9 @@ namespace Launcher2 {
/// <summary> Bitmap that contains the entire array of pixels that describe the client drawing area. </summary>
public Bitmap Framebuffer;
/// <summary> Whether at the next tick, the launcher window should proceed to stop displaying frames and subsequently exit. </summary>
public bool ShouldExit;
/// <summary> Contains metadata attached for different screen instances,
/// typically used to save 'last text entered' text when a screen is disposed. </summary>
public Dictionary<string, Dictionary<string, object>> ScreenMetadata =
@ -90,7 +93,7 @@ namespace Launcher2 {
if( entry.Hash == hash ) {
data = new ClientStartData( Session.Username, entry.Mppass,
entry.IPAddress, entry.Port );
Client.Start( data, true );
Client.Start( data, true, ref ShouldExit );
return true;
}
}
@ -102,7 +105,7 @@ namespace Launcher2 {
ErrorHandler.LogError( "retrieving server information", ex );
return false;
}
Client.Start( data, true );
Client.Start( data, true, ref ShouldExit );
return true;
}
@ -124,12 +127,18 @@ namespace Launcher2 {
while( true ) {
Window.ProcessEvents();
if( !Window.Exists ) break;
if( ShouldExit ) {
if( Screen != null )
Screen.Dispose();
break;
}
Screen.Tick();
if( Dirty || Screen.Dirty )
Display();
Thread.Sleep( 1 );
}
Window.Close();
}
void Display() {

View File

@ -7,21 +7,26 @@ namespace Launcher2 {
public static class Client {
public static bool Start( ClientStartData data, bool classicubeSkins ) {
string skinServer = classicubeSkins ? "http://www.classicube.net/static/skins/" : "http://s3.amazonaws.com/MinecraftSkins/";
public static bool Start( ClientStartData data, bool classicubeSkins, ref bool shouldExit ) {
string skinServer = classicubeSkins ? "http://www.classicube.net/static/skins/" :
"http://s3.amazonaws.com/MinecraftSkins/";
string args = data.Username + " " + data.Mppass + " " +
data.Ip + " " + data.Port + " " + skinServer;
UpdateResumeInfo( data, classicubeSkins );
return Start( args );
return Start( args, ref shouldExit );
}
public static bool Start( string args ) {
public static bool Start( string args, ref bool shouldExit ) {
return StartImpl( null, true, args, ref shouldExit );
}
static bool StartImpl( ClientStartData data, bool classicubeSkins,
string args, ref bool shouldExit ) {
Process process = null;
string path = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "ClassicalSharp.exe" );
if( !File.Exists( path ) )
return false;
CheckSettings( data, classicubeSkins, out shouldExit );
if( Type.GetType( "Mono.Runtime" ) != null ) {
process = Process.Start( "mono", "\"" + path + "\" " + args );
} else {
@ -30,16 +35,19 @@ namespace Launcher2 {
return true;
}
internal static void UpdateResumeInfo( ClientStartData data, bool classiCubeSkins ) {
// If the client has changed some settings in the meantime, make sure we keep the changes
internal static void CheckSettings( ClientStartData data, bool classiCubeSkins, out bool shouldExit ) {
shouldExit = false;
// Make sure if the client has changed some settings in the meantime, we keep the changes
if( !Options.Load() )
return;
shouldExit = Options.GetBool( OptionsKey.AutoCloseLauncher, false );
if( data == null ) return;
Options.Set( "launcher-username", data.Username );
Options.Set( "launcher-ip", data.Ip );
Options.Set( "launcher-port", data.Port );
Options.Set( "launcher-mppass", Secure.Encode( data.Mppass, data.Username ) );
Options.Set( "launcher-ccskins", classiCubeSkins );
Options.Set( "launcher-ccskins", classiCubeSkins );
Options.Save();
}
}

View File

@ -75,7 +75,7 @@ namespace Launcher2 {
data = (Dictionary<string, object>)Json.ParseValue( response, ref index, ref success );
List<object> errors = (List<object>)data["errors"];
if( errors.Count > 0 )
if( errors.Count > 0 || (data.ContainsKey( "username" ) && data["username"] == null) )
throw new InvalidOperationException( "Wrong username or password." );
Username = (string)data["username"];