2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
2019-04-03 21:44:36 +08:00
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-03-11 09:18:41 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-04-18 12:08:53 +08:00
|
|
|
using osu.Game.Overlays;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class DrawableCarouselBeatmap : DrawableCarouselItem, IHasContextMenu
|
|
|
|
{
|
|
|
|
private readonly BeatmapInfo beatmap;
|
|
|
|
|
|
|
|
private Sprite background;
|
|
|
|
|
|
|
|
private Action<BeatmapInfo> startRequested;
|
|
|
|
private Action<BeatmapInfo> editRequested;
|
|
|
|
private Action<BeatmapInfo> hideRequested;
|
|
|
|
|
|
|
|
private Triangles triangles;
|
|
|
|
private StarCounter starCounter;
|
|
|
|
|
2020-02-14 21:59:51 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
2020-02-14 21:14:00 +08:00
|
|
|
private BeatmapSetOverlay beatmapOverlay { get; set; }
|
2018-04-18 12:08:53 +08:00
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
public DrawableCarouselBeatmap(CarouselBeatmap panel)
|
|
|
|
: base(panel)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
beatmap = panel.Beatmap;
|
|
|
|
Height *= 0.60f;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2020-04-16 11:10:20 +08:00
|
|
|
private void load(BeatmapManager manager, SongSelect songSelect)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
if (songSelect != null)
|
|
|
|
{
|
2018-05-30 14:44:35 +08:00
|
|
|
startRequested = b => songSelect.FinaliseSelection(b);
|
2020-04-16 11:10:20 +08:00
|
|
|
if (songSelect.AllowEditing)
|
|
|
|
editRequested = songSelect.Edit;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (manager != null)
|
|
|
|
hideRequested = manager.Hide;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
triangles = new Triangles
|
|
|
|
{
|
|
|
|
TriangleScale = 2,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 09:18:41 +08:00
|
|
|
ColourLight = Color4Extensions.FromHex(@"3a7285"),
|
|
|
|
ColourDark = Color4Extensions.FromHex(@"123744")
|
2018-04-13 17:19:50 +08:00
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2019-08-15 11:11:54 +08:00
|
|
|
new DifficultyIcon(beatmap, shouldShowTooltip: false)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
Scale = new Vector2(1.8f),
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding { Left = 5 },
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(4, 0),
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = beatmap.Version,
|
2019-02-20 15:52:36 +08:00
|
|
|
Font = OsuFont.GetFont(size: 20),
|
2018-04-13 17:19:50 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "mapped by",
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = $"{(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author.Username}",
|
2019-02-20 15:52:36 +08:00
|
|
|
Font = OsuFont.GetFont(italics: true),
|
2018-04-13 17:19:50 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2020-03-28 23:22:01 +08:00
|
|
|
new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2020-03-28 23:22:01 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(4, 0),
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-04-05 03:28:36 +08:00
|
|
|
new TopLocalRank(beatmap)
|
2020-03-28 23:22:01 +08:00
|
|
|
{
|
2020-04-05 03:28:36 +08:00
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
Size = new Vector2(40, 20)
|
2020-03-28 23:22:01 +08:00
|
|
|
},
|
|
|
|
starCounter = new StarCounter
|
|
|
|
{
|
|
|
|
Current = (float)beatmap.StarDifficulty,
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Selected()
|
|
|
|
{
|
|
|
|
base.Selected();
|
|
|
|
|
|
|
|
background.Colour = ColourInfo.GradientVertical(
|
|
|
|
new Color4(20, 43, 51, 255),
|
|
|
|
new Color4(40, 86, 102, 255));
|
|
|
|
|
|
|
|
triangles.Colour = Color4.White;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Deselected()
|
|
|
|
{
|
|
|
|
base.Deselected();
|
|
|
|
|
|
|
|
background.Colour = new Color4(20, 43, 51, 255);
|
|
|
|
triangles.Colour = OsuColour.Gray(0.5f);
|
|
|
|
}
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
if (Item.State.Value == CarouselItemState.Selected)
|
2018-04-13 17:19:50 +08:00
|
|
|
startRequested?.Invoke(beatmap);
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
return base.OnClick(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ApplyState()
|
|
|
|
{
|
|
|
|
if (Item.State.Value != CarouselItemState.Collapsed && Alpha == 0)
|
|
|
|
starCounter.ReplayAnimation();
|
|
|
|
|
|
|
|
base.ApplyState();
|
|
|
|
}
|
2019-04-03 22:37:50 +08:00
|
|
|
|
2019-04-03 21:44:36 +08:00
|
|
|
public MenuItem[] ContextMenuItems
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-04-03 21:44:36 +08:00
|
|
|
get
|
2018-04-18 12:08:53 +08:00
|
|
|
{
|
2020-04-16 11:10:20 +08:00
|
|
|
List<MenuItem> items = new List<MenuItem>();
|
2019-04-03 22:40:20 +08:00
|
|
|
|
2020-04-16 11:10:20 +08:00
|
|
|
if (startRequested != null)
|
|
|
|
items.Add(new OsuMenuItem("Play", MenuItemType.Highlighted, () => startRequested(beatmap)));
|
|
|
|
|
|
|
|
if (editRequested != null)
|
|
|
|
items.Add(new OsuMenuItem("Edit", MenuItemType.Standard, () => editRequested(beatmap)));
|
2020-04-16 09:17:12 +08:00
|
|
|
|
2020-04-16 11:10:20 +08:00
|
|
|
if (hideRequested != null)
|
|
|
|
items.Add(new OsuMenuItem("Hide", MenuItemType.Destructive, () => hideRequested(beatmap)));
|
2020-04-16 09:17:12 +08:00
|
|
|
|
2020-04-16 11:10:20 +08:00
|
|
|
if (beatmap.OnlineBeatmapID.HasValue && beatmapOverlay != null)
|
|
|
|
items.Add(new OsuMenuItem("Details", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmap.OnlineBeatmapID.Value)));
|
2019-04-03 21:44:36 +08:00
|
|
|
|
|
|
|
return items.ToArray();
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|