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