1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 14:52:57 +08:00

More clean-ups and event bindings

This commit is contained in:
Dean Herbert 2017-12-13 12:46:02 +09:00
parent 78dd975a35
commit 99b00143eb
9 changed files with 116 additions and 152 deletions

View File

@ -20,7 +20,7 @@ namespace osu.Game.Configuration
Set(OsuSetting.DisplayStarsMinimum, 0.0, 0, 10, 0.1); Set(OsuSetting.DisplayStarsMinimum, 0.0, 0, 10, 0.1);
Set(OsuSetting.DisplayStarsMaximum, 10.0, 0, 10, 0.1); Set(OsuSetting.DisplayStarsMaximum, 10.0, 0, 10, 0.1);
Set(OsuSetting.SelectionRandomType, SelectionRandomType.RandomPermutation); Set(OsuSetting.SelectionRandomType, SongSelectRandomMode.RandomPermutation);
Set(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2, 1); Set(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2, 1);

View File

@ -5,7 +5,7 @@ using System.ComponentModel;
namespace osu.Game.Configuration namespace osu.Game.Configuration
{ {
public enum SelectionRandomType public enum SongSelectRandomMode
{ {
[Description("Never repeat")] [Description("Never repeat")]
RandomPermutation, RandomPermutation,

View File

@ -34,10 +34,10 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
Bindable = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum), Bindable = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum),
KeyboardStep = 1f KeyboardStep = 1f
}, },
new SettingsEnumDropdown<SelectionRandomType> new SettingsEnumDropdown<SongSelectRandomMode>
{ {
LabelText = "Random beatmap selection", LabelText = "Random beatmap selection",
Bindable = config.GetBindable<SelectionRandomType>(OsuSetting.SelectionRandomType), Bindable = config.GetBindable<SongSelectRandomMode>(OsuSetting.SelectionRandomType),
} }
}; };
} }

View File

@ -52,7 +52,7 @@ namespace osu.Game.Screens.Select
Schedule(() => Schedule(() =>
{ {
foreach (var g in newSets) foreach (var g in newSets)
addGroup(g); addBeatmapSet(g);
root = new CarouselGroup(newSets.OfType<CarouselItem>().ToList()); root = new CarouselGroup(newSets.OfType<CarouselItem>().ToList());
items = root.Drawables.Value.ToList(); items = root.Drawables.Value.ToList();
@ -65,12 +65,13 @@ namespace osu.Game.Screens.Select
} }
private readonly List<float> yPositions = new List<float>(); private readonly List<float> yPositions = new List<float>();
private Cached yPositionsCache = new Cached();
private readonly Container<DrawableCarouselItem> scrollableContent; private readonly Container<DrawableCarouselItem> scrollableContent;
private readonly List<CarouselBeatmapSet> carouselSets = new List<CarouselBeatmapSet>(); private readonly List<CarouselBeatmapSet> carouselSets = new List<CarouselBeatmapSet>();
private Bindable<SelectionRandomType> randomType; private Bindable<SongSelectRandomMode> randomType;
private readonly List<CarouselBeatmapSet> seenSets = new List<CarouselBeatmapSet>(); private readonly List<CarouselBeatmapSet> seenSets = new List<CarouselBeatmapSet>();
private List<DrawableCarouselItem> items = new List<DrawableCarouselItem>(); private List<DrawableCarouselItem> items = new List<DrawableCarouselItem>();
@ -95,7 +96,7 @@ namespace osu.Game.Screens.Select
public void RemoveBeatmap(BeatmapSetInfo beatmapSet) public void RemoveBeatmap(BeatmapSetInfo beatmapSet)
{ {
Schedule(() => removeGroup(carouselSets.Find(b => b.BeatmapSet.ID == beatmapSet.ID))); Schedule(() => removeBeatmapSet(carouselSets.Find(b => b.BeatmapSet.ID == beatmapSet.ID)));
} }
public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet) public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet)
@ -116,7 +117,7 @@ namespace osu.Game.Screens.Select
if (index >= 0) if (index >= 0)
carouselSets.Insert(index, newSet); carouselSets.Insert(index, newSet);
else else
addGroup(newSet); addBeatmapSet(newSet);
} }
if (hadSelection && newSet == null) if (hadSelection && newSet == null)
@ -151,7 +152,7 @@ namespace osu.Game.Screens.Select
var item = group.Beatmaps.FirstOrDefault(p => p.Beatmap.Equals(beatmap)); var item = group.Beatmaps.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (item != null) if (item != null)
{ {
select(item, animated); select(item);
return; return;
} }
} }
@ -220,7 +221,7 @@ namespace osu.Game.Screens.Select
CarouselBeatmapSet group; CarouselBeatmapSet group;
if (randomType == SelectionRandomType.RandomPermutation) if (randomType == SongSelectRandomMode.RandomPermutation)
{ {
var notSeenGroups = visibleGroups.Except(seenSets); var notSeenGroups = visibleGroups.Except(seenSets);
if (!notSeenGroups.Any()) if (!notSeenGroups.Any())
@ -337,10 +338,10 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
randomType = config.GetBindable<SelectionRandomType>(OsuSetting.SelectionRandomType); randomType = config.GetBindable<SongSelectRandomMode>(OsuSetting.SelectionRandomType);
} }
private void addGroup(CarouselBeatmapSet set) private void addBeatmapSet(CarouselBeatmapSet set)
{ {
// prevent duplicates by concurrent independent actions trying to add a group // prevent duplicates by concurrent independent actions trying to add a group
//todo: check this //todo: check this
@ -351,19 +352,11 @@ namespace osu.Game.Screens.Select
carouselSets.Add(set); carouselSets.Add(set);
} }
private void removeGroup(CarouselBeatmapSet set) private void removeBeatmapSet(CarouselBeatmapSet set)
{ {
if (set == null) if (set == null)
return; return;
if (set.State == CarouselItemState.Selected)
{
if (getVisibleGroups().Count() == 1)
selectNullBeatmap();
else
SelectNext();
}
carouselSets.Remove(set); carouselSets.Remove(set);
foreach (var d in set.Drawables.Value) foreach (var d in set.Drawables.Value)
@ -372,11 +365,12 @@ namespace osu.Game.Screens.Select
scrollableContent.Remove(d); scrollableContent.Remove(d);
} }
if (set.State == CarouselItemState.Selected)
SelectNext();
yPositionsCache.Invalidate(); yPositionsCache.Invalidate();
} }
private Cached yPositionsCache = new Cached();
/// <summary> /// <summary>
/// Computes the target Y positions for every item in the carousel. /// Computes the target Y positions for every item in the carousel.
/// </summary> /// </summary>
@ -396,10 +390,7 @@ namespace osu.Game.Screens.Select
{ {
case DrawableCarouselBeatmapSet set: case DrawableCarouselBeatmapSet set:
set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo); set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo);
lastSetY = set.Position.Y; lastSetY = set.Position.Y;
movePanel(set, set.Item.Visible, animated, ref currentY);
break; break;
case DrawableCarouselBeatmap beatmap: case DrawableCarouselBeatmap beatmap:
beatmap.MoveToX(beatmap.Item.State == CarouselItemState.Selected ? -50 : 0, 500, Easing.OutExpo); beatmap.MoveToX(beatmap.Item.State == CarouselItemState.Selected ? -50 : 0, 500, Easing.OutExpo);
@ -410,10 +401,14 @@ namespace osu.Game.Screens.Select
// on first display we want to begin hidden under our group's header. // on first display we want to begin hidden under our group's header.
if (animated && !beatmap.IsPresent) if (animated && !beatmap.IsPresent)
beatmap.MoveToY(lastSetY); beatmap.MoveToY(lastSetY);
movePanel(beatmap, beatmap.Item.Visible, animated, ref currentY);
break; break;
} }
yPositions.Add(currentY);
d.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
if (d.Item.Visible)
currentY += d.DrawHeight + 5;
} }
currentY += DrawHeight / 2; currentY += DrawHeight / 2;
@ -424,25 +419,11 @@ namespace osu.Game.Screens.Select
return selectedY; return selectedY;
} }
private void movePanel(DrawableCarouselItem item, bool advance, bool animated, ref float currentY) private void select(CarouselItem item)
{ {
yPositions.Add(currentY); if (item == null) return;
item.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
if (advance) item.State.Value = CarouselItemState.Selected;
currentY += item.DrawHeight + 5;
}
private void select(CarouselBeatmapSet beatmapSet = null)
{
if (beatmapSet == null) return;
beatmapSet.State.Value = CarouselItemState.Selected;
}
private void select(CarouselBeatmap beatmap = null, bool animated = true)
{
if (beatmap == null) return;
beatmap.State.Value = CarouselItemState.Selected;
} }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)

View File

@ -17,19 +17,13 @@ namespace osu.Game.Screens.Select.Carousel
State.Value = CarouselItemState.Hidden; State.Value = CarouselItemState.Hidden;
} }
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this) protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
{
/*GainedSelection = panelGainedSelection,
HideRequested = p => HideDifficultyRequested?.Invoke(p),
StartRequested = p => StartRequested?.Invoke(p.beatmap),
EditRequested = p => EditRequested?.Invoke(p.beatmap),*/
};
public override void Filter(FilterCriteria criteria) public override void Filter(FilterCriteria criteria)
{ {
base.Filter(criteria); base.Filter(criteria);
bool match = criteria.Ruleset == null || (Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps); bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps;
if (!string.IsNullOrEmpty(criteria.SearchText)) if (!string.IsNullOrEmpty(criteria.SearchText))
match &= match &=

View File

@ -36,10 +36,11 @@ namespace osu.Game.Screens.Select.Carousel
private readonly StarCounter starCounter; private readonly StarCounter starCounter;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(SongSelect songSelect) private void load(SongSelect songSelect, BeatmapManager manager)
{ {
StartRequested = songSelect.Start; StartRequested = songSelect.Start;
EditRequested = songSelect.Edit; EditRequested = songSelect.Edit;
HideRequested = manager.Hide;
} }
public DrawableCarouselBeatmap(CarouselBeatmap panel) public DrawableCarouselBeatmap(CarouselBeatmap panel)

View File

@ -24,10 +24,7 @@ namespace osu.Game.Screens.Select.Carousel
{ {
public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
{ {
public Action<DrawableCarouselBeatmapSet> GainedSelection;
public Action<BeatmapSetInfo> DeleteRequested; public Action<BeatmapSetInfo> DeleteRequested;
public Action<BeatmapSetInfo> RestoreHiddenRequested; public Action<BeatmapSetInfo> RestoreHiddenRequested;
private readonly BeatmapSetInfo beatmapSet; private readonly BeatmapSetInfo beatmapSet;
@ -40,18 +37,15 @@ namespace osu.Game.Screens.Select.Carousel
beatmapSet = set.BeatmapSet; beatmapSet = set.BeatmapSet;
} }
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(LocalisationEngine localisation, BeatmapManager manager) private void load(LocalisationEngine localisation, BeatmapManager manager)
{ {
if (localisation == null) if (localisation == null)
throw new ArgumentNullException(nameof(localisation)); throw new ArgumentNullException(nameof(localisation));
RestoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
DeleteRequested = manager.Delete;
var working = manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()); var working = manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault());
Children = new Drawable[] Children = new Drawable[]
@ -61,7 +55,8 @@ namespace osu.Game.Screens.Select.Carousel
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out), OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
}, 300), }, 300
),
new FillFlowContainer new FillFlowContainer
{ {
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
@ -94,6 +89,24 @@ namespace osu.Game.Screens.Select.Carousel
}; };
} }
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (Item.State == CarouselItemState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.Beatmaps.Any(b => b.Hidden))
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => RestoreHiddenRequested?.Invoke(beatmapSet)));
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke(beatmapSet)));
return items.ToArray();
}
}
private class PanelBackground : BufferedContainer private class PanelBackground : BufferedContainer
{ {
public PanelBackground(WorkingBeatmap working) public PanelBackground(WorkingBeatmap working)
@ -130,22 +143,19 @@ namespace osu.Game.Screens.Select.Carousel
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal( Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f, Width = 0.05f,
}, },
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal( Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Width = 0.2f, Width = 0.2f,
}, },
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal( Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f, Width = 0.05f,
}, },
} }
@ -154,24 +164,6 @@ namespace osu.Game.Screens.Select.Carousel
} }
} }
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (Item.State == CarouselItemState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.Beatmaps.Any(b => b.Hidden))
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => RestoreHiddenRequested?.Invoke(beatmapSet)));
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke(beatmapSet)));
return items.ToArray();
}
}
public class FilterableDifficultyIcon : DifficultyIcon public class FilterableDifficultyIcon : DifficultyIcon
{ {
private readonly BindableBool filtered = new BindableBool(); private readonly BindableBool filtered = new BindableBool();

View File

@ -76,68 +76,68 @@ namespace osu.Game.Screens.Select
const float carousel_width = 640; const float carousel_width = 640;
const float filter_height = 100; const float filter_height = 100;
Add(new ParallaxContainer AddRange(new Drawable[]
{ {
Padding = new MarginPadding { Top = filter_height }, new ParallaxContainer
ParallaxAmount = 0.005f,
RelativeSizeAxes = Axes.Both,
Children = new[]
{ {
new WedgeBackground Padding = new MarginPadding { Top = filter_height },
ParallaxAmount = 0.005f,
RelativeSizeAxes = Axes.Both,
Children = new[]
{ {
RelativeSizeAxes = Axes.Both, new WedgeBackground
Padding = new MarginPadding { Right = carousel_width * 0.76f }, {
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = carousel_width * 0.76f },
}
} }
}
});
Add(LeftContent = new Container
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(wedged_container_size.X, 1),
Padding = new MarginPadding
{
Bottom = 50,
Top = wedged_container_size.Y + left_area_padding,
Left = left_area_padding,
Right = left_area_padding * 2,
}
});
Add(carousel = new BeatmapCarousel
{
RelativeSizeAxes = Axes.Y,
Size = new Vector2(carousel_width, 1),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
//todo: clicking play on another map doesn't work bindable disabled
SelectionChanged = carouselSelectionChanged,
BeatmapsChanged = carouselBeatmapsLoaded,
//RestoreRequested = s => { foreach (var b in s.Beatmaps) beatmaps.Restore(b); },
});
Add(FilterControl = new FilterControl
{
RelativeSizeAxes = Axes.X,
Height = filter_height,
FilterChanged = criteria => filterChanged(criteria),
Exit = Exit,
});
Add(beatmapInfoWedge = new BeatmapInfoWedge
{
Alpha = 0,
Size = wedged_container_size,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Top = left_area_padding,
Right = left_area_padding,
}, },
}); LeftContent = new Container
Add(new ResetScrollContainer(() => carousel.ScrollToSelected()) {
{ Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Y, Anchor = Anchor.BottomLeft,
Width = 250, RelativeSizeAxes = Axes.Both,
Size = new Vector2(wedged_container_size.X, 1),
Padding = new MarginPadding
{
Bottom = 50,
Top = wedged_container_size.Y + left_area_padding,
Left = left_area_padding,
Right = left_area_padding * 2,
}
},
carousel = new BeatmapCarousel
{
RelativeSizeAxes = Axes.Y,
Size = new Vector2(carousel_width, 1),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
SelectionChanged = carouselSelectionChanged,
BeatmapsChanged = carouselBeatmapsLoaded,
},
FilterControl = new FilterControl
{
RelativeSizeAxes = Axes.X,
Height = filter_height,
FilterChanged = c => carousel.Filter(c),
Exit = Exit,
},
beatmapInfoWedge = new BeatmapInfoWedge
{
Alpha = 0,
Size = wedged_container_size,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Top = left_area_padding,
Right = left_area_padding,
},
},
new ResetScrollContainer(() => carousel.ScrollToSelected())
{
RelativeSizeAxes = Axes.Y,
Width = 250,
}
}); });
if (ShowFooter) if (ShowFooter)
@ -309,11 +309,6 @@ namespace osu.Game.Screens.Select
protected abstract void Start(); protected abstract void Start();
private void filterChanged(FilterCriteria criteria, bool debounce = true)
{
carousel.Filter(criteria, debounce);
}
private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => carousel.UpdateBeatmapSet(s)); private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => carousel.UpdateBeatmapSet(s));
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => removeBeatmapSet(s)); private void onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => removeBeatmapSet(s));
@ -489,6 +484,7 @@ namespace osu.Game.Screens.Select
Delete(Beatmap.Value.BeatmapSetInfo); Delete(Beatmap.Value.BeatmapSetInfo);
return true; return true;
} }
break; break;
} }

View File

@ -343,7 +343,7 @@
<Compile Include="Configuration\ReleaseStream.cs" /> <Compile Include="Configuration\ReleaseStream.cs" />
<Compile Include="Configuration\ScoreMeterType.cs" /> <Compile Include="Configuration\ScoreMeterType.cs" />
<Compile Include="Configuration\ScreenshotFormat.cs" /> <Compile Include="Configuration\ScreenshotFormat.cs" />
<Compile Include="Configuration\SelectionRandomType.cs" /> <Compile Include="Configuration\SongSelectRandomMode.cs" />
<Compile Include="Database\DatabaseBackedStore.cs" /> <Compile Include="Database\DatabaseBackedStore.cs" />
<Compile Include="Database\OsuDbContext.cs" /> <Compile Include="Database\OsuDbContext.cs" />
<Compile Include="Graphics\Backgrounds\Background.cs" /> <Compile Include="Graphics\Backgrounds\Background.cs" />