mirror of
https://github.com/ppy/osu
synced 2024-12-25 16:22:23 +00:00
Add basic match pairing component for ladder display
This commit is contained in:
parent
51dcfeee92
commit
40b01ec35a
61
osu.Game.Tournament.Tests/TestCaseMatchPairings.cs
Normal file
61
osu.Game.Tournament.Tests/TestCaseMatchPairings.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osu.Game.Tournament.Screens.Drawings.Components;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
|
||||
namespace osu.Game.Tournament.Tests
|
||||
{
|
||||
public class TestCaseMatchPairings : OsuTestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(MatchPairing),
|
||||
typeof(DrawableMatchPairing),
|
||||
typeof(DrawableMatchTeam),
|
||||
typeof(DrawableTournamentTeam),
|
||||
};
|
||||
|
||||
public TestCaseMatchPairings()
|
||||
{
|
||||
var pairing1 = new MatchPairing(
|
||||
new TournamentTeam { FlagName = "AU", FullName = "Australia", },
|
||||
new TournamentTeam { FlagName = "JP", FullName = "Japan", Acronym = "JPN" })
|
||||
{
|
||||
Team1Score = { Value = 8 },
|
||||
Team2Score = { Value = 6 },
|
||||
};
|
||||
|
||||
var pairing2 = new MatchPairing(
|
||||
new TournamentTeam
|
||||
{
|
||||
FlagName = "RO",
|
||||
FullName = "Romania",
|
||||
}
|
||||
);
|
||||
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new DrawableMatchPairing(pairing1),
|
||||
new DrawableMatchPairing(pairing2),
|
||||
new DrawableMatchPairing(new MatchPairing())
|
||||
}
|
||||
};
|
||||
|
||||
AddStep("mark complete", () => pairing1.Completed.Value = true);
|
||||
AddRepeatStep("change scores", () => pairing1.Team2Score.Value++, 5);
|
||||
AddStep("mark complete", () => pairing1.Completed.Value = true);
|
||||
|
||||
AddStep("add new team", () => pairing2.Team2.Value =
|
||||
new TournamentTeam { FlagName = "PT", FullName = "Portugal" }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
public class DrawableMatchPairing : CompositeDrawable
|
||||
{
|
||||
private readonly MatchPairing pairing;
|
||||
private readonly FillFlowContainer<DrawableMatchTeam> flow;
|
||||
|
||||
public DrawableMatchPairing(MatchPairing pairing)
|
||||
{
|
||||
this.pairing = pairing;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
Margin = new MarginPadding(5);
|
||||
|
||||
InternalChild = flow = new FillFlowContainer<DrawableMatchTeam>
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
};
|
||||
|
||||
pairing.Team1.BindValueChanged(_ => updateTeams());
|
||||
pairing.Team2.BindValueChanged(_ => updateTeams());
|
||||
|
||||
updateTeams();
|
||||
}
|
||||
|
||||
private void updateTeams()
|
||||
{
|
||||
// todo: teams may need to be bindable for transitions at a later point.
|
||||
|
||||
flow.Children = new[]
|
||||
{
|
||||
new DrawableMatchTeam(pairing.Team1, pairing),
|
||||
new DrawableMatchTeam(pairing.Team2, pairing)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Tournament.Screens.Drawings.Components;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
public class DrawableMatchTeam : DrawableTournamentTeam
|
||||
{
|
||||
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;
|
||||
|
||||
public DrawableMatchTeam(TournamentTeam team, MatchPairing pairing)
|
||||
: base(team)
|
||||
{
|
||||
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 };
|
||||
AcronymText.TextSize = 24;
|
||||
|
||||
if (pairing != null)
|
||||
{
|
||||
completed.BindTo(pairing.Completed);
|
||||
|
||||
if (team == pairing.Team1.Value)
|
||||
{
|
||||
score.BindTo(pairing.Team1Score);
|
||||
isWinner = () => pairing.Team1Score.Value > pairing.Team2Score.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
score.BindTo(pairing.Team2Score);
|
||||
isWinner = () => pairing.Team2Score.Value > pairing.Team1Score.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
colourWinner = colours.BlueDarker;
|
||||
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,
|
||||
TextSize = 20,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
completed.BindValueChanged(_ => updateWinStyle());
|
||||
|
||||
score.BindValueChanged(val =>
|
||||
{
|
||||
scoreText.Text = val?.ToString() ?? string.Empty;
|
||||
updateWinStyle();
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void updateWinStyle()
|
||||
{
|
||||
bool winner = completed && isWinner?.Invoke() == true;
|
||||
|
||||
background.FadeColour(winner ? colourWinner : colourNormal, winner ? 500 : 0, Easing.OutQuint);
|
||||
|
||||
scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Tournament.Screens.Drawings.Components;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
public abstract class DrawableTournamentTeam : CompositeDrawable
|
||||
{
|
||||
public readonly TournamentTeam Team;
|
||||
|
||||
protected readonly Sprite Flag;
|
||||
protected readonly OsuSpriteText AcronymText;
|
||||
|
||||
protected DrawableTournamentTeam(TournamentTeam team)
|
||||
{
|
||||
Team = team;
|
||||
|
||||
Flag = new Sprite
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit
|
||||
};
|
||||
|
||||
AcronymText = new OsuSpriteText
|
||||
{
|
||||
Text = team?.Acronym.ToUpperInvariant() ?? string.Empty,
|
||||
Font = @"Exo2.0-Regular"
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures)
|
||||
{
|
||||
if (Team != null)
|
||||
Flag.Texture = textures.Get($@"Flags/{Team.FlagName}");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Tournament.Screens.Drawings.Components;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of two teams competing in a head-to-head match.
|
||||
/// </summary>
|
||||
public class MatchPairing
|
||||
{
|
||||
public Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
|
||||
public Bindable<int?> Team1Score = new Bindable<int?>();
|
||||
|
||||
public Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
|
||||
public Bindable<int?> Team2Score = new Bindable<int?>();
|
||||
|
||||
public Bindable<bool> Completed = new Bindable<bool>();
|
||||
|
||||
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)
|
||||
{
|
||||
Team1.Value = team1;
|
||||
Team2.Value = team2;
|
||||
|
||||
Team1Score.ValueChanged += _ => Completed.Value = false;
|
||||
Team2Score.ValueChanged += _ => Completed.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user