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-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 12:40:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-08-26 00:14:18 +08:00
|
|
|
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-11-22 09:25:30 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
using osuTK.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-11-16 19:14:34 +08:00
|
|
|
private LadderEditorScreen ladderEditor;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
2018-11-11 09:13:17 +08:00
|
|
|
[Resolved]
|
|
|
|
private LadderInfo ladderInfo { get; set; }
|
|
|
|
|
|
|
|
private void setCurrent()
|
|
|
|
{
|
|
|
|
//todo: tournamentgamebase?
|
|
|
|
if (ladderInfo.CurrentMatch.Value != null)
|
|
|
|
ladderInfo.CurrentMatch.Value.Current.Value = false;
|
|
|
|
|
|
|
|
ladderInfo.CurrentMatch.Value = pairing;
|
|
|
|
ladderInfo.CurrentMatch.Value.Current.Value = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-03-02 12:40:43 +08:00
|
|
|
public DrawableMatchTeam(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 };
|
2019-03-04 11:06:41 +08:00
|
|
|
AcronymText.Font = OsuFont.GetFont(size: 24);
|
2018-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
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);
|
2019-03-02 12:40:43 +08:00
|
|
|
if (team != null)
|
|
|
|
score.BindTo(team == 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)]
|
2018-11-16 19:14:34 +08:00
|
|
|
private void load(OsuColour colours, LadderEditorScreen ladderEditor)
|
2018-08-26 00:14:18 +08:00
|
|
|
{
|
2018-11-16 19:14:34 +08:00
|
|
|
this.ladderEditor = ladderEditor;
|
2018-09-10 03:51:38 +08:00
|
|
|
|
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,
|
2019-03-04 11:06:41 +08:00
|
|
|
Font = OsuFont.GetFont(size: 20),
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
completed.BindValueChanged(_ => updateWinStyle());
|
|
|
|
|
|
|
|
score.BindValueChanged(val =>
|
|
|
|
{
|
2019-03-02 12:40:43 +08:00
|
|
|
scoreText.Text = val.NewValue?.ToString() ?? string.Empty;
|
2018-08-26 00:14:18 +08:00
|
|
|
updateWinStyle();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2018-09-25 09:35:00 +08:00
|
|
|
//TODO: use OnClick instead once we have per-button clicks.
|
2018-11-07 00:20:32 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-08-26 18:11:46 +08:00
|
|
|
{
|
2018-11-16 19:14:34 +08:00
|
|
|
if (Team == null || editorInfo != null) return false;
|
2018-08-26 18:11:46 +08:00
|
|
|
|
2018-11-07 00:20:32 +08:00
|
|
|
if (!pairing.Current.Value)
|
|
|
|
{
|
2018-11-11 09:13:17 +08:00
|
|
|
setCurrent();
|
2018-11-07 00:20:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2019-03-02 12:40:43 +08:00
|
|
|
else if (!pairing.Completed.Value)
|
2018-08-26 18:11:46 +08:00
|
|
|
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;
|
|
|
|
|
2019-03-02 12:40:43 +08:00
|
|
|
if (pairing.Completed.Value && pairing.Winner != Team)
|
2018-09-25 02:14:30 +08:00
|
|
|
// 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()
|
|
|
|
{
|
2019-03-02 12:40:43 +08:00
|
|
|
bool winner = completed.Value && isWinner?.Invoke() == true;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
background.FadeColour(winner ? colourWinner : colourNormal, winner ? 500 : 0, Easing.OutQuint);
|
|
|
|
|
2019-05-15 12:10:58 +08:00
|
|
|
scoreText.Font = AcronymText.Font = OsuFont.GetFont(weight: winner ? FontWeight.Bold : FontWeight.Regular);
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|
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
|
|
|
|
{
|
2018-11-16 19:14:34 +08:00
|
|
|
if (editorInfo == null)
|
2018-09-22 04:52:25 +08:00
|
|
|
return new MenuItem[0];
|
|
|
|
|
|
|
|
return new MenuItem[]
|
|
|
|
{
|
2018-11-11 09:13:17 +08:00
|
|
|
new OsuMenuItem("Set as current", MenuItemType.Standard, setCurrent),
|
2018-11-16 19:14:34 +08:00
|
|
|
new OsuMenuItem("Join with", MenuItemType.Standard, () => ladderEditor.RequestJoin(pairing, false)),
|
|
|
|
new OsuMenuItem("Join with (loser)", MenuItemType.Standard, () => ladderEditor.RequestJoin(pairing, true)),
|
|
|
|
new OsuMenuItem("Remove", MenuItemType.Destructive, () => ladderEditor.Remove(pairing)),
|
2018-09-22 04:52:25 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
}
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|