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-11-10 16:26:21 +08:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 12:40:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-11-10 16:26:21 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Events;
|
2020-03-07 11:51:11 +08:00
|
|
|
using osu.Game.Tournament.Components;
|
2019-06-18 13:51:48 +08:00
|
|
|
using osu.Game.Tournament.Models;
|
2020-03-07 11:51:11 +08:00
|
|
|
using osuTK;
|
2018-11-22 09:25:30 +08:00
|
|
|
using osuTK.Input;
|
2018-11-10 16:26:21 +08:00
|
|
|
|
2018-11-15 20:28:42 +08:00
|
|
|
namespace osu.Game.Tournament.Screens.Gameplay.Components
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
|
|
|
public class MatchHeader : Container
|
|
|
|
{
|
2020-03-07 13:46:40 +08:00
|
|
|
private TeamScoreDisplay teamDisplay1;
|
|
|
|
private TeamScoreDisplay teamDisplay2;
|
|
|
|
|
|
|
|
public bool ShowScores
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
teamDisplay1.ShowScore = value;
|
|
|
|
teamDisplay2.ShowScore = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-10 16:26:21 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2019-05-18 20:37:46 +08:00
|
|
|
private void load()
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-11-22 14:42:10 +08:00
|
|
|
Height = 95;
|
2018-11-10 16:26:21 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-03-07 11:51:11 +08:00
|
|
|
new FillFlowContainer
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
2020-03-07 11:51:11 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new DrawableTournamentTitleText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(1.2f)
|
|
|
|
},
|
|
|
|
new RoundDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(0.4f)
|
|
|
|
},
|
|
|
|
}
|
2018-11-10 16:26:21 +08:00
|
|
|
},
|
2020-03-07 13:46:40 +08:00
|
|
|
teamDisplay1 = new TeamScoreDisplay(TeamColour.Red)
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
},
|
2020-03-07 13:46:40 +08:00
|
|
|
teamDisplay2 = new TeamScoreDisplay(TeamColour.Blue)
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-03-06 15:07:54 +08:00
|
|
|
}
|
2018-11-10 16:26:21 +08:00
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
public class TeamScoreDisplay : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly TeamColour teamColour;
|
2018-11-10 16:26:21 +08:00
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
|
|
|
private readonly Bindable<TournamentTeam> currentTeam = new Bindable<TournamentTeam>();
|
|
|
|
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
|
2018-11-10 16:26:21 +08:00
|
|
|
|
2020-03-07 13:46:40 +08:00
|
|
|
private TeamDisplay teamDisplay;
|
|
|
|
|
|
|
|
public bool ShowScore { set => teamDisplay.ShowScore = value; }
|
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
public TeamScoreDisplay(TeamColour teamColour)
|
|
|
|
{
|
|
|
|
this.teamColour = teamColour;
|
2018-11-15 13:12:14 +08:00
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
RelativeSizeAxes = Axes.Y;
|
2020-03-07 11:51:11 +08:00
|
|
|
AutoSizeAxes = Axes.X;
|
2018-11-10 16:26:21 +08:00
|
|
|
}
|
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(LadderInfo ladder)
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
2020-03-06 15:07:54 +08:00
|
|
|
currentMatch.BindTo(ladder.CurrentMatch);
|
2020-03-09 13:57:19 +08:00
|
|
|
currentMatch.BindValueChanged(matchChanged, true);
|
2020-03-06 15:07:54 +08:00
|
|
|
}
|
2018-11-10 16:26:21 +08:00
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
|
|
|
|
{
|
|
|
|
currentTeamScore.UnbindBindings();
|
|
|
|
currentTeam.UnbindBindings();
|
2020-03-09 13:57:19 +08:00
|
|
|
|
|
|
|
if (match.NewValue != null)
|
|
|
|
{
|
|
|
|
currentTeamScore.BindTo(teamColour == TeamColour.Red ? match.NewValue.Team1Score : match.NewValue.Team2Score);
|
|
|
|
currentTeam.BindTo(teamColour == TeamColour.Red ? match.NewValue.Team1 : match.NewValue.Team2);
|
|
|
|
}
|
2018-11-10 16:26:21 +08:00
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
// team may change to same team, which means score is not in a good state.
|
|
|
|
// thus we handle this manually.
|
|
|
|
teamChanged(currentTeam.Value);
|
2018-11-10 16:26:21 +08:00
|
|
|
}
|
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
2020-03-06 15:07:54 +08:00
|
|
|
switch (e.Button)
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
2020-03-06 15:07:54 +08:00
|
|
|
case MouseButton.Left:
|
|
|
|
if (currentTeamScore.Value < currentMatch.Value.PointsToWin)
|
|
|
|
currentTeamScore.Value++;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case MouseButton.Right:
|
|
|
|
if (currentTeamScore.Value > 0)
|
|
|
|
currentTeamScore.Value--;
|
|
|
|
return true;
|
2018-11-10 16:26:21 +08:00
|
|
|
}
|
2020-03-06 15:07:54 +08:00
|
|
|
|
|
|
|
return base.OnMouseDown(e);
|
2018-11-10 16:26:21 +08:00
|
|
|
}
|
|
|
|
|
2020-03-06 15:07:54 +08:00
|
|
|
private void teamChanged(TournamentTeam team)
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
2020-03-06 15:07:54 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2018-11-10 16:26:21 +08:00
|
|
|
{
|
2020-03-09 13:57:19 +08:00
|
|
|
teamDisplay = new TeamDisplay(team, teamColour, currentTeamScore, currentMatch.Value?.PointsToWin ?? 0),
|
2020-03-06 15:07:54 +08:00
|
|
|
};
|
2018-11-10 16:26:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|