Adjust game-side text flow containers to part-based model

This commit is contained in:
Bartłomiej Dach
2021-08-01 17:12:04 +02:00
parent fe86ae51b0
commit 6f863ca204
8 changed files with 73 additions and 37 deletions

View File

@ -3,12 +3,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
@ -25,7 +23,7 @@ namespace osu.Game.Overlays.Music
public Action<BeatmapSetInfo> RequestSelection;
private TextFlowContainer text;
private IEnumerable<Drawable> titleSprites;
private ITextPart titlePart;
private ILocalisedBindableString title;
private ILocalisedBindableString artist;
@ -63,11 +61,16 @@ namespace osu.Game.Overlays.Music
if (set.OldValue?.Equals(Model) != true && set.NewValue?.Equals(Model) != true)
return;
foreach (Drawable s in titleSprites)
s.FadeColour(set.NewValue.Equals(Model) ? selectedColour : Color4.White, FADE_DURATION);
updateSelectionState(false);
}, true);
}
private void updateSelectionState(bool instant)
{
foreach (Drawable s in titlePart.Drawables)
s.FadeColour(SelectedSet.Value?.Equals(Model) == true ? selectedColour : Color4.White, instant ? 0 : FADE_DURATION);
}
protected override Drawable CreateContent() => text = new OsuTextFlowContainer
{
RelativeSizeAxes = Axes.X,
@ -79,7 +82,8 @@ namespace osu.Game.Overlays.Music
text.Clear();
// space after the title to put a space between the title and artist
titleSprites = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)).OfType<SpriteText>();
titlePart = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular));
updateSelectionState(true);
text.AddText(artist.Value, sprite =>
{