Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(LivePerformance): add pp options #12

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private static void After(
[HarmonyArgument(3)] float scale
)
{
if (!PerformanceOptions.ShowPerformanceInGame.Value)
return;

Debug.WriteLine("Adding Performance Counter to ScoreDisplay", nameof(AddPerformanceToUi));

var currentSkin = SkinManager.Current.Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Osu.Patcher.Hook.Patches.LivePerformance;
internal static class PerformanceCalculator
{
private static readonly Obfuscated ObfuscatedModsStub = new(Stubs.Root.Mods.Type.Reference);

public static OsuPerformance? Calculator { get; private set; }

public static bool IsInitialized => Calculator != null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Osu.Patcher.Hook.Patches.LivePerformance;

/// <summary>
/// The type of performance counter display to show in UI.
/// </summary>
[Serializable]
public enum PerformanceCalculatorType
{
/// <summary>
/// Use Bancho pp calculations.
/// </summary>
Bancho,

/// <summary>
/// Use Akatsuki pp calculations.
/// </summary>
Akatsuki,

/// <summary>
/// Use Akatsuki pp calculations when either Relax or Autopilot is enabled, and Bancho otherwise.
/// </summary>
AkatsukiLimited,
}
90 changes: 90 additions & 0 deletions Osu.Patcher.Hook/Patches/LivePerformance/PerformanceOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Osu.Stubs.GameModes.Options;
using Osu.Stubs.Graphics;
using Osu.Stubs.Wrappers;
using Osu.Utils.Extensions;
using static Osu.Patcher.Hook.Patches.CustomStrings.CustomStrings;

namespace Osu.Patcher.Hook.Patches.LivePerformance;

[UsedImplicitly]
internal class PerformanceOptions : PatchOptions
{
private static readonly OptionDropdown OptionDropdownStub = new(typeof(PerformanceCalculatorType));

public override IEnumerable<object> CreateOptions() =>
[
CreateInGameDisplayOption(),
CreateLeaderboardDisplayOption(),
CreatePerformanceTypeOption(),
];

public override void Load(Settings config)
{
ShowPerformanceInGame.Value = config.ShowPerformanceInGame;
ShowPerformanceOnLeaderboard.Value = config.ShowPerformanceOnLeaderboard;
PerformanceType.Value = config.PerformanceCalculator;
}

public override void Save(Settings config)
{
config.ShowPerformanceInGame = ShowPerformanceInGame.Value;
config.ShowPerformanceOnLeaderboard = ShowPerformanceOnLeaderboard.Value;
config.PerformanceCalculator = PerformanceType.Value;
}

#region Options Creation

private static object CreateInGameDisplayOption() => OptionCheckbox.Constructor.Invoke([
/* title: */ "Show PP during gameplay",
/* tooltip: */ "A small PP counter display will be visible below the accuracy display.",
/* binding: */ ShowPerformanceInGame.Bindable,
/* onChange: */ null,
]);

private static object CreateLeaderboardDisplayOption() => OptionCheckbox.Constructor.Invoke([
/* title: */ "Show PP on local leaderboards",
/* tooltip: */ "A small PP counter display will be visible on each local score.",
/* binding: */ ShowPerformanceOnLeaderboard.Bindable,
/* onChange: */ null,
]);

private static object CreatePerformanceTypeOption()
{
var dropdownOptions = new[]
{
pDropdownItem.Constructor.Invoke(["Bancho", PerformanceCalculatorType.Bancho]),
pDropdownItem.Constructor.Invoke(["Akatsuki", PerformanceCalculatorType.Akatsuki]),
pDropdownItem.Constructor.Invoke([
"Akatsuki if RX/AP else Bancho",
PerformanceCalculatorType.AkatsukiLimited,
]),
}.ToType(pDropdownItem.Class.Reference);

return OptionDropdownStub.Constructor.Invoke([
/* title: */ AddOsuString("PatcherPerformance", "PP calculator"),
/* items: */ dropdownOptions,
/* bindable: */ PerformanceType.Bindable,
/* onChange: */ null,
]);
}

#endregion

#region Bindables

public static readonly BindableWrapper<bool> ShowPerformanceInGame =
new(BindableType.Bool, false, Settings.Default.ShowPerformanceInGame);

public static readonly BindableWrapper<bool> ShowPerformanceOnLeaderboard =
new(BindableType.Bool, false, Settings.Default.ShowPerformanceOnLeaderboard);

public static readonly BindableWrapper<PerformanceCalculatorType> PerformanceType = new(
BindableType.Object,
Settings.Default.PerformanceCalculator,
Settings.Default.PerformanceCalculator
);

#endregion
}
3 changes: 3 additions & 0 deletions Osu.Patcher.Hook/Patches/LivePerformance/TrackOnScoreHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ private static void After(
[HarmonyArgument(0)] int increaseScoreType,
[HarmonyArgument(2)] bool increaseCombo)
{
if (!PerformanceOptions.ShowPerformanceInGame.Value)
return;

if (!PerformanceCalculator.IsInitialized)
{
Debug.Fail("OnIncreaseScoreHit called before performance calculator initialized!");
Expand Down
8 changes: 7 additions & 1 deletion Osu.Patcher.Hook/Patches/LivePerformance/TrackResetScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ internal static class TrackResetScore

[UsedImplicitly]
[HarmonyPostfix]
private static void After() => PerformanceCalculator.ResetCalculator();
private static void After()
{
if (!PerformanceOptions.ShowPerformanceInGame.Value)
return;

PerformanceCalculator.ResetCalculator();
}
}
4 changes: 4 additions & 0 deletions Osu.Patcher.Hook/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using Osu.Patcher.Hook.Patches.LivePerformance;

namespace Osu.Patcher.Hook;

Expand Down Expand Up @@ -71,6 +72,9 @@ public static void WriteToDisk(Settings settings, string osuDir)
#region Options

public bool EnableModAudioPreview { get; set; } = true;
public bool ShowPerformanceInGame { get; set; } = true;
public bool ShowPerformanceOnLeaderboard { get; set; } = true;
public PerformanceCalculatorType PerformanceCalculator { get; set; } = PerformanceCalculatorType.AkatsukiLimited;

#endregion
}
Loading