diff --git a/osu-framework b/osu-framework index 93cd883930..3811650c08 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 93cd883930e362f7bb8c361ac7f36b5387d4fac3 +Subproject commit 3811650c08bc47282a373d870e4d2203b38d275d diff --git a/osu.Game/Graphics/Sprites/OsuSpriteText.cs b/osu.Game/Graphics/Sprites/OsuSpriteText.cs index 02c71f46ca..5bc76b74b4 100644 --- a/osu.Game/Graphics/Sprites/OsuSpriteText.cs +++ b/osu.Game/Graphics/Sprites/OsuSpriteText.cs @@ -1,7 +1,11 @@ // 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.Sprites; +using osu.Framework.MathUtils; +using OpenTK; +using OpenTK.Graphics; namespace osu.Game.Graphics.Sprites { @@ -14,5 +18,26 @@ namespace osu.Game.Graphics.Sprites Shadow = true; TextSize = FONT_SIZE; } + + protected override Drawable CreateFallbackCharacterDrawable() + { + var tex = GetTextureForCharacter('?'); + + if (tex != null) + { + float adjust = (RNG.NextSingle() - 0.5f) * 2; + return new Sprite + { + Texture = tex, + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Scale = new Vector2(1 + adjust * 0.2f), + Rotation = adjust * 15, + Colour = Color4.White, + }; + } + + return base.CreateFallbackCharacterDrawable(); + } } } diff --git a/osu.Game/Graphics/UserInterface/Nub.cs b/osu.Game/Graphics/UserInterface/Nub.cs index 4ce25095b9..c8174ef546 100644 --- a/osu.Game/Graphics/UserInterface/Nub.cs +++ b/osu.Game/Graphics/UserInterface/Nub.cs @@ -13,7 +13,7 @@ using osu.Framework.Graphics.UserInterface; namespace osu.Game.Graphics.UserInterface { - class Nub : Container, IStateful + class Nub : CircularContainer, IStateful { public const float COLLAPSED_SIZE = 20; public const float EXPANDED_SIZE = 40; @@ -27,10 +27,6 @@ namespace osu.Game.Graphics.UserInterface { Size = new Vector2(COLLAPSED_SIZE, 12); - Masking = true; - - CornerRadius = Height / 2; - Masking = true; BorderColour = Color4.White; BorderThickness = border_width; diff --git a/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs b/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs new file mode 100644 index 0000000000..13fbbb16e0 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs @@ -0,0 +1,52 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuPasswordTextBox : OsuTextBox + { + protected override Drawable GetDrawableCharacter(char c) => new PasswordMaskChar(CalculatedTextSize); + + public class PasswordMaskChar : Container + { + private CircularContainer circle; + + public PasswordMaskChar(float size) + { + Size = new Vector2(size / 2, size); + Children = new[] + { + circle = new CircularContainer + { + Anchor = Anchor.Centre, + 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, EasingTypes.OutQuint); + circle.ResizeTo(new Vector2(0.8f), 500, EasingTypes.OutQuint); + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuTextBox.cs b/osu.Game/Graphics/UserInterface/OsuTextBox.cs index ae1b1f7a18..0e551380ed 100644 --- a/osu.Game/Graphics/UserInterface/OsuTextBox.cs +++ b/osu.Game/Graphics/UserInterface/OsuTextBox.cs @@ -3,6 +3,8 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Game.Graphics.Sprites; @@ -17,10 +19,19 @@ namespace osu.Game.Graphics.UserInterface protected override Color4 BackgroundFocused => OsuColour.Gray(0.3f).Opacity(0.8f); protected override Color4 BackgroundCommit => BorderColour; + protected override float LeftRightPadding => 10; + + protected override SpriteText CreatePlaceholder() => new OsuSpriteText + { + Font = @"Exo2.0-MediumItalic", + Colour = new Color4(180, 180, 180, 255), + Margin = new MarginPadding { Left = 2 }, + }; + public OsuTextBox() { Height = 40; - TextContainer.Height = OsuSpriteText.FONT_SIZE / Height; + TextContainer.Height = 0.5f; CornerRadius = 5; } @@ -43,12 +54,7 @@ namespace osu.Game.Graphics.UserInterface base.OnFocusLost(state); } - } - public class OsuPasswordTextBox : OsuTextBox - { - protected virtual char MaskCharacter => '*'; - - protected override Drawable AddCharacterToFlow(char c) => base.AddCharacterToFlow(MaskCharacter); + protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), TextSize = CalculatedTextSize }; } } diff --git a/osu.Game/Overlays/LoginOverlay.cs b/osu.Game/Overlays/LoginOverlay.cs index ff7a63969e..4ffa63d7cb 100644 --- a/osu.Game/Overlays/LoginOverlay.cs +++ b/osu.Game/Overlays/LoginOverlay.cs @@ -14,7 +14,7 @@ using OpenTK.Graphics; namespace osu.Game.Overlays { - class LoginOverlay : OverlayContainer + class LoginOverlay : FocusedOverlayContainer { private LoginOptions optionsSection; @@ -64,6 +64,8 @@ namespace osu.Game.Overlays protected override void PopIn() { + base.PopIn(); + optionsSection.Bounding = true; FadeIn(transition_time, EasingTypes.OutQuint); } diff --git a/osu.Game/Overlays/Options/OptionTextBox.cs b/osu.Game/Overlays/Options/OptionTextBox.cs index 74730481ab..18fcfa6fca 100644 --- a/osu.Game/Overlays/Options/OptionTextBox.cs +++ b/osu.Game/Overlays/Options/OptionTextBox.cs @@ -26,16 +26,16 @@ namespace osu.Game.Overlays.Options } } } - - protected override string InternalText + + public OptionTextBox() { - get { return base.InternalText; } - set - { - base.InternalText = value; - if (bindable != null) - bindable.Value = value; - } + OnChange += onChange; + } + + private void onChange(TextBox sender, bool newText) + { + if (bindable != null) + bindable.Value = Text; } private void bindableValueChanged(object sender, EventArgs e) diff --git a/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs b/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs index 398cb969e3..916159fc88 100644 --- a/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs +++ b/osu.Game/Overlays/Options/Sections/General/LoginOptions.cs @@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Options.Sections.General { private bool bounding = true; - protected override string Header => "Sign In"; + protected override string Header => "Account"; public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty; @@ -112,11 +112,13 @@ namespace osu.Game.Overlays.Options.Sections.General { username = new OsuTextBox { + PlaceholderText = "Username", RelativeSizeAxes = Axes.X, Text = api?.Username ?? string.Empty }, password = new OsuPasswordTextBox { + PlaceholderText = "Password", RelativeSizeAxes = Axes.X }, saveUsername = new OsuCheckbox diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 28f67357c2..0b481ee068 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -23,7 +23,7 @@ using osu.Game.Overlays.Options.Sections; namespace osu.Game.Overlays { - public class OptionsOverlay : OverlayContainer + public class OptionsOverlay : FocusedOverlayContainer { internal const float CONTENT_MARGINS = 10; @@ -159,26 +159,10 @@ namespace osu.Game.Overlays } } - protected override bool OnHover(InputState state) => true; - - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; - - protected override bool OnClick(InputState state) => true; - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - switch (args.Key) - { - case Key.Escape: - if (State == Visibility.Hidden) return false; - Hide(); - return true; - } - return base.OnKeyDown(state, args); - } - protected override void PopIn() { + base.PopIn(); + scrollContainer.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint); sidebar.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint); FadeTo(1, TRANSITION_LENGTH / 2); diff --git a/osu.Game/Screens/Select/SearchTextBox.cs b/osu.Game/Screens/Select/SearchTextBox.cs index 39f9fd0f80..d6385d463a 100644 --- a/osu.Game/Screens/Select/SearchTextBox.cs +++ b/osu.Game/Screens/Select/SearchTextBox.cs @@ -3,19 +3,20 @@ using System; using System.Linq; -using OpenTK; using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; namespace osu.Game.Screens.Select { - public class SearchTextBox : TextBox + /// + /// A textbox which holds focus eagerly. + /// + public class SearchTextBox : OsuTextBox { protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255); protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255); @@ -33,39 +34,13 @@ namespace osu.Game.Screens.Select } } - private SpriteText placeholder; - - protected override string InternalText - { - get { return base.InternalText; } - set - { - base.InternalText = value; - if (placeholder != null) - { - if (string.IsNullOrEmpty(value)) - placeholder.Text = "type to search"; - else - placeholder.Text = string.Empty; - } - } - } + public override bool RequestingFocus => HoldFocus; public SearchTextBox() { Height = 35; - TextContainer.Padding = new MarginPadding(5); Add(new Drawable[] { - placeholder = new SpriteText - { - Font = @"Exo2.0-MediumItalic", - Text = "type to search", - Colour = new Color4(180, 180, 180, 255), - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Margin = new MarginPadding { Left = 10 }, - }, new TextAwesome { Icon = FontAwesome.fa_search, @@ -74,25 +49,44 @@ namespace osu.Game.Screens.Select Margin = new MarginPadding { Right = 10 }, } }); + + PlaceholderText = "type to search"; } - protected override void Update() + protected override bool OnFocus(InputState state) { - if (HoldFocus) RequestFocus(); - base.Update(); + var result = base.OnFocus(state); + BorderThickness = 0; + return result; } protected override void OnFocusLost(InputState state) { if (state.Keyboard.Keys.Any(key => key == Key.Escape)) - Exit?.Invoke(); + { + if (Text.Length > 0) + Text = string.Empty; + else + Exit?.Invoke(); + } base.OnFocusLost(state); } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (args.Key == Key.Left || args.Key == Key.Right || args.Key == Key.Enter) - return false; + if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed) + { + switch (args.Key) + { + case Key.Left: + case Key.Right: + case Key.Up: + case Key.Down: + case Key.Enter: + return false; + } + } + return base.OnKeyDown(state, args); } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 5f7c171cfe..1b1c851128 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -69,6 +69,7 @@ +