mirror of
https://github.com/ppy/osu.git
synced 2025-03-19 09:07:18 +08:00
Merge pull request #330 from peppy/textbox-improvements
Textbox improvements
This commit is contained in:
commit
fd8179b370
@ -1 +1 @@
|
||||
Subproject commit 93cd883930e362f7bb8c361ac7f36b5387d4fac3
|
||||
Subproject commit 3811650c08bc47282a373d870e4d2203b38d275d
|
@ -1,7 +1,11 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ using osu.Framework.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
class Nub : Container, IStateful<CheckBoxState>
|
||||
class Nub : CircularContainer, IStateful<CheckBoxState>
|
||||
{
|
||||
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;
|
||||
|
||||
|
52
osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs
Normal file
52
osu.Game/Graphics/UserInterface/OsuPasswordTextBox.cs
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 };
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// A textbox which holds focus eagerly.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,7 @@
|
||||
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
|
||||
<Compile Include="Graphics\UserInterface\BackButton.cs" />
|
||||
<Compile Include="Graphics\UserInterface\Nub.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuPasswordTextBox.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuSliderBar.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuTextBox.cs" />
|
||||
<Compile Include="Graphics\UserInterface\TwoLayerButton.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user