Skip to content

Commit

Permalink
Make Results a base class
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Sep 8, 2024
1 parent 587d1dd commit 32c641d
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 92 deletions.
12 changes: 3 additions & 9 deletions fluXis.Game.Tests/Screens/TestResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,14 @@ private RealmMap getMap()
Mods = new List<string> { "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) }));
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fluXis.Game/FluXisGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fluXis.Game/Screens/Result/Center/ResultsCenterScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
98 changes: 98 additions & 0 deletions fluXis.Game/Screens/Result/Results.cs
Original file line number Diff line number Diff line change
@@ -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<FluXisGlobalKeybind>
{
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<Drawable>();

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<FluXisGlobalKeybind> e)
{
switch (e.Action)
{
case FluXisGlobalKeybind.Back:
this.Exit();
return true;
}

return false;
}

public void OnReleased(KeyBindingReleaseEvent<FluXisGlobalKeybind> e) { }
}
14 changes: 9 additions & 5 deletions fluXis.Game/Screens/Result/ResultsContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ 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; }

[Resolved]
private ScoreInfo score { get; set; }

private Drawable[] rightContent;

private bool rankMoveSmoothly;
private bool rankUseCenter;

Expand All @@ -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)
{
Expand Down Expand Up @@ -86,10 +93,7 @@ private void load(SkinManager skins)
center = new ResultsCenter(),
right = new ResultsSideList
{
Children = new Drawable[]
{
new ResultsSideRankings(screen.SubmitRequest)
}
Children = rightContent
}
}
}
Expand Down
85 changes: 9 additions & 76 deletions fluXis.Game/Screens/Result/SoloResults.cs
Original file line number Diff line number Diff line change
@@ -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<FluXisGlobalKeybind>
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<FluXisGlobalKeybind> e)
{
switch (e.Action)
{
case FluXisGlobalKeybind.Back:
this.Exit();
return true;
}

return false;
}

public void OnReleased(KeyBindingReleaseEvent<FluXisGlobalKeybind> e) { }
new ResultsSideRankings(SubmitRequest)
};
}

0 comments on commit 32c641d

Please sign in to comment.