mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:53:04 +08:00
Clean up selection handling
This commit is contained in:
parent
6a466ea2f5
commit
aceba8791c
@ -46,6 +46,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
moveToItem(0);
|
moveToItem(0);
|
||||||
assertHandleVisibility(0, false);
|
assertHandleVisibility(0, false);
|
||||||
assertDeleteButtonVisibility(0, false);
|
assertDeleteButtonVisibility(0, false);
|
||||||
|
|
||||||
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
||||||
|
AddAssert("no item selected", () => playlist.SelectedItem.Value == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -56,6 +59,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
moveToItem(0);
|
moveToItem(0);
|
||||||
assertHandleVisibility(0, true);
|
assertHandleVisibility(0, true);
|
||||||
assertDeleteButtonVisibility(0, true);
|
assertDeleteButtonVisibility(0, true);
|
||||||
|
|
||||||
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
||||||
|
AddAssert("no item selected", () => playlist.SelectedItem.Value == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -165,7 +171,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
moveToDeleteButton(0);
|
moveToDeleteButton(0);
|
||||||
AddStep("click delete button", () => InputManager.Click(MouseButton.Left));
|
AddStep("click delete button", () => InputManager.Click(MouseButton.Left));
|
||||||
|
|
||||||
AddAssert("selected item is null", () => playlist.SelectedItem.Value == null);
|
AddAssert("no item selected", () => playlist.SelectedItem.Value == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: currently not possible due to bindable list shortcomings (https://github.com/ppy/osu-framework/issues/3081)
|
// Todo: currently not possible due to bindable list shortcomings (https://github.com/ppy/osu-framework/issues/3081)
|
||||||
|
@ -28,15 +28,7 @@ namespace osu.Game.Screens.Multi
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
SelectedItem.BindValueChanged(item =>
|
// Scheduled since items are removed and re-added upon rearrangement
|
||||||
{
|
|
||||||
if (item.OldValue != null && ItemMap.TryGetValue(item.OldValue, out var oldItem))
|
|
||||||
((DrawableRoomPlaylistItem)oldItem).Deselect();
|
|
||||||
|
|
||||||
if (item.NewValue != null && ItemMap.TryGetValue(item.NewValue, out var newItem))
|
|
||||||
((DrawableRoomPlaylistItem)newItem).Select();
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
Items.ItemsRemoved += items => Schedule(() =>
|
Items.ItemsRemoved += items => Schedule(() =>
|
||||||
{
|
{
|
||||||
if (!Items.Contains(SelectedItem.Value))
|
if (!Items.Contains(SelectedItem.Value))
|
||||||
@ -58,7 +50,7 @@ namespace osu.Game.Screens.Multi
|
|||||||
|
|
||||||
protected override OsuRearrangeableListItem<PlaylistItem> CreateOsuDrawable(PlaylistItem item) => new DrawableRoomPlaylistItem(item, allowEdit, allowSelection)
|
protected override OsuRearrangeableListItem<PlaylistItem> CreateOsuDrawable(PlaylistItem item) => new DrawableRoomPlaylistItem(item, allowEdit, allowSelection)
|
||||||
{
|
{
|
||||||
RequestSelection = requestSelection,
|
SelectedItem = { BindTarget = SelectedItem },
|
||||||
RequestDeletion = requestDeletion
|
RequestDeletion = requestDeletion
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,9 +31,10 @@ namespace osu.Game.Screens.Multi
|
|||||||
{
|
{
|
||||||
public class DrawableRoomPlaylistItem : OsuRearrangeableListItem<PlaylistItem>
|
public class DrawableRoomPlaylistItem : OsuRearrangeableListItem<PlaylistItem>
|
||||||
{
|
{
|
||||||
public Action<PlaylistItem> RequestSelection;
|
|
||||||
public Action<PlaylistItem> RequestDeletion;
|
public Action<PlaylistItem> RequestDeletion;
|
||||||
|
|
||||||
|
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||||
|
|
||||||
protected override bool ShowDragHandle => allowEdit;
|
protected override bool ShowDragHandle => allowEdit;
|
||||||
|
|
||||||
private Container maskingContainer;
|
private Container maskingContainer;
|
||||||
@ -75,6 +76,8 @@ namespace osu.Game.Screens.Multi
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
SelectedItem.BindValueChanged(selected => maskingContainer.BorderThickness = selected.NewValue == Model ? 5 : 0);
|
||||||
|
|
||||||
beatmap.BindValueChanged(_ => scheduleRefresh());
|
beatmap.BindValueChanged(_ => scheduleRefresh());
|
||||||
ruleset.BindValueChanged(_ => scheduleRefresh());
|
ruleset.BindValueChanged(_ => scheduleRefresh());
|
||||||
|
|
||||||
@ -84,6 +87,32 @@ namespace osu.Game.Screens.Multi
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ScheduledDelegate scheduledRefresh;
|
||||||
|
|
||||||
|
private void scheduleRefresh()
|
||||||
|
{
|
||||||
|
scheduledRefresh?.Cancel();
|
||||||
|
scheduledRefresh = Schedule(refresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refresh()
|
||||||
|
{
|
||||||
|
difficultyIconContainer.Child = new DifficultyIcon(beatmap.Value, ruleset.Value) { Size = new Vector2(32) };
|
||||||
|
|
||||||
|
beatmapText.Clear();
|
||||||
|
beatmapText.AddLink(item.Beatmap.ToString(), LinkAction.OpenBeatmap, item.Beatmap.Value.OnlineBeatmapID.ToString());
|
||||||
|
|
||||||
|
authorText.Clear();
|
||||||
|
|
||||||
|
if (item.Beatmap?.Value?.Metadata?.Author != null)
|
||||||
|
{
|
||||||
|
authorText.AddText("mapped by ");
|
||||||
|
authorText.AddUserLink(item.Beatmap.Value?.Metadata.Author);
|
||||||
|
}
|
||||||
|
|
||||||
|
modDisplay.Current.Value = requiredMods.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
protected override Drawable CreateContent() => maskingContainer = new Container
|
protected override Drawable CreateContent() => maskingContainer = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
@ -173,43 +202,13 @@ namespace osu.Game.Screens.Multi
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private ScheduledDelegate scheduledRefresh;
|
|
||||||
|
|
||||||
private void scheduleRefresh()
|
|
||||||
{
|
|
||||||
scheduledRefresh?.Cancel();
|
|
||||||
scheduledRefresh = Schedule(refresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refresh()
|
|
||||||
{
|
|
||||||
difficultyIconContainer.Child = new DifficultyIcon(beatmap.Value, ruleset.Value) { Size = new Vector2(32) };
|
|
||||||
|
|
||||||
beatmapText.Clear();
|
|
||||||
beatmapText.AddLink(item.Beatmap.ToString(), LinkAction.OpenBeatmap, item.Beatmap.Value.OnlineBeatmapID.ToString());
|
|
||||||
|
|
||||||
authorText.Clear();
|
|
||||||
|
|
||||||
if (item.Beatmap?.Value?.Metadata?.Author != null)
|
|
||||||
{
|
|
||||||
authorText.AddText("mapped by ");
|
|
||||||
authorText.AddUserLink(item.Beatmap.Value?.Metadata.Author);
|
|
||||||
}
|
|
||||||
|
|
||||||
modDisplay.Current.Value = requiredMods.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (allowSelection)
|
if (allowSelection)
|
||||||
RequestSelection?.Invoke(Model);
|
SelectedItem.Value = Model;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Select() => maskingContainer.BorderThickness = 5;
|
|
||||||
|
|
||||||
public void Deselect() => maskingContainer.BorderThickness = 0;
|
|
||||||
|
|
||||||
// For now, this is the same implementation as in PanelBackground, but supports a beatmap info rather than a working beatmap
|
// For now, this is the same implementation as in PanelBackground, but supports a beatmap info rather than a working beatmap
|
||||||
private class PanelBackground : Container // todo: should be a buffered container (https://github.com/ppy/osu-framework/issues/3222)
|
private class PanelBackground : Container // todo: should be a buffered container (https://github.com/ppy/osu-framework/issues/3222)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user