1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Merge pull request #28480 from bdach/storyboard-pass-fail-show

Implement toggling visibility of pass and fail storyboard layers
This commit is contained in:
Dean Herbert 2024-06-16 11:08:00 +09:00 committed by GitHub
commit 15fbad0097
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 25 deletions

View File

@ -14,8 +14,11 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Storyboards; using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables; using osu.Game.Storyboards.Drawables;
using osu.Game.Tests.Gameplay;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using osuTK.Graphics; using osuTK.Graphics;
@ -28,14 +31,14 @@ namespace osu.Game.Tests.Visual.Gameplay
private DrawableStoryboard? storyboard; private DrawableStoryboard? storyboard;
[Cached]
private GameplayState testGameplayState = TestGameplayState.Create(new OsuRuleset());
[Test] [Test]
public void TestStoryboard() public void TestStoryboard()
{ {
AddStep("Restart", restart); AddStep("Restart", restart);
AddToggleStep("Passing", passing => AddToggleStep("Toggle passing state", passing => testGameplayState.HealthProcessor.Health.Value = passing ? 1 : 0);
{
if (storyboard != null) storyboard.Passing = passing;
});
} }
[Test] [Test]
@ -109,7 +112,6 @@ namespace osu.Game.Tests.Visual.Gameplay
storyboardContainer.Clock = new FramedClock(Beatmap.Value.Track); storyboardContainer.Clock = new FramedClock(Beatmap.Value.Track);
storyboard = toLoad.CreateDrawable(SelectedMods.Value); storyboard = toLoad.CreateDrawable(SelectedMods.Value);
storyboard.Passing = false;
storyboardContainer.Add(storyboard); storyboardContainer.Add(storyboard);
} }

View File

@ -40,6 +40,7 @@ namespace osu.Game.Screens.Play
public readonly Score Score; public readonly Score Score;
public readonly ScoreProcessor ScoreProcessor; public readonly ScoreProcessor ScoreProcessor;
public readonly HealthProcessor HealthProcessor;
/// <summary> /// <summary>
/// The storyboard associated with the beatmap. /// The storyboard associated with the beatmap.
@ -68,7 +69,14 @@ namespace osu.Game.Screens.Play
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>(); private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
public GameplayState(IBeatmap beatmap, Ruleset ruleset, IReadOnlyList<Mod>? mods = null, Score? score = null, ScoreProcessor? scoreProcessor = null, Storyboard? storyboard = null) public GameplayState(
IBeatmap beatmap,
Ruleset ruleset,
IReadOnlyList<Mod>? mods = null,
Score? score = null,
ScoreProcessor? scoreProcessor = null,
HealthProcessor? healthProcessor = null,
Storyboard? storyboard = null)
{ {
Beatmap = beatmap; Beatmap = beatmap;
Ruleset = ruleset; Ruleset = ruleset;
@ -82,6 +90,7 @@ namespace osu.Game.Screens.Play
}; };
Mods = mods ?? Array.Empty<Mod>(); Mods = mods ?? Array.Empty<Mod>();
ScoreProcessor = scoreProcessor ?? ruleset.CreateScoreProcessor(); ScoreProcessor = scoreProcessor ?? ruleset.CreateScoreProcessor();
HealthProcessor = healthProcessor ?? ruleset.CreateHealthProcessor(beatmap.HitObjects[0].StartTime);
Storyboard = storyboard ?? new Storyboard(); Storyboard = storyboard ?? new Storyboard();
} }

View File

@ -260,7 +260,7 @@ namespace osu.Game.Screens.Play
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo; Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
Score.ScoreInfo.Mods = gameplayMods; Score.ScoreInfo.Mods = gameplayMods;
dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, gameplayMods, Score, ScoreProcessor, Beatmap.Value.Storyboard)); dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, gameplayMods, Score, ScoreProcessor, HealthProcessor, Beatmap.Value.Storyboard));
var rulesetSkinProvider = new RulesetSkinProvidingContainer(ruleset, playableBeatmap, Beatmap.Value.Skin); var rulesetSkinProvider = new RulesetSkinProvidingContainer(ruleset, playableBeatmap, Beatmap.Value.Skin);

View File

@ -37,20 +37,6 @@ namespace osu.Game.Storyboards.Drawables
protected override Vector2 DrawScale => new Vector2(Parent!.DrawHeight / 480); protected override Vector2 DrawScale => new Vector2(Parent!.DrawHeight / 480);
private bool passing = true;
public bool Passing
{
get => passing;
set
{
if (passing == value) return;
passing = value;
updateLayerVisibility();
}
}
public override bool RemoveCompletedTransforms => false; public override bool RemoveCompletedTransforms => false;
private double? lastEventEndTime; private double? lastEventEndTime;
@ -66,6 +52,9 @@ namespace osu.Game.Storyboards.Drawables
private DependencyContainer dependencies = null!; private DependencyContainer dependencies = null!;
private BindableNumber<double> health = null!;
private readonly BindableBool passing = new BindableBool(true);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -91,8 +80,8 @@ namespace osu.Game.Storyboards.Drawables
}); });
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader]
private void load(IGameplayClock? clock, CancellationToken? cancellationToken) private void load(IGameplayClock? clock, CancellationToken? cancellationToken, GameplayState? gameplayState)
{ {
if (clock != null) if (clock != null)
Clock = clock; Clock = clock;
@ -110,6 +99,16 @@ namespace osu.Game.Storyboards.Drawables
} }
lastEventEndTime = Storyboard.LatestEventTime; lastEventEndTime = Storyboard.LatestEventTime;
health = gameplayState?.HealthProcessor.Health.GetBoundCopy() ?? new BindableDouble(1);
}
protected override void LoadComplete()
{
base.LoadComplete();
health.BindValueChanged(val => passing.Value = val.NewValue >= 0.5, true);
passing.BindValueChanged(_ => updateLayerVisibility(), true);
} }
protected virtual IResourceStore<byte[]> CreateResourceLookupStore() => new StoryboardResourceLookupStore(Storyboard, realm, host); protected virtual IResourceStore<byte[]> CreateResourceLookupStore() => new StoryboardResourceLookupStore(Storyboard, realm, host);
@ -125,7 +124,7 @@ namespace osu.Game.Storyboards.Drawables
private void updateLayerVisibility() private void updateLayerVisibility()
{ {
foreach (var layer in Children) foreach (var layer in Children)
layer.Enabled = passing ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing; layer.Enabled = passing.Value ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing;
} }
private class StoryboardResourceLookupStore : IResourceStore<byte[]> private class StoryboardResourceLookupStore : IResourceStore<byte[]>

View File

@ -27,7 +27,9 @@ namespace osu.Game.Tests.Gameplay
var scoreProcessor = ruleset.CreateScoreProcessor(); var scoreProcessor = ruleset.CreateScoreProcessor();
scoreProcessor.ApplyBeatmap(playableBeatmap); scoreProcessor.ApplyBeatmap(playableBeatmap);
return new GameplayState(playableBeatmap, ruleset, mods, score, scoreProcessor); var healthProcessor = ruleset.CreateHealthProcessor(beatmap.HitObjects[0].StartTime);
return new GameplayState(playableBeatmap, ruleset, mods, score, scoreProcessor, healthProcessor);
} }
} }
} }