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;
|
|
|
|
|
using osu.Framework.Configuration;
|
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;
|
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;
|
2018-07-31 13:41:31 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2019-01-17 20:10:34 +08:00
|
|
|
|
using osu.Game.Overlays.Direct;
|
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-01-18 13:28:06 +08:00
|
|
|
|
public class DownloadButton : DownloadTrackingComposite, IHasTooltip
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
private readonly bool noVideo;
|
2019-01-23 10:06:29 +08:00
|
|
|
|
|
2019-02-21 17:56:34 +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;
|
|
|
|
|
|
|
|
|
|
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
|
|
|
|
: 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]
|
|
|
|
|
private void load(APIAccess api, BeatmapManager beatmaps)
|
|
|
|
|
{
|
2019-01-18 11:04:49 +08:00
|
|
|
|
FillFlowContainer textSprites;
|
|
|
|
|
|
2019-01-18 13:28:06 +08:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
shakeContainer = new ShakeContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-17 20:10:34 +08:00
|
|
|
|
Depth = -1,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-01-18 13:28:06 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 5,
|
2019-01-17 20:10:34 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
button = new HeaderButton { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
// cannot nest inside here due to the structure of button (putting things in its own content).
|
|
|
|
|
// requires framework fix.
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 },
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
textSprites = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Depth = -1,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
AutoSizeDuration = 500,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
},
|
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Depth = -1,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Icon = FontAwesome.fa_download,
|
|
|
|
|
Size = new Vector2(16),
|
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
},
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-02-21 17:56:34 +08:00
|
|
|
|
new DownloadProgressBar(BeatmapSet.Value)
|
2019-01-17 20:10:34 +08:00
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
Depth = -2,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-01-17 20:10:34 +08:00
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
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-21 17:56:34 +08:00
|
|
|
|
State.BindValueChanged(e =>
|
2018-06-05 07:27:34 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
switch (e.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...",
|
|
|
|
|
TextSize = 13,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
2019-01-18 13:28:06 +08:00
|
|
|
|
case DownloadState.Downloaded:
|
2019-01-31 18:09:04 +08:00
|
|
|
|
textSprites.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = "Importing...",
|
|
|
|
|
TextSize = 13,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
2018-07-17 13:35:09 +08:00
|
|
|
|
this.FadeOut(200);
|
|
|
|
|
break;
|
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",
|
|
|
|
|
TextSize = 13,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2019-01-18 13:28:06 +08:00
|
|
|
|
Text = BeatmapSet.Value.OnlineInfo.HasVideo && noVideo ? "without Video" : string.Empty,
|
2019-01-18 11:04:49 +08:00
|
|
|
|
TextSize = 11,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
|
|
|
|
};
|
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);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|