mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 23:07:26 +08:00
167 lines
5.8 KiB
C#
167 lines
5.8 KiB
C#
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using System;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Colour;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Graphics.Transformations;
|
|
using osu.Framework.Input;
|
|
using osu.Game.Configuration;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Modes;
|
|
using osu.Game.Online.API;
|
|
using OpenTK;
|
|
using OpenTK.Graphics;
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
{
|
|
public class Toolbar : OverlayContainer, IOnlineComponent
|
|
{
|
|
private const float height = 50;
|
|
|
|
public Action OnSettings;
|
|
public Action OnHome;
|
|
public Action<PlayMode> OnPlayModeChange;
|
|
public Action OnMusicController;
|
|
|
|
private ToolbarModeSelector modeSelector;
|
|
private ToolbarButton userButton;
|
|
private Box solidBackground;
|
|
private Box gradientBackground;
|
|
|
|
private const int transition_time = 250;
|
|
|
|
private const float alpha_hovering = 0.8f;
|
|
private const float alpha_normal = 0.6f;
|
|
|
|
|
|
protected override void PopIn()
|
|
{
|
|
MoveToY(0, transition_time, EasingTypes.OutQuint);
|
|
FadeIn(transition_time, EasingTypes.OutQuint);
|
|
}
|
|
|
|
protected override void PopOut()
|
|
{
|
|
MoveToY(-DrawSize.Y, transition_time, EasingTypes.InQuint);
|
|
FadeOut(transition_time, EasingTypes.InQuint);
|
|
}
|
|
|
|
protected override bool OnHover(InputState state)
|
|
{
|
|
solidBackground.FadeTo(alpha_hovering, transition_time, EasingTypes.OutQuint);
|
|
gradientBackground.FadeIn(transition_time, EasingTypes.OutQuint);
|
|
return true;
|
|
}
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
{
|
|
solidBackground.FadeTo(alpha_normal, transition_time, EasingTypes.OutQuint);
|
|
gradientBackground.FadeOut(transition_time, EasingTypes.OutQuint);
|
|
}
|
|
|
|
public Toolbar()
|
|
{
|
|
Children = new Drawable[]
|
|
{
|
|
solidBackground = new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = new Color4(0.1f, 0.1f, 0.1f, 1),
|
|
Alpha = alpha_normal,
|
|
},
|
|
gradientBackground = new Box
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
Anchor = Anchor.BottomLeft,
|
|
Alpha = 0,
|
|
Height = 90,
|
|
ColourInfo = ColourInfo.GradientVertical(new Color4(0.1f, 0.1f, 0.1f, 0.5f), new Color4(0.1f, 0.1f, 0.1f, 0f)),
|
|
},
|
|
new FlowContainer
|
|
{
|
|
Direction = FlowDirection.HorizontalOnly,
|
|
RelativeSizeAxes = Axes.Y,
|
|
AutoSizeAxes = Axes.X,
|
|
Children = new Drawable[]
|
|
{
|
|
new ToolbarButton
|
|
{
|
|
Icon = FontAwesome.fa_gear,
|
|
TooltipMain = "Settings",
|
|
TooltipSub = "Change your settings",
|
|
Action = () => OnSettings?.Invoke()
|
|
},
|
|
new ToolbarButton
|
|
{
|
|
Icon = FontAwesome.fa_home,
|
|
TooltipMain = "Home",
|
|
TooltipSub = "Return to the main menu",
|
|
Action = () => OnHome?.Invoke()
|
|
},
|
|
modeSelector = new ToolbarModeSelector
|
|
{
|
|
OnPlayModeChange = OnPlayModeChange
|
|
}
|
|
}
|
|
},
|
|
new FlowContainer
|
|
{
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
Direction = FlowDirection.HorizontalOnly,
|
|
RelativeSizeAxes = Axes.Y,
|
|
AutoSizeAxes = Axes.X,
|
|
Children = new []
|
|
{
|
|
new ToolbarButton
|
|
{
|
|
Icon = FontAwesome.fa_music,
|
|
Action = () => OnMusicController?.Invoke()
|
|
},
|
|
new ToolbarButton
|
|
{
|
|
Icon = FontAwesome.fa_search
|
|
},
|
|
userButton = new ToolbarButton
|
|
{
|
|
Icon = FontAwesome.fa_user,
|
|
},
|
|
new ToolbarButton
|
|
{
|
|
Icon = FontAwesome.fa_bars
|
|
},
|
|
}
|
|
}
|
|
};
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
Size = new Vector2(1, height);
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(APIAccess api, OsuConfigManager config)
|
|
{
|
|
api.Register(this);
|
|
}
|
|
|
|
public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode);
|
|
|
|
public void APIStateChanged(APIAccess api, APIState state)
|
|
{
|
|
switch (state)
|
|
{
|
|
default:
|
|
userButton.Text = @"Guest";
|
|
break;
|
|
case APIState.Online:
|
|
userButton.Text = api.Username;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|