2019-09-21 17:10:04 +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.
2019-09-22 19:22:50 +00:00
using System ;
2019-11-12 02:04:49 +00:00
using System.Collections.Generic ;
2020-03-13 06:44:13 +00:00
using System.Drawing ;
2019-09-21 19:15:02 +00:00
using osu.Framework.Allocation ;
2020-03-13 06:44:13 +00:00
using osu.Framework.Bindables ;
using osu.Framework.Configuration ;
2019-09-22 19:22:50 +00:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Game.Graphics.UserInterface ;
2019-09-24 10:00:26 +00:00
using osu.Game.Graphics.UserInterfaceV2 ;
2019-09-22 19:45:23 +00:00
using osu.Game.Online.API ;
using osu.Game.Overlays ;
2019-11-11 08:03:50 +00:00
using osu.Game.Rulesets ;
2019-09-21 19:15:02 +00:00
using osu.Game.Tournament.IPC ;
2019-09-22 19:22:50 +00:00
using osuTK ;
using osuTK.Graphics ;
2019-09-21 19:15:02 +00:00
2019-09-21 17:10:04 +00:00
namespace osu.Game.Tournament.Screens
{
2019-09-22 19:49:21 +00:00
public class SetupScreen : TournamentScreen , IProvideVideo
2019-09-21 17:10:04 +00:00
{
2019-09-22 19:45:23 +00:00
private FillFlowContainer fillFlow ;
private LoginOverlay loginOverlay ;
2020-05-22 17:25:05 +00:00
private ActionableInfoWithNumberBox resolution ;
2019-09-22 19:45:23 +00:00
2019-09-21 19:15:02 +00:00
[Resolved]
private MatchIPCInfo ipc { get ; set ; }
2019-09-22 19:45:23 +00:00
[Resolved]
private IAPIProvider api { get ; set ; }
2019-11-11 08:03:50 +00:00
[Resolved]
private RulesetStore rulesets { get ; set ; }
2020-03-13 06:44:13 +00:00
private Bindable < Size > windowSize ;
2019-09-21 19:15:02 +00:00
[BackgroundDependencyLoader]
2020-03-13 06:44:13 +00:00
private void load ( FrameworkConfigManager frameworkConfig )
2019-09-21 19:15:02 +00:00
{
2020-03-13 06:44:13 +00:00
windowSize = frameworkConfig . GetBindable < Size > ( FrameworkSetting . WindowedSize ) ;
2019-09-22 19:45:23 +00:00
InternalChild = fillFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y ,
Direction = FillDirection . Vertical ,
Padding = new MarginPadding ( 10 ) ,
Spacing = new Vector2 ( 10 ) ,
} ;
api . LocalUser . BindValueChanged ( _ = > Schedule ( reload ) ) ;
2019-09-22 19:22:50 +00:00
reload ( ) ;
}
2020-03-13 06:44:13 +00:00
[Resolved]
private Framework . Game game { get ; set ; }
2019-09-22 19:22:50 +00:00
private void reload ( )
{
var fileBasedIpc = ipc as FileBasedIPC ;
2019-09-22 19:45:23 +00:00
fillFlow . Children = new Drawable [ ]
2019-09-22 19:22:50 +00:00
{
new ActionableInfo
{
Label = "Current IPC source" ,
ButtonText = "Refresh" ,
Action = ( ) = >
{
fileBasedIpc ? . LocateStableStorage ( ) ;
reload ( ) ;
} ,
Value = fileBasedIpc ? . Storage ? . GetFullPath ( string . Empty ) ? ? "Not found" ,
Failing = fileBasedIpc ? . Storage = = null ,
Description = "The osu!stable installation which is currently being used as a data source. If a source is not found, make sure you have created an empty ipc.txt in your stable cutting-edge installation, and that it is registered as the default osu! install."
2019-09-22 19:45:23 +00:00
} ,
new ActionableInfo
{
Label = "Current User" ,
ButtonText = "Change Login" ,
Action = ( ) = >
{
api . Logout ( ) ;
if ( loginOverlay = = null )
{
2019-09-22 19:49:21 +00:00
AddInternal ( loginOverlay = new LoginOverlay
2019-09-22 19:45:23 +00:00
{
Anchor = Anchor . TopRight ,
Origin = Anchor . TopRight ,
} ) ;
}
loginOverlay . State . Value = Visibility . Visible ;
} ,
Value = api ? . LocalUser . Value . Username ,
Failing = api ? . IsLoggedIn ! = true ,
Description = "In order to access the API and display metadata, a login is required."
2019-11-11 08:03:50 +00:00
} ,
new LabelledDropdown < RulesetInfo >
{
Label = "Ruleset" ,
Description = "Decides what stats are displayed and which ranks are retrieved for players" ,
Items = rulesets . AvailableRulesets ,
Current = LadderInfo . Ruleset ,
} ,
2020-05-22 17:25:05 +00:00
resolution = new ActionableInfoWithNumberBox
2020-03-13 06:44:13 +00:00
{
Label = "Stream area resolution" ,
2020-05-22 17:25:05 +00:00
ButtonText = "Set size" ,
Action = i = >
2020-03-13 06:44:13 +00:00
{
2020-05-22 17:25:05 +00:00
i = Math . Clamp ( i , 480 , 2160 ) ;
windowSize . Value = new Size ( ( int ) ( i * aspect_ratio / TournamentSceneManager . STREAM_AREA_WIDTH * TournamentSceneManager . REQUIRED_WIDTH ) , i ) ;
resolution . NumberValue = i ;
2020-03-13 06:44:13 +00:00
}
2020-03-23 02:47:24 +00:00
} ,
2019-09-22 19:22:50 +00:00
} ;
}
2020-05-22 17:25:05 +00:00
private const float aspect_ratio = 16f / 9f ;
2020-03-13 06:44:13 +00:00
protected override void Update ( )
{
base . Update ( ) ;
resolution . Value = $"{ScreenSpaceDrawQuad.Width:N0}x{ScreenSpaceDrawQuad.Height:N0}" ;
}
2019-11-12 02:04:49 +00:00
public class LabelledDropdown < T > : LabelledComponent < OsuDropdown < T > , T >
{
public LabelledDropdown ( )
: base ( true )
{
}
public IEnumerable < T > Items
{
get = > Component . Items ;
set = > Component . Items = value ;
}
protected override OsuDropdown < T > CreateComponent ( ) = > new OsuDropdown < T >
{
RelativeSizeAxes = Axes . X ,
Width = 0.5f ,
} ;
}
2019-10-28 06:33:08 +00:00
private class ActionableInfo : LabelledDrawable < Drawable >
2019-09-22 19:22:50 +00:00
{
2020-05-22 17:25:05 +00:00
protected OsuButton Button ;
2019-09-22 19:22:50 +00:00
public ActionableInfo ( )
: base ( true )
{
}
public string ButtonText
{
2020-05-22 17:25:05 +00:00
set = > Button . Text = value ;
2019-09-22 19:22:50 +00:00
}
public string Value
{
2020-05-22 17:25:05 +00:00
set = > ValueText . Text = value ;
2019-09-22 19:22:50 +00:00
}
public bool Failing
{
2020-05-22 17:25:05 +00:00
set = > ValueText . Colour = value ? Color4 . Red : Color4 . White ;
2019-09-22 19:22:50 +00:00
}
public Action Action ;
2020-05-22 17:25:05 +00:00
protected TournamentSpriteText ValueText ;
2019-09-22 19:22:50 +00:00
protected override Drawable CreateComponent ( ) = > new Container
2019-09-21 19:15:02 +00:00
{
2019-09-22 19:22:50 +00:00
AutoSizeAxes = Axes . Y ,
RelativeSizeAxes = Axes . X ,
Children = new Drawable [ ]
{
2020-05-22 17:25:05 +00:00
ValueText = new TournamentSpriteText
2019-09-22 19:22:50 +00:00
{
Anchor = Anchor . CentreLeft ,
Origin = Anchor . CentreLeft ,
} ,
2020-05-22 17:25:05 +00:00
Button = new TriangleButton
2019-09-22 19:22:50 +00:00
{
Anchor = Anchor . CentreRight ,
Origin = Anchor . CentreRight ,
Size = new Vector2 ( 100 , 30 ) ,
Action = ( ) = > Action ? . Invoke ( )
} ,
}
} ;
2019-09-21 19:15:02 +00:00
}
2020-05-22 17:25:05 +00:00
private class ActionableInfoWithNumberBox : ActionableInfo
{
public new Action < int > Action ;
private OsuNumberBox numberBox ;
public int NumberValue
{
get
{
int . TryParse ( numberBox . Text , out var val ) ;
return val ;
}
set = > numberBox . Text = value . ToString ( ) ;
}
protected override Drawable CreateComponent ( ) = > new Container
{
AutoSizeAxes = Axes . Y ,
RelativeSizeAxes = Axes . X ,
Children = new Drawable [ ]
{
ValueText = new TournamentSpriteText
{
Anchor = Anchor . CentreLeft ,
Origin = Anchor . CentreLeft ,
} ,
numberBox = new OsuNumberBox
{
Anchor = Anchor . CentreRight ,
Origin = Anchor . CentreRight ,
Width = 100 ,
Margin = new MarginPadding
{
Right = 110
}
} ,
Button = new TriangleButton
{
Anchor = Anchor . CentreRight ,
Origin = Anchor . CentreRight ,
Size = new Vector2 ( 100 , 30 ) ,
Action = ( ) = >
{
if ( numberBox . Text . Length > 0 ) Action ? . Invoke ( NumberValue ) ;
}
} ,
}
} ;
}
2019-09-21 17:10:04 +00:00
}
}