1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 03:52:55 +08:00
osu-lazer/osu.Game/Overlays/Options/General/LoginOptions.cs

140 lines
4.6 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-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
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-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:
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;
2016-12-20 22:52:16 +08:00
private PasswordTextBox password;
private APIAccess api;
2016-11-30 15:54:15 +08:00
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
},
new CheckBoxOption
{
LabelText = "Remember Username",
Bindable = config.GetBindable<bool>(OsuConfig.SaveUsername),
},
new CheckBoxOption
{
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",
//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
}