diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs b/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs index 7fd7a15..08c3473 100644 --- a/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs +++ b/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs @@ -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(); diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculator.cs b/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculator.cs index 6eda314..b9f9bb8 100644 --- a/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculator.cs +++ b/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculator.cs @@ -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; diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculatorType.cs b/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculatorType.cs new file mode 100644 index 0000000..5df9415 --- /dev/null +++ b/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculatorType.cs @@ -0,0 +1,25 @@ +using System; + +namespace Osu.Patcher.Hook.Patches.LivePerformance; + +/// +/// The type of performance counter display to show in UI. +/// +[Serializable] +public enum PerformanceCalculatorType +{ + /// + /// Use Bancho pp calculations. + /// + Bancho, + + /// + /// Use Akatsuki pp calculations. + /// + Akatsuki, + + /// + /// Use Akatsuki pp calculations when either Relax or Autopilot is enabled, and Bancho otherwise. + /// + AkatsukiLimited, +} \ No newline at end of file diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceOptions.cs b/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceOptions.cs new file mode 100644 index 0000000..2df0263 --- /dev/null +++ b/Osu.Patcher.Hook/Patches/LivePerformance/PerformanceOptions.cs @@ -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 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 ShowPerformanceInGame = + new(BindableType.Bool, false, Settings.Default.ShowPerformanceInGame); + + public static readonly BindableWrapper ShowPerformanceOnLeaderboard = + new(BindableType.Bool, false, Settings.Default.ShowPerformanceOnLeaderboard); + + public static readonly BindableWrapper PerformanceType = new( + BindableType.Object, + Settings.Default.PerformanceCalculator, + Settings.Default.PerformanceCalculator + ); + + #endregion +} \ No newline at end of file diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/TrackOnScoreHit.cs b/Osu.Patcher.Hook/Patches/LivePerformance/TrackOnScoreHit.cs index be60d0e..ab2c151 100644 --- a/Osu.Patcher.Hook/Patches/LivePerformance/TrackOnScoreHit.cs +++ b/Osu.Patcher.Hook/Patches/LivePerformance/TrackOnScoreHit.cs @@ -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!"); diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/TrackResetScore.cs b/Osu.Patcher.Hook/Patches/LivePerformance/TrackResetScore.cs index 99ce404..2d2a176 100644 --- a/Osu.Patcher.Hook/Patches/LivePerformance/TrackResetScore.cs +++ b/Osu.Patcher.Hook/Patches/LivePerformance/TrackResetScore.cs @@ -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(); + } } \ No newline at end of file diff --git a/Osu.Patcher.Hook/Settings.cs b/Osu.Patcher.Hook/Settings.cs index 2e05370..c9af18c 100644 --- a/Osu.Patcher.Hook/Settings.cs +++ b/Osu.Patcher.Hook/Settings.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Xml.Serialization; +using Osu.Patcher.Hook.Patches.LivePerformance; namespace Osu.Patcher.Hook; @@ -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 } \ No newline at end of file