Skip to content

Commit

Permalink
Merge branch 'grids' of https://github.com/OliBomby/osu into grids
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Oct 11, 2024
2 parents a236866 + 852959d commit 546910c
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 43 deletions.
10 changes: 6 additions & 4 deletions osu.Desktop/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,12 @@ private static string clampLength(string str)

// As above, discord decides that *non-empty* strings shorter than 2 characters cannot possibly be valid input, because... reasons?
// And yes, that is two *characters*, or *codepoints*, not *bytes* as further down below (as determined by empirical testing).
// That seems very questionable, and isn't even documented anywhere. So to *make it* accept such valid input,
// just tack on enough of U+200B ZERO WIDTH SPACEs at the end.
if (str.Length < 2)
return str.PadRight(2, '\u200B');
// Also, spaces don't count. Because reasons, clearly.
// That all seems very questionable, and isn't even documented anywhere. So to *make it* accept such valid input,
// just tack on enough of U+200B ZERO WIDTH SPACEs at the end. After making sure to trim whitespace.
string trimmed = str.Trim();
if (trimmed.Length < 2)
return trimmed.PadRight(2, '\u200B');

if (Encoding.UTF8.GetByteCount(str) <= 128)
return str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Rulesets.Osu.Objects;

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, SingleThread)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, SingleThread)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, MultiThreaded)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, MultiThreaded)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, SingleThread)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, SingleThread)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, MultiThreaded)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, MultiThreaded)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check failure on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check warning on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace

Check warning on line 14 in osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The using directive for 'osu.Game.Rulesets.Osu.Objects' appeared previously in this namespace
using osu.Game.Tests.Visual;
using osu.Game.Utils;
using osuTK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private bool splitSelected()

private bool isSplittable(PathControlPointPiece<T> p) =>
// A hit object can only be split on control points which connect two different path segments.
p.ControlPoint.Type.HasValue && p != Pieces.FirstOrDefault() && p != Pieces.LastOrDefault();
p.ControlPoint.Type.HasValue && p.ControlPoint != controlPoints.FirstOrDefault() && p.ControlPoint != controlPoints.LastOrDefault();

private void onControlPointsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Tests/Visual/SongSelect/TestSceneAdvancedStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void TestEasyMod()
AddStep("select EZ mod", () =>
{
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance().AsNonNull();
SelectedMods.Value = new[] { ruleset.CreateMod<ModEasy>() };
advancedStats.Mods.Value = new[] { ruleset.CreateMod<ModEasy>() };
});

AddAssert("circle size bar is blue", () => barIsBlue(advancedStats.FirstValue));
Expand All @@ -101,7 +101,7 @@ public void TestHardRockMod()
AddStep("select HR mod", () =>
{
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance().AsNonNull();
SelectedMods.Value = new[] { ruleset.CreateMod<ModHardRock>() };
advancedStats.Mods.Value = new[] { ruleset.CreateMod<ModHardRock>() };
});

AddAssert("circle size bar is red", () => barIsRed(advancedStats.FirstValue));
Expand All @@ -120,7 +120,7 @@ public void TestUnchangedDifficultyAdjustMod()
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance().AsNonNull();
var difficultyAdjustMod = ruleset.CreateMod<ModDifficultyAdjust>().AsNonNull();
difficultyAdjustMod.ReadFromDifficulty(advancedStats.BeatmapInfo.Difficulty);
SelectedMods.Value = new[] { difficultyAdjustMod };
advancedStats.Mods.Value = new[] { difficultyAdjustMod };
});

AddAssert("circle size bar is white", () => barIsWhite(advancedStats.FirstValue));
Expand All @@ -143,7 +143,7 @@ public void TestChangedDifficultyAdjustMod()
difficultyAdjustMod.ReadFromDifficulty(originalDifficulty);
difficultyAdjustMod.DrainRate.Value = originalDifficulty.DrainRate - 0.5f;
difficultyAdjustMod.ApproachRate.Value = originalDifficulty.ApproachRate + 2.2f;
SelectedMods.Value = new[] { difficultyAdjustMod };
advancedStats.Mods.Value = new[] { difficultyAdjustMod };
});

AddAssert("circle size bar is white", () => barIsWhite(advancedStats.FirstValue));
Expand Down
12 changes: 0 additions & 12 deletions osu.Game/Overlays/BeatmapSetOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand All @@ -16,8 +14,6 @@
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Overlays.BeatmapSet.Scores;
using osu.Game.Overlays.Comments;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select.Details;
using osuTK;
using osuTK.Graphics;

Expand All @@ -37,14 +33,6 @@ public partial class BeatmapSetOverlay : OnlineOverlay<BeatmapSetHeader>

private (BeatmapSetLookupType type, int id)? lastLookup;

/// <remarks>
/// Isolates the beatmap set overlay from the game-wide selected mods bindable
/// to avoid affecting the beatmap details section (i.e. <see cref="AdvancedStats.StatisticRow"/>).
/// </remarks>
[Cached]
[Cached(typeof(IBindable<IReadOnlyList<Mod>>))]
protected readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());

public BeatmapSetOverlay()
: base(OverlayColourScheme.Blue)
{
Expand Down
20 changes: 16 additions & 4 deletions osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,25 @@ protected override bool OnKeyDown(KeyDownEvent e)
switch (e.Key)
{
case Key.G:
return CanReverse && reverseButton?.TriggerClick() == true;
if (!CanReverse || reverseButton == null)
return false;

reverseButton.TriggerAction();
return true;

case Key.Comma:
return canRotate.Value && rotateCounterClockwiseButton?.TriggerClick() == true;
if (!canRotate.Value || rotateCounterClockwiseButton == null)
return false;

rotateCounterClockwiseButton.TriggerAction();
return true;

case Key.Period:
return canRotate.Value && rotateClockwiseButton?.TriggerClick() == true;
if (!canRotate.Value || rotateClockwiseButton == null)
return false;

rotateClockwiseButton.TriggerAction();
return true;
}

return base.OnKeyDown(e);
Expand Down Expand Up @@ -285,7 +297,7 @@ private SelectionBoxButton addButton(IconUsage icon, string tooltip, Action acti
Action = action
};

button.OperationStarted += freezeButtonPosition;
button.Clicked += freezeButtonPosition;
button.HoverLost += unfreezeButtonPosition;

button.OperationStarted += operationStarted;
Expand Down
18 changes: 14 additions & 4 deletions osu.Game/Screens/Edit/Compose/Components/SelectionBoxButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed partial class SelectionBoxButton : SelectionBoxControl, IHasToolti

public Action? Action;

public event Action? Clicked;

public event Action? HoverLost;

public SelectionBoxButton(IconUsage iconUsage, string tooltip)
Expand Down Expand Up @@ -49,11 +51,10 @@ private void load()

protected override bool OnClick(ClickEvent e)
{
Circle.FlashColour(Colours.GrayF, 300);
Clicked?.Invoke();

TriggerAction();

TriggerOperationStarted();
Action?.Invoke();
TriggerOperationEnded();
return true;
}

Expand All @@ -71,5 +72,14 @@ protected override void OnHoverLost(HoverLostEvent e)
}

public LocalisableString TooltipText { get; }

public void TriggerAction()
{
Circle.FlashColour(Colours.GrayF, 300);

TriggerOperationStarted();
Action?.Invoke();
TriggerOperationEnded();
}
}
}
3 changes: 3 additions & 0 deletions osu.Game/Screens/Play/HUD/ArgonSongProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public LocalisableString TooltipText
{
get
{
if (!Interactive)
return default;

double progress = Math.Clamp(lastMouseX, 0, DrawWidth) / DrawWidth;

TimeSpan currentSpan = TimeSpan.FromMilliseconds(Math.Round((EndTime - StartTime) * progress));
Expand Down
23 changes: 14 additions & 9 deletions osu.Game/Screens/Select/Details/AdvancedStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#nullable disable

using System;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
Expand Down Expand Up @@ -36,9 +37,6 @@ public partial class AdvancedStats : Container, IHasCustomTooltip<AdjustedAttrib
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; }

[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; }

protected readonly StatisticRow FirstValue, HpDrain, Accuracy, ApproachRate;
private readonly StatisticRow starDifficulty;

Expand Down Expand Up @@ -69,6 +67,14 @@ public IBeatmapInfo BeatmapInfo
/// </remarks>
public Bindable<RulesetInfo> Ruleset { get; } = new Bindable<RulesetInfo>();

/// <summary>
/// Mods to be used for certain elements of display.
/// </summary>
/// <remarks>
/// No checks are done as to whether the mods specified are valid for the current <see cref="Ruleset"/>.
/// </remarks>
public Bindable<IReadOnlyList<Mod>> Mods { get; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());

public AdvancedStats(int columns = 1)
{
switch (columns)
Expand Down Expand Up @@ -143,8 +149,7 @@ protected override void LoadComplete()
base.LoadComplete();

Ruleset.BindValueChanged(_ => updateStatistics());

mods.BindValueChanged(modsChanged, true);
Mods.BindValueChanged(modsChanged, true);
}

private ModSettingChangeTracker modSettingChangeTracker;
Expand Down Expand Up @@ -173,14 +178,14 @@ private void updateStatistics()
{
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(baseDifficulty);

foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
foreach (var mod in Mods.Value.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(originalDifficulty);

adjustedDifficulty = originalDifficulty;

if (Ruleset.Value != null)
{
double rate = ModUtils.CalculateRateWithMods(mods.Value);
double rate = ModUtils.CalculateRateWithMods(Mods.Value);

adjustedDifficulty = Ruleset.Value.CreateInstance().GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);

Expand All @@ -198,7 +203,7 @@ private void updateStatistics()
// For the time being, the key count is static no matter what, because:
// a) The method doesn't have knowledge of the active keymods. Doing so may require considerations for filtering.
// b) Using the difficulty adjustment mod to adjust OD doesn't have an effect on conversion.
int keyCount = baseDifficulty == null ? 0 : legacyRuleset.GetKeyCount(BeatmapInfo, mods.Value);
int keyCount = baseDifficulty == null ? 0 : legacyRuleset.GetKeyCount(BeatmapInfo, Mods.Value);

FirstValue.Title = BeatmapsetsStrings.ShowStatsCsMania;
FirstValue.Value = (keyCount, keyCount);
Expand Down Expand Up @@ -236,7 +241,7 @@ private void updateStarDifficulty() => Scheduler.AddOnce(() =>
starDifficultyCancellationSource = new CancellationTokenSource();

var normalStarDifficultyTask = difficultyCache.GetDifficultyAsync(BeatmapInfo, Ruleset.Value, null, starDifficultyCancellationSource.Token);
var moddedStarDifficultyTask = difficultyCache.GetDifficultyAsync(BeatmapInfo, Ruleset.Value, mods.Value, starDifficultyCancellationSource.Token);
var moddedStarDifficultyTask = difficultyCache.GetDifficultyAsync(BeatmapInfo, Ruleset.Value, Mods.Value, starDifficultyCancellationSource.Token);

Task.WhenAll(normalStarDifficultyTask, moddedStarDifficultyTask).ContinueWith(_ => Schedule(() =>
{
Expand Down
13 changes: 8 additions & 5 deletions osu.Game/Screens/Select/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,6 @@ private void performUpdateSelected()
beatmapInfoPrevious = beatmap;
}

// we can't run this in the debounced run due to the selected mods bindable not being debounced,
// since mods could be updated to the new ruleset instances while the decoupled bindable is held behind,
// therefore resulting in performing difficulty calculation with invalid states.
advancedStats.Ruleset.Value = ruleset;

void run()
{
// clear pending task immediately to track any potential nested debounce operation.
Expand Down Expand Up @@ -878,6 +873,8 @@ private void updateComponentFromBeatmap(WorkingBeatmap beatmap)
ModSelect.Beatmap.Value = beatmap;

advancedStats.BeatmapInfo = beatmap.BeatmapInfo;
advancedStats.Mods.Value = selectedMods.Value;
advancedStats.Ruleset.Value = Ruleset.Value;

bool beatmapSelected = beatmap is not DummyWorkingBeatmap;

Expand Down Expand Up @@ -990,6 +987,12 @@ private void bindBindables()

Beatmap.BindValueChanged(updateCarouselSelection);

selectedMods.BindValueChanged(_ =>
{
if (decoupledRuleset.Value.Equals(rulesetNoDebounce))
advancedStats.Mods.Value = selectedMods.Value;
}, true);

boundLocalBindables = true;
}

Expand Down

0 comments on commit 546910c

Please sign in to comment.