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-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2017-06-03 17:21:21 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-08 03:41:23 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-03 17:21:21 +00:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-02-03 11:34:38 +00:00
|
|
|
|
using osu.Framework.Input;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-06-25 17:10:04 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-08-22 13:43:45 +00:00
|
|
|
|
using osu.Framework.Platform;
|
2023-01-16 20:08:29 +00:00
|
|
|
|
using osu.Game.Localisation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-08 03:41:23 +00:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2019-02-03 11:34:38 +00:00
|
|
|
|
public partial class OsuPasswordTextBox : OsuTextBox, ISuppressKeyEventLogging
|
2017-02-08 03:41:23 +00:00
|
|
|
|
{
|
2020-03-09 02:43:53 +00:00
|
|
|
|
protected override Drawable GetDrawableCharacter(char c) => new FallingDownContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Child = new PasswordMaskChar(CalculatedTextSize),
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-07-10 09:19:18 +00:00
|
|
|
|
protected override bool AllowUniqueCharacterSamples => false;
|
2020-06-05 03:44:41 +00:00
|
|
|
|
|
2018-06-29 12:25:51 +00:00
|
|
|
|
protected override bool AllowClipboardExport => false;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-01-11 23:15:17 +00:00
|
|
|
|
protected override bool AllowWordNavigation => false;
|
|
|
|
|
|
|
|
|
|
protected override bool AllowIme => false;
|
|
|
|
|
|
2017-08-24 20:13:20 +00:00
|
|
|
|
private readonly CapsWarning warning;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-14 13:14:00 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; } = null!;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 17:21:21 +00:00
|
|
|
|
public OsuPasswordTextBox()
|
|
|
|
|
{
|
2017-08-24 20:13:20 +00:00
|
|
|
|
Add(warning = new CapsWarning
|
2017-06-03 17:21:21 +00:00
|
|
|
|
{
|
2017-08-22 11:35:30 +00:00
|
|
|
|
Size = new Vector2(20),
|
2017-08-24 20:13:20 +00:00
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
|
|
|
|
Alpha = 0,
|
2017-06-03 17:21:21 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2017-08-24 20:13:20 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
if (e.Key == Key.CapsLock)
|
2017-08-25 14:39:49 +00:00
|
|
|
|
updateCapsWarning(host.CapsLockEnabled);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnKeyDown(e);
|
2017-08-24 20:13:20 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
2017-08-25 14:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
updateCapsWarning(host.CapsLockEnabled);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnFocus(e);
|
2017-08-25 14:39:49 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnFocusLost(FocusLostEvent e)
|
2017-08-25 14:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
updateCapsWarning(false);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnFocusLost(e);
|
2017-08-25 14:39:49 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-25 14:39:49 +00:00
|
|
|
|
private void updateCapsWarning(bool visible) => warning.FadeTo(visible ? 1 : 0, 250, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-08 07:01:58 +00:00
|
|
|
|
public partial class PasswordMaskChar : Container
|
|
|
|
|
{
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly CircularContainer circle;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-08 07:01:58 +00:00
|
|
|
|
public PasswordMaskChar(float size)
|
2017-02-08 03:41:23 +00:00
|
|
|
|
{
|
2017-02-08 07:01:58 +00:00
|
|
|
|
Size = new Vector2(size / 2, size);
|
2017-02-08 03:41:23 +00:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-02-08 07:01:58 +00:00
|
|
|
|
circle = new CircularContainer
|
2017-02-08 03:41:23 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-22 06:27:22 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Masking = true,
|
2017-02-08 07:01:58 +00:00
|
|
|
|
Alpha = 0,
|
2017-02-08 03:41:23 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-08 07:01:58 +00:00
|
|
|
|
Size = new Vector2(0.8f, 0),
|
2017-02-08 03:41:23 +00:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
2017-02-08 07:01:58 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-08 07:01:58 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-07-22 18:50:25 +00:00
|
|
|
|
circle.FadeIn(500, Easing.OutQuint);
|
|
|
|
|
circle.ResizeTo(new Vector2(0.8f), 500, Easing.OutQuint);
|
2017-02-08 07:01:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-22 11:35:30 +00:00
|
|
|
|
private partial class CapsWarning : SpriteIcon, IHasTooltip
|
2017-06-03 17:21:21 +00:00
|
|
|
|
{
|
2023-01-16 20:08:29 +00:00
|
|
|
|
public LocalisableString TooltipText => CommonStrings.CapsLockIsActive;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 17:21:21 +00:00
|
|
|
|
public CapsWarning()
|
|
|
|
|
{
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Solid.ExclamationTriangle;
|
2017-06-03 17:21:21 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 17:21:21 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-08-24 20:13:20 +00:00
|
|
|
|
private void load(OsuColour colour)
|
2017-06-03 17:21:21 +00:00
|
|
|
|
{
|
|
|
|
|
Colour = colour.YellowLight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-08 03:41:23 +00:00
|
|
|
|
}
|
2017-02-08 07:01:58 +00:00
|
|
|
|
}
|