Make ComboEffects its own class

This commit is contained in:
Welsar55 2019-06-29 11:28:40 -05:00
parent a57218e50e
commit a22c166575
4 changed files with 44 additions and 29 deletions

View File

@ -4,7 +4,6 @@
using System;
using NUnit.Framework;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -29,7 +28,7 @@ namespace osu.Game.Tests.Visual.Gameplay
Child = new SkinSourceContainer
{
RelativeSizeAxes = Axes.Both,
Child = new LocalSkinOverrideContainer(secondarySource, new BindableInt())
Child = new LocalSkinOverrideContainer(secondarySource)
{
RelativeSizeAxes = Axes.Both,
Child = consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"), source => true)
@ -54,7 +53,7 @@ namespace osu.Game.Tests.Visual.Gameplay
Child = new SkinSourceContainer
{
RelativeSizeAxes = Axes.Both,
Child = target = new LocalSkinOverrideContainer(secondarySource, new BindableInt())
Child = target = new LocalSkinOverrideContainer(secondarySource)
{
RelativeSizeAxes = Axes.Both,
}

View File

@ -0,0 +1,35 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
namespace osu.Game.Screens.Play
{
public class ComboEffects : CompositeDrawable
{
private SampleChannel sampleComboBreak;
public ComboEffects(ScoreProcessor processor)
{
processor.Combo.BindValueChanged(onComboChange);
}
private void onComboChange(ValueChangedEvent<int> combo)
{
if (combo.NewValue == 0 && combo.OldValue > 20)
sampleComboBreak?.Play();
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, AudioManager audio)
{
sampleComboBreak = skin.GetSample(@"Gameplay/combobreak") ?? audio.Samples.Get(@"Gameplay/combobreak");
}
}
}

View File

@ -124,10 +124,14 @@ namespace osu.Game.Screens.Play
StoryboardContainer = CreateStoryboardContainer(),
new ScalingContainer(ScalingMode.Gameplay)
{
Child = new LocalSkinOverrideContainer(working.Skin, ScoreProcessor.Combo)
Child = new LocalSkinOverrideContainer(working.Skin)
{
RelativeSizeAxes = Axes.Both,
Child = DrawableRuleset
Children = new Drawable[]
{
DrawableRuleset,
new ComboEffects(ScoreProcessor)
}
}
},
new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)

View File

@ -3,7 +3,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -25,14 +24,11 @@ namespace osu.Game.Skinning
private readonly ISkin skin;
private readonly ComboEffects comboEffects;
private ISkinSource fallbackSource;
public LocalSkinOverrideContainer(ISkin skin, BindableInt combo)
public LocalSkinOverrideContainer(ISkin skin)
{
this.skin = skin;
comboEffects = new ComboEffects(combo);
}
public Drawable GetDrawableComponent(string componentName)
@ -92,9 +88,6 @@ namespace osu.Game.Skinning
beatmapSkins.BindValueChanged(_ => onSourceChanged());
beatmapHitsounds.BindValueChanged(_ => onSourceChanged());
AudioManager audio = dependencies.Get<AudioManager>();
comboEffects.SampleComboBreak = GetSample(@"Gameplay/combobreak") ?? audio.Samples.Get(@"Gameplay/combobreak");
return dependencies;
}
@ -108,21 +101,5 @@ namespace osu.Game.Skinning
if (fallbackSource != null)
fallbackSource.SourceChanged -= onSourceChanged;
}
private class ComboEffects
{
public SampleChannel SampleComboBreak;
public ComboEffects(BindableInt combo)
{
combo.BindValueChanged(onComboChange);
}
private void onComboChange(ValueChangedEvent<int> combo)
{
if (combo.NewValue == 0 && combo.OldValue > 20)
SampleComboBreak?.Play();
}
}
}
}