1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 00:53:19 +08:00

Tidy up options login section code; fix incorrect flow logic for online state.

This commit is contained in:
Dean Herbert 2016-12-01 13:07:19 +09:00
parent 9d05c132e8
commit 13d26d0601

View File

@ -14,27 +14,14 @@ namespace osu.Game.Overlays.Options.General
public class LoginOptions : OptionsSubsection, IOnlineComponent public class LoginOptions : OptionsSubsection, IOnlineComponent
{ {
private Container loginForm; private Container loginForm;
private APIAccess api;
protected override string Header => "Sign In";
public LoginOptions() private Action performLogout;
{ protected override string Header => "Sign In";
Children = new[]
{
loginForm = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new[] { new LoadingAnimation() }
}
};
}
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api) private void load(APIAccess api)
{ {
this.api = api; api?.Register(this);
api?.Register(this);
} }
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(APIAccess api, APIState state)
@ -42,13 +29,13 @@ namespace osu.Game.Overlays.Options.General
switch (state) switch (state)
{ {
case APIState.Offline: case APIState.Offline:
loginForm.Children = new Drawable[] Children = new Drawable[]
{ {
new LoginForm(api) new LoginForm()
}; };
break; break;
case APIState.Failing: case APIState.Failing:
loginForm.Children = new Drawable[] Children = new Drawable[]
{ {
new SpriteText new SpriteText
{ {
@ -57,7 +44,7 @@ namespace osu.Game.Overlays.Options.General
}; };
break; break;
case APIState.Connecting: case APIState.Connecting:
loginForm.Children = new Drawable[] Children = new Drawable[]
{ {
new SpriteText new SpriteText
{ {
@ -66,7 +53,7 @@ namespace osu.Game.Overlays.Options.General
}; };
break; break;
case APIState.Online: case APIState.Online:
loginForm.Children = new Drawable[] Children = new Drawable[]
{ {
new SpriteText new SpriteText
{ {
@ -76,26 +63,20 @@ namespace osu.Game.Overlays.Options.General
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Text = "Sign out", Text = "Sign out",
Action = performLogout Action = api.Logout
} }
}; };
break; break;
} }
} }
private void performLogout()
{
api.Logout();
}
class LoginForm : FlowContainer class LoginForm : FlowContainer
{ {
private APIAccess api;
private TextBox username; private TextBox username;
private TextBox password; private TextBox password;
private APIAccess api;
public LoginForm(APIAccess api) public LoginForm()
{ {
Direction = FlowDirection.VerticalOnly; Direction = FlowDirection.VerticalOnly;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;