2016-12-06 17:56:20 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-11-30 15:54:15 +08:00
|
|
|
|
using OpenTK;
|
2016-11-12 18:44:16 +08:00
|
|
|
|
using osu.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online.API;
|
2016-12-20 22:28:27 +08:00
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
|
2016-11-08 10:24:41 +08:00
|
|
|
|
namespace osu.Game.Overlays.Options.General
|
2016-11-03 10:22:34 +08:00
|
|
|
|
{
|
2016-11-30 15:54:15 +08:00
|
|
|
|
public class LoginOptions : OptionsSubsection, IOnlineComponent
|
2016-11-03 10:22:34 +08:00
|
|
|
|
{
|
2016-12-20 22:28:27 +08:00
|
|
|
|
private APIAccess api;
|
2016-11-09 11:38:40 +08:00
|
|
|
|
|
2016-12-01 12:07:19 +08:00
|
|
|
|
protected override string Header => "Sign In";
|
2016-11-09 11:38:40 +08:00
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
|
|
|
|
private void load(APIAccess api)
|
2016-12-01 12:07:19 +08:00
|
|
|
|
{
|
|
|
|
|
api?.Register(this);
|
2016-12-20 22:28:27 +08:00
|
|
|
|
this.api = api;
|
2016-11-04 10:43:00 +08:00
|
|
|
|
}
|
2016-11-09 11:38:40 +08:00
|
|
|
|
|
2016-11-30 15:54:15 +08:00
|
|
|
|
public void APIStateChanged(APIAccess api, APIState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case APIState.Offline:
|
2016-12-01 12:07:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-30 15:54:15 +08:00
|
|
|
|
{
|
2016-12-01 12:07:19 +08:00
|
|
|
|
new LoginForm()
|
2016-11-30 15:54:15 +08:00
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case APIState.Failing:
|
2016-12-01 12:07:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-30 15:54:15 +08:00
|
|
|
|
{
|
2016-11-30 18:43:03 +08:00
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
2016-12-01 15:04:58 +08:00
|
|
|
|
Text = "Connection failing :(",
|
2016-11-30 15:54:15 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case APIState.Connecting:
|
2016-12-01 12:07:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-30 15:54:15 +08:00
|
|
|
|
{
|
2016-11-30 18:43:03 +08:00
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
2016-12-01 15:04:58 +08:00
|
|
|
|
Text = "Connecting...",
|
2016-11-30 15:54:15 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case APIState.Online:
|
2016-12-01 12:07:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-30 15:54:15 +08:00
|
|
|
|
{
|
2016-11-30 18:43:03 +08:00
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
2016-12-01 15:04:58 +08:00
|
|
|
|
Text = $"Connected as {api.Username}!",
|
2016-11-30 15:54:15 +08:00
|
|
|
|
},
|
2016-11-30 18:43:03 +08:00
|
|
|
|
new OsuButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = "Sign out",
|
2016-12-21 06:51:01 +08:00
|
|
|
|
Action = api.Logout
|
2016-11-30 18:43:03 +08:00
|
|
|
|
}
|
2016-11-30 15:54:15 +08:00
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-11-30 18:43:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 10:43:00 +08:00
|
|
|
|
class LoginForm : FlowContainer
|
|
|
|
|
{
|
2016-11-30 15:54:15 +08:00
|
|
|
|
private TextBox username;
|
2016-12-20 22:52:16 +08:00
|
|
|
|
private PasswordTextBox password;
|
2016-12-01 12:07:19 +08:00
|
|
|
|
private APIAccess api;
|
2016-11-30 15:54:15 +08:00
|
|
|
|
|
2016-12-24 04:49:42 +08:00
|
|
|
|
private CheckBoxOption saveUsername;
|
|
|
|
|
private CheckBoxOption savePassword;
|
2016-12-20 22:28:27 +08:00
|
|
|
|
|
|
|
|
|
private void performLogin()
|
2016-11-04 10:43:00 +08:00
|
|
|
|
{
|
2016-12-20 22:28:27 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text))
|
|
|
|
|
api.Login(username.Text, password.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
|
|
|
|
private void load(APIAccess api, OsuConfigManager config)
|
|
|
|
|
{
|
|
|
|
|
this.api = api;
|
2016-11-04 10:43:00 +08:00
|
|
|
|
Direction = FlowDirection.VerticalOnly;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Spacing = new Vector2(0, 5);
|
|
|
|
|
Children = new Drawable[]
|
2016-11-03 10:22:34 +08:00
|
|
|
|
{
|
2016-11-04 10:43:00 +08:00
|
|
|
|
new SpriteText { Text = "Username" },
|
2016-12-20 22:28:27 +08:00
|
|
|
|
username = new TextBox
|
|
|
|
|
{
|
|
|
|
|
Height = 20,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = api?.Username ?? string.Empty
|
|
|
|
|
},
|
2016-11-04 10:43:00 +08:00
|
|
|
|
new SpriteText { Text = "Password" },
|
2016-12-20 22:28:27 +08:00
|
|
|
|
password = new PasswordTextBox
|
|
|
|
|
{
|
|
|
|
|
Height = 20,
|
|
|
|
|
RelativeSizeAxes = Axes.X
|
|
|
|
|
},
|
2016-12-24 04:49:42 +08:00
|
|
|
|
saveUsername = new CheckBoxOption
|
2016-12-20 22:28:27 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Remember Username",
|
|
|
|
|
Bindable = config.GetBindable<bool>(OsuConfig.SaveUsername),
|
|
|
|
|
},
|
2016-12-24 04:49:42 +08:00
|
|
|
|
savePassword = new CheckBoxOption
|
2016-12-20 22:28:27 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Remember Password",
|
|
|
|
|
Bindable = config.GetBindable<bool>(OsuConfig.SavePassword),
|
|
|
|
|
},
|
2016-11-04 10:43:00 +08:00
|
|
|
|
new OsuButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = "Log in",
|
2016-11-30 15:54:15 +08:00
|
|
|
|
Action = performLogin
|
2016-12-20 22:28:27 +08:00
|
|
|
|
},
|
|
|
|
|
new OsuButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = "Register",
|
2016-12-21 06:51:01 +08:00
|
|
|
|
//Action = registerLink
|
2016-11-04 10:43:00 +08:00
|
|
|
|
}
|
2016-12-20 22:28:27 +08:00
|
|
|
|
};
|
2016-11-30 15:54:15 +08:00
|
|
|
|
}
|
2016-11-03 10:22:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-09 07:13:20 +08:00
|
|
|
|
}
|