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
|
|
|
|
|
2018-07-31 05:41:31 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +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;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2019-01-18 05:28:06 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-04-13 09:19:50 +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;
|
2020-04-21 07:03:18 +00:00
|
|
|
|
using osu.Game.Overlays.BeatmapListing.Panels;
|
2021-08-07 16:27:55 +00:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-07-31 05:41:31 +00:00
|
|
|
|
using osu.Game.Users;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2021-08-07 16:27:55 +00:00
|
|
|
|
using osu.Game.Localisation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-04-18 07:04:02 +00:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-07-03 03:02:35 +00:00
|
|
|
|
public class HeaderDownloadButton : BeatmapDownloadTrackingComposite, IHasTooltip
|
2018-04-13 09:19:50 +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
|
|
|
|
|
2018-07-31 05:41:31 +00:00
|
|
|
|
private readonly IBindable<User> localUser = new Bindable<User>();
|
|
|
|
|
|
2019-01-18 05:28:06 +00:00
|
|
|
|
private ShakeContainer shakeContainer;
|
|
|
|
|
private HeaderButton button;
|
|
|
|
|
|
2019-07-03 03:02:35 +00:00
|
|
|
|
public HeaderDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
2019-01-18 05:28:06 +00:00
|
|
|
|
: base(beatmapSet)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-01-18 05:28:06 +00:00
|
|
|
|
this.noVideo = noVideo;
|
|
|
|
|
|
2018-04-13 09:19:50 +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]
|
2019-03-13 03:56:47 +00:00
|
|
|
|
private void load(IAPIProvider api, BeatmapManager beatmaps)
|
2019-01-18 05:28:06 +00:00
|
|
|
|
{
|
2019-01-18 03:04:49 +00:00
|
|
|
|
FillFlowContainer textSprites;
|
|
|
|
|
|
2021-04-19 02:16:20 +00:00
|
|
|
|
AddInternal(shakeContainer = new ShakeContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-04-19 02:16:20 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
Child = button = new HeaderButton { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
button.AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
2018-04-13 09:19:50 +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[]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-04-19 02:16:20 +00:00
|
|
|
|
textSprites = new FillFlowContainer
|
2018-04-13 09:19:50 +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,
|
2018-04-13 09:19:50 +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
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new DownloadProgressBar(BeatmapSet.Value)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-01-17 12:10:34 +00:00
|
|
|
|
},
|
2018-04-13 09:19:50 +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
|
|
|
|
{
|
2019-01-31 10:15:04 +00:00
|
|
|
|
if (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
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
beatmaps.Download(BeatmapSet.Value, 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);
|
|
|
|
|
|
2019-02-22 11:13:38 +00:00
|
|
|
|
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-08-07 16:27:55 +00:00
|
|
|
|
Text = DownloadButtonStrings.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-08-07 16:27:55 +00:00
|
|
|
|
Text = DownloadButtonStrings.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-07 16:27:55 +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
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
private void userChanged(ValueChangedEvent<User> 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
|
|
|
|
{
|
|
|
|
|
if (!BeatmapSet.Value.OnlineInfo.HasVideo)
|
|
|
|
|
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
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|