1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 15:27:30 +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.IO;
using osu.Game.Overlays;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables;
using osu.Game.Tests.Gameplay;
using osu.Game.Tests.Resources;
using osuTK.Graphics;
@ -28,14 +31,14 @@ namespace osu.Game.Tests.Visual.Gameplay
private DrawableStoryboard? storyboard;
[Cached]
private GameplayState testGameplayState = TestGameplayState.Create(new OsuRuleset());
[Test]
public void TestStoryboard()
{
AddStep("Restart", restart);
AddToggleStep("Passing", passing =>
{
if (storyboard != null) storyboard.Passing = passing;
});
AddToggleStep("Toggle passing state", passing => testGameplayState.HealthProcessor.Health.Value = passing ? 1 : 0);
}
[Test]
@ -109,7 +112,6 @@ namespace osu.Game.Tests.Visual.Gameplay
storyboardContainer.Clock = new FramedClock(Beatmap.Value.Track);
storyboard = toLoad.CreateDrawable(SelectedMods.Value);
storyboard.Passing = false;
storyboardContainer.Add(storyboard);
}

View File

@ -40,6 +40,7 @@ namespace osu.Game.Screens.Play
public readonly Score Score;
public readonly ScoreProcessor ScoreProcessor;
public readonly HealthProcessor HealthProcessor;
/// <summary>
/// The storyboard associated with the beatmap.
@ -68,7 +69,14 @@ namespace osu.Game.Screens.Play
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;
Ruleset = ruleset;
@ -82,6 +90,7 @@ namespace osu.Game.Screens.Play
};
Mods = mods ?? Array.Empty<Mod>();
ScoreProcessor = scoreProcessor ?? ruleset.CreateScoreProcessor();
HealthProcessor = healthProcessor ?? ruleset.CreateHealthProcessor(beatmap.HitObjects[0].StartTime);
Storyboard = storyboard ?? new Storyboard();
}

View File

@ -260,7 +260,7 @@ namespace osu.Game.Screens.Play
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
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);

View File

@ -37,20 +37,6 @@ namespace osu.Game.Storyboards.Drawables
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;
private double? lastEventEndTime;
@ -66,6 +52,9 @@ namespace osu.Game.Storyboards.Drawables
private DependencyContainer dependencies = null!;
private BindableNumber<double> health = null!;
private readonly BindableBool passing = new BindableBool(true);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -91,8 +80,8 @@ namespace osu.Game.Storyboards.Drawables
});
}
[BackgroundDependencyLoader(true)]
private void load(IGameplayClock? clock, CancellationToken? cancellationToken)
[BackgroundDependencyLoader]
private void load(IGameplayClock? clock, CancellationToken? cancellationToken, GameplayState? gameplayState)
{
if (clock != null)
Clock = clock;
@ -110,6 +99,16 @@ namespace osu.Game.Storyboards.Drawables
}
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);
@ -125,7 +124,7 @@ namespace osu.Game.Storyboards.Drawables
private void updateLayerVisibility()
{
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[]>

View File

@ -27,7 +27,9 @@ namespace osu.Game.Tests.Gameplay
var scoreProcessor = ruleset.CreateScoreProcessor();
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);
}
}
}