1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 18:07:25 +08:00
osu-lazer/osu.Game/Overlays/Options/General/LoginOptions.cs

118 lines
3.8 KiB
C#
Raw Normal View History

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;
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-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-11-04 10:43:00 +08:00
private Container loginForm;
2016-11-09 11:38:40 +08:00
private Action performLogout;
protected override string Header => "Sign In";
2016-11-09 11:38:40 +08:00
[BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api)
{
api?.Register(this);
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:
Children = new Drawable[]
2016-11-30 15:54:15 +08:00
{
new LoginForm()
2016-11-30 15:54:15 +08:00
};
break;
case APIState.Failing:
Children = new Drawable[]
2016-11-30 15:54:15 +08:00
{
new SpriteText
{
Text = "Connection failing :(",
2016-11-30 15:54:15 +08:00
},
};
break;
case APIState.Connecting:
Children = new Drawable[]
2016-11-30 15:54:15 +08:00
{
new SpriteText
{
Text = "Connecting...",
2016-11-30 15:54:15 +08:00
},
};
break;
case APIState.Online:
Children = new Drawable[]
2016-11-30 15:54:15 +08:00
{
new SpriteText
{
Text = $"Connected as {api.Username}!",
2016-11-30 15:54:15 +08:00
},
new OsuButton
{
RelativeSizeAxes = Axes.X,
Text = "Sign out",
Action = api.Logout
}
2016-11-30 15:54:15 +08:00
};
break;
}
}
2016-11-04 10:43:00 +08:00
class LoginForm : FlowContainer
{
2016-11-30 15:54:15 +08:00
private TextBox username;
private TextBox password;
private APIAccess api;
2016-11-30 15:54:15 +08:00
public LoginForm()
2016-11-04 10:43:00 +08:00
{
Direction = FlowDirection.VerticalOnly;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
Spacing = new Vector2(0, 5);
// TODO: Wire things up
Children = new Drawable[]
2016-11-03 10:22:34 +08:00
{
2016-11-04 10:43:00 +08:00
new SpriteText { Text = "Username" },
2016-11-30 15:54:15 +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-11-30 15:54:15 +08:00
password = new PasswordTextBox { Height = 20, RelativeSizeAxes = Axes.X },
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-11-04 10:43:00 +08:00
}
};
}
2016-11-30 15:54:15 +08:00
private void performLogin()
{
if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text))
api.Login(username.Text, password.Text);
2016-11-30 15:54:15 +08:00
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api)
{
this.api = api;
}
2016-11-03 10:22:34 +08:00
}
}
2016-11-09 07:13:20 +08:00
}