mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 23:07:26 +08:00
Merge remote-tracking branch 'upstream/master' into catch-catcher-skinning
This commit is contained in:
commit
cc9e46f8ee
@ -4,7 +4,6 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
@ -25,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures)
|
||||
{
|
||||
Child = new SkinnableDrawable("Play/osu/approachcircle", name => new Sprite { Texture = textures.Get(name) });
|
||||
Child = new SkinnableSprite("Play/osu/approachcircle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
55
osu.Game.Tests/Visual/UserInterface/TestSceneNumberBox.cs
Normal file
55
osu.Game.Tests/Visual/UserInterface/TestSceneNumberBox.cs
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneNumberBox : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(OsuNumberBox),
|
||||
};
|
||||
|
||||
private OsuNumberBox numberBox;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Child = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Padding = new MarginPadding { Horizontal = 250 },
|
||||
Child = numberBox = new OsuNumberBox
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
PlaceholderText = "Insert numbers here"
|
||||
}
|
||||
};
|
||||
|
||||
clearInput();
|
||||
AddStep("enter numbers", () => numberBox.Text = "987654321");
|
||||
expectedValue("987654321");
|
||||
clearInput();
|
||||
AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3");
|
||||
expectedValue("123");
|
||||
clearInput();
|
||||
}
|
||||
|
||||
private void clearInput() => AddStep("clear input", () => numberBox.Text = null);
|
||||
|
||||
private void expectedValue(string value) => AddAssert("expect number", () => numberBox.Text == value);
|
||||
}
|
||||
}
|
@ -183,7 +183,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsTextBox
|
||||
new SettingsNumberBox
|
||||
{
|
||||
LabelText = "Beatmap ID",
|
||||
RelativeSizeAxes = Axes.None,
|
||||
|
@ -231,7 +231,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsTextBox
|
||||
new SettingsNumberBox
|
||||
{
|
||||
LabelText = "User ID",
|
||||
RelativeSizeAxes = Axes.None,
|
||||
|
@ -5,7 +5,6 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
@ -191,8 +190,6 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
|
||||
|
||||
public RoundDisplay()
|
||||
{
|
||||
CornerRadius = 10;
|
||||
Masking = true;
|
||||
Width = 200;
|
||||
Height = 20;
|
||||
}
|
||||
@ -208,11 +205,6 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = new Color4(47, 71, 67, 255),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
|
@ -6,17 +6,25 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Showcase
|
||||
{
|
||||
public class TournamentLogo : CompositeDrawable
|
||||
{
|
||||
public TournamentLogo()
|
||||
public TournamentLogo(bool includeRoundBackground = true)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 95;
|
||||
Margin = new MarginPadding { Vertical = 5 };
|
||||
|
||||
if (includeRoundBackground)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
Masking = true;
|
||||
Height = 100;
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -27,9 +35,6 @@ namespace osu.Game.Tournament.Screens.Showcase
|
||||
Texture = textures.Get("game-screen-logo"),
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
FillMode = FillMode.Fit,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Tournament.Screens.TeamIntro
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Loop = true,
|
||||
},
|
||||
new TournamentLogo(),
|
||||
new TournamentLogo(false),
|
||||
mainContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
|
10
osu.Game/Graphics/UserInterface/OsuNumberBox.cs
Normal file
10
osu.Game/Graphics/UserInterface/OsuNumberBox.cs
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class OsuNumberBox : OsuTextBox
|
||||
{
|
||||
protected override bool CanAddCharacter(char character) => char.IsNumber(character);
|
||||
}
|
||||
}
|
17
osu.Game/Overlays/Settings/SettingsNumberBox.cs
Normal file
17
osu.Game/Overlays/Settings/SettingsNumberBox.cs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public class SettingsNumberBox : SettingsItem<string>
|
||||
{
|
||||
protected override Drawable CreateControl() => new OsuNumberBox
|
||||
{
|
||||
Margin = new MarginPadding { Top = 5 },
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
}
|
||||
}
|
@ -15,6 +15,10 @@ namespace osu.Game.Skinning
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A drawable which can be skinned via an <see cref="ISkinSource"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of drawable.</typeparam>
|
||||
public class SkinnableDrawable<T> : SkinReloadableDrawable
|
||||
where T : Drawable
|
||||
{
|
||||
@ -23,16 +27,12 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
protected Drawable Drawable { get; private set; }
|
||||
|
||||
protected virtual T CreateDefault(string name) => createDefault(name);
|
||||
|
||||
private readonly Func<string, T> createDefault;
|
||||
|
||||
private readonly string componentName;
|
||||
|
||||
private readonly bool restrictSize;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Create a new skinnable drawable.
|
||||
/// </summary>
|
||||
/// <param name="name">The namespace-complete resource name for this skinnable element.</param>
|
||||
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
||||
@ -53,7 +53,14 @@ namespace osu.Game.Skinning
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
protected virtual bool ApplySizeToDefault => false;
|
||||
private readonly Func<string, T> createDefault;
|
||||
|
||||
protected virtual T CreateDefault(string name) => createDefault(name);
|
||||
|
||||
/// <summary>
|
||||
/// Whether to apply size restrictions (specified via <see cref="restrictSize"/>) to the default implementation.
|
||||
/// </summary>
|
||||
protected virtual bool ApplySizeRestrictionsToDefault => false;
|
||||
|
||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||
{
|
||||
@ -69,7 +76,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
if (Drawable != null)
|
||||
{
|
||||
if (restrictSize && (!isDefault || ApplySizeToDefault))
|
||||
if (restrictSize && (!isDefault || ApplySizeRestrictionsToDefault))
|
||||
{
|
||||
Drawable.RelativeSizeAxes = Axes.Both;
|
||||
Drawable.Size = Vector2.One;
|
||||
|
@ -8,11 +8,12 @@ using osu.Framework.Graphics.Textures;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
/// <summary>
|
||||
/// A skinnable element which uses a stable sprite and can therefore share implementation logic.
|
||||
/// </summary>
|
||||
public class SkinnableSprite : SkinnableDrawable<Sprite>
|
||||
{
|
||||
protected override bool ApplySizeToDefault => true;
|
||||
|
||||
protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) };
|
||||
protected override bool ApplySizeRestrictionsToDefault => true;
|
||||
|
||||
[Resolved]
|
||||
private TextureStore textures { get; set; }
|
||||
@ -21,5 +22,7 @@ namespace osu.Game.Skinning
|
||||
: base(name, allowFallback, restrictSize)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) };
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user