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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-09-13 10:41:10 +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;
|
2021-06-26 01:10:04 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-06-05 07:27:34 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-27 22:06:57 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2017-09-13 10:41:10 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-09-13 10:41:10 +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;
|
2021-10-29 16:58:46 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-08-08 00:27:55 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
2021-10-29 16:58:46 +08:00
|
|
|
|
using CommonStrings = osu.Game.Localisation.CommonStrings;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-04-18 15:04:02 +08:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
2017-09-13 10:41:10 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
public class HeaderDownloadButton : CompositeDrawable, IHasTooltip
|
2017-09-13 10:41:10 +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
|
|
|
|
|
2021-08-19 00:53:01 +08:00
|
|
|
|
public LocalisableString TooltipText => BeatmapsetsStrings.ShowDetailsDownloadDefault;
|
2018-07-31 13:50:57 +08:00
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private readonly IBindable<APIUser> localUser = new Bindable<APIUser>();
|
2018-07-31 13:41:31 +08:00
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private ShakeContainer shakeContainer;
|
|
|
|
|
private HeaderButton button;
|
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
private BeatmapDownloadTracker downloadTracker;
|
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
private readonly APIBeatmapSet beatmapSet;
|
|
|
|
|
|
|
|
|
|
public HeaderDownloadButton(APIBeatmapSet beatmapSet, bool noVideo = false)
|
2017-09-13 10:41:10 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
this.beatmapSet = beatmapSet;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
this.noVideo = noVideo;
|
|
|
|
|
|
2017-09-13 10:41:10 +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]
|
2021-11-25 16:23:46 +08:00
|
|
|
|
private void load(IAPIProvider api, BeatmapModelDownloader beatmaps)
|
2019-01-18 13:28:06 +08:00
|
|
|
|
{
|
2019-01-18 11:04:49 +08:00
|
|
|
|
FillFlowContainer textSprites;
|
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-09-13 10:41:10 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
shakeContainer = new ShakeContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
Child = button = new HeaderButton { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
},
|
|
|
|
|
downloadTracker = new BeatmapDownloadTracker(beatmapSet),
|
|
|
|
|
};
|
2021-04-19 10:16:20 +08:00
|
|
|
|
|
|
|
|
|
button.AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
2017-09-13 10:41:10 +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[]
|
2017-09-13 10:41:10 +08:00
|
|
|
|
{
|
2021-04-19 10:16:20 +08:00
|
|
|
|
textSprites = new FillFlowContainer
|
2017-09-13 10:41:10 +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,
|
2017-09-13 10:41:10 +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
|
|
|
|
}
|
|
|
|
|
},
|
2021-10-27 19:49:15 +08:00
|
|
|
|
new DownloadProgressBar(beatmapSet)
|
2021-04-19 10:16:20 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-01-17 20:10:34 +08:00
|
|
|
|
},
|
2017-11-28 06:09:58 +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
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
if (downloadTracker.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
|
|
|
|
|
2021-11-03 02:22:39 +08:00
|
|
|
|
beatmaps.Download(beatmapSet, 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);
|
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
downloadTracker.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
|
|
|
|
|
{
|
2021-10-29 16:58:46 +08:00
|
|
|
|
Text = CommonStrings.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
|
|
|
|
|
{
|
2021-10-29 16:58:46 +08:00
|
|
|
|
Text = CommonStrings.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
|
|
|
|
|
{
|
2021-08-20 01:02:04 +08:00
|
|
|
|
Text = BeatmapsetsStrings.ShowDetailsDownloadDefault,
|
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
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private void userChanged(ValueChangedEvent<APIUser> 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
|
|
|
|
|
2021-08-08 00:27:55 +08:00
|
|
|
|
private LocalisableString getVideoSuffixText()
|
2020-02-11 03:27:46 +08:00
|
|
|
|
{
|
2021-10-29 16:58:46 +08:00
|
|
|
|
if (!beatmapSet.HasVideo)
|
2020-02-11 03:27:46 +08:00
|
|
|
|
return string.Empty;
|
|
|
|
|
|
2021-08-08 00:27:55 +08:00
|
|
|
|
return noVideo ? BeatmapsetsStrings.ShowDetailsDownloadNoVideo : BeatmapsetsStrings.ShowDetailsDownloadVideo;
|
2020-02-11 03:27:46 +08:00
|
|
|
|
}
|
2017-09-13 10:41:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|