2016-09-02 18:25:13 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-09-02 18:25:13 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Beatmaps.Objects;
|
2016-10-10 16:17:26 +08:00
|
|
|
|
using osu.Framework;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
using System;
|
2016-11-02 13:07:20 +08:00
|
|
|
|
using System.Linq;
|
2016-11-09 07:13:20 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-09-02 18:25:13 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.GameModes.Play
|
|
|
|
|
{
|
2016-10-19 18:44:03 +08:00
|
|
|
|
public abstract class HitRenderer : Container
|
|
|
|
|
{
|
|
|
|
|
public Action<HitObject> OnHit;
|
|
|
|
|
public Action<HitObject> OnMiss;
|
2016-11-02 13:07:20 +08:00
|
|
|
|
|
|
|
|
|
protected Playfield Playfield;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<DrawableHitObject> DrawableObjects => Playfield.Children.Cast<DrawableHitObject>();
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class HitRenderer<T> : HitRenderer
|
2016-10-13 21:14:18 +08:00
|
|
|
|
where T : HitObject
|
2016-09-02 18:25:13 +08:00
|
|
|
|
{
|
2016-10-13 09:10:15 +08:00
|
|
|
|
private List<T> objects;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2016-10-13 09:10:15 +08:00
|
|
|
|
public List<HitObject> Objects
|
2016-10-01 17:40:14 +08:00
|
|
|
|
{
|
2016-10-13 09:10:15 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
objects = Convert(value);
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
loadObjects();
|
|
|
|
|
}
|
2016-10-01 17:40:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 09:10:15 +08:00
|
|
|
|
protected abstract Playfield CreatePlayfield();
|
|
|
|
|
|
2016-10-13 21:14:18 +08:00
|
|
|
|
protected abstract HitObjectConverter<T> Converter { get; }
|
|
|
|
|
|
|
|
|
|
protected virtual List<T> Convert(List<HitObject> objects) => Converter.Convert(objects);
|
2016-10-13 09:10:15 +08:00
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2016-10-13 09:10:15 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
2016-10-05 19:49:31 +08:00
|
|
|
|
{
|
2016-11-02 13:07:20 +08:00
|
|
|
|
Playfield = CreatePlayfield()
|
2016-10-13 09:10:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadObjects();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadObjects()
|
|
|
|
|
{
|
|
|
|
|
if (objects == null) return;
|
|
|
|
|
foreach (T h in objects)
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
|
|
|
|
var drawableObject = GetVisualRepresentation(h);
|
|
|
|
|
|
|
|
|
|
if (drawableObject == null) continue;
|
|
|
|
|
|
|
|
|
|
drawableObject.OnHit = onHit;
|
|
|
|
|
drawableObject.OnMiss = onMiss;
|
|
|
|
|
|
2016-11-02 13:07:20 +08:00
|
|
|
|
Playfield.Add(drawableObject);
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMiss(DrawableHitObject obj)
|
|
|
|
|
{
|
|
|
|
|
OnMiss?.Invoke(obj.HitObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onHit(DrawableHitObject obj)
|
|
|
|
|
{
|
|
|
|
|
OnHit?.Invoke(obj.HitObject);
|
2016-09-02 19:30:27 +08:00
|
|
|
|
}
|
2016-10-13 09:10:15 +08:00
|
|
|
|
|
2016-10-19 18:44:03 +08:00
|
|
|
|
protected abstract DrawableHitObject GetVisualRepresentation(T h);
|
2016-09-02 18:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|