osu/osu.Game.Modes.Osu/Objects/Drawables/SliderTicksLayer.cs

96 lines
2.7 KiB
C#
Raw Normal View History

2017-02-12 19:38:05 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-02-14 14:16:18 +00:00
using osu.Framework.Allocation;
using osu.Framework.Caching;
2017-02-12 19:38:05 +00:00
using osu.Framework.Graphics.Containers;
using System.Collections.Generic;
namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
{
public class SliderTicksRenderer : Container<DrawableSliderTick>
{
2017-02-14 14:16:18 +00:00
private Cached drawableTicks = new Cached();
2017-02-12 19:38:05 +00:00
private double startTime;
public double StartTime
{
get { return startTime; }
set
{
startTime = value;
2017-02-14 14:16:18 +00:00
drawableTicks.Invalidate();
2017-02-12 19:38:05 +00:00
}
}
private double repeatDuration;
public double RepeatDuration
{
get { return repeatDuration; }
set
{
repeatDuration = value;
2017-02-14 14:16:18 +00:00
drawableTicks.Invalidate();
2017-02-12 19:38:05 +00:00
}
}
private IEnumerable<SliderTick> ticks;
public IEnumerable<SliderTick> Ticks
{
get { return ticks; }
set
{
ticks = value;
2017-02-14 14:16:18 +00:00
drawableTicks.Invalidate();
2017-02-12 19:38:05 +00:00
}
}
public bool ShouldHit
{
set
{
foreach (var tick in Children)
tick.ShouldHit = value;
}
}
2017-02-14 14:16:18 +00:00
protected override void Update()
2017-02-12 19:38:05 +00:00
{
2017-02-14 14:16:18 +00:00
base.Update();
updateDrawableTicks();
}
[BackgroundDependencyLoader]
private void load()
{
updateDrawableTicks();
}
private void updateDrawableTicks()
{
if (drawableTicks.EnsureValid())
2017-02-12 19:38:05 +00:00
return;
2017-02-14 14:16:18 +00:00
drawableTicks.Refresh(delegate
2017-02-12 19:38:05 +00:00
{
2017-02-14 14:16:18 +00:00
Clear();
if (ticks == null || repeatDuration == 0)
return;
2017-02-12 19:38:05 +00:00
2017-02-14 14:16:18 +00:00
foreach (var tick in ticks)
2017-02-12 19:38:05 +00:00
{
2017-02-14 14:16:18 +00:00
var repeatStartTime = startTime + tick.RepeatIndex * repeatDuration;
var fadeInTime = repeatStartTime + (tick.StartTime - repeatStartTime) / 2 - (tick.RepeatIndex == 0 ? DrawableOsuHitObject.TIME_FADEIN : DrawableOsuHitObject.TIME_FADEIN / 2);
var fadeOutTime = repeatStartTime + repeatDuration;
Add(new DrawableSliderTick(tick)
{
FadeInTime = fadeInTime,
FadeOutTime = fadeOutTime,
Position = tick.Position,
});
}
});
2017-02-12 19:38:05 +00:00
}
}
}