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

Move BeatmapOptions buttons to derived class and simplify.

This commit is contained in:
Huo Yaoyuan 2017-03-14 19:38:21 +08:00
parent c4e5eac35b
commit 3871a350f8
9 changed files with 40 additions and 146 deletions

View File

@ -3,6 +3,7 @@
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -48,6 +49,8 @@ namespace osu.Game.Screens.Select.Options
set { secondLine.Text = value; }
}
public Key? HotKey;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
flash.FadeTo(0.1f, 1000, EasingTypes.OutQuint);
@ -69,6 +72,17 @@ namespace osu.Game.Screens.Select.Options
return base.OnClick(state);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!args.Repeat && args.Key == HotKey)
{
OnClick(state);
return true;
}
return false;
}
public override bool Contains(Vector2 screenSpacePos) => box.Contains(screenSpacePos);
public BeatmapOptionsButton()

View File

@ -1,24 +0,0 @@
// 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

@ -1,24 +0,0 @@
// 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

@ -1,24 +0,0 @@
// 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

@ -6,11 +6,13 @@ using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Game.Graphics;
namespace osu.Game.Screens.Select.Options
{
@ -24,11 +26,6 @@ namespace osu.Game.Screens.Select.Options
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();
@ -85,45 +82,27 @@ namespace osu.Game.Screens.Select.Options
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();
},
},
},
},
};
}
public void AddButton(string firstLine, string secongLine, FontAwesome icon, Color4 colour, Action action, Key? hotkey = null)
{
buttonsContainer.Add(new BeatmapOptionsButton
{
FirstLineText = firstLine,
SecondLineText = secongLine,
Icon = icon,
ButtonColour = colour,
Action = () =>
{
Hide();
action?.Invoke();
},
HotKey = hotkey
});
}
private class ButtonFlow : FillFlowContainer<BeatmapOptionsButton>
{
protected override IComparer<Drawable> DepthComparer => new ReverseCreationOrderDepthComparer();

View File

@ -1,24 +0,0 @@
// 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

@ -32,6 +32,11 @@ namespace osu.Game.Screens.Select
Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1);
Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2);
Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3);
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null, Key.Number1);
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null, Key.Number2);
BeatmapOptions.AddButton(@"Edit", @"Beatmap", FontAwesome.fa_pencil, colours.Yellow, null, Key.Number3);
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, PromptDelete, Key.Number4);
}
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)

View File

@ -128,10 +128,6 @@ namespace osu.Game.Screens.Select
},
BeatmapOptions = new BeatmapOptionsOverlay
{
OnRemoveFromUnplayed = null,
OnClearLocalScores = null,
OnEdit = null,
OnDelete = promptDelete,
Margin = new MarginPadding
{
Bottom = 50,
@ -408,7 +404,7 @@ namespace osu.Game.Screens.Select
}
}
private void promptDelete()
protected void PromptDelete()
{
if (Beatmap != null)
dialogOverlay?.Push(new BeatmapDeleteDialog(Beatmap));
@ -418,7 +414,7 @@ namespace osu.Game.Screens.Select
{
if (!args.Repeat && args.Key == Key.Delete && state.Keyboard.ShiftPressed)
{
promptDelete();
PromptDelete();
return true;
}

View File

@ -324,11 +324,7 @@
<Compile Include="Overlays\Mods\AssistedSection.cs" />
<Compile Include="Overlays\WaveOverlayContainer.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">