1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 00:27:25 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/BeatmapPanel.cs

168 lines
6.5 KiB
C#
Raw Normal View History

// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Beatmaps.Drawables
{
public class BeatmapPanel : Panel, IHasContextMenu
{
public BeatmapInfo Beatmap;
private readonly Sprite background;
public Action<BeatmapPanel> GainedSelection;
public Action<BeatmapPanel> StartRequested;
2017-08-30 20:12:58 +08:00
public Action<BeatmapPanel> EditRequested;
2017-09-04 06:59:32 +08:00
public Action<BeatmapInfo> HideRequested;
private readonly Triangles triangles;
private readonly StarCounter starCounter;
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
2017-07-23 13:30:50 +08:00
background.Colour = ColourInfo.GradientVertical(
new Color4(20, 43, 51, 255),
new Color4(40, 86, 102, 255));
2017-01-30 15:53:12 +08:00
triangles.Colour = Color4.White;
}
protected override void Deselected()
{
base.Deselected();
background.Colour = new Color4(20, 43, 51, 255);
2017-01-30 15:53:12 +08:00
triangles.Colour = OsuColour.Gray(0.5f);
}
protected override bool OnClick(InputState state)
{
if (State == PanelSelectedState.Selected)
StartRequested?.Invoke(this);
return base.OnClick(state);
}
protected override void ApplyState(PanelSelectedState last = PanelSelectedState.Hidden)
{
if (!IsLoaded) return;
base.ApplyState(last);
if (last == PanelSelectedState.Hidden && State != last)
starCounter.ReplayAnimation();
}
public BeatmapPanel(BeatmapInfo beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
Beatmap = beatmap;
Height *= 0.60f;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
2017-01-30 15:53:12 +08:00
triangles = new Triangles
2016-11-26 16:10:13 +08:00
{
TriangleScale = 2,
2016-11-26 16:10:13 +08:00
RelativeSizeAxes = Axes.Both,
2017-01-30 15:53:12 +08:00
ColourLight = OsuColour.FromHex(@"3a7285"),
ColourDark = OsuColour.FromHex(@"123744")
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Padding = new MarginPadding(5),
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
2017-01-30 12:35:40 +08:00
new DifficultyIcon(beatmap)
{
Scale = new Vector2(1.8f),
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Padding = new MarginPadding { Left = 5 },
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Horizontal,
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(4, 0),
AutoSizeAxes = Axes.Both,
Children = new[]
{
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = beatmap.Version,
TextSize = 20,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = "mapped by",
TextSize = 16,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
2017-10-17 10:24:59 +08:00
Text = $"{(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author.Username}",
TextSize = 16,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
}
},
starCounter = new StarCounter
{
2017-07-11 21:58:06 +08:00
CountStars = (float)beatmap.StarDifficulty,
Scale = new Vector2(0.8f),
}
}
}
}
}
};
}
public MenuItem[] ContextMenuItems => new MenuItem[]
{
2017-08-30 20:12:58 +08:00
new OsuMenuItem("Play", MenuItemType.Highlighted, () => StartRequested?.Invoke(this)),
new OsuMenuItem("Edit", MenuItemType.Standard, () => EditRequested?.Invoke(this)),
2017-09-04 06:59:32 +08:00
new OsuMenuItem("Hide", MenuItemType.Destructive, () => HideRequested?.Invoke(Beatmap)),
};
}
}