1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +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

@ -1,212 +1,212 @@
using System;
using OpenTK;
using OpenTK.Input;
using OpenTK.Graphics;
using osu.Game.Graphics;
using osu.Framework.Input;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
using System;
using OpenTK;
using OpenTK.Input;
using OpenTK.Graphics;
using osu.Game.Graphics;
using osu.Framework.Input;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using System.Threading.Tasks;
namespace osu.Game.Overlays.Pause
{
public class PauseOverlay : OverlayContainer
{
private const int transition_duration = 200;
private const int button_height = 70;
private const float background_alpha = 0.75f;
public Action OnResume;
public Action OnRetry;
public Action OnQuit;
public int Retries
{
set
{
namespace osu.Game.Overlays.Pause
{
public class PauseOverlay : OverlayContainer
{
private const int transition_duration = 200;
private const int button_height = 70;
private const float background_alpha = 0.75f;
public Action OnResume;
public Action OnRetry;
public Action OnQuit;
public int Retries
{
set
{
if (retryCounterContainer != null)
{
// "You've retried 1,065 times in this session"
// "You've retried 1 time in this session"
// "You've retried 1 time in this session"
retryCounterContainer.Children = new Drawable[]
{
new SpriteText
{
Text = "You've retried ",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
},
new SpriteText
{
Text = String.Format("{0:n0}", value),
Font = @"Exo2.0-Bold",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
},
new SpriteText
{
Text = $" time{((value == 1) ? "" : "s")} in this session",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
{
new SpriteText
{
Text = "You've retried ",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
},
new SpriteText
{
Text = String.Format("{0:n0}", value),
Font = @"Exo2.0-Bold",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
},
new SpriteText
{
Text = $" time{((value == 1) ? "" : "s")} in this session",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
}
};
}
}
}
private FlowContainer retryCounterContainer;
public override bool Contains(Vector2 screenSpacePos) => true;
public override bool HandleInput => State == Visibility.Visible;
protected override void PopIn() => FadeIn(transition_duration, EasingTypes.In);
protected override void PopOut() => FadeOut(transition_duration, EasingTypes.In);
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Key == Key.Escape)
{
}
}
}
private FlowContainer retryCounterContainer;
public override bool Contains(Vector2 screenSpacePos) => true;
public override bool HandleInput => State == Visibility.Visible;
protected override void PopIn() => FadeIn(transition_duration, EasingTypes.In);
protected override void PopOut() => FadeOut(transition_duration, EasingTypes.In);
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Key == Key.Escape)
{
if (State == Visibility.Hidden) return false;
resume();
return true;
}
return base.OnKeyDown(state, args);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
return true;
}
return base.OnKeyDown(state, args);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = background_alpha,
},
new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0f, 50f),
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
new FlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0f, 20f),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Children = new Drawable[]
{
new SpriteText
{
Text = @"paused",
Font = @"Exo2.0-Medium",
Spacing = new Vector2(5, 0),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
TextSize = 30,
Colour = colours.Yellow,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
},
new SpriteText
{
Text = @"you're not going to do what i think you're going to do, are ya?",
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
}
}
},
new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Masking = true,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.6f),
Radius = 50
},
Children = new Drawable[]
{
new ResumeButton
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = resume
},
new RetryButton
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = delegate
{
Hide();
OnRetry?.Invoke();
}
},
new QuitButton
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = delegate
{
Hide();
OnQuit?.Invoke();
}
}
}
},
retryCounterContainer = new FlowContainer
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre
}
}
},
new PauseProgressBar
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Width = 1f
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = background_alpha,
},
new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0f, 50f),
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
new FlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0f, 20f),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Children = new Drawable[]
{
new SpriteText
{
Text = @"paused",
Font = @"Exo2.0-Medium",
Spacing = new Vector2(5, 0),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
TextSize = 30,
Colour = colours.Yellow,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
},
new SpriteText
{
Text = @"you're not going to do what i think you're going to do, are ya?",
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
}
}
},
new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Masking = true,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.6f),
Radius = 50
},
Children = new Drawable[]
{
new ResumeButton
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = resume
},
new RetryButton
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = delegate
{
Hide();
OnRetry?.Invoke();
}
},
new QuitButton
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = delegate
{
Hide();
OnQuit?.Invoke();
}
}
}
},
retryCounterContainer = new FlowContainer
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre
}
}
},
new PauseProgressBar
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Width = 1f
}
};
};
Retries = 0;
}
private void resume()
{
}
private void resume()
{
Hide();
OnResume?.Invoke();
}
OnResume?.Invoke();
}
public PauseOverlay()
{
RelativeSizeAxes = Axes.Both;
}
}
}
}
}

View File

@ -1,23 +1,23 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Game.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Beatmaps.Drawables;
using OpenTK;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Game.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Beatmaps.Drawables;
using osu.Framework.Timing;
using osu.Framework.Input;
using OpenTK.Input;
using System.Collections;
using osu.Framework.MathUtils;
using osu.Framework.MathUtils;
namespace osu.Game.Screens.Select
{
@ -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;
@ -298,17 +292,17 @@ namespace osu.Game.Screens.Select
}
return base.OnKeyDown(state, args);
}
public void SelectRandom()
{
if (groups.Count < 1)
return;
}
public void SelectRandom()
{
if (groups.Count < 1)
return;
BeatmapGroup group = groups[RNG.Next(groups.Count)];
BeatmapPanel panel = group?.BeatmapPanels.First();
if (panel == null)
return;
SelectGroup(group, panel);
BeatmapPanel panel = group?.BeatmapPanels.First();
if (panel == null)
return;
SelectGroup(group, panel);
}
public IEnumerator<BeatmapGroup> GetEnumerator() => groups.GetEnumerator();

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,24 +208,20 @@ 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);
}
private void onDatabaseOnBeatmapSetAdded(BeatmapSetInfo s)
{
Schedule(() => addBeatmapSet(s, Game, true));
@ -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>