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;
|
2017-01-30 21:53:50 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2017-01-31 16:05:33 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-11-12 18:44:16 +08:00
|
|
|
|
|
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
|
|
|
|
{
|
2017-01-31 15:42:46 +08:00
|
|
|
|
private bool bounding = true;
|
|
|
|
|
|
2016-12-01 12:07:19 +08:00
|
|
|
|
protected override string Header => "Sign In";
|
2016-11-09 11:38:40 +08:00
|
|
|
|
|
2017-01-31 15:42:46 +08:00
|
|
|
|
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
|
|
|
|
|
|
|
|
|
|
public bool Bounding
|
|
|
|
|
{
|
|
|
|
|
get { return bounding; }
|
2017-01-31 16:05:33 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
bounding = value;
|
|
|
|
|
Invalidate(Invalidation.SizeInParentSpace);
|
2017-01-31 15:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
|
|
|
|
private void load(APIAccess api)
|
2017-01-30 21:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
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:
|
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;
|
|
|
|
|
private TextBox 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);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 21:53:50 +08:00
|
|
|
|
[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" },
|
2017-01-30 20:44:54 +08:00
|
|
|
|
username = new OsuTextBox
|
2017-01-30 21:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = api?.Username ?? string.Empty
|
2016-12-20 22:28:27 +08:00
|
|
|
|
},
|
2016-11-04 10:43:00 +08:00
|
|
|
|
new SpriteText { Text = "Password" },
|
2017-01-30 20:44:54 +08:00
|
|
|
|
password = new OsuPasswordTextBox
|
2017-01-30 21:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X
|
2016-12-20 22:28:27 +08:00
|
|
|
|
},
|
2017-01-30 21:53:50 +08:00
|
|
|
|
saveUsername = new CheckBoxOption
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Remember username",
|
|
|
|
|
Bindable = config.GetBindable<bool>(OsuConfig.SaveUsername),
|
2016-12-20 22:28:27 +08:00
|
|
|
|
},
|
2017-01-30 21:53:50 +08:00
|
|
|
|
savePassword = new CheckBoxOption
|
|
|
|
|
{
|
|
|
|
|
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,
|
2017-01-30 21:53:50 +08:00
|
|
|
|
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,
|
2017-01-30 21:53:50 +08:00
|
|
|
|
Text = "Register new account",
|
2016-12-21 06:51:01 +08:00
|
|
|
|
//Action = registerLink
|
2016-11-04 10:43:00 +08:00
|
|
|
|
}
|
2017-01-30 21:53:50 +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
|
|
|
|
}
|