mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 17:23:52 +08:00
Don't query GetContainingInputManager every Update.
This commit is contained in:
parent
ad966f41f5
commit
e9f0762440
@ -59,8 +59,6 @@ namespace osu.Game.Overlays.Music
|
|||||||
private readonly SearchContainer search;
|
private readonly SearchContainer search;
|
||||||
private readonly FillFlowContainer<PlaylistItem> items;
|
private readonly FillFlowContainer<PlaylistItem> items;
|
||||||
|
|
||||||
private PlaylistItem draggedItem;
|
|
||||||
|
|
||||||
public ItemsScrollContainer()
|
public ItemsScrollContainer()
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -127,14 +125,19 @@ namespace osu.Game.Overlays.Music
|
|||||||
public BeatmapSetInfo NextSet => (items.SkipWhile(i => !i.Selected).Skip(1).FirstOrDefault() ?? items.FirstOrDefault())?.BeatmapSetInfo;
|
public BeatmapSetInfo NextSet => (items.SkipWhile(i => !i.Selected).Skip(1).FirstOrDefault() ?? items.FirstOrDefault())?.BeatmapSetInfo;
|
||||||
public BeatmapSetInfo PreviousSet => (items.TakeWhile(i => !i.Selected).LastOrDefault() ?? items.LastOrDefault())?.BeatmapSetInfo;
|
public BeatmapSetInfo PreviousSet => (items.TakeWhile(i => !i.Selected).LastOrDefault() ?? items.LastOrDefault())?.BeatmapSetInfo;
|
||||||
|
|
||||||
|
private InputState dragInputState;
|
||||||
|
private PlaylistItem draggedItem;
|
||||||
|
|
||||||
protected override bool OnDragStart(InputState state)
|
protected override bool OnDragStart(InputState state)
|
||||||
{
|
{
|
||||||
|
dragInputState = state;
|
||||||
draggedItem = items.FirstOrDefault(d => d.IsDraggable);
|
draggedItem = items.FirstOrDefault(d => d.IsDraggable);
|
||||||
return draggedItem != null || base.OnDragStart(state);
|
return draggedItem != null || base.OnDragStart(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDrag(InputState state)
|
protected override bool OnDrag(InputState state)
|
||||||
{
|
{
|
||||||
|
dragInputState = state;
|
||||||
if (draggedItem == null)
|
if (draggedItem == null)
|
||||||
return base.OnDrag(state);
|
return base.OnDrag(state);
|
||||||
return true;
|
return true;
|
||||||
@ -142,6 +145,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
protected override bool OnDragEnd(InputState state)
|
protected override bool OnDragEnd(InputState state)
|
||||||
{
|
{
|
||||||
|
dragInputState = state;
|
||||||
var handled = draggedItem != null || base.OnDragEnd(state);
|
var handled = draggedItem != null || base.OnDragEnd(state);
|
||||||
draggedItem = null;
|
draggedItem = null;
|
||||||
|
|
||||||
@ -155,19 +159,17 @@ namespace osu.Game.Overlays.Music
|
|||||||
if (draggedItem == null)
|
if (draggedItem == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var mouseState = GetContainingInputManager().CurrentState.Mouse;
|
updateScrollPosition();
|
||||||
|
updateDragPosition();
|
||||||
updateScrollPosition(mouseState);
|
|
||||||
updateDragPosition(mouseState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateScrollPosition(IMouseState mouseState)
|
private void updateScrollPosition()
|
||||||
{
|
{
|
||||||
const float start_offset = 10;
|
const float start_offset = 10;
|
||||||
const double max_power = 50;
|
const double max_power = 50;
|
||||||
const double exp_base = 1.05;
|
const double exp_base = 1.05;
|
||||||
|
|
||||||
var localPos = ToLocalSpace(mouseState.Position);
|
var localPos = ToLocalSpace(dragInputState.Mouse.NativeState.Position);
|
||||||
|
|
||||||
if (localPos.Y < start_offset)
|
if (localPos.Y < start_offset)
|
||||||
{
|
{
|
||||||
@ -187,9 +189,9 @@ namespace osu.Game.Overlays.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDragPosition(IMouseState mouseState)
|
private void updateDragPosition()
|
||||||
{
|
{
|
||||||
var itemsPos = items.ToLocalSpace(mouseState.Position);
|
var itemsPos = items.ToLocalSpace(dragInputState.Mouse.NativeState.Position);
|
||||||
|
|
||||||
int srcIndex = (int)draggedItem.Depth;
|
int srcIndex = (int)draggedItem.Depth;
|
||||||
|
|
||||||
@ -250,4 +252,4 @@ namespace osu.Game.Overlays.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user