Skip to content

Commit

Permalink
Merge pull request #20488 from nanashi-1/toggle-score-overlay
Browse files Browse the repository at this point in the history
Add toggle for solo gameplay leaderboard
  • Loading branch information
smoogipoo authored Sep 27, 2022
2 parents aa3956c + 0296685 commit 5a28174
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
Expand All @@ -24,6 +25,16 @@ public class TestSceneSoloGameplayLeaderboard : OsuTestScene

private readonly BindableList<ScoreInfo> scores = new BindableList<ScoreInfo>();

private readonly Bindable<bool> configVisibility = new Bindable<bool>();

private SoloGameplayLeaderboard leaderboard = null!;

[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.GameplayLeaderboard, configVisibility);
}

[SetUpSteps]
public void SetUpSteps()
{
Expand All @@ -37,11 +48,12 @@ public void SetUpSteps()
Id = 2,
};

Child = new SoloGameplayLeaderboard(trackingUser)
Child = leaderboard = new SoloGameplayLeaderboard(trackingUser)
{
Scores = { BindTarget = scores },
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AlwaysVisible = { Value = false },
Expanded = { Value = true },
};
});
Expand All @@ -57,6 +69,22 @@ public void TestLocalUser()
AddSliderStep("combo", 0, 1000, 0, v => scoreProcessor.Combo.Value = v);
}

[Test]
public void TestVisibility()
{
AddStep("set config visible true", () => configVisibility.Value = true);
AddUntilStep("leaderboard visible", () => leaderboard.Alpha == 1);

AddStep("set config visible false", () => configVisibility.Value = false);
AddUntilStep("leaderboard not visible", () => leaderboard.Alpha == 0);

AddStep("set always visible", () => leaderboard.AlwaysVisible.Value = true);
AddUntilStep("leaderboard visible", () => leaderboard.Alpha == 1);

AddStep("set config visible true", () => configVisibility.Value = true);
AddAssert("leaderboard still visible", () => leaderboard.Alpha == 1);
}

private static List<ScoreInfo> createSampleScores()
{
return new[]
Expand Down
2 changes: 2 additions & 0 deletions osu.Game/Configuration/OsuConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected override void InitialiseDefaults()
SetDefault(OsuSetting.ShowHealthDisplayWhenCantFail, true);
SetDefault(OsuSetting.FadePlayfieldWhenHealthLow, true);
SetDefault(OsuSetting.KeyOverlay, false);
SetDefault(OsuSetting.GameplayLeaderboard, true);
SetDefault(OsuSetting.AlwaysPlayFirstComboBreak, true);

SetDefault(OsuSetting.FloatingComments, false);
Expand Down Expand Up @@ -294,6 +295,7 @@ public enum OsuSetting
LightenDuringBreaks,
ShowStoryboard,
KeyOverlay,
GameplayLeaderboard,
PositionalHitsounds,
PositionalHitsoundsLevel,
AlwaysPlayFirstComboBreak,
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/Localisation/GameplaySettingsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public static class GameplaySettingsStrings
/// </summary>
public static LocalisableString AlwaysShowKeyOverlay => new TranslatableString(getKey(@"key_overlay"), @"Always show key overlay");

/// <summary>
/// "Always show gameplay leaderboard"
/// </summary>
public static LocalisableString AlwaysShowGameplayLeaderboard => new TranslatableString(getKey(@"gameplay_leaderboard"), @"Always show gameplay leaderboard");

/// <summary>
/// "Always play first combo break sound"
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/Overlays/Settings/Sections/Gameplay/HUDSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ private void load(OsuConfigManager config)
Current = config.GetBindable<bool>(OsuSetting.KeyOverlay),
Keywords = new[] { "counter" },
},
new SettingsCheckbox
{
LabelText = GameplaySettingsStrings.AlwaysShowGameplayLeaderboard,
Current = config.GetBindable<bool>(OsuSetting.GameplayLeaderboard),
},
};
}
}
Expand Down
26 changes: 26 additions & 0 deletions osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Users;
Expand All @@ -13,6 +15,9 @@ namespace osu.Game.Screens.Play.HUD
{
public class SoloGameplayLeaderboard : GameplayLeaderboard
{
private const int duration = 100;

private readonly Bindable<bool> configVisibility = new Bindable<bool>();
private readonly IUser trackingUser;

public readonly IBindableList<ScoreInfo> Scores = new BindableList<ScoreInfo>();
Expand All @@ -26,15 +31,33 @@ public class SoloGameplayLeaderboard : GameplayLeaderboard
[Resolved]
private ScoreManager scoreManager { get; set; } = null!;

/// <summary>
/// Whether the leaderboard should be visible regardless of the configuration value.
/// This is true by default, but can be changed.
/// </summary>
public readonly Bindable<bool> AlwaysVisible = new Bindable<bool>(true);

public SoloGameplayLeaderboard(IUser trackingUser)
{
this.trackingUser = trackingUser;
}

[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.GameplayLeaderboard, configVisibility);
}

protected override void LoadComplete()
{
base.LoadComplete();
Scores.BindCollectionChanged((_, _) => Scheduler.AddOnce(showScores), true);

// Alpha will be updated via `updateVisibility` below.
Alpha = 0;

AlwaysVisible.BindValueChanged(_ => updateVisibility());
configVisibility.BindValueChanged(_ => updateVisibility(), true);
}

private void showScores()
Expand Down Expand Up @@ -69,5 +92,8 @@ private void showScores()
// Local score should always show lower than any existing scores in cases of ties.
local.DisplayOrder.Value = long.MaxValue;
}

private void updateVisibility() =>
this.FadeTo(AlwaysVisible.Value || configVisibility.Value ? 1 : 0, duration);
}
}
1 change: 1 addition & 0 deletions osu.Game/Screens/Play/KeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public KeyCounterDisplay()
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Alpha = 0,
};
}

Expand Down
1 change: 1 addition & 0 deletions osu.Game/Screens/Play/ReplayPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected override void PrepareReplay()
protected override GameplayLeaderboard CreateGameplayLeaderboard() =>
new SoloGameplayLeaderboard(Score.ScoreInfo.User)
{
AlwaysVisible = { Value = true },
Scores = { BindTarget = LeaderboardScores }
};

Expand Down
1 change: 1 addition & 0 deletions osu.Game/Screens/Play/SoloPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected override APIRequest<APIScoreToken> CreateTokenRequest()
protected override GameplayLeaderboard CreateGameplayLeaderboard() =>
new SoloGameplayLeaderboard(Score.ScoreInfo.User)
{
AlwaysVisible = { Value = false },
Scores = { BindTarget = LeaderboardScores }
};

Expand Down

0 comments on commit 5a28174

Please sign in to comment.