mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Merge branch 'refs/heads/master' into better-anchors
# Conflicts: # osu.Game.Mode.Osu/UI/OsuComboCounter.cs # osu.Game.Mode.Osu/UI/OsuScoreOverlay.cs
This commit is contained in:
282
osu.Game/Screens/Menu/Button.cs
Normal file
282
osu.Game/Screens/Menu/Button.cs
Normal file
@ -0,0 +1,282 @@
|
||||
using System;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// Button designed specifically for the osu!next main menu.
|
||||
/// In order to correctly flow, we have to use a negative margin on the parent container (due to the parallelogram shape).
|
||||
/// </summary>
|
||||
public class Button : Container, IStateful<ButtonState>
|
||||
{
|
||||
private Container iconText;
|
||||
private Box box;
|
||||
private Color4 colour;
|
||||
private TextAwesome icon;
|
||||
private string internalName;
|
||||
private readonly FontAwesome symbol;
|
||||
private Action clickAction;
|
||||
private readonly float extraWidth;
|
||||
private Key triggerKey;
|
||||
private string text;
|
||||
|
||||
public override bool Contains(Vector2 screenSpacePos)
|
||||
{
|
||||
return box.Contains(screenSpacePos);
|
||||
}
|
||||
|
||||
public Button(string text, string internalName, FontAwesome symbol, Color4 colour, Action clickAction = null, float extraWidth = 0, Key triggerKey = Key.Unknown)
|
||||
{
|
||||
this.internalName = internalName;
|
||||
this.symbol = symbol;
|
||||
this.colour = colour;
|
||||
this.clickAction = clickAction;
|
||||
this.extraWidth = extraWidth;
|
||||
this.triggerKey = triggerKey;
|
||||
this.text = text;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Alpha = 0;
|
||||
|
||||
Vector2 boxSize = new Vector2(ButtonSystem.button_width + Math.Abs(extraWidth), ButtonSystem.button_area_height);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
box = new Box
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = colour,
|
||||
Scale = new Vector2(0, 1),
|
||||
Size = boxSize,
|
||||
Shear = new Vector2(ButtonSystem.wedge_width / boxSize.Y, 0),
|
||||
EdgeSmoothness = new Vector2(2, 0),
|
||||
},
|
||||
iconText = new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Position = new Vector2(extraWidth / 2, 0),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
icon = new TextAwesome
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
TextSize = 30,
|
||||
Position = new Vector2(0, 0),
|
||||
Icon = symbol
|
||||
},
|
||||
new SpriteText
|
||||
{
|
||||
Direction = FlowDirection.HorizontalOnly,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
TextSize = 16,
|
||||
Position = new Vector2(0, 35),
|
||||
Text = text
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
if (State != ButtonState.Expanded) return true;
|
||||
|
||||
//if (OsuGame.Instance.IsActive)
|
||||
// Game.Audio.PlaySamplePositional($@"menu-{internalName}-hover", @"menuclick");
|
||||
|
||||
box.ScaleTo(new Vector2(1.5f, 1), 500, EasingTypes.OutElastic);
|
||||
|
||||
int duration = 0; //(int)(Game.Audio.BeatLength / 2);
|
||||
if (duration == 0) duration = 250;
|
||||
|
||||
icon.ClearTransformations();
|
||||
|
||||
icon.ScaleTo(1, 500, EasingTypes.OutElasticHalf);
|
||||
|
||||
double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration;
|
||||
double startTime = Time.Current + offset;
|
||||
|
||||
icon.RotateTo(10, offset, EasingTypes.InOutSine);
|
||||
icon.ScaleTo(new Vector2(1, 0.9f), offset, EasingTypes.Out);
|
||||
|
||||
icon.Transforms.Add(new TransformRotation
|
||||
{
|
||||
StartValue = -10,
|
||||
EndValue = 10,
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration * 2,
|
||||
Easing = EasingTypes.InOutSine,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration * 2
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformPosition
|
||||
{
|
||||
StartValue = Vector2.Zero,
|
||||
EndValue = new Vector2(0, -10),
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration,
|
||||
Easing = EasingTypes.Out,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformScale
|
||||
{
|
||||
StartValue = new Vector2(1, 0.9f),
|
||||
EndValue = Vector2.One,
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration,
|
||||
Easing = EasingTypes.Out,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformPosition
|
||||
{
|
||||
StartValue = new Vector2(0, -10),
|
||||
EndValue = Vector2.Zero,
|
||||
StartTime = startTime + duration,
|
||||
EndTime = startTime + duration * 2,
|
||||
Easing = EasingTypes.In,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformScale
|
||||
{
|
||||
StartValue = Vector2.One,
|
||||
EndValue = new Vector2(1, 0.9f),
|
||||
StartTime = startTime + duration,
|
||||
EndTime = startTime + duration * 2,
|
||||
Easing = EasingTypes.In,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformRotation
|
||||
{
|
||||
StartValue = 10,
|
||||
EndValue = -10,
|
||||
StartTime = startTime + duration * 2,
|
||||
EndTime = startTime + duration * 4,
|
||||
Easing = EasingTypes.InOutSine,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration * 2
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
icon.ClearTransformations();
|
||||
icon.RotateTo(0, 500, EasingTypes.Out);
|
||||
icon.MoveTo(Vector2.Zero, 500, EasingTypes.Out);
|
||||
icon.ScaleTo(0.7f, 500, EasingTypes.OutElasticHalf);
|
||||
icon.ScaleTo(Vector2.One, 200, EasingTypes.Out);
|
||||
|
||||
if (State == ButtonState.Expanded)
|
||||
box.ScaleTo(new Vector2(1, 1), 500, EasingTypes.OutElastic);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
base.OnKeyDown(state, args);
|
||||
|
||||
if (triggerKey == args.Key && triggerKey != Key.Unknown)
|
||||
{
|
||||
trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void trigger()
|
||||
{
|
||||
//Game.Audio.PlaySamplePositional($@"menu-{internalName}-click", internalName.Contains(@"back") ? @"menuback" : @"menuhit");
|
||||
|
||||
clickAction?.Invoke();
|
||||
|
||||
//box.FlashColour(ColourHelper.Lighten2(colour, 0.7f), 200);
|
||||
}
|
||||
|
||||
public override bool HandleInput => state != ButtonState.Exploded && box.Scale.X >= 0.8f;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
iconText.Alpha = MathHelper.Clamp((box.Scale.X - 0.5f) / 0.3f, 0, 1);
|
||||
base.Update();
|
||||
}
|
||||
|
||||
public int ContractStyle;
|
||||
|
||||
ButtonState state;
|
||||
public ButtonState State
|
||||
{
|
||||
get { return state; }
|
||||
set
|
||||
{
|
||||
|
||||
if (state == value)
|
||||
return;
|
||||
|
||||
state = value;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ButtonState.Contracted:
|
||||
switch (ContractStyle)
|
||||
{
|
||||
default:
|
||||
box.ScaleTo(new Vector2(0, 1), 500, EasingTypes.OutExpo);
|
||||
FadeOut(500);
|
||||
break;
|
||||
case 1:
|
||||
box.ScaleTo(new Vector2(0, 1), 400, EasingTypes.InSine);
|
||||
FadeOut(800);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ButtonState.Expanded:
|
||||
const int expand_duration = 500;
|
||||
box.ScaleTo(new Vector2(1, 1), expand_duration, EasingTypes.OutExpo);
|
||||
FadeIn(expand_duration / 6);
|
||||
break;
|
||||
case ButtonState.Exploded:
|
||||
const int explode_duration = 200;
|
||||
box.ScaleTo(new Vector2(2, 1), explode_duration, EasingTypes.OutExpo);
|
||||
FadeOut(explode_duration / 4 * 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ButtonState
|
||||
{
|
||||
Contracted,
|
||||
Expanded,
|
||||
Exploded
|
||||
}
|
||||
}
|
294
osu.Game/Screens/Menu/ButtonSystem.cs
Normal file
294
osu.Game/Screens/Menu/ButtonSystem.cs
Normal file
@ -0,0 +1,294 @@
|
||||
//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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public partial class ButtonSystem : Container, IStateful<MenuState>
|
||||
{
|
||||
public Action OnEdit;
|
||||
public Action OnExit;
|
||||
public Action OnDirect;
|
||||
public Action OnSolo;
|
||||
public Action OnSettings;
|
||||
public Action OnMulti;
|
||||
public Action OnChart;
|
||||
public Action OnTest;
|
||||
|
||||
private FlowContainerWithOrigin buttonFlow;
|
||||
|
||||
//todo: make these non-internal somehow.
|
||||
internal const float button_area_height = 100;
|
||||
internal const float button_width = 140f;
|
||||
internal const float wedge_width = 20;
|
||||
|
||||
public const int EXIT_DELAY = 3000;
|
||||
|
||||
private OsuLogo osuLogo;
|
||||
private Drawable iconFacade;
|
||||
private Container buttonArea;
|
||||
private Box buttonAreaBackground;
|
||||
|
||||
private Button backButton;
|
||||
private Button settingsButton;
|
||||
|
||||
List<Button> buttonsTopLevel = new List<Button>();
|
||||
List<Button> buttonsPlay = new List<Button>();
|
||||
|
||||
public ButtonSystem()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
buttonArea = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Size = new Vector2(1, button_area_height),
|
||||
Alpha = 0,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
buttonAreaBackground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = new Vector2(2, 1),
|
||||
Colour = new Color4(50, 50, 50, 255),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
buttonFlow = new FlowContainerWithOrigin
|
||||
{
|
||||
Direction = FlowDirection.HorizontalOnly,
|
||||
Anchor = Anchor.Centre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Spacing = new Vector2(-wedge_width, 0),
|
||||
Children = new[]
|
||||
{
|
||||
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),
|
||||
iconFacade = new Container //need a container to make the osu! icon flow properly.
|
||||
{
|
||||
Size = new Vector2(0, button_area_height)
|
||||
}
|
||||
},
|
||||
CentreTarget = iconFacade
|
||||
}
|
||||
}
|
||||
},
|
||||
osuLogo = new OsuLogo
|
||||
{
|
||||
Action = onOsuLogo,
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre
|
||||
}
|
||||
};
|
||||
|
||||
buttonsPlay.Add(new Button(@"solo", @"freeplay", FontAwesome.fa_user, new Color4(102, 68, 204, 255), () => OnSolo?.Invoke(), wedge_width, Key.P));
|
||||
buttonsPlay.Add(new Button(@"multi", @"multiplayer", FontAwesome.fa_users, new Color4(94, 63, 186, 255), () => OnMulti?.Invoke(), 0, Key.M));
|
||||
buttonsPlay.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), () => OnChart?.Invoke()));
|
||||
|
||||
buttonsTopLevel.Add(new Button(@"play", @"play", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), onPlay, wedge_width, Key.P));
|
||||
buttonsTopLevel.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), () => OnEdit?.Invoke(), 0, Key.E));
|
||||
buttonsTopLevel.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), () => OnDirect?.Invoke(), 0, Key.D));
|
||||
buttonsTopLevel.Add(new Button(@"exit", @"exit", FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), onExit, 0, Key.Q));
|
||||
|
||||
buttonFlow.Add(buttonsPlay);
|
||||
buttonFlow.Add(buttonsTopLevel);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
// osuLogo.SizeForFlow relies on loading to be complete.
|
||||
buttonFlow.Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Space:
|
||||
osuLogo.TriggerClick(state);
|
||||
return true;
|
||||
case Key.Escape:
|
||||
if (State == MenuState.Initial)
|
||||
return false;
|
||||
|
||||
State = MenuState.Initial;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onPlay()
|
||||
{
|
||||
State = MenuState.Play;
|
||||
}
|
||||
|
||||
private void onExit()
|
||||
{
|
||||
State = MenuState.Exit;
|
||||
OnExit?.Invoke();
|
||||
}
|
||||
|
||||
private void onBack()
|
||||
{
|
||||
State = MenuState.TopLevel;
|
||||
}
|
||||
|
||||
private void onOsuLogo()
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case MenuState.Initial:
|
||||
//Game.Audio.PlaySamplePositional(@"menuhit");
|
||||
State = MenuState.TopLevel;
|
||||
return;
|
||||
case MenuState.TopLevel:
|
||||
buttonsTopLevel.First().TriggerMouseDown();
|
||||
return;
|
||||
case MenuState.Play:
|
||||
buttonsPlay.First().TriggerMouseDown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MenuState state;
|
||||
|
||||
public override bool HandleInput => state != MenuState.Exit;
|
||||
|
||||
public MenuState State
|
||||
{
|
||||
get
|
||||
{
|
||||
return state;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (state == value) return;
|
||||
|
||||
MenuState lastState = state;
|
||||
state = value;
|
||||
|
||||
//todo: figure a more elegant way of doing this.
|
||||
buttonsTopLevel.ForEach(b => b.ContractStyle = 0);
|
||||
buttonsPlay.ForEach(b => b.ContractStyle = 0);
|
||||
backButton.ContractStyle = 0;
|
||||
settingsButton.ContractStyle = 0;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case MenuState.Initial:
|
||||
buttonAreaBackground.ScaleTo(Vector2.One, 500, EasingTypes.Out);
|
||||
buttonArea.FadeOut(500);
|
||||
|
||||
osuLogo.Delay(150);
|
||||
osuLogo.MoveTo(Vector2.Zero, 800, EasingTypes.OutExpo);
|
||||
osuLogo.ScaleTo(1, 800, EasingTypes.OutExpo);
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = ButtonState.Contracted;
|
||||
break;
|
||||
case MenuState.TopLevel:
|
||||
buttonAreaBackground.ScaleTo(Vector2.One, 200, EasingTypes.Out);
|
||||
|
||||
osuLogo.MoveTo(buttonFlow.DrawPosition, 200, EasingTypes.In);
|
||||
osuLogo.ScaleTo(0.5f, 200, EasingTypes.In);
|
||||
|
||||
buttonArea.FadeIn(300);
|
||||
|
||||
if (lastState == MenuState.Initial)
|
||||
//todo: this propagates to invisible children and causes delays later down the track (on first MenuState.Play)
|
||||
buttonArea.Delay(150, true);
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = ButtonState.Expanded;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = ButtonState.Contracted;
|
||||
break;
|
||||
case MenuState.Play:
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = ButtonState.Exploded;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = ButtonState.Expanded;
|
||||
break;
|
||||
case MenuState.EnteringMode:
|
||||
buttonAreaBackground.ScaleTo(new Vector2(2, 0), 300, EasingTypes.InSine);
|
||||
|
||||
buttonsTopLevel.ForEach(b => b.ContractStyle = 1);
|
||||
buttonsPlay.ForEach(b => b.ContractStyle = 1);
|
||||
backButton.ContractStyle = 1;
|
||||
settingsButton.ContractStyle = 1;
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = ButtonState.Contracted;
|
||||
break;
|
||||
case MenuState.Exit:
|
||||
buttonArea.FadeOut(200);
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
osuLogo.Delay(150);
|
||||
|
||||
osuLogo.ScaleTo(1f, EXIT_DELAY * 1.5f);
|
||||
osuLogo.RotateTo(20, EXIT_DELAY * 1.5f);
|
||||
osuLogo.FadeOut(EXIT_DELAY);
|
||||
break;
|
||||
}
|
||||
|
||||
backButton.State = state == MenuState.Play ? ButtonState.Expanded : ButtonState.Contracted;
|
||||
settingsButton.State = state == MenuState.TopLevel ? ButtonState.Expanded : ButtonState.Contracted;
|
||||
|
||||
if (lastState == MenuState.Initial)
|
||||
buttonArea.DelayReset();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
//if (OsuGame.IdleTime > 6000 && State != MenuState.Exit)
|
||||
// State = MenuState.Initial;
|
||||
|
||||
iconFacade.Width = osuLogo.SizeForFlow * 0.5f;
|
||||
base.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public enum MenuState
|
||||
{
|
||||
Initial,
|
||||
TopLevel,
|
||||
Play,
|
||||
EnteringMode,
|
||||
Exit,
|
||||
}
|
||||
}
|
31
osu.Game/Screens/Menu/FlowContainerWithOrigin.cs
Normal file
31
osu.Game/Screens/Menu/FlowContainerWithOrigin.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// A flow container with an origin based on one of its contained drawables.
|
||||
/// </summary>
|
||||
public class FlowContainerWithOrigin : FlowContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// A target drawable which this flowcontainer should be centered around.
|
||||
/// This target should be a direct child of this FlowContainer.
|
||||
/// </summary>
|
||||
public Drawable CentreTarget;
|
||||
|
||||
public override Anchor Origin => Anchor.Custom;
|
||||
|
||||
public override Vector2 OriginPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CentreTarget == null)
|
||||
return base.OriginPosition;
|
||||
|
||||
return CentreTarget.DrawPosition + CentreTarget.DrawSize / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
106
osu.Game/Screens/Menu/Intro.cs
Normal file
106
osu.Game/Screens/Menu/Intro.cs
Normal file
@ -0,0 +1,106 @@
|
||||
//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.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.GameModes;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
class Intro : OsuGameMode
|
||||
{
|
||||
private OsuLogo logo;
|
||||
|
||||
/// <summary>
|
||||
/// Whether we have loaded the menu previously.
|
||||
/// </summary>
|
||||
internal bool DidLoadMenu;
|
||||
|
||||
MainMenu mainMenu;
|
||||
private AudioSample welcome;
|
||||
private AudioTrack bgm;
|
||||
|
||||
internal override bool ShowToolbar => (ParentGameMode as OsuGameMode)?.ShowToolbar ?? false;
|
||||
|
||||
protected override BackgroundMode CreateBackground() => new BackgroundModeEmpty();
|
||||
|
||||
public Intro()
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
logo = new OsuLogo()
|
||||
{
|
||||
Alpha = 0,
|
||||
BlendingMode = BlendingMode.Additive,
|
||||
Interactive = false,
|
||||
Colour = Color4.DarkGray,
|
||||
Ripple = false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
welcome = audio.Sample.Get(@"welcome");
|
||||
|
||||
bgm = audio.Track.Get(@"circles");
|
||||
bgm.Looping = true;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Scheduler.Add(delegate
|
||||
{
|
||||
welcome.Play();
|
||||
|
||||
Scheduler.AddDelayed(delegate
|
||||
{
|
||||
bgm.Start();
|
||||
|
||||
mainMenu = new MainMenu();
|
||||
mainMenu.Preload(Game);
|
||||
|
||||
Scheduler.AddDelayed(delegate
|
||||
{
|
||||
DidLoadMenu = true;
|
||||
Push(mainMenu);
|
||||
}, 2300);
|
||||
}, 600);
|
||||
});
|
||||
|
||||
logo.ScaleTo(0.4f);
|
||||
logo.FadeOut();
|
||||
|
||||
logo.ScaleTo(1, 4400, EasingTypes.OutQuint);
|
||||
logo.FadeIn(20000, EasingTypes.OutQuint);
|
||||
}
|
||||
|
||||
protected override void OnSuspending(GameMode next)
|
||||
{
|
||||
Content.FadeOut(300);
|
||||
base.OnSuspending(next);
|
||||
}
|
||||
|
||||
protected override bool OnExiting(GameMode next)
|
||||
{
|
||||
//cancel exiting if we haven't loaded the menu yet.
|
||||
return !DidLoadMenu;
|
||||
}
|
||||
|
||||
protected override void OnResuming(GameMode last)
|
||||
{
|
||||
//we are just an intro. if we are resumed, we just want to exit after a short delay (to allow the last mode to transition out).
|
||||
Scheduler.AddDelayed(Exit, 600);
|
||||
|
||||
base.OnResuming(last);
|
||||
}
|
||||
}
|
||||
}
|
96
osu.Game/Screens/Menu/MainMenu.cs
Normal file
96
osu.Game/Screens/Menu/MainMenu.cs
Normal file
@ -0,0 +1,96 @@
|
||||
//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.Allocation;
|
||||
using osu.Framework.GameModes;
|
||||
using osu.Framework.GameModes.Testing;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Modes;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osu.Game.Screens.Charts;
|
||||
using osu.Game.Screens.Direct;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Multiplayer;
|
||||
using osu.Game.Screens.Play;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public class MainMenu : OsuGameMode
|
||||
{
|
||||
private ButtonSystem buttons;
|
||||
public override string Name => @"Main Menu";
|
||||
|
||||
internal override bool ShowToolbar => true;
|
||||
|
||||
private BackgroundMode background;
|
||||
|
||||
protected override BackgroundMode CreateBackground() => background;
|
||||
|
||||
public MainMenu()
|
||||
{
|
||||
background = new BackgroundModeDefault();
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new ParallaxContainer
|
||||
{
|
||||
ParallaxAmount = 0.01f,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
buttons = new ButtonSystem()
|
||||
{
|
||||
OnChart = delegate { Push(new ChartListing()); },
|
||||
OnDirect = delegate { Push(new OnlineListing()); },
|
||||
OnEdit = delegate { Push(new EditSongSelect()); },
|
||||
OnSolo = delegate { Push(new PlaySongSelect()); },
|
||||
OnMulti = delegate { Push(new Lobby()); },
|
||||
OnTest = delegate { Push(new TestBrowser()); },
|
||||
OnExit = delegate { Scheduler.AddDelayed(Exit, ButtonSystem.EXIT_DELAY); },
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGame game)
|
||||
{
|
||||
background.Preload(game);
|
||||
|
||||
buttons.OnSettings = game.ToggleOptions;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
buttons.FadeInFromZero(500);
|
||||
}
|
||||
|
||||
protected override void OnSuspending(GameMode next)
|
||||
{
|
||||
base.OnSuspending(next);
|
||||
|
||||
const float length = 400;
|
||||
|
||||
buttons.State = MenuState.EnteringMode;
|
||||
|
||||
Content.FadeOut(length, EasingTypes.InSine);
|
||||
Content.MoveTo(new Vector2(-800, 0), length, EasingTypes.InSine);
|
||||
}
|
||||
|
||||
protected override void OnResuming(GameMode last)
|
||||
{
|
||||
base.OnResuming(last);
|
||||
|
||||
const float length = 300;
|
||||
|
||||
buttons.State = MenuState.TopLevel;
|
||||
|
||||
Content.FadeIn(length, EasingTypes.OutQuint);
|
||||
Content.MoveTo(new Vector2(0, 0), length, EasingTypes.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
8
osu.Game/Screens/Menu/MenuVisualisation.cs
Normal file
8
osu.Game/Screens/Menu/MenuVisualisation.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
internal class MenuVisualisation : Drawable
|
||||
{
|
||||
}
|
||||
}
|
156
osu.Game/Screens/Menu/OsuLogo.cs
Normal file
156
osu.Game/Screens/Menu/OsuLogo.cs
Normal file
@ -0,0 +1,156 @@
|
||||
//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.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// osu! logo and its attachments (pulsing, visualiser etc.)
|
||||
/// </summary>
|
||||
public partial class OsuLogo : Container
|
||||
{
|
||||
private Sprite logo;
|
||||
private CircularContainer logoContainer;
|
||||
private Container logoBounceContainer;
|
||||
private MenuVisualisation vis;
|
||||
|
||||
public Action Action;
|
||||
|
||||
public float SizeForFlow => logo == null ? 0 : logo.DrawSize.X * logo.Scale.X * logoBounceContainer.Scale.X * 0.8f;
|
||||
|
||||
private Sprite ripple;
|
||||
|
||||
private Container rippleContainer;
|
||||
|
||||
public override bool Contains(Vector2 screenSpacePos)
|
||||
{
|
||||
return logoContainer.Contains(screenSpacePos);
|
||||
}
|
||||
|
||||
public bool Ripple
|
||||
{
|
||||
get { return rippleContainer.Alpha > 0; }
|
||||
set
|
||||
{
|
||||
rippleContainer.Alpha = value ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Interactive = true;
|
||||
|
||||
public OsuLogo()
|
||||
{
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
logoBounceContainer = new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
logoContainer = new CircularContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Children = new[]
|
||||
{
|
||||
logo = new Sprite
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
},
|
||||
},
|
||||
rippleContainer = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
ripple = new Sprite()
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
BlendingMode = BlendingMode.Additive,
|
||||
Alpha = 0.05f
|
||||
}
|
||||
}
|
||||
},
|
||||
vis = new MenuVisualisation
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = logo.Size,
|
||||
BlendingMode = BlendingMode.Additive,
|
||||
Alpha = 0.2f,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures)
|
||||
{
|
||||
logo.Texture = textures.Get(@"Menu/logo");
|
||||
ripple.Texture = textures.Get(@"Menu/logo");
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
ripple.ScaleTo(1.1f, 500);
|
||||
ripple.FadeOut(500);
|
||||
ripple.Loop(300);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
if (!Interactive) return false;
|
||||
|
||||
logoBounceContainer.ScaleTo(1.1f, 1000, EasingTypes.Out);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||
{
|
||||
|
||||
logoBounceContainer.ScaleTo(1.2f, 500, EasingTypes.OutElastic);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
if (!Interactive) return false;
|
||||
|
||||
Action?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
if (!Interactive) return false;
|
||||
logoBounceContainer.ScaleTo(1.2f, 500, EasingTypes.OutElastic);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
logoBounceContainer.ScaleTo(1, 500, EasingTypes.OutElastic);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user