mirror of
https://github.com/ppy/osu.git
synced 2025-03-22 06:47:19 +08:00
move stuff thats duplicated in PreviewButton and DirectPanel to PlayButton
This commit is contained in:
parent
fffeac638f
commit
5a8b8dacbb
@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Audio
|
||||
{
|
||||
public class AudioLoadWrapper : Drawable
|
||||
{
|
||||
private readonly string preview;
|
||||
|
||||
public Track Preview;
|
||||
|
||||
public AudioLoadWrapper(string preview)
|
||||
{
|
||||
this.preview = preview;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(preview))
|
||||
{
|
||||
Preview = audio.Track.Get(preview);
|
||||
Preview.Volume.Value = 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -27,21 +27,13 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
private readonly Box bg, progress;
|
||||
private readonly PlayButton playButton;
|
||||
|
||||
private Track preview;
|
||||
private readonly Bindable<bool> playing = new Bindable<bool>();
|
||||
private Track preview => playButton.Preview;
|
||||
private Bindable<bool> playing => playButton.Playing;
|
||||
|
||||
private BeatmapSetInfo beatmapSet;
|
||||
public BeatmapSetInfo BeatmapSet
|
||||
{
|
||||
get { return beatmapSet; }
|
||||
set
|
||||
{
|
||||
if (value == beatmapSet) return;
|
||||
beatmapSet = value;
|
||||
|
||||
playing.Value = false;
|
||||
preview = null;
|
||||
}
|
||||
get { return playButton.SetInfo; }
|
||||
set { playButton.SetInfo = value; }
|
||||
}
|
||||
|
||||
public PreviewButton()
|
||||
@ -69,7 +61,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Alpha = 0f,
|
||||
},
|
||||
},
|
||||
playButton = new PlayButton(playing)
|
||||
playButton = new PlayButton()
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
@ -78,7 +70,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
};
|
||||
|
||||
Action = () => playing.Value = !playing.Value;
|
||||
playing.ValueChanged += updatePlayingState;
|
||||
playing.ValueChanged += newValue => progress.FadeTo(newValue ? 1 : 0, 100);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -94,11 +86,6 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
if (playing.Value && preview != null)
|
||||
{
|
||||
progress.Width = (float)(preview.CurrentTime / preview.Length);
|
||||
if (preview.HasCompleted)
|
||||
{
|
||||
playing.Value = false;
|
||||
preview = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,38 +106,5 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
bg.FadeColour(Color4.Black.Opacity(0.25f), 100);
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
private void updatePlayingState(bool newValue)
|
||||
{
|
||||
if (preview == null)
|
||||
{
|
||||
playButton.Loading = true;
|
||||
audioWrapper.Child = new AsyncLoadWrapper(new AudioLoadWrapper(BeatmapSet.OnlineInfo.Preview)
|
||||
{
|
||||
OnLoadComplete = d =>
|
||||
{
|
||||
playButton.Loading = false;
|
||||
|
||||
preview = (d as AudioLoadWrapper)?.Preview;
|
||||
playing.TriggerChange();
|
||||
},
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
progress.FadeIn(100);
|
||||
|
||||
preview.Seek(0);
|
||||
preview.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
progress.FadeOut(100);
|
||||
preview.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ namespace osu.Game.Overlays.Direct
|
||||
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
|
||||
},
|
||||
},
|
||||
playButton = new PlayButton(PreviewPlaying)
|
||||
playButton = new PlayButton(SetInfo)
|
||||
{
|
||||
Margin = new MarginPadding { Top = 5, Left = 10 },
|
||||
Size = new Vector2(30),
|
||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Overlays.Direct
|
||||
Spacing = new Vector2(10, 0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
playButton = new PlayButton(PreviewPlaying)
|
||||
playButton = new PlayButton(SetInfo)
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
|
@ -41,10 +41,9 @@ namespace osu.Game.Overlays.Direct
|
||||
private BeatmapManager beatmaps;
|
||||
private NotificationOverlay notifications;
|
||||
private BeatmapSetOverlay beatmapSetOverlay;
|
||||
private Container audioWrapper;
|
||||
|
||||
protected Track Preview;
|
||||
public readonly Bindable<bool> PreviewPlaying = new Bindable<bool>();
|
||||
public Track Preview => PlayButton.Preview;
|
||||
public Bindable<bool> PreviewPlaying => PlayButton.Playing;
|
||||
protected abstract PlayButton PlayButton { get; }
|
||||
protected abstract Box PreviewBar { get; }
|
||||
|
||||
@ -87,7 +86,6 @@ namespace osu.Game.Overlays.Direct
|
||||
EdgeEffect = edgeEffectNormal,
|
||||
Children = new[]
|
||||
{
|
||||
audioWrapper = new Container(),
|
||||
// temporary blackness until the actual background loads.
|
||||
BlackBackground = new Box
|
||||
{
|
||||
@ -112,39 +110,6 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
if (downloadRequest != null)
|
||||
attachDownload(downloadRequest);
|
||||
|
||||
PreviewPlaying.ValueChanged += newValue => PlayButton.FadeTo(newValue || IsHovered ? 1 : 0, 120, Easing.InOutQuint);
|
||||
PreviewPlaying.ValueChanged += newValue => PreviewBar.FadeTo(newValue ? 1 : 0, 120, Easing.InOutQuint);
|
||||
PreviewPlaying.ValueChanged += setPlaying;
|
||||
}
|
||||
|
||||
private void setPlaying(bool newValue)
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
if(Preview == null)
|
||||
{
|
||||
PlayButton.Loading = true;
|
||||
audioWrapper.Child = new AsyncLoadWrapper(new AudioLoadWrapper("https://b.ppy.sh/preview/" + SetInfo.OnlineBeatmapSetID + ".mp3")
|
||||
{
|
||||
OnLoadComplete = d =>
|
||||
{
|
||||
PlayButton.Loading = false;
|
||||
Preview = (d as AudioLoadWrapper)?.Preview;
|
||||
PreviewPlaying.TriggerChange();
|
||||
},
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Preview.Seek(0);
|
||||
Preview.Start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Preview?.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@ -154,11 +119,6 @@ namespace osu.Game.Overlays.Direct
|
||||
if (PreviewPlaying && Preview != null)
|
||||
{
|
||||
PreviewBar.Width = (float)(Preview.CurrentTime / Preview.Length);
|
||||
if (Preview.HasCompleted)
|
||||
{
|
||||
PreviewPlaying.Value = false;
|
||||
Preview = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,6 +144,7 @@ namespace osu.Game.Overlays.Direct
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
ShowInformation();
|
||||
PreviewPlaying.Value = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -244,6 +205,9 @@ namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
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()
|
||||
|
@ -3,10 +3,14 @@
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
@ -14,11 +18,28 @@ namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
public class PlayButton : Container
|
||||
{
|
||||
private readonly Bindable<bool> playing;
|
||||
public readonly Bindable<bool> Playing = new Bindable<bool>();
|
||||
public Track Preview { get; private set; }
|
||||
|
||||
private BeatmapSetInfo setInfo;
|
||||
public BeatmapSetInfo SetInfo
|
||||
{
|
||||
get { return setInfo; }
|
||||
set
|
||||
{
|
||||
if (value == setInfo) return;
|
||||
setInfo = value;
|
||||
|
||||
Playing.Value = false;
|
||||
Preview = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Color4 hoverColour;
|
||||
private readonly SpriteIcon icon;
|
||||
private readonly LoadingAnimation loadingAnimation;
|
||||
private Container audioWrapper;
|
||||
|
||||
private const float transition_duration = 500;
|
||||
|
||||
private bool loading;
|
||||
@ -41,11 +62,12 @@ namespace osu.Game.Overlays.Direct
|
||||
}
|
||||
}
|
||||
|
||||
public PlayButton(Bindable<bool> playing)
|
||||
public PlayButton(BeatmapSetInfo setInfo = null)
|
||||
{
|
||||
this.playing = playing;
|
||||
this.SetInfo = setInfo;
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
audioWrapper = new Container(),
|
||||
icon = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
@ -57,9 +79,10 @@ namespace osu.Game.Overlays.Direct
|
||||
loadingAnimation = new LoadingAnimation(),
|
||||
});
|
||||
|
||||
playing.ValueChanged += newValue => icon.Icon = newValue ? FontAwesome.fa_pause : FontAwesome.fa_play;
|
||||
Playing.ValueChanged += newValue => icon.Icon = newValue ? FontAwesome.fa_pause : FontAwesome.fa_play;
|
||||
Playing.ValueChanged += newValue => icon.FadeColour(newValue || IsHovered ? hoverColour : Color4.White, 120, Easing.InOutQuint);
|
||||
|
||||
playing.ValueChanged += newValue => icon.FadeColour(newValue || IsHovered ? hoverColour : Color4.White, 120, Easing.InOutQuint);
|
||||
Playing.ValueChanged += updatePreviewTrack;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -70,7 +93,7 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
playing.Value = !playing.Value;
|
||||
Playing.Value = !Playing.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,9 +105,71 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
if(!playing.Value)
|
||||
if(!Playing.Value)
|
||||
icon.FadeColour(Color4.White, 120, Easing.InOutQuint);
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if(Preview?.HasCompleted ?? false)
|
||||
{
|
||||
Playing.Value = false;
|
||||
Preview = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreviewTrack(bool newValue)
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
if (Preview == null)
|
||||
{
|
||||
Loading = true;
|
||||
audioWrapper.Child = new AsyncLoadWrapper(new AudioLoadWrapper("https://b.ppy.sh/preview/" + SetInfo.OnlineBeatmapSetID + ".mp3")
|
||||
{
|
||||
OnLoadComplete = d =>
|
||||
{
|
||||
Loading = false;
|
||||
Preview = (d as AudioLoadWrapper)?.Preview;
|
||||
Playing.TriggerChange();
|
||||
},
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Preview.Seek(0);
|
||||
Preview.Start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Preview?.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private class AudioLoadWrapper : Drawable
|
||||
{
|
||||
private readonly string preview;
|
||||
|
||||
public Track Preview;
|
||||
|
||||
public AudioLoadWrapper(string preview)
|
||||
{
|
||||
this.preview = preview;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(preview))
|
||||
{
|
||||
Preview = audio.Track.Get(preview);
|
||||
Preview.Volume.Value = 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,21 +230,21 @@ namespace osu.Game.Overlays
|
||||
})
|
||||
};
|
||||
|
||||
foreach (DirectPanel panel in newPanels.Children)
|
||||
panel.PreviewPlaying.ValueChanged += newValue =>
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
if (playing != null && playing != panel)
|
||||
playing.PreviewPlaying.Value = false;
|
||||
playing = panel;
|
||||
}
|
||||
};
|
||||
|
||||
LoadComponentAsync(newPanels, p =>
|
||||
{
|
||||
if (panels != null) ScrollFlow.Remove(panels);
|
||||
ScrollFlow.Add(panels = newPanels);
|
||||
|
||||
foreach (DirectPanel panel in p.Children)
|
||||
panel.PreviewPlaying.ValueChanged += newValue =>
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
if (playing != null && playing != panel)
|
||||
playing.PreviewPlaying.Value = false;
|
||||
playing = panel;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,6 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Audio\AudioLoadWrapper.cs" />
|
||||
<Compile Include="Audio\SampleInfo.cs" />
|
||||
<Compile Include="Audio\SampleInfoList.cs" />
|
||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user