2020-05-16 09:03:10 +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.
using System.IO ;
using osu.Framework.Allocation ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Graphics.Shapes ;
using osu.Framework.Logging ;
using osu.Framework.Platform ;
using osu.Game.Graphics ;
using osu.Game.Graphics.Sprites ;
using osu.Game.Graphics.UserInterface ;
using osu.Game.Graphics.UserInterfaceV2 ;
using osu.Game.Overlays ;
using osu.Game.Tournament.Components ;
2021-01-11 13:44:07 +08:00
using osu.Game.Tournament.IPC ;
2020-05-16 09:03:10 +08:00
using osuTK ;
2021-01-11 13:44:07 +08:00
namespace osu.Game.Tournament.Screens.Setup
2020-05-16 09:03:10 +08:00
{
public partial class StablePathSelectScreen : TournamentScreen
{
2023-07-30 00:57:44 +08:00
[Resolved]
2023-07-25 19:50:55 +08:00
private TournamentSceneManager ? sceneManager { get ; set ; }
2020-05-16 09:03:10 +08:00
2020-05-31 22:50:13 +08:00
[Resolved]
2023-07-25 19:50:55 +08:00
private MatchIPCInfo ipc { get ; set ; } = null ! ;
2020-06-13 21:05:52 +08:00
2023-07-25 19:50:55 +08:00
private OsuDirectorySelector directorySelector = null ! ;
private DialogOverlay ? overlay ;
2020-05-31 22:50:13 +08:00
2020-05-16 09:03:10 +08:00
[BackgroundDependencyLoader(true)]
private void load ( Storage storage , OsuColour colours )
{
2020-06-14 01:28:21 +08:00
var initialStorage = ( ipc as FileBasedIPC ) ? . IPCStorage ? ? storage ;
2023-07-25 19:50:55 +08:00
string? initialPath = new DirectoryInfo ( initialStorage . GetFullPath ( string . Empty ) ) . Parent ? . FullName ;
2020-06-02 04:50:24 +08:00
2020-05-18 04:28:24 +08:00
AddRangeInternal ( new Drawable [ ]
{
new Container
2020-05-16 09:03:10 +08:00
{
2020-05-18 04:28:24 +08:00
Masking = true ,
CornerRadius = 10 ,
RelativeSizeAxes = Axes . Both ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Size = new Vector2 ( 0.5f , 0.8f ) ,
Children = new Drawable [ ]
2020-05-16 09:03:10 +08:00
{
2020-05-18 04:28:24 +08:00
new Box
2020-05-16 09:03:10 +08:00
{
2021-12-10 13:15:00 +08:00
Colour = colours . GreySeaFoamDark ,
2020-05-18 04:28:24 +08:00
RelativeSizeAxes = Axes . Both ,
2020-05-16 09:03:10 +08:00
} ,
2020-05-18 04:28:24 +08:00
new GridContainer
2020-05-16 09:03:10 +08:00
{
2020-05-18 04:28:24 +08:00
RelativeSizeAxes = Axes . Both ,
RowDimensions = new [ ]
2020-05-16 09:03:10 +08:00
{
2020-05-18 04:28:24 +08:00
new Dimension ( ) ,
new Dimension ( GridSizeMode . Relative , 0.8f ) ,
new Dimension ( ) ,
2020-05-16 09:03:10 +08:00
} ,
2020-05-18 04:28:24 +08:00
Content = new [ ]
2020-05-16 09:03:10 +08:00
{
2020-05-18 04:28:24 +08:00
new Drawable [ ]
2020-05-16 09:03:10 +08:00
{
2020-05-18 04:28:24 +08:00
new OsuSpriteText
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Text = "Please select a new location" ,
Font = OsuFont . Default . With ( size : 40 )
} ,
} ,
new Drawable [ ]
2020-05-16 09:03:10 +08:00
{
2021-07-06 06:15:17 +08:00
directorySelector = new OsuDirectorySelector ( initialPath )
2020-05-18 04:28:24 +08:00
{
RelativeSizeAxes = Axes . Both ,
}
2020-05-16 09:03:10 +08:00
} ,
2020-05-18 04:28:24 +08:00
new Drawable [ ]
{
new FillFlowContainer
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Direction = FillDirection . Horizontal ,
Spacing = new Vector2 ( 20 ) ,
Children = new Drawable [ ]
{
2022-11-24 15:26:57 +08:00
new RoundedButton
2020-05-18 04:28:24 +08:00
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Width = 300 ,
Text = "Select stable path" ,
2020-06-13 21:07:21 +08:00
Action = ChangePath
2020-05-18 04:28:24 +08:00
} ,
2022-11-24 15:26:57 +08:00
new RoundedButton
2020-05-18 04:28:24 +08:00
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Width = 300 ,
Text = "Auto detect" ,
2020-05-23 02:01:26 +08:00
Action = AutoDetect
2020-05-18 04:28:24 +08:00
} ,
}
}
}
2020-05-16 09:03:10 +08:00
}
}
2020-05-18 04:28:24 +08:00
} ,
} ,
new BackButton
{
Anchor = Anchor . BottomLeft ,
Origin = Anchor . BottomLeft ,
State = { Value = Visibility . Visible } ,
Action = ( ) = > sceneManager ? . SetScreen ( typeof ( SetupScreen ) )
2020-05-16 09:03:10 +08:00
}
} ) ;
}
2020-06-13 21:07:21 +08:00
protected virtual void ChangePath ( )
2020-05-16 09:03:10 +08:00
{
2021-10-27 12:04:41 +08:00
string target = directorySelector . CurrentPath . Value . FullName ;
2020-05-31 22:27:05 +08:00
var fileBasedIpc = ipc as FileBasedIPC ;
2020-05-21 04:30:31 +08:00
Logger . Log ( $"Changing Stable CE location to {target}" ) ;
2020-05-21 04:16:37 +08:00
2020-06-13 21:38:29 +08:00
if ( ! fileBasedIpc ? . SetIPCLocation ( target ) ? ? true )
2020-05-20 23:25:53 +08:00
{
2020-05-21 04:30:31 +08:00
overlay = new DialogOverlay ( ) ;
overlay . Push ( new IPCErrorDialog ( "This is an invalid IPC Directory" , "Select a directory that contains an osu! stable cutting edge installation and make sure it has an empty ipc.txt file in it." ) ) ;
AddInternal ( overlay ) ;
Logger . Log ( "Folder is not an osu! stable CE directory" ) ;
return ;
2020-05-20 23:25:53 +08:00
}
2020-05-21 04:30:31 +08:00
sceneManager ? . SetScreen ( typeof ( SetupScreen ) ) ;
2020-05-16 09:03:10 +08:00
}
2020-05-18 04:28:24 +08:00
2020-05-23 02:01:26 +08:00
protected virtual void AutoDetect ( )
2020-05-18 04:28:24 +08:00
{
var fileBasedIpc = ipc as FileBasedIPC ;
2020-05-18 04:46:43 +08:00
2020-06-13 21:27:46 +08:00
if ( ! fileBasedIpc ? . AutoDetectIPCLocation ( ) ? ? true )
2020-05-18 04:28:24 +08:00
{
overlay = new DialogOverlay ( ) ;
2020-05-18 04:46:43 +08:00
overlay . Push ( new IPCErrorDialog ( "Failed to auto detect" , "An osu! stable cutting-edge installation could not be auto detected.\nPlease try and manually point to the directory." ) ) ;
2020-05-18 04:28:24 +08:00
AddInternal ( overlay ) ;
}
else
{
sceneManager ? . SetScreen ( typeof ( SetupScreen ) ) ;
}
}
2020-05-16 09:03:10 +08:00
}
}