2018-08-26 00:14:18 +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
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-09-10 03:51:38 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2018-08-26 00:14:18 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-09-10 03:51:38 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-12 17:49:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-08-26 00:14:18 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-09-21 18:58:47 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-08-26 00:24:19 +08:00
|
|
|
using osu.Game.Tournament.Components;
|
2018-08-26 00:14:18 +08:00
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
2018-08-26 18:11:46 +08:00
|
|
|
using OpenTK.Input;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder.Components
|
|
|
|
{
|
2018-09-10 03:51:38 +08:00
|
|
|
public class DrawableMatchTeam : DrawableTournamentTeam, IHasContextMenu
|
2018-08-26 00:14:18 +08:00
|
|
|
{
|
2018-08-26 18:11:46 +08:00
|
|
|
private readonly MatchPairing pairing;
|
2018-09-25 02:55:24 +08:00
|
|
|
private readonly bool losers;
|
2018-08-26 00:14:18 +08:00
|
|
|
private OsuSpriteText scoreText;
|
|
|
|
private Box background;
|
|
|
|
|
|
|
|
private readonly Bindable<int?> score = new Bindable<int?>();
|
|
|
|
private readonly BindableBool completed = new BindableBool();
|
|
|
|
|
|
|
|
private Color4 colourWinner;
|
|
|
|
private Color4 colourNormal;
|
|
|
|
|
|
|
|
private readonly Func<bool> isWinner;
|
2018-09-10 03:51:38 +08:00
|
|
|
private LadderManager manager;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
2018-09-22 04:52:25 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
2018-11-06 13:49:20 +08:00
|
|
|
private LadderEditorInfo editorInfo { get; set; }
|
2018-09-22 04:52:25 +08:00
|
|
|
|
2018-09-25 02:55:24 +08:00
|
|
|
public DrawableMatchTeam(Bindable<TournamentTeam> team, MatchPairing pairing, bool losers)
|
2018-08-26 00:14:18 +08:00
|
|
|
: base(team)
|
|
|
|
{
|
2018-08-26 18:11:46 +08:00
|
|
|
this.pairing = pairing;
|
2018-09-25 02:55:24 +08:00
|
|
|
this.losers = losers;
|
2018-08-26 00:14:18 +08:00
|
|
|
Size = new Vector2(150, 40);
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
|
|
|
Flag.Scale = new Vector2(0.9f);
|
|
|
|
Flag.Anchor = Flag.Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
AcronymText.Anchor = AcronymText.Origin = Anchor.CentreLeft;
|
|
|
|
AcronymText.Padding = new MarginPadding { Left = 50 };
|
|
|
|
AcronymText.TextSize = 24;
|
|
|
|
|
|
|
|
if (pairing != null)
|
|
|
|
{
|
2018-08-26 17:41:21 +08:00
|
|
|
isWinner = () => pairing.Winner == Team;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
2018-08-26 17:41:21 +08:00
|
|
|
completed.BindTo(pairing.Completed);
|
2018-09-10 03:51:38 +08:00
|
|
|
if (team.Value != null)
|
|
|
|
score.BindTo(team.Value == pairing.Team1.Value ? pairing.Team1Score : pairing.Team2Score);
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 03:51:38 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(OsuColour colours, LadderManager manager)
|
2018-08-26 00:14:18 +08:00
|
|
|
{
|
2018-09-10 03:51:38 +08:00
|
|
|
this.manager = manager;
|
|
|
|
|
2018-09-25 02:55:24 +08:00
|
|
|
colourWinner = losers ? colours.YellowDarker : colours.BlueDarker;
|
2018-08-26 00:14:18 +08:00
|
|
|
colourNormal = OsuColour.Gray(0.2f);
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
AcronymText,
|
|
|
|
Flag,
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
Width = 0.3f,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.1f),
|
|
|
|
Alpha = 0.8f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
scoreText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
TextSize = 20,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
completed.BindValueChanged(_ => updateWinStyle());
|
|
|
|
|
|
|
|
score.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
scoreText.Text = val?.ToString() ?? string.Empty;
|
|
|
|
updateWinStyle();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2018-09-25 09:35:00 +08:00
|
|
|
//TODO: use OnClick instead once we have per-button clicks.
|
2018-10-12 17:49:47 +08:00
|
|
|
protected override bool OnMouseUp(MouseUpEvent e)
|
2018-08-26 18:11:46 +08:00
|
|
|
{
|
2018-09-22 04:52:25 +08:00
|
|
|
if (Team == null || editorInfo.EditingEnabled) return false;
|
2018-08-26 18:11:46 +08:00
|
|
|
|
2018-10-12 17:49:47 +08:00
|
|
|
if (e.Button == MouseButton.Left)
|
2018-08-26 18:11:46 +08:00
|
|
|
{
|
|
|
|
if (score.Value == null)
|
|
|
|
{
|
|
|
|
pairing.StartMatch();
|
|
|
|
}
|
|
|
|
else if (!pairing.Completed)
|
|
|
|
score.Value++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 02:03:40 +08:00
|
|
|
if (pairing.Progression.Value?.Completed.Value == true)
|
2018-09-25 01:31:48 +08:00
|
|
|
// don't allow changing scores if the match has a progression. can cause large data loss
|
|
|
|
return false;
|
|
|
|
|
2018-09-25 02:14:30 +08:00
|
|
|
if (pairing.Completed && pairing.Winner != Team)
|
|
|
|
// don't allow changing scores from the non-winner
|
|
|
|
return false;
|
|
|
|
|
2018-08-26 18:11:46 +08:00
|
|
|
if (score.Value > 0)
|
|
|
|
score.Value--;
|
|
|
|
else
|
|
|
|
pairing.CancelMatchStart();
|
|
|
|
}
|
|
|
|
|
2018-09-10 03:51:38 +08:00
|
|
|
return false;
|
2018-08-26 18:11:46 +08:00
|
|
|
}
|
|
|
|
|
2018-08-26 00:14:18 +08:00
|
|
|
private void updateWinStyle()
|
|
|
|
{
|
|
|
|
bool winner = completed && isWinner?.Invoke() == true;
|
|
|
|
|
|
|
|
background.FadeColour(winner ? colourWinner : colourNormal, winner ? 500 : 0, Easing.OutQuint);
|
|
|
|
|
|
|
|
scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular";
|
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
|
2018-09-22 04:52:25 +08:00
|
|
|
public MenuItem[] ContextMenuItems
|
2018-09-10 03:51:38 +08:00
|
|
|
{
|
2018-09-22 04:52:25 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
if (!editorInfo.EditingEnabled)
|
|
|
|
return new MenuItem[0];
|
|
|
|
|
|
|
|
return new MenuItem[]
|
|
|
|
{
|
2018-09-25 01:31:48 +08:00
|
|
|
new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing, false)),
|
|
|
|
new OsuMenuItem("Join with (loser)", MenuItemType.Standard, () => manager.RequestJoin(pairing, true)),
|
2018-09-22 04:52:25 +08:00
|
|
|
new OsuMenuItem("Remove", MenuItemType.Destructive, () => manager.Remove(pairing)),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
}
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|