2019-01-24 16:43:03 +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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2016-10-13 22:57:05 +08:00
using System ;
2017-03-05 02:42:37 +08:00
using osu.Framework.Extensions.Color4Extensions ;
2016-09-30 17:45:27 +08:00
using osu.Framework.Graphics ;
2016-12-01 13:22:29 +08:00
using osu.Framework.Graphics.Colour ;
2016-09-30 17:45:27 +08:00
using osu.Framework.Graphics.Containers ;
2016-10-13 22:57:05 +08:00
using osu.Game.Graphics ;
2018-11-20 15:51:59 +08:00
using osuTK ;
2017-06-20 13:54:23 +08:00
using osu.Framework.Graphics.Shapes ;
2018-05-28 19:43:47 +08:00
using osu.Framework.Allocation ;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables ;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events ;
2019-06-25 04:13:28 +08:00
using osu.Game.Rulesets ;
2020-11-10 06:45:20 +08:00
using osu.Framework.Input.Bindings ;
2022-06-15 00:43:10 +08:00
using osu.Game.Graphics.Containers ;
2020-11-10 06:45:20 +08:00
using osu.Game.Input.Bindings ;
2018-04-13 17:19:50 +08:00
2016-12-01 13:22:29 +08:00
namespace osu.Game.Overlays.Toolbar
2016-09-30 17:45:27 +08:00
{
2021-09-01 03:39:18 +08:00
public partial class Toolbar : OverlayContainer , IKeyBindingHandler < GlobalAction >
2016-09-30 17:45:27 +08:00
{
2017-02-08 19:14:17 +08:00
public const float HEIGHT = 40 ;
2017-02-10 15:26:43 +08:00
public const float TOOLTIP_HEIGHT = 30 ;
2018-04-13 17:19:50 +08:00
2020-11-10 07:16:35 +08:00
/// <summary>
/// Whether the user hid this <see cref="Toolbar"/> with <see cref="GlobalAction.ToggleToolbar"/>.
2021-03-13 22:29:47 +08:00
/// In this state, automatic toggles should not occur, respecting the user's preference to have no toolbar.
2020-11-10 07:16:35 +08:00
/// </summary>
2021-03-13 16:05:26 +08:00
private bool hiddenByUser ;
2016-10-04 16:15:03 +08:00
public Action OnHome ;
2018-04-13 17:19:50 +08:00
2019-03-28 13:01:06 +08:00
private ToolbarUserButton userButton ;
2019-06-25 04:13:28 +08:00
private ToolbarRulesetSelector rulesetSelector ;
2018-04-13 17:19:50 +08:00
2017-03-09 14:52:40 +08:00
private const double transition_time = 500 ;
2018-04-13 17:19:50 +08:00
2020-08-28 02:07:24 +08:00
protected readonly IBindable < OverlayActivation > OverlayActivationMode = new Bindable < OverlayActivation > ( OverlayActivation . All ) ;
2018-05-28 19:43:47 +08:00
2020-11-10 06:45:20 +08:00
// Toolbar and its components need keyboard input even when hidden.
2020-04-25 14:53:09 +08:00
public override bool PropagateNonPositionalInputSubTree = > true ;
2019-03-08 14:14:07 +08:00
public Toolbar ( )
{
RelativeSizeAxes = Axes . X ;
Size = new Vector2 ( 1 , HEIGHT ) ;
2021-02-25 13:52:51 +08:00
AlwaysPresent = true ;
}
protected override void UpdateAfterChildren ( )
{
base . UpdateAfterChildren ( ) ;
// this only needed to be set for the initial LoadComplete/Update, so layout completes and gets buttons in a state they can correctly handle keyboard input for hotkeys.
AlwaysPresent = false ;
2019-03-08 14:14:07 +08:00
}
2022-01-10 15:31:28 +08:00
[Resolved]
private Bindable < RulesetInfo > ruleset { get ; set ; }
2019-03-08 11:01:40 +08:00
[BackgroundDependencyLoader(true)]
2022-01-10 15:31:28 +08:00
private void load ( OsuGame osuGame )
2016-09-30 17:45:27 +08:00
{
Children = new Drawable [ ]
{
2017-01-30 22:24:30 +08:00
new ToolbarBackground ( ) ,
2022-06-15 00:43:10 +08:00
new GridContainer
2016-10-03 19:39:32 +08:00
{
2022-06-15 00:43:10 +08:00
RelativeSizeAxes = Axes . Both ,
ColumnDimensions = new [ ]
2016-10-03 19:39:32 +08:00
{
2022-06-15 00:43:10 +08:00
new Dimension ( GridSizeMode . AutoSize ) ,
new Dimension ( ) ,
new Dimension ( GridSizeMode . AutoSize )
} ,
Content = new [ ]
{
new Drawable [ ]
2016-10-04 16:15:03 +08:00
{
2022-06-15 00:43:10 +08:00
new Container
{
Name = "Left buttons" ,
RelativeSizeAxes = Axes . Y ,
AutoSizeAxes = Axes . X ,
Depth = float . MinValue ,
Children = new Drawable [ ]
{
new Box
{
Colour = OsuColour . Gray ( 0.1f ) ,
RelativeSizeAxes = Axes . Both ,
} ,
new FillFlowContainer
{
Direction = FillDirection . Horizontal ,
RelativeSizeAxes = Axes . Y ,
AutoSizeAxes = Axes . X ,
Children = new Drawable [ ]
{
new ToolbarSettingsButton ( ) ,
new ToolbarHomeButton
{
Action = ( ) = > OnHome ? . Invoke ( )
} ,
} ,
} ,
}
} ,
new Container
{
Name = "Ruleset selector" ,
RelativeSizeAxes = Axes . Both ,
Children = new Drawable [ ]
{
new OsuScrollContainer ( Direction . Horizontal )
{
ScrollbarVisible = false ,
RelativeSizeAxes = Axes . Both ,
Masking = false ,
Children = new Drawable [ ]
{
rulesetSelector = new ToolbarRulesetSelector ( )
}
} ,
new Box
{
Colour = ColourInfo . GradientHorizontal ( OsuColour . Gray ( 0.1f ) . Opacity ( 0 ) , OsuColour . Gray ( 0.1f ) ) ,
Width = 50 ,
RelativeSizeAxes = Axes . Y ,
Anchor = Anchor . TopRight ,
Origin = Anchor . TopRight ,
} ,
}
} ,
new Container
{
Name = "Right buttons" ,
RelativeSizeAxes = Axes . Y ,
AutoSizeAxes = Axes . X ,
2022-10-30 06:25:16 +08:00
Anchor = Anchor . TopRight ,
Origin = Anchor . TopRight ,
2022-06-15 00:43:10 +08:00
Children = new Drawable [ ]
{
new Box
{
Colour = OsuColour . Gray ( 0.1f ) ,
RelativeSizeAxes = Axes . Both ,
} ,
new FillFlowContainer
{
Anchor = Anchor . TopRight ,
Origin = Anchor . TopRight ,
Direction = FillDirection . Horizontal ,
RelativeSizeAxes = Axes . Y ,
AutoSizeAxes = Axes . X ,
Children = new Drawable [ ]
{
new ToolbarNewsButton ( ) ,
new ToolbarChangelogButton ( ) ,
new ToolbarRankingsButton ( ) ,
new ToolbarBeatmapListingButton ( ) ,
new ToolbarChatButton ( ) ,
new ToolbarSocialButton ( ) ,
new ToolbarWikiButton ( ) ,
new ToolbarMusicButton ( ) ,
//new ToolbarButton
//{
// Icon = FontAwesome.Solid.search
//},
userButton = new ToolbarUserButton ( ) ,
new ToolbarClock ( ) ,
new ToolbarNotificationButton ( ) ,
}
} ,
}
} ,
2016-10-04 16:15:03 +08:00
} ,
2016-10-03 19:39:32 +08:00
}
2016-09-30 17:45:27 +08:00
}
} ;
2018-04-13 17:19:50 +08:00
2018-09-05 09:38:05 +08:00
if ( osuGame ! = null )
2020-08-18 21:25:51 +08:00
OverlayActivationMode . BindTo ( osuGame . OverlayActivationMode ) ;
2018-05-28 19:43:47 +08:00
}
2022-01-10 15:31:28 +08:00
protected override void LoadComplete ( )
{
base . LoadComplete ( ) ;
rulesetSelector . Current . BindTo ( ruleset ) ;
}
2017-01-30 22:24:30 +08:00
public partial class ToolbarBackground : Container
{
2017-03-23 12:41:50 +08:00
private readonly Box gradientBackground ;
2018-04-13 17:19:50 +08:00
2017-01-30 22:24:30 +08:00
public ToolbarBackground ( )
{
RelativeSizeAxes = Axes . Both ;
Children = new Drawable [ ]
{
2020-07-08 12:36:32 +08:00
new Box
2017-01-30 22:24:30 +08:00
{
RelativeSizeAxes = Axes . Both ,
Colour = OsuColour . Gray ( 0.1f ) ,
} ,
gradientBackground = new Box
{
RelativeSizeAxes = Axes . X ,
Anchor = Anchor . BottomLeft ,
Alpha = 0 ,
2020-08-17 13:56:05 +08:00
Height = 100 ,
2017-07-23 13:30:50 +08:00
Colour = ColourInfo . GradientVertical (
2020-08-17 13:56:05 +08:00
OsuColour . Gray ( 0 ) . Opacity ( 0.9f ) , OsuColour . Gray ( 0 ) . Opacity ( 0 ) ) ,
2017-01-30 22:24:30 +08:00
} ,
} ;
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
protected override bool OnHover ( HoverEvent e )
2017-01-30 22:24:30 +08:00
{
2017-07-23 02:50:25 +08:00
gradientBackground . FadeIn ( transition_time , Easing . OutQuint ) ;
2021-08-31 11:53:43 +08:00
return true ;
2017-01-30 22:24:30 +08:00
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost ( HoverLostEvent e )
2017-01-30 22:24:30 +08:00
{
2017-07-23 02:50:25 +08:00
gradientBackground . FadeOut ( transition_time , Easing . OutQuint ) ;
2017-01-30 22:24:30 +08:00
}
}
2018-04-13 17:19:50 +08:00
2020-08-18 21:25:51 +08:00
protected override void UpdateState ( ValueChangedEvent < Visibility > state )
{
2021-03-13 22:29:01 +08:00
bool blockShow = hiddenByUser | | OverlayActivationMode . Value = = OverlayActivation . Disabled ;
2021-03-13 16:05:26 +08:00
2021-03-13 22:29:01 +08:00
if ( state . NewValue = = Visibility . Visible & & blockShow )
2020-08-18 21:25:51 +08:00
{
State . Value = Visibility . Hidden ;
return ;
}
base . UpdateState ( state ) ;
}
2017-01-30 21:53:50 +08:00
protected override void PopIn ( )
{
2017-07-23 02:50:25 +08:00
this . MoveToY ( 0 , transition_time , Easing . OutQuint ) ;
2020-07-08 14:06:40 +08:00
this . FadeIn ( transition_time / 4 , Easing . OutQuint ) ;
2017-01-30 21:53:50 +08:00
}
2018-04-13 17:19:50 +08:00
2017-01-30 21:53:50 +08:00
protected override void PopOut ( )
{
2020-04-25 14:45:11 +08:00
userButton . StateContainer ? . Hide ( ) ;
2018-04-13 17:19:50 +08:00
2017-07-23 02:50:25 +08:00
this . MoveToY ( - DrawSize . Y , transition_time , Easing . OutQuint ) ;
2020-07-08 14:06:40 +08:00
this . FadeOut ( transition_time , Easing . InQuint ) ;
2017-01-30 21:53:50 +08:00
}
2020-11-10 06:45:20 +08:00
2021-09-16 17:26:12 +08:00
public bool OnPressed ( KeyBindingPressEvent < GlobalAction > e )
2020-11-10 06:45:20 +08:00
{
2020-11-10 06:46:08 +08:00
if ( OverlayActivationMode . Value = = OverlayActivation . Disabled )
return false ;
2021-09-16 17:26:12 +08:00
switch ( e . Action )
2020-11-10 06:45:20 +08:00
{
case GlobalAction . ToggleToolbar :
2021-03-13 22:29:01 +08:00
hiddenByUser = State . Value = = Visibility . Visible ; // set before toggling to allow the operation to always succeed.
2020-11-10 06:45:20 +08:00
ToggleVisibility ( ) ;
return true ;
}
return false ;
}
2021-09-16 17:26:12 +08:00
public void OnReleased ( KeyBindingReleaseEvent < GlobalAction > e )
2020-11-10 06:45:20 +08:00
{
}
2016-09-30 17:45:27 +08:00
}
}