1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 04:52:57 +08:00

Merge branch 'master' into scorev2

This commit is contained in:
Dean Herbert 2023-05-30 14:34:43 +09:00
commit 14a376c041
7 changed files with 166 additions and 42 deletions

View File

@ -0,0 +1,69 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;
namespace osu.Game.Tests.Visual.Mods
{
public partial class TestSceneModAccuracyChallenge : ModTestScene
{
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
protected override TestPlayer CreateModPlayer(Ruleset ruleset)
{
var player = base.CreateModPlayer(ruleset);
return player;
}
protected override bool AllowFail => true;
[Test]
public void TestMaximumAchievableAccuracy() =>
CreateModTest(new ModTestData
{
Mod = new ModAccuracyChallenge
{
MinimumAccuracy = { Value = 0.6 }
},
Autoplay = false,
Beatmap = new Beatmap
{
HitObjects = Enumerable.Range(0, 5).Select(i => new HitCircle
{
StartTime = i * 250,
Position = new Vector2(i * 50)
}).Cast<HitObject>().ToList()
},
PassCondition = () => Player.GameplayState.HasFailed && Player.ScoreProcessor.JudgedHits >= 3
});
[Test]
public void TestStandardAccuracy() =>
CreateModTest(new ModTestData
{
Mod = new ModAccuracyChallenge
{
MinimumAccuracy = { Value = 0.6 },
AccuracyJudgeMode = { Value = ModAccuracyChallenge.AccuracyMode.Standard }
},
Autoplay = false,
Beatmap = new Beatmap
{
HitObjects = Enumerable.Range(0, 5).Select(i => new HitCircle
{
StartTime = i * 250,
Position = new Vector2(i * 50)
}).Cast<HitObject>().ToList()
},
PassCondition = () => Player.GameplayState.HasFailed && Player.ScoreProcessor.JudgedHits >= 1
});
}
}

View File

@ -89,14 +89,16 @@ namespace osu.Game.Graphics.UserInterface
double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo);
if (DisplayAsPercentage)
return floatValue.ToString("0%");
decimal decimalPrecision = normalise(CurrentNumber.Precision.ToDecimal(NumberFormatInfo.InvariantInfo), max_decimal_digits);
// Find the number of significant digits (we could have less than 5 after normalize())
int significantDigits = FormatUtils.FindPrecision(decimalPrecision);
if (DisplayAsPercentage)
{
return floatValue.ToString($@"P{Math.Max(0, significantDigits - 2)}");
}
string negativeSign = Math.Round(floatValue, significantDigits) < 0 ? "-" : string.Empty;
return $"{negativeSign}{Math.Abs(floatValue).ToString($"N{significantDigits}")}";

View File

@ -0,0 +1,49 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Localisation;
namespace osu.Game.Localisation
{
public static class GameplayMenuOverlayStrings
{
private const string prefix = @"osu.Game.Resources.Localisation.GameplayMenuOverlay";
/// <summary>
/// "Continue"
/// </summary>
public static LocalisableString Continue => new TranslatableString(getKey(@"continue"), @"Continue");
/// <summary>
/// "Retry"
/// </summary>
public static LocalisableString Retry => new TranslatableString(getKey(@"retry"), @"Retry");
/// <summary>
/// "Quit"
/// </summary>
public static LocalisableString Quit => new TranslatableString(getKey(@"quit"), @"Quit");
/// <summary>
/// "failed"
/// </summary>
public static LocalisableString FailedHeader => new TranslatableString(getKey(@"failed_header"), @"failed");
/// <summary>
/// "paused"
/// </summary>
public static LocalisableString PausedHeader => new TranslatableString(getKey(@"paused_header"), @"paused");
/// <summary>
/// "Retry count: "
/// </summary>
public static LocalisableString RetryCount => new TranslatableString(getKey(@"retry_count"), @"Retry count: ");
/// <summary>
/// "Song progress: "
/// </summary>
public static LocalisableString SongProgress => new TranslatableString(getKey(@"song_progress"), @"Song progress: ");
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Localisation.HUD;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Judgements;
@ -42,47 +43,44 @@ namespace osu.Game.Rulesets.Mods
Value = 0.9,
};
private int baseScore;
private int maxBaseScore;
[SettingSource("Accuracy mode", "The mode of accuracy that will trigger failure.")]
public Bindable<AccuracyMode> AccuracyJudgeMode { get; } = new Bindable<AccuracyMode>();
private readonly Bindable<double> currentAccuracy = new Bindable<double>();
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
{
scoreProcessor.NewJudgement += j =>
switch (AccuracyJudgeMode.Value)
{
if (!j.Type.AffectsAccuracy())
return;
case AccuracyMode.Standard:
currentAccuracy.BindTo(scoreProcessor.Accuracy);
break;
baseScore += Judgement.ToNumericResult(j.Type);
maxBaseScore += Judgement.ToNumericResult(j.Judgement.MaxResult);
};
case AccuracyMode.MaximumAchievable:
currentAccuracy.BindTo(scoreProcessor.MaximumAccuracy);
break;
}
scoreProcessor.JudgementReverted += j =>
currentAccuracy.BindValueChanged(s =>
{
if (!j.Type.AffectsAccuracy())
return;
baseScore -= Judgement.ToNumericResult(j.Type);
maxBaseScore -= Judgement.ToNumericResult(j.Judgement.MaxResult);
};
if (s.NewValue < MinimumAccuracy.Value)
{
TriggerFailure();
}
});
}
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
protected override bool FailCondition(HealthProcessor healthProcessor, JudgementResult result)
protected override bool FailCondition(HealthProcessor healthProcessor, JudgementResult result) => false;
public enum AccuracyMode
{
if (!result.Type.AffectsAccuracy())
return false;
[LocalisableDescription(typeof(GameplayAccuracyCounterStrings), nameof(GameplayAccuracyCounterStrings.AccuracyDisplayModeMax))]
MaximumAchievable,
return getAccuracyWithImminentResultAdded(result) < MinimumAccuracy.Value;
}
private double getAccuracyWithImminentResultAdded(JudgementResult result)
{
// baseScore and maxBaseScore are always exactly one judgement behind because the health processor is processed first (see: Player).
int imminentBaseScore = baseScore + Judgement.ToNumericResult(result.Type);
int imminentMaxBaseScore = maxBaseScore + Judgement.ToNumericResult(result.Judgement.MaxResult);
return imminentMaxBaseScore > 0 ? imminentBaseScore / (double)imminentMaxBaseScore : 1;
[LocalisableDescription(typeof(GameplayAccuracyCounterStrings), nameof(GameplayAccuracyCounterStrings.AccuracyDisplayModeStandard))]
Standard,
}
}
}

View File

@ -15,6 +15,8 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Localisation;
namespace osu.Game.Screens.Play
{
@ -22,13 +24,13 @@ namespace osu.Game.Screens.Play
{
public Func<Task<ScoreInfo>> SaveReplay;
public override string Header => "failed";
public override LocalisableString Header => GameplayMenuOverlayStrings.FailedHeader;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
// from #10339 maybe this is a better visual effect
Add(new Container
{

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
@ -20,6 +21,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osuTK;
using osuTK.Graphics;
using osu.Game.Localisation;
namespace osu.Game.Screens.Play
{
@ -49,7 +51,7 @@ namespace osu.Game.Screens.Play
/// </summary>
protected virtual Action SelectAction => () => InternalButtons.Selected?.TriggerClick();
public abstract string Header { get; }
public abstract LocalisableString Header { get; }
protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons = null!;
public IReadOnlyList<DialogButton> Buttons => InternalButtons;
@ -153,7 +155,7 @@ namespace osu.Game.Screens.Play
protected override bool OnMouseMove(MouseMoveEvent e) => true;
protected void AddButton(string text, Color4 colour, Action? action)
protected void AddButton(LocalisableString text, Color4 colour, Action? action)
{
var button = new Button
{
@ -209,13 +211,13 @@ namespace osu.Game.Screens.Play
private void updateInfoText()
{
playInfoText.Clear();
playInfoText.AddText("Retry count: ");
playInfoText.AddText(GameplayMenuOverlayStrings.RetryCount);
playInfoText.AddText(retries.ToString(), cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
if (getSongProgress() is int progress)
{
playInfoText.NewLine();
playInfoText.AddText("Song progress: ");
playInfoText.AddText(GameplayMenuOverlayStrings.SongProgress);
playInfoText.AddText($"{progress}%", cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
}
}

View File

@ -9,9 +9,11 @@ using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -23,7 +25,7 @@ namespace osu.Game.Screens.Play
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
public override string Header => "paused";
public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
private SkinnableSound pauseLoop;
@ -32,9 +34,9 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddButton("Continue", colours.Green, () => OnResume?.Invoke());
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume?.Invoke());
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
{