2022-04-28 07:09:00 +00:00
#nullable enable
2022-04-27 09:57:20 +00: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.
using System.ComponentModel ;
2022-04-27 10:41:13 +00:00
using System.Linq ;
2022-04-27 09:57:20 +00:00
using osu.Framework.Allocation ;
using osu.Framework.Graphics ;
using osu.Game.Beatmaps.Drawables ;
2022-04-28 07:09:00 +00:00
using osu.Game.Database ;
2022-04-27 09:57:20 +00:00
using osu.Game.Graphics ;
using osu.Game.Graphics.Containers ;
using osu.Game.Graphics.UserInterface ;
2022-04-27 11:19:11 +00:00
using osu.Game.Graphics.UserInterfaceV2 ;
2022-04-28 07:09:00 +00:00
using osu.Game.Localisation ;
2022-04-27 10:41:13 +00:00
using osu.Game.Online ;
2022-04-27 11:19:11 +00:00
using osuTK ;
2022-04-27 09:57:20 +00:00
namespace osu.Game.Overlays.FirstRunSetup
{
2022-04-28 07:09:00 +00:00
[Description("Obtaining Beatmaps")]
public class ScreenBeatmaps : FirstRunSetupScreen
2022-04-27 09:57:20 +00:00
{
2022-04-28 07:09:00 +00:00
private RoundedButton downloadBundledButton = null ! ;
private RoundedButton importBeatmapsButton = null ! ;
2022-04-27 09:57:20 +00:00
2022-04-28 07:09:00 +00:00
private ProgressBar progressBarBundled = null ! ;
2022-04-27 11:19:11 +00:00
2022-04-28 07:09:00 +00:00
private RoundedButton downloadTutorialButton = null ! ;
private ProgressBar progressBarTutorial = null ! ;
2022-04-27 11:19:11 +00:00
2022-04-28 07:09:00 +00:00
private BundledBeatmapDownloader tutorialDownloader = null ! ;
private BundledBeatmapDownloader bundledDownloader = null ! ;
2022-04-27 10:41:13 +00:00
2022-04-28 07:09:00 +00:00
[BackgroundDependencyLoader(permitNulls: true)]
private void load ( OsuColour colours , OverlayColourProvider overlayColourProvider , LegacyImportManager ? legacyImportManager )
2022-04-27 09:57:20 +00:00
{
2022-04-28 07:09:00 +00:00
Vector2 buttonSize = new Vector2 ( 500 , 60 ) ;
2022-04-27 11:19:11 +00:00
2022-04-27 09:57:20 +00:00
Content . Children = new Drawable [ ]
{
new OsuTextFlowContainer ( cp = > cp . Font = OsuFont . Default . With ( size : 20 ) )
{
2022-04-28 07:09:00 +00:00
Colour = overlayColourProvider . Content1 ,
2022-04-27 11:19:11 +00:00
Text =
2022-04-28 07:36:25 +00:00
"\"Beatmaps\" are what we call playable levels. osu! doesn't come with any beatmaps pre-loaded. This step will help you get started on your beatmap collection." ,
2022-04-28 07:09:00 +00:00
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y
} ,
new OsuTextFlowContainer ( cp = > cp . Font = OsuFont . Default . With ( size : 20 ) )
{
Colour = overlayColourProvider . Content1 ,
Text =
"If you are a new player, we recommend playing through the tutorial to get accustomed to the gameplay." ,
2022-04-27 09:57:20 +00:00
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y
} ,
2022-04-27 11:19:11 +00:00
downloadTutorialButton = new RoundedButton
{
Size = buttonSize ,
Anchor = Anchor . TopCentre ,
Origin = Anchor . TopCentre ,
BackgroundColour = colours . Pink3 ,
2022-04-28 07:36:25 +00:00
Text = "Get the osu! tutorial" ,
2022-04-27 11:19:11 +00:00
Action = downloadTutorial
} ,
2022-04-28 07:09:00 +00:00
new OsuTextFlowContainer ( cp = > cp . Font = OsuFont . Default . With ( size : 20 ) )
{
Colour = overlayColourProvider . Content1 ,
Text = "To get you started, we have some recommended beatmaps." ,
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y
} ,
2022-04-27 11:19:11 +00:00
downloadBundledButton = new RoundedButton
2022-04-27 09:57:20 +00:00
{
2022-04-27 11:19:11 +00:00
Size = buttonSize ,
2022-04-27 09:57:20 +00:00
Anchor = Anchor . TopCentre ,
Origin = Anchor . TopCentre ,
2022-04-27 11:19:11 +00:00
BackgroundColour = colours . Blue3 ,
2022-04-28 07:36:25 +00:00
Text = "Get recommended beatmaps" ,
2022-04-27 11:19:11 +00:00
Action = downloadBundled
2022-04-27 10:41:13 +00:00
} ,
2022-04-28 07:09:00 +00:00
new OsuTextFlowContainer ( cp = > cp . Font = OsuFont . Default . With ( size : 20 ) )
{
Colour = overlayColourProvider . Content1 ,
Text = "If you have an existing osu! install, you can also choose to import your existing beatmap collection." ,
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y
} ,
importBeatmapsButton = new RoundedButton
{
Size = buttonSize ,
Anchor = Anchor . TopCentre ,
Origin = Anchor . TopCentre ,
BackgroundColour = colours . Blue3 ,
Text = MaintenanceSettingsStrings . ImportBeatmapsFromStable ,
Action = ( ) = >
{
importBeatmapsButton . Enabled . Value = false ;
legacyImportManager ? . ImportFromStableAsync ( StableContent . Beatmaps ) . ContinueWith ( t = > Schedule ( ( ) = > importBeatmapsButton . Enabled . Value = true ) ) ;
}
} ,
new OsuTextFlowContainer ( cp = > cp . Font = OsuFont . Default . With ( size : 20 ) )
{
Colour = overlayColourProvider . Content1 ,
Text = "You can also obtain more beatmaps from the main menu \"browse\" button at any time." ,
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y
} ,
2022-04-27 09:57:20 +00:00
} ;
2022-04-27 11:19:11 +00:00
downloadTutorialButton . Add ( progressBarTutorial = new ProgressBar ( false )
{
RelativeSizeAxes = Axes . Both ,
Blending = BlendingParameters . Additive ,
FillColour = downloadTutorialButton . BackgroundColour ,
Alpha = 0.5f ,
Depth = float . MinValue
} ) ;
downloadBundledButton . Add ( progressBarBundled = new ProgressBar ( false )
2022-04-27 10:41:13 +00:00
{
RelativeSizeAxes = Axes . Both ,
Blending = BlendingParameters . Additive ,
2022-04-27 11:19:11 +00:00
FillColour = downloadBundledButton . BackgroundColour ,
2022-04-27 10:41:13 +00:00
Alpha = 0.5f ,
Depth = float . MinValue
} ) ;
2022-04-27 09:57:20 +00:00
}
2022-04-27 11:19:11 +00:00
private void downloadTutorial ( )
2022-04-27 09:57:20 +00:00
{
2022-04-27 11:19:11 +00:00
tutorialDownloader = new BundledBeatmapDownloader ( true ) ;
AddInternal ( tutorialDownloader ) ;
var downloadTracker = tutorialDownloader . DownloadTrackers . First ( ) ;
2022-04-27 10:41:13 +00:00
2022-04-27 11:19:11 +00:00
downloadTracker . Progress . BindValueChanged ( progress = >
{
progressBarTutorial . Current . Value = progress . NewValue ;
if ( progress . NewValue = = 1 )
downloadTutorialButton . Enabled . Value = false ;
} , true ) ;
2022-04-27 10:41:13 +00:00
}
2022-04-27 11:19:11 +00:00
private void downloadBundled ( )
2022-04-27 10:41:13 +00:00
{
2022-04-27 11:19:11 +00:00
bundledDownloader = new BundledBeatmapDownloader ( false ) ;
AddInternal ( bundledDownloader ) ;
foreach ( var tracker in bundledDownloader . DownloadTrackers )
tracker . State . BindValueChanged ( _ = > updateProgress ( ) , true ) ;
void updateProgress ( )
{
double progress = ( double ) bundledDownloader . DownloadTrackers . Count ( t = > t . State . Value = = DownloadState . LocallyAvailable ) / bundledDownloader . DownloadTrackers . Count ( ) ;
this . TransformBindableTo ( progressBarBundled . Current , progress , 1000 , Easing . OutQuint ) ;
2022-04-27 10:41:13 +00:00
2022-04-27 11:19:11 +00:00
if ( progress = = 1 )
downloadBundledButton . Enabled . Value = false ;
}
2022-04-27 09:57:20 +00:00
}
}
}