osu/osu.Game/Overlays/Toolbar.cs

117 lines
3.9 KiB
C#
Raw Normal View History

2016-09-30 09:45:27 +00:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-10-13 14:57:05 +00:00
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
2016-09-30 09:45:27 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2016-10-07 11:38:52 +00:00
using osu.Framework.Graphics.Transformations;
2016-10-13 14:57:05 +00:00
using osu.Game.Configuration;
using osu.Game.GameModes.Play;
2016-10-13 14:57:05 +00:00
using osu.Game.Graphics;
2016-10-16 12:10:06 +00:00
using osu.Framework.Graphics.Sprites;
2016-09-30 09:45:27 +00:00
namespace osu.Game.Overlays
{
2016-10-16 09:14:17 +00:00
public class Toolbar : OverlayContainer
2016-09-30 09:45:27 +00:00
{
2016-10-13 14:57:05 +00:00
private const float height = 50;
public Action OnSettings;
public Action OnHome;
public Action<PlayMode> OnPlayModeChange;
private ToolbarModeSelector modeSelector;
2016-11-01 14:24:14 +00:00
private ToolbarButton userButton;
2016-09-30 09:45:27 +00:00
2016-10-13 14:57:05 +00:00
private const int transition_time = 200;
2016-10-07 11:38:52 +00:00
2016-10-13 14:57:05 +00:00
protected override void PopIn()
2016-10-07 11:38:52 +00:00
{
2016-10-13 14:57:05 +00:00
MoveToY(0, transition_time, EasingTypes.OutQuint);
FadeIn(transition_time, EasingTypes.OutQuint);
}
2016-10-07 11:38:52 +00:00
2016-10-13 14:57:05 +00:00
protected override void PopOut()
{
MoveToY(-DrawSize.Y, transition_time, EasingTypes.InQuint);
2016-10-13 14:57:05 +00:00
FadeOut(transition_time, EasingTypes.InQuint);
2016-10-07 11:38:52 +00:00
}
2016-11-01 14:24:14 +00:00
public Toolbar()
2016-09-30 09:45:27 +00:00
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(0.1f, 0.1f, 0.1f, 0.4f)
2016-10-03 11:39:32 +00:00
},
2016-10-04 10:57:32 +00:00
new FlowContainer
2016-10-03 11:39:32 +00:00
{
Direction = FlowDirection.HorizontalOnly,
RelativeSizeAxes = Axes.Y,
2016-10-22 09:05:46 +00:00
AutoSizeAxes = Axes.X,
Children = new Drawable[]
2016-10-03 11:39:32 +00:00
{
new ToolbarButton
{
2016-11-07 08:58:32 +00:00
Icon = FontAwesome.fa_gear,
2016-10-04 10:57:32 +00:00
TooltipMain = "Settings",
TooltipSub = "Change your settings",
2016-11-04 03:27:43 +00:00
Action = () => OnSettings?.Invoke()
},
new ToolbarButton
{
2016-11-07 08:58:32 +00:00
Icon = FontAwesome.fa_home,
TooltipMain = "Home",
2016-10-04 10:57:32 +00:00
TooltipSub = "Return to the main menu",
2016-11-04 03:27:43 +00:00
Action = () => OnHome?.Invoke()
},
modeSelector = new ToolbarModeSelector
{
2016-10-04 10:57:32 +00:00
OnPlayModeChange = OnPlayModeChange
}
2016-10-03 11:39:32 +00:00
}
},
2016-10-04 10:57:32 +00:00
new FlowContainer
2016-10-03 11:39:32 +00:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Direction = FlowDirection.HorizontalOnly,
RelativeSizeAxes = Axes.Y,
2016-10-22 09:05:46 +00:00
AutoSizeAxes = Axes.X,
2016-10-03 11:39:32 +00:00
Children = new []
{
new ToolbarButton
{
2016-11-07 08:58:32 +00:00
Icon = FontAwesome.fa_search
},
2016-11-01 14:24:14 +00:00
userButton = new ToolbarButton
{
2016-11-07 08:58:32 +00:00
Icon = FontAwesome.fa_user,
},
new ToolbarButton
{
2016-11-07 08:58:32 +00:00
Icon = FontAwesome.fa_bars
},
2016-10-03 11:39:32 +00:00
}
2016-09-30 09:45:27 +00:00
}
};
2016-11-01 14:24:14 +00:00
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, height);
}
protected override void Load(BaseGame game)
{
base.Load(game);
userButton.Text = ((OsuGame)game).Config.Get<string>(OsuConfig.Username);
2016-09-30 09:45:27 +00:00
}
2016-10-03 11:39:32 +00:00
public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode);
2016-09-30 09:45:27 +00:00
}
}