mirror of
https://github.com/ppy/osu.git
synced 2025-02-28 04:43:37 +08:00
Merge remote-tracking branch 'origin/not-available-to-download' into not-available-to-download
This commit is contained in:
commit
04f5ee21e1
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -73,8 +73,6 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
normal.OnlineInfo.HasStoryboard = true;
|
normal.OnlineInfo.HasStoryboard = true;
|
||||||
|
|
||||||
var undownloadable = getUndownloadableBeatmapSet(ruleset);
|
var undownloadable = getUndownloadableBeatmapSet(ruleset);
|
||||||
TestDirectGridPanel undownloadableGridPanel;
|
|
||||||
TestDirectListPanel undownloadableListPanel;
|
|
||||||
|
|
||||||
Child = new BasicScrollContainer
|
Child = new BasicScrollContainer
|
||||||
{
|
{
|
||||||
@ -90,34 +88,11 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
new DirectGridPanel(normal),
|
new DirectGridPanel(normal),
|
||||||
new DirectListPanel(normal),
|
new DirectListPanel(normal),
|
||||||
undownloadableGridPanel = new TestDirectGridPanel(undownloadable),
|
new DirectGridPanel(undownloadable),
|
||||||
undownloadableListPanel = new TestDirectListPanel(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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
private const float vertical_padding = 5;
|
private const float vertical_padding = 5;
|
||||||
|
|
||||||
private FillFlowContainer bottomPanel, statusContainer;
|
private FillFlowContainer bottomPanel, statusContainer;
|
||||||
protected DownloadButton DownloadButton;
|
|
||||||
private PlayButton playButton;
|
private PlayButton playButton;
|
||||||
private Box progressBar;
|
private Box progressBar;
|
||||||
|
|
||||||
@ -156,7 +155,7 @@ namespace osu.Game.Overlays.Direct
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DownloadButton = new DownloadButton(SetInfo)
|
new DownloadButton(SetInfo)
|
||||||
{
|
{
|
||||||
Size = new Vector2(50, 30),
|
Size = new Vector2(50, 30),
|
||||||
Margin = new MarginPadding(horizontal_padding),
|
Margin = new MarginPadding(horizontal_padding),
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
@ -17,19 +16,17 @@ namespace osu.Game.Overlays.Direct
|
|||||||
{
|
{
|
||||||
public class DownloadButton : BeatmapDownloadTrackingComposite
|
public class DownloadButton : BeatmapDownloadTrackingComposite
|
||||||
{
|
{
|
||||||
|
protected bool DownloadEnabled => button.Enabled.Value;
|
||||||
|
|
||||||
private readonly bool noVideo;
|
private readonly bool noVideo;
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
private readonly SpriteIcon checkmark;
|
private readonly SpriteIcon checkmark;
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
|
|
||||||
private OsuColour colours;
|
private OsuColour colours;
|
||||||
|
|
||||||
private readonly ShakeContainer shakeContainer;
|
private readonly ShakeContainer shakeContainer;
|
||||||
|
|
||||||
private readonly OsuAnimatedButton button;
|
private readonly OsuAnimatedButton button;
|
||||||
|
|
||||||
public readonly BindableBool Enabled = new BindableBool(true);
|
|
||||||
|
|
||||||
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
||||||
: base(beatmapSet)
|
: base(beatmapSet)
|
||||||
{
|
{
|
||||||
@ -66,8 +63,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Enabled.BindTo(button.Enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -78,14 +73,14 @@ namespace osu.Game.Overlays.Direct
|
|||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(permitNulls: true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(OsuColour colours, OsuGame game, BeatmapManager beatmaps)
|
private void load(OsuColour colours, OsuGame game, BeatmapManager beatmaps)
|
||||||
{
|
{
|
||||||
this.colours = colours;
|
this.colours = colours;
|
||||||
|
|
||||||
if (BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false)
|
if (BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false)
|
||||||
{
|
{
|
||||||
Enabled.Value = false;
|
button.Enabled.Value = false;
|
||||||
button.TooltipText = "This beatmap is currently not available for download.";
|
button.TooltipText = "This beatmap is currently not available for download.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user