1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-10 21:52:59 +08:00
osu-lazer/osu.Game.Tournament/Screens/Gameplay/Components/MatchHeader.cs

115 lines
3.7 KiB
C#
Raw Normal View History

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;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
2018-11-11 08:16:46 +08:00
using osu.Game.Tournament.Screens.Showcase;
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
{
[BackgroundDependencyLoader]
2019-05-18 20:37:46 +08:00
private void load()
2018-11-10 16:26:21 +08:00
{
RelativeSizeAxes = Axes.X;
Height = 95;
2018-11-10 16:26:21 +08:00
Children = new Drawable[]
{
2018-11-11 08:16:46 +08:00
new TournamentLogo(),
2018-11-10 16:26:21 +08:00
new RoundDisplay
{
Y = 5,
2018-11-10 16:26:21 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.TopCentre,
},
new TeamScoreDisplay(TeamColour.Red)
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
},
new TeamScoreDisplay(TeamColour.Blue)
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
};
}
}
2018-11-10 16:26:21 +08:00
public class TeamScoreDisplay : CompositeDrawable
{
private readonly TeamColour teamColour;
2018-11-10 16:26:21 +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
public TeamScoreDisplay(TeamColour teamColour)
{
this.teamColour = teamColour;
2018-11-15 13:12:14 +08:00
RelativeSizeAxes = Axes.Y;
Width = 300;
2018-11-10 16:26:21 +08:00
}
[BackgroundDependencyLoader]
private void load(LadderInfo ladder)
2018-11-10 16:26:21 +08:00
{
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(ladder.CurrentMatch);
}
2018-11-10 16:26:21 +08:00
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
{
currentTeamScore.UnbindBindings();
currentTeamScore.BindTo(teamColour == TeamColour.Red ? match.NewValue.Team1Score : match.NewValue.Team2Score);
2018-11-10 16:26:21 +08:00
currentTeam.UnbindBindings();
currentTeam.BindTo(teamColour == TeamColour.Red ? match.NewValue.Team1 : match.NewValue.Team2);
2018-11-10 16:26:21 +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
}
protected override bool OnMouseDown(MouseDownEvent e)
2018-11-10 16:26:21 +08:00
{
switch (e.Button)
2018-11-10 16:26:21 +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
}
return base.OnMouseDown(e);
2018-11-10 16:26:21 +08:00
}
private void teamChanged(TournamentTeam team)
2018-11-10 16:26:21 +08:00
{
var colour = teamColour == TeamColour.Red ? TournamentGame.COLOUR_RED : TournamentGame.COLOUR_BLUE;
var flip = teamColour == TeamColour.Red;
InternalChildren = new Drawable[]
2018-11-10 16:26:21 +08:00
{
new TeamDisplay(team, colour, flip),
new TeamScore(currentTeamScore, flip, currentMatch.Value.PointsToWin)
2018-11-10 16:26:21 +08:00
{
Colour = colour
}
};
2018-11-10 16:26:21 +08:00
}
}
}