1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00

Merge pull request #328 from peppy/main-menu-onclick

Change main menu buttons to be activated OnClick.
This commit is contained in:
Thomas Müller 2017-02-07 15:29:58 +01:00 committed by GitHub
commit 82b8b5af79
4 changed files with 62 additions and 17 deletions

View File

@ -27,6 +27,8 @@ namespace osu.Game.Screens.Menu
{ {
private Container iconText; private Container iconText;
private Container box; private Container box;
private Box boxColourLayer;
private Box boxHoverLayer;
private Color4 colour; private Color4 colour;
private TextAwesome icon; private TextAwesome icon;
private string internalName; private string internalName;
@ -72,16 +74,24 @@ namespace osu.Game.Screens.Menu
}, },
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Colour = colour,
Scale = new Vector2(0, 1), Scale = new Vector2(0, 1),
Size = boxSize, Size = boxSize,
Shear = new Vector2(ButtonSystem.WEDGE_WIDTH / boxSize.Y, 0), Shear = new Vector2(ButtonSystem.WEDGE_WIDTH / boxSize.Y, 0),
Children = new Drawable[] Children = new []
{ {
new Box boxColourLayer = new Box
{ {
EdgeSmoothness = new Vector2(1.5f, 0), EdgeSmoothness = new Vector2(1.5f, 0),
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colour,
},
boxHoverLayer = new Box
{
EdgeSmoothness = new Vector2(1.5f, 0),
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = Color4.White,
Alpha = 0,
}, },
} }
}, },
@ -228,6 +238,18 @@ namespace osu.Game.Screens.Menu
} }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
boxHoverLayer.FadeTo(0.1f, 1000, EasingTypes.OutQuint);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
boxHoverLayer.FadeTo(0, 1000, EasingTypes.OutQuint);
return base.OnMouseUp(state, args);
}
protected override bool OnClick(InputState state)
{ {
trigger(); trigger();
return true; return true;
@ -235,7 +257,7 @@ namespace osu.Game.Screens.Menu
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{ {
base.OnKeyDown(state, args); if (args.Repeat) return false;
if (triggerKey == args.Key && triggerKey != Key.Unknown) if (triggerKey == args.Key && triggerKey != Key.Unknown)
{ {
@ -250,9 +272,11 @@ namespace osu.Game.Screens.Menu
{ {
sampleClick.Play(); sampleClick.Play();
box.FlashColour(Color4.White, 500, EasingTypes.OutExpo);
clickAction?.Invoke(); clickAction?.Invoke();
boxHoverLayer.ClearTransformations();
boxHoverLayer.Alpha = 0.9f;
boxHoverLayer.FadeOut(800, EasingTypes.OutExpo);
} }
public override bool HandleInput => state != ButtonState.Exploded && box.Scale.X >= 0.8f; public override bool HandleInput => state != ButtonState.Exploded && box.Scale.X >= 0.8f;

View File

@ -85,7 +85,7 @@ namespace osu.Game.Screens.Menu
Children = new[] Children = new[]
{ {
settingsButton = new Button(@"settings", @"options", FontAwesome.fa_gear, new Color4(85, 85, 85, 255), () => OnSettings?.Invoke(), -WEDGE_WIDTH, Key.O), settingsButton = new Button(@"settings", @"options", FontAwesome.fa_gear, new Color4(85, 85, 85, 255), () => OnSettings?.Invoke(), -WEDGE_WIDTH, Key.O),
backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -WEDGE_WIDTH, Key.Escape), backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -WEDGE_WIDTH),
iconFacade = new Container //need a container to make the osu! icon flow properly. iconFacade = new Container //need a container to make the osu! icon flow properly.
{ {
Size = new Vector2(0, BUTTON_AREA_HEIGHT) Size = new Vector2(0, BUTTON_AREA_HEIGHT)
@ -132,17 +132,26 @@ namespace osu.Game.Screens.Menu
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{ {
if (args.Repeat) return false;
switch (args.Key) switch (args.Key)
{ {
case Key.Space: case Key.Space:
osuLogo.TriggerClick(state); osuLogo.TriggerClick(state);
return true; return true;
case Key.Escape: case Key.Escape:
if (State == MenuState.Initial) switch (State)
return false; {
case MenuState.TopLevel:
State = MenuState.Initial; State = MenuState.Initial;
return true; return true;
case MenuState.Play:
backButton.TriggerClick();
return true;
}
return false;
} }
return false; return false;
@ -172,10 +181,10 @@ namespace osu.Game.Screens.Menu
State = MenuState.TopLevel; State = MenuState.TopLevel;
return; return;
case MenuState.TopLevel: case MenuState.TopLevel:
buttonsTopLevel.First().TriggerMouseDown(); buttonsTopLevel.First().TriggerClick();
return; return;
case MenuState.Play: case MenuState.Play:
buttonsPlay.First().TriggerMouseDown(); buttonsPlay.First().TriggerClick();
return; return;
} }
} }
@ -207,7 +216,7 @@ namespace osu.Game.Screens.Menu
{ {
case MenuState.Initial: case MenuState.Initial:
buttonAreaBackground.ScaleTo(Vector2.One, 500, EasingTypes.Out); buttonAreaBackground.ScaleTo(Vector2.One, 500, EasingTypes.Out);
buttonArea.FadeOut(500); buttonArea.FadeOut(300);
osuLogo.Delay(150); osuLogo.Delay(150);
osuLogo.MoveTo(Vector2.Zero, 800, EasingTypes.OutExpo); osuLogo.MoveTo(Vector2.Zero, 800, EasingTypes.OutExpo);
@ -220,6 +229,8 @@ namespace osu.Game.Screens.Menu
b.State = ButtonState.Contracted; b.State = ButtonState.Contracted;
break; break;
case MenuState.TopLevel: case MenuState.TopLevel:
buttonArea.Flush(true);
buttonAreaBackground.ScaleTo(Vector2.One, 200, EasingTypes.Out); buttonAreaBackground.ScaleTo(Vector2.One, 200, EasingTypes.Out);
osuLogo.MoveTo(buttonFlow.DrawPosition, 200, EasingTypes.In); osuLogo.MoveTo(buttonFlow.DrawPosition, 200, EasingTypes.In);
@ -288,6 +299,8 @@ namespace osu.Game.Screens.Menu
//if (OsuGame.IdleTime > 6000 && State != MenuState.Exit) //if (OsuGame.IdleTime > 6000 && State != MenuState.Exit)
// State = MenuState.Initial; // State = MenuState.Initial;
osuLogo.Interactive = Alpha > 0.2f;
iconFacade.Width = osuLogo.SizeForFlow * 0.5f; iconFacade.Width = osuLogo.SizeForFlow * 0.5f;
base.Update(); base.Update();
} }

View File

@ -65,9 +65,10 @@ namespace osu.Game.Screens.Menu
buttons.OnSettings = game.ToggleOptions; buttons.OnSettings = game.ToggleOptions;
} }
protected override void LoadComplete() protected override void OnEntering(GameMode last)
{ {
base.LoadComplete();
base.OnEntering(last);
buttons.FadeInFromZero(500); buttons.FadeInFromZero(500);
} }

View File

@ -4,6 +4,8 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -32,6 +34,8 @@ namespace osu.Game.Screens.Menu
private Container logoHoverContainer; private Container logoHoverContainer;
private MenuVisualisation vis; private MenuVisualisation vis;
private AudioSample sampleClick;
private Container colourAndTriangles; private Container colourAndTriangles;
public Action Action; public Action Action;
@ -166,8 +170,9 @@ namespace osu.Game.Screens.Menu
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore textures) private void load(TextureStore textures, AudioManager audio)
{ {
sampleClick = audio.Sample.Get(@"Menu/menuhit");
logo.Texture = textures.Get(@"Menu/logo"); logo.Texture = textures.Get(@"Menu/logo");
ripple.Texture = textures.Get(@"Menu/logo"); ripple.Texture = textures.Get(@"Menu/logo");
} }
@ -200,6 +205,8 @@ namespace osu.Game.Screens.Menu
{ {
if (!Interactive) return false; if (!Interactive) return false;
sampleClick.Play();
flashLayer.ClearTransformations(); flashLayer.ClearTransformations();
flashLayer.Alpha = 0.4f; flashLayer.Alpha = 0.4f;
flashLayer.FadeOut(1500, EasingTypes.OutExpo); flashLayer.FadeOut(1500, EasingTypes.OutExpo);