2018-10-13 23:40:33 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-12-01 08:50:11 +08:00
|
|
|
using System;
|
2018-11-08 05:29:04 +08:00
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
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;
|
2018-11-17 15:00:12 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.IO.Stores;
|
2018-10-13 23:40:33 +08:00
|
|
|
using osu.Framework.Localisation;
|
2018-11-17 15:00:12 +08:00
|
|
|
using osu.Framework.Platform;
|
2018-10-13 23:40:33 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-08 05:29:04 +08:00
|
|
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
2018-11-22 09:25:30 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-10-13 23:40:33 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
{
|
|
|
|
public class TournamentBeatmapPanel : CompositeDrawable
|
|
|
|
{
|
2018-11-08 05:29:04 +08:00
|
|
|
public readonly BeatmapInfo Beatmap;
|
2018-11-17 15:00:12 +08:00
|
|
|
private readonly string mods;
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2018-10-13 23:40:33 +08:00
|
|
|
private const float horizontal_padding = 10;
|
|
|
|
private const float vertical_padding = 5;
|
|
|
|
|
2018-11-04 06:12:07 +08:00
|
|
|
public const float HEIGHT = 50;
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
|
2018-11-11 09:48:57 +08:00
|
|
|
private Box flash;
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2018-11-17 15:00:12 +08:00
|
|
|
public TournamentBeatmapPanel(BeatmapInfo beatmap, string mods = null)
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2018-12-01 08:50:11 +08:00
|
|
|
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
Beatmap = beatmap;
|
2018-11-17 15:00:12 +08:00
|
|
|
this.mods = mods;
|
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]
|
2018-11-17 15:00:12 +08:00
|
|
|
private void load(LadderInfo ladder, Storage storage)
|
2018-10-13 23:40:33 +08:00
|
|
|
{
|
2018-11-08 05:29:04 +08:00
|
|
|
currentMatch.BindValueChanged(matchChanged);
|
|
|
|
currentMatch.BindTo(ladder.CurrentMatch);
|
|
|
|
|
2018-11-16 17:14:42 +08:00
|
|
|
CornerRadius = HEIGHT / 2;
|
2018-10-13 23:40:33 +08:00
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
},
|
|
|
|
new UpdateableBeatmapSetCover
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(0.5f),
|
2018-11-08 05:29:04 +08:00
|
|
|
BeatmapSet = Beatmap.BeatmapSet,
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding(vertical_padding),
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Text = new LocalisedString((
|
2018-11-08 05:29:04 +08:00
|
|
|
$"{Beatmap.Metadata.ArtistUnicode} - {Beatmap.Metadata.TitleUnicode}",
|
|
|
|
$"{Beatmap.Metadata.Artist} - {Beatmap.Metadata.Title}")),
|
2018-10-13 23:40:33 +08:00
|
|
|
Font = @"Exo2.0-BoldItalic",
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding(vertical_padding),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "mapper",
|
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2019-03-04 11:06:41 +08:00
|
|
|
Font = OsuFont.GetFont(italics: true, weight: FontWeight.Regular, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2018-11-08 05:29:04 +08:00
|
|
|
Text = Beatmap.Metadata.AuthorString,
|
2018-10-13 23:40:33 +08:00
|
|
|
Padding = new MarginPadding { Right = 20 },
|
2019-03-04 11:06:41 +08:00
|
|
|
Font = OsuFont.GetFont(italics: true, weight: FontWeight.Bold, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "difficulty",
|
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2019-03-04 11:06:41 +08:00
|
|
|
Font = OsuFont.GetFont(italics: true, weight: FontWeight.Regular, size: 14)
|
2018-10-13 23:40:33 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2018-11-08 05:29:04 +08:00
|
|
|
Text = Beatmap.Version,
|
2019-03-04 11:06:41 +08:00
|
|
|
Font = OsuFont.GetFont(italics: true, 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,
|
|
|
|
Blending = BlendingMode.Additive,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
2018-10-13 23:40:33 +08:00
|
|
|
});
|
2018-11-17 15:00:12 +08:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(mods))
|
|
|
|
AddInternal(new Sprite
|
|
|
|
{
|
2019-02-17 18:48:54 +08:00
|
|
|
Texture = new LargeTextureStore(new TextureLoaderStore(new StorageBackedResourceStore(storage))).Get($"mods/{mods}"),
|
2018-11-17 15:00:12 +08:00
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
Scale = new Vector2(0.5f)
|
|
|
|
});
|
2018-10-13 23:40:33 +08:00
|
|
|
}
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2019-03-02 12:40:43 +08:00
|
|
|
private void matchChanged(ValueChangedEvent<MatchPairing> pairing)
|
2018-11-08 05:29:04 +08:00
|
|
|
{
|
2019-03-02 12:40:43 +08:00
|
|
|
pairing.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged;
|
2018-11-08 05:29:04 +08:00
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
|
2018-11-11 09:48:57 +08:00
|
|
|
private BeatmapChoice choice;
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
var found = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap.OnlineBeatmapID);
|
|
|
|
|
2018-11-11 09:48:57 +08:00
|
|
|
bool doFlash = found != choice;
|
|
|
|
choice = found;
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
if (found != null)
|
|
|
|
{
|
2018-11-11 09:48:57 +08:00
|
|
|
if (doFlash)
|
2018-11-12 00:25:31 +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;
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
switch (found.Team)
|
|
|
|
{
|
|
|
|
case TeamColour.Red:
|
2018-11-08 05:47:42 +08:00
|
|
|
BorderColour = Color4.Red;
|
2018-11-08 05:29:04 +08:00
|
|
|
break;
|
|
|
|
case TeamColour.Blue:
|
2018-11-08 05:47:42 +08:00
|
|
|
BorderColour = Color4.Blue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (found.Type)
|
|
|
|
{
|
|
|
|
case ChoiceType.Pick:
|
|
|
|
Colour = Color4.White;
|
|
|
|
Alpha = 1;
|
|
|
|
break;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void picksBansOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
var list = (ObservableCollection<BeatmapChoice>)sender;
|
|
|
|
if (sender != currentMatch.Value.PicksBans)
|
|
|
|
{
|
|
|
|
// todo: we need a last attribute in bindable valuechanged events badly.
|
|
|
|
list.CollectionChanged -= picksBansOnCollectionChanged;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
}
|
2018-10-13 23:40:33 +08:00
|
|
|
}
|
|
|
|
}
|