mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 01:47:33 +08:00
Refactored out changes in DifficultyColourBar
This commit is contained in:
parent
4ef901d08d
commit
5049e2fbf9
@ -174,6 +174,7 @@ namespace osu.Game.Screens.Select
|
|||||||
private FillFlowContainer infoLabelContainer;
|
private FillFlowContainer infoLabelContainer;
|
||||||
private Container topRightMetadataContainer;
|
private Container topRightMetadataContainer;
|
||||||
private Container bpmLabelContainer;
|
private Container bpmLabelContainer;
|
||||||
|
private Container difficultyColourBarContainer;
|
||||||
private ModSettingChangeTracker settingChangeTracker;
|
private ModSettingChangeTracker settingChangeTracker;
|
||||||
private CancellationTokenSource cancellationTokenSource;
|
private CancellationTokenSource cancellationTokenSource;
|
||||||
private IBindable<StarDifficulty?> starDifficulty;
|
private IBindable<StarDifficulty?> starDifficulty;
|
||||||
@ -206,10 +207,11 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new DifficultyColourBar(beatmapInfo)
|
difficultyColourBarContainer = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Width = 20,
|
Width = 20,
|
||||||
|
Child = createDifficultyColourBar(starDifficulty.Value ?? new StarDifficulty()),
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -286,20 +288,32 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
titleBinding.BindValueChanged(_ => setMetadata(metadata.Source));
|
titleBinding.BindValueChanged(_ => setMetadata(metadata.Source));
|
||||||
artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true);
|
artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true);
|
||||||
starDifficulty.BindValueChanged(updateTopRightMetadata, true);
|
starDifficulty.BindValueChanged(updateDifficulty, true);
|
||||||
|
|
||||||
// no difficulty means it can't have a status to show
|
// no difficulty means it can't have a status to show
|
||||||
if (beatmapInfo.Version == null)
|
if (beatmapInfo.Version == null)
|
||||||
StatusPill.Hide();
|
StatusPill.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTopRightMetadata(ValueChangedEvent<StarDifficulty?> valueChanged)
|
private void updateDifficulty(ValueChangedEvent<StarDifficulty?> valueChanged)
|
||||||
{
|
{
|
||||||
|
var difficulty = valueChanged.NewValue ?? new StarDifficulty();
|
||||||
|
|
||||||
topRightMetadataContainer.Child.FadeOut(250);
|
topRightMetadataContainer.Child.FadeOut(250);
|
||||||
topRightMetadataContainer.Child.Expire();
|
topRightMetadataContainer.Child.Expire();
|
||||||
topRightMetadataContainer.Child = createTopRightMetadataContainer(beatmap.BeatmapInfo, valueChanged.NewValue ?? new StarDifficulty());
|
topRightMetadataContainer.Child = createTopRightMetadataContainer(beatmap.BeatmapInfo, difficulty);
|
||||||
|
|
||||||
|
difficultyColourBarContainer.Child.Expire();
|
||||||
|
difficultyColourBarContainer.Child = createDifficultyColourBar(difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DifficultyColourBar createDifficultyColourBar(StarDifficulty difficulty)
|
||||||
|
=> new DifficultyColourBar(difficulty)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
Width = 20,
|
||||||
|
};
|
||||||
|
|
||||||
private FillFlowContainer createTopRightMetadataContainer(BeatmapInfo beatmapInfo, StarDifficulty difficulty)
|
private FillFlowContainer createTopRightMetadataContainer(BeatmapInfo beatmapInfo, StarDifficulty difficulty)
|
||||||
{
|
{
|
||||||
var container = new FillFlowContainer
|
var container = new FillFlowContainer
|
||||||
@ -515,64 +529,38 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
private class DifficultyColourBar : Container
|
private class DifficultyColourBar : Container
|
||||||
{
|
{
|
||||||
[Resolved]
|
private readonly StarDifficulty difficulty;
|
||||||
private OsuColour colours { get; set; }
|
|
||||||
|
|
||||||
private Box solidDifficultyBox;
|
public DifficultyColourBar(StarDifficulty difficulty)
|
||||||
private Box transparentDifficultyBox;
|
|
||||||
private CancellationTokenSource cancellationTokenSource;
|
|
||||||
private IBindable<StarDifficulty?> starDifficulty;
|
|
||||||
|
|
||||||
private readonly BeatmapInfo beatmapInfo;
|
|
||||||
|
|
||||||
public DifficultyColourBar(BeatmapInfo beatmapInfo)
|
|
||||||
{
|
{
|
||||||
this.beatmapInfo = beatmapInfo;
|
this.difficulty = difficulty;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(BeatmapDifficultyCache difficultyCache)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
const float full_opacity_ratio = 0.7f;
|
const float full_opacity_ratio = 0.7f;
|
||||||
|
|
||||||
cancellationTokenSource?.Cancel();
|
var difficultyColour = colours.ForDifficultyRating(difficulty.DifficultyRating);
|
||||||
cancellationTokenSource = new CancellationTokenSource();
|
|
||||||
|
|
||||||
starDifficulty?.UnbindAll();
|
|
||||||
starDifficulty = difficultyCache.GetBindableDifficulty(beatmapInfo, cancellationTokenSource.Token);
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
solidDifficultyBox = new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = difficultyColour,
|
||||||
Width = full_opacity_ratio,
|
Width = full_opacity_ratio,
|
||||||
},
|
},
|
||||||
transparentDifficultyBox = new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
RelativePositionAxes = Axes.Both,
|
||||||
|
Colour = difficultyColour,
|
||||||
Alpha = 0.5f,
|
Alpha = 0.5f,
|
||||||
X = full_opacity_ratio,
|
X = full_opacity_ratio,
|
||||||
Width = 1 - full_opacity_ratio,
|
Width = 1 - full_opacity_ratio,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
starDifficulty.BindValueChanged(setColour, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setColour(ValueChangedEvent<StarDifficulty?> valueChanged)
|
|
||||||
{
|
|
||||||
var difficultyColour = colours.ForDifficultyRating(valueChanged.NewValue?.DifficultyRating ?? (new StarDifficulty()).DifficultyRating);
|
|
||||||
|
|
||||||
solidDifficultyBox.Colour = difficultyColour;
|
|
||||||
transparentDifficultyBox.Colour = difficultyColour;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
|
||||||
{
|
|
||||||
base.Dispose(isDisposing);
|
|
||||||
cancellationTokenSource?.Cancel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user