mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Merge branch 'master' into notification-fling
This commit is contained in:
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
@ -19,14 +20,24 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
|
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
|
||||||
{
|
{
|
||||||
private HitEventTimingDistributionGraph graph = null!;
|
private HitEventTimingDistributionGraph graph = null!;
|
||||||
|
private readonly BindableFloat width = new BindableFloat(600);
|
||||||
|
private readonly BindableFloat height = new BindableFloat(130);
|
||||||
|
|
||||||
private static readonly HitObject placeholder_object = new HitCircle();
|
private static readonly HitObject placeholder_object = new HitCircle();
|
||||||
|
|
||||||
|
public TestSceneHitEventTimingDistributionGraph()
|
||||||
|
{
|
||||||
|
width.BindValueChanged(e => graph.Width = e.NewValue);
|
||||||
|
height.BindValueChanged(e => graph.Height = e.NewValue);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestManyDistributedEvents()
|
public void TestManyDistributedEvents()
|
||||||
{
|
{
|
||||||
createTest(CreateDistributedHitEvents());
|
createTest(CreateDistributedHitEvents());
|
||||||
AddStep("add adjustment", () => graph.UpdateOffset(10));
|
AddStep("add adjustment", () => graph.UpdateOffset(10));
|
||||||
|
AddSliderStep("width", 0.0f, 1000.0f, width.Value, width.Set);
|
||||||
|
AddSliderStep("height", 0.0f, 1000.0f, height.Value, height.Set);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -137,7 +148,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(600, 130)
|
Size = new Vector2(width.Value, height.Value)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
using System.Diagnostics;
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -13,6 +12,7 @@ using osu.Framework.Platform;
|
|||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.Select.Carousel;
|
using osu.Game.Screens.Select.Carousel;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
@ -22,10 +22,10 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
{
|
{
|
||||||
public class TestSceneTopLocalRank : OsuTestScene
|
public class TestSceneTopLocalRank : OsuTestScene
|
||||||
{
|
{
|
||||||
private RulesetStore rulesets;
|
private RulesetStore rulesets = null!;
|
||||||
private BeatmapManager beatmapManager;
|
private BeatmapManager beatmapManager = null!;
|
||||||
private ScoreManager scoreManager;
|
private ScoreManager scoreManager = null!;
|
||||||
private TopLocalRank topLocalRank;
|
private TopLocalRank topLocalRank = null!;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host, AudioManager audio)
|
private void load(GameHost host, AudioManager audio)
|
||||||
@ -47,21 +47,21 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
AddStep("Create local rank", () =>
|
AddStep("Create local rank", () =>
|
||||||
{
|
{
|
||||||
Add(topLocalRank = new TopLocalRank(importedBeatmap)
|
Child = topLocalRank = new TopLocalRank(importedBeatmap)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Scale = new Vector2(10),
|
Scale = new Vector2(10),
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
AddAssert("No rank displayed initially", () => topLocalRank.DisplayedRank == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBasicImportDelete()
|
public void TestBasicImportDelete()
|
||||||
{
|
{
|
||||||
ScoreInfo testScoreInfo = null;
|
ScoreInfo testScoreInfo = null!;
|
||||||
|
|
||||||
AddAssert("Initially not present", () => !topLocalRank.IsPresent);
|
|
||||||
|
|
||||||
AddStep("Add score for current user", () =>
|
AddStep("Add score for current user", () =>
|
||||||
{
|
{
|
||||||
@ -73,25 +73,19 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
scoreManager.Import(testScoreInfo);
|
scoreManager.Import(testScoreInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("Became present", () => topLocalRank.IsPresent);
|
AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
|
||||||
AddAssert("Correct rank", () => topLocalRank.Rank == ScoreRank.B);
|
|
||||||
|
|
||||||
AddStep("Delete score", () =>
|
AddStep("Delete score", () => scoreManager.Delete(testScoreInfo));
|
||||||
{
|
|
||||||
scoreManager.Delete(testScoreInfo);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddUntilStep("Became not present", () => !topLocalRank.IsPresent);
|
AddUntilStep("No rank displayed", () => topLocalRank.DisplayedRank == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestRulesetChange()
|
public void TestRulesetChange()
|
||||||
{
|
{
|
||||||
ScoreInfo testScoreInfo;
|
|
||||||
|
|
||||||
AddStep("Add score for current user", () =>
|
AddStep("Add score for current user", () =>
|
||||||
{
|
{
|
||||||
testScoreInfo = TestResources.CreateTestScoreInfo(importedBeatmap);
|
var testScoreInfo = TestResources.CreateTestScoreInfo(importedBeatmap);
|
||||||
|
|
||||||
testScoreInfo.User = API.LocalUser.Value;
|
testScoreInfo.User = API.LocalUser.Value;
|
||||||
testScoreInfo.Rank = ScoreRank.B;
|
testScoreInfo.Rank = ScoreRank.B;
|
||||||
@ -99,25 +93,21 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
scoreManager.Import(testScoreInfo);
|
scoreManager.Import(testScoreInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("Wait for initial presence", () => topLocalRank.IsPresent);
|
AddUntilStep("Wait for initial display", () => topLocalRank.DisplayedRank == ScoreRank.B);
|
||||||
|
|
||||||
AddStep("Change ruleset", () => Ruleset.Value = rulesets.GetRuleset("fruits"));
|
AddStep("Change ruleset", () => Ruleset.Value = rulesets.GetRuleset("fruits"));
|
||||||
AddUntilStep("Became not present", () => !topLocalRank.IsPresent);
|
AddUntilStep("No rank displayed", () => topLocalRank.DisplayedRank == null);
|
||||||
|
|
||||||
AddStep("Change ruleset back", () => Ruleset.Value = rulesets.GetRuleset("osu"));
|
AddStep("Change ruleset back", () => Ruleset.Value = rulesets.GetRuleset("osu"));
|
||||||
AddUntilStep("Became present", () => topLocalRank.IsPresent);
|
AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestHigherScoreSet()
|
public void TestHigherScoreSet()
|
||||||
{
|
{
|
||||||
ScoreInfo testScoreInfo = null;
|
|
||||||
|
|
||||||
AddAssert("Initially not present", () => !topLocalRank.IsPresent);
|
|
||||||
|
|
||||||
AddStep("Add score for current user", () =>
|
AddStep("Add score for current user", () =>
|
||||||
{
|
{
|
||||||
testScoreInfo = TestResources.CreateTestScoreInfo(importedBeatmap);
|
var testScoreInfo = TestResources.CreateTestScoreInfo(importedBeatmap);
|
||||||
|
|
||||||
testScoreInfo.User = API.LocalUser.Value;
|
testScoreInfo.User = API.LocalUser.Value;
|
||||||
testScoreInfo.Rank = ScoreRank.B;
|
testScoreInfo.Rank = ScoreRank.B;
|
||||||
@ -125,21 +115,58 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
scoreManager.Import(testScoreInfo);
|
scoreManager.Import(testScoreInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("Became present", () => topLocalRank.IsPresent);
|
AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
|
||||||
AddUntilStep("Correct rank", () => topLocalRank.Rank == ScoreRank.B);
|
|
||||||
|
|
||||||
AddStep("Add higher score for current user", () =>
|
AddStep("Add higher score for current user", () =>
|
||||||
{
|
{
|
||||||
var testScoreInfo2 = TestResources.CreateTestScoreInfo(importedBeatmap);
|
var testScoreInfo2 = TestResources.CreateTestScoreInfo(importedBeatmap);
|
||||||
|
|
||||||
testScoreInfo2.User = API.LocalUser.Value;
|
testScoreInfo2.User = API.LocalUser.Value;
|
||||||
testScoreInfo2.Rank = ScoreRank.S;
|
testScoreInfo2.Rank = ScoreRank.X;
|
||||||
testScoreInfo2.TotalScore = testScoreInfo.TotalScore + 1;
|
testScoreInfo2.TotalScore = 1000000;
|
||||||
|
testScoreInfo2.Statistics = testScoreInfo2.MaximumStatistics;
|
||||||
|
|
||||||
scoreManager.Import(testScoreInfo2);
|
scoreManager.Import(testScoreInfo2);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("Correct rank", () => topLocalRank.Rank == ScoreRank.S);
|
AddUntilStep("SS rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.X);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLegacyScore()
|
||||||
|
{
|
||||||
|
ScoreInfo testScoreInfo = null!;
|
||||||
|
|
||||||
|
AddStep("Add legacy score for current user", () =>
|
||||||
|
{
|
||||||
|
testScoreInfo = TestResources.CreateTestScoreInfo(importedBeatmap);
|
||||||
|
|
||||||
|
testScoreInfo.User = API.LocalUser.Value;
|
||||||
|
testScoreInfo.Rank = ScoreRank.B;
|
||||||
|
testScoreInfo.TotalScore = scoreManager.GetTotalScore(testScoreInfo, ScoringMode.Classic);
|
||||||
|
|
||||||
|
scoreManager.Import(testScoreInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
|
||||||
|
|
||||||
|
AddStep("Add higher score for current user", () =>
|
||||||
|
{
|
||||||
|
var testScoreInfo2 = TestResources.CreateTestScoreInfo(importedBeatmap);
|
||||||
|
|
||||||
|
testScoreInfo2.User = API.LocalUser.Value;
|
||||||
|
testScoreInfo2.Rank = ScoreRank.X;
|
||||||
|
testScoreInfo2.Statistics = testScoreInfo2.MaximumStatistics;
|
||||||
|
testScoreInfo2.TotalScore = scoreManager.GetTotalScore(testScoreInfo2);
|
||||||
|
|
||||||
|
// ensure second score has a total score (standardised) less than first one (classic)
|
||||||
|
// despite having better statistics, otherwise this test is pointless.
|
||||||
|
Debug.Assert(testScoreInfo2.TotalScore < testScoreInfo.TotalScore);
|
||||||
|
|
||||||
|
scoreManager.Import(testScoreInfo2);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("SS rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
set => Model = value;
|
set => Model = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateableRank(ScoreRank? rank)
|
public UpdateableRank(ScoreRank? rank = null)
|
||||||
{
|
{
|
||||||
Rank = rank;
|
Rank = rank;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -47,6 +45,12 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IReadOnlyList<HitEvent> hitEvents;
|
private readonly IReadOnlyList<HitEvent> hitEvents;
|
||||||
|
|
||||||
|
private readonly IDictionary<HitResult, int>[] bins;
|
||||||
|
private double binSize;
|
||||||
|
private double hitOffset;
|
||||||
|
|
||||||
|
private Bar[]? barDrawables;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="HitEventTimingDistributionGraph"/>.
|
/// Creates a new <see cref="HitEventTimingDistributionGraph"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,22 +58,15 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
public HitEventTimingDistributionGraph(IReadOnlyList<HitEvent> hitEvents)
|
public HitEventTimingDistributionGraph(IReadOnlyList<HitEvent> hitEvents)
|
||||||
{
|
{
|
||||||
this.hitEvents = hitEvents.Where(e => !(e.HitObject.HitWindows is HitWindows.EmptyHitWindows) && e.Result.IsHit()).ToList();
|
this.hitEvents = hitEvents.Where(e => !(e.HitObject.HitWindows is HitWindows.EmptyHitWindows) && e.Result.IsHit()).ToList();
|
||||||
|
bins = Enumerable.Range(0, total_timing_distribution_bins).Select(_ => new Dictionary<HitResult, int>()).ToArray<IDictionary<HitResult, int>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IDictionary<HitResult, int>[] bins;
|
|
||||||
private double binSize;
|
|
||||||
private double hitOffset;
|
|
||||||
|
|
||||||
private Bar[] barDrawables;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
if (hitEvents == null || hitEvents.Count == 0)
|
if (hitEvents.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bins = Enumerable.Range(0, total_timing_distribution_bins).Select(_ => new Dictionary<HitResult, int>()).ToArray<IDictionary<HitResult, int>>();
|
|
||||||
|
|
||||||
binSize = Math.Ceiling(hitEvents.Max(e => Math.Abs(e.TimeOffset)) / timing_distribution_bins);
|
binSize = Math.Ceiling(hitEvents.Max(e => Math.Abs(e.TimeOffset)) / timing_distribution_bins);
|
||||||
|
|
||||||
// Prevent div-by-0 by enforcing a minimum bin size
|
// Prevent div-by-0 by enforcing a minimum bin size
|
||||||
@ -209,25 +206,30 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
|
|
||||||
private class Bar : CompositeDrawable
|
private class Bar : CompositeDrawable
|
||||||
{
|
{
|
||||||
private float totalValue => values.Sum(v => v.Value);
|
|
||||||
private float basalHeight => BoundingBox.Width / BoundingBox.Height;
|
|
||||||
private float availableHeight => 1 - basalHeight;
|
|
||||||
|
|
||||||
private readonly IReadOnlyList<KeyValuePair<HitResult, int>> values;
|
private readonly IReadOnlyList<KeyValuePair<HitResult, int>> values;
|
||||||
private readonly float maxValue;
|
private readonly float maxValue;
|
||||||
private readonly bool isCentre;
|
private readonly bool isCentre;
|
||||||
|
private readonly float totalValue;
|
||||||
|
|
||||||
private Circle[] boxOriginals;
|
private float basalHeight;
|
||||||
private Circle boxAdjustment;
|
private float offsetAdjustment;
|
||||||
|
|
||||||
|
private Circle[] boxOriginals = null!;
|
||||||
|
|
||||||
|
private Circle? boxAdjustment;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
|
private const double duration = 300;
|
||||||
|
|
||||||
public Bar(IDictionary<HitResult, int> values, float maxValue, bool isCentre)
|
public Bar(IDictionary<HitResult, int> values, float maxValue, bool isCentre)
|
||||||
{
|
{
|
||||||
this.values = values.OrderBy(v => v.Key.GetIndexForOrderedDisplay()).ToList();
|
this.values = values.OrderBy(v => v.Key.GetIndexForOrderedDisplay()).ToList();
|
||||||
this.maxValue = maxValue;
|
this.maxValue = maxValue;
|
||||||
this.isCentre = isCentre;
|
this.isCentre = isCentre;
|
||||||
|
totalValue = values.Sum(v => v.Value);
|
||||||
|
offsetAdjustment = totalValue;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
Masking = true;
|
Masking = true;
|
||||||
@ -254,38 +256,32 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// A bin with no value draws a grey dot instead.
|
// A bin with no value draws a grey dot instead.
|
||||||
InternalChildren = boxOriginals = new[]
|
Circle dot = new Circle
|
||||||
{
|
|
||||||
new Circle
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.BottomCentre,
|
Anchor = Anchor.BottomCentre,
|
||||||
Origin = Anchor.BottomCentre,
|
Origin = Anchor.BottomCentre,
|
||||||
Colour = isCentre ? Color4.White : Color4.Gray,
|
Colour = isCentre ? Color4.White : Color4.Gray,
|
||||||
Height = 0,
|
Height = 0,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
InternalChildren = boxOriginals = new[] { dot };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const double duration = 300;
|
|
||||||
|
|
||||||
private float offsetForValue(float value)
|
|
||||||
{
|
|
||||||
return availableHeight * value / maxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float heightForValue(float value)
|
|
||||||
{
|
|
||||||
return basalHeight + offsetForValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
if (!values.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
updateBasalHeight();
|
||||||
|
|
||||||
foreach (var boxOriginal in boxOriginals)
|
foreach (var boxOriginal in boxOriginals)
|
||||||
|
{
|
||||||
|
boxOriginal.Y = 0;
|
||||||
boxOriginal.Height = basalHeight;
|
boxOriginal.Height = basalHeight;
|
||||||
|
}
|
||||||
|
|
||||||
float offsetValue = 0;
|
float offsetValue = 0;
|
||||||
|
|
||||||
@ -297,6 +293,12 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
updateBasalHeight();
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateOffset(float adjustment)
|
public void UpdateOffset(float adjustment)
|
||||||
{
|
{
|
||||||
bool hasAdjustment = adjustment != totalValue;
|
bool hasAdjustment = adjustment != totalValue;
|
||||||
@ -318,7 +320,53 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
boxAdjustment.ResizeHeightTo(heightForValue(adjustment), duration, Easing.OutQuint);
|
offsetAdjustment = adjustment;
|
||||||
|
drawAdjustmentBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBasalHeight()
|
||||||
|
{
|
||||||
|
float newBasalHeight = DrawHeight > DrawWidth ? DrawWidth / DrawHeight : 1;
|
||||||
|
|
||||||
|
if (newBasalHeight == basalHeight)
|
||||||
|
return;
|
||||||
|
|
||||||
|
basalHeight = newBasalHeight;
|
||||||
|
foreach (var dot in boxOriginals)
|
||||||
|
dot.Height = basalHeight;
|
||||||
|
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private float offsetForValue(float value) => (1 - basalHeight) * value / maxValue;
|
||||||
|
|
||||||
|
private float heightForValue(float value) => MathF.Max(basalHeight + offsetForValue(value), 0);
|
||||||
|
|
||||||
|
private void draw()
|
||||||
|
{
|
||||||
|
resizeBars();
|
||||||
|
|
||||||
|
if (boxAdjustment != null)
|
||||||
|
drawAdjustmentBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resizeBars()
|
||||||
|
{
|
||||||
|
float offsetValue = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < values.Count; i++)
|
||||||
|
{
|
||||||
|
boxOriginals[i].Y = offsetForValue(offsetValue) * DrawHeight;
|
||||||
|
boxOriginals[i].Height = heightForValue(values[i].Value);
|
||||||
|
offsetValue -= values[i].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawAdjustmentBar()
|
||||||
|
{
|
||||||
|
bool hasAdjustment = offsetAdjustment != totalValue;
|
||||||
|
|
||||||
|
boxAdjustment.ResizeHeightTo(heightForValue(offsetAdjustment), duration, Easing.OutQuint);
|
||||||
boxAdjustment.FadeTo(!hasAdjustment ? 0 : 1, duration, Easing.OutQuint);
|
boxAdjustment.FadeTo(!hasAdjustment ? 0 : 1, duration, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Models;
|
using osu.Game.Models;
|
||||||
@ -20,27 +19,39 @@ using Realms;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Select.Carousel
|
namespace osu.Game.Screens.Select.Carousel
|
||||||
{
|
{
|
||||||
public class TopLocalRank : UpdateableRank
|
public class TopLocalRank : CompositeDrawable
|
||||||
{
|
{
|
||||||
private readonly BeatmapInfo beatmapInfo;
|
private readonly BeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private RealmAccess realm { get; set; }
|
private RealmAccess realm { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private ScoreManager scoreManager { get; set; } = null!;
|
||||||
|
|
||||||
private IDisposable scoreSubscription;
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
|
private IDisposable? scoreSubscription;
|
||||||
|
|
||||||
|
private readonly UpdateableRank updateable;
|
||||||
|
|
||||||
|
public ScoreRank? DisplayedRank => updateable.Rank;
|
||||||
|
|
||||||
public TopLocalRank(BeatmapInfo beatmapInfo)
|
public TopLocalRank(BeatmapInfo beatmapInfo)
|
||||||
: base(null)
|
|
||||||
{
|
{
|
||||||
this.beatmapInfo = beatmapInfo;
|
this.beatmapInfo = beatmapInfo;
|
||||||
|
|
||||||
Size = new Vector2(40, 20);
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
InternalChild = updateable = new UpdateableRank
|
||||||
|
{
|
||||||
|
Size = new Vector2(40, 20),
|
||||||
|
Alpha = 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -55,23 +66,27 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
.Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0"
|
.Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0"
|
||||||
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1"
|
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1"
|
||||||
+ $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2"
|
+ $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2"
|
||||||
+ $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName)
|
+ $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName),
|
||||||
.OrderByDescending(s => s.TotalScore),
|
localScoresChanged);
|
||||||
(items, _, _) =>
|
|
||||||
{
|
|
||||||
Rank = items.FirstOrDefault()?.Rank;
|
|
||||||
// Required since presence is changed via IsPresent override
|
|
||||||
Invalidate(Invalidation.Presence);
|
|
||||||
});
|
|
||||||
}, true);
|
}, true);
|
||||||
}
|
|
||||||
|
|
||||||
public override bool IsPresent => base.IsPresent && Rank != null;
|
void localScoresChanged(IRealmCollection<ScoreInfo> sender, ChangeSet? changes, Exception _)
|
||||||
|
{
|
||||||
|
// This subscription may fire from changes to linked beatmaps, which we don't care about.
|
||||||
|
// It's currently not possible for a score to be modified after insertion, so we can safely ignore callbacks with only modifications.
|
||||||
|
if (changes?.HasCollectionChanges() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ScoreInfo? topScore = scoreManager.OrderByTotalScore(sender.Detach()).FirstOrDefault();
|
||||||
|
|
||||||
|
updateable.Rank = topScore?.Rank;
|
||||||
|
updateable.Alpha = topScore != null ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
scoreSubscription?.Dispose();
|
scoreSubscription?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Overlays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -22,6 +24,15 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
private SpriteIcon icon = null!;
|
private SpriteIcon icon = null!;
|
||||||
private Box progressFill = null!;
|
private Box progressFill = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BeatmapModelDownloader beatmapDownloader { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
|
private LoginOverlay? loginOverlay { get; set; }
|
||||||
|
|
||||||
public UpdateBeatmapSetButton(BeatmapSetInfo beatmapSetInfo)
|
public UpdateBeatmapSetButton(BeatmapSetInfo beatmapSetInfo)
|
||||||
{
|
{
|
||||||
this.beatmapSetInfo = beatmapSetInfo;
|
this.beatmapSetInfo = beatmapSetInfo;
|
||||||
@ -32,9 +43,6 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
Origin = Anchor.CentreLeft;
|
Origin = Anchor.CentreLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private BeatmapModelDownloader beatmapDownloader { get; set; } = null!;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
@ -90,6 +98,12 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
|
if (!api.IsLoggedIn)
|
||||||
|
{
|
||||||
|
loginOverlay?.Show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
beatmapDownloader.DownloadAsUpdate(beatmapSetInfo);
|
beatmapDownloader.DownloadAsUpdate(beatmapSetInfo);
|
||||||
attachExistingDownload();
|
attachExistingDownload();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user