mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 09:03:00 +08:00
Make beatmap download buttons inherit BeatmapDownloadTrackingComposite
- Move DownloadTrackingComposite into the online namespace
This commit is contained in:
parent
4a6074865e
commit
ab27d82cd5
@ -29,7 +29,7 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The model type.</typeparam>
|
||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
||||
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager
|
||||
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager<TModel>
|
||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
||||
where TFileModel : INamedFileInfo, new()
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace osu.Game.Database
|
||||
/// Fired when a new <see cref="TModel"/> becomes available in the database.
|
||||
/// This is not guaranteed to run on the update thread.
|
||||
/// </summary>
|
||||
public event ItemAddedDelegate ItemAdded;
|
||||
public event Action<TModel, bool> ItemAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a <see cref="TModel"/> is removed from the database.
|
||||
|
@ -1,7 +1,7 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Overlays.Direct
|
||||
namespace osu.Game.Online
|
||||
{
|
||||
public enum DownloadState
|
||||
{
|
@ -7,18 +7,21 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
|
||||
namespace osu.Game.Overlays.Direct
|
||||
namespace osu.Game.Online
|
||||
{
|
||||
/// <summary>
|
||||
/// A component which tracks a beatmap through potential download/import/deletion.
|
||||
/// </summary>
|
||||
public abstract class DownloadTrackingComposite : CompositeDrawable
|
||||
public abstract class DownloadTrackingComposite<TModel, TModelManager> : CompositeDrawable
|
||||
where TModel : class
|
||||
where TModelManager : class, IDownloadModelManager<TModel>
|
||||
{
|
||||
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
|
||||
public readonly Bindable<TModel> ModelInfo = new Bindable<TModel>();
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
private TModelManager manager;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current download state of the beatmap, whether is has already been downloaded, is in progress, or is not downloaded.
|
||||
@ -27,34 +30,34 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
protected readonly Bindable<double> Progress = new Bindable<double>();
|
||||
|
||||
protected DownloadTrackingComposite(BeatmapSetInfo beatmapSet = null)
|
||||
protected DownloadTrackingComposite(TModel model = null)
|
||||
{
|
||||
BeatmapSet.Value = beatmapSet;
|
||||
ModelInfo.Value = model;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(BeatmapManager beatmaps)
|
||||
private void load(TModelManager manager)
|
||||
{
|
||||
this.beatmaps = beatmaps;
|
||||
this.manager = manager;
|
||||
|
||||
BeatmapSet.BindValueChanged(setInfo =>
|
||||
ModelInfo.BindValueChanged(modelInfo =>
|
||||
{
|
||||
if (setInfo.NewValue == null)
|
||||
if (modelInfo.NewValue == null)
|
||||
attachDownload(null);
|
||||
else if (beatmaps.GetAllUsableBeatmapSetsEnumerable().Any(s => s.OnlineBeatmapSetID == setInfo.NewValue.OnlineBeatmapSetID))
|
||||
else if (manager.IsAvailableLocally(modelInfo.NewValue))
|
||||
State.Value = DownloadState.LocallyAvailable;
|
||||
else
|
||||
attachDownload(beatmaps.GetExistingDownload(setInfo.NewValue));
|
||||
attachDownload(manager.GetExistingDownload(modelInfo.NewValue));
|
||||
}, true);
|
||||
|
||||
beatmaps.DownloadBegan += download =>
|
||||
manager.DownloadBegan += download =>
|
||||
{
|
||||
if (download.Info.OnlineBeatmapSetID == BeatmapSet.Value?.OnlineBeatmapSetID)
|
||||
if (download.Info.Equals(ModelInfo.Value))
|
||||
attachDownload(download);
|
||||
};
|
||||
|
||||
beatmaps.ItemAdded += setAdded;
|
||||
beatmaps.ItemRemoved += setRemoved;
|
||||
manager.ItemAdded += itemAdded;
|
||||
manager.ItemRemoved += itemRemoved;
|
||||
}
|
||||
|
||||
#region Disposal
|
||||
@ -63,10 +66,10 @@ namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (beatmaps != null)
|
||||
if (manager != null)
|
||||
{
|
||||
beatmaps.DownloadBegan -= attachDownload;
|
||||
beatmaps.ItemAdded -= setAdded;
|
||||
manager.DownloadBegan -= attachDownload;
|
||||
manager.ItemAdded -= itemAdded;
|
||||
}
|
||||
|
||||
State.UnbindAll();
|
||||
@ -76,9 +79,9 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
#endregion
|
||||
|
||||
private ArchiveDownloadModelRequest<BeatmapSetInfo> attachedRequest;
|
||||
private ArchiveDownloadModelRequest<TModel> attachedRequest;
|
||||
|
||||
private void attachDownload(ArchiveDownloadModelRequest<BeatmapSetInfo> request)
|
||||
private void attachDownload(ArchiveDownloadModelRequest<TModel> request)
|
||||
{
|
||||
if (attachedRequest != null)
|
||||
{
|
||||
@ -118,13 +121,13 @@ namespace osu.Game.Overlays.Direct
|
||||
|
||||
private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null));
|
||||
|
||||
private void setAdded(BeatmapSetInfo s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable);
|
||||
private void itemAdded(TModel s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable);
|
||||
|
||||
private void setRemoved(BeatmapSetInfo s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded);
|
||||
private void itemRemoved(TModel s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded);
|
||||
|
||||
private void setDownloadStateFromManager(BeatmapSetInfo s, DownloadState state) => Schedule(() =>
|
||||
private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() =>
|
||||
{
|
||||
if (s.OnlineBeatmapSetID != BeatmapSet.Value?.OnlineBeatmapSetID)
|
||||
if (s.Equals(ModelInfo.Value))
|
||||
return;
|
||||
|
||||
State.Value = state;
|
@ -11,6 +11,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Overlays.Direct;
|
||||
using osu.Game.Users;
|
||||
@ -19,7 +20,7 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
||||
{
|
||||
public class DownloadButton : DownloadTrackingComposite, IHasTooltip
|
||||
public class DownloadButton : BeatmapDownloadTrackingComposite, IHasTooltip
|
||||
{
|
||||
private readonly bool noVideo;
|
||||
|
||||
|
@ -13,6 +13,7 @@ using osu.Game.Beatmaps.Drawables;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Overlays.BeatmapSet.Buttons;
|
||||
using osu.Game.Overlays.Direct;
|
||||
using osuTK;
|
||||
@ -21,7 +22,7 @@ using DownloadButton = osu.Game.Overlays.BeatmapSet.Buttons.DownloadButton;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
public class Header : DownloadTrackingComposite
|
||||
public class Header : BeatmapDownloadTrackingComposite
|
||||
{
|
||||
private const float transition_duration = 200;
|
||||
private const float tabs_height = 50;
|
||||
|
16
osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs
Normal file
16
osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online;
|
||||
|
||||
namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
public abstract class BeatmapDownloadTrackingComposite : DownloadTrackingComposite<BeatmapSetInfo, BeatmapManager>
|
||||
{
|
||||
public Bindable<BeatmapSetInfo> BeatmapSet => ModelInfo;
|
||||
|
||||
public BeatmapDownloadTrackingComposite(BeatmapSetInfo set = null)
|
||||
: base(set)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -9,11 +9,12 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
public class DownloadButton : DownloadTrackingComposite
|
||||
public class DownloadButton : BeatmapDownloadTrackingComposite
|
||||
{
|
||||
private readonly bool noVideo;
|
||||
private readonly SpriteIcon icon;
|
||||
|
@ -7,11 +7,12 @@ using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
public class DownloadProgressBar : DownloadTrackingComposite
|
||||
public class DownloadProgressBar : BeatmapDownloadTrackingComposite
|
||||
{
|
||||
private readonly ProgressBar progressBar;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user