1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 16:03:01 +08:00

Merge pull request #231 from peppy/hit-samples

Add very basic hitsound support.
This commit is contained in:
Thomas Müller 2016-12-13 14:24:12 +01:00 committed by GitHub
commit 10de34930b
7 changed files with 55 additions and 12 deletions

@ -1 +1 @@
Subproject commit 73ddad1f01f223c6c311f1302ed1658a2320813d
Subproject commit e24414a277e407ae2438e4b6d9fa9c7992dd6485

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects.Drawables.Pieces;
using OpenTK;
using osu.Framework.Input;
namespace osu.Game.Modes.Osu.Objects.Drawables
{
@ -18,13 +19,12 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
private List<ISliderProgress> components = new List<ISliderProgress>();
SliderBody body;
SliderBall ball;
SliderBouncer bouncer1, bouncer2;
public DrawableSlider(Slider s) : base(s)
{
SliderBall ball;
slider = s;
Children = new Drawable[]
@ -54,10 +54,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
Position = s.Position,
Scale = s.Scale,
Colour = s.Colour,
})
{
Depth = -1 //override time-based depth.
},
Sample = s.Sample,
}),
};
components.Add(body);
@ -70,6 +68,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
// pass all input through.
public override bool Contains(Vector2 screenSpacePos) => true;
int currentRepeat;
protected override void Update()
{
base.Update();
@ -79,6 +79,13 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
int repeat = (int)(progress * slider.RepeatCount);
progress = (progress * slider.RepeatCount) % 1;
if (repeat > currentRepeat)
{
if (ball.Tracking)
PlaySample();
currentRepeat = repeat;
}
if (repeat % 2 == 1)
progress = 1 - progress;
@ -107,14 +114,22 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
{
base.UpdateInitialState();
body.Alpha = 1;
//we need to be visible to handle input events. note that we still don't get enough events (we don't get a position if the mouse hasn't moved since the slider appeared).
ball.Alpha = 0.01f;
}
protected override void UpdateState(ArmedState state)
{
base.UpdateState(state);
ball.FadeIn();
Delay(HitObject.Duration, true);
body.FadeOut(160);
ball.FadeOut(160);
FadeOut(800);
}
}

View File

@ -84,7 +84,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
}
bool tracking;
protected bool Tracking
public bool Tracking
{
get { return tracking; }
set
@ -98,17 +98,18 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
}
}
private bool canCurrentlyTrack => Time.Current >= slider.StartTime && Time.Current < slider.EndTime;
protected override void Update()
{
base.Update();
CornerRadius = DrawWidth / 2;
Tracking = lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed;
Tracking = canCurrentlyTrack && lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed;
}
public void UpdateProgress(double progress, int repeat)
{
Alpha = Time.Current >= slider.StartTime && Time.Current <= slider.EndTime ? 1 : 0;
Position = slider.Curve.PositionAt(progress);
}
}

View File

@ -101,7 +101,10 @@ namespace osu.Game.Modes.Osu.Objects
}
result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1]));
result.StartTime = double.Parse(split[2]);
result.Sample = new HitSampleInfo { Type = (SampleType)int.Parse(split[4]) };
result.Sample = new HitSampleInfo {
Type = (SampleType)int.Parse(split[4]),
Set = SampleSet.Soft,
};
result.NewCombo = combo;
// TODO: "addition" field
return result;

View File

@ -51,6 +51,7 @@ namespace osu.Game.Modes.Osu.UI
public override void Add(DrawableHitObject h)
{
h.Depth = (float)h.HitObject.StartTime;
DrawableHitCircle c = h as DrawableHitCircle;
if (c != null)
{

View File

@ -5,7 +5,11 @@ using System;
using System.ComponentModel;
using System.Diagnostics;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps.Samples;
using OpenTK;
using Container = osu.Framework.Graphics.Containers.Container;
@ -26,7 +30,6 @@ namespace osu.Game.Modes.Objects.Drawables
public DrawableHitObject(HitObject hitObject)
{
HitObject = hitObject;
Depth = (float)hitObject.StartTime;
}
private ArmedState state;
@ -40,9 +43,28 @@ namespace osu.Game.Modes.Objects.Drawables
state = value;
UpdateState(state);
if (State == ArmedState.Hit)
PlaySample();
}
}
AudioSample sample;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
string hitType = (HitObject.Sample.Type == SampleType.None ? SampleType.Normal : HitObject.Sample.Type).ToString().ToLower();
string sampleSet = HitObject.Sample.Set.ToString().ToLower();
sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}");
}
protected void PlaySample()
{
sample?.Play();
}
protected override void LoadComplete()
{
base.LoadComplete();

View File

@ -132,6 +132,7 @@ namespace osu.Game.Screens.Play
Delay(1000);
Schedule(delegate
{
ValidForResume = false;
Push(new Results
{
Score = scoreProcessor.GetScore()