osu/osu.Game.Modes.Taiko/UI/TaikoPlayfield.cs

233 lines
9.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-02 10:58:57 +00:00
2016-11-14 08:23:33 +00:00
using osu.Framework.Allocation;
2016-09-02 10:58:57 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
2017-03-06 04:59:11 +00:00
using osu.Game.Modes.Taiko.Objects;
2016-11-14 09:54:24 +00:00
using osu.Game.Modes.UI;
2016-09-02 10:58:57 +00:00
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Modes.Taiko.Judgements;
2017-03-21 06:09:54 +00:00
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Primitives;
using System.Linq;
2017-04-04 03:38:55 +00:00
using osu.Game.Modes.Taiko.Objects.Drawables;
2016-09-02 10:58:57 +00:00
2016-11-14 09:54:24 +00:00
namespace osu.Game.Modes.Taiko.UI
2016-09-02 10:58:57 +00:00
{
public class TaikoPlayfield : Playfield<TaikoHitObject, TaikoJudgement>
2016-09-02 10:58:57 +00:00
{
2017-03-21 06:09:54 +00:00
/// <summary>
/// The play field height. This is relative to the size of hit objects
/// such that the playfield is just a bit larger than strong hits.
2017-03-21 06:09:54 +00:00
/// </summary>
public const float DEFAULT_PLAYFIELD_HEIGHT = 168f;
2017-03-21 06:09:54 +00:00
/// <summary>
/// The offset from <see cref="left_area_size"/> which the center of the hit target lies at.
/// </summary>
private const float hit_target_offset = TaikoHitObject.DEFAULT_STRONG_CIRCLE_DIAMETER / 2f + 40;
2017-03-21 06:09:54 +00:00
/// <summary>
/// The size of the left area of the playfield. This area contains the input drum.
/// </summary>
private const float left_area_size = 240;
protected override Container<Drawable> Content => hitObjectContainer;
2017-03-23 05:37:00 +00:00
private readonly Container<HitExplosion> hitExplosionContainer;
2017-04-01 14:59:44 +00:00
private readonly Container<DrawableBarLine> barLineContainer;
private readonly Container<DrawableTaikoJudgement> judgementContainer;
2017-03-21 06:09:54 +00:00
2017-03-23 05:37:00 +00:00
private readonly Container hitObjectContainer;
2017-03-29 00:02:49 +00:00
private readonly Container topLevelHitContainer;
2017-03-23 05:37:00 +00:00
private readonly Container leftBackgroundContainer;
private readonly Container rightBackgroundContainer;
private readonly Box leftBackground;
private readonly Box rightBackground;
2017-03-21 06:09:54 +00:00
2016-09-02 10:58:57 +00:00
public TaikoPlayfield()
{
RelativeSizeAxes = Axes.X;
2017-04-09 20:08:05 +00:00
Height = DEFAULT_PLAYFIELD_HEIGHT;
2017-03-21 06:09:54 +00:00
AddInternal(new Drawable[]
{
rightBackgroundContainer = new Container
{
RelativeSizeAxes = Axes.Both,
BorderThickness = 2,
Masking = true,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.2f),
Radius = 5,
},
Children = new Drawable[]
{
rightBackground = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.6f
},
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = left_area_size },
Children = new Drawable[]
{
new Container
{
X = hit_target_offset,
2017-03-21 06:09:54 +00:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
hitExplosionContainer = new Container<HitExplosion>
2017-03-21 06:09:54 +00:00
{
2017-03-21 09:28:04 +00:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
2017-04-09 20:08:05 +00:00
Size = new Vector2(DEFAULT_PLAYFIELD_HEIGHT),
FillMode = FillMode.Fit,
2017-03-21 09:28:04 +00:00
BlendingMode = BlendingMode.Additive
2017-03-21 06:09:54 +00:00
},
2017-03-21 11:39:18 +00:00
barLineContainer = new Container<DrawableBarLine>
{
RelativeSizeAxes = Axes.Both,
},
2017-03-21 08:50:05 +00:00
new HitTarget
2017-03-21 06:09:54 +00:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
2017-04-09 20:08:05 +00:00
FillMode = FillMode.Fit
2017-03-21 06:09:54 +00:00
},
hitObjectContainer = new HitObjectContainer
2017-03-21 06:09:54 +00:00
{
Height = DEFAULT_PLAYFIELD_HEIGHT,
FillMode = FillMode.Fit
2017-03-21 06:09:54 +00:00
},
judgementContainer = new Container<DrawableTaikoJudgement>
2017-03-21 07:33:25 +00:00
{
2017-04-09 20:08:05 +00:00
Size = new Vector2(DEFAULT_PLAYFIELD_HEIGHT),
FillMode = FillMode.Fit,
2017-03-21 07:33:25 +00:00
BlendingMode = BlendingMode.Additive
},
2017-03-21 06:09:54 +00:00
},
},
}
},
leftBackgroundContainer = new Container
{
2017-04-09 20:08:05 +00:00
RelativeSizeAxes = Axes.Y,
Width = left_area_size,
2017-03-21 06:09:54 +00:00
BorderThickness = 1,
Children = new Drawable[]
{
leftBackground = new Box
{
RelativeSizeAxes = Axes.Both,
},
2017-03-21 09:28:04 +00:00
new InputDrum
2017-03-21 06:09:54 +00:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
Position = new Vector2(0.10f, 0),
2017-04-09 20:08:05 +00:00
FillMode = FillMode.Fit,
2017-03-21 09:28:04 +00:00
Scale = new Vector2(0.9f)
2017-03-21 06:09:54 +00:00
},
new Box
{
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = 10,
ColourInfo = Framework.Graphics.Colour.ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.6f), Color4.Black.Opacity(0)),
},
}
},
topLevelHitContainer = new Container
{
RelativeSizeAxes = Axes.Both,
}
});
2016-09-02 10:58:57 +00:00
}
[BackgroundDependencyLoader]
2017-03-21 06:09:54 +00:00
private void load(OsuColour colours)
2016-09-02 10:58:57 +00:00
{
2017-03-21 06:09:54 +00:00
leftBackgroundContainer.BorderColour = colours.Gray0;
leftBackground.Colour = colours.Gray1;
2016-09-02 10:58:57 +00:00
2017-03-21 06:09:54 +00:00
rightBackgroundContainer.BorderColour = colours.Gray1;
rightBackground.Colour = colours.Gray0;
}
public override void Add(DrawableHitObject<TaikoHitObject, TaikoJudgement> h)
2017-03-21 06:09:54 +00:00
{
h.Depth = (float)h.HitObject.StartTime;
base.Add(h);
// Swells should be moved at the very top of the playfield when they reach the hit target
var swell = h as DrawableSwell;
if (swell != null)
swell.OnStart += () => topLevelHitContainer.Add(swell.CreateProxy());
2017-03-21 06:09:54 +00:00
}
public void AddBarLine(DrawableBarLine barLine)
{
barLineContainer.Add(barLine);
}
public override void OnJudgement(DrawableHitObject<TaikoHitObject, TaikoJudgement> judgedObject)
2017-03-21 06:09:54 +00:00
{
bool wasHit = judgedObject.Judgement.Result == HitResult.Hit;
bool secondHit = judgedObject.Judgement.SecondHit;
2017-03-21 07:33:25 +00:00
judgementContainer.Add(new DrawableTaikoJudgement(judgedObject.Judgement)
2017-03-21 07:33:25 +00:00
{
Anchor = wasHit ? Anchor.TopLeft : Anchor.CentreLeft,
Origin = wasHit ? Anchor.BottomCentre : Anchor.Centre,
2017-03-21 07:33:25 +00:00
RelativePositionAxes = Axes.X,
X = wasHit ? judgedObject.Position.X : 0,
2017-03-21 07:33:25 +00:00
});
if (!wasHit)
return;
if (!secondHit)
{
if (judgedObject.X >= -0.05f && !(judgedObject is DrawableSwell))
{
// If we're far enough away from the left stage, we should bring outselves in front of it
topLevelHitContainer.Add(judgedObject.CreateProxy());
}
hitExplosionContainer.Add(new HitExplosion(judgedObject.Judgement));
}
else
hitExplosionContainer.Children.FirstOrDefault(e => e.Judgement == judgedObject.Judgement)?.VisualiseSecondHit();
2016-09-02 10:58:57 +00:00
}
private class HitObjectContainer : Container
{
public HitObjectContainer()
{
RelativeSizeAxes = Axes.X;
}
protected override void Update()
{
base.Update();
Width = 1 / DrawScale.X;
}
}
2016-09-02 10:58:57 +00:00
}
}