2020-03-12 13:06:40 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-12 13:06:40 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Tournament.Models;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Gameplay.Components
|
|
|
|
{
|
|
|
|
public class TeamScoreDisplay : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly TeamColour teamColour;
|
|
|
|
|
|
|
|
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
|
|
|
private readonly Bindable<TournamentTeam> currentTeam = new Bindable<TournamentTeam>();
|
|
|
|
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
|
|
|
|
|
|
|
|
private TeamDisplay teamDisplay;
|
|
|
|
|
2020-06-09 22:38:54 +08:00
|
|
|
public bool ShowScore
|
|
|
|
{
|
2022-09-02 17:20:23 +08:00
|
|
|
get => teamDisplay.ShowScore;
|
2020-06-09 22:38:54 +08:00
|
|
|
set => teamDisplay.ShowScore = value;
|
|
|
|
}
|
2020-03-12 13:06:40 +08:00
|
|
|
|
|
|
|
public TeamScoreDisplay(TeamColour teamColour)
|
|
|
|
{
|
|
|
|
this.teamColour = teamColour;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(LadderInfo ladder)
|
|
|
|
{
|
|
|
|
currentMatch.BindTo(ladder.CurrentMatch);
|
2020-03-17 12:16:52 +08:00
|
|
|
currentMatch.BindValueChanged(matchChanged);
|
|
|
|
|
2022-07-13 17:15:59 +08:00
|
|
|
currentTeam.BindValueChanged(teamChanged);
|
|
|
|
|
2020-03-17 12:16:52 +08:00
|
|
|
updateMatch();
|
2020-03-12 13:06:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
|
|
|
|
{
|
|
|
|
currentTeamScore.UnbindBindings();
|
|
|
|
currentTeam.UnbindBindings();
|
|
|
|
|
2020-03-17 12:16:52 +08:00
|
|
|
Scheduler.AddOnce(updateMatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMatch()
|
|
|
|
{
|
|
|
|
var match = currentMatch.Value;
|
|
|
|
|
|
|
|
if (match != null)
|
2020-03-12 13:06:40 +08:00
|
|
|
{
|
2020-03-17 12:16:52 +08:00
|
|
|
match.StartMatch();
|
|
|
|
|
|
|
|
currentTeamScore.BindTo(teamColour == TeamColour.Red ? match.Team1Score : match.Team2Score);
|
|
|
|
currentTeam.BindTo(teamColour == TeamColour.Red ? match.Team1 : match.Team2);
|
2020-03-12 13:06:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// team may change to same team, which means score is not in a good state.
|
|
|
|
// thus we handle this manually.
|
2022-07-13 17:15:59 +08:00
|
|
|
currentTeam.TriggerChange();
|
2020-03-12 13:06:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
switch (e.Button)
|
|
|
|
{
|
|
|
|
case MouseButton.Left:
|
|
|
|
if (currentTeamScore.Value < currentMatch.Value.PointsToWin)
|
|
|
|
currentTeamScore.Value++;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case MouseButton.Right:
|
|
|
|
if (currentTeamScore.Value > 0)
|
|
|
|
currentTeamScore.Value--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnMouseDown(e);
|
|
|
|
}
|
|
|
|
|
2022-07-13 17:15:59 +08:00
|
|
|
private void teamChanged(ValueChangedEvent<TournamentTeam> team)
|
2020-03-12 13:06:40 +08:00
|
|
|
{
|
2022-09-02 17:20:23 +08:00
|
|
|
bool wasShowingScores = teamDisplay?.ShowScore ?? false;
|
|
|
|
|
2020-03-12 13:06:40 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2022-07-13 17:15:59 +08:00
|
|
|
teamDisplay = new TeamDisplay(team.NewValue, teamColour, currentTeamScore, currentMatch.Value?.PointsToWin ?? 0),
|
2020-03-12 13:06:40 +08:00
|
|
|
};
|
2022-09-02 17:20:23 +08:00
|
|
|
|
|
|
|
teamDisplay.ShowScore = wasShowingScores;
|
2020-03-12 13:06:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|