1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 14:02:55 +08:00

Merge pull request #199 from stanriders/back-button

Add stable-alike BackButton
This commit is contained in:
Dean Herbert 2016-11-30 03:20:03 +09:00 committed by GitHub
commit 53df2932ad
4 changed files with 163 additions and 6 deletions

View File

@ -0,0 +1,151 @@
// Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
// Basic back button as it was on stable (kinda). No skinning possible for now
public class BackButton : ClickableContainer
{
private TextAwesome icon;
private Container leftContainer;
private Container rightContainer;
private const double transform_time = 300.0;
private const int pulse_length = 250;
private const float shear = 0.1f;
private static readonly Vector2 size_extended = new Vector2(140, 50);
private static readonly Vector2 size_retracted = new Vector2(100, 50);
public BackButton()
{
Size = size_retracted;
Children = new Drawable[]
{
leftContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(195, 40, 140, 255),
Shear = new Vector2(shear, 0),
},
icon = new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = 25,
Icon = FontAwesome.fa_osu_left_o
},
}
},
rightContainer = new Container
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Width = 0.6f,
Children = new Drawable[]
{
new Box
{
Colour = new Color4(238, 51, 153, 255),
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
EdgeSmoothness = new Vector2(1.5f, 0),
},
new SpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = @"Back",
}
}
}
};
}
protected override bool OnHover(InputState state)
{
icon.ClearTransformations();
ResizeTo(size_extended, transform_time, EasingTypes.OutElastic);
int duration = 0; //(int)(Game.Audio.BeatLength / 2);
if (duration == 0) duration = pulse_length;
double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration;
double startTime = Time.Current + offset;
// basic pulse
icon.Transforms.Add(new TransformScale
{
StartValue = new Vector2(1.1f),
EndValue = Vector2.One,
StartTime = startTime,
EndTime = startTime + duration,
Easing = EasingTypes.Out,
LoopCount = -1,
LoopDelay = duration
});
return true;
}
protected override void OnHoverLost(InputState state)
{
icon.ClearTransformations();
ResizeTo(size_retracted, transform_time, EasingTypes.OutElastic);
int duration = 0; //(int)(Game.Audio.BeatLength);
if (duration == 0) duration = pulse_length * 2;
double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration;
double startTime = Time.Current + offset;
// slow pulse
icon.Transforms.Add(new TransformScale
{
StartValue = new Vector2(1.1f),
EndValue = Vector2.One,
StartTime = startTime,
EndTime = startTime + duration,
Easing = EasingTypes.Out,
LoopCount = -1,
LoopDelay = duration
});
}
protected override bool OnClick(InputState state)
{
var flash = new Box
{
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
Colour = new Color4(255, 255, 255, 128),
};
Add(flash);
flash.FadeOutFromOne(200);
flash.Expire();
return base.OnClick(state);
}
}
}

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Screens.Backgrounds;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
@ -17,7 +18,7 @@ namespace osu.Game.Screens
{
public class GameModeWhiteBox : OsuGameMode
{
private Button popButton;
private BackButton popButton;
const int transition_time = 1000;
@ -113,14 +114,10 @@ namespace osu.Game.Screens
},
}
},
popButton = new Button
popButton = new BackButton
{
Text = @"Back",
RelativeSizeAxes = Axes.X,
Size = new Vector2(0.1f, 40),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Colour = new Color4(235, 51, 153, 255),
Alpha = 0,
Action = delegate {
Exit();

View File

@ -19,6 +19,7 @@ using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Screens.Backgrounds;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Screens.Play;
@ -120,6 +121,13 @@ namespace osu.Game.Screens.Select
Size = Vector2.One,
Colour = new Color4(0, 0, 0, 0.5f),
},
new BackButton
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
//RelativeSizeAxes = Axes.Y,
Action = () => Exit()
},
new Button
{
Anchor = Anchor.CentreRight,

View File

@ -65,6 +65,7 @@
<ItemGroup>
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
<Compile Include="Graphics\Cursor\CursorTrail.cs" />
<Compile Include="Graphics\UserInterface\BackButton.cs" />
<Compile Include="Modes\Objects\HitObjectParser.cs" />
<Compile Include="Overlays\DragBar.cs" />
<Compile Include="Overlays\MusicController.cs" />