2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-07-31 05:41:31 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-09-13 02:41:10 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-07-31 05:50:57 +00:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-06-25 17:10:04 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-06-04 23:27:34 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-27 14:06:57 +00:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2017-09-13 02:41:10 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2019-01-18 05:28:06 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-09-13 02:41:10 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-06-11 17:31:01 +00:00
|
|
|
|
using osu.Game.Online;
|
2018-07-31 05:41:31 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2021-10-29 08:58:46 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-08-07 16:27:55 +00:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2021-11-04 09:02:44 +00:00
|
|
|
|
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
2021-10-29 08:58:46 +00:00
|
|
|
|
using CommonStrings = osu.Game.Localisation.CommonStrings;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-04-18 07:04:02 +00:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2021-10-27 11:49:15 +00:00
|
|
|
|
public class HeaderDownloadButton : CompositeDrawable, IHasTooltip
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2020-02-16 20:43:33 +00:00
|
|
|
|
private const int text_size = 12;
|
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
private readonly bool noVideo;
|
2019-01-23 02:06:29 +00:00
|
|
|
|
|
2021-08-18 16:53:01 +00:00
|
|
|
|
public LocalisableString TooltipText => BeatmapsetsStrings.ShowDetailsDownloadDefault;
|
2018-07-31 05:50:57 +00:00
|
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
|
private readonly IBindable<APIUser> localUser = new Bindable<APIUser>();
|
2018-07-31 05:41:31 +00:00
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
private ShakeContainer shakeContainer;
|
|
|
|
|
private HeaderButton button;
|
|
|
|
|
|
2021-10-27 11:49:15 +00:00
|
|
|
|
private BeatmapDownloadTracker downloadTracker;
|
|
|
|
|
|
2021-10-29 08:58:46 +00:00
|
|
|
|
private readonly APIBeatmapSet beatmapSet;
|
|
|
|
|
|
|
|
|
|
public HeaderDownloadButton(APIBeatmapSet beatmapSet, bool noVideo = false)
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2021-10-27 11:49:15 +00:00
|
|
|
|
this.beatmapSet = beatmapSet;
|
2019-01-18 05:28:06 +00:00
|
|
|
|
this.noVideo = noVideo;
|
|
|
|
|
|
2017-09-13 02:41:10 +00:00
|
|
|
|
Width = 120;
|
2019-01-18 05:28:06 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-11-25 08:23:46 +00:00
|
|
|
|
private void load(IAPIProvider api, BeatmapModelDownloader beatmaps)
|
2019-01-18 05:28:06 +00:00
|
|
|
|
{
|
2019-01-18 03:04:49 +00:00
|
|
|
|
FillFlowContainer textSprites;
|
|
|
|
|
|
2021-10-27 11:49:15 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2021-10-27 11:49:15 +00: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 02:16:20 +00:00
|
|
|
|
|
|
|
|
|
button.AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2021-04-19 02:16:20 +00:00
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 },
|
2019-01-17 12:10:34 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2021-04-19 02:16:20 +00:00
|
|
|
|
textSprites = new FillFlowContainer
|
2017-09-13 02:41:10 +00:00
|
|
|
|
{
|
2021-04-19 02:16:20 +00:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
AutoSizeDuration = 500,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-09-13 02:41:10 +00:00
|
|
|
|
},
|
2021-04-19 02:16:20 +00:00
|
|
|
|
new SpriteIcon
|
2019-01-17 12:10:34 +00:00
|
|
|
|
{
|
2021-04-19 02:16:20 +00:00
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Icon = FontAwesome.Solid.Download,
|
|
|
|
|
Size = new Vector2(18),
|
2019-01-17 12:10:34 +00:00
|
|
|
|
},
|
2021-04-19 02:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-10-27 11:49:15 +00:00
|
|
|
|
new DownloadProgressBar(beatmapSet)
|
2021-04-19 02:16:20 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-01-17 12:10:34 +00:00
|
|
|
|
},
|
2017-11-27 22:09:58 +00:00
|
|
|
|
});
|
2018-06-04 23:27:34 +00:00
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
button.Action = () =>
|
2018-06-06 06:18:42 +00:00
|
|
|
|
{
|
2021-10-27 11:49:15 +00:00
|
|
|
|
if (downloadTracker.State.Value != DownloadState.NotDownloaded)
|
2018-06-06 06:18:42 +00:00
|
|
|
|
{
|
2019-01-18 05:28:06 +00:00
|
|
|
|
shakeContainer.Shake();
|
2018-07-03 13:43:42 +00:00
|
|
|
|
return;
|
2018-06-06 06:18:42 +00:00
|
|
|
|
}
|
2018-07-03 13:43:42 +00:00
|
|
|
|
|
2021-11-02 18:22:39 +00:00
|
|
|
|
beatmaps.Download(beatmapSet, noVideo);
|
2018-06-06 06:18:42 +00:00
|
|
|
|
};
|
2018-06-04 23:27:34 +00:00
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
localUser.BindTo(api.LocalUser);
|
|
|
|
|
localUser.BindValueChanged(userChanged, true);
|
|
|
|
|
button.Enabled.BindValueChanged(enabledChanged, true);
|
|
|
|
|
|
2021-10-27 11:49:15 +00:00
|
|
|
|
downloadTracker.State.BindValueChanged(state =>
|
2018-06-04 23:27:34 +00:00
|
|
|
|
{
|
2019-02-22 11:13:38 +00:00
|
|
|
|
switch (state.NewValue)
|
2018-07-17 05:35:09 +00:00
|
|
|
|
{
|
2019-01-18 05:28:06 +00:00
|
|
|
|
case DownloadState.Downloading:
|
2019-01-18 03:04:49 +00:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2021-10-29 08:58:46 +00:00
|
|
|
|
Text = CommonStrings.Downloading,
|
2020-02-16 20:43:33 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
2019-01-18 03:04:49 +00:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2021-01-13 15:04:29 +00:00
|
|
|
|
case DownloadState.Importing:
|
2019-01-31 10:09:04 +00:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2021-10-29 08:58:46 +00:00
|
|
|
|
Text = CommonStrings.Importing,
|
2020-02-16 20:43:33 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
2019-01-31 10:09:04 +00:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2019-01-31 10:09:04 +00:00
|
|
|
|
case DownloadState.LocallyAvailable:
|
2018-07-17 05:35:09 +00:00
|
|
|
|
this.FadeOut(200);
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
case DownloadState.NotDownloaded:
|
2019-01-18 03:04:49 +00:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2021-08-19 17:02:04 +00:00
|
|
|
|
Text = BeatmapsetsStrings.ShowDetailsDownloadDefault,
|
2020-02-16 20:43:33 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
2019-01-18 03:04:49 +00:00
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2020-02-10 19:27:46 +00:00
|
|
|
|
Text = getVideoSuffixText(),
|
2020-02-16 20:43:33 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: text_size - 2, weight: FontWeight.Bold)
|
2019-01-18 03:04:49 +00:00
|
|
|
|
},
|
|
|
|
|
};
|
2018-07-17 05:35:09 +00:00
|
|
|
|
this.FadeIn(200);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-01-18 05:28:06 +00:00
|
|
|
|
}, true);
|
2018-07-31 05:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
|
private void userChanged(ValueChangedEvent<APIUser> e) => button.Enabled.Value = !(e.NewValue is GuestUser);
|
2018-07-31 05:41:31 +00:00
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
private void enabledChanged(ValueChangedEvent<bool> e) => this.FadeColour(e.NewValue ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
2020-02-10 19:27:46 +00:00
|
|
|
|
|
2021-08-07 16:27:55 +00:00
|
|
|
|
private LocalisableString getVideoSuffixText()
|
2020-02-10 19:27:46 +00:00
|
|
|
|
{
|
2021-10-29 08:58:46 +00:00
|
|
|
|
if (!beatmapSet.HasVideo)
|
2020-02-10 19:27:46 +00:00
|
|
|
|
return string.Empty;
|
|
|
|
|
|
2021-08-07 16:27:55 +00:00
|
|
|
|
return noVideo ? BeatmapsetsStrings.ShowDetailsDownloadNoVideo : BeatmapsetsStrings.ShowDetailsDownloadVideo;
|
2020-02-10 19:27:46 +00:00
|
|
|
|
}
|
2017-09-13 02:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|