From f6e0e0bc38197ba9086b0e44a89e9da7f015dd42 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Sat, 3 Jun 2017 19:21:21 +0200 Subject: [PATCH] add caps lock warning --- .../UserInterface/OsuPasswordTextBox.cs | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs b/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs index 904aa14aa7..8ad3febf19 100644 --- a/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs +++ b/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs @@ -1,11 +1,14 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using OpenTK; using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; +using System; namespace osu.Game.Graphics.UserInterface { @@ -15,6 +18,14 @@ namespace osu.Game.Graphics.UserInterface public override bool AllowClipboardExport => false; + public OsuPasswordTextBox() + { + Add(new CapsWarning + { + TextSize = 20, + }); + } + public class PasswordMaskChar : Container { private readonly CircularContainer circle; @@ -51,5 +62,36 @@ namespace osu.Game.Graphics.UserInterface circle.ResizeTo(new Vector2(0.8f), 500, EasingTypes.OutQuint); } } + + private class CapsWarning : TextAwesome, IHasTooltip + { + public string TooltipText => Console.CapsLock ? @"Caps lock is active" : string.Empty; + + public override bool HandleInput => true; + + public CapsWarning() + { + Icon = FontAwesome.fa_warning; + Origin = Anchor.CentreRight; + Anchor = Anchor.CentreRight; + Margin = new MarginPadding { Right = 10 }; + AlwaysPresent = true; + Alpha = 0; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colour) + { + Colour = colour.YellowLight; + } + + protected override void Update() + { + base.Update(); + updateVisibility(); + } + + private void updateVisibility() => FadeTo(Console.CapsLock ? 1 : 0, 250, EasingTypes.OutQuint); + } } }