2017-05-20 07:34:51 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
2017-05-18 03:37:34 +08:00
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2017-05-19 23:52:23 +08:00
|
|
|
using System.Collections.Generic;
|
2017-08-24 16:39:39 +08:00
|
|
|
using osu.Framework.Allocation;
|
2017-08-24 16:30:10 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-05-18 03:37:34 +08:00
|
|
|
using OpenTK;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-08-24 16:39:39 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-18 03:37:34 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-07-26 12:22:46 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2017-05-18 05:42:40 +08:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2017-05-18 03:37:34 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-08-24 16:30:10 +08:00
|
|
|
using OpenTK.Graphics;
|
2017-08-24 17:18:03 +08:00
|
|
|
using osu.Framework.Input;
|
2017-08-24 17:51:50 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.API;
|
2017-08-24 19:16:03 +08:00
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2017-09-09 02:25:20 +08:00
|
|
|
using osu.Game.Online.API.Requests;
|
2017-05-18 03:37:34 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Direct
|
|
|
|
{
|
2017-05-18 05:02:33 +08:00
|
|
|
public abstract class DirectPanel : Container
|
2017-05-18 03:37:34 +08:00
|
|
|
{
|
2017-08-25 10:54:18 +08:00
|
|
|
public readonly BeatmapSetInfo SetInfo;
|
2017-05-19 23:52:23 +08:00
|
|
|
|
2017-08-24 16:39:39 +08:00
|
|
|
protected Box BlackBackground;
|
|
|
|
|
2017-08-24 17:18:03 +08:00
|
|
|
private const double hover_transition_time = 400;
|
|
|
|
|
|
|
|
private Container content;
|
|
|
|
|
2017-08-24 17:51:50 +08:00
|
|
|
private APIAccess api;
|
|
|
|
private ProgressBar progressBar;
|
2017-08-24 19:16:03 +08:00
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private NotificationOverlay notifications;
|
2017-08-24 17:51:50 +08:00
|
|
|
|
2017-09-09 02:25:20 +08:00
|
|
|
private DownloadBeatmapSetRequest downloadRequest;
|
|
|
|
protected DownloadBeatmapSetRequest DownloadRequest
|
|
|
|
{
|
|
|
|
get { return downloadRequest; }
|
|
|
|
set
|
|
|
|
{
|
2017-09-09 03:34:55 +08:00
|
|
|
if (value == null || downloadRequest == value) return;
|
2017-09-09 02:25:20 +08:00
|
|
|
|
|
|
|
downloadRequest = value;
|
|
|
|
|
|
|
|
progressBar.FadeIn(400, Easing.OutQuint);
|
|
|
|
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
|
|
|
|
|
|
|
|
progressBar.Current.Value = 0;
|
|
|
|
|
|
|
|
downloadRequest.Failure += e =>
|
|
|
|
{
|
|
|
|
progressBar.Current.Value = 0;
|
|
|
|
progressBar.FadeOut(500);
|
|
|
|
Logger.Error(e, "Failed to get beatmap download information");
|
|
|
|
};
|
|
|
|
|
2017-09-09 04:23:42 +08:00
|
|
|
downloadRequest.DownloadProgressed += progress => progressBar.Current.Value = progress;
|
2017-09-09 02:25:20 +08:00
|
|
|
|
|
|
|
downloadRequest.Success += data =>
|
|
|
|
{
|
|
|
|
progressBar.Current.Value = 1;
|
|
|
|
progressBar.FadeOut(500);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:18:03 +08:00
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
2017-05-20 06:50:45 +08:00
|
|
|
protected DirectPanel(BeatmapSetInfo setInfo)
|
2017-05-20 03:12:47 +08:00
|
|
|
{
|
|
|
|
SetInfo = setInfo;
|
2017-08-24 16:30:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-25 13:36:14 +08:00
|
|
|
private readonly EdgeEffectParameters edgeEffectNormal = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Offset = new Vector2(0f, 1f),
|
|
|
|
Radius = 2f,
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly EdgeEffectParameters edgeEffectHovered = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Offset = new Vector2(0f, 5f),
|
|
|
|
Radius = 10f,
|
|
|
|
Colour = Color4.Black.Opacity(0.3f),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-24 20:26:50 +08:00
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2017-08-24 19:16:03 +08:00
|
|
|
private void load(APIAccess api, BeatmapManager beatmaps, OsuColour colours, NotificationOverlay notifications)
|
2017-08-24 16:39:39 +08:00
|
|
|
{
|
2017-08-24 17:51:50 +08:00
|
|
|
this.api = api;
|
2017-08-24 19:16:03 +08:00
|
|
|
this.beatmaps = beatmaps;
|
|
|
|
this.notifications = notifications;
|
2017-08-24 17:51:50 +08:00
|
|
|
|
2017-08-24 17:18:03 +08:00
|
|
|
AddInternal(content = new Container
|
2017-08-24 16:39:39 +08:00
|
|
|
{
|
2017-08-24 17:18:03 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
2017-08-25 13:36:14 +08:00
|
|
|
EdgeEffect = edgeEffectNormal,
|
2017-08-24 17:18:03 +08:00
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
// temporary blackness until the actual background loads.
|
|
|
|
BlackBackground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
},
|
|
|
|
CreateBackground(),
|
2017-08-24 17:51:50 +08:00
|
|
|
progressBar = new ProgressBar
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Height = 0,
|
|
|
|
Alpha = 0,
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.7f),
|
|
|
|
FillColour = colours.Blue,
|
|
|
|
Depth = -1,
|
|
|
|
},
|
2017-08-24 17:18:03 +08:00
|
|
|
}
|
2017-08-24 16:39:39 +08:00
|
|
|
});
|
2017-09-09 02:25:20 +08:00
|
|
|
|
|
|
|
DownloadRequest = beatmaps.GetExistingDownload(SetInfo);
|
2017-08-24 16:39:39 +08:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:18:03 +08:00
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
{
|
2017-08-25 13:36:14 +08:00
|
|
|
content.TweenEdgeEffectTo(edgeEffectHovered, hover_transition_time, Easing.OutQuint);
|
2017-08-24 17:18:03 +08:00
|
|
|
content.MoveToY(-4, hover_transition_time, Easing.OutQuint);
|
|
|
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
{
|
2017-08-25 13:36:14 +08:00
|
|
|
content.TweenEdgeEffectTo(edgeEffectNormal, hover_transition_time, Easing.OutQuint);
|
2017-08-24 17:18:03 +08:00
|
|
|
content.MoveToY(0, hover_transition_time, Easing.OutQuint);
|
|
|
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:51:50 +08:00
|
|
|
protected void StartDownload()
|
|
|
|
{
|
2017-09-09 01:07:28 +08:00
|
|
|
if (!api.LocalUser.Value.IsSupporter)
|
|
|
|
{
|
|
|
|
notifications.Post(new SimpleNotification
|
|
|
|
{
|
|
|
|
Icon = FontAwesome.fa_superpowers,
|
|
|
|
Text = "You gotta be a supporter to download for now 'yo"
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2017-08-24 20:26:50 +08:00
|
|
|
|
2017-08-25 10:54:18 +08:00
|
|
|
// we already have an active download running.
|
2017-09-09 12:55:28 +08:00
|
|
|
if (beatmaps.GetExistingDownload(SetInfo) != null)
|
2017-08-25 10:54:18 +08:00
|
|
|
{
|
|
|
|
content.MoveToX(-5, 50, Easing.OutSine).Then()
|
|
|
|
.MoveToX(5, 100, Easing.InOutSine).Then()
|
|
|
|
.MoveToX(-5, 100, Easing.InOutSine).Then()
|
|
|
|
.MoveToX(0, 50, Easing.InSine).Then();
|
2017-09-09 12:55:28 +08:00
|
|
|
|
|
|
|
return;
|
2017-08-25 10:54:18 +08:00
|
|
|
}
|
2017-09-09 12:55:28 +08:00
|
|
|
|
|
|
|
DownloadRequest = beatmaps.Download(SetInfo);
|
2017-08-24 17:51:50 +08:00
|
|
|
}
|
|
|
|
|
2017-08-24 16:30:10 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
this.FadeInFromZero(200, Easing.Out);
|
2017-05-20 03:12:47 +08:00
|
|
|
}
|
|
|
|
|
2017-06-24 18:56:35 +08:00
|
|
|
protected List<DifficultyIcon> GetDifficultyIcons()
|
2017-05-19 23:52:23 +08:00
|
|
|
{
|
2017-05-20 03:11:45 +08:00
|
|
|
var icons = new List<DifficultyIcon>();
|
2017-05-20 06:22:42 +08:00
|
|
|
|
2017-05-20 03:11:45 +08:00
|
|
|
foreach (var b in SetInfo.Beatmaps)
|
|
|
|
icons.Add(new DifficultyIcon(b));
|
2017-05-20 06:27:51 +08:00
|
|
|
|
2017-05-20 03:11:45 +08:00
|
|
|
return icons;
|
2017-05-19 02:01:01 +08:00
|
|
|
}
|
2017-05-20 06:27:51 +08:00
|
|
|
|
2017-07-13 12:17:47 +08:00
|
|
|
protected Drawable CreateBackground() => new DelayedLoadWrapper(new BeatmapSetCover(SetInfo)
|
2017-05-20 02:43:18 +08:00
|
|
|
{
|
2017-07-13 09:30:09 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
FillMode = FillMode.Fill,
|
2017-08-24 16:39:39 +08:00
|
|
|
OnLoadComplete = d =>
|
|
|
|
{
|
|
|
|
d.FadeInFromZero(400, Easing.Out);
|
|
|
|
BlackBackground.Delay(400).FadeOut();
|
|
|
|
},
|
2017-07-13 09:30:09 +08:00
|
|
|
})
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
TimeBeforeLoad = 300
|
|
|
|
};
|
2017-05-19 23:52:23 +08:00
|
|
|
|
2017-05-18 05:02:33 +08:00
|
|
|
public class Statistic : FillFlowContainer
|
2017-05-18 03:37:34 +08:00
|
|
|
{
|
|
|
|
private readonly SpriteText text;
|
|
|
|
|
|
|
|
private int value;
|
2017-07-13 09:30:09 +08:00
|
|
|
|
2017-05-18 03:37:34 +08:00
|
|
|
public int Value
|
|
|
|
{
|
|
|
|
get { return value; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
this.value = value;
|
2017-05-20 07:37:13 +08:00
|
|
|
text.Text = Value.ToString(@"N0");
|
2017-05-18 03:37:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Statistic(FontAwesome icon, int value = 0)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight;
|
|
|
|
Origin = Anchor.TopRight;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
Spacing = new Vector2(5f, 0f);
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = @"Exo2.0-SemiBoldItalic",
|
|
|
|
},
|
2017-08-03 13:36:21 +08:00
|
|
|
new SpriteIcon
|
2017-05-18 03:37:34 +08:00
|
|
|
{
|
|
|
|
Icon = icon,
|
|
|
|
Shadow = true,
|
2017-08-03 13:36:21 +08:00
|
|
|
Size = new Vector2(14),
|
2017-05-18 03:37:34 +08:00
|
|
|
Margin = new MarginPadding { Top = 1 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|