mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Standardise drawable state access and split large nested classes out of MainMenu.ButtonSystem
This commit is contained in:
parent
97c2dcf590
commit
9594b7193c
314
osu.Game/GameModes/Menu/Button.cs
Normal file
314
osu.Game/GameModes/Menu/Button.cs
Normal file
@ -0,0 +1,314 @@
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Drawables;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.GameModes.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 : AutoSizeContainer, IStateful<ButtonState>
|
||||
{
|
||||
private Container iconText;
|
||||
private WedgedBox 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 Quad ScreenSpaceInputQuad => box.ScreenSpaceInputQuad;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
base.Load();
|
||||
Alpha = 0;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
box = new WedgedBox(new Vector2(ButtonSystem.button_width + Math.Abs(extraWidth), ButtonSystem.button_area_height), ButtonSystem.wedge_width)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = colour,
|
||||
Scale = new Vector2(0, 1)
|
||||
},
|
||||
iconText = new AutoSizeContainer
|
||||
{
|
||||
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 + offset;
|
||||
|
||||
icon.RotateTo(10, offset, EasingTypes.InOutSine);
|
||||
icon.ScaleTo(new Vector2(1, 0.9f), offset, EasingTypes.Out);
|
||||
|
||||
icon.Transforms.Add(new TransformRotation(Clock)
|
||||
{
|
||||
StartValue = -10,
|
||||
EndValue = 10,
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration * 2,
|
||||
Easing = EasingTypes.InOutSine,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration * 2
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformPosition(Clock)
|
||||
{
|
||||
StartValue = Vector2.Zero,
|
||||
EndValue = new Vector2(0, -10),
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration,
|
||||
Easing = EasingTypes.Out,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformScaleVector(Clock)
|
||||
{
|
||||
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(Clock)
|
||||
{
|
||||
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 TransformScaleVector(Clock)
|
||||
{
|
||||
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(Clock)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ________
|
||||
/// / /
|
||||
/// / /
|
||||
/// /_______/
|
||||
/// </summary>
|
||||
class WedgedBox : Box
|
||||
{
|
||||
float wedgeWidth;
|
||||
|
||||
public WedgedBox(Vector2 boxSize, float wedgeWidth)
|
||||
{
|
||||
Size = boxSize;
|
||||
this.wedgeWidth = wedgeWidth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom DrawQuad used to create the slanted effect.
|
||||
/// </summary>
|
||||
protected override Quad DrawQuad
|
||||
{
|
||||
get
|
||||
{
|
||||
Quad q = base.DrawQuad;
|
||||
|
||||
//Will become infinite if we don't limit its maximum size.
|
||||
float wedge = Math.Min(q.Width, wedgeWidth / Scale.X);
|
||||
|
||||
q.TopLeft.X += wedge;
|
||||
q.BottomRight.X -= wedge;
|
||||
|
||||
return q;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ButtonState
|
||||
{
|
||||
Contracted,
|
||||
Expanded,
|
||||
Exploded
|
||||
}
|
||||
}
|
@ -16,10 +16,11 @@ using osu.Game.Graphics.Containers;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework;
|
||||
|
||||
namespace osu.Game.GameModes.Menu
|
||||
{
|
||||
public partial class ButtonSystem : Container
|
||||
public partial class ButtonSystem : Container, IStateful<MenuState>
|
||||
{
|
||||
public Action OnEdit;
|
||||
public Action OnExit;
|
||||
@ -32,9 +33,10 @@ namespace osu.Game.GameModes.Menu
|
||||
|
||||
private FlowContainerWithOrigin buttonFlow;
|
||||
|
||||
const float button_area_height = 100;
|
||||
const float button_width = 140f;
|
||||
const float wedge_width = 20;
|
||||
//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;
|
||||
|
||||
@ -49,15 +51,6 @@ namespace osu.Game.GameModes.Menu
|
||||
List<Button> buttonsTopLevel = new List<Button>();
|
||||
List<Button> buttonsPlay = new List<Button>();
|
||||
|
||||
public enum MenuState
|
||||
{
|
||||
Initial,
|
||||
TopLevel,
|
||||
Play,
|
||||
EnteringMode,
|
||||
Exit,
|
||||
}
|
||||
|
||||
public ButtonSystem()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
@ -208,10 +201,10 @@ namespace osu.Game.GameModes.Menu
|
||||
osuLogo.ScaleTo(1, 800, EasingTypes.OutExpo);
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
break;
|
||||
case MenuState.TopLevel:
|
||||
buttonAreaBackground.ScaleTo(Vector2.One, 200, EasingTypes.Out);
|
||||
@ -226,17 +219,17 @@ namespace osu.Game.GameModes.Menu
|
||||
buttonArea.Delay(150, true);
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = Button.ButtonState.Expanded;
|
||||
b.State = ButtonState.Expanded;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
break;
|
||||
case MenuState.Play:
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = Button.ButtonState.Exploded;
|
||||
b.State = ButtonState.Exploded;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = Button.ButtonState.Expanded;
|
||||
b.State = ButtonState.Expanded;
|
||||
break;
|
||||
case MenuState.EnteringMode:
|
||||
buttonAreaBackground.ScaleTo(new Vector2(2, 0), 300, EasingTypes.InSine);
|
||||
@ -247,19 +240,19 @@ namespace osu.Game.GameModes.Menu
|
||||
settingsButton.ContractStyle = 1;
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
break;
|
||||
case MenuState.Exit:
|
||||
buttonArea.FadeOut(200);
|
||||
|
||||
foreach (Button b in buttonsTopLevel)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
foreach (Button b in buttonsPlay)
|
||||
b.State = Button.ButtonState.Contracted;
|
||||
b.State = ButtonState.Contracted;
|
||||
|
||||
osuLogo.Delay(150);
|
||||
|
||||
@ -269,8 +262,8 @@ namespace osu.Game.GameModes.Menu
|
||||
break;
|
||||
}
|
||||
|
||||
backButton.State = state == MenuState.Play ? Button.ButtonState.Expanded : Button.ButtonState.Contracted;
|
||||
settingsButton.State = state == MenuState.TopLevel ? Button.ButtonState.Expanded : Button.ButtonState.Contracted;
|
||||
backButton.State = state == MenuState.Play ? ButtonState.Expanded : ButtonState.Contracted;
|
||||
settingsButton.State = state == MenuState.TopLevel ? ButtonState.Expanded : ButtonState.Contracted;
|
||||
|
||||
if (lastState == MenuState.Initial)
|
||||
buttonArea.DelayReset();
|
||||
@ -285,337 +278,14 @@ namespace osu.Game.GameModes.Menu
|
||||
iconFacade.Width = osuLogo.SizeForFlow * 0.5f;
|
||||
base.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A flow container with an origin based on one of its contained drawables.
|
||||
/// </summary>
|
||||
private class FlowContainerWithOrigin : FlowContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// A target drawable which this flowcontainer should be centered around.
|
||||
/// This target MUST be in this FlowContainer's *direct* children.
|
||||
/// </summary>
|
||||
internal Drawable CentreTarget;
|
||||
|
||||
public override Anchor Origin => Anchor.Custom;
|
||||
|
||||
public override Vector2 OriginPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CentreTarget == null)
|
||||
return base.OriginPosition;
|
||||
|
||||
return CentreTarget.Position + CentreTarget.Size / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public FlowContainerWithOrigin()
|
||||
{
|
||||
Direction = FlowDirection.HorizontalOnly;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
private class Button : AutoSizeContainer
|
||||
{
|
||||
private Container iconText;
|
||||
private WedgedBox 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 Quad ScreenSpaceInputQuad => box.ScreenSpaceInputQuad;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
base.Load();
|
||||
Alpha = 0;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = colour,
|
||||
Scale = new Vector2(0, 1)
|
||||
},
|
||||
iconText = new AutoSizeContainer
|
||||
{
|
||||
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 + offset;
|
||||
|
||||
icon.RotateTo(10, offset, EasingTypes.InOutSine);
|
||||
icon.ScaleTo(new Vector2(1, 0.9f), offset, EasingTypes.Out);
|
||||
|
||||
icon.Transforms.Add(new TransformRotation(Clock)
|
||||
{
|
||||
StartValue = -10,
|
||||
EndValue = 10,
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration * 2,
|
||||
Easing = EasingTypes.InOutSine,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration * 2
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformPosition(Clock)
|
||||
{
|
||||
StartValue = Vector2.Zero,
|
||||
EndValue = new Vector2(0, -10),
|
||||
StartTime = startTime,
|
||||
EndTime = startTime + duration,
|
||||
Easing = EasingTypes.Out,
|
||||
LoopCount = -1,
|
||||
LoopDelay = duration
|
||||
});
|
||||
|
||||
icon.Transforms.Add(new TransformScaleVector(Clock)
|
||||
{
|
||||
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(Clock)
|
||||
{
|
||||
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 TransformScaleVector(Clock)
|
||||
{
|
||||
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(Clock)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ________
|
||||
/// / /
|
||||
/// / /
|
||||
/// /_______/
|
||||
/// </summary>
|
||||
class WedgedBox : Box
|
||||
{
|
||||
float wedgeWidth;
|
||||
|
||||
public WedgedBox(Vector2 boxSize, float wedgeWidth)
|
||||
{
|
||||
Size = boxSize;
|
||||
this.wedgeWidth = wedgeWidth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom DrawQuad used to create the slanted effect.
|
||||
/// </summary>
|
||||
protected override Quad DrawQuad
|
||||
{
|
||||
get
|
||||
{
|
||||
Quad q = base.DrawQuad;
|
||||
|
||||
//Will become infinite if we don't limit its maximum size.
|
||||
float wedge = Math.Min(q.Width, wedgeWidth / Scale.X);
|
||||
|
||||
q.TopLeft.X += wedge;
|
||||
q.BottomRight.X -= wedge;
|
||||
|
||||
return q;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class MenuVisualisation : Drawable
|
||||
{
|
||||
}
|
||||
public enum MenuState
|
||||
{
|
||||
Initial,
|
||||
TopLevel,
|
||||
Play,
|
||||
EnteringMode,
|
||||
Exit,
|
||||
}
|
||||
}
|
||||
|
36
osu.Game/GameModes/Menu/FlowContainerWithOrigin.cs
Normal file
36
osu.Game/GameModes/Menu/FlowContainerWithOrigin.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.GameModes.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 MUST be in this FlowContainer's *direct* children.
|
||||
/// </summary>
|
||||
internal Drawable CentreTarget;
|
||||
|
||||
public override Anchor Origin => Anchor.Custom;
|
||||
|
||||
public override Vector2 OriginPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CentreTarget == null)
|
||||
return base.OriginPosition;
|
||||
|
||||
return CentreTarget.Position + CentreTarget.Size / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public FlowContainerWithOrigin()
|
||||
{
|
||||
Direction = FlowDirection.HorizontalOnly;
|
||||
}
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ namespace osu.Game.GameModes.Menu
|
||||
|
||||
const float length = 400;
|
||||
|
||||
buttons.State = ButtonSystem.MenuState.EnteringMode;
|
||||
buttons.State = MenuState.EnteringMode;
|
||||
|
||||
Content.FadeOut(length, EasingTypes.InSine);
|
||||
Content.MoveTo(new Vector2(-800, 0), length, EasingTypes.InSine);
|
||||
@ -77,7 +77,7 @@ namespace osu.Game.GameModes.Menu
|
||||
|
||||
const float length = 300;
|
||||
|
||||
buttons.State = ButtonSystem.MenuState.TopLevel;
|
||||
buttons.State = MenuState.TopLevel;
|
||||
|
||||
Content.FadeIn(length, EasingTypes.OutQuint);
|
||||
Content.MoveTo(new Vector2(0, 0), length, EasingTypes.OutQuint);
|
||||
|
13
osu.Game/GameModes/Menu/MenuVisualisation.cs
Normal file
13
osu.Game/GameModes/Menu/MenuVisualisation.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using osu.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.GameModes.Menu
|
||||
{
|
||||
internal class MenuVisualisation : Drawable
|
||||
{
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace osu.Game.GameModes.Menu
|
||||
{
|
||||
private Sprite logo;
|
||||
private Container logoBounceContainer;
|
||||
private ButtonSystem.MenuVisualisation vis;
|
||||
private MenuVisualisation vis;
|
||||
|
||||
public Action Action;
|
||||
|
||||
@ -69,7 +69,7 @@ namespace osu.Game.GameModes.Menu
|
||||
}
|
||||
}
|
||||
},
|
||||
vis = new ButtonSystem.MenuVisualisation
|
||||
vis = new MenuVisualisation
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -69,8 +69,11 @@ namespace osu.Game
|
||||
}
|
||||
});
|
||||
|
||||
Toolbar.SetState(ToolbarState.Hidden, true);
|
||||
Chat.SetState(ChatConsoleState.Hidden, true);
|
||||
Toolbar.State = ToolbarState.Hidden;
|
||||
Toolbar.Flush();
|
||||
|
||||
Chat.State = ChatConsoleState.Hidden;
|
||||
Chat.Flush();
|
||||
|
||||
intro.ModePushed += modeAdded;
|
||||
intro.Exited += modeRemoved;
|
||||
@ -87,7 +90,7 @@ namespace osu.Game
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.F8:
|
||||
Chat.SetState(Chat.State == ChatConsoleState.Hidden ? ChatConsoleState.Visible : ChatConsoleState.Hidden);
|
||||
Chat.State = Chat.State == ChatConsoleState.Hidden ? ChatConsoleState.Visible : ChatConsoleState.Hidden;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -105,12 +108,12 @@ namespace osu.Game
|
||||
//central game mode change logic.
|
||||
if (newMode is Player || newMode is Intro)
|
||||
{
|
||||
Toolbar.SetState(ToolbarState.Hidden);
|
||||
Chat.SetState(ChatConsoleState.Hidden);
|
||||
Toolbar.State = ToolbarState.Hidden;
|
||||
Chat.State = ChatConsoleState.Hidden;
|
||||
}
|
||||
else
|
||||
{
|
||||
Toolbar.SetState(ToolbarState.Visible);
|
||||
Toolbar.State = ToolbarState.Visible;
|
||||
}
|
||||
|
||||
Cursor.FadeIn(100);
|
||||
|
@ -21,10 +21,11 @@ using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public class ChatConsole : Container
|
||||
public class ChatConsole : Container, IStateful<ChatConsoleState>
|
||||
{
|
||||
private APIAccess api => ((OsuGameBase)Game).API;
|
||||
|
||||
@ -71,7 +72,7 @@ namespace osu.Game.Overlays
|
||||
careChannels = new List<Channel>();
|
||||
|
||||
//if (api.State != APIAccess.APIState.Online)
|
||||
// return;
|
||||
// return;
|
||||
|
||||
Add(new FlowContainer
|
||||
{
|
||||
@ -141,24 +142,32 @@ namespace osu.Game.Overlays
|
||||
api.Queue(fetchReq);
|
||||
}
|
||||
|
||||
public ChatConsoleState State { get; private set; }
|
||||
private ChatConsoleState state;
|
||||
|
||||
public void SetState(ChatConsoleState state, bool instant = false)
|
||||
public ChatConsoleState State
|
||||
{
|
||||
State = state;
|
||||
|
||||
int time = instant ? 0 : 500;
|
||||
|
||||
switch (state)
|
||||
get
|
||||
{
|
||||
case ChatConsoleState.Hidden:
|
||||
MoveToY(-Size.Y, time, EasingTypes.InQuint);
|
||||
FadeOut(time, EasingTypes.InQuint);
|
||||
break;
|
||||
case ChatConsoleState.Visible:
|
||||
MoveToY(0, time, EasingTypes.OutQuint);
|
||||
FadeIn(time, EasingTypes.OutQuint);
|
||||
break;
|
||||
return state;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
state = value;
|
||||
|
||||
const int transition_length = 500;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ChatConsoleState.Hidden:
|
||||
MoveToY(-Size.Y, transition_length, EasingTypes.InQuint);
|
||||
FadeOut(transition_length, EasingTypes.InQuint);
|
||||
break;
|
||||
case ChatConsoleState.Visible:
|
||||
MoveToY(0, transition_length, EasingTypes.OutQuint);
|
||||
FadeIn(transition_length, EasingTypes.OutQuint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,11 @@ using System;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.GameModes.Play;
|
||||
using osu.Framework;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public class Toolbar : Container
|
||||
public class Toolbar : Container, IStateful<ToolbarState>
|
||||
{
|
||||
const float height = 50;
|
||||
|
||||
@ -25,24 +26,28 @@ namespace osu.Game.Overlays
|
||||
|
||||
private ToolbarModeSelector modeSelector;
|
||||
|
||||
public ToolbarState State { get; private set; }
|
||||
private ToolbarState state;
|
||||
|
||||
public void SetState(ToolbarState state, bool instant = false)
|
||||
public ToolbarState State
|
||||
{
|
||||
State = state;
|
||||
|
||||
int time = instant ? 0 : 200;
|
||||
|
||||
switch (state)
|
||||
get { return state; }
|
||||
set
|
||||
{
|
||||
case ToolbarState.Hidden:
|
||||
MoveToY(-Size.Y, time, EasingTypes.InQuint);
|
||||
FadeOut(time);
|
||||
break;
|
||||
case ToolbarState.Visible:
|
||||
MoveToY(0, time, EasingTypes.OutQuint);
|
||||
FadeIn(time);
|
||||
break;
|
||||
state = value;
|
||||
|
||||
const int transition_time = 200;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ToolbarState.Hidden:
|
||||
MoveToY(-Size.Y, transition_time, EasingTypes.InQuint);
|
||||
FadeOut(transition_time);
|
||||
break;
|
||||
case ToolbarState.Visible:
|
||||
MoveToY(0, transition_time, EasingTypes.OutQuint);
|
||||
FadeIn(transition_time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,9 +76,12 @@
|
||||
<Compile Include="GameModes\Charts\ChartInfo.cs" />
|
||||
<Compile Include="GameModes\Edit\Editor.cs" />
|
||||
<Compile Include="GameModes\GameModeWhiteBox.cs" />
|
||||
<Compile Include="GameModes\Menu\Button.cs" />
|
||||
<Compile Include="GameModes\Menu\FlowContainerWithOrigin.cs" />
|
||||
<Compile Include="GameModes\Menu\Intro.cs" />
|
||||
<Compile Include="GameModes\Menu\ButtonSystem.cs" />
|
||||
<Compile Include="GameModes\Menu\MainMenu.cs" />
|
||||
<Compile Include="GameModes\Menu\MenuVisualisation.cs" />
|
||||
<Compile Include="GameModes\Menu\OsuLogo.cs" />
|
||||
<Compile Include="GameModes\Multiplayer\Lobby.cs" />
|
||||
<Compile Include="GameModes\Multiplayer\Match.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user