mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 01:47:33 +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 Box bg, progress;
|
||||||
private readonly PlayButton playButton;
|
private readonly PlayButton playButton;
|
||||||
|
|
||||||
private Track preview;
|
private Track preview => playButton.Preview;
|
||||||
private readonly Bindable<bool> playing = new Bindable<bool>();
|
private Bindable<bool> playing => playButton.Playing;
|
||||||
|
|
||||||
private BeatmapSetInfo beatmapSet;
|
|
||||||
public BeatmapSetInfo BeatmapSet
|
public BeatmapSetInfo BeatmapSet
|
||||||
{
|
{
|
||||||
get { return beatmapSet; }
|
get { return playButton.SetInfo; }
|
||||||
set
|
set { playButton.SetInfo = value; }
|
||||||
{
|
|
||||||
if (value == beatmapSet) return;
|
|
||||||
beatmapSet = value;
|
|
||||||
|
|
||||||
playing.Value = false;
|
|
||||||
preview = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreviewButton()
|
public PreviewButton()
|
||||||
@ -69,7 +61,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
Alpha = 0f,
|
Alpha = 0f,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
playButton = new PlayButton(playing)
|
playButton = new PlayButton()
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -78,7 +70,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
};
|
};
|
||||||
|
|
||||||
Action = () => playing.Value = !playing.Value;
|
Action = () => playing.Value = !playing.Value;
|
||||||
playing.ValueChanged += updatePlayingState;
|
playing.ValueChanged += newValue => progress.FadeTo(newValue ? 1 : 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -94,11 +86,6 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
if (playing.Value && preview != null)
|
if (playing.Value && preview != null)
|
||||||
{
|
{
|
||||||
progress.Width = (float)(preview.CurrentTime / preview.Length);
|
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);
|
bg.FadeColour(Color4.Black.Opacity(0.25f), 100);
|
||||||
base.OnHoverLost(state);
|
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),
|
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
playButton = new PlayButton(PreviewPlaying)
|
playButton = new PlayButton(SetInfo)
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5, Left = 10 },
|
Margin = new MarginPadding { Top = 5, Left = 10 },
|
||||||
Size = new Vector2(30),
|
Size = new Vector2(30),
|
||||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Overlays.Direct
|
|||||||
Spacing = new Vector2(10, 0),
|
Spacing = new Vector2(10, 0),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
playButton = new PlayButton(PreviewPlaying)
|
playButton = new PlayButton(SetInfo)
|
||||||
{
|
{
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
|
@ -41,10 +41,9 @@ namespace osu.Game.Overlays.Direct
|
|||||||
private BeatmapManager beatmaps;
|
private BeatmapManager beatmaps;
|
||||||
private NotificationOverlay notifications;
|
private NotificationOverlay notifications;
|
||||||
private BeatmapSetOverlay beatmapSetOverlay;
|
private BeatmapSetOverlay beatmapSetOverlay;
|
||||||
private Container audioWrapper;
|
|
||||||
|
|
||||||
protected Track Preview;
|
public Track Preview => PlayButton.Preview;
|
||||||
public readonly Bindable<bool> PreviewPlaying = new Bindable<bool>();
|
public Bindable<bool> PreviewPlaying => PlayButton.Playing;
|
||||||
protected abstract PlayButton PlayButton { get; }
|
protected abstract PlayButton PlayButton { get; }
|
||||||
protected abstract Box PreviewBar { get; }
|
protected abstract Box PreviewBar { get; }
|
||||||
|
|
||||||
@ -87,7 +86,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
EdgeEffect = edgeEffectNormal,
|
EdgeEffect = edgeEffectNormal,
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
audioWrapper = new Container(),
|
|
||||||
// temporary blackness until the actual background loads.
|
// temporary blackness until the actual background loads.
|
||||||
BlackBackground = new Box
|
BlackBackground = new Box
|
||||||
{
|
{
|
||||||
@ -112,39 +110,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
|
|
||||||
if (downloadRequest != null)
|
if (downloadRequest != null)
|
||||||
attachDownload(downloadRequest);
|
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()
|
protected override void Update()
|
||||||
@ -154,11 +119,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
if (PreviewPlaying && Preview != null)
|
if (PreviewPlaying && Preview != null)
|
||||||
{
|
{
|
||||||
PreviewBar.Width = (float)(Preview.CurrentTime / Preview.Length);
|
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)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
ShowInformation();
|
ShowInformation();
|
||||||
|
PreviewPlaying.Value = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +205,9 @@ namespace osu.Game.Overlays.Direct
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
this.FadeInFromZero(200, Easing.Out);
|
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()
|
protected List<DifficultyIcon> GetDifficultyIcons()
|
||||||
|
@ -3,10 +3,14 @@
|
|||||||
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
@ -14,11 +18,28 @@ namespace osu.Game.Overlays.Direct
|
|||||||
{
|
{
|
||||||
public class PlayButton : Container
|
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 Color4 hoverColour;
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
private readonly LoadingAnimation loadingAnimation;
|
private readonly LoadingAnimation loadingAnimation;
|
||||||
|
private Container audioWrapper;
|
||||||
|
|
||||||
private const float transition_duration = 500;
|
private const float transition_duration = 500;
|
||||||
|
|
||||||
private bool loading;
|
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[]
|
AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
|
audioWrapper = new Container(),
|
||||||
icon = new SpriteIcon
|
icon = new SpriteIcon
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -57,9 +79,10 @@ namespace osu.Game.Overlays.Direct
|
|||||||
loadingAnimation = new LoadingAnimation(),
|
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]
|
[BackgroundDependencyLoader]
|
||||||
@ -70,7 +93,7 @@ namespace osu.Game.Overlays.Direct
|
|||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
playing.Value = !playing.Value;
|
Playing.Value = !Playing.Value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,9 +105,71 @@ namespace osu.Game.Overlays.Direct
|
|||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override void OnHoverLost(InputState state)
|
||||||
{
|
{
|
||||||
if(!playing.Value)
|
if(!Playing.Value)
|
||||||
icon.FadeColour(Color4.White, 120, Easing.InOutQuint);
|
icon.FadeColour(Color4.White, 120, Easing.InOutQuint);
|
||||||
base.OnHoverLost(state);
|
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 =>
|
LoadComponentAsync(newPanels, p =>
|
||||||
{
|
{
|
||||||
if (panels != null) ScrollFlow.Remove(panels);
|
if (panels != null) ScrollFlow.Remove(panels);
|
||||||
ScrollFlow.Add(panels = newPanels);
|
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>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Audio\AudioLoadWrapper.cs" />
|
|
||||||
<Compile Include="Audio\SampleInfo.cs" />
|
<Compile Include="Audio\SampleInfo.cs" />
|
||||||
<Compile Include="Audio\SampleInfoList.cs" />
|
<Compile Include="Audio\SampleInfoList.cs" />
|
||||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user