2019-01-24 08:43:03 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-12-06 02:58:09 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2018-12-06 05:57:00 +00:00
|
|
|
using System.Linq;
|
2018-12-06 02:58:09 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-09 04:43:44 +00:00
|
|
|
using osu.Framework.Utils;
|
2019-01-29 08:01:53 +00:00
|
|
|
using osu.Framework.Platform;
|
2018-12-06 07:29:41 +00:00
|
|
|
using osu.Framework.Screens;
|
2018-12-06 02:58:09 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.AccountCreation
|
|
|
|
{
|
|
|
|
public class ScreenEntry : AccountCreationScreen
|
|
|
|
{
|
|
|
|
private ErrorTextFlowContainer usernameDescription;
|
|
|
|
private ErrorTextFlowContainer emailAddressDescription;
|
|
|
|
private ErrorTextFlowContainer passwordDescription;
|
|
|
|
|
|
|
|
private OsuTextBox usernameTextBox;
|
|
|
|
private OsuTextBox emailTextBox;
|
|
|
|
private OsuPasswordTextBox passwordTextBox;
|
|
|
|
|
2020-02-14 13:14:00 +00:00
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2018-12-06 02:58:09 +00:00
|
|
|
private ShakeContainer registerShake;
|
2018-12-14 10:56:21 +00:00
|
|
|
private IEnumerable<Drawable> characterCheckText;
|
2018-12-06 02:58:09 +00:00
|
|
|
|
2018-12-06 05:57:00 +00:00
|
|
|
private OsuTextBox[] textboxes;
|
2020-02-21 06:31:40 +00:00
|
|
|
private LoadingLayer loadingLayer;
|
2020-02-14 13:14:00 +00:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
2018-12-06 02:58:09 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 13:14:00 +00:00
|
|
|
private void load(OsuColour colours)
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
InternalChildren = new Drawable[]
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2021-01-05 21:39:59 +00:00
|
|
|
new FillFlowContainer
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 07:29:41 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
Children = new Drawable[]
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 07:29:41 +00:00
|
|
|
new OsuSpriteText
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 07:29:41 +00:00
|
|
|
Margin = new MarginPadding { Vertical = 10 },
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2019-02-12 04:04:46 +00:00
|
|
|
Font = OsuFont.GetFont(size: 20),
|
2018-12-06 07:29:41 +00:00
|
|
|
Text = "Let's create an account!",
|
|
|
|
},
|
|
|
|
usernameTextBox = new OsuTextBox
|
|
|
|
{
|
|
|
|
PlaceholderText = "username",
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this
|
|
|
|
},
|
|
|
|
usernameDescription = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
emailTextBox = new OsuTextBox
|
|
|
|
{
|
|
|
|
PlaceholderText = "email address",
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this
|
|
|
|
},
|
|
|
|
emailAddressDescription = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
passwordTextBox = new OsuPasswordTextBox
|
|
|
|
{
|
|
|
|
PlaceholderText = "password",
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
},
|
|
|
|
passwordDescription = new ErrorTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 07:29:41 +00:00
|
|
|
registerShake = new ShakeContainer
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 07:29:41 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Child = new SettingsButton
|
|
|
|
{
|
|
|
|
Text = "Register",
|
|
|
|
Margin = new MarginPadding { Vertical = 20 },
|
|
|
|
Action = performRegistration
|
|
|
|
}
|
2018-12-06 02:58:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 07:29:41 +00:00
|
|
|
},
|
2018-12-06 02:58:09 +00:00
|
|
|
},
|
2018-12-06 07:29:41 +00:00
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
loadingLayer = new LoadingLayer(true)
|
2018-12-06 02:58:09 +00:00
|
|
|
};
|
|
|
|
|
2018-12-06 05:57:00 +00:00
|
|
|
textboxes = new[] { usernameTextBox, emailTextBox, passwordTextBox };
|
|
|
|
|
2018-12-06 02:58:09 +00:00
|
|
|
usernameDescription.AddText("This will be your public presence. No profanity, no impersonation. Avoid exposing your own personal details, too!");
|
|
|
|
|
|
|
|
emailAddressDescription.AddText("Will be used for notifications, account verification and in the case you forget your password. No spam, ever.");
|
2020-03-13 04:32:16 +00:00
|
|
|
emailAddressDescription.AddText(" Make sure to get it right!", cp => cp.Font = cp.Font.With(Typeface.Torus, weight: FontWeight.Bold));
|
2018-12-06 02:58:09 +00:00
|
|
|
|
|
|
|
passwordDescription.AddText("At least ");
|
|
|
|
characterCheckText = passwordDescription.AddText("8 characters long");
|
|
|
|
passwordDescription.AddText(". Choose something long but also something you will remember, like a line from your favourite song.");
|
|
|
|
|
2019-02-22 08:51:39 +00:00
|
|
|
passwordTextBox.Current.ValueChanged += password => { characterCheckText.ForEach(s => s.Colour = password.NewValue.Length == 0 ? Color4.White : Interpolation.ValueAt(password.NewValue.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In)); };
|
2018-12-06 02:58:09 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
public override void OnEntering(IScreen last)
|
2018-12-06 07:29:41 +00:00
|
|
|
{
|
|
|
|
base.OnEntering(last);
|
2020-02-21 06:31:40 +00:00
|
|
|
loadingLayer.Hide();
|
2019-10-22 21:40:56 +00:00
|
|
|
|
2019-10-23 02:51:29 +00:00
|
|
|
if (host?.OnScreenKeyboardOverlapsGameWindow != true)
|
|
|
|
focusNextTextbox();
|
2018-12-06 07:29:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 05:57:00 +00:00
|
|
|
private void performRegistration()
|
|
|
|
{
|
|
|
|
if (focusNextTextbox())
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
|
|
|
registerShake.Shake();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usernameDescription.ClearErrors();
|
|
|
|
emailAddressDescription.ClearErrors();
|
|
|
|
passwordDescription.ClearErrors();
|
|
|
|
|
2020-02-21 06:31:40 +00:00
|
|
|
loadingLayer.Show();
|
2018-12-06 07:29:41 +00:00
|
|
|
|
2018-12-06 02:58:09 +00:00
|
|
|
Task.Run(() =>
|
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
RegistrationRequest.RegistrationRequestErrors errors = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
errors = api.CreateAccount(emailTextBox.Text, usernameTextBox.Text, passwordTextBox.Text);
|
|
|
|
success = errors == null;
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
if (errors != null)
|
|
|
|
{
|
|
|
|
usernameDescription.AddErrors(errors.User.Username);
|
|
|
|
emailAddressDescription.AddErrors(errors.User.Email);
|
|
|
|
passwordDescription.AddErrors(errors.User.Password);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
passwordDescription.AddErrors(new[] { "Something happened... but we're not sure what." });
|
|
|
|
}
|
|
|
|
|
|
|
|
registerShake.Shake();
|
2020-02-21 06:31:40 +00:00
|
|
|
loadingLayer.Hide();
|
2018-12-06 02:58:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-04 05:52:07 +00:00
|
|
|
api.Login(usernameTextBox.Text, passwordTextBox.Text);
|
2018-12-06 02:58:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-06 05:57:00 +00:00
|
|
|
private bool focusNextTextbox()
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 05:57:00 +00:00
|
|
|
var nextTextbox = nextUnfilledTextbox();
|
2019-04-01 03:16:05 +00:00
|
|
|
|
2018-12-06 05:57:00 +00:00
|
|
|
if (nextTextbox != null)
|
2018-12-06 02:58:09 +00:00
|
|
|
{
|
2018-12-06 05:57:00 +00:00
|
|
|
Schedule(() => GetContainingInputManager().ChangeFocus(nextTextbox));
|
|
|
|
return true;
|
2018-12-06 02:58:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 05:57:00 +00:00
|
|
|
return false;
|
2018-12-06 02:58:09 +00:00
|
|
|
}
|
2018-12-06 05:57:00 +00:00
|
|
|
|
|
|
|
private OsuTextBox nextUnfilledTextbox() => textboxes.FirstOrDefault(t => string.IsNullOrEmpty(t.Text));
|
2018-12-06 02:58:09 +00:00
|
|
|
}
|
|
|
|
}
|