2017-05-09 19:55:20 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
2017-05-04 17:02:43 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-09-11 03:21:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Caching;
|
2017-05-09 19:55:20 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-09-11 03:21:22 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-05-09 19:55:20 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
|
|
|
|
|
{
|
2017-05-09 19:55:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents length-wise portion of a hold note.
|
|
|
|
|
/// </summary>
|
2017-05-04 17:02:43 +08:00
|
|
|
|
internal class BodyPiece : Container, IHasAccentColour
|
|
|
|
|
{
|
2017-09-11 03:21:22 +08:00
|
|
|
|
private readonly Container subtractionLayer;
|
|
|
|
|
|
|
|
|
|
private readonly Drawable background;
|
|
|
|
|
private readonly BufferedContainer foreground;
|
|
|
|
|
private readonly BufferedContainer subtractionContainer;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
|
|
|
|
|
public BodyPiece()
|
|
|
|
|
{
|
2017-09-11 03:21:22 +08:00
|
|
|
|
Blending = BlendingMode.Additive;
|
2017-05-04 17:02:43 +08:00
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-09-11 03:21:22 +08:00
|
|
|
|
background = new Box { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
foreground = new BufferedContainer
|
2017-05-04 17:02:43 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-09-11 03:21:22 +08:00
|
|
|
|
CacheDrawnFrameBuffer = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
subtractionContainer = new BufferedContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
// This is needed because we're blending with another object
|
|
|
|
|
BackgroundColour = Color4.White.Opacity(0),
|
|
|
|
|
CacheDrawnFrameBuffer = true,
|
|
|
|
|
// The 'hole' is achieved by subtracting the result of this container with the parent
|
2017-09-11 07:59:56 +08:00
|
|
|
|
Blending = new BlendingParameters { AlphaEquation = BlendingEquation.ReverseSubtract },
|
2017-09-11 03:21:22 +08:00
|
|
|
|
Child = subtractionLayer = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
// Height computed in Update
|
|
|
|
|
Width = 1,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 03:21:22 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
updateAccentColour();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 17:02:43 +08:00
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return accentColour; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == value)
|
|
|
|
|
return;
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
2017-09-11 03:21:22 +08:00
|
|
|
|
updateAccentColour();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Cached subtractionCache = new Cached();
|
|
|
|
|
|
|
|
|
|
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
|
|
|
|
{
|
|
|
|
|
if ((invalidation & Invalidation.DrawSize) > 0)
|
|
|
|
|
subtractionCache.Invalidate();
|
|
|
|
|
|
|
|
|
|
return base.Invalidate(invalidation, source, shallPropagate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (!subtractionCache.IsValid)
|
|
|
|
|
{
|
|
|
|
|
subtractionLayer.Width = 5;
|
|
|
|
|
subtractionLayer.Height = Math.Max(0, DrawHeight - DrawWidth);
|
|
|
|
|
subtractionLayer.EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = DrawWidth
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreground.ForceRedraw();
|
|
|
|
|
subtractionContainer.ForceRedraw();
|
|
|
|
|
|
|
|
|
|
subtractionCache.Validate();
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-11 03:21:22 +08:00
|
|
|
|
|
|
|
|
|
private void updateAccentColour()
|
|
|
|
|
{
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreground.Colour = AccentColour.Opacity(0.4f);
|
|
|
|
|
background.Colour = AccentColour.Opacity(0.2f);
|
|
|
|
|
|
|
|
|
|
subtractionCache.Invalidate();
|
|
|
|
|
}
|
2017-05-04 17:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|