1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 16:47:24 +08:00
osu-lazer/osu.Game.Tournament/Screens/Gameplay/Components/MatchHeader.cs

227 lines
7.8 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.Graphics.Shapes;
2018-11-10 16:26:21 +08:00
using osu.Framework.Input.Events;
2019-03-04 11:06:41 +08:00
using osu.Game.Graphics;
2018-11-10 16:26:21 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Tournament.Components;
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;
using osuTK.Graphics;
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,
},
};
}
private class TeamScoreDisplay : CompositeDrawable
{
private readonly TeamColour teamColour;
2019-06-18 13:57:05 +08:00
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
2018-11-10 16:26:21 +08:00
private readonly Bindable<TournamentTeam> currentTeam = new Bindable<TournamentTeam>();
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
public TeamScoreDisplay(TeamColour teamColour)
{
this.teamColour = teamColour;
RelativeSizeAxes = Axes.Y;
Width = 300;
}
[BackgroundDependencyLoader]
private void load(LadderInfo ladder)
{
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(ladder.CurrentMatch);
}
2019-06-18 13:57:05 +08:00
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
2018-11-10 16:26:21 +08:00
{
currentTeamScore.UnbindBindings();
2019-03-02 12:40:43 +08:00
currentTeamScore.BindTo(teamColour == TeamColour.Red ? match.NewValue.Team1Score : match.NewValue.Team2Score);
2018-11-10 16:26:21 +08:00
currentTeam.UnbindBindings();
2019-03-02 12:40:43 +08:00
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);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
switch (e.Button)
{
case MouseButton.Left:
if (currentTeamScore.Value < currentMatch.Value.PointsToWin)
currentTeamScore.Value++;
return true;
2018-11-10 16:26:21 +08:00
case MouseButton.Right:
if (currentTeamScore.Value > 0)
currentTeamScore.Value--;
return true;
}
return base.OnMouseDown(e);
}
private void teamChanged(TournamentTeam team)
{
var colour = teamColour == TeamColour.Red ? TournamentGame.COLOUR_RED : TournamentGame.COLOUR_BLUE;
2018-11-15 13:12:14 +08:00
var flip = teamColour != TeamColour.Red;
2018-11-10 16:26:21 +08:00
InternalChildren = new Drawable[]
{
2018-11-15 13:12:14 +08:00
new TeamDisplay(team, colour, flip),
2018-11-15 20:28:42 +08:00
new TeamScore(currentTeamScore, flip, currentMatch.Value.PointsToWin)
2018-11-15 13:12:14 +08:00
{
Colour = colour
}
2018-11-10 16:26:21 +08:00
};
}
}
2018-11-15 20:28:42 +08:00
private class TeamScore : CompositeDrawable
2018-11-10 16:26:21 +08:00
{
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
private readonly StarCounter counter;
2018-11-15 20:28:42 +08:00
public TeamScore(Bindable<int?> score, bool flip, int count)
2018-11-10 16:26:21 +08:00
{
var anchor = flip ? Anchor.CentreRight : Anchor.CentreLeft;
Anchor = anchor;
Origin = anchor;
InternalChild = counter = new StarCounter(count)
{
Anchor = anchor,
X = (flip ? -1 : 1) * 90,
Y = 5,
Scale = flip ? new Vector2(-1, 1) : Vector2.One,
};
currentTeamScore.BindValueChanged(scoreChanged);
currentTeamScore.BindTo(score);
}
2019-03-02 12:40:43 +08:00
private void scoreChanged(ValueChangedEvent<int?> score) => counter.CountStars = score.NewValue ?? 0;
2018-11-10 16:26:21 +08:00
}
private class TeamDisplay : DrawableTournamentTeam
{
public TeamDisplay(TournamentTeam team, Color4 colour, bool flip)
: base(team)
{
RelativeSizeAxes = Axes.Both;
var anchor = flip ? Anchor.CentreRight : Anchor.CentreLeft;
Anchor = Origin = anchor;
Flag.Anchor = Flag.Origin = anchor;
Flag.RelativeSizeAxes = Axes.None;
Flag.Size = new Vector2(60, 40);
Flag.Margin = new MarginPadding(20);
InternalChild = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
Flag,
new TournamentSpriteText
2018-11-10 16:26:21 +08:00
{
Text = team?.FullName.Value.ToUpper() ?? "???",
2018-11-10 16:26:21 +08:00
X = (flip ? -1 : 1) * 90,
Y = -10,
Colour = colour,
2020-03-03 17:04:12 +08:00
Font = OsuFont.Torus.With(weight: FontWeight.Regular, size: 20),
2018-11-10 16:26:21 +08:00
Origin = anchor,
Anchor = anchor,
},
}
};
}
}
private class RoundDisplay : CompositeDrawable
{
2019-06-18 13:57:05 +08:00
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
2018-11-10 16:26:21 +08:00
private readonly TournamentSpriteText text;
2018-11-10 16:26:21 +08:00
public RoundDisplay()
{
Width = 200;
Height = 20;
Masking = true;
CornerRadius = 10;
2018-11-10 16:26:21 +08:00
InternalChildren = new Drawable[]
{
new Box
{
Colour = OsuColour.Gray(0.18f),
RelativeSizeAxes = Axes.Both,
},
text = new TournamentSpriteText
2018-11-10 16:26:21 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.White,
Font = OsuFont.Torus.With(weight: FontWeight.Regular, size: 16),
2018-11-10 16:26:21 +08:00
},
};
}
[BackgroundDependencyLoader]
private void load(LadderInfo ladder)
{
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(ladder.CurrentMatch);
}
private void matchChanged(ValueChangedEvent<TournamentMatch> match) =>
text.Text = match.NewValue.Round.Value?.Name.Value ?? "Unknown Round";
2018-11-10 16:26:21 +08:00
}
}
}