Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
78 changes: 78 additions & 0 deletions osu.Game.Tests/Visual/RankedPlay/TestSceneCompactDivisionBadge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.RankedPlay;
using osuTK;

namespace osu.Game.Tests.Visual.RankedPlay
{
public partial class TestSceneCompactDivisionBadge : OsuTestScene
{
public TestSceneCompactDivisionBadge()
{
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(),
},
Content = new[]
{
new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
Width = 150,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Full,
Spacing = new Vector2(10),
Children = DIVISIONS.Select(d => new CompactDivisionBadge(d)).ToArray(),
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
ChildrenEnumerable = Enumerable.Range(1, 100).Where(i => i == 1 || i == 100 || i % 5 == 0).Select(i => new CompactDivisionBadge(
new RankedPlayDivision { Tier = Tier.Lustrous, DisplayName = "Lustrous", StartRating = 2400, EndRating = 3000 },
i
)),
}
}
},
};
}

public static readonly RankedPlayDivision[] DIVISIONS =
[
new RankedPlayDivision { Key = "Bronze-I", Tier = Tier.Bronze, Division = Division.I, DisplayName = "Bronze I", StartRating = 600, EndRating = 699 },
new RankedPlayDivision { Key = "Bronze-II", Tier = Tier.Bronze, Division = Division.II, DisplayName = "Bronze II", StartRating = 700, EndRating = 799 },
new RankedPlayDivision { Key = "Bronze-III", Tier = Tier.Bronze, Division = Division.III, DisplayName = "Bronze III", StartRating = 800, EndRating = 899 },
new RankedPlayDivision { Key = "Silver-I", Tier = Tier.Silver, Division = Division.I, DisplayName = "Silver I", StartRating = 900, EndRating = 999 },
new RankedPlayDivision { Key = "Silver-II", Tier = Tier.Silver, Division = Division.II, DisplayName = "Silver II", StartRating = 1000, EndRating = 1099 },
new RankedPlayDivision { Key = "Silver-III", Tier = Tier.Silver, Division = Division.III, DisplayName = "Silver III", StartRating = 1100, EndRating = 1199 },
new RankedPlayDivision { Key = "Gold-I", Tier = Tier.Gold, Division = Division.I, DisplayName = "Gold I", StartRating = 1200, EndRating = 1299 },
new RankedPlayDivision { Key = "Gold-II", Tier = Tier.Gold, Division = Division.II, DisplayName = "Gold II", StartRating = 1300, EndRating = 1399 },
new RankedPlayDivision { Key = "Gold-III", Tier = Tier.Gold, Division = Division.III, DisplayName = "Gold III", StartRating = 1400, EndRating = 1499 },
new RankedPlayDivision { Key = "Platinum-I", Tier = Tier.Platinum, Division = Division.I, DisplayName = "Platinum I", StartRating = 1500, EndRating = 1599 },
new RankedPlayDivision { Key = "Platinum-II", Tier = Tier.Platinum, Division = Division.II, DisplayName = "Platinum II", StartRating = 1600, EndRating = 1699 },
new RankedPlayDivision { Key = "Platinum-III", Tier = Tier.Platinum, Division = Division.III, DisplayName = "Platinum III", StartRating = 1700, EndRating = 1799 },
new RankedPlayDivision { Key = "Rhodium-I", Tier = Tier.Rhodium, Division = Division.I, DisplayName = "Rhodium I", StartRating = 1800, EndRating = 1899 },
new RankedPlayDivision { Key = "Rhodium-II", Tier = Tier.Rhodium, Division = Division.II, DisplayName = "Rhodium II", StartRating = 1900, EndRating = 1999 },
new RankedPlayDivision { Key = "Rhodium-III", Tier = Tier.Rhodium, Division = Division.III, DisplayName = "Rhodium III", StartRating = 2000, EndRating = 2099 },
new RankedPlayDivision { Key = "Radiant-I", Tier = Tier.Radiant, Division = Division.I, DisplayName = "Radiant I", StartRating = 2100, EndRating = 2199 },
new RankedPlayDivision { Key = "Radiant-II", Tier = Tier.Radiant, Division = Division.II, DisplayName = "Radiant II", StartRating = 2200, EndRating = 2299 },
new RankedPlayDivision { Key = "Radiant-III", Tier = Tier.Radiant, Division = Division.III, DisplayName = "Radiant III", StartRating = 2300, EndRating = 2399 },
];
}
}
71 changes: 71 additions & 0 deletions osu.Game.Tests/Visual/RankedPlay/TestSceneDivisionBadge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Components;
using osuTK;

namespace osu.Game.Tests.Visual.RankedPlay
{
public partial class TestSceneDivisionBadge : OsuTestScene
{
[Resolved]
private RulesetStore rulesetStore { get; set; } = null!;

[TestCase("osu")]
[TestCase("taiko")]
[TestCase("fruits")]
[TestCase("mania")]
public void TestRuleset(string rulesetName)
{
var ruleset = rulesetStore.GetRuleset(rulesetName)!;
AddStep("create", () =>
{
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(),
},
Content = new[]
{
new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
Width = 400,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Full,
Spacing = new Vector2(10),
ChildrenEnumerable = TestSceneCompactDivisionBadge.DIVISIONS.Select(d => new DivisionBadge(d, ruleset)),
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
ChildrenEnumerable = Enumerable.Range(1, 100).Where(i => i == 1 || i == 100 || i % 20 == 0).Select(i => new DivisionBadge(
new RankedPlayDivision { Key = "Lustrous", Tier = Tier.Lustrous, DisplayName = "Lustrous", StartRating = 2400, EndRating = 3000 },
ruleset,
i
)),
},
},
},
};
});
}
}
}
53 changes: 53 additions & 0 deletions osu.Game/Online/API/Requests/Responses/RankedPlayDivision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace osu.Game.Online.API.Requests.Responses
{
public class RankedPlayDivision
{
[JsonProperty(@"key")]
public string Key = string.Empty;

[JsonProperty(@"tier")]
public Tier Tier;

[JsonProperty(@"division")]
public Division Division;

[JsonProperty(@"display_name")]
public string DisplayName = string.Empty;

[JsonProperty(@"start_rating")]
public int StartRating;

[JsonProperty("@end_rating")]
public int EndRating;

public int Width => EndRating - StartRating + 1;
}

[JsonConverter(typeof(StringEnumConverter))]
public enum Tier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not put these in the same file as RankedPlayDivision. Maybe RankedPlayTier/RankedPlayDivision so that they're distinct from RankingTier (if we even want this to be separate in the first place).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely missed RankingTier existing, will use that for now. Also will split out the division enum to a separate file and rename the model to APIRankedPlayDivision or something like that (is there a reason some response models have the API prefix and some don't?).

{
Bronze,
Silver,
Gold,
Platinum,
Rhodium,
Radiant,
Lustrous,
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
[JsonConverter(typeof(StringEnumConverter))]
public enum Division
{
I = 1,
II = 2,
III = 3,
}
}
87 changes: 87 additions & 0 deletions osu.Game/Online/RankedPlay/CompactDivisionBadge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Online.RankedPlay
{
public partial class CompactDivisionBadge : CompositeDrawable, IHasTooltip
{
private readonly RankedPlayDivision division;
private readonly int? rank;

public CompactDivisionBadge(RankedPlayDivision division, int? rank = null)
{
if (division.Tier == Tier.Lustrous && rank == null)
throw new ArgumentException("Must specify a rank for Lustrous tier.");

this.division = division;
this.rank = rank;
}

[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Size = new Vector2(36, 19.5f);

InternalChild = new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = textures.Get(@$"Online/RankedPlay/Tiers/Compact/{division.Tier}"),
};

if (division.Tier != Tier.Lustrous)
{
AddInternal(new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4),
ChildrenEnumerable = Enumerable.Range(1, (int)division.Division)
.Select(_ => new Container
{
Size = new Vector2(3, 10),
Masking = true,
CornerRadius = 1.5f,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.75f),
},
}),
});
}
else if (rank != null)
{
AddInternal(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Torus.With(size: 18, weight: FontWeight.Bold),
Colour = Colour4.Black.Opacity(0.75f),
Text = rank.ToLocalisableString(@"N0"),
});
}
}

public LocalisableString TooltipText => division.DisplayName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.RankedPlay;
using osu.Game.Rulesets;
using osuTK;

namespace osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Components
{
public partial class DivisionBadge : CompositeDrawable, IHasTooltip
{
private readonly RankedPlayDivision division;
private readonly RulesetInfo ruleset;
private readonly int? rank;

public DivisionBadge(RankedPlayDivision division, RulesetInfo ruleset, int? rank = null)
{
if (division.Tier == Tier.Lustrous && rank == null)
throw new ArgumentException("Must specify a rank for Lustrous tier.");

this.division = division;
this.ruleset = ruleset;
this.rank = rank;
}

[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Size = division.Tier switch
{
Tier.Bronze => new Vector2(120, 96),
Tier.Silver => new Vector2(120, 99.75f),
Tier.Gold => new Vector2(120, 100.5f),
Tier.Platinum => new Vector2(120, 107.25f),
Tier.Rhodium => new Vector2(120, 108),
Tier.Radiant => new Vector2(120, 112.5f),
Tier.Lustrous => new Vector2(120, 122.5f),
_ => throw new ArgumentOutOfRangeException()
};

InternalChildren = new Drawable[]
{
new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = textures.Get($@"Online/RankedPlay/Tiers/Base/{division.Tier}"),
FillMode = FillMode.Fit,
},
new Sprite
{
Size = division.Tier switch
{
Tier.Bronze => new Vector2(33),
Tier.Silver => new Vector2(34.5f),
_ => new Vector2(36),
},
Position = division.Tier switch
{
Tier.Bronze => new Vector2(43.5f, 24.75f),
Tier.Silver => new Vector2(42.75f, 27),
Tier.Gold => new Vector2(42, 23.25f),
Tier.Platinum => new Vector2(42, 28.5f),
Tier.Rhodium => new Vector2(42, 30),
Tier.Radiant => new Vector2(42, 33),
Tier.Lustrous => new Vector2(42, 43.5f),
_ => throw new ArgumentOutOfRangeException()
},
Texture = textures.Get($@"Online/RankedPlay/Tiers/Rulesets/{ruleset.ShortName}"),
},
new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = textures.Get($@"Online/RankedPlay/Tiers/Stars/{division.Key}"),
FillMode = FillMode.Fit,
},

@minetoblend minetoblend Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the shine layer will go above the stars but below the ruleset icon, so probably a good idea to swap the draw order these two

new CompactDivisionBadge(division, rank)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
},
};
}

public LocalisableString TooltipText => division.DisplayName;
}
}
Loading