2019-03-04 12:24:19 +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-10-13 23:40:33 +08:00
|
|
|
|
2018-12-01 08:50:11 +08:00
|
|
|
using System;
|
2018-11-08 05:29:04 +08:00
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Linq;
|
2018-10-13 23:40:33 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 12:40:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-10-13 23:40:33 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-07-26 16:43:45 +08:00
|
|
|
using osu.Framework.Localisation;
|
2018-10-13 23:40:33 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics;
|
2021-01-25 06:29:05 +08:00
|
|
|
using osu.Game.Tournament.Models;
|
2018-11-22 09:25:30 +08:00
|
|
|
using osuTK.Graphics;
|
2018-10-13 23:40:33 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TournamentBeatmapPanel : CompositeDrawable
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2023-08-01 13:56:48 +08:00
|
|
|
public readonly IBeatmapInfo? Beatmap;
|
2021-10-20 17:43:48 +08:00
|
|
|
|
2023-07-30 01:38:19 +08:00
|
|
|
private readonly string mod;
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2018-11-04 06:12:07 +08:00
|
|
|
public const float HEIGHT = 50;
|
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>();
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2023-07-30 01:49:13 +08:00
|
|
|
private Box flash = null!;
|
2018-12-01 08:50:11 +08:00
|
|
|
|
2023-08-01 13:56:48 +08:00
|
|
|
public TournamentBeatmapPanel(IBeatmapInfo? beatmap, string mod = "")
|
2023-07-26 16:43:45 +08:00
|
|
|
{
|
2021-10-27 17:25:23 +08:00
|
|
|
Beatmap = beatmap;
|
2021-01-25 20:24:43 +08:00
|
|
|
this.mod = mod;
|
2021-10-20 17:43:48 +08:00
|
|
|
|
2018-10-13 23:40:33 +08:00
|
|
|
Width = 400;
|
2018-11-04 06:12:07 +08:00
|
|
|
Height = HEIGHT;
|
2018-10-13 23:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 08:06:39 +08:00
|
|
|
private void load(LadderInfo ladder)
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2018-11-08 05:29:04 +08:00
|
|
|
currentMatch.BindValueChanged(matchChanged);
|
|
|
|
currentMatch.BindTo(ladder.CurrentMatch);
|
|
|
|
|
2018-10-13 23:40:33 +08:00
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
},
|
2023-07-25 15:15:16 +08:00
|
|
|
new NoUnloadBeatmapSetCover
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(0.5f),
|
2023-08-01 13:56:48 +08:00
|
|
|
OnlineInfo = (Beatmap as IBeatmapSetOnlineInfo),
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-03-08 13:46:09 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-03-09 14:08:24 +08:00
|
|
|
Padding = new MarginPadding(15),
|
2018-10-13 23:40:33 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-03-03 18:14:44 +08:00
|
|
|
new TournamentSpriteText
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2023-07-26 16:43:45 +08:00
|
|
|
Text = Beatmap?.GetDisplayTitleRomanisable(false, false) ?? (LocalisableString)@"unknown",
|
2020-03-03 18:14:44 +08:00
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Bold),
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-03-03 18:14:44 +08:00
|
|
|
new TournamentSpriteText
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
|
|
|
Text = "mapper",
|
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2020-03-03 18:14:44 +08:00
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Regular, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
2020-03-03 18:14:44 +08:00
|
|
|
new TournamentSpriteText
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2023-07-26 16:43:45 +08:00
|
|
|
Text = Beatmap?.Metadata.Author.Username ?? "unknown",
|
2018-10-13 23:40:33 +08:00
|
|
|
Padding = new MarginPadding { Right = 20 },
|
2020-03-03 18:14:44 +08:00
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
2020-03-03 18:14:44 +08:00
|
|
|
new TournamentSpriteText
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
|
|
|
Text = "difficulty",
|
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2020-03-03 18:14:44 +08:00
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Regular, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
2020-03-03 18:14:44 +08:00
|
|
|
new TournamentSpriteText
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2023-07-26 16:43:45 +08:00
|
|
|
Text = Beatmap?.DifficultyName ?? "unknown",
|
2020-03-03 18:14:44 +08:00
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2018-11-11 09:48:57 +08:00
|
|
|
flash = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Gray,
|
2019-08-21 12:29:50 +08:00
|
|
|
Blending = BlendingParameters.Additive,
|
2018-11-11 09:48:57 +08:00
|
|
|
Alpha = 0,
|
|
|
|
},
|
2018-10-13 23:40:33 +08:00
|
|
|
});
|
2018-11-17 15:00:12 +08:00
|
|
|
|
2021-01-25 20:22:37 +08:00
|
|
|
if (!string.IsNullOrEmpty(mod))
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2021-01-26 18:15:19 +08:00
|
|
|
AddInternal(new TournamentModIcon(mod)
|
2018-11-17 15:00:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2021-01-25 20:22:37 +08:00
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
Width = 60,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2018-11-17 15:00:12 +08:00
|
|
|
});
|
2019-11-11 19:53:22 +08:00
|
|
|
}
|
2018-10-13 23:40:33 +08:00
|
|
|
}
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
private void matchChanged(ValueChangedEvent<TournamentMatch?> match)
|
2018-11-08 05:29:04 +08:00
|
|
|
{
|
2019-06-18 13:57:05 +08:00
|
|
|
if (match.OldValue != null)
|
|
|
|
match.OldValue.PicksBans.CollectionChanged -= picksBansOnCollectionChanged;
|
2023-07-26 16:43:45 +08:00
|
|
|
if (match.NewValue != null)
|
|
|
|
match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged;
|
2023-07-30 01:49:13 +08:00
|
|
|
|
|
|
|
Scheduler.AddOnce(updateState);
|
2018-11-08 05:29:04 +08:00
|
|
|
}
|
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
private void picksBansOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
2023-07-30 01:49:13 +08:00
|
|
|
=> Scheduler.AddOnce(updateState);
|
2019-05-20 13:47:46 +08:00
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
private BeatmapChoice? choice;
|
2018-11-11 09:48:57 +08:00
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
private void updateState()
|
|
|
|
{
|
2023-07-25 19:50:55 +08:00
|
|
|
if (currentMatch.Value == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var newChoice = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap?.OnlineID);
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
bool shouldFlash = newChoice != choice;
|
2018-11-11 09:48:57 +08:00
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
if (newChoice != null)
|
2018-11-08 05:29:04 +08:00
|
|
|
{
|
2023-07-26 16:43:45 +08:00
|
|
|
if (shouldFlash)
|
2023-07-30 01:49:13 +08:00
|
|
|
flash.FadeOutFromOne(500).Loop(0, 10);
|
2018-11-11 09:48:57 +08:00
|
|
|
|
2018-11-08 05:47:42 +08:00
|
|
|
BorderThickness = 6;
|
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
BorderColour = TournamentGame.GetTeamColour(newChoice.Team);
|
2018-11-08 05:47:42 +08:00
|
|
|
|
2023-07-26 16:43:45 +08:00
|
|
|
switch (newChoice.Type)
|
2018-11-08 05:47:42 +08:00
|
|
|
{
|
|
|
|
case ChoiceType.Pick:
|
|
|
|
Colour = Color4.White;
|
|
|
|
Alpha = 1;
|
|
|
|
break;
|
2019-05-15 11:08:23 +08:00
|
|
|
|
2018-11-08 05:47:42 +08:00
|
|
|
case ChoiceType.Ban:
|
|
|
|
Colour = Color4.Gray;
|
|
|
|
Alpha = 0.5f;
|
2018-11-08 05:29:04 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Colour = Color4.White;
|
2018-11-08 05:47:42 +08:00
|
|
|
BorderThickness = 0;
|
|
|
|
Alpha = 1;
|
2018-11-08 05:29:04 +08:00
|
|
|
}
|
2023-07-26 16:43:45 +08:00
|
|
|
|
|
|
|
choice = newChoice;
|
2018-11-08 05:29:04 +08:00
|
|
|
}
|
2023-07-24 01:48:01 +08:00
|
|
|
|
2023-07-25 15:15:16 +08:00
|
|
|
private partial class NoUnloadBeatmapSetCover : UpdateableOnlineBeatmapSetCover
|
2023-07-24 01:48:01 +08:00
|
|
|
{
|
2023-07-25 15:15:16 +08:00
|
|
|
// As covers are displayed on stream, we want them to load as soon as possible.
|
2023-07-25 06:45:48 +08:00
|
|
|
protected override double LoadDelay => 0;
|
|
|
|
|
2023-07-25 15:15:16 +08:00
|
|
|
// Use DelayedLoadWrapper to avoid content unloading when switching away to another screen.
|
2023-07-24 01:48:01 +08:00
|
|
|
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad)
|
2024-01-17 15:26:01 +08:00
|
|
|
=> new DelayedLoadWrapper(createContentFunc(), timeBeforeLoad);
|
2023-07-24 01:48:01 +08:00
|
|
|
}
|
2018-10-13 23:40:33 +08:00
|
|
|
}
|
|
|
|
}
|