1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 16:52:57 +08:00
osu-lazer/osu.Game.Modes.Osu/Objects/Drawables/SliderTicksRenderer.cs

96 lines
2.7 KiB
C#
Raw Normal View History

2017-02-13 03:38:05 +08: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 22:16:18 +08:00
using osu.Framework.Allocation;
using osu.Framework.Caching;
2017-02-13 03:38:05 +08: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 22:16:18 +08:00
private Cached drawableTicks = new Cached();
2017-02-13 03:38:05 +08:00
private double startTime;
public double StartTime
{
get { return startTime; }
set
{
startTime = value;
2017-02-14 22:16:18 +08:00
drawableTicks.Invalidate();
2017-02-13 03:38:05 +08:00
}
}
private double repeatDuration;
public double RepeatDuration
{
get { return repeatDuration; }
set
{
repeatDuration = value;
2017-02-14 22:16:18 +08:00
drawableTicks.Invalidate();
2017-02-13 03:38:05 +08:00
}
}
private IEnumerable<SliderTick> ticks;
public IEnumerable<SliderTick> Ticks
{
get { return ticks; }
set
{
ticks = value;
2017-02-14 22:16:18 +08:00
drawableTicks.Invalidate();
2017-02-13 03:38:05 +08:00
}
}
public bool ShouldHit
{
set
{
foreach (var tick in Children)
tick.ShouldHit = value;
}
}
2017-02-14 22:16:18 +08:00
protected override void Update()
2017-02-13 03:38:05 +08:00
{
2017-02-14 22:16:18 +08:00
base.Update();
updateDrawableTicks();
}
[BackgroundDependencyLoader]
private void load()
{
updateDrawableTicks();
}
private void updateDrawableTicks()
{
if (drawableTicks.EnsureValid())
2017-02-13 03:38:05 +08:00
return;
2017-02-14 22:16:18 +08:00
drawableTicks.Refresh(delegate
2017-02-13 03:38:05 +08:00
{
2017-02-14 22:16:18 +08:00
Clear();
if (ticks == null || repeatDuration == 0)
return;
2017-02-13 03:38:05 +08:00
2017-02-14 22:16:18 +08:00
foreach (var tick in ticks)
2017-02-13 03:38:05 +08:00
{
2017-02-14 22:16:18 +08: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-13 03:38:05 +08:00
}
}
}