1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 18:42:56 +08:00

Merge pull request #2181 from peppy/more-skinning

Add skin support for hit judgements
This commit is contained in:
Dan Balasescu 2018-03-13 12:58:44 +09:00 committed by GitHub
commit f06f31a269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 48 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -12,6 +13,12 @@ namespace osu.Game.Rulesets.Mania.UI
public DrawableManiaJudgement(Judgement judgement, DrawableHitObject judgedObject) public DrawableManiaJudgement(Judgement judgement, DrawableHitObject judgedObject)
: base(judgement, judgedObject) : base(judgement, judgedObject)
{ {
}
[BackgroundDependencyLoader]
private void load()
{
if (JudgementText != null)
JudgementText.TextSize = 25; JudgementText.TextSize = 25;
} }

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
protected override void LoadComplete() protected override void LoadComplete()
{ {
if (Judgement.Result != HitResult.Miss) if (Judgement.Result != HitResult.Miss)
JudgementText.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint); JudgementText?.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
base.LoadComplete(); base.LoadComplete();
} }

View File

@ -3,6 +3,7 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Skinning;
using OpenTK; using OpenTK;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
@ -19,15 +20,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
Blending = BlendingMode.Additive; Blending = BlendingMode.Additive;
Alpha = 0; Alpha = 0;
Children = new Drawable[] Child = new SkinnableDrawable("Play/osu/hitcircle-explode", _ => new TrianglesPiece
{
new TrianglesPiece
{ {
Blending = BlendingMode.Additive, Blending = BlendingMode.Additive,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0.2f, Alpha = 0.2f,
} }, false);
};
} }
} }
} }

View File

@ -5,6 +5,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using OpenTK; using OpenTK;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
@ -14,22 +15,21 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
Size = new Vector2(128); Size = new Vector2(128);
Masking = true;
CornerRadius = Size.X / 2;
Anchor = Anchor.Centre; Anchor = Anchor.Centre;
Origin = Anchor.Centre; Origin = Anchor.Centre;
Blending = BlendingMode.Additive; Blending = BlendingMode.Additive;
Alpha = 0; Alpha = 0;
Children = new Drawable[] Child = new SkinnableDrawable("Play/osu/hitcircle-flash", name => new CircularContainer
{ {
new Box Masking = true,
RelativeSizeAxes = Axes.Both,
Child = new Box
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
} }
}; }, false);
} }
} }
} }

View File

@ -11,6 +11,8 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using OpenTK.Graphics;
namespace osu.Game.Rulesets.Judgements namespace osu.Game.Rulesets.Judgements
{ {
@ -19,11 +21,13 @@ namespace osu.Game.Rulesets.Judgements
/// </summary> /// </summary>
public class DrawableJudgement : Container public class DrawableJudgement : Container
{ {
private const float judgement_size = 80;
protected readonly Judgement Judgement; protected readonly Judgement Judgement;
public readonly DrawableHitObject JudgedObject; public readonly DrawableHitObject JudgedObject;
protected readonly SpriteText JudgementText; protected SpriteText JudgementText;
/// <summary> /// <summary>
/// Creates a drawable which visualises a <see cref="Judgements.Judgement"/>. /// Creates a drawable which visualises a <see cref="Judgements.Judgement"/>.
@ -34,31 +38,20 @@ namespace osu.Game.Rulesets.Judgements
Judgement = judgement; Judgement = judgement;
JudgedObject = judgedObject; JudgedObject = judgedObject;
AutoSizeAxes = Axes.Both; Size = new Vector2(judgement_size);
Children = new[]
{
JudgementText = new OsuSpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = judgement.Result.GetDescription().ToUpper(),
Font = @"Venera",
Scale = new Vector2(0.85f, 1),
TextSize = 12
}
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
switch (Judgement.Result) Child = new SkinnableDrawable($"Play/{Judgement.Result}", _ => JudgementText = new OsuSpriteText
{ {
case HitResult.Miss: Text = Judgement.Result.GetDescription().ToUpper(),
Colour = colours.Red; Font = @"Venera",
break; Colour = Judgement.Result == HitResult.Miss ? colours.Red : Color4.White,
} Scale = new Vector2(0.85f, 1),
TextSize = 12
}, restrictSize: false);
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -29,15 +29,26 @@ namespace osu.Game.Skinning
public override Drawable GetDrawableComponent(string componentName) public override Drawable GetDrawableComponent(string componentName)
{ {
switch (componentName)
{
case "Play/Miss":
componentName = "hit0";
break;
case "Play/Meh":
componentName = "hit50";
break;
case "Play/Good":
componentName = "hit100";
break;
case "Play/Great":
componentName = "hit300";
break;
}
var texture = textures.Get(componentName); var texture = textures.Get(componentName);
if (texture == null) return null; if (texture == null) return null;
return new Sprite return new Sprite { Texture = texture };
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
Texture = texture,
};
} }
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName); public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName);
@ -47,8 +58,14 @@ namespace osu.Game.Skinning
private readonly SkinInfo skin; private readonly SkinInfo skin;
private readonly IResourceStore<byte[]> underlyingStore; private readonly IResourceStore<byte[]> underlyingStore;
private string getPathForFile(string filename) => private string getPathForFile(string filename)
skin.Files.FirstOrDefault(f => string.Equals(Path.GetFileNameWithoutExtension(f.Filename), filename.Split('/').Last(), StringComparison.InvariantCultureIgnoreCase))?.FileInfo.StoragePath; {
string lastPiece = filename.Split('/').Last();
var file = skin.Files.FirstOrDefault(f =>
string.Equals(Path.GetFileNameWithoutExtension(f.Filename), lastPiece, StringComparison.InvariantCultureIgnoreCase));
return file?.FileInfo.StoragePath;
}
public LegacySkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingStore) public LegacySkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingStore)
{ {

View File

@ -3,13 +3,14 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using OpenTK;
namespace osu.Game.Skinning namespace osu.Game.Skinning
{ {
public class SkinnableDrawable : SkinnableDrawable<Drawable> public class SkinnableDrawable : SkinnableDrawable<Drawable>
{ {
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true) public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true, bool restrictSize = true)
: base(name, defaultImplementation, fallback) : base(name, defaultImplementation, fallback, restrictSize)
{ {
} }
} }
@ -21,10 +22,20 @@ namespace osu.Game.Skinning
private readonly string componentName; private readonly string componentName;
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true) : base(fallback) private readonly bool restrictSize;
/// <summary>
///
/// </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>
/// <param name="fallback">Whther to fallback to the default implementation when a custom skin is specified but not implementation is present.</param>
/// <param name="restrictSize">Whether a user-skin drawable should be limited to the size of our parent.</param>
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true, bool restrictSize = true) : base(fallback)
{ {
componentName = name; componentName = name;
createDefault = defaultImplementation; createDefault = defaultImplementation;
this.restrictSize = restrictSize;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
@ -32,11 +43,25 @@ namespace osu.Game.Skinning
protected override void SkinChanged(Skin skin, bool allowFallback) protected override void SkinChanged(Skin skin, bool allowFallback)
{ {
var drawable = skin.GetDrawableComponent(componentName); var drawable = skin.GetDrawableComponent(componentName);
if (drawable == null && allowFallback) if (drawable != null)
{
if (restrictSize)
{
drawable.RelativeSizeAxes = Axes.Both;
drawable.Size = Vector2.One;
drawable.FillMode = FillMode.Fit;
}
}
else if (allowFallback)
drawable = createDefault(componentName); drawable = createDefault(componentName);
if (drawable != null) if (drawable != null)
{
drawable.Origin = Anchor.Centre;
drawable.Anchor = Anchor.Centre;
InternalChild = drawable; InternalChild = drawable;
}
else else
ClearInternal(); ClearInternal();
} }