Merge remote-tracking branch 'origin/not-available-to-download' into not-available-to-download

This commit is contained in:
KingLuigi4932 2019-06-27 07:49:35 +03:00
commit 04f5ee21e1
4 changed files with 101 additions and 38 deletions

View File

@ -0,0 +1,94 @@
// 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.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Overlays.Direct;
using osu.Game.Rulesets.Osu;
using osuTK;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneDirectDownloadButton : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(DownloadButton)
};
private TestDownloadButton downloadButton;
[Test]
public void TestDownloadableBeatmap()
{
createButton(true);
assertEnabled(true);
}
[Test]
public void TestUndownloadableBeatmap()
{
createButton(false);
assertEnabled(false);
}
private void assertEnabled(bool enabled)
{
AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled);
}
private void createButton(bool downloadable)
{
AddStep("create button", () =>
{
Child = downloadButton = new TestDownloadButton(downloadable ? getDownloadableBeatmapSet() : getUndownloadableBeatmapSet())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(75, 50),
};
});
}
private BeatmapSetInfo getDownloadableBeatmapSet()
{
var normal = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo;
normal.OnlineInfo.HasVideo = true;
normal.OnlineInfo.HasStoryboard = true;
return normal;
}
private BeatmapSetInfo getUndownloadableBeatmapSet()
{
var beatmap = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo;
beatmap.Metadata.Artist = "test";
beatmap.Metadata.Title = "undownloadable";
beatmap.Metadata.AuthorString = "test";
beatmap.OnlineInfo.HasVideo = true;
beatmap.OnlineInfo.HasStoryboard = true;
beatmap.OnlineInfo.Availability = new BeatmapSetOnlineAvailability
{
DownloadDisabled = true,
ExternalLink = "http://osu.ppy.sh",
};
return beatmap;
}
private class TestDownloadButton : DownloadButton
{
public new bool DownloadEnabled => base.DownloadEnabled;
public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
: base(beatmapSet, noVideo)
{
}
}
}
}

View File

@ -73,8 +73,6 @@ private void load()
normal.OnlineInfo.HasStoryboard = true;
var undownloadable = getUndownloadableBeatmapSet(ruleset);
TestDirectGridPanel undownloadableGridPanel;
TestDirectListPanel undownloadableListPanel;
Child = new BasicScrollContainer
{
@ -90,34 +88,11 @@ private void load()
{
new DirectGridPanel(normal),
new DirectListPanel(normal),
undownloadableGridPanel = new TestDirectGridPanel(undownloadable),
undownloadableListPanel = new TestDirectListPanel(undownloadable),
new DirectGridPanel(undownloadable),
new DirectListPanel(undownloadable),
},
},
};
AddAssert("is download button disabled on second grid panel", () => !undownloadableGridPanel.IsDownloadButtonEnabled);
AddAssert("is download button disabled on second list panel", () => !undownloadableListPanel.IsDownloadButtonEnabled);
}
private class TestDirectGridPanel : DirectGridPanel
{
public bool IsDownloadButtonEnabled => DownloadButton.Enabled.Value;
public TestDirectGridPanel(BeatmapSetInfo beatmap)
: base(beatmap)
{
}
}
private class TestDirectListPanel : DirectListPanel
{
public bool IsDownloadButtonEnabled => DownloadButton.Enabled.Value;
public TestDirectListPanel(BeatmapSetInfo beatmap)
: base(beatmap)
{
}
}
}
}

View File

@ -25,7 +25,6 @@ public class DirectGridPanel : DirectPanel
private const float vertical_padding = 5;
private FillFlowContainer bottomPanel, statusContainer;
protected DownloadButton DownloadButton;
private PlayButton playButton;
private Box progressBar;
@ -156,7 +155,7 @@ private void load(OsuColour colours)
},
},
},
DownloadButton = new DownloadButton(SetInfo)
new DownloadButton(SetInfo)
{
Size = new Vector2(50, 30),
Margin = new MarginPadding(horizontal_padding),

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
@ -17,19 +16,17 @@ namespace osu.Game.Overlays.Direct
{
public class DownloadButton : BeatmapDownloadTrackingComposite
{
protected bool DownloadEnabled => button.Enabled.Value;
private readonly bool noVideo;
private readonly SpriteIcon icon;
private readonly SpriteIcon checkmark;
private readonly Box background;
private OsuColour colours;
private readonly ShakeContainer shakeContainer;
private readonly OsuAnimatedButton button;
public readonly BindableBool Enabled = new BindableBool(true);
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
: base(beatmapSet)
{
@ -66,8 +63,6 @@ public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
}
}
};
Enabled.BindTo(button.Enabled);
}
protected override void LoadComplete()
@ -78,14 +73,14 @@ protected override void LoadComplete()
FinishTransforms(true);
}
[BackgroundDependencyLoader(permitNulls: true)]
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, OsuGame game, BeatmapManager beatmaps)
{
this.colours = colours;
if (BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false)
{
Enabled.Value = false;
button.Enabled.Value = false;
button.TooltipText = "This beatmap is currently not available for download.";
return;
}