Add beatmap update button

This commit is contained in:
Dean Herbert 2022-07-18 18:06:11 +09:00
parent 6adcf82d2e
commit eaf4f6dbb7
5 changed files with 141 additions and 11 deletions

View File

@ -11,6 +11,7 @@
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
@ -43,6 +44,29 @@ private void load(RulesetStore rulesets)
this.rulesets = rulesets;
}
[Test]
public void TestBeatmapWithOnlineUpdates()
{
var testBeatmapSetInfo = TestResources.CreateTestBeatmapSetInfo();
createCarousel(new List<BeatmapSetInfo>
{
testBeatmapSetInfo,
});
AddAssert("update button not visible", () => !carousel.ChildrenOfType<UpdateBeatmapSetButton>().Any());
AddStep("update online hash", () =>
{
testBeatmapSetInfo.Beatmaps.First().OnlineMD5Hash = "different hash";
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
});
AddUntilStep("update button visible", () => carousel.ChildrenOfType<UpdateBeatmapSetButton>().Any());
}
[Test]
public void TestExternalRulesetChange()
{
@ -825,7 +849,8 @@ public void TestFilteringByUserStarDifficulty()
checkVisibleItemCount(true, 15);
}
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null, int? count = null, bool randomDifficulties = false)
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null, int? count = null,
bool randomDifficulties = false)
{
bool changed = false;

View File

@ -93,5 +93,7 @@ public bool Equals(BeatmapSetInfo? other)
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
public bool AllBeatmapsUpToDate => Beatmaps.All(b => b.MatchesOnlineVersion);
}
}

View File

@ -153,17 +153,12 @@ private void load(BeatmapManager manager, SongSelect songSelect)
{
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4, 0),
Scale = new Vector2(0.8f),
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new TopLocalRank(beatmapInfo)
{
Scale = new Vector2(0.8f),
},
starCounter = new StarCounter
{
Scale = new Vector2(0.8f),
}
new TopLocalRank(beatmapInfo),
starCounter = new StarCounter()
}
}
}

View File

@ -61,14 +61,15 @@ private void load()
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 5 },
Children = new Drawable[]
Spacing = new Vector2(5),
Children = new[]
{
beatmapSet.AllBeatmapsUpToDate ? Empty() : new UpdateRequiredIcon(beatmapSet),
new BeatmapSetOnlineStatusPill
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 5 },
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapSet.Status
@ -76,6 +77,8 @@ private void load()
new FillFlowContainer<DifficultyIcon>
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Spacing = new Vector2(3),
ChildrenEnumerable = getDifficultyIcons(),
},

View File

@ -0,0 +1,105 @@
// 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.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Screens.Select.Carousel
{
public class UpdateRequiredIcon : OsuAnimatedButton
{
private readonly BeatmapSetInfo beatmapSetInfo;
private SpriteIcon icon;
public UpdateRequiredIcon(BeatmapSetInfo beatmapSetInfo)
{
this.beatmapSetInfo = beatmapSetInfo;
AutoSizeAxes = Axes.Both;
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
}
[Resolved]
private BeatmapModelDownloader beatmaps { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
const float icon_size = 14;
Content.Anchor = Anchor.CentreLeft;
Content.Origin = Anchor.CentreLeft;
Content.AddRange(new Drawable[]
{
new FillFlowContainer
{
Padding = new MarginPadding { Horizontal = 5, Vertical = 3 },
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4),
Children = new Drawable[]
{
new Container
{
Size = new Vector2(icon_size),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.SyncAlt,
Size = new Vector2(icon_size),
},
}
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.Default.With(weight: FontWeight.Bold),
Text = "Update",
}
}
},
});
TooltipText = "Update beatmap with online changes";
Action = () => beatmaps.Download(beatmapSetInfo);
}
protected override void LoadComplete()
{
base.LoadComplete();
icon.Spin(4000, RotationDirection.Clockwise);
}
protected override bool OnHover(HoverEvent e)
{
icon.Spin(400, RotationDirection.Clockwise);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
icon.Spin(4000, RotationDirection.Clockwise);
base.OnHoverLost(e);
}
}
}