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

Merge pull request #418 from DrabWeb/beatmap-options

Beatmap options overlay
This commit is contained in:
Dean Herbert 2017-03-03 16:59:21 +09:00 committed by GitHub
commit 511c072270
10 changed files with 443 additions and 4 deletions

View File

@ -0,0 +1,28 @@
// Copyright (c) 2007-2017 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.Screens.Testing;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Screens.Select.Options;
namespace osu.Desktop.VisualTests
{
class TestCaseBeatmapOptionsOverlay : TestCase
{
public override string Name => @"Beatmap Options";
public override string Description => @"Beatmap options in song select";
public override void Reset()
{
base.Reset();
var overlay = new BeatmapOptionsOverlay();
Add(overlay);
AddButton(@"Toggle", overlay.ToggleVisibility);
}
}
}

View File

@ -195,6 +195,7 @@
<Compile Include="Tests\TestCaseOptions.cs" />
<Compile Include="Tests\TestCasePauseOverlay.cs" />
<Compile Include="Tests\TestCaseDialogOverlay.cs" />
<Compile Include="Tests\TestCaseBeatmapOptionsOverlay.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup />

View File

@ -0,0 +1,152 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsButton : ClickableContainer
{
private static readonly float width = 130;
private Box background, flash;
private TextAwesome iconText;
private OsuSpriteText firstLine, secondLine;
private Container box;
public Color4 ButtonColour
{
get { return background.Colour; }
set { background.Colour = value; }
}
public FontAwesome Icon
{
get { return iconText.Icon; }
set { iconText.Icon = value; }
}
public string FirstLineText
{
get { return firstLine.Text; }
set { firstLine.Text = value; }
}
public string SecondLineText
{
get { return secondLine.Text; }
set { secondLine.Text = value; }
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
flash.FadeTo(0.1f, 1000, EasingTypes.OutQuint);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
flash.FadeTo(0, 1000, EasingTypes.OutQuint);
return base.OnMouseUp(state, args);
}
protected override bool OnClick(InputState state)
{
flash.ClearTransforms();
flash.Alpha = 0.9f;
flash.FadeOut(800, EasingTypes.OutExpo);
return base.OnClick(state);
}
public override bool Contains(Vector2 screenSpacePos) => box.Contains(screenSpacePos);
public BeatmapOptionsButton()
{
Width = width;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
box = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(0.2f, 0f),
Masking = true,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.2f),
Roundness = 5,
Radius = 8,
},
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
EdgeSmoothness = new Vector2(1.5f, 0),
Colour = Color4.Black,
},
flash = new Box
{
RelativeSizeAxes = Axes.Both,
EdgeSmoothness = new Vector2(1.5f, 0),
BlendingMode = BlendingMode.Additive,
Colour = Color4.White,
Alpha = 0,
},
},
},
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Down,
Children = new Drawable[]
{
iconText = new TextAwesome
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
TextSize = 30,
Shadow = true,
Icon = FontAwesome.fa_close,
Margin = new MarginPadding
{
Bottom = 5,
},
},
firstLine = new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Font = @"Exo2.0-Bold",
Text = @"",
},
secondLine = new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Font = @"Exo2.0-Bold",
Text = @"",
},
},
},
};
}
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2017 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.Game.Graphics;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsClearLocalScoresButton : BeatmapOptionsButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
ButtonColour = colour.Purple;
}
public BeatmapOptionsClearLocalScoresButton()
{
Icon = FontAwesome.fa_eraser;
FirstLineText = @"Clear";
SecondLineText = @"local scores";
}
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2017 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.Game.Graphics;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsDeleteButton : BeatmapOptionsButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
ButtonColour = colour.Pink;
}
public BeatmapOptionsDeleteButton()
{
Icon = FontAwesome.fa_trash;
FirstLineText = @"Delete";
SecondLineText = @"Beatmap";
}
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2017 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.Game.Graphics;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsEditButton : BeatmapOptionsButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
ButtonColour = colour.Yellow;
}
public BeatmapOptionsEditButton()
{
Icon = FontAwesome.fa_pencil;
FirstLineText = @"Edit";
SecondLineText = @"Beatmap";
}
}
}

View File

@ -0,0 +1,139 @@
// Copyright (c) 2007-2017 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 OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Game.Graphics;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsOverlay : FocusedOverlayContainer
{
private const float transition_duration = 500;
private const float x_position = 290;
private const float height = 100;
private Box holder;
private FillFlowContainer<BeatmapOptionsButton> buttonsContainer;
public Action OnRemoveFromUnplayed;
public Action OnClearLocalScores;
public Action OnEdit;
public Action OnDelete;
protected override void PopIn()
{
base.PopIn();
if (buttonsContainer.Position.X >= DrawWidth || buttonsContainer.Alpha <= 0)
buttonsContainer.MoveToX(-buttonsContainer.DrawWidth);
buttonsContainer.Alpha = 1;
holder.ScaleTo(new Vector2(1, 1), transition_duration / 2, EasingTypes.OutQuint);
buttonsContainer.MoveToX(x_position, transition_duration, EasingTypes.OutQuint);
buttonsContainer.TransformSpacingTo(Vector2.Zero, transition_duration, EasingTypes.OutQuint);
}
protected override void PopOut()
{
base.PopOut();
holder.ScaleTo(new Vector2(1, 0), transition_duration / 2, EasingTypes.InSine);
buttonsContainer.MoveToX(DrawWidth, transition_duration, EasingTypes.InSine);
buttonsContainer.TransformSpacingTo(new Vector2(200f, 0f), transition_duration, EasingTypes.InSine);
Delay(transition_duration);
Schedule(() =>
{
if (State == Visibility.Hidden)
buttonsContainer.Alpha = 0;
});
}
public BeatmapOptionsOverlay()
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
Children = new Drawable[]
{
holder = new Box
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Height = 0.5f,
Scale = new Vector2(1, 0),
Colour = Color4.Black.Opacity(0.5f),
},
buttonsContainer = new ButtonFlow
{
Height = height,
AutoSizeAxes = Axes.X,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Children = new BeatmapOptionsButton[]
{
new BeatmapOptionsRemoveFromUnplayedButton
{
Action = () =>
{
Hide();
OnRemoveFromUnplayed?.Invoke();
},
},
new BeatmapOptionsClearLocalScoresButton
{
Action = () =>
{
Hide();
OnClearLocalScores?.Invoke();
},
},
new BeatmapOptionsEditButton
{
Action = () =>
{
Hide();
OnEdit?.Invoke();
},
},
new BeatmapOptionsDeleteButton
{
Action = () =>
{
Hide();
OnDelete?.Invoke();
},
},
},
},
};
}
class ButtonFlow : FillFlowContainer<BeatmapOptionsButton>
{
protected override IComparer<Drawable> DepthComparer => new ReverseCreationOrderDepthComparer();
protected override IEnumerable<BeatmapOptionsButton> FlowingChildren => base.FlowingChildren.Reverse();
public ButtonFlow()
{
Direction = FillDirection.Right;
}
}
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2017 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.Game.Graphics;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsRemoveFromUnplayedButton : BeatmapOptionsButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
ButtonColour = colour.Purple;
}
public BeatmapOptionsRemoveFromUnplayedButton()
{
Icon = FontAwesome.fa_times_circle_o;
FirstLineText = @"Remove";
SecondLineText = @"from Unplayed";
}
}
}

View File

@ -28,6 +28,7 @@ using OpenTK.Input;
using System.Collections.Generic;
using osu.Framework.Threading;
using osu.Game.Overlays;
using osu.Game.Screens.Select.Options;
namespace osu.Game.Screens.Select
{
@ -52,6 +53,7 @@ namespace osu.Game.Screens.Select
private List<BeatmapGroup> beatmapGroups;
private BeatmapOptionsOverlay beatmapOptions;
private Footer footer;
OsuScreen player;
@ -125,6 +127,17 @@ namespace osu.Game.Screens.Select
Right = 20,
},
},
beatmapOptions = new BeatmapOptionsOverlay
{
OnRemoveFromUnplayed = null,
OnClearLocalScores = null,
OnEdit = null,
OnDelete = promptDelete,
Margin = new MarginPadding
{
Bottom = 50,
},
},
footer = new Footer
{
OnBack = Exit,
@ -144,7 +157,7 @@ namespace osu.Game.Screens.Select
footer.AddButton(@"mods", colours.Yellow, null);
footer.AddButton(@"random", colours.Green, carousel.SelectRandom);
footer.AddButton(@"options", colours.Blue, null);
footer.AddButton(@"options", colours.Blue, beatmapOptions.ToggleVisibility);
if (osu != null)
playMode.BindTo(osu.PlayMode);
@ -409,6 +422,12 @@ namespace osu.Game.Screens.Select
}
}
private void promptDelete()
{
if (Beatmap != null)
dialogOverlay?.Push(new BeatmapDeleteDialog(Beatmap));
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
@ -419,9 +438,7 @@ namespace osu.Game.Screens.Select
case Key.Delete:
if (state.Keyboard.ShiftPressed)
{
if (Beatmap != null)
dialogOverlay?.Push(new BeatmapDeleteDialog(Beatmap));
promptDelete();
return true;
}
break;

View File

@ -287,6 +287,12 @@
<Compile Include="Overlays\Dialog\PopupDialogCancelButton.cs" />
<Compile Include="Screens\Select\BeatmapDeleteDialog.cs" />
<Compile Include="Overlays\DialogOverlay.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsButton.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsClearLocalScoresButton.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsDeleteButton.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsEditButton.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsOverlay.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsRemoveFromUnplayedButton.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">