From f8cc4238ffa88e96e42a8744986e1adfe65b3288 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Thu, 24 Aug 2017 22:13:20 +0200 Subject: [PATCH] cleanup code --- .../UserInterface/OsuPasswordTextBox.cs | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs b/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs index 2b175b9eed..2fdbf64d08 100644 --- a/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs +++ b/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs @@ -7,8 +7,8 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; -using System; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input; using osu.Framework.Platform; namespace osu.Game.Graphics.UserInterface @@ -19,14 +19,35 @@ namespace osu.Game.Graphics.UserInterface public override bool AllowClipboardExport => false; + private readonly CapsWarning warning; + + private GameHost host; + public OsuPasswordTextBox() { - Add(new CapsWarning + Add(warning = new CapsWarning { Size = new Vector2(20), + Origin = Anchor.CentreRight, + Anchor = Anchor.CentreRight, + Margin = new MarginPadding { Right = 10 }, + Alpha = 0, }); } + [BackgroundDependencyLoader] + private void load(GameHost host) + { + this.host = host; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (args.Key == OpenTK.Input.Key.CapsLock) + warning.FadeTo(host.CapsLockEnabled ? 1 : 0, 250, Easing.OutQuint); + return base.OnKeyDown(state, args); + } + public class PasswordMaskChar : Container { private readonly CircularContainer circle; @@ -66,36 +87,18 @@ namespace osu.Game.Graphics.UserInterface private class CapsWarning : SpriteIcon, IHasTooltip { - public string TooltipText => host.CapsLockEnabled ? @"Caps lock is active" : string.Empty; - - public override bool HandleInput => true; - - private GameHost host; + public string TooltipText => @"Caps lock is active"; 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, GameHost host) + private void load(OsuColour colour) { Colour = colour.YellowLight; - this.host = host; } - - protected override void Update() - { - base.Update(); - updateVisibility(); - } - - private void updateVisibility() => this.FadeTo(host.CapsLockEnabled ? 1 : 0, 250, Easing.OutQuint); } } }