1
0
mirror of https://github.com/ppy/osu.git synced 2024-10-01 00:37:51 +08:00
osu-lazer/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs

149 lines
4.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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using OpenTK;
namespace osu.Game.Overlays.Options.Sections.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
{
private bool bounding = true;
protected override string Header => "Sign In";
2016-11-09 11:38:40 +08:00
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
public bool Bounding
{
get { return bounding; }
set
{
bounding = value;
2017-01-31 16:15:46 +08:00
Invalidate(Invalidation.Geometry);
}
}
[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 OsuSpriteText
{
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 OsuSpriteText
{
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 OsuSpriteText
{
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
private OsuCheckbox saveUsername;
private OsuCheckbox 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
{
username = new OsuTextBox
{
RelativeSizeAxes = Axes.X,
Text = api?.Username ?? string.Empty
2016-12-20 22:28:27 +08:00
},
password = new OsuPasswordTextBox
{
RelativeSizeAxes = Axes.X
2016-12-20 22:28:27 +08:00
},
saveUsername = new OsuCheckbox
{
LabelText = "Remember username",
Bindable = config.GetBindable<bool>(OsuConfig.SaveUsername),
2016-12-20 22:28:27 +08:00
},
savePassword = new OsuCheckbox
{
LabelText = "Stay logged in",
Bindable = config.GetBindable<bool>(OsuConfig.SavePassword),
2016-12-20 22:28:27 +08:00
},
2016-11-04 10:43:00 +08:00
new OsuButton
{
RelativeSizeAxes = Axes.X,
Text = "Sign 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 new account",
//Action = registerLink
2016-11-04 10:43:00 +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
}