1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 05:12:57 +08:00
osu-lazer/osu.Game/Overlays/Direct/DirectPanel.cs

276 lines
9.0 KiB
C#
Raw Normal View History

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
using System.Collections.Generic;
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;
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;
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;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Logging;
using osu.Game.Online.API.Requests;
2017-09-18 04:39:34 +08:00
using osu.Framework.Configuration;
using osu.Framework.Audio.Track;
2017-05-18 03:37:34 +08:00
namespace osu.Game.Overlays.Direct
{
public abstract class DirectPanel : Container
2017-05-18 03:37:34 +08:00
{
public readonly BeatmapSetInfo SetInfo;
protected Box BlackBackground;
2017-08-24 17:18:03 +08:00
private const double hover_transition_time = 400;
private Container content;
private ProgressBar progressBar;
private BeatmapManager beatmaps;
private BeatmapSetOverlay beatmapSetOverlay;
public Track Preview => PlayButton.Preview;
public Bindable<bool> PreviewPlaying => PlayButton.Playing;
2017-09-18 04:39:34 +08:00
protected abstract PlayButton PlayButton { get; }
protected abstract Box PreviewBar { get; }
2017-09-18 04:39:34 +08:00
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)
{
SetInfo = setInfo;
2017-08-24 16:30:10 +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),
};
[BackgroundDependencyLoader(permitNulls: true)]
2017-11-15 20:28:02 +08:00
private void load(BeatmapManager beatmaps, OsuColour colours, BeatmapSetOverlay beatmapSetOverlay)
{
this.beatmaps = beatmaps;
this.beatmapSetOverlay = beatmapSetOverlay;
2017-08-24 17:18:03 +08:00
AddInternal(content = new Container
{
2017-08-24 17:18:03 +08:00
RelativeSizeAxes = Axes.Both,
Masking = true,
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(),
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-09-09 15:14:27 +08:00
var downloadRequest = beatmaps.GetExistingDownload(SetInfo);
if (downloadRequest != null)
attachDownload(downloadRequest);
beatmaps.BeatmapDownloadBegan += attachDownload;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
beatmaps.BeatmapDownloadBegan -= attachDownload;
}
protected override void Update()
{
base.Update();
if (PreviewPlaying && Preview != null && Preview.IsLoaded)
{
PreviewBar.Width = (float)(Preview.CurrentTime / Preview.Length);
}
}
2017-08-24 17:18:03 +08:00
protected override bool OnHover(InputState state)
{
content.TweenEdgeEffectTo(edgeEffectHovered, hover_transition_time, Easing.OutQuint);
2017-08-24 17:18:03 +08:00
content.MoveToY(-4, hover_transition_time, Easing.OutQuint);
2017-09-18 04:39:34 +08:00
PlayButton.FadeIn(120, Easing.InOutQuint);
2017-08-24 17:18:03 +08:00
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
content.TweenEdgeEffectTo(edgeEffectNormal, hover_transition_time, Easing.OutQuint);
2017-08-24 17:18:03 +08:00
content.MoveToY(0, hover_transition_time, Easing.OutQuint);
2017-09-18 04:39:34 +08:00
if (!PreviewPlaying)
PlayButton.FadeOut(120, Easing.InOutQuint);
2017-08-24 17:18:03 +08:00
base.OnHoverLost(state);
}
protected override bool OnClick(InputState state)
{
ShowInformation();
PreviewPlaying.Value = false;
return true;
}
protected void ShowInformation() => beatmapSetOverlay?.ShowBeatmapSet(SetInfo);
protected void StartDownload()
{
2017-09-09 12:55:28 +08:00
if (beatmaps.GetExistingDownload(SetInfo) != null)
{
2017-09-09 15:14:27 +08:00
// we already have an active download running.
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-09-09 12:55:28 +08:00
beatmaps.Download(SetInfo);
2017-09-09 15:14:27 +08:00
}
private void attachDownload(DownloadBeatmapSetRequest request)
{
if (request.BeatmapSet.OnlineBeatmapSetID != SetInfo.OnlineBeatmapSetID)
return;
2017-09-09 15:14:27 +08:00
progressBar.FadeIn(400, Easing.OutQuint);
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
progressBar.Current.Value = 0;
request.Failure += e =>
{
progressBar.Current.Value = 0;
progressBar.FadeOut(500);
Logger.Error(e, "Failed to get beatmap download information");
};
request.DownloadProgressed += progress => progressBar.Current.Value = progress;
request.Success += data =>
{
progressBar.Current.Value = 1;
progressBar.FadeOut(500);
};
}
2017-08-24 16:30:10 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
this.FadeInFromZero(200, Easing.Out);
PreviewPlaying.ValueChanged += newValue => PlayButton.FadeTo(newValue || IsHovered ? 1 : 0, 120, Easing.InOutQuint);
PreviewPlaying.ValueChanged += newValue => PreviewBar.FadeTo(newValue ? 1 : 0, 120, Easing.InOutQuint);
}
protected List<DifficultyIcon> GetDifficultyIcons()
{
var icons = new List<DifficultyIcon>();
2017-05-20 06:22:42 +08:00
foreach (var b in SetInfo.Beatmaps)
icons.Add(new DifficultyIcon(b));
2017-05-20 06:27:51 +08:00
return icons;
}
2017-05-20 06:27:51 +08:00
protected Drawable CreateBackground() => new DelayedLoadWrapper(
2017-11-22 02:16:44 +08:00
new BeatmapSetCover(SetInfo)
{
2017-11-22 02:16:44 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
OnLoadComplete = d =>
{
d.FadeInFromZero(400, Easing.Out);
BlackBackground.Delay(400).FadeOut();
},
}, 300)
{
RelativeSizeAxes = Axes.Both,
};
public class Statistic : FillFlowContainer
2017-05-18 03:37:34 +08:00
{
private readonly SpriteText text;
private int value;
2017-05-18 03:37:34 +08:00
public int Value
{
get { return value; }
set
{
this.value = value;
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",
},
new SpriteIcon
2017-05-18 03:37:34 +08:00
{
Icon = icon,
Shadow = true,
Size = new Vector2(14),
2017-05-18 03:37:34 +08:00
Margin = new MarginPadding { Top = 1 },
},
};
Value = value;
}
}
}
}