mirror of
https://github.com/ppy/osu
synced 2025-01-11 08:39:31 +00:00
more visual tests for BeatmapInfoWedge
also fix Author showing when not wanted
This commit is contained in:
parent
07f55a2a60
commit
ed827d5424
@ -1,36 +1,48 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Tests.Beatmaps;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public class TestCaseBeatmapInfoWedge : OsuTestCase
|
||||
{
|
||||
private BeatmapManager beatmaps;
|
||||
private readonly Random random;
|
||||
private readonly BeatmapInfoWedge infoWedge;
|
||||
private TestBeatmapInfoWedge infoWedge;
|
||||
private readonly List<Beatmap> beatmaps = new List<Beatmap>();
|
||||
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||
|
||||
public TestCaseBeatmapInfoWedge()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game, RulesetStore rulesets)
|
||||
{
|
||||
random = new Random(0123);
|
||||
beatmap.BindTo(game.Beatmap);
|
||||
|
||||
Add(infoWedge = new BeatmapInfoWedge
|
||||
Add(infoWedge = new TestBeatmapInfoWedge
|
||||
{
|
||||
Size = new Vector2(0.5f, 245),
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Top = 20,
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("hide", () =>
|
||||
{
|
||||
infoWedge.State = Visibility.Hidden;
|
||||
Content.FadeOut(100);
|
||||
});
|
||||
|
||||
AddStep("show", () =>
|
||||
@ -39,31 +51,88 @@ namespace osu.Game.Tests.Visual
|
||||
infoWedge.State = Visibility.Visible;
|
||||
infoWedge.UpdateBeatmap(beatmap);
|
||||
});
|
||||
AddStep("hide", () =>
|
||||
|
||||
foreach (var rulesetInfo in rulesets.AvailableRulesets)
|
||||
{
|
||||
infoWedge.State = Visibility.Hidden;
|
||||
Content.FadeOut(100);
|
||||
var ruleset = rulesetInfo.CreateInstance();
|
||||
beatmaps.Add(createTestBeatmap(rulesetInfo));
|
||||
|
||||
var name = rulesetInfo.ShortName;
|
||||
selectBeatmap(name);
|
||||
|
||||
// TODO: check InfoLabels of other rulesets
|
||||
switch (ruleset)
|
||||
{
|
||||
case OsuRuleset osu:
|
||||
testOsuBeatmap(osu);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
testNullBeatmap();
|
||||
}
|
||||
|
||||
private void testOsuBeatmap(OsuRuleset ruleset)
|
||||
{
|
||||
AddAssert("check version", () => infoWedge.Info.VersionLabel.Text == $"{ruleset.ShortName}Version");
|
||||
AddAssert("check title", () => infoWedge.Info.TitleLabel.Text == $"{ruleset.ShortName}Source — {ruleset.ShortName}Title");
|
||||
AddAssert("check artist", () => infoWedge.Info.ArtistLabel.Text == $"{ruleset.ShortName}Artist");
|
||||
AddAssert("check author", () => infoWedge.Info.MapperContainer.Children.OfType<OsuSpriteText>().Any(s => s.Text == $"{ruleset.ShortName}Author"));
|
||||
// TODO: check InfoLabels
|
||||
}
|
||||
|
||||
private void testNullBeatmap()
|
||||
{
|
||||
selectNullBeatmap();
|
||||
AddAssert("check empty version", () => string.IsNullOrEmpty(infoWedge.Info.VersionLabel.Text));
|
||||
AddAssert("check default title", () => infoWedge.Info.TitleLabel.Text == beatmap.Default.BeatmapInfo.Metadata.Title);
|
||||
AddAssert("check default artist", () => infoWedge.Info.ArtistLabel.Text == beatmap.Default.BeatmapInfo.Metadata.Artist);
|
||||
AddAssert("check empty author", () => !infoWedge.Info.MapperContainer.Children.Any());
|
||||
AddAssert("check empty infos", () => !infoWedge.Info.InfoLabelContainer.Children.Any());
|
||||
}
|
||||
|
||||
private void selectBeatmap(string name)
|
||||
{
|
||||
AddStep($"select {name} beatmap", () =>
|
||||
{
|
||||
beatmap.Value = new TestWorkingBeatmap(beatmaps.First(b => b.BeatmapInfo.Ruleset.ShortName == name));
|
||||
infoWedge.UpdateBeatmap(beatmap);
|
||||
});
|
||||
AddStep("random beatmap", randomBeatmap);
|
||||
AddStep("null beatmap", () => infoWedge.UpdateBeatmap(beatmap.Default));
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game, BeatmapManager beatmaps)
|
||||
private void selectNullBeatmap()
|
||||
{
|
||||
this.beatmaps = beatmaps;
|
||||
beatmap.BindTo(game.Beatmap);
|
||||
AddStep("select null beatmap", () =>
|
||||
{
|
||||
beatmap.Value = beatmap.Default;
|
||||
infoWedge.UpdateBeatmap(beatmap);
|
||||
});
|
||||
}
|
||||
|
||||
private void randomBeatmap()
|
||||
private Beatmap createTestBeatmap(RulesetInfo ruleset)
|
||||
{
|
||||
var sets = beatmaps.GetAllUsableBeatmapSets();
|
||||
if (sets.Count == 0)
|
||||
return;
|
||||
return new Beatmap
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
AuthorString = $"{ruleset.ShortName}Author",
|
||||
Artist = $"{ruleset.ShortName}Artist",
|
||||
Source = $"{ruleset.ShortName}Source",
|
||||
Title = $"{ruleset.ShortName}Title"
|
||||
},
|
||||
Ruleset = ruleset,
|
||||
StarDifficulty = 6,
|
||||
Version = $"{ruleset.ShortName}Version"
|
||||
},
|
||||
HitObjects = new List<HitObject>() // TODO: Fill it with something depending on ruleset?
|
||||
};
|
||||
}
|
||||
|
||||
var b = sets[random.Next(0, sets.Count)].Beatmaps[0];
|
||||
beatmap.Value = beatmaps.GetWorkingBeatmap(b);
|
||||
infoWedge.UpdateBeatmap(beatmap);
|
||||
private class TestBeatmapInfoWedge : BeatmapInfoWedge
|
||||
{
|
||||
public new BufferedWedgeInfo Info => base.Info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ namespace osu.Game.Beatmaps
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "please load a beatmap!",
|
||||
Title = "no beatmaps available!",
|
||||
AuthorString = "no one",
|
||||
Title = "no beatmaps available!"
|
||||
},
|
||||
BeatmapSet = new BeatmapSetInfo(),
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
|
||||
|
||||
private Drawable info;
|
||||
protected BufferedWedgeInfo Info;
|
||||
|
||||
public BeatmapInfoWedge()
|
||||
{
|
||||
@ -63,23 +63,28 @@ namespace osu.Game.Screens.Select
|
||||
LoadComponentAsync(new BufferedWedgeInfo(beatmap)
|
||||
{
|
||||
Shear = -Shear,
|
||||
Depth = info?.Depth + 1 ?? 0,
|
||||
Depth = Info?.Depth + 1 ?? 0,
|
||||
}, newInfo =>
|
||||
{
|
||||
// ensure we ourselves are visible if not already.
|
||||
if (!IsPresent)
|
||||
this.FadeIn(250);
|
||||
|
||||
info?.FadeOut(250);
|
||||
info?.Expire();
|
||||
Info?.FadeOut(250);
|
||||
Info?.Expire();
|
||||
|
||||
Add(info = newInfo);
|
||||
Add(Info = newInfo);
|
||||
});
|
||||
}
|
||||
|
||||
public class BufferedWedgeInfo : BufferedContainer
|
||||
{
|
||||
private readonly WorkingBeatmap working;
|
||||
public OsuSpriteText VersionLabel { get; private set; }
|
||||
public OsuSpriteText TitleLabel { get; private set; }
|
||||
public OsuSpriteText ArtistLabel { get; private set; }
|
||||
public FillFlowContainer MapperContainer { get; private set; }
|
||||
public FillFlowContainer InfoLabelContainer { get; private set; }
|
||||
|
||||
public BufferedWedgeInfo(WorkingBeatmap working)
|
||||
{
|
||||
@ -139,7 +144,7 @@ namespace osu.Game.Screens.Select
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
VersionLabel = new OsuSpriteText
|
||||
{
|
||||
Font = @"Exo2.0-MediumItalic",
|
||||
Text = beatmapInfo.Version,
|
||||
@ -157,26 +162,26 @@ namespace osu.Game.Screens.Select
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
TitleLabel = new OsuSpriteText
|
||||
{
|
||||
Font = @"Exo2.0-MediumItalic",
|
||||
Text = string.IsNullOrEmpty(metadata.Source) ? metadata.Title : metadata.Source + " — " + metadata.Title,
|
||||
TextSize = 28,
|
||||
},
|
||||
new OsuSpriteText
|
||||
ArtistLabel = new OsuSpriteText
|
||||
{
|
||||
Font = @"Exo2.0-MediumItalic",
|
||||
Text = metadata.Artist,
|
||||
TextSize = 17,
|
||||
},
|
||||
new FillFlowContainer
|
||||
MapperContainer = new FillFlowContainer
|
||||
{
|
||||
Margin = new MarginPadding { Top = 10 },
|
||||
Direction = FillDirection.Horizontal,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = getMapper(metadata)
|
||||
},
|
||||
new FillFlowContainer
|
||||
InfoLabelContainer = new FillFlowContainer
|
||||
{
|
||||
Margin = new MarginPadding { Top = 20 },
|
||||
Spacing = new Vector2(20, 0),
|
||||
|
Loading…
Reference in New Issue
Block a user