1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Fix laggy animations, incorrect hiding logic.

This commit is contained in:
Dean Herbert 2017-02-02 17:33:39 +09:00
parent c88a2fbf8a
commit aec84ae725
7 changed files with 247 additions and 265 deletions

View File

@ -38,25 +38,22 @@ namespace osu.Game.Beatmaps.Drawables
get { return state; }
set
{
Header.Alpha = value == BeatmapGroupState.Hidden ? 0 : 1;
switch (value)
{
case BeatmapGroupState.Expanded:
foreach (BeatmapPanel panel in BeatmapPanels)
panel.FadeIn(250);
Header.State = PanelSelectedState.Selected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.Selected;
foreach (BeatmapPanel panel in BeatmapPanels)
panel.State = panel == SelectedPanel ? PanelSelectedState.Selected : PanelSelectedState.NotSelected;
break;
case BeatmapGroupState.Collapsed:
case BeatmapGroupState.Hidden:
Header.State = PanelSelectedState.NotSelected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.NotSelected;
foreach (BeatmapPanel panel in BeatmapPanels)
panel.FadeOut(300, EasingTypes.OutQuint);
panel.State = PanelSelectedState.Hidden;
break;
case BeatmapGroupState.Hidden:
Header.State = PanelSelectedState.Hidden;
foreach (BeatmapPanel panel in BeatmapPanels)
panel.State = PanelSelectedState.Hidden;
break;
}
state = value;

View File

@ -2,14 +2,11 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.MathUtils;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
@ -17,7 +14,6 @@ using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Input;
using osu.Game.Modes;
namespace osu.Game.Beatmaps.Drawables
{
@ -33,6 +29,7 @@ namespace osu.Game.Beatmaps.Drawables
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
background.ColourInfo = ColourInfo.GradientVertical(

View File

@ -68,12 +68,6 @@ namespace osu.Game.Beatmaps.Drawables
};
}
protected override void LoadComplete()
{
base.LoadComplete();
FadeInFromZero(250);
}
protected override void Selected()
{
base.Selected();

View File

@ -55,6 +55,7 @@ namespace osu.Game.Beatmaps.Drawables
{
switch (state)
{
case PanelSelectedState.Hidden:
case PanelSelectedState.NotSelected:
Deselected();
break;
@ -62,6 +63,11 @@ namespace osu.Game.Beatmaps.Drawables
Selected();
break;
}
if (state == PanelSelectedState.Hidden)
FadeOut(300, EasingTypes.OutQuint);
else
FadeIn(250);
}
private PanelSelectedState state = PanelSelectedState.NotSelected;
@ -112,6 +118,7 @@ namespace osu.Game.Beatmaps.Drawables
enum PanelSelectedState
{
Hidden,
NotSelected,
Selected
}

View File

@ -97,10 +97,10 @@ namespace osu.Game.Screens.Select
computeYPositions();
}
private void movePanel(Panel panel, bool advance, ref float currentY)
private void movePanel(Panel panel, bool advance, bool animated, ref float currentY)
{
yPositions.Add(currentY);
panel.MoveToY(currentY, 750, EasingTypes.OutExpo);
panel.MoveToY(currentY, animated && (panel.IsOnScreen || panel.State != PanelSelectedState.Hidden) ? 750 : 0, EasingTypes.OutExpo);
if (advance)
currentY += panel.DrawHeight + 5;
@ -110,7 +110,7 @@ namespace osu.Game.Screens.Select
/// Computes the target Y positions for every panel in the carousel.
/// </summary>
/// <returns>The Y position of the currently selected panel.</returns>
private float computeYPositions()
private float computeYPositions(bool animated = true)
{
yPositions.Clear();
@ -119,7 +119,7 @@ namespace osu.Game.Screens.Select
foreach (BeatmapGroup group in groups)
{
movePanel(group.Header, group.State != BeatmapGroupState.Hidden, ref currentY);
movePanel(group.Header, group.State != BeatmapGroupState.Hidden, animated, ref currentY);
if (group.State == BeatmapGroupState.Expanded)
{
@ -137,7 +137,7 @@ namespace osu.Game.Screens.Select
if (panel.Alpha == 0)
panel.MoveToY(headerY);
movePanel(panel, true, ref currentY);
movePanel(panel, true, animated, ref currentY);
}
}
else
@ -147,7 +147,7 @@ namespace osu.Game.Screens.Select
foreach (BeatmapPanel panel in group.BeatmapPanels)
{
panel.MoveToX(0, 500, EasingTypes.OutExpo);
movePanel(panel, false, ref currentY);
movePanel(panel, false, animated, ref currentY);
}
}
}
@ -158,20 +158,20 @@ namespace osu.Game.Screens.Select
return selectedY;
}
public void SelectBeatmap(BeatmapInfo beatmap)
public void SelectBeatmap(BeatmapInfo beatmap, bool animated = true)
{
foreach (BeatmapGroup group in groups)
{
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (panel != null)
{
SelectGroup(group, panel);
SelectGroup(group, panel, animated);
return;
}
}
}
public void SelectGroup(BeatmapGroup group, BeatmapPanel panel)
public void SelectGroup(BeatmapGroup group, BeatmapPanel panel, bool animated = true)
{
if (SelectedGroup != null && SelectedGroup != group)
SelectedGroup.State = BeatmapGroupState.Collapsed;
@ -180,8 +180,8 @@ namespace osu.Game.Screens.Select
panel.State = PanelSelectedState.Selected;
SelectedPanel = panel;
float selectedY = computeYPositions();
ScrollTo(selectedY);
float selectedY = computeYPositions(animated);
ScrollTo(selectedY, animated);
}
private static float offsetX(float dist, float halfHeight)
@ -246,18 +246,12 @@ namespace osu.Game.Screens.Select
for (int i = firstIndex; i < lastIndex; ++i)
{
Panel p = Lifetime[i];
p.IsOnScreen = true;
if (p.State != PanelSelectedState.Hidden)
p.IsOnScreen = true; //we don't want to update the on-screen state of hidden pannels as they have incorrect (stacked) y values.
updatePanel(p, halfHeight);
}
}
public void InvalidateVisible()
{
Lifetime.StartIndex = 0;
Lifetime.EndIndex = groups.Count - 1;
computeYPositions();
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
int direction = 0;

View File

@ -146,7 +146,7 @@ namespace osu.Game.Screens.Select
Position = wedged_container_start_position,
RelativeSizeAxes = Axes.X,
FilterChanged = filterChanged,
Exit = () => Exit(),
Exit = Exit,
},
beatmapInfoWedge = new BeatmapInfoWedge
{
@ -198,7 +198,6 @@ namespace osu.Game.Screens.Select
filterTask = null;
var search = filter.Search;
BeatmapGroup newSelection = null;
bool changed = false;
foreach (var beatmapGroup in carousel)
{
var set = beatmapGroup.BeatmapSet;
@ -209,21 +208,17 @@ namespace osu.Game.Screens.Select
|| (set.Metadata.TitleUnicode ?? "").IndexOf(search, StringComparison.InvariantCultureIgnoreCase) != -1;
if (match)
{
changed |= beatmapGroup.State != BeatmapGroupState.Hidden;
beatmapGroup.State = BeatmapGroupState.Collapsed;
if (newSelection == null || beatmapGroup.BeatmapSet.OnlineBeatmapSetID == Beatmap.BeatmapSetInfo.OnlineBeatmapSetID)
newSelection = beatmapGroup;
}
else
{
changed |= beatmapGroup.State == BeatmapGroupState.Hidden;
beatmapGroup.State = BeatmapGroupState.Hidden;
}
}
if (newSelection != null)
selectBeatmap(newSelection.BeatmapSet.Beatmaps[0]);
if (changed)
carousel.InvalidateVisible();
carousel.SelectBeatmap(newSelection.BeatmapSet.Beatmaps[0], false);
}, 250);
}
@ -320,11 +315,9 @@ namespace osu.Game.Screens.Select
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
changeBackground(beatmap);
selectBeatmap(beatmap.BeatmapInfo);
carousel.SelectBeatmap(beatmap.BeatmapInfo);
}
private void selectBeatmap(BeatmapInfo beatmap) => carousel.SelectBeatmap(beatmap);
/// <summary>
/// selection has been changed as the result of interaction with the carousel.
/// </summary>