2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-07-31 13:50:57 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-06-05 07:27:34 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-06-12 01:31:01 +08:00
|
|
|
|
using osu.Game.Online;
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2020-04-21 15:03:18 +08:00
|
|
|
|
using osu.Game.Overlays.BeatmapListing.Panels;
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Game.Users;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-04-18 15:04:02 +08:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-07-03 11:02:35 +08:00
|
|
|
|
public class HeaderDownloadButton : BeatmapDownloadTrackingComposite, IHasTooltip
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-17 04:43:33 +08:00
|
|
|
|
private const int text_size = 12;
|
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private readonly bool noVideo;
|
2019-01-23 10:06:29 +08:00
|
|
|
|
|
2020-01-15 03:26:54 +08:00
|
|
|
|
public string TooltipText => button.Enabled.Value ? "download this beatmap" : "login to download";
|
2018-07-31 13:50:57 +08:00
|
|
|
|
|
2018-07-31 13:41:31 +08:00
|
|
|
|
private readonly IBindable<User> localUser = new Bindable<User>();
|
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private ShakeContainer shakeContainer;
|
|
|
|
|
private HeaderButton button;
|
|
|
|
|
|
2019-07-03 11:02:35 +08:00
|
|
|
|
public HeaderDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
2019-01-18 13:28:06 +08:00
|
|
|
|
: base(beatmapSet)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
this.noVideo = noVideo;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Width = 120;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2019-03-13 11:56:47 +08:00
|
|
|
|
private void load(IAPIProvider api, BeatmapManager beatmaps)
|
2019-01-18 13:28:06 +08:00
|
|
|
|
{
|
2019-01-18 11:04:49 +08:00
|
|
|
|
FillFlowContainer textSprites;
|
|
|
|
|
|
2021-04-19 10:16:20 +08:00
|
|
|
|
AddInternal(shakeContainer = new ShakeContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-19 10:16:20 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
Child = button = new HeaderButton { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
button.AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-19 10:16:20 +08:00
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 },
|
2019-01-17 20:10:34 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-19 10:16:20 +08:00
|
|
|
|
textSprites = new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-19 10:16:20 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
AutoSizeDuration = 500,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2021-04-19 10:16:20 +08:00
|
|
|
|
new SpriteIcon
|
2019-01-17 20:10:34 +08:00
|
|
|
|
{
|
2021-04-19 10:16:20 +08:00
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Icon = FontAwesome.Solid.Download,
|
|
|
|
|
Size = new Vector2(18),
|
2019-01-17 20:10:34 +08:00
|
|
|
|
},
|
2021-04-19 10:16:20 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new DownloadProgressBar(BeatmapSet.Value)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-01-17 20:10:34 +08:00
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
2018-06-05 07:27:34 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
button.Action = () =>
|
2018-06-06 14:18:42 +08:00
|
|
|
|
{
|
2019-01-31 18:15:04 +08:00
|
|
|
|
if (State.Value != DownloadState.NotDownloaded)
|
2018-06-06 14:18:42 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
shakeContainer.Shake();
|
2018-07-03 21:43:42 +08:00
|
|
|
|
return;
|
2018-06-06 14:18:42 +08:00
|
|
|
|
}
|
2018-07-03 21:43:42 +08:00
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
beatmaps.Download(BeatmapSet.Value, noVideo);
|
2018-06-06 14:18:42 +08:00
|
|
|
|
};
|
2018-06-05 07:27:34 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
localUser.BindTo(api.LocalUser);
|
|
|
|
|
localUser.BindValueChanged(userChanged, true);
|
|
|
|
|
button.Enabled.BindValueChanged(enabledChanged, true);
|
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
|
State.BindValueChanged(state =>
|
2018-06-05 07:27:34 +08:00
|
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
|
switch (state.NewValue)
|
2018-07-17 13:35:09 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.Downloading:
|
2019-01-18 11:04:49 +08:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = "Downloading...",
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
2019-01-18 11:04:49 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2021-01-13 23:04:29 +08:00
|
|
|
|
case DownloadState.Importing:
|
2019-01-31 18:09:04 +08:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = "Importing...",
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
2019-01-31 18:09:04 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-01-31 18:09:04 +08:00
|
|
|
|
case DownloadState.LocallyAvailable:
|
2018-07-17 13:35:09 +08:00
|
|
|
|
this.FadeOut(200);
|
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.NotDownloaded:
|
2019-01-18 11:04:49 +08:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = "Download",
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
2019-01-18 11:04:49 +08:00
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2020-02-11 03:27:46 +08:00
|
|
|
|
Text = getVideoSuffixText(),
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size - 2, weight: FontWeight.Bold)
|
2019-01-18 11:04:49 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2018-07-17 13:35:09 +08:00
|
|
|
|
this.FadeIn(200);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-01-18 13:28:06 +08:00
|
|
|
|
}, true);
|
2018-07-31 13:41:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void userChanged(ValueChangedEvent<User> e) => button.Enabled.Value = !(e.NewValue is GuestUser);
|
2018-07-31 13:41:31 +08:00
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void enabledChanged(ValueChangedEvent<bool> e) => this.FadeColour(e.NewValue ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
2020-02-11 03:27:46 +08:00
|
|
|
|
|
|
|
|
|
private string getVideoSuffixText()
|
|
|
|
|
{
|
|
|
|
|
if (!BeatmapSet.Value.OnlineInfo.HasVideo)
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
|
|
return noVideo ? "without Video" : "with Video";
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|