1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 21:52:55 +08:00

Make ShowDragHandle into a bindable

This commit is contained in:
smoogipoo 2020-09-08 16:36:36 +09:00
parent 17e8171827
commit 1260e30cde
3 changed files with 15 additions and 14 deletions

View File

@ -12,13 +12,13 @@ namespace osu.Game.Graphics.Containers
/// <summary> /// <summary>
/// Whether any item is currently being dragged. Used to hide other items' drag handles. /// Whether any item is currently being dragged. Used to hide other items' drag handles.
/// </summary> /// </summary>
private readonly BindableBool playlistDragActive = new BindableBool(); protected readonly BindableBool DragActive = new BindableBool();
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer(); protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer();
protected sealed override RearrangeableListItem<TModel> CreateDrawable(TModel item) => CreateOsuDrawable(item).With(d => protected sealed override RearrangeableListItem<TModel> CreateDrawable(TModel item) => CreateOsuDrawable(item).With(d =>
{ {
d.PlaylistDragActive.BindTo(playlistDragActive); d.DragActive.BindTo(DragActive);
}); });
protected abstract OsuRearrangeableListItem<TModel> CreateOsuDrawable(TModel item); protected abstract OsuRearrangeableListItem<TModel> CreateOsuDrawable(TModel item);

View File

@ -19,7 +19,7 @@ namespace osu.Game.Graphics.Containers
/// <summary> /// <summary>
/// Whether any item is currently being dragged. Used to hide other items' drag handles. /// Whether any item is currently being dragged. Used to hide other items' drag handles.
/// </summary> /// </summary>
public readonly BindableBool PlaylistDragActive = new BindableBool(); public readonly BindableBool DragActive = new BindableBool();
private Color4 handleColour = Color4.White; private Color4 handleColour = Color4.White;
@ -44,8 +44,9 @@ namespace osu.Game.Graphics.Containers
/// <summary> /// <summary>
/// Whether the drag handle should be shown. /// Whether the drag handle should be shown.
/// </summary> /// </summary>
protected virtual bool ShowDragHandle => true; protected readonly Bindable<bool> ShowDragHandle = new Bindable<bool>();
private Container handleContainer;
private PlaylistItemHandle handle; private PlaylistItemHandle handle;
protected OsuRearrangeableListItem(TModel item) protected OsuRearrangeableListItem(TModel item)
@ -58,8 +59,6 @@ namespace osu.Game.Graphics.Containers
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Container handleContainer;
InternalChild = new GridContainer InternalChild = new GridContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -88,9 +87,12 @@ namespace osu.Game.Graphics.Containers
ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) } RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
}; };
}
if (!ShowDragHandle) protected override void LoadComplete()
handleContainer.Alpha = 0; {
base.LoadComplete();
ShowDragHandle.BindValueChanged(show => handleContainer.Alpha = show.NewValue ? 1 : 0, true);
} }
protected override bool OnDragStart(DragStartEvent e) protected override bool OnDragStart(DragStartEvent e)
@ -98,13 +100,13 @@ namespace osu.Game.Graphics.Containers
if (!base.OnDragStart(e)) if (!base.OnDragStart(e))
return false; return false;
PlaylistDragActive.Value = true; DragActive.Value = true;
return true; return true;
} }
protected override void OnDragEnd(DragEndEvent e) protected override void OnDragEnd(DragEndEvent e)
{ {
PlaylistDragActive.Value = false; DragActive.Value = false;
base.OnDragEnd(e); base.OnDragEnd(e);
} }
@ -112,7 +114,7 @@ namespace osu.Game.Graphics.Containers
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
handle.UpdateHoverState(IsDragged || !PlaylistDragActive.Value); handle.UpdateHoverState(IsDragged || !DragActive.Value);
return base.OnHover(e); return base.OnHover(e);
} }

View File

@ -37,8 +37,6 @@ namespace osu.Game.Screens.Multi
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>(); public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
protected override bool ShowDragHandle => allowEdit;
private Container maskingContainer; private Container maskingContainer;
private Container difficultyIconContainer; private Container difficultyIconContainer;
private LinkFlowContainer beatmapText; private LinkFlowContainer beatmapText;
@ -63,12 +61,13 @@ namespace osu.Game.Screens.Multi
// TODO: edit support should be moved out into a derived class // TODO: edit support should be moved out into a derived class
this.allowEdit = allowEdit; this.allowEdit = allowEdit;
this.allowSelection = allowSelection; this.allowSelection = allowSelection;
beatmap.BindTo(item.Beatmap); beatmap.BindTo(item.Beatmap);
ruleset.BindTo(item.Ruleset); ruleset.BindTo(item.Ruleset);
requiredMods.BindTo(item.RequiredMods); requiredMods.BindTo(item.RequiredMods);
ShowDragHandle.Value = allowEdit;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]