1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +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.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);

View File

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

View File

@ -34,10 +34,10 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
Bindable = config.GetBindable<double>(OsuSetting.DisplayStarsMaximum),
KeyboardStep = 1f
},
new SettingsEnumDropdown<SelectionRandomType>
new SettingsEnumDropdown<SongSelectRandomMode>
{
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(() =>
{
foreach (var g in newSets)
addGroup(g);
addBeatmapSet(g);
root = new CarouselGroup(newSets.OfType<CarouselItem>().ToList());
items = root.Drawables.Value.ToList();
@ -65,12 +65,13 @@ namespace osu.Game.Screens.Select
}
private readonly List<float> yPositions = new List<float>();
private Cached yPositionsCache = new Cached();
private readonly Container<DrawableCarouselItem> scrollableContent;
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 List<DrawableCarouselItem> items = new List<DrawableCarouselItem>();
@ -95,7 +96,7 @@ namespace osu.Game.Screens.Select
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)
@ -116,7 +117,7 @@ namespace osu.Game.Screens.Select
if (index >= 0)
carouselSets.Insert(index, newSet);
else
addGroup(newSet);
addBeatmapSet(newSet);
}
if (hadSelection && newSet == null)
@ -151,7 +152,7 @@ namespace osu.Game.Screens.Select
var item = group.Beatmaps.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (item != null)
{
select(item, animated);
select(item);
return;
}
}
@ -220,7 +221,7 @@ namespace osu.Game.Screens.Select
CarouselBeatmapSet group;
if (randomType == SelectionRandomType.RandomPermutation)
if (randomType == SongSelectRandomMode.RandomPermutation)
{
var notSeenGroups = visibleGroups.Except(seenSets);
if (!notSeenGroups.Any())
@ -337,10 +338,10 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader(permitNulls: true)]
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
//todo: check this
@ -351,19 +352,11 @@ namespace osu.Game.Screens.Select
carouselSets.Add(set);
}
private void removeGroup(CarouselBeatmapSet set)
private void removeBeatmapSet(CarouselBeatmapSet set)
{
if (set == null)
return;
if (set.State == CarouselItemState.Selected)
{
if (getVisibleGroups().Count() == 1)
selectNullBeatmap();
else
SelectNext();
}
carouselSets.Remove(set);
foreach (var d in set.Drawables.Value)
@ -372,11 +365,12 @@ namespace osu.Game.Screens.Select
scrollableContent.Remove(d);
}
if (set.State == CarouselItemState.Selected)
SelectNext();
yPositionsCache.Invalidate();
}
private Cached yPositionsCache = new Cached();
/// <summary>
/// Computes the target Y positions for every item in the carousel.
/// </summary>
@ -396,10 +390,7 @@ namespace osu.Game.Screens.Select
{
case DrawableCarouselBeatmapSet set:
set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo);
lastSetY = set.Position.Y;
movePanel(set, set.Item.Visible, animated, ref currentY);
break;
case DrawableCarouselBeatmap beatmap:
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.
if (animated && !beatmap.IsPresent)
beatmap.MoveToY(lastSetY);
movePanel(beatmap, beatmap.Item.Visible, animated, ref currentY);
break;
}
yPositions.Add(currentY);
d.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
if (d.Item.Visible)
currentY += d.DrawHeight + 5;
}
currentY += DrawHeight / 2;
@ -424,25 +419,11 @@ namespace osu.Game.Screens.Select
return selectedY;
}
private void movePanel(DrawableCarouselItem item, bool advance, bool animated, ref float currentY)
private void select(CarouselItem item)
{
yPositions.Add(currentY);
item.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
if (item == null) return;
if (advance)
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;
item.State.Value = CarouselItemState.Selected;
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)

View File

@ -17,19 +17,13 @@ namespace osu.Game.Screens.Select.Carousel
State.Value = CarouselItemState.Hidden;
}
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),*/
};
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
public override void Filter(FilterCriteria 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))
match &=

View File

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

View File

@ -24,10 +24,7 @@ namespace osu.Game.Screens.Select.Carousel
{
public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
{
public Action<DrawableCarouselBeatmapSet> GainedSelection;
public Action<BeatmapSetInfo> DeleteRequested;
public Action<BeatmapSetInfo> RestoreHiddenRequested;
private readonly BeatmapSetInfo beatmapSet;
@ -40,18 +37,15 @@ namespace osu.Game.Screens.Select.Carousel
beatmapSet = set.BeatmapSet;
}
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
}
[BackgroundDependencyLoader]
private void load(LocalisationEngine localisation, BeatmapManager manager)
{
if (localisation == null)
throw new ArgumentNullException(nameof(localisation));
RestoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
DeleteRequested = manager.Delete;
var working = manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault());
Children = new Drawable[]
@ -61,7 +55,8 @@ namespace osu.Game.Screens.Select.Carousel
{
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
}, 300),
}, 300
),
new FillFlowContainer
{
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
{
public PanelBackground(WorkingBeatmap working)
@ -130,22 +143,19 @@ namespace osu.Game.Screens.Select.Carousel
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(
Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(
new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Width = 0.2f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(
new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
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
{
private readonly BindableBool filtered = new BindableBool();

View File

@ -76,68 +76,68 @@ namespace osu.Game.Screens.Select
const float carousel_width = 640;
const float filter_height = 100;
Add(new ParallaxContainer
AddRange(new Drawable[]
{
Padding = new MarginPadding { Top = filter_height },
ParallaxAmount = 0.005f,
RelativeSizeAxes = Axes.Both,
Children = new[]
new ParallaxContainer
{
new WedgeBackground
Padding = new MarginPadding { Top = filter_height },
ParallaxAmount = 0.005f,
RelativeSizeAxes = Axes.Both,
Children = new[]
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = carousel_width * 0.76f },
new WedgeBackground
{
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,
},
});
Add(new ResetScrollContainer(() => carousel.ScrollToSelected())
{
RelativeSizeAxes = Axes.Y,
Width = 250,
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,
}
},
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)
@ -309,11 +309,6 @@ namespace osu.Game.Screens.Select
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 onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => removeBeatmapSet(s));
@ -489,6 +484,7 @@ namespace osu.Game.Screens.Select
Delete(Beatmap.Value.BeatmapSetInfo);
return true;
}
break;
}

View File

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