osu/osu.Game/Overlays/Toolbar.cs

120 lines
3.8 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
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using OpenTK;
using OpenTK.Graphics;
2016-10-03 11:39:32 +00:00
using osu.Game.Graphics;
using osu.Game.Configuration;
using System;
2016-10-07 11:38:52 +00:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Timing;
using osu.Game.GameModes.Play;
2016-09-30 09:45:27 +00:00
namespace osu.Game.Overlays
{
2016-10-04 10:57:32 +00:00
public class Toolbar : Container
2016-09-30 09:45:27 +00:00
{
const float height = 50;
public Action OnSettings;
public Action OnHome;
public Action<PlayMode> OnPlayModeChange;
private ToolbarModeSelector modeSelector;
2016-09-30 09:45:27 +00:00
2016-10-07 11:38:52 +00:00
public void SetState(ToolbarState state, bool instant = false)
{
int time = instant ? 0 : 200;
switch (state)
{
case ToolbarState.Hidden:
MoveToY(-Size.Y, time, EasingTypes.InQuint);
FadeOut(time);
break;
case ToolbarState.Visible:
MoveToY(0, time, EasingTypes.OutQuint);
FadeIn(time);
break;
}
}
2016-09-30 09:45:27 +00:00
public override void Load()
{
base.Load();
RelativeSizeAxes = Axes.X;
2016-09-30 09:45:27 +00:00
Size = new Vector2(1, height);
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,
Children = new Drawable[]
2016-10-03 11:39:32 +00:00
{
new ToolbarButton
{
Icon = FontAwesome.gear,
Action = OnSettings,
2016-10-04 10:57:32 +00:00
TooltipMain = "Settings",
TooltipSub = "Change your settings",
},
new ToolbarButton
{
Icon = FontAwesome.home,
TooltipMain = "Home",
2016-10-04 10:57:32 +00:00
TooltipSub = "Return to the main menu",
Action = OnHome
},
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,
Children = new []
{
new ToolbarButton
{
Icon = FontAwesome.search
},
new ToolbarButton
{
Icon = FontAwesome.user,
Text = ((OsuGame)Game).Config.Get<string>(OsuConfig.Username)
},
new ToolbarButton
{
Icon = FontAwesome.bars
},
2016-10-03 11:39:32 +00:00
}
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
}
2016-10-07 11:38:52 +00:00
public enum ToolbarState
{
Visible,
Hidden,
}
2016-09-30 09:45:27 +00:00
}