mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Make the cover into a container
This commit is contained in:
parent
1384e61747
commit
b7f6ae5db9
@ -3,9 +3,7 @@
|
||||
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osuTK;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Mods
|
||||
{
|
||||
@ -16,10 +14,6 @@ namespace osu.Game.Rulesets.Mania.Mods
|
||||
public override IconUsage? Icon => OsuIcon.ModHidden;
|
||||
public override string Description => @"Keys appear out of nowhere!";
|
||||
|
||||
public override void ApplyToDrawableRuleset(DrawableRuleset<ManiaHitObject> drawableRuleset)
|
||||
{
|
||||
base.ApplyToDrawableRuleset(drawableRuleset);
|
||||
LaneCovers.ForEach(laneCover => laneCover.Scale = new Vector2(1f, -1f));
|
||||
}
|
||||
protected override PlayfieldCoveringContainer CreateCover() => new PlayfieldCoveringContainer();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -10,6 +9,7 @@ using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Mods
|
||||
{
|
||||
@ -18,7 +18,6 @@ namespace osu.Game.Rulesets.Mania.Mods
|
||||
public override string Description => @"Keys fade out before you hit them!";
|
||||
public override double ScoreMultiplier => 1;
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModFlashlight<ManiaHitObject>) };
|
||||
protected List<PlayfieldCover> PlayfieldCovers = new List<PlayfieldCover>();
|
||||
|
||||
public virtual void ApplyToDrawableRuleset(DrawableRuleset<ManiaHitObject> drawableRuleset)
|
||||
{
|
||||
@ -29,26 +28,23 @@ namespace osu.Game.Rulesets.Mania.Mods
|
||||
HitObjectContainer hoc = column.HitObjectArea.HitObjectContainer;
|
||||
Container hocParent = (Container)hoc.Parent;
|
||||
|
||||
PlayfieldCover laneCover;
|
||||
|
||||
hocParent.Remove(hoc);
|
||||
hocParent.Add(new BufferedContainer
|
||||
hocParent.Add(CreateCover().With(c =>
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
hoc,
|
||||
laneCover = new PlayfieldCover
|
||||
{
|
||||
Coverage = 0.5f,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre
|
||||
}
|
||||
}
|
||||
});
|
||||
c.RelativeSizeAxes = Axes.Both;
|
||||
c.Coverage = 0.5f;
|
||||
c.Child = hoc;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
PlayfieldCovers.Add(laneCover);
|
||||
protected virtual PlayfieldCoveringContainer CreateCover() => new ModHiddenCoveringContainer();
|
||||
|
||||
private class ModHiddenCoveringContainer : PlayfieldCoveringContainer
|
||||
{
|
||||
public ModHiddenCoveringContainer()
|
||||
{
|
||||
Cover.Scale = new Vector2(1, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.UI
|
||||
{
|
||||
public class PlayfieldCover : CompositeDrawable
|
||||
{
|
||||
private readonly Box gradient;
|
||||
private readonly Box filled;
|
||||
private readonly IBindable<ScrollingDirection> scrollDirection = new Bindable<ScrollingDirection>();
|
||||
|
||||
public PlayfieldCover()
|
||||
{
|
||||
Blending = new BlendingParameters
|
||||
{
|
||||
RGBEquation = BlendingEquation.Add,
|
||||
Source = BlendingType.Zero,
|
||||
Destination = BlendingType.One,
|
||||
AlphaEquation = BlendingEquation.Add,
|
||||
SourceAlpha = BlendingType.Zero,
|
||||
DestinationAlpha = BlendingType.OneMinusSrcAlpha
|
||||
};
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
gradient = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Height = 0.25f,
|
||||
Colour = ColourInfo.GradientVertical(
|
||||
Color4.White.Opacity(0f),
|
||||
Color4.White.Opacity(1f)
|
||||
)
|
||||
},
|
||||
filled = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IScrollingInfo scrollingInfo)
|
||||
{
|
||||
scrollDirection.BindTo(scrollingInfo.Direction);
|
||||
scrollDirection.BindValueChanged(onScrollDirectionChanged, true);
|
||||
}
|
||||
|
||||
private void onScrollDirectionChanged(ValueChangedEvent<ScrollingDirection> valueChangedEvent)
|
||||
{
|
||||
bool isUpscroll = valueChangedEvent.NewValue == ScrollingDirection.Up;
|
||||
Rotation = isUpscroll ? 180f : 0f;
|
||||
}
|
||||
|
||||
public float Coverage
|
||||
{
|
||||
set
|
||||
{
|
||||
filled.Height = value;
|
||||
gradient.Y = 1 - filled.Height - gradient.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
116
osu.Game.Rulesets.Mania/UI/PlayfieldCoveringContainer.cs
Normal file
116
osu.Game.Rulesets.Mania/UI/PlayfieldCoveringContainer.cs
Normal file
@ -0,0 +1,116 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Container"/> that has its contents partially hidden by an adjustable "cover".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The covered area extends in the scrolling direction, with its size depending on <see cref="Coverage"/>.
|
||||
/// </remarks>
|
||||
public class PlayfieldCoveringContainer : Container
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
|
||||
/// <summary>
|
||||
/// The complete cover, including gradient and fill.
|
||||
/// </summary>
|
||||
protected readonly Drawable Cover;
|
||||
|
||||
/// <summary>
|
||||
/// The gradient portion of the cover.
|
||||
/// </summary>
|
||||
private readonly Box gradient;
|
||||
|
||||
/// <summary>
|
||||
/// The fully-opaque portion of the cover.
|
||||
/// </summary>
|
||||
private readonly Box filled;
|
||||
|
||||
private readonly IBindable<ScrollingDirection> scrollDirection = new Bindable<ScrollingDirection>();
|
||||
|
||||
public PlayfieldCoveringContainer()
|
||||
{
|
||||
InternalChild = new BufferedContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new[]
|
||||
{
|
||||
content = new Container { RelativeSizeAxes = Axes.Both },
|
||||
Cover = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Blending = new BlendingParameters
|
||||
{
|
||||
// Don't change the destination colour.
|
||||
RGBEquation = BlendingEquation.Add,
|
||||
Source = BlendingType.Zero,
|
||||
Destination = BlendingType.One,
|
||||
// Subtract the cover's alpha from the destination (points with alpha 1 should make the destination completely transparent).
|
||||
AlphaEquation = BlendingEquation.Add,
|
||||
SourceAlpha = BlendingType.Zero,
|
||||
DestinationAlpha = BlendingType.OneMinusSrcAlpha
|
||||
},
|
||||
Children = new Drawable[]
|
||||
{
|
||||
gradient = new Box
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Height = 0.25f,
|
||||
Colour = ColourInfo.GradientVertical(
|
||||
Color4.White.Opacity(0f),
|
||||
Color4.White.Opacity(1f)
|
||||
)
|
||||
},
|
||||
filled = new Box
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IScrollingInfo scrollingInfo)
|
||||
{
|
||||
scrollDirection.BindTo(scrollingInfo.Direction);
|
||||
scrollDirection.BindValueChanged(onScrollDirectionChanged, true);
|
||||
}
|
||||
|
||||
private void onScrollDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
||||
=> Cover.Rotation = direction.NewValue == ScrollingDirection.Up ? 0 : 180f;
|
||||
|
||||
/// <summary>
|
||||
/// The relative area that should be completely covered. This does not include the fade.
|
||||
/// </summary>
|
||||
public float Coverage
|
||||
{
|
||||
set
|
||||
{
|
||||
filled.Height = value;
|
||||
gradient.Y = -value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user