2017-02-08 11:41:23 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-14 15:13:25 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-02-08 11:41:23 +08:00
|
|
|
|
|
2017-06-04 01:21:21 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-08-29 17:18:36 +08:00
|
|
|
|
using OpenTK.Input;
|
2017-06-04 01:21:21 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-08 11:41:23 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-04 01:21:21 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-08-25 04:13:20 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-08-22 21:43:45 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2017-02-08 11:41:23 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class OsuPasswordTextBox : OsuTextBox
|
|
|
|
|
{
|
2017-02-08 15:01:58 +08:00
|
|
|
|
protected override Drawable GetDrawableCharacter(char c) => new PasswordMaskChar(CalculatedTextSize);
|
|
|
|
|
|
2017-03-03 10:00:39 +08:00
|
|
|
|
public override bool AllowClipboardExport => false;
|
|
|
|
|
|
2017-08-25 04:13:20 +08:00
|
|
|
|
private readonly CapsWarning warning;
|
|
|
|
|
|
|
|
|
|
private GameHost host;
|
|
|
|
|
|
2017-06-04 01:21:21 +08:00
|
|
|
|
public OsuPasswordTextBox()
|
|
|
|
|
{
|
2017-08-25 04:13:20 +08:00
|
|
|
|
Add(warning = new CapsWarning
|
2017-06-04 01:21:21 +08:00
|
|
|
|
{
|
2017-08-22 19:35:30 +08:00
|
|
|
|
Size = new Vector2(20),
|
2017-08-25 04:13:20 +08:00
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
|
|
|
|
Alpha = 0,
|
2017-06-04 01:21:21 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 04:13:20 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(GameHost host)
|
|
|
|
|
{
|
|
|
|
|
this.host = host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
2017-08-29 17:18:36 +08:00
|
|
|
|
if (args.Key == Key.CapsLock)
|
2017-08-25 22:39:49 +08:00
|
|
|
|
updateCapsWarning(host.CapsLockEnabled);
|
2017-08-25 04:13:20 +08:00
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 22:39:49 +08:00
|
|
|
|
protected override void OnFocus(InputState state)
|
|
|
|
|
{
|
|
|
|
|
updateCapsWarning(host.CapsLockEnabled);
|
|
|
|
|
base.OnFocus(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnFocusLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
updateCapsWarning(false);
|
|
|
|
|
base.OnFocusLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateCapsWarning(bool visible) => warning.FadeTo(visible ? 1 : 0, 250, Easing.OutQuint);
|
|
|
|
|
|
2017-02-08 15:01:58 +08:00
|
|
|
|
public class PasswordMaskChar : Container
|
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly CircularContainer circle;
|
2017-02-08 15:01:58 +08:00
|
|
|
|
|
|
|
|
|
public PasswordMaskChar(float size)
|
2017-02-08 11:41:23 +08:00
|
|
|
|
{
|
2017-02-08 15:01:58 +08:00
|
|
|
|
Size = new Vector2(size / 2, size);
|
2017-02-08 11:41:23 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-02-08 15:01:58 +08:00
|
|
|
|
circle = new CircularContainer
|
2017-02-08 11:41:23 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-22 14:27:22 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Masking = true,
|
2017-02-08 15:01:58 +08:00
|
|
|
|
Alpha = 0,
|
2017-02-08 11:41:23 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-08 15:01:58 +08:00
|
|
|
|
Size = new Vector2(0.8f, 0),
|
2017-02-08 11:41:23 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
2017-02-08 15:01:58 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-07-23 02:50:25 +08:00
|
|
|
|
circle.FadeIn(500, Easing.OutQuint);
|
|
|
|
|
circle.ResizeTo(new Vector2(0.8f), 500, Easing.OutQuint);
|
2017-02-08 15:01:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-04 01:21:21 +08:00
|
|
|
|
|
2017-08-22 19:35:30 +08:00
|
|
|
|
private class CapsWarning : SpriteIcon, IHasTooltip
|
2017-06-04 01:21:21 +08:00
|
|
|
|
{
|
2017-08-25 04:13:20 +08:00
|
|
|
|
public string TooltipText => @"Caps lock is active";
|
2017-08-22 21:43:45 +08:00
|
|
|
|
|
2017-06-04 01:21:21 +08:00
|
|
|
|
public CapsWarning()
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.fa_warning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-08-25 04:13:20 +08:00
|
|
|
|
private void load(OsuColour colour)
|
2017-06-04 01:21:21 +08:00
|
|
|
|
{
|
|
|
|
|
Colour = colour.YellowLight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-08 11:41:23 +08:00
|
|
|
|
}
|
2017-02-08 15:01:58 +08:00
|
|
|
|
}
|