1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 17:17:26 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeIntro.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

428 lines
19 KiB
C#
Raw Normal View History

2024-08-05 17:07:56 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2024-08-07 17:29:15 +08:00
using System;
2024-08-06 16:00:04 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2024-08-06 16:00:04 +08:00
using osu.Framework.Extensions.Color4Extensions;
2024-08-05 17:07:56 +08:00
using osu.Framework.Graphics;
2024-08-06 16:00:04 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2024-08-05 17:07:56 +08:00
using osu.Framework.Screens;
2024-08-06 16:00:04 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
2024-08-05 17:07:56 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Rooms;
2024-08-06 16:00:04 +08:00
using osu.Game.Overlays;
2024-08-07 17:29:15 +08:00
using osu.Game.Rulesets;
2024-08-06 16:00:04 +08:00
using osu.Game.Screens.OnlinePlay.Match;
2024-08-07 17:29:15 +08:00
using osu.Game.Screens.Play.HUD;
2024-08-06 16:00:04 +08:00
using osuTK;
2024-08-07 17:29:15 +08:00
using osuTK.Graphics;
2024-08-05 17:07:56 +08:00
namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
public partial class DailyChallengeIntro : OsuScreen
{
public override bool DisallowExternalBeatmapRulesetChanges => true;
public override bool? ApplyModTrackAdjustments => true;
2024-08-05 17:07:56 +08:00
private readonly Room room;
2024-08-06 16:00:04 +08:00
private readonly PlaylistItem item;
2024-08-07 17:29:15 +08:00
private Container introContent = null!;
private Container topTitleDisplay = null!;
private Container bottomDateDisplay = null!;
2024-08-06 16:00:04 +08:00
private Container beatmapBackground = null!;
2024-08-07 17:29:15 +08:00
private Box flash = null!;
private FillFlowContainer beatmapContent = null!;
2024-08-06 16:00:04 +08:00
private Container titleContainer = null!;
2024-08-06 16:00:04 +08:00
private bool beatmapBackgroundLoaded;
private bool animationBegan;
private IBindable<StarDifficulty?> starDifficulty = null!;
2024-08-06 16:00:04 +08:00
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
2024-08-05 17:07:56 +08:00
[Resolved]
private BeatmapManager beatmapManager { get; set; } = null!;
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
[Resolved]
private MusicController musicController { get; set; } = null!;
2024-08-05 17:07:56 +08:00
public DailyChallengeIntro(Room room)
{
this.room = room;
2024-08-06 16:00:04 +08:00
item = room.Playlist.Single();
2024-08-05 17:07:56 +08:00
ValidForResume = false;
}
2024-08-06 16:00:04 +08:00
protected override BackgroundScreen CreateBackground() => new DailyChallengeIntroBackgroundScreen(colourProvider);
2024-08-05 17:07:56 +08:00
2024-08-06 16:00:04 +08:00
[BackgroundDependencyLoader]
private void load(BeatmapDifficultyCache difficultyCache)
2024-08-06 16:00:04 +08:00
{
const float horizontal_info_size = 500f;
2024-08-07 17:29:15 +08:00
Ruleset ruleset = Ruleset.Value.CreateInstance();
StarRatingDisplay starRatingDisplay;
2024-08-05 17:07:56 +08:00
InternalChildren = new Drawable[]
{
2024-08-07 17:29:15 +08:00
introContent = new Container
2024-08-05 17:07:56 +08:00
{
2024-08-06 16:00:04 +08:00
Alpha = 0f,
2024-08-07 17:29:15 +08:00
RelativeSizeAxes = Axes.Both,
2024-08-05 17:07:56 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2024-08-07 17:29:15 +08:00
Shear = new Vector2(OsuGame.SHEAR, 0f),
2024-08-06 16:00:04 +08:00
Children = new Drawable[]
{
titleContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
topTitleDisplay = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
CornerRadius = 10f,
Masking = true,
X = -10,
Children = new Drawable[]
{
new Box
{
Colour = colourProvider.Background3,
RelativeSizeAxes = Axes.Both,
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Today's Challenge",
Margin = new MarginPadding { Horizontal = 10f, Vertical = 5f },
Shear = new Vector2(-OsuGame.SHEAR, 0f),
Font = OsuFont.GetFont(size: 32, weight: FontWeight.Light, typeface: Typeface.TorusAlternate),
},
}
},
bottomDateDisplay = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
CornerRadius = 10f,
Masking = true,
X = 10,
Children = new Drawable[]
{
new Box
{
Colour = colourProvider.Background3,
RelativeSizeAxes = Axes.Both,
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = room.Name.Value.Split(':', StringSplitOptions.TrimEntries).Last(),
Margin = new MarginPadding { Horizontal = 10f, Vertical = 5f },
Shear = new Vector2(-OsuGame.SHEAR, 0f),
Font = OsuFont.GetFont(size: 32, weight: FontWeight.Light, typeface: Typeface.TorusAlternate),
},
}
},
}
},
2024-08-07 17:29:15 +08:00
beatmapContent = new FillFlowContainer
2024-08-06 16:00:04 +08:00
{
2024-08-07 17:29:15 +08:00
AlwaysPresent = true, // so we can get the size ahead of time
Direction = FillDirection.Vertical,
2024-08-06 16:00:04 +08:00
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2024-08-07 17:29:15 +08:00
Alpha = 0,
Scale = new Vector2(0.001f),
Spacing = new Vector2(10),
Children = new Drawable[]
2024-08-06 16:00:04 +08:00
{
2024-08-07 17:29:15 +08:00
beatmapBackground = new Container
2024-08-06 16:00:04 +08:00
{
2024-08-07 17:29:15 +08:00
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(horizontal_info_size, 150f),
2024-08-07 17:29:15 +08:00
CornerRadius = 20f,
BorderColour = colourProvider.Content2,
BorderThickness = 3f,
Masking = true,
Children = new Drawable[]
2024-08-06 16:00:04 +08:00
{
2024-08-07 17:29:15 +08:00
new Box
{
Colour = colourProvider.Background3,
RelativeSizeAxes = Axes.Both,
},
flash = new Box
{
Colour = Color4.White,
Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both,
Depth = float.MinValue,
}
}
},
new Container
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = horizontal_info_size,
2024-08-07 17:29:15 +08:00
AutoSizeAxes = Axes.Y,
CornerRadius = 10f,
Masking = true,
Children = new Drawable[]
2024-08-06 16:00:04 +08:00
{
2024-08-07 17:29:15 +08:00
new Box
{
Colour = colourProvider.Background3,
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
2024-08-07 17:29:15 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Direction = FillDirection.Vertical,
Padding = new MarginPadding(5f),
Children = new Drawable[]
{
new TruncatingSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Shear = new Vector2(-OsuGame.SHEAR, 0f),
MaxWidth = horizontal_info_size,
Text = item.Beatmap.BeatmapSet!.Metadata.GetDisplayTitleRomanisable(false),
Padding = new MarginPadding { Horizontal = 5f },
Font = OsuFont.GetFont(size: 26),
},
new TruncatingSpriteText
{
Text = $"Difficulty: {item.Beatmap.DifficultyName}",
Font = OsuFont.GetFont(size: 20, italics: true),
MaxWidth = horizontal_info_size,
Shear = new Vector2(-OsuGame.SHEAR, 0f),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
new TruncatingSpriteText
{
Text = $"by {item.Beatmap.Metadata.Author.Username}",
Font = OsuFont.GetFont(size: 16, italics: true),
MaxWidth = horizontal_info_size,
Shear = new Vector2(-OsuGame.SHEAR, 0f),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
starRatingDisplay = new StarRatingDisplay(default)
{
Shear = new Vector2(-OsuGame.SHEAR, 0f),
Margin = new MarginPadding(5),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
}
}
2024-08-07 17:29:15 +08:00
},
}
},
new Container
2024-08-07 17:29:15 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = horizontal_info_size,
AutoSizeAxes = Axes.Y,
CornerRadius = 10f,
Masking = true,
Children = new Drawable[]
2024-08-07 17:29:15 +08:00
{
new Box
{
Colour = colourProvider.Background3,
RelativeSizeAxes = Axes.Both,
},
new ModFlowDisplay
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Shear = new Vector2(-OsuGame.SHEAR, 0f),
Current =
{
Value = item.RequiredMods.Select(m => m.ToMod(ruleset)).ToArray()
},
}
}
2024-08-06 16:00:04 +08:00
}
2024-08-07 17:29:15 +08:00
}
2024-08-06 16:00:04 +08:00
},
}
2024-08-05 17:07:56 +08:00
}
};
starDifficulty = difficultyCache.GetBindableDifficulty(item.Beatmap);
starDifficulty.BindValueChanged(star =>
{
if (star.NewValue != null)
starRatingDisplay.Current.Value = star.NewValue.Value;
}, true);
2024-08-06 16:00:04 +08:00
LoadComponentAsync(new OnlineBeatmapSetCover(item.Beatmap.BeatmapSet as IBeatmapSetOnlineInfo)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit,
Scale = new Vector2(1.2f),
Shear = new Vector2(-OsuGame.SHEAR, 0f),
}, c =>
2024-08-05 17:07:56 +08:00
{
2024-08-06 16:00:04 +08:00
beatmapBackground.Add(c);
2024-08-07 17:29:15 +08:00
2024-08-06 16:00:04 +08:00
beatmapBackgroundLoaded = true;
updateAnimationState();
});
}
public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);
this.FadeInFromZero(400, Easing.OutQuint);
updateAnimationState();
}
public override void OnSuspending(ScreenTransitionEvent e)
{
this.FadeOut(800, Easing.OutQuint);
2024-08-06 16:00:04 +08:00
base.OnSuspending(e);
}
private void updateAnimationState()
{
if (!beatmapBackgroundLoaded || !this.IsCurrentScreen())
return;
if (animationBegan)
return;
beginAnimation();
animationBegan = true;
}
private void beginAnimation()
{
2024-08-07 17:29:15 +08:00
using (BeginDelayedSequence(200))
{
introContent.Show();
2024-08-06 16:00:04 +08:00
const float y_offset_start = 260;
const float y_offset_end = 20;
topTitleDisplay
.FadeInFromZero(400, Easing.OutQuint);
topTitleDisplay.MoveToY(-y_offset_start)
.MoveToY(-y_offset_end, 300, Easing.OutQuint)
.Then()
.MoveToY(0, 4000);
2024-08-06 16:00:04 +08:00
bottomDateDisplay.MoveToY(y_offset_start)
.MoveToY(y_offset_end, 300, Easing.OutQuint)
.Then()
.MoveToY(0, 4000);
2024-08-06 16:00:04 +08:00
2024-08-08 13:15:40 +08:00
using (BeginDelayedSequence(1000))
2024-08-07 17:29:15 +08:00
{
beatmapContent
.ScaleTo(3)
.ScaleTo(1f, 500, Easing.In)
.Then()
.ScaleTo(1.1f, 4000);
2024-08-07 17:29:15 +08:00
using (BeginDelayedSequence(100))
2024-08-07 17:29:15 +08:00
{
titleContainer
.ScaleTo(0.4f, 400, Easing.In)
.FadeOut(500, Easing.OutQuint);
}
2024-08-08 12:17:25 +08:00
using (BeginDelayedSequence(240))
{
2024-08-07 17:29:15 +08:00
beatmapContent.FadeInFromZero(280, Easing.InQuad);
2024-08-06 16:00:04 +08:00
using (BeginDelayedSequence(300))
{
Schedule(() =>
{
DailyChallenge.TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, item);
ApplyToBackground(bs => ((RoomBackgroundScreen)bs).SelectedItem.Value = item);
});
}
2024-08-06 16:00:04 +08:00
using (BeginDelayedSequence(400))
flash.FadeOutFromOne(5000, Easing.OutQuint);
2024-08-07 17:29:15 +08:00
using (BeginDelayedSequence(2600))
2024-08-06 16:00:04 +08:00
{
Schedule(() =>
2024-08-07 17:29:15 +08:00
{
if (this.IsCurrentScreen())
this.Push(new DailyChallenge(room));
});
}
}
}
}
2024-08-06 16:00:04 +08:00
}
private partial class DailyChallengeIntroBackgroundScreen : RoomBackgroundScreen
{
private readonly OverlayColourProvider colourProvider;
public DailyChallengeIntroBackgroundScreen(OverlayColourProvider colourProvider)
: base(null)
{
this.colourProvider = colourProvider;
}
[BackgroundDependencyLoader]
private void load()
{
AddInternal(new Box
{
Depth = float.MinValue,
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5.Opacity(0.6f),
});
}
2024-08-05 17:07:56 +08:00
}
}
}