Add basic support for loading multiple images

This commit is contained in:
Dean Herbert 2024-03-24 15:14:56 +08:00
parent ec4a9a5fdd
commit a4c619ea97
No known key found for this signature in database
2 changed files with 64 additions and 37 deletions

View File

@ -31,7 +31,6 @@ namespace osu.Game.Tests.Visual.Menus
[Test]
public void TestBasic()
{
AddAssert("system title not visible", () => onlineMenuBanner.State.Value, () => Is.EqualTo(Visibility.Hidden));
AddStep("set online content", () => onlineMenuBanner.Current.Value = new APIMenuContent
{
Images = new[]
@ -43,6 +42,7 @@ namespace osu.Game.Tests.Visual.Menus
}
},
});
AddStep("set another title", () => onlineMenuBanner.Current.Value = new APIMenuContent
{
Images = new[]
@ -54,6 +54,24 @@ namespace osu.Game.Tests.Visual.Menus
}
}
});
AddStep("set multiple images", () => onlineMenuBanner.Current.Value = new APIMenuContent
{
Images = new[]
{
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/project-loved-2@2x.png",
Url = @"https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023",
},
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/wf2023-vote@2x.png",
Url = @"https://osu.ppy.sh/community/contests/189",
}
},
});
AddStep("set title with nonexistent image", () => onlineMenuBanner.Current.Value = new APIMenuContent
{
Images = new[]
@ -65,6 +83,7 @@ namespace osu.Game.Tests.Visual.Menus
}
}
});
AddStep("unset system title", () => onlineMenuBanner.Current.Value = new APIMenuContent());
}
}

View File

@ -27,7 +27,6 @@ namespace osu.Game.Screens.Menu
private Container content = null!;
private CancellationTokenSource? cancellationTokenSource;
private MenuImage? currentImage;
[BackgroundDependencyLoader]
private void load()
@ -48,32 +47,6 @@ namespace osu.Game.Screens.Menu
protected override void PopOut() => content.FadeOut(transition_duration, Easing.OutQuint);
protected override bool OnHover(HoverEvent e)
{
content.ScaleTo(1.05f, 2000, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
content.ScaleTo(1f, 500, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
content.ScaleTo(0.95f, 500, Easing.OutQuint);
return base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseUpEvent e)
{
content
.ScaleTo(0.95f)
.ScaleTo(1, 500, Easing.OutElastic);
base.OnMouseUp(e);
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -106,17 +79,26 @@ namespace osu.Game.Screens.Menu
{
cancellationTokenSource?.Cancel();
cancellationTokenSource = null;
currentImage?.FadeOut(500, Easing.OutQuint).Expire();
if (Current.Value.Images.Length == 0)
var newContent = Current.Value;
foreach (var i in content)
{
i.FadeOutFromOne(100, Easing.OutQuint)
.Expire();
}
if (newContent.Images.Length == 0)
return;
LoadComponentAsync(new MenuImage(Current.Value.Images.First()), loaded =>
LoadComponentsAsync(newContent.Images.Select(i => new MenuImage(i)), loaded =>
{
if (!loaded.Image.Equals(Current.Value.Images.First()))
loaded.Dispose();
if (!newContent.Equals(Current.Value))
return;
content.Add(currentImage = loaded);
content.AddRange(loaded);
loaded.First().Show();
}, (cancellationTokenSource ??= new CancellationTokenSource()).Token);
}
@ -132,6 +114,8 @@ namespace osu.Game.Screens.Menu
public MenuImage(APIMenuImage image)
{
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Image = image;
}
@ -169,13 +153,37 @@ namespace osu.Game.Screens.Menu
};
}
protected override void LoadComplete()
public override void Show()
{
base.LoadComplete();
this.FadeInFromZero(500, Easing.OutQuint);
flash.FadeOutFromOne(4000, Easing.OutQuint);
}
protected override bool OnHover(HoverEvent e)
{
this.ScaleTo(1.05f, 2000, Easing.OutQuint);
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
this.ScaleTo(1f, 500, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
this.ScaleTo(0.95f, 500, Easing.OutQuint);
return true;
}
protected override void OnMouseUp(MouseUpEvent e)
{
this
.ScaleTo(0.95f)
.ScaleTo(1, 500, Easing.OutElastic);
base.OnMouseUp(e);
}
}
}
}