From 32c641ddc877a19921725c9d3d8fd08fb0701376 Mon Sep 17 00:00:00 2001 From: flustix Date: Sun, 8 Sep 2024 15:27:46 +0200 Subject: [PATCH] Make `Results` a base class --- fluXis.Game.Tests/Screens/TestResults.cs | 12 +-- fluXis.Game/FluXisGame.cs | 2 +- .../Result/Center/ResultsCenterScore.cs | 2 +- fluXis.Game/Screens/Result/Results.cs | 98 +++++++++++++++++++ fluXis.Game/Screens/Result/ResultsContent.cs | 14 ++- fluXis.Game/Screens/Result/SoloResults.cs | 85 ++-------------- 6 files changed, 121 insertions(+), 92 deletions(-) create mode 100644 fluXis.Game/Screens/Result/Results.cs diff --git a/fluXis.Game.Tests/Screens/TestResults.cs b/fluXis.Game.Tests/Screens/TestResults.cs index d13d50ac..6f130f1b 100644 --- a/fluXis.Game.Tests/Screens/TestResults.cs +++ b/fluXis.Game.Tests/Screens/TestResults.cs @@ -67,20 +67,14 @@ private RealmMap getMap() Mods = new List { "1.5x" } }; - [Test] - public void FromGameplay() - { - AddStep("Push", () => stack.Push(new SoloResults(getMap(), getScore(), APIUser.Dummy) { ForceFromGameplay = true })); - } - [Test] public void Normal() { - AddStep("Push", () => stack.Push(new SoloResults(getMap(), getScore(), APIUser.Dummy))); + AddStep("Push", () => stack.Push(new Results(getMap(), getScore(), APIUser.Dummy))); } [Test] - public void WithRequest() + public void WithRequestFromGameplay() { var score = getScore(); AddStep("Push With Request", () => stack.Push(new SoloResults(getMap(), score, APIUser.Dummy) { SubmitRequest = new SimulatedScoreRequest(score) })); @@ -89,7 +83,7 @@ public void WithRequest() [Test] public void WithRestart() { - AddStep("Push With Restart", () => stack.Push(new SoloResults(getMap(), getScore(), APIUser.Dummy) { OnRestart = () => Logger.Log("Restart pressed.") })); + AddStep("Push With Restart", () => stack.Push(new Results(getMap(), getScore(), APIUser.Dummy) { OnRestart = () => Logger.Log("Restart pressed.") })); } private class SimulatedScoreRequest : ScoreSubmitRequest diff --git a/fluXis.Game/FluXisGame.cs b/fluXis.Game/FluXisGame.cs index 414751ed..8c80deed 100644 --- a/fluXis.Game/FluXisGame.cs +++ b/fluXis.Game/FluXisGame.cs @@ -340,7 +340,7 @@ public override void PresentScore(RealmMap map, ScoreInfo score, APIUser player) if (map == null || score == null) throw new ArgumentNullException(); - screenStack.Push(new SoloResults(map, score, player)); + screenStack.Push(new Results(map, score, player)); } public void PresentUser(long id) diff --git a/fluXis.Game/Screens/Result/Center/ResultsCenterScore.cs b/fluXis.Game/Screens/Result/Center/ResultsCenterScore.cs index aadd2341..e2fc3db5 100644 --- a/fluXis.Game/Screens/Result/Center/ResultsCenterScore.cs +++ b/fluXis.Game/Screens/Result/Center/ResultsCenterScore.cs @@ -10,7 +10,7 @@ namespace fluXis.Game.Screens.Result.Center; public partial class ResultsCenterScore : CompositeDrawable { [BackgroundDependencyLoader] - private void load(SoloResults results, ScoreInfo score) + private void load(Results results, ScoreInfo score) { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; diff --git a/fluXis.Game/Screens/Result/Results.cs b/fluXis.Game/Screens/Result/Results.cs new file mode 100644 index 00000000..aa14487e --- /dev/null +++ b/fluXis.Game/Screens/Result/Results.cs @@ -0,0 +1,98 @@ +using System; +using fluXis.Game.Database.Maps; +using fluXis.Game.Input; +using fluXis.Shared.Components.Users; +using fluXis.Shared.Scoring; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.Events; +using osu.Framework.Screens; + +namespace fluXis.Game.Screens.Result; + +public partial class Results : FluXisScreen, IKeyBindingHandler +{ + public override float Zoom => 1.2f; + public override float BackgroundDim => 0.75f; + public override float BackgroundBlur => 0.2f; + + public ScoreInfo ComparisonScore { get; set; } + + protected ScoreInfo Score { get; } + protected RealmMap Map { get; } + protected APIUser Player { get; } + + protected DependencyContainer ExtraDependencies { get; set; } + + protected virtual bool PlayEnterAnimation => false; + + public Action OnRestart; + + private ResultsContent content; + private ResultsFooter footer; + + public Results(RealmMap map, ScoreInfo score, APIUser player) + { + Map = map; + Score = score; + Player = player; + } + + [BackgroundDependencyLoader] + private void load() + { + ExtraDependencies.CacheAs(this); + ExtraDependencies.CacheAs(Score); + ExtraDependencies.CacheAs(Map); + ExtraDependencies.CacheAs(Player ?? APIUser.Default); + + InternalChildren = new Drawable[] + { + content = new ResultsContent(CreateRightContent()), + footer = new ResultsFooter + { + BackAction = this.Exit, + RestartAction = OnRestart + } + }; + } + + protected virtual Drawable[] CreateRightContent() => Array.Empty(); + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => ExtraDependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + + public override void OnEntering(ScreenTransitionEvent e) + { + this.FadeOut(); + + using (BeginDelayedSequence(ENTER_DELAY)) + { + this.FadeInFromZero(FADE_DURATION); + content.Show(PlayEnterAnimation); + footer.Show(); + } + } + + public override bool OnExiting(ScreenExitEvent e) + { + this.FadeOut(FADE_DURATION); + content.Hide(); + footer.Hide(); + return base.OnExiting(e); + } + + public bool OnPressed(KeyBindingPressEvent e) + { + switch (e.Action) + { + case FluXisGlobalKeybind.Back: + this.Exit(); + return true; + } + + return false; + } + + public void OnReleased(KeyBindingReleaseEvent e) { } +} diff --git a/fluXis.Game/Screens/Result/ResultsContent.cs b/fluXis.Game/Screens/Result/ResultsContent.cs index caa38b59..50a27748 100644 --- a/fluXis.Game/Screens/Result/ResultsContent.cs +++ b/fluXis.Game/Screens/Result/ResultsContent.cs @@ -14,7 +14,7 @@ namespace fluXis.Game.Screens.Result; public partial class ResultsContent : CompositeDrawable { [Resolved] - private SoloResults screen { get; set; } + private Results screen { get; set; } [Resolved] private SkinManager skins { get; set; } @@ -22,6 +22,8 @@ public partial class ResultsContent : CompositeDrawable [Resolved] private ScoreInfo score { get; set; } + private Drawable[] rightContent; + private bool rankMoveSmoothly; private bool rankUseCenter; @@ -31,6 +33,11 @@ public partial class ResultsContent : CompositeDrawable private ResultsCenter center; private ResultsSideList right; + public ResultsContent(Drawable[] rightContent) + { + this.rightContent = rightContent; + } + [BackgroundDependencyLoader] private void load(SkinManager skins) { @@ -86,10 +93,7 @@ private void load(SkinManager skins) center = new ResultsCenter(), right = new ResultsSideList { - Children = new Drawable[] - { - new ResultsSideRankings(screen.SubmitRequest) - } + Children = rightContent } } } diff --git a/fluXis.Game/Screens/Result/SoloResults.cs b/fluXis.Game/Screens/Result/SoloResults.cs index e1825290..368ca2f1 100644 --- a/fluXis.Game/Screens/Result/SoloResults.cs +++ b/fluXis.Game/Screens/Result/SoloResults.cs @@ -1,99 +1,32 @@ -using System; -using fluXis.Game.Database.Maps; -using fluXis.Game.Input; +using fluXis.Game.Database.Maps; using fluXis.Game.Online.API.Requests.Scores; -using fluXis.Game.Screens.Gameplay; +using fluXis.Game.Screens.Result.Sides.Types; using fluXis.Shared.Components.Users; using fluXis.Shared.Scoring; using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Input.Bindings; -using osu.Framework.Input.Events; -using osu.Framework.Screens; namespace fluXis.Game.Screens.Result; -public partial class SoloResults : FluXisScreen, IKeyBindingHandler +public partial class SoloResults : Results { - public override float Zoom => 1.2f; - public override float BackgroundDim => 0.75f; - public override float BackgroundBlur => 0.2f; + protected override bool PlayEnterAnimation => true; - public bool ForceFromGameplay { get; init; } - - public ScoreInfo Score { get; } - public RealmMap Map { get; } - public APIUser Player { get; } - - public ScoreInfo ComparisonScore { get; set; } public ScoreSubmitRequest SubmitRequest { get; set; } - private DependencyContainer dependencies; - - public Action OnRestart; - - private ResultsContent content; - private ResultsFooter footer; - public SoloResults(RealmMap map, ScoreInfo score, APIUser player) + : base(map, score, player) { - Map = map; - Score = score; - Player = player; } [BackgroundDependencyLoader] private void load() { - dependencies.CacheAs(this); - dependencies.CacheAs(Score); - dependencies.CacheAs(Map); - dependencies.CacheAs(Player ?? APIUser.Default); - - InternalChildren = new Drawable[] - { - content = new ResultsContent(), - footer = new ResultsFooter - { - BackAction = this.Exit, - RestartAction = OnRestart - } - }; + ExtraDependencies.CacheAs(this); } - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - - public override void OnEntering(ScreenTransitionEvent e) + protected override Drawable[] CreateRightContent() => new Drawable[] { - this.FadeOut(); - - using (BeginDelayedSequence(ENTER_DELAY)) - { - this.FadeInFromZero(FADE_DURATION); - content.Show(e.Last is GameplayScreen || ForceFromGameplay); - footer.Show(); - } - } - - public override bool OnExiting(ScreenExitEvent e) - { - this.FadeOut(FADE_DURATION); - content.Hide(); - footer.Hide(); - return base.OnExiting(e); - } - - public bool OnPressed(KeyBindingPressEvent e) - { - switch (e.Action) - { - case FluXisGlobalKeybind.Back: - this.Exit(); - return true; - } - - return false; - } - - public void OnReleased(KeyBindingReleaseEvent e) { } + new ResultsSideRankings(SubmitRequest) + }; }