1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

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.Allocation;
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 @@ namespace osu.Game.Tests.Visual.SongSelect
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 @@ namespace osu.Game.Tests.Visual.SongSelect
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 @@ namespace osu.Game.Beatmaps
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
public bool AllBeatmapsUpToDate => Beatmaps.All(b => b.MatchesOnlineVersion);
}
}

View File

@ -153,17 +153,12 @@ namespace osu.Game.Screens.Select.Carousel
{
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 @@ namespace osu.Game.Screens.Select.Carousel
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 @@ namespace osu.Game.Screens.Select.Carousel
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);
}
}
}